You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"ìnvoke" is the actual instruction. It "becomes" ADD_I32 in the first case and "MUL_I32" int he second. So the preceding code returns 90. ( (10+20)*3 )
This could be useful to implement "eval" like functions in languages that support it. Or allow to compile to a form of "dynamic code".
As of now only instructions that don't need arguments can be called this way, and there seems to be an issue with the "JUMP_STUB" opcode (it tries to update the opcode in memory). So not all opcodes make sense invoking dynamically.
Anyways.
The text was updated successfully, but these errors were encountered:
This kind of an instruction is unfortunately not great for JIT compilation, because it makes it more difficult to generate efficient machine code. It would make dynamic execution less predictable.
But, worry not. We already have eval covered! The bytecode format is made of plain objects and arrays native to Zeta. If you create, in the plush language, objects that are "in the shape of a function", you can then call this as a normal function with the call opcode. You can dynamically generate new functions in memory. This is something that should already be possible with the parser in plush/parser.pls.
I had an idea that I've implemented (basically).
It is an opcode that uses the value from the top of stack as the opcode which is then executed.
Ex:
{ op: "push", val: 10 },
{ op: "push", val: 20 },
{ op: "push", val: 6 }, #ADD_I32 opcode
{ op: "invoke"},
{ op: "push", val: 3 },
{ op: "push", val: 8 }, #MUL_I32 opcode
{ op: "invoke"},
{ op: "ret"},
"ìnvoke" is the actual instruction. It "becomes" ADD_I32 in the first case and "MUL_I32" int he second. So the preceding code returns 90. ( (10+20)*3 )
This could be useful to implement "eval" like functions in languages that support it. Or allow to compile to a form of "dynamic code".
As of now only instructions that don't need arguments can be called this way, and there seems to be an issue with the "JUMP_STUB" opcode (it tries to update the opcode in memory). So not all opcodes make sense invoking dynamically.
Anyways.
The text was updated successfully, but these errors were encountered: