-
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.
- Loading branch information
1 parent
f9dafe8
commit 8db81eb
Showing
10 changed files
with
141 additions
and
46 deletions.
There are no files selected for viewing
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
59 changes: 59 additions & 0 deletions
59
...in/java/org/openzen/zenscript/codemodel/compilation/impl/capture/LocalThisExpression.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,59 @@ | ||
package org.openzen.zenscript.codemodel.compilation.impl.capture; | ||
|
||
import org.openzen.zencode.shared.CodePosition; | ||
import org.openzen.zenscript.codemodel.FunctionParameter; | ||
import org.openzen.zenscript.codemodel.compilation.CompilingExpression; | ||
import org.openzen.zenscript.codemodel.compilation.ExpressionCompiler; | ||
import org.openzen.zenscript.codemodel.compilation.expression.AbstractCompilingExpression; | ||
import org.openzen.zenscript.codemodel.expression.*; | ||
import org.openzen.zenscript.codemodel.ssa.CodeBlockStatement; | ||
import org.openzen.zenscript.codemodel.ssa.SSAVariableCollector; | ||
import org.openzen.zenscript.codemodel.type.TypeID; | ||
|
||
public class LocalThisExpression implements LocalExpression { | ||
private final CodePosition position; | ||
private final TypeID type; | ||
|
||
public LocalThisExpression(CodePosition position, TypeID type) { | ||
this.position = position; | ||
this.type = type; | ||
} | ||
|
||
@Override | ||
public LocalExpression capture(LambdaClosure closure) { | ||
CapturedExpression value = new CapturedThisExpression(position, type, closure); | ||
closure.add(value); | ||
return new LocalCapturedExpression(value); | ||
} | ||
|
||
@Override | ||
public CompilingExpression compile(ExpressionCompiler compiler) { | ||
return new Compiling(compiler, position, type); | ||
} | ||
|
||
private static class Compiling extends AbstractCompilingExpression { | ||
private final TypeID type; | ||
|
||
public Compiling(ExpressionCompiler compiler, CodePosition position, TypeID type) { | ||
super(compiler, position); | ||
|
||
this.type = type; | ||
} | ||
|
||
@Override | ||
public Expression eval() { | ||
return compiler.at(position).getThis(type); | ||
} | ||
|
||
@Override | ||
public CompilingExpression assign(CompilingExpression value) { | ||
return this; | ||
} | ||
|
||
@Override | ||
public void collect(SSAVariableCollector collector) {} | ||
|
||
@Override | ||
public void linkVariables(CodeBlockStatement.VariableLinker 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
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
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
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
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
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
28 changes: 9 additions & 19 deletions
28
ScriptingEngineTester/src/main/resources/zencode-tests/arrays/arrays-map-2.zc
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 |
---|---|---|
@@ -1,26 +1,16 @@ | ||
#output: 2 | ||
#output: 4 | ||
#output: 6 | ||
#output: a1 | ||
#output: a2 | ||
#output: a3 | ||
|
||
public expand <T> T[] { | ||
public map<U>(projection as function(value as T) as U) as U[] { | ||
var values = new U[](length); | ||
for i, value in this | ||
values[i] = projection(value); | ||
return values; | ||
} | ||
|
||
[Native("mapKeyValues")] | ||
public map<U>(projection as function(index as usize, value as T) as U) as U[] { | ||
var values = new U[](length); | ||
for i, value in this | ||
values[i] = projection(i, value); | ||
return values; | ||
return new U[](length, index => projection(this[index])); | ||
} | ||
} | ||
|
||
var a = [1, 2, 3]; | ||
var b = a.map<int>(x => x * 2); | ||
for item in b { | ||
var a = ["1", "2", "3"]; | ||
var b = a.map<string>(x => "a" + x); | ||
println(typeof(b)); | ||
/*for item in b { | ||
println(item); | ||
} | ||
}*/ |
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