-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partial solution for multiple evaluation in dollar expressions
- Loading branch information
1 parent
935712c
commit 9ecc78a
Showing
2 changed files
with
38 additions
and
30 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...rc/main/java/org/openzen/zenscript/codemodel/compilation/MemoizedCompilingExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.openzen.zenscript.codemodel.compilation; | ||
|
||
import org.openzen.zencode.shared.CodePosition; | ||
import org.openzen.zenscript.codemodel.compilation.expression.AbstractCompilingExpression; | ||
import org.openzen.zenscript.codemodel.expression.Expression; | ||
import org.openzen.zenscript.codemodel.ssa.CodeBlockStatement; | ||
import org.openzen.zenscript.codemodel.ssa.SSAVariableCollector; | ||
|
||
public class MemoizedCompilingExpression extends AbstractCompilingExpression { | ||
private final CompilingExpression expression; | ||
private Expression result; | ||
|
||
public MemoizedCompilingExpression(ExpressionCompiler compiler, CodePosition position, CompilingExpression expression) { | ||
super(compiler, position); | ||
|
||
this.expression = expression; | ||
} | ||
|
||
@Override | ||
public Expression eval() { | ||
if (result == null) | ||
result = expression.eval(); | ||
return result; | ||
} | ||
|
||
@Override | ||
public void collect(SSAVariableCollector collector) { | ||
expression.collect(collector); | ||
} | ||
|
||
@Override | ||
public void linkVariables(CodeBlockStatement.VariableLinker linker) { | ||
expression.linkVariables(linker); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters