org.millscript.millscript.expr
Class ForExpr

java.lang.Object
  extended by org.millscript.millscript.expr.Expr<ForAction>
      extended by org.millscript.millscript.expr.ForExpr

public final class ForExpr
extends Expr<ForAction>

This class represents a For loop expression. A for loop expression may contain multiple condition/binding expressions, a single body expression and a single termination expression.

See Also:
ForSyntax, ForAction

Constructor Summary
ForExpr(org.millscript.commons.util.IList<ForConditionExpr> a, Expr<?> b, Expr<?> t)
          Construct a new For Expression with the supplied conditions/bindings, body and normal termination expression.
 
Method Summary
 int arity()
          Returns the arity of this expression.
 ForAction compileIt()
          Compiles this expression into an action.
 void resolve(CompilerState state)
          Resolves any NameExpr in the tree so that they refer to the correct ident.
 
Methods inherited from class org.millscript.millscript.expr.Expr
compile, isIntegerExpr, resolveList, setLineNumber, setOrigin, show, show
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ForExpr

public ForExpr(org.millscript.commons.util.IList<ForConditionExpr> a,
               Expr<?> b,
               Expr<?> t)
Construct a new For Expression with the supplied conditions/bindings, body and normal termination expression.

Parameters:
a - list of conditions and bindings
b - body Expr
t - normal termination Expr
Method Detail

arity

public int arity()
Returns the arity of this expression. Positive numbers represent exact arity, while negative numbers represent unknown arity.

If the for loop body has an arity of zero, the for loops arity is zero, otherwise the for loop arity is unknown. The for loop arity would depend on the number of iterations, etc.

Overrides:
arity in class Expr<ForAction>
Returns:
0 if the expression returns zero results, 1 if the expression returns one result or -1 if the expression returns an unknown number of results.

compileIt

public ForAction compileIt()
Description copied from class: Expr
Compiles this expression into an action.

Specified by:
compileIt in class Expr<ForAction>
Returns:
the Action for this expression
See Also:
Expr.compileIt()

resolve

public void resolve(CompilerState state)
Description copied from class: Expr
Resolves any NameExpr in the tree so that they refer to the correct ident. e.g. This method is responsible for ensuring that references to a function argument in the body of a function actually refer to the correct value.

Specified by:
resolve in class Expr<ForAction>
Parameters:
state - the compiler state we are resolving in
See Also:

In a for expression, the renaming process is slightly more compilcated than usual. The renaming uses the following sequence:

  1. binding expressions children are pushed onto the stack
  2. binding expressions are renamed
  3. the termination expression is renamed
  4. a new scope is declared
    1. any bound variables are pushed onto the stack
    2. remaining for conditions are renamed
    3. for loop body is renamed
Which ensures that the relevant bindings are available within the condition and body expression.



Copyright © 2001-2007 Open World Ltd. All Rights Reserved.