org.millscript.millscript.expr
Class MemoExpr

java.lang.Object
  extended by org.millscript.millscript.expr.Expr<MemoAction>
      extended by org.millscript.millscript.expr.MemoExpr
All Implemented Interfaces:
OneResult

public final class MemoExpr
extends Expr<MemoAction>
implements OneResult

This class implements a memo expression. A memo expression wraps a normal lambda expression, with the exception that the lambda expression must have one argument and return a single result. When the memo expression is applied the first time, the lambda expression is applied and it's result is remembered and returned. Subsequent applications of the memo expression with the same argument return the remembered value, rather than re-applying the function.

See Also:
DefineSyntax, LambdaExpr, MemoAction

Constructor Summary
MemoExpr(LambdaExpr e)
          Creates a new memo expression, for the specified lamba expression.
 
Method Summary
 MemoAction 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
arity, 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

MemoExpr

public MemoExpr(LambdaExpr e)
Creates a new memo expression, for the specified lamba expression.

Parameters:
e - the lamba expression, whose results should be remembered
Method Detail

compileIt

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

Specified by:
compileIt in class Expr<MemoAction>
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<MemoAction>
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.