VirtualMachine

This class implements a virtual machine that runs Chunks of bytecode. This class is not thread safe and a copy() of the VM should be instantiated to run scripts in multiple threads. The Environments are shallow copied and not guaranteed to be thread safe either.

Constructors

this
this(Environment globalEnv, bool printDisasm, bool printSteps)

ctor

Members

Functions

addFiber
ScriptObject addFiber(string name, ScriptFunction func, ScriptAny thisToUse, ScriptAny[] args)

Queue a fiber last.

addFiberFirst
ScriptObject addFiberFirst(string name, ScriptFunction func, ScriptAny thisToUse, ScriptAny[] args)

Add fiber to front.

copy
VirtualMachine copy(bool copyStack)

For coroutines (and in the future threads.)

hasException
bool hasException()

Whether or not there is an exception flag set

lastValuePopped
ScriptAny lastValuePopped()

Get the last value from opPop

printInstruction
void printInstruction(size_t ip, ubyte[] chunk)

prints an individual instruction without moving the ip

printProgram
void printProgram(Program program, bool printConstTable)

print a program instruction by instruction, using the const table to indicate values

printStack
void printStack()

print the current contents of the stack

removeFiber
bool removeFiber(ScriptFiber fiber)

Removes a ScriptFiber from the queue

runFibersToCompletion
void runFibersToCompletion()

Runs the queued fibers repeatedly until they are done. This is called by Interpreter.runVMFibers

runFunction
ScriptAny runFunction(ScriptFunction func, ScriptAny thisObj, ScriptAny[] args, ScriptAny[string] contextValues)

This method provides a common interface for calling any ScriptFunction under the same compilation unit as the initial program. It should not be used to run "foreign" functions with a different const table. Use runProgram for that. This method may throw ScriptRuntimeException. Such an exception is caught at opNew and opCall boundaries and propagated or caught by the script.

runProgram
ScriptAny runProgram(Program program, ScriptAny[] args)

Runs a compiled program

setException
void setException(ScriptRuntimeException ex)

Sets the exception flag of the VM. This is checked after each opCall for Generators

Meta