jsint
Class Evaluator

java.lang.Object
  extended byjsint.Evaluator
All Implemented Interfaces:
java.io.Serializable

public class Evaluator
extends java.lang.Object
implements java.io.Serializable

This class represents a Scheme interpreter.

Author:
Peter Norvig, Copyright 1998, peter@norvig.com, license subsequently modified by Jscheme project members licensed under zlib licence (see license.txt)
See Also:
Serialized Form

Field Summary
 DynamicEnvironment INITIAL_ENVIRONMENT
           
 DynamicEnvironment interactionEnvironment
           
 boolean INTERRUPTABLE
          Is execution interruptable.
static DynamicEnvironment NULL_ENVIRONMENT
           
 
Constructor Summary
Evaluator()
           
Evaluator(DynamicEnvironment env)
           
 
Method Summary
 java.lang.Object analyze(java.lang.Object x, DynamicEnvironment dynamicEnv, LexicalEnvironment lexenv)
          Analyze (or preprocess or precompile) an expression into "code".
 void enableNamedResults(boolean enabled)
           
 java.lang.Boolean environmentImport(java.lang.Object x, java.lang.Object prefix)
           
 java.lang.Boolean environmentImport(java.lang.Object x, java.lang.Object prefix, boolean macrosFlag, Symbol[] procnames)
           
 java.lang.Object eval(java.lang.Object x)
          Evaluate an s-expression in the global environment.
 java.lang.Object eval(java.lang.Object x, java.lang.Object env)
          Evaluate an s-expression in a lexical environment.
 java.lang.Object evalToplevel(java.lang.Object x, DynamicEnvironment env)
          evalToplevel evaluates each element of a BEGIN.
 java.lang.Object execute(java.lang.Object x, LexicalEnvironment lexenv)
          Evaluate analyzed code in a lexical environment.
 java.io.PrintWriter getError()
           
 DynamicEnvironment getInitialEnvironment()
           
 InputPort getInput()
           
 DynamicEnvironment getInteractionEnvironment()
           
static DynamicEnvironment getNullEnvironment()
           
 java.io.PrintWriter getOutput()
           
 void interrupt(java.lang.Thread t)
          Interrupt execution on thread t.
 void interruptCheck()
          Maybe interrupt this thread of execution.
 java.lang.Boolean languageImport(java.lang.Object x)
           
 java.lang.Object load(InputPort in)
          Eval all the expressions coming from an InputPort, putting them in the interactionEnvironment.
 java.lang.Object load(java.lang.Object fileName)
          Eval all the expressions in a file.
 DynamicEnvironment loadEnvironment(java.lang.Object x)
          load the current object (file or class) into a new Evaluator and return the resulting Evaluator's DynamicEnvironment.
 boolean readEvalWriteLoop(java.lang.String prompt)
          Prompt, read, eval, and write the result.
 void runJscheme()
           
 void setError(java.io.PrintWriter w)
           
 boolean setExit(boolean exit)
           
 void setInput(InputPort ip)
           
 void setOutput(java.io.PrintWriter w)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INTERRUPTABLE

public boolean INTERRUPTABLE
Is execution interruptable.


interactionEnvironment

public DynamicEnvironment interactionEnvironment

NULL_ENVIRONMENT

public static DynamicEnvironment NULL_ENVIRONMENT

INITIAL_ENVIRONMENT

public DynamicEnvironment INITIAL_ENVIRONMENT
Constructor Detail

Evaluator

public Evaluator()

Evaluator

public Evaluator(DynamicEnvironment env)
Method Detail

setExit

public boolean setExit(boolean exit)

setInput

public void setInput(InputPort ip)

getInput

public InputPort getInput()

getOutput

public java.io.PrintWriter getOutput()

setOutput

public void setOutput(java.io.PrintWriter w)

getError

public java.io.PrintWriter getError()

setError

public void setError(java.io.PrintWriter w)

interrupt

public void interrupt(java.lang.Thread t)
Interrupt execution on thread t.


interruptCheck

public void interruptCheck()
Maybe interrupt this thread of execution.


getInteractionEnvironment

public DynamicEnvironment getInteractionEnvironment()

getNullEnvironment

public static DynamicEnvironment getNullEnvironment()

getInitialEnvironment

public DynamicEnvironment getInitialEnvironment()

runJscheme

public void runJscheme()

enableNamedResults

public void enableNamedResults(boolean enabled)

readEvalWriteLoop

public boolean readEvalWriteLoop(java.lang.String prompt)
Prompt, read, eval, and write the result. Also sets up a catch for any RuntimeExceptions encountered. Returns true on EOF, false if (exit) was evaluated.


loadEnvironment

public DynamicEnvironment loadEnvironment(java.lang.Object x)
load the current object (file or class) into a new Evaluator and return the resulting Evaluator's DynamicEnvironment.


environmentImport

public java.lang.Boolean environmentImport(java.lang.Object x,
                                           java.lang.Object prefix)

environmentImport

public java.lang.Boolean environmentImport(java.lang.Object x,
                                           java.lang.Object prefix,
                                           boolean macrosFlag,
                                           Symbol[] procnames)

languageImport

public java.lang.Boolean languageImport(java.lang.Object x)

load

public java.lang.Object load(java.lang.Object fileName)
Eval all the expressions in a file. Calls load(InputPort).


load

public java.lang.Object load(InputPort in)
Eval all the expressions coming from an InputPort, putting them in the interactionEnvironment. The interactionEnvironment might have been rebound to a module environment, but we don't care about that. Returns TRUE on EOF, FALSE if (exit) was evaluated.


evalToplevel

public java.lang.Object evalToplevel(java.lang.Object x,
                                     DynamicEnvironment env)
evalToplevel evaluates each element of a BEGIN. This is so macros can be defined and then used. Also toplevel macros can expand into begin.


eval

public java.lang.Object eval(java.lang.Object x)
Evaluate an s-expression in the global environment.


eval

public java.lang.Object eval(java.lang.Object x,
                             java.lang.Object env)
Evaluate an s-expression in a lexical environment. First analyze it.


analyze

public java.lang.Object analyze(java.lang.Object x,
                                DynamicEnvironment dynamicEnv,
                                LexicalEnvironment lexenv)
Analyze (or preprocess or precompile) an expression into "code". The code returned is either a Symbol, a LocalVariable, a Closure, or an array whose first element is either one of (quote if or begin set!) or is code evaluating to a procedure.


execute

public java.lang.Object execute(java.lang.Object x,
                                LexicalEnvironment lexenv)
Evaluate analyzed code in a lexical environment. Don't pass this a raw s-expression; you need to analyze the s-expression first.