|
@@ -8,16 +8,40 @@ namespace MoonSharp.Interpreter.Execution.VM
|
|
|
|
|
|
|
|
public enum OpCode
|
|
public enum OpCode
|
|
|
{
|
|
{
|
|
|
|
|
+ // Meta-opcodes
|
|
|
Nop, // Does not perform any operation.
|
|
Nop, // Does not perform any operation.
|
|
|
Invalid, // Crashes the executor with an unrecoverable NotImplementedException.
|
|
Invalid, // Crashes the executor with an unrecoverable NotImplementedException.
|
|
|
|
|
+ Debug, // Does not perform any operation.
|
|
|
|
|
+
|
|
|
|
|
+ // Stack ops and assignment
|
|
|
Pop, // Discards the topmost n elements from the v-stack.
|
|
Pop, // Discards the topmost n elements from the v-stack.
|
|
|
Load, // Loads a value from the specified symbol, and pushes it on the v-stack.
|
|
Load, // Loads a value from the specified symbol, and pushes it on the v-stack.
|
|
|
- Call, // Calls the function specified on the specified element from the top of the v-stack. If the function is a Moon# function, it pushes its numeric value on the v-stack, then pushes the current PC onto the x-stack, enters the function closure and jumps to the function first instruction. If the function is a CLR function, it pops the function value from the v-stack, then invokes the function synchronously and finally pushes the result on the v-stack.
|
|
|
|
|
Literal, // Pushes a literal (constant value) on the stack.
|
|
Literal, // Pushes a literal (constant value) on the stack.
|
|
|
Symbol, // Loads a symbol on the stack
|
|
Symbol, // Loads a symbol on the stack
|
|
|
- MkTuple, // Creates a tuple from the topmost n values
|
|
|
|
|
|
|
+ SymStorN, // Performs a store to a symbol, without needing the symbol on the v-stack and without extracting the operand from the v-stack.
|
|
|
|
|
+ Store, // Performs a single value assignment [including table fields]
|
|
|
|
|
+ Assign, // Performs complex assignment supporting tuples [including table fields]
|
|
|
|
|
+ Reverse, // Reverses the last n elements of the stack
|
|
|
|
|
+ Closure, // Creates a closure on the top of the v-stack, using the symbols for upvalues and num-val for entry point of the function.
|
|
|
|
|
+
|
|
|
|
|
+ // Stack-frame ops and calls
|
|
|
|
|
+ Enter, // Enters a new stack frame
|
|
|
|
|
+ Leave, // Leaves a stack frame
|
|
|
|
|
+ Exit, // Leaves every stack frame up and including the topmost function frame, plus it exits the topmost closure
|
|
|
|
|
+ ExitClsr, // Exits a closure at runtime
|
|
|
|
|
+ Args, // Takes the arguments passed to a function and sets the appropriate symbols in the local scope
|
|
|
|
|
+ Call, // Calls the function specified on the specified element from the top of the v-stack. If the function is a Moon# function, it pushes its numeric value on the v-stack, then pushes the current PC onto the x-stack, enters the function closure and jumps to the function first instruction. If the function is a CLR function, it pops the function value from the v-stack, then invokes the function synchronously and finally pushes the result on the v-stack.
|
|
|
|
|
+ Ret, // Pops the top n values of the v-stack. Then pops an X value from the v-stack. Then pops X values from the v-stack. Afterwards, it pushes the top n values popped in the first step, pops the top of the x-stack and jumps to that location.
|
|
|
|
|
+
|
|
|
|
|
+ // Jumps
|
|
|
|
|
+ Jump, // Jumps to the specified PC
|
|
|
|
|
+ Jf, // Pops the top of the v-stack and jumps to the specified location if it's false
|
|
|
|
|
+ JNil, // Jumps if the top of the stack is nil
|
|
|
|
|
+ JFor, // Peeks at the top, top-1 and top-2 values of the v-stack which it assumes to be numbers. Then if top-1 is less than zero, checks if top is <= top-2, otherwise it checks that top is >= top-2. Then if the condition is false, it jumps.
|
|
|
JtOrPop, // Peeks at the topmost value of the v-stack as a boolean. If true, it performs a jump, otherwise it removes the topmost value from the v-stack.
|
|
JtOrPop, // Peeks at the topmost value of the v-stack as a boolean. If true, it performs a jump, otherwise it removes the topmost value from the v-stack.
|
|
|
JfOrPop, // Peeks at the topmost value of the v-stack as a boolean. If false, it performs a jump, otherwise it removes the topmost value from the v-stack.
|
|
JfOrPop, // Peeks at the topmost value of the v-stack as a boolean. If false, it performs a jump, otherwise it removes the topmost value from the v-stack.
|
|
|
|
|
+
|
|
|
|
|
+ // Operators
|
|
|
Concat, // Concatenation of the two topmost operands on the v-stack
|
|
Concat, // Concatenation of the two topmost operands on the v-stack
|
|
|
LessEq, // Compare <= of the two topmost operands on the v-stack
|
|
LessEq, // Compare <= of the two topmost operands on the v-stack
|
|
|
Less, // Compare < of the two topmost operands on the v-stack
|
|
Less, // Compare < of the two topmost operands on the v-stack
|
|
@@ -31,33 +55,29 @@ namespace MoonSharp.Interpreter.Execution.VM
|
|
|
Len, // Size operator of the topmost operand on the v-stack
|
|
Len, // Size operator of the topmost operand on the v-stack
|
|
|
Neg, // Negation (unary minus) operator of the topmost operand on the v-stack
|
|
Neg, // Negation (unary minus) operator of the topmost operand on the v-stack
|
|
|
Power, // Power of the two topmost operands on the v-stack
|
|
Power, // Power of the two topmost operands on the v-stack
|
|
|
- Bool, // Converts the top of the v-stack to a boolean
|
|
|
|
|
- Debug, // Does not perform any operation.
|
|
|
|
|
- Enter, // Enters a new stack frame
|
|
|
|
|
- Leave, // Leaves a stack frame
|
|
|
|
|
- Exit, // Leaves every stack frame up and including the topmost function frame, plus it exits the topmost closure
|
|
|
|
|
- Closure, // Creates a closure on the top of the v-stack, using the symbols for upvalues and num-val for entry point of the function.
|
|
|
|
|
- ExitClsr, // Exits a closure at runtime
|
|
|
|
|
- Args, // Takes the arguments passed to a function and sets the appropriate symbols in the local scope
|
|
|
|
|
- Jump, // Jumps to the specified PC
|
|
|
|
|
- Ret, // Pops the top n values of the v-stack. Then pops an X value from the v-stack. Then pops X values from the v-stack. Afterwards, it pushes the top n values popped in the first step, pops the top of the x-stack and jumps to that location.
|
|
|
|
|
- Jf, // Pops the top of the v-stack and jumps to the specified location if it's false
|
|
|
|
|
|
|
|
|
|
|
|
+ // Type conversions and manipulations
|
|
|
|
|
+ MkTuple, // Creates a tuple from the topmost n values
|
|
|
|
|
+ Bool, // Converts the top of the v-stack to a boolean
|
|
|
Incr, // Performs an add operation, without extracting the operands from the v-stack and assuming the operands are numbers.
|
|
Incr, // Performs an add operation, without extracting the operands from the v-stack and assuming the operands are numbers.
|
|
|
- JFor, // Peeks at the top, top-1 and top-2 values of the v-stack which it assumes to be numbers. Then if top-1 is less than zero, checks if top is <= top-2, otherwise it checks that top is >= top-2. Then if the condition is false, it jumps.
|
|
|
|
|
ToNum, // Converts the top of the stack to a number
|
|
ToNum, // Converts the top of the stack to a number
|
|
|
- NSymStor, // Performs a store to a symbol, without needing the symbol on the v-stack and without extracting the operand from the v-stack.
|
|
|
|
|
- Store, // Performs a single value assignment [including table fields]
|
|
|
|
|
- Assign, // Performs complex assignment supporting tuples [including table fields]
|
|
|
|
|
- IndexGet, // Performs an index operation, pushing the indexed value on the stack.
|
|
|
|
|
- IndexSet, // Performs an index operation, pushing a writable indexded value on the stack.
|
|
|
|
|
- IndexSetN, // Performs an index operation, pushing a writable indexed value on the stack, does not pop the table.
|
|
|
|
|
|
|
+ ExpTuple, // Expands a tuple on the stack
|
|
|
|
|
+
|
|
|
|
|
+ // Tables
|
|
|
|
|
+ Index, // Performs an index operation, pushing the indexed value on the stack.
|
|
|
|
|
+ IndexRef, // Performs an index operation, pushing a writable indexded value on the stack.
|
|
|
|
|
+ IndexRefN, // Performs an index operation, pushing a writable indexed value on the stack, does not pop the table.
|
|
|
NewTable, // Creates a new table on the stack
|
|
NewTable, // Creates a new table on the stack
|
|
|
|
|
|
|
|
|
|
+ // ScratchPad
|
|
|
TmpPeek, // Peeks the top of the stack in a temporary reg.
|
|
TmpPeek, // Peeks the top of the stack in a temporary reg.
|
|
|
TmpPush, // Pushes a temporary reg on the top of the stack.
|
|
TmpPush, // Pushes a temporary reg on the top of the stack.
|
|
|
TmpPop, // Pops the top of the stack in a temporary reg.
|
|
TmpPop, // Pops the top of the stack in a temporary reg.
|
|
|
TmpClear, // Clears a temporary reg
|
|
TmpClear, // Clears a temporary reg
|
|
|
|
|
|
|
|
|
|
+ // Iterators
|
|
|
|
|
+ IterPrep, // Prepares an interator for execution
|
|
|
|
|
+ IterUpd, // Updates the var part of an iterator
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|