edu.vub.at.eval
Class Evaluator

java.lang.Object
  extended byedu.vub.at.eval.Evaluator

public final class Evaluator
extends java.lang.Object

The Evaluator class serves as a repository for auxiliary evaluation methods.

Author:
tvc

Nested Class Summary
private static interface Evaluator.BindClosure
           
 
Field Summary
static NATTable _ANON_MTH_ARGS_
           
static AGSymbol _ANON_MTH_NAM_
           
static AGSymbol _APPLY_
           
static AGSymbol _CURNS_SYM_
           
private static java.lang.ThreadLocal _GLOBAL_SCOPE_
          A thread-local variable is used to assign a unique global scope to each separate actor.
static AGSymbol _INIT_
           
private static java.lang.ThreadLocal _JLOBBY_ROOT_
          A thread-local variable is used to assign a unique jlobby root to each separate actor.
static AGSymbol _LAMBDA_
           
private static java.lang.ThreadLocal _LOBBY_NAMESPACE_
          A thread-local variable is used to assign a unique lobby namespace to each separate actor.
 
Constructor Summary
Evaluator()
           
 
Method Summary
static void assignArgsToParams(java.lang.String funnam, ATContext context, ATTable parameters, ATTable arguments)
          Deprecated. use partial evalation using PartialBinder.bind(ATObject[], ATContext, edu.vub.at.eval.PartialBinder.BindClosure) instead.
private static void bindArguments(java.lang.String funnam, ATContext context, ATTable parameters, ATTable arguments, Evaluator.BindClosure binder)
          Deprecated. use partial evalation using PartialBinder.bind(ATObject[], ATContext, edu.vub.at.eval.PartialBinder.BindClosure) instead.
private static java.lang.String classnameToValuename(java.lang.String classname, java.lang.String prefix)
           
private static NATObject createGlobalLexicalScope()
          A global scope has the sentinel instance as its lexical parent.
private static NATObject createJLobbyRoot()
          A jlobby root package is a JavaPackage with an empty path prefix
private static NATObject createLobbyNamespace()
          A lobby namespace is a simple empty object
static void defineParamsForArgs(java.lang.String funnam, ATContext context, ATTable parameters, ATTable arguments)
          Deprecated. use partial evalation using PartialBinder.bind(ATObject[], ATContext, edu.vub.at.eval.PartialBinder.BindClosure) instead.
static NATTable evalMandatoryPars(ATTable formals, ATContext ctx)
          Given a formal parameter list, this auxiliary method returns a new table consisting of the values of the bindings of the mandatory parameters of formals within the context ctx.
static NATTable evaluateArguments(NATTable args, ATContext ctx)
          This function is called whenever arguments to a function, message, method need to be evaluated.
static NATObject getGlobalLexicalScope()
           
static JavaPackage getJLobbyRoot()
           
static NATObject getLobbyNamespace()
           
static java.lang.String getSimpleName(java.lang.Class c)
          Returns the unqualified name of a class.
