Compiler

Implements a bytecode compiler that can be used by mildew.vm.virtualmachine. This class is not thread safe and each thread must use its own Compiler instance. Only one program can be compiled at a time.

class Compiler : INodeVisitor {}

Members

Classes

UnimplementedException
class UnimplementedException

thrown when a feature is missing

Functions

compile
Program compile(string source, string name)

compile code into chunk usable by vm

compile
Program compile(StatementNode[] statements)

This is strictly for use by the Parser to evaluate case expressions and such.

visitArrayIndexNode
Variant visitArrayIndexNode(ArrayIndexNode ainode)

handle [] operator. This method cannot be used in assignment

visitArrayLiteralNode
Variant visitArrayLiteralNode(ArrayLiteralNode alnode)

handle array literals

visitBinaryOpNode
Variant visitBinaryOpNode(BinaryOpNode bonode)

handles binary operations

visitBlockStatementNode
Variant visitBlockStatementNode(BlockStatementNode bsnode)

handle {} braces

visitBreakStatementNode
Variant visitBreakStatementNode(BreakStatementNode bsnode)

visit break statements

visitClassDeclarationStatementNode
Variant visitClassDeclarationStatementNode(ClassDeclarationStatementNode cdsnode)

Class declarations. Reduce to let leftHand = classExpression

visitClassLiteralNode
Variant visitClassLiteralNode(ClassLiteralNode clnode)

Class literals. Parser is supposed to make sure string-function pairs match up

visitContinueStatementNode
Variant visitContinueStatementNode(ContinueStatementNode csnode)

visit continue statements

visitDeleteStatementNode
Variant visitDeleteStatementNode(DeleteStatementNode dsnode)

delete statement. can be used on ArrayIndexNode or MemberAccessNode

visitDoWhileStatementNode
Variant visitDoWhileStatementNode(DoWhileStatementNode dwsnode)

do-while loops

visitExpressionStatementNode
Variant visitExpressionStatementNode(ExpressionStatementNode esnode)

handle expression statements

visitForOfStatementNode
Variant visitForOfStatementNode(ForOfStatementNode fosnode)

Visit for-of statements

visitForStatementNode
Variant visitForStatementNode(ForStatementNode fsnode)

handle regular for loops

visitFunctionCallNode
Variant visitFunctionCallNode(FunctionCallNode fcnode)

Handle function() calls

visitFunctionDeclarationStatementNode
Variant visitFunctionDeclarationStatementNode(FunctionDeclarationStatementNode fdsnode)

function declarations

visitFunctionLiteralNode
Variant visitFunctionLiteralNode(FunctionLiteralNode flnode)

handle function literals. The VM should create new functions with the appropriate context when a function is loaded from the const table

visitIfStatementNode
Variant visitIfStatementNode(IfStatementNode isnode)

emit if statements

visitLambdaNode
Variant visitLambdaNode(LambdaNode lnode)

handle lambdas

visitLiteralNode
Variant visitLiteralNode(LiteralNode lnode)

handle literal value node (easiest)

visitMemberAccessNode
Variant visitMemberAccessNode(MemberAccessNode manode)

handle . operator. This method cannot be used in assignment

visitNewExpressionNode
Variant visitNewExpressionNode(NewExpressionNode nenode)

handle new operator. visitFunctionCallExpression will handle returnThis field

visitObjectLiteralNode
Variant visitObjectLiteralNode(ObjectLiteralNode olnode)

handle object literal nodes

visitPostfixOpNode
Variant visitPostfixOpNode(PostfixOpNode ponode)

Handle x++ and x--

visitReturnStatementNode
Variant visitReturnStatementNode(ReturnStatementNode rsnode)

Return statements

visitSuperNode
Variant visitSuperNode(SuperNode snode)

this should only be directly visited when used by itself

visitSwitchStatementNode
Variant visitSwitchStatementNode(SwitchStatementNode ssnode)

Switch statements

visitTemplateStringNode
Variant visitTemplateStringNode(TemplateStringNode tsnode)

handles template strings

visitTerniaryOpNode
Variant visitTerniaryOpNode(TerniaryOpNode tonode)

handle :? operator

visitThrowStatementNode
Variant visitThrowStatementNode(ThrowStatementNode tsnode)

Throw statement

visitTryCatchBlockStatementNode
Variant visitTryCatchBlockStatementNode(TryCatchBlockStatementNode tcbsnode)

Try catch

visitUnaryOpNode
Variant visitUnaryOpNode(UnaryOpNode uonode)

handle unary operations

visitVarAccessNode
Variant visitVarAccessNode(VarAccessNode vanode)

These should not be directly visited for assignment

visitVarDeclarationStatementNode
Variant visitVarDeclarationStatementNode(VarDeclarationStatementNode vdsnode)

Handle var declaration

visitWhileStatementNode
Variant visitWhileStatementNode(WhileStatementNode wsnode)

Handle while loops

visitYieldNode
Variant visitYieldNode(YieldNode ynode)

handle yield statements.

Meta