org.millscript.millscript.expr
Class CommaExpr

java.lang.Object
  extended by org.millscript.millscript.expr.Expr<CommaAction>
      extended by org.millscript.millscript.expr.CommaExpr

public final class CommaExpr
extends Expr<CommaAction>

This class implements a comma expression. A comma expression simply has a left and right hand side expression, which are executed in that order. The comma sits between the left and right hand side expressions.

See Also:
CommaAction

Constructor Summary
CommaExpr(Expr<?> l, Expr<?> r)
          Creates a new comma expression with the specifed left and right hand side expressions.
 
Method Summary
 int arity()
          Returns the arity of this expression.
 CommaAction compileIt()
          Compiles this expression into an action.
 Expr getLeft()
          Returns the left hand side expression, that which preceeds the comma.
 Expr getRight()
          Returns the right hand side expression, that which follows the comma.
static Expr<?> make(Expr l, Expr r)
          Returns an expression for the specified left and right hand side 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

CommaExpr

public CommaExpr(Expr<?> l,
                 Expr<?> r)
Creates a new comma expression with the specifed left and right hand side expressions.

Parameters:
l - the left hand side expression
r - the right hand side expression
Method Detail

make

public static Expr<?> make(Expr l,
                           Expr r)
Returns an expression for the specified left and right hand side expressions. This method provides some compile-time optimisation, as it avoids creating additional unnecessary objects in the expression tree. If the left hand side expression is a SkipExpr, the right hand side expression is returned, and vice versa. Otherwise, if neither the left or right hand side expressions are SkipExprs, a new comma expression is returned.

Parameters:
l - the left hand side expression
r - the right hand side expression
Returns:
a new CommaExpr if the left or right hand side are not SkipExpr, otherwise the right or left hand side expression

arity

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

For a comma expression, the arity is the sum of each expressions arity. e.g. if either arity is unknown, the comma expressions arity is unknown, otherwise the comma expression arity is the sum of the left and right hand side arity.

Overrides:
arity in class Expr<CommaAction>
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.addArity(int, int)

compileIt

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

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

getLeft

public Expr getLeft()
Returns the left hand side expression, that which preceeds the comma.

Returns:
the left hand side expression

getRight

public Expr getRight()
Returns the right hand side expression, that which follows the comma.

Returns:
the right hand side expression

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<CommaAction>
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.