orc.ast.simple
Class Expression

java.lang.Object
  extended by orc.ast.simple.Expression
Direct Known Subclasses:
Atomic, Call, Defs, HasType, Isolated, Let, Parallel, Semi, Sequential, Silent, TypeDecl, Where, WithLocation

public abstract class Expression
extends java.lang.Object

Base class for the simplified abstract syntax tree.

Author:
dkitchin, wcook

Constructor Summary
Expression()
           
 
Method Summary
abstract  Expr convert(Env<Var> vars, Env<java.lang.String> typevars)
          Converts abstract syntax tree into a serializable form, used to generate portable .oil (Orc Intermediate Language) files.
 Expression suball(java.util.Map<NamedVar,? extends Argument> m)
          Perform a set of substitutions defined by a map.
abstract  Expression subst(Argument a, NamedVar x)
          Performs the substitution [a/x], replacing occurrences of the free variable x with the new argument a (which could be any argument, including another variable).
 Expression subvar(Var v, NamedVar x)
          Performs the substitution [v/x], replacing occurrences of the free variable x with the nameless variable v.
abstract  java.util.Set<Var> vars()
          Find the set of all unbound Vars (note: not FreeVars) in this expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Expression

public Expression()
Method Detail

convert

public abstract Expr convert(Env<Var> vars,
                             Env<java.lang.String> typevars)
                      throws CompilationException
Converts abstract syntax tree into a serializable form, used to generate portable .oil (Orc Intermediate Language) files. Note that the typevars environment is a content-addressable environment of strings. Type vars are represented as strings for simplicity, because unlike regular vars, there are not yet any compiler steps which generate temporary type variables.

Parameters:
vars - The vars environment, used in content addressable mode to find the appropriate deBruijn index of a var.
typevars - The type vars environment, used in content addressable mode to find the appropriate deBruijn index of a type var.
Returns:
A new node.
Throws:
CompilationException

subst

public abstract Expression subst(Argument a,
                                 NamedVar x)
Performs the substitution [a/x], replacing occurrences of the free variable x with the new argument a (which could be any argument, including another variable).

Parameters:
a - The replacing variable or value
x - The free variable whose occurrences will be replaced
Returns:
A new copy of the expression with the substitution performed

subvar

public Expression subvar(Var v,
                         NamedVar x)
Performs the substitution [v/x], replacing occurrences of the free variable x with the nameless variable v. Additionally, attach the name of x as documentation on the variable v so that it can be used later for debugging or other purposes. This method delegates to the subst method after attaching the name.

Parameters:
v - The replacing variable
x - The free variable whose occurrences will be replaced
Returns:
A new copy of the expression with the substitution performed

suball

public Expression suball(java.util.Map<NamedVar,? extends Argument> m)
Perform a set of substitutions defined by a map. For each x |-> a in the map, the substitution [a/x] occurs. If a is a nameless variable v, the name of the corresponding x will be attached to it.

Parameters:
m -

vars

public abstract java.util.Set<Var> vars()
Find the set of all unbound Vars (note: not FreeVars) in this expression.