jsint
Class Evaluator

java.lang.Object
  |
  +--jsint.Evaluator
All Implemented Interfaces:
SchemeEvaluator

public class Evaluator
extends java.lang.Object
implements SchemeEvaluator

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)

Field Summary
 java.io.PrintWriter error
           
 boolean EXIT
          Should REP Loop exit?
 DynamicEnvironment INITIAL_ENVIRONMENT
           
 InputPort input
           
 DynamicEnvironment interactionEnvironment
           
 boolean INTERRUPTABLE
          Is execution interruptable.
static DynamicEnvironment NULL_ENVIRONMENT
           
 java.io.PrintWriter output
           
 
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".
 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.
 DynamicEnvironment getInitialEnvironment()
           
 DynamicEnvironment getInteractionEnvironment()
           
static DynamicEnvironment getNullEnvironment()
           
 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.
 void readEvalWriteLoop(java.lang.String prompt)
          Prompt, read, eval, and write the result.
 void runJscheme()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXIT

public boolean EXIT
Should REP Loop exit?

input

public InputPort input

output

public java.io.PrintWriter output

error

public java.io.PrintWriter error

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

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()

readEvalWriteLoop

public void readEvalWriteLoop(java.lang.String prompt)
Prompt, read, eval, and write the result. Also sets up a catch for any RuntimeExceptions encountered.

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.

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.