Instruction Set - griderd/Jebnix GitHub Wiki
These are the instructions used with compiled KerboScript++. Unless you're getting down into the guts of the compiler, or are doing some heavy debugging, you don't need to worry about this.
Stack Instructions
- pushv - Pushes a local variable onto the data stack. Argument: Pointer
- pushg - Pushes a global variable onto the data stack. Argument: Pointer
- pushl - Pushes a literal onto the data stack. Argument: JObject
- popg - Pops a value off the data stack and assigns it to a global variable. Argument: Pointer
- popv - Pops a value off the data stack and assigns it to a local variable. Argument: Pointer
- pop - Pops a value off of the data stack. Does not get assigned. Argument: None
Arithmetic Instructions
- add - Pops the top two values off the data stack, adds them, and pushes the result. Argument: None
- sub - Pops the top two values off the data stack, subtracts the first from the second, and pushes the result. Argument: None
- mult - Pops the top two values off the data stack, multiplies them, and pushes the result. Argument: None
- div - Pops the top two values off the data stack, divides the second by the first, and pushes the result. Argument: None
- mod - Pops the top two values off the data stack, performs modulus on the second by the first, and pushes the result. Argument: None
- and - Pops the top two values off the data stack, performs bitwise or logical AND on them, and pushes the result. Argument: None
- or - Pops the top two values off the data stack, performs bitwise or logical OR on them, and pushes the result. Argument: None
- not - Pops the top value off the data stack, performs bitwise or logical NOT on it, and pushes the result. Argument: None
- pos - Pops the top value off the data stack, performs the positive operator on it, and pushes the result. Argument: None
- neg - Pops the top value off the data stack, peforms the negative operator on it, and pushes the result. Argument: None
- pow - Pops the top two values off the stack, calculates the second to the power of the first, and pushes the result. Argument: None
Branching Instructions
- jmp - Unconditional jump. Pushes the next instruction address onto the call stack and moves to the indicated location. Argument: Pointer
- jmpt - Conditional jump. Jumps only if the value at the top of the data stack is True. On jump, pushes the next instruction address onto the call stack and moves to the indicated location. Argument: Pointer
- jmpf - Conditional jump. Jumps only if the value at the top of the data stack is False. On jump, pushes the next instruction address onto the call stack and moves to the indicated location. Argument: Pointer
- hop - Unconditional hop. Moves immediately to the indicated location without leaving an address. Argument: Pointer
- hopt - Conditional hop. Hops only if the value at the top of the data stack is True. Moves immediately to the indicated location without leaving an address. Argument: Pointer
- hopf - Conditional hop. Hops only if the value at the top of the data stack is False. Moves immediately to the indicated location without leaving an address. Argument: Pointer
- ret - Returns to the location at the top of the call stack. Pops the address off the call stack. Argument: None
Function Calls
- call - Calls a function. This can be an external function (written in C#), an internal function (a function inside the script), or a script function (running another script as a function). The function to call is determined at runtime. Argument: FunctionPointer
- scr - Executes a script with the calling script as the parent. Local variables do not copy over unless passed as arguments. Global variables are always accessible. The data stack does copy over. Argument: JString
Memory Management
- lok - Adds a variable to the lock list. Variables on the lock list are refreshed each cycle. A variable cannot be locked twice. Remember to unlock your variable before you lock it again (this rule only applies to the assembly language. The compiler takes care of this for you in KerboScript). Argument: Pointer
- ulok - Removes a variable from the lock list. Argument: Pointer
Input/Output
- inp - Halt and wait for input. When the script resumes, the result of the input will be on the stack. Argument: None