static java.lang.String loadContentOfFile(java.io.File file)
          Returns the raw contents of a file in a String (using this JVM's default character encoding)
static NATText printAsList(ATTable tab)
           
static NATText printAsStatements(ATTable tab)
           
static NATText printElements(ATObject[] els, java.lang.String start, java.lang.String sep, java.lang.String stop)
          Auxiliary function used to print the elements of a table using various separators.
static NATText printElements(NATTable tab, java.lang.String start, java.lang.String sep, java.lang.String stop)
          Auxiliary function used to print the elements of a table using various separators.
static void resetEnvironment()
          Restores the global lexical scope to a fresh empty object.
static java.lang.String toString(ATObject obj)
           
static java.lang.String valueNameOf(java.lang.Class c)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_ANON_MTH_NAM_

public static final AGSymbol _ANON_MTH_NAM_

_ANON_MTH_ARGS_

public static final NATTable _ANON_MTH_ARGS_

_LAMBDA_

public static final AGSymbol _LAMBDA_

_APPLY_

public static final AGSymbol _APPLY_

_INIT_

public static final AGSymbol _INIT_

_CURNS_SYM_

public static final AGSymbol _CURNS_SYM_

_GLOBAL_SCOPE_

private static final java.lang.ThreadLocal _GLOBAL_SCOPE_
A thread-local variable is used to assign a unique global scope to each separate actor. Each actor that invokes the getGlobalLexicalScope method receives its own separate copy of the global scope


_LOBBY_NAMESPACE_

private static final java.lang.ThreadLocal _LOBBY_NAMESPACE_
A thread-local variable is used to assign a unique lobby namespace to each separate actor. Each actor that invokes the getLobby() method receives its own separate copy of the lobby namespace


_JLOBBY_ROOT_

private static final java.lang.ThreadLocal _JLOBBY_ROOT_
A thread-local variable is used to assign a unique jlobby root to each separate actor. The jlobby root is the root JavaPackage from which other Java packages can be loaded. Each actor that invokes the getJLobbyRoot() method receives its own separate copy of the jlobby root

Constructor Detail

Evaluator

public Evaluator()
Method Detail

printElements

public static final NATText printElements(ATObject[] els,
                                          java.lang.String start,
                                          java.lang.String sep,
                                          java.lang.String stop)
                                   throws InterpreterException
Auxiliary function used to print the elements of a table using various separators.

Throws:
InterpreterException

printElements

public static final NATText printElements(NATTable tab,
                                          java.lang.String start,
                                          java.lang.String sep,
                                          java.lang.String stop)
                                   throws InterpreterException
Auxiliary function used to print the elements of a table using various separators.

Throws:
InterpreterException

printAsStatements

public static final NATText printAsStatements(ATTable tab)
                                       throws InterpreterException
Throws:
InterpreterException

printAsList

public static final NATText printAsList(ATTable tab)
                                 throws InterpreterException
Throws:
InterpreterException

evaluateArguments

public static final NATTable evaluateArguments(NATTable args,
                                               ATContext ctx)
                                        throws InterpreterException
This function is called whenever arguments to a function, message, method need to be evaluated. TODO(coercers) currently does not work for user-defined tables

Throws:
InterpreterException

bindArguments

private static final void bindArguments(java.lang.String funnam,
                                        ATContext context,
                                        ATTable parameters,
                                        ATTable arguments,
                                        Evaluator.BindClosure binder)
                                 throws InterpreterException
Deprecated. use partial evalation using PartialBinder.bind(ATObject[], ATContext, edu.vub.at.eval.PartialBinder.BindClosure) instead.

Auxiliary function to bind formal parameters to actual arguments within a certain scope. A formal parameter list is defined as: (mandatory arg: ATSymbol)* , (optional arg: ATVarAssignment)*, (rest arg: ATSplice)? An actual argument list is defined as: (actual arg: ATObject)*

Parameters:
funnam - the name of the function for which to bind these elements, for debugging purposes only
context - the context whose lexical scope denotes the frame in which to store the bindings The context is also the context in which to evaluate optional argument expressions.
parameters - the formal parameter references (of which the last element may be a 'rest' arg to collect left-over arguments)
arguments - the actual arguments, already evaluated
binder - a functor object describing the strategy to bind an argument to a parameter (assign or define the parameter)
Throws:
XArityMismatch - when the formals don't match the actuals
InterpreterException

defineParamsForArgs

public static final void defineParamsForArgs(java.lang.String funnam,
                                             ATContext context,
                                             ATTable parameters,
                                             ATTable arguments)
                                      throws InterpreterException
Deprecated. use partial evalation using PartialBinder.bind(ATObject[], ATContext, edu.vub.at.eval.PartialBinder.BindClosure) instead.

Bind all of the given parameters as newly defined slots in the given scope to the given arguments. The scope is defined as the lexical scope of the given context.

Throws:
InterpreterException

assignArgsToParams

public static final void assignArgsToParams(java.lang.String funnam,
                                            ATContext context,
                                            ATTable parameters,
                                            ATTable arguments)
                                     throws InterpreterException
Deprecated. use partial evalation using PartialBinder.bind(ATObject[], ATContext, edu.vub.at.eval.PartialBinder.BindClosure) instead.

Assign all of the formal parameter names in the scope object to the given arguments The scope is defined as the lexical scope of the given context.

Throws:
InterpreterException

evalMandatoryPars

public static NATTable evalMandatoryPars(ATTable formals,
                                         ATContext ctx)
                                  throws InterpreterException
Given a formal parameter list, this auxiliary method returns a new table consisting of the values of the bindings of the mandatory parameters of formals within the context ctx.

Throws:
InterpreterException

loadContentOfFile

public static java.lang.String loadContentOfFile(java.io.File file)
                                          throws java.io.IOException
Returns the raw contents of a file in a String (using this JVM's default character encoding)

Throws:
java.io.IOException

getGlobalLexicalScope

public static NATObject getGlobalLexicalScope()
Returns:
the 'global' lexical scope of an actor, which is a normal native object whose lexical parent is OBJLexicalRoot.

getLobbyNamespace

public static NATObject getLobbyNamespace()
Returns:
the lobby namespace of an actor, which is a normal empty object

getJLobbyRoot

public static JavaPackage getJLobbyRoot()
Returns:
the jlobby root package of an actor, which is a JavaPackage with an empty path prefix.

resetEnvironment

public static void resetEnvironment()
Restores the global lexical scope to a fresh empty object. Resets the lobby global namespace.


createGlobalLexicalScope

private static NATObject createGlobalLexicalScope()
A global scope has the sentinel instance as its lexical parent.


createLobbyNamespace

private static NATObject createLobbyNamespace()
A lobby namespace is a simple empty object


createJLobbyRoot

private static NATObject createJLobbyRoot()
A jlobby root package is a JavaPackage with an empty path prefix


valueNameOf

public static final java.lang.String valueNameOf(java.lang.Class c)

toString

public static final java.lang.String toString(ATObject obj)

classnameToValuename

private static final java.lang.String classnameToValuename(java.lang.String classname,
                                                           java.lang.String prefix)

getSimpleName

public static final java.lang.String getSimpleName(java.lang.Class c)
Returns the unqualified name of a class.