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)

ctor

Members

Functions

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

Queue a fiber. TODO rewrite to accept a ScriptFiber

copy
VirtualMachine copy(bool copyStack)

For coroutines and threads.

lastValuePopped
ScriptAny lastValuePopped()

Get the last value from opPop

printChunk
void printChunk(Chunk chunk, bool printConstTable)

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

printInstruction
void printInstruction(size_t ip, Chunk chunk)

prints an individual instruction without moving the ip

printStack
void printStack()

print the current contents of the stack

removeFiber
bool removeFiber(ScriptFiber fiber)

Removes a ScriptFiber from the queue

run
ScriptAny run(Chunk chunk, bool printDebugInfo, bool retCS)

run a chunk of bytecode with a given const table

runFunction
ScriptAny runFunction(ScriptFunction func, ScriptAny thisObj, ScriptAny[] args, ScriptAny yieldFunc)

For calling script functions with call or apply. Ugly hackish function that needs to be reworked.

runQueue
void runQueue()

Runs the asyncs queued up. This is called by Interpreter.runVMFibers

Meta