oscript.compiler
Class CompiledNodeEvaluator

java.lang.Object
  extended byoscript.NodeEvaluator
      extended byoscript.compiler.CompiledNodeEvaluator

public abstract class CompiledNodeEvaluator
extends NodeEvaluator

This is the base class for all compiled script functions. I could have used an interface, but there was no need for a compiled script function object to subclass any other object.

A compiled function does not store the scope the script function was defined in, but simply a compiled version of the function's syntaxtree. This means that once a function is compiled for one scope, it does not need to be recompiled for a different scope.

Version:
1.19
Author:
Rob Clark (rob@ti.com)

Field Summary
 
Fields inherited from class oscript.NodeEvaluator
ALL, PRIVATE, PUBPROT, SMIT_PERMS
 
Constructor Summary
protected CompiledNodeEvaluator(java.lang.String name, java.lang.String desc)
          Class Constructor.
 
Method Summary
protected static Value evalHelper(java.lang.String str, Scope scope)
          A helper function for evaluating an EvalBlock.
abstract  java.lang.Object evalInnerNode(int idx, StackFrame sf, Scope scope)
          Evaluate, in the specified scope.
 java.lang.Object evalNode(StackFrame sf, Scope scope)
          Evaluate, in the specified scope.
 AbstractFile getFile()
          Get the file that this node was parsed from.
 int getId()
          Get the function symbol (name), if this node evaluator is a function, otherwise return -1.
abstract  SymbolTable getInnerSharedMemberIndexTable(int idx, int perm)
          Get the SMIT for the scope(s) created when invoking this node evaluator.
 SymbolTable getSharedMemberIndexTable(int perm)
          Get the SMIT for the scope(s) created when invoking this node evaluator.
protected static Value importHelper(java.lang.String str, Scope scope)
          A helper function for evaluating an ImportBlock.
static Value returnHelper(Value val)
          A helper function for evaluating an ReturnStatement or ThrowBlock, to ensure that the value being returned/thrown is not (undefined).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompiledNodeEvaluator

protected CompiledNodeEvaluator(java.lang.String name,
                                java.lang.String desc)
Class Constructor.

Parameters:
name - the name of this function
desc - the description of input source (ie. filename)
Method Detail

getFile

public AbstractFile getFile()
Get the file that this node was parsed from.

Specified by:
getFile in class NodeEvaluator
Returns:
the file

getId

public int getId()
Get the function symbol (name), if this node evaluator is a function, otherwise return -1.

Specified by:
getId in class NodeEvaluator
Returns:
the symbol, or -1

evalNode

public java.lang.Object evalNode(StackFrame sf,
                                 Scope scope)
                          throws PackagedScriptObjectException
Evaluate, in the specified scope. If this is a function, the Arguments to the function, etc., are defined in the scope that the function is evaluated in.

Specified by:
evalNode in class NodeEvaluator
Parameters:
sf - the stack frame to evaluate the node in
scope - the scope to evaluate the function in
Returns:
the result of evaluating the function
Throws:
PackagedScriptObjectException

evalInnerNode

public abstract java.lang.Object evalInnerNode(int idx,
                                               StackFrame sf,
                                               Scope scope)
                                        throws PackagedScriptObjectException
Evaluate, in the specified scope. If this is a function, the Arguments to the function, etc., are defined in the scope that the function is evaluated in.

Parameters:
sf - the stack frame to evaluate the node in
scope - the scope to evaluate the function in
Returns:
the result of evaluating the function
Throws:
PackagedScriptObjectException

getSharedMemberIndexTable

public SymbolTable getSharedMemberIndexTable(int perm)
Get the SMIT for the scope(s) created when invoking this node evaluator.

Specified by:
getSharedMemberIndexTable in class NodeEvaluator
Parameters:
perm - PRIVATE, PUBPROT, ALL

getInnerSharedMemberIndexTable

public abstract SymbolTable getInnerSharedMemberIndexTable(int idx,
                                                           int perm)
Get the SMIT for the scope(s) created when invoking this node evaluator.


evalHelper

protected static final Value evalHelper(java.lang.String str,
                                        Scope scope)
A helper function for evaluating an EvalBlock.

Parameters:
str - the string to evaluate
scope - the scope to evaluate in
Returns:
the result

importHelper

protected static final Value importHelper(java.lang.String str,
                                          Scope scope)
A helper function for evaluating an ImportBlock.

Parameters:
str - the string identifying what to import
scope - the scope to evaluate in
Returns:
the result

returnHelper

public static final Value returnHelper(Value val)
A helper function for evaluating an ReturnStatement or ThrowBlock, to ensure that the value being returned/thrown is not (undefined).