org.millscript.millscript.expr
Class If3Expr

java.lang.Object
  extended by org.millscript.millscript.expr.Expr<If3Action>
      extended by org.millscript.millscript.expr.If3Expr

public final class If3Expr
extends Expr<If3Action>

This class implements an if3 expression. An if3 expression has a predicate, ifso and ifnot expression, where if ifso expression is executed if the predicate expression returns true and the ifnot expression is executed otherwise.

See Also:
ConditionalSyntax, If2Expr, If3Action

Constructor Summary
If3Expr(Expr a, Expr b, Expr c)
          Creates a new if3 expression with the specified predicate, ifso and ifnot expressions.
 
Method Summary
 int arity()
          Returns the arity of this expression.
 If3Action compileIt()
          Compiles this expression into an action.
static Expr make(Expr a, Expr<?> b, Expr<?> c)
          Returns an if3 expression for the specified predicate, ifso and ifnot expressions.
 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

If3Expr

public If3Expr(Expr a,
               Expr b,
               Expr c)
Creates a new if3 expression with the specified predicate, ifso and ifnot expressions.

Parameters:
a - the predicate expression which must return a single result
b - the ifso expression
c - the ifnot expression
Method Detail

make

public static Expr make(Expr a,
                        Expr<?> b,
                        Expr<?> c)
Returns an if3 expression for the specified predicate, ifso and ifnot expressions. This method provides some compile-time optimisation, as it trys to simplify the predicate expression. If the predicate is a not expression, it remakes the if3 expression after removing the not.

Parameters:
a - the predicate expression which must return a single result
b - the ifso expression
c - the ifnot expression
Returns:
an If3Expr for the specified values

arity

public int arity()
Description copied from class: Expr
Returns the arity of this expression. Positive numbers represent exact arity, while negative numbers represent unknown arity.

Overrides:
arity in class Expr<If3Action>
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.
See Also:
Expr.arity()

compileIt

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

Specified by:
compileIt in class Expr<If3Action>
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<If3Action>
Parameters:
state - the compiler state we are resolving in
See Also:
Expr.resolve(org.millscript.millscript.vm.CompilerState)


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