Code Monkey home page Code Monkey logo

Comments (4)

JohnEarnest avatar JohnEarnest commented on May 13, 2024

It's worth considering, but it's a little like adding macros- the simple implementation is easy, but this quickly turns into a more elaborate feature. Single addition/subtraction/multiplication expressions will be useful for certain situations, but you really want fully nestable expressions. This might require rewriting Octo's token-at-a-time parsing strategy.

One relatively simple idea I had was to use {} to permit embedding arbitrary javascript expressions, computed at compile time. With a little magic you could inject Octo constants (and labels) into the JS scope and the results would be fairly clean to use and very flexible. You'd even be able to compute complex lookup tables this way, right in your Octo source code. There are downsides to this idea, though- not only would it permanently tie the Octo language to Javascript (there has been a bit of tinkering done with making an Octo-compatible assembler in C#, for example), but it would also mean that compiling Octo programs becomes a potential security risk with arbitrary code execution on the client (in the browser, fairly sandboxed, but not if you use the Node CLI frontend).

I am not hard-set against having constant expression evaluation in Octo, but I want to make it clear that doing it right will be a big effort, both in design and implementation, and any solution must be backwards-compatible with the existing corpus of Octo programs.

from octo.

whoozle avatar whoozle commented on May 13, 2024

I was thinking about supporting very simple expressions, maybe even without braces for now. This is perfectly compatible with current language. This could be very handy and many assemblers (masm/tasm for sure, even z80's ZEUS) supported it. :)
Frankly, I think that inlining js code is not so good idea at all.

from octo.

JohnEarnest avatar JohnEarnest commented on May 13, 2024

I just added a new preprocessor command, :calc, which I believe addresses this issue. See 5b8506e for details and documentation. :calc permits you to compute a constant based on existing constants or literals, so the above could be written as something like:

:const step 12
:const x 10
:calc  y { x + step }
va := x
vb := y

It's a bit more verbose than allowing expressions directly within arguments to Octo instructions, but allows you to express relationships between constants at compile time.

from octo.

whoozle avatar whoozle commented on May 13, 2024

Yes, this is definitely cleaner solution. Thanks a lot

from octo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.