edu.iu.cnets.klatsch.lang
Class Runtime

java.lang.Object
  extended by edu.iu.cnets.klatsch.lang.Runtime

public class Runtime
extends java.lang.Object

This class holds all of the variables for the current runtime environment. It is simply a mapping from variable names to Value objects -- the language is dynamically typed, so one mapping works for everything.


Field Summary
(package private)  java.util.Map<java.lang.String,Value> env
           
(package private)  Runtime parent
           
 
Constructor Summary
Runtime()
          Initialize a new top-level environment.
Runtime(Runtime parent)
          Creates a new environment with the given one as parent.
 
Method Summary
 void addLibrary()
          Extends the environment to include the standard utility functions.
 Runtime extend(java.lang.String[] idList, Value[] valList)
          Extends this environment with multiple ID and value bindings.
 Runtime extend(java.lang.String id, Value val)
          Extends this environment with a single ID/value binding.
 Value get(java.lang.String id)
          Returns the value of the given variable.
(package private)  boolean isDefined(java.lang.String id)
          Checks to see if the given variable is defined in this environment.
 void set(java.lang.String id, Value value)
          Sets the value of the given variable as specified.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

env

java.util.Map<java.lang.String,Value> env

parent

Runtime parent
Constructor Detail

Runtime

public Runtime()
Initialize a new top-level environment.


Runtime

Runtime(Runtime parent)
Creates a new environment with the given one as parent. Client classes have no need to use this constructor -- they should call {link #extend} instead.

Parameters:
parent - the parent environment
Method Detail

addLibrary

public void addLibrary()
Extends the environment to include the standard utility functions. These are necessary to include features like stream.map(), which are difficult to implement in the interpreter but easy to implement in Klatsch.


extend

public Runtime extend(java.lang.String id,
                      Value val)
Extends this environment with a single ID/value binding.

Parameters:
id - the ID
val - the value

extend

public Runtime extend(java.lang.String[] idList,
                      Value[] valList)
Extends this environment with multiple ID and value bindings.

Parameters:
idList - the set of IDs
valList - the list of values

get

public Value get(java.lang.String id)
          throws EvaluationException
Returns the value of the given variable.

Parameters:
id - the name of the variable
Returns:
current value
Throws:
EvaluationException - if the variable is undefined

isDefined

boolean isDefined(java.lang.String id)
Checks to see if the given variable is defined in this environment.

Parameters:
id - the name of the variable
Returns:
true if the variable is defined

set

public void set(java.lang.String id,
                Value value)
Sets the value of the given variable as specified. This should be called only by the ELValue class.

Parameters:
id - the variable to set
value - the value to set it to