org.millscript.millscript.vm
Class CompilerState

java.lang.Object
  extended by org.millscript.millscript.vm.CompilerState

public final class CompilerState
extends java.lang.Object

This class represents the compiler state during compilation from a given parser.


Constructor Summary
CompilerState(Engine e)
          Constructs a new CompilerState to compile and execute code in the specified engine.
 
Method Summary
 void changePackage(Package p)
          Changes the current package to the specified one.
 void compile(Parser parser)
          Compiles the next expression from the supplied parser.
 void compileAllowResults(Parser parser, boolean interactive)
          Compiles expressions from the supplied parser, allowing results to be returned by each compiled each expression.
 void compileConst(java.lang.String sym, Expr e)
          Compiles the specified expression as the value of a constant variable with the specified symbol.
 void compileConstant(java.lang.String sym, java.lang.Object obj)
          Compiles the specified object as a constant value and binds it to the specified symbol.
 void compileExpr(Expr e)
          Compiles the specified expression and executes it in the engine associated with this compiler state.
 Action compileExprToAction(Expr<?> e)
          Compiles the specified expression to it's action tree.
 java.lang.Object compileExprToValue(Expr<?> e)
          Compiles the specified expression, executes it in the engine associated with this compiler state and returns the last result the expression generates.
 void compileNoResults(Parser parser)
          Compiles expressions from the supplied parser, ensuring no results are returned after compiling each expression.
 GlobalIdent declareGlobal(java.lang.String sym)
          Declares the specified symbol as a global variable in the current package.
 void declareLocalsFrom(int prev)
          Declares all the expressions in scope as local variables, from the specified position in the scope stack to the top.
 GlobalIdent findIdent(java.lang.String nickname, java.lang.String sym)
          Finds the GlobalIdent for the specified symbol in the specified package.
 boolean getIsProtected(java.lang.String sym)
          Checks if the specified symbol is protected in the current package.
 java.util.Stack<Expr> getScopes()
          Returns the stack of scopes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompilerState

public CompilerState(Engine e)
Constructs a new CompilerState to compile and execute code in the specified engine.

Parameters:
e - the engine to compile and execute code in
Method Detail

changePackage

public void changePackage(Package p)
Changes the current package to the specified one.

Parameters:
p - the new current package

getIsProtected

public boolean getIsProtected(java.lang.String sym)
Checks if the specified symbol is protected in the current package.

Parameters:
sym - the symbol to test
Returns:
true if the symbol is protected in the current package, false otherwise

declareGlobal

public GlobalIdent declareGlobal(java.lang.String sym)
Declares the specified symbol as a global variable in the current package.

Parameters:
sym - the symbol to declare as a global
Returns:
the GlobalIdent for the symbol

findIdent

public GlobalIdent findIdent(java.lang.String nickname,
                             java.lang.String sym)
Finds the GlobalIdent for the specified symbol in the specified package.

Parameters:
nickname - the nickname of the package the symbol is in
sym - the symbol we want to find the Ident for
Returns:
the GlobalIdent for the symbol

getScopes

public java.util.Stack<Expr> getScopes()
Returns the stack of scopes.

Returns:
the Stack of scopes

declareLocalsFrom

public void declareLocalsFrom(int prev)
Declares all the expressions in scope as local variables, from the specified position in the scope stack to the top.

Parameters:
prev - the position in the scope stack to start declaring as local variables from

compileConstant

public void compileConstant(java.lang.String sym,
                            java.lang.Object obj)
Compiles the specified object as a constant value and binds it to the specified symbol.

Parameters:
sym - the symbol to define as a const
obj - the value to make a constant

compileConst

public void compileConst(java.lang.String sym,
                         Expr e)
Compiles the specified expression as the value of a constant variable with the specified symbol.

Parameters:
sym - the symbol to define as a const
e - the expression for the value of the const

compileExpr

public void compileExpr(Expr e)
Compiles the specified expression and executes it in the engine associated with this compiler state.

Parameters:
e - the expression to compile and execute

compileExprToAction

public Action compileExprToAction(Expr<?> e)
Compiles the specified expression to it's action tree.

Parameters:
e - the expression to compile
Returns:
the action tree for the specified expression

compileExprToValue

public java.lang.Object compileExprToValue(Expr<?> e)
Compiles the specified expression, executes it in the engine associated with this compiler state and returns the last result the expression generates.

Parameters:
e - the expression to compile and execute
Returns:
the last result returned after compiling and executing the specified expression

compile

public void compile(Parser parser)
Compiles the next expression from the supplied parser.

Parameters:
parser - the parser to compile an expression from.

compileNoResults

public void compileNoResults(Parser parser)
Compiles expressions from the supplied parser, ensuring no results are returned after compiling each expression.

Parameters:
parser - the Parser to read expressions from

compileAllowResults

public void compileAllowResults(Parser parser,
                                boolean interactive)
Compiles expressions from the supplied parser, allowing results to be returned by each compiled each expression.

Parameters:
parser - the Parser to read expressions from
interactive - indicates if this compilation is being done from an interactive mode


Copyright © 2001-2007 Open World Ltd. All Rights Reserved.