sisc.interpreter
Class Interpreter

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

public class Interpreter
extends Util

The SISC engine.

Interpreter is the SISC engine. It contains the engine registers, and the main loop responsible for repeatedly executing the nxp register and maintaining the stack. Interpreter also localizes all thread-specific information. Interpreters must only execute in the thread which created them. Furthermore, nested calls from Java into Scheme must be carried out in fresh interpreter instances; thus at any point in time a thread contains a stack of interpreters, the top of which is the interpreter currently in use.

Additionally, it is the interface from Java code for evaluating Scheme code or calling Scheme procedures.

See Also:
Context

Nested Class Summary
static class Interpreter.ThrowSchemeException
           
 
Field Summary
 Value acc
           
static Compiler compiler
           
protected  Value[] dv1
           
protected  Value[] dv2
           
protected  Value[] dv3
           
protected  Value[] dv4
           
 DynamicEnvironment dynenv
           
 Value[] env
           
 CallFrame fk
           
protected  CallFrame frameFreeList
           
protected  int frameFreeListSize
           
protected static int FRAMEPOOLMAX
           
 Value[][] IAI
           
 Value[] lcl
           
 Expression nxp
           
 ThreadContext tctx
           
 SymbolicEnvironment tpl
           
 Value[] vlr
           
 
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
Interpreter(ThreadContext tctx, DynamicEnvironment dynenv)
           
 
Method Summary
 Procedure captureContinuation()
           
 Procedure captureEscapingContinuation()
           
 Expression compile(Value v)
           
 Expression compile(Value v, SymbolicEnvironment env)
           
 Value[] createValues(int size)
           
 void define(Symbol s, Value v, Symbol context)
          Defines a new binding in a named environment.
 void defineContextEnv(Symbol s, SymbolicEnvironment env)
           
 void error(Pair error)
           
 Value eval(Procedure p, Value[] args)
          Applies the given procedure to the given values
 Value eval(java.lang.String expr)
          Parses and evaluates s-expression(s)
 Value eval(Value v)
          Evaluates a Scheme value as code.
 Value eval(Value v, SymbolicEnvironment env)
          Evaluates a Scheme value as code.
 Value evalInput(java.io.PushbackReader port)
          Parses and evaluates s-expression(s) from an input port
 SymbolicEnvironment getContextEnv(Symbol s)
           
 AppContext getCtx()
           
 Symbol getSymbol(java.lang.String v)
           
protected  void interpret()
           
 Value interpret(Expression e)
           
 boolean loadSourceFiles(java.lang.String[] files)
          Loads zero or more Scheme source files or compiled libraries.
 Expression lookup(Symbol s, Symbol context)
          Retrieves the value of a binding in a named environment
 SymbolicEnvironment lookupContextEnv(Symbol s)
           
 StackTracer makeStackTracer()
           
 void newVLR(int size)
           
 void newVLR(Value[] vlr)
           
 void next(Expression nextExpr)
           
 void pop(CallFrame c)
           
 void push(Expression n)
           
 void pushExpr(Expression e)
           
 void returnFrame(CallFrame f)
           
 void returnValues(Value[] v)
           
 void returnVLR()
           
 void setFailureContinuation(Expression e)
           
 void setupTailCall(Expression e, Value vlr0)
           
 void setupTailCall(Expression e, Value[] newvlr)
           
 void setVLR(int pos, Value v)
           
 void trace(Expression e)
           
 void undefine(Symbol s, Symbol context)
          Removes a binding in a named environment
 Value[] vlrToArgs()
          Returns a Value[] prepared as a value rib for a procedure with a fixed argument count.
 Value[] vlrToRestArgs(int fcount)
          Returns a Value[] prepared as a value rib for a for procedure expecting rest args in the last rib position.
 
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
 

Field Detail

compiler

public static Compiler compiler

tctx

public ThreadContext tctx

dynenv

public DynamicEnvironment dynenv

IAI

public Value[][] IAI

acc

public Value acc

nxp

public Expression nxp

vlr

public Value[] vlr

lcl

public Value[] lcl

env

public Value[] env

fk

public CallFrame fk

tpl

public SymbolicEnvironment tpl

FRAMEPOOLMAX

protected static final int FRAMEPOOLMAX
See Also:
Constant Field Values

frameFreeList

protected CallFrame frameFreeList

frameFreeListSize

protected int frameFreeListSize

dv1

protected Value[] dv1

dv2

protected Value[] dv2

dv3

protected Value[] dv3

dv4

protected Value[] dv4
Constructor Detail

Interpreter

public Interpreter(ThreadContext tctx,
                   DynamicEnvironment dynenv)
Method Detail

getCtx

public AppContext getCtx()

getSymbol

public Symbol getSymbol(java.lang.String v)

compile

public Expression compile(Value v)
                   throws ContinuationException
Throws:
ContinuationException

compile

