sisc.interpreter
Class Context

java.lang.Object
  extended by sisc.util.Util
      extended by sisc.interpreter.Context
All Implemented Interfaces:
Version

public abstract class Context
extends Util

Context is a utility class which facilitates Java to Scheme calls in SISC. Typically, this involves obtaining an Interpreter for a given initialized AppContext, using the Interpreter for one or more evaluations, then exiting the context, as follows:

   AppContext ctx = ...
   Interpreter r=Context.enter(ctx);
   r.eval(someProcedure, new Value[] { ... some arguments ... });
   Context.exit();
 
Preferrably, one should use the SchemeCaller supported visitor pattern to allow Context to handle the management of the Interpreter Context, as follows:
   Object returnValue=Context.execute(ctx, mySchemeCaller);
 
The provided SchemeCaller instance's execute method is invoked with an Interpreter which is automatically obtained and then returned when the call completes. The return value of the SchemeCaller's execute method is returned from the Context method.

See Also:
SchemeCaller, AppContext, Interpreter

Field Summary
 
Fields inherited from class sisc.util.Util
BACKQUOTE, BEGIN, bundles, caseSensitive, EMPTYLIST, EMPTYVEC, EOF, ERRORK, EVAL, EXPSC, EXPTOP, FALSE, FCONT, FIVE, JEXCEPTION, LAMBDA, LOCATION, maxFloatPrecision, MESSAGE, minFloatPrecision, NAME, OTHER, PARENT, permitInterrupts, QUOTE, QUOTESYM, REPORT, SETBANG, SISC, SISC_SPECIFIC, SISCB, SOURCE_COLUMN, SOURCE_FILE, SOURCE_LINE, SYMENV, THIS, TOPLEVEL, TRUE, UNQUOTE, UNQUOTE_SPLICING, VOID, ZV
 
Fields inherited from interface sisc.util.Version
VERSION
 
Constructor Summary
Context()
           
 
Method Summary
static AppContext currentAppContext()
          Returns the AppContext of any current interpreter in an internal call, or the default AppContext if no current interpreter is present.
static Interpreter currentInterpreter()
          Fetches the current Interpreter, if this is an internal call (that is, a call from Java to Scheme in the contex of a Scheme->Java call).
static Interpreter currentInterpreter(AppContext ctx)
          Fetches the nearest enclosing Interpreter that operates on a given AppContext, if this is an internal call (that is, a call from Java to Scheme in the contex of a Scheme->Java call).
static Interpreter enter()
          Returns an Interpreter that shares the AppContext and DynamicEnvironment with the current Interpreter.
static Interpreter enter(AppContext ctx)
          Returns an Interpreter bound to the given AppContext with same DynamicEnvironment as the nearest enclosing Interpreter in the same thread that is bound to the same AppContext.
static Interpreter enter(DynamicEnvironment dynenv)
          Returns an Interpreter bound to the given DynamicEnvironment.
static Interpreter enter(java.lang.String appName)
          Deprecated. use enter(AppContext) instead
static java.lang.Object execute(AppContext ctx, SchemeCaller caller)
          Calls caller with an Interpreter bound to the given AppContext with same DynamicEnvironment as the nearest enclosing Interpreter in the same thread that is bound to the same AppContext.
static java.lang.Object execute(DynamicEnvironment dynenv, SchemeCaller caller)
          Obtains an Interpreter bound to the given DynamicEnvironment and invokes caller.execute(Interpreter) with that Interper.
static java.lang.Object execute(SchemeCaller caller)
          Calls caller with an Interpreter that shares the AppContext and DynamicEnvironment with the current Interpreter.
static java.lang.Object execute(java.lang.String appName, SchemeCaller caller)
          Deprecated. use execute(AppContext, SchemeCaller) instead
static void exit()
          Exits the current context, releasing the current Interpreter.
static AppContext getDefaultAppContext()
          Returns the currently set default AppContext, or creates a new AppContext with default values if non was already set, and attempts to initialize it with the default heap.
static AppContext lookup(java.lang.String appName)
          Deprecated.  
static ThreadContext lookupThreadContext()
          thread context lookup
static void register(java.lang.String appName, AppContext ctx)
          Deprecated.  
static void setDefaultAppContext(AppContext ctx)
          Sets the default AppContext, which is used sparingly whenever a call originates from uncontrolled Java source that involves the Scheme environment.
static void unregister(java.lang.String appName)
          Deprecated.  
 
Methods inherited from class sisc.util.Util
annotated, annotatedAppEval, append, argCheck, argsToSymbols, assq, bininport, bininstream, binoutport, binoutstream, box, character, charinport, charinreader, charoutport, charoutwriter, charsetFromString, chr, cont, currentClassLoader, env, error, error, error, error, error, error, error, expr, getDefaultCharacterSet, immutablePair, immutableVector, inport, javaExceptionToString, javaWrap, justify, length, liMessage, liMessage, liMessage, liMessage, liMessage, liMessage, liMessage, list, list, list, list, list, makeURL, mapcar, memq, nlib, num, outport, pair, pairToExpressions, pairToExpVect, pairToValues, proc, read, registerBundle, reverse, reverseInPlace, simpleErrorToString, sourceAnnotations, str, string, sym, symbol, symval, truePair, truth, truth, typeError, typeError, updateName, url, url, url, valArrayToList, valArrayToList, valArrayToVec, vec, warn, warn, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Context

