Interpreter

This is the main interface for the host application to interact with scripts. It can run scripts in interpreted mode by walking the syntax tree (deprecated), or if given the useVM option, can run a compiler to compile scripts into bytecode which is then executed by a VirtualMachine. Note that interpreted mode is deprecated.

class Interpreter : INodeVisitor {}

Constructors

this
this(bool useVM, bool printVMDebugInfo)

Constructs a new Interpreter with a global environment. Note that all calls to evaluate run in a new environment below the global environment. This allows keywords such as let and const to not pollute the global namespace. However, scripts can use var to declare variables that are global.

Members

Functions

callFunction
deprecated ScriptAny callFunction(ScriptFunction func, ScriptAny thisObj, ScriptAny[] args, bool useVM)

Calls a script function. Can throw ScriptRuntimeException.

evaluate
ScriptAny evaluate(string code, bool printDisasm)

This is the main entry point for evaluating a script program. If the useVM option was set in the constructor, bytecode compilation and execution will be used, otherwise tree walking.

evaluateFile
ScriptAny evaluateFile(string pathName, bool printDisasm)

Evaluates a file that can be either binary bytecode or textual source code.

forceSetGlobal
void forceSetGlobal(string name, T value, bool isConst)

Sets a global variable or constant without checking whether or not the variable or const was already declared. This is used by host applications to define custom functions or objects.

forceUnsetGlobal
void forceUnsetGlobal(string name)

Unsets a variable or constant in the global environment. Used by host applications to remove items that were loaded by the standard library load functions. Specific functions of script classes can be removed by modifying the "prototype" field of their constructor.

initializeStdlib
void initializeStdlib()

Initializes the Mildew standard library, such as Object, Math, and console namespaces. This is optional and is not called by the constructor. For a script to use these methods such as console.log this must be called first. It is also possible to only call specific initialize*Library functions and/or force set globals from them to UNDEFINED.

printVMDebugInfo
bool printVMDebugInfo()

whether or not debug info should be printed between each VM instruction

usingVM
bool usingVM()

whether or not VM option was set when created

visitArrayIndexNode
deprecated Variant visitArrayIndexNode(ArrayIndexNode ainode)

handle array index

visitArrayLiteralNode
deprecated Variant visitArrayLiteralNode(ArrayLiteralNode alnode)

return an array from an array literal node

visitBinaryOpNode
deprecated Variant visitBinaryOpNode(BinaryOpNode bonode)

processes binary operations including assignment

visitBlockStatementNode
deprecated Variant visitBlockStatementNode(BlockStatementNode bsnode)

handles {block} statement

visitBreakStatementNode
deprecated Variant visitBreakStatementNode(BreakStatementNode bsnode)

handle break statements

visitClassDeclarationStatementNode
deprecated Variant visitClassDeclarationStatementNode(ClassDeclarationStatementNode cdsnode)

handle class declaration

visitClassLiteralNode
deprecated Variant visitClassLiteralNode(ClassLiteralNode clnode)

handle class literals

visitContinueStatementNode
deprecated Variant visitContinueStatementNode(ContinueStatementNode csnode)

handle continue statements

visitDeleteStatementNode
deprecated Variant visitDeleteStatementNode(DeleteStatementNode dsnode)

handle delete statement

visitDoWhileStatementNode
deprecated Variant visitDoWhileStatementNode(DoWhileStatementNode dwsnode)

handles do-while statement

visitExpressionStatementNode
deprecated Variant visitExpressionStatementNode(ExpressionStatementNode esnode)

handle expression statements

visitForOfStatementNode
deprecated Variant visitForOfStatementNode(ForOfStatementNode fosnode)

handles for-of (and for-in) loops. TODO rewrite with iterators and implement string

visitForStatementNode
deprecated Variant visitForStatementNode(ForStatementNode fsnode)

handles for(;;) statements

visitFunctionCallNode
deprecated Variant visitFunctionCallNode(FunctionCallNode fcnode)

handles function calls

visitFunctionDeclarationStatementNode
deprecated Variant visitFunctionDeclarationStatementNode(FunctionDeclarationStatementNode fdsnode)

handle function declarations

visitFunctionLiteralNode
deprecated Variant visitFunctionLiteralNode(FunctionLiteralNode flnode)

handles function literals

visitIfStatementNode
deprecated Variant visitIfStatementNode(IfStatementNode isnode)

handles if statements

visitLambdaNode
deprecated Variant visitLambdaNode(LambdaNode lnode)

handle lambda

visitLiteralNode
deprecated Variant visitLiteralNode(LiteralNode lnode)

extract a VisitResult from a LiteralNode

visitMemberAccessNode
deprecated Variant visitMemberAccessNode(MemberAccessNode manode)

handle dot operator

visitNewExpressionNode
deprecated Variant visitNewExpressionNode(NewExpressionNode nenode)

handles new expression

visitObjectLiteralNode
deprecated Variant visitObjectLiteralNode(ObjectLiteralNode olnode)

generates object from object literal node

visitPostfixOpNode
deprecated Variant visitPostfixOpNode(PostfixOpNode ponode)

handle constructs such as i++ and i--

visitReturnStatementNode
deprecated Variant visitReturnStatementNode(ReturnStatementNode rsnode)

handles return statements

visitSuperNode
deprecated Variant visitSuperNode(SuperNode snode)

this should only be directly visited when used by itself

visitSwitchStatementNode
deprecated Variant visitSwitchStatementNode(SwitchStatementNode ssnode)

handles switch case statements

visitTemplateStringNode
deprecated Variant visitTemplateStringNode(TemplateStringNode tsnode)

handle template literal nodes

visitTerniaryOpNode
deprecated Variant visitTerniaryOpNode(TerniaryOpNode tonode)

handles : ? operator

visitThrowStatementNode
deprecated Variant visitThrowStatementNode(ThrowStatementNode tsnode)

handles throw statements

visitTryCatchBlockStatementNode
deprecated Variant visitTryCatchBlockStatementNode(TryCatchBlockStatementNode tcbsnode)

handle try catch block statements

visitUnaryOpNode
deprecated Variant visitUnaryOpNode(UnaryOpNode uonode)

returns a value from a unary operation

visitVarAccessNode
deprecated Variant visitVarAccessNode(VarAccessNode vanode)

handles variable access

visitVarDeclarationStatementNode
deprecated Variant visitVarDeclarationStatementNode(VarDeclarationStatementNode vdsnode)

handles var, let, and const declarations

visitWhileStatementNode
deprecated Variant visitWhileStatementNode(WhileStatementNode wsnode)

handles while statements

visitYieldNode
deprecated Variant visitYieldNode(YieldNode ynode)
Undocumented in source. Be warned that the author may not have intended to support it.
vm
VirtualMachine vm()

Virtual machine property, may be null

Structs

VisitResult
deprecated struct VisitResult

holds information from visiting nodes TODO redesign this as a union

Meta