public Expression compile(Value v,
                          SymbolicEnvironment env)
                   throws ContinuationException
Throws:
ContinuationException

interpret

public Value interpret(Expression e)
                throws SchemeException
Throws:
SchemeException

interpret

protected void interpret()
                  throws SchemeException
Throws:
SchemeException

next

public final void next(Expression nextExpr)
                throws ContinuationException
Throws:
ContinuationException

newVLR

public final void newVLR(int size)

newVLR

public final void newVLR(Value[] vlr)

pop

public final void pop(CallFrame c)

makeStackTracer

public final StackTracer makeStackTracer()

setVLR

public final void setVLR(int pos,
                         Value v)

pushExpr

public final void pushExpr(Expression e)

setFailureContinuation

public final void setFailureContinuation(Expression e)

captureContinuation

public final Procedure captureContinuation()

captureEscapingContinuation

public final Procedure captureEscapingContinuation()

trace

public void trace(Expression e)

error

public void error(Pair error)
           throws ContinuationException
Throws:
ContinuationException

evalInput

public Value evalInput(java.io.PushbackReader port)
                throws java.io.IOException,
                       SchemeException
Parses and evaluates s-expression(s) from an input port

Parameters:
port - input port
Returns:
The value of the last evaluated s-expression
Throws:
java.io.IOException - Raised if the port does not contain a parseable s-expression
Interpreter.ThrowSchemeException - Raised if the evaluation of an expression results in an error
SchemeException

eval

public Value eval(java.lang.String expr)
           throws java.io.IOException,
                  SchemeException
Parses and evaluates s-expression(s)

Parameters:
expr - s-expressions(s)
Returns:
The value of the last evaluated s-expression
Throws:
java.io.IOException - Raised if the given string does not contain a parseable s-expression
Interpreter.ThrowSchemeException - Raised if the evaluation of an expression results in an error
SchemeException

eval

public Value eval(Value v)
           throws SchemeException
Evaluates a Scheme value as code. This is equivalent to (eval v) in Scheme.

Parameters:
v - A Scheme Value
Returns:
The resulting value
Throws:
Interpreter.ThrowSchemeException - Raised if the evaluation of the expression results in an error
SchemeException

eval

public Value eval(Value v,
                  SymbolicEnvironment env)
           throws SchemeException
Evaluates a Scheme value as code. This is equivalent to (eval v e) in Scheme.

Parameters:
v - A Scheme Value
env - The environment in which to evaluate the value
Returns:
The resulting value
Throws:
Interpreter.ThrowSchemeException - Raised if the evaluation of the expression results in an error
SchemeException

eval

public Value eval(Procedure p,
                  Value[] args)
           throws SchemeException
Applies the given procedure to the given values

Parameters:
p - A procedure
args - Arguments to call the procedure with
Returns:
The result returned by the procedure
Throws:
Interpreter.ThrowSchemeException - Raised if applying the procedure results in an error
SchemeException

loadSourceFiles

public boolean loadSourceFiles(java.lang.String[] files)
Loads zero or more Scheme source files or compiled libraries.

Parameters:
files - An array of Strings naming files to load.
Returns:
true on success, false if any source file produced an error.

lookupContextEnv

public SymbolicEnvironment lookupContextEnv(Symbol s)

defineContextEnv

public void defineContextEnv(Symbol s,
                             SymbolicEnvironment env)

getContextEnv

public SymbolicEnvironment getContextEnv(Symbol s)

define

public void define(Symbol s,
                   Value v,
                   Symbol context)
Defines a new binding in a named environment.

Parameters:
s - The name of the new binding
v - The value of the new binding
context - The name of the environment in which to create the binding

lookup

public Expression lookup(Symbol s,
                         Symbol context)
Retrieves the value of a binding in a named environment

Parameters:
s - The name of the binding
context - The name of the environment from which the binding will be retrieved
Returns:
A value or expression

undefine

public void undefine(Symbol s,
                     Symbol context)
Removes a binding in a named environment

Parameters:
s - The name of the binding
context - The name of the environment from which the binding will be retrieved

push

public final void push(Expression n)

returnFrame

public final void returnFrame(CallFrame f)

createValues

public final Value[] createValues(int size)

returnVLR

public final void returnVLR()

setupTailCall

public final void setupTailCall(Expression e,
                                Value vlr0)

setupTailCall

public final void setupTailCall(Expression e,
                                Value[] newvlr)

returnValues

public final void returnValues(Value[] v)

vlrToArgs

public Value[] vlrToArgs()
Returns a Value[] prepared as a value rib for a procedure with a fixed argument count. This may or may not clone the VLR depending on whether it is safe to not do so.


vlrToRestArgs

public Value[] vlrToRestArgs(int fcount)
Returns a Value[] prepared as a value rib for a for procedure expecting rest args in the last rib position. This may or may not clone the VLR depending on whether it is safe to not do so.

Parameters:
fcount - The number of arguments to prepare including the rest variable