public Context()
Method Detail

register

public static void register(java.lang.String appName,
                            AppContext ctx)
Deprecated. 


unregister

public static void unregister(java.lang.String appName)
Deprecated. 


lookup

public static AppContext lookup(java.lang.String appName)
Deprecated. 


lookupThreadContext

public static ThreadContext lookupThreadContext()
thread context lookup


currentInterpreter

public static Interpreter currentInterpreter()
Fetches the current Interpreter, if this is an internal call (that is, a call from Java to Scheme in the contex of a Scheme->Java call).

Returns:
the current Interpreter, or null if this is not an internal call.

currentInterpreter

public static Interpreter currentInterpreter(AppContext ctx)
Fetches the nearest enclosing Interpreter that operates on a given AppContext, if this is an internal call (that is, a call from Java to Scheme in the contex of a Scheme->Java call).

Parameters:
ctx - the AppContext
Returns:
the nearest enclosing Interpreter operating on the given ctx, or null if no such Interpreter exists.

setDefaultAppContext

public static void setDefaultAppContext(AppContext ctx)
Sets the default AppContext, which is used sparingly whenever a call originates from uncontrolled Java source that involves the Scheme environment. For example, Java serialization initiated by a web application server.

Parameters:
ctx - the AppContext to make the default.

getDefaultAppContext

public static AppContext getDefaultAppContext()
Returns the currently set default AppContext, or creates a new AppContext with default values if non was already set, and attempts to initialize it with the default heap.


currentAppContext

public static AppContext currentAppContext()
Returns the AppContext of any current interpreter in an internal call, or the default AppContext if no current interpreter is present.


enter

public static Interpreter enter()
Returns an Interpreter that shares the AppContext and DynamicEnvironment with the current Interpreter. If there is no current Interpreter present, an Interpreter bound to the default AppContext is returned instead. This method provides the usual mechanism for obtaining an Interpreter for calling from Java to Scheme.

See Also:
Interpreter

enter

public static Interpreter enter(AppContext ctx)
Returns an Interpreter bound to the given AppContext with same DynamicEnvironment as the nearest enclosing Interpreter in the same thread that is bound to the same AppContext. If no such Interpreter exists then a new DynamicEnvironment is created, bound to the AppContext.

Parameters:
ctx - The AppContext
Returns:
The newly created Interpreter

enter

public static Interpreter enter(DynamicEnvironment dynenv)
Returns an Interpreter bound to the given DynamicEnvironment.

Parameters:
dynenv - The DynamicEnvironment
Returns:
The newly created Interpreter

enter

public static Interpreter enter(java.lang.String appName)
Deprecated. use enter(AppContext) instead


exit

public static void exit()
Exits the current context, releasing the current Interpreter.


execute

public static java.lang.Object execute(SchemeCaller caller)
                                throws SchemeException
Calls caller with an Interpreter that shares the AppContext and DynamicEnvironment with the current Interpreter. If there is no current Interpreter present, an Interpreter bound to the default AppContext is created instead. This method provides the usual mechanism for managed calls from Java to Scheme.

Parameters:
caller - The SchemeCaller to invoke
Returns:
the result of invoking the SchemeCaller
Throws:
SchemeException

execute

public static java.lang.Object execute(AppContext ctx,
                                       SchemeCaller caller)
                                throws SchemeException
Calls caller with an Interpreter bound to the given AppContext with same DynamicEnvironment as the nearest enclosing Interpreter in the same thread that is bound to the same AppContext. If no such Interpreter exists then a new DynamicEnvironment is returned, bound to the AppContext.

Parameters:
ctx - The AppContext
caller - The SchemeCaller to invoke.
Returns:
the result of invoking the SchemeCaller
Throws:
SchemeException

execute

public static java.lang.Object execute(DynamicEnvironment dynenv,
                                       SchemeCaller caller)
                                throws SchemeException
Obtains an Interpreter bound to the given DynamicEnvironment and invokes caller.execute(Interpreter) with that Interper. Once execute returns, the Interpreter is freed, and the return value of caller.execute() is returned from this method. NB: It is critical that the Interpreter reference provided during the call is used only in the thread which calls this method. New threads should obtain a different Interpreter via this or enter() calls.

Parameters:
dynenv - The DynamicEnvironment.
caller - The SchemeCaller to invoke.
Returns:
the result of invoking the SchemeCaller
Throws:
SchemeException

execute

public static java.lang.Object execute(java.lang.String appName,
                                       SchemeCaller caller)
Deprecated. use execute(AppContext, SchemeCaller) instead