-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathSymbolCaptured.java
More file actions
61 lines (47 loc) · 1.91 KB
/
SymbolCaptured.java
File metadata and controls
61 lines (47 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package stanhebben.zenscript.symbols;
import org.objectweb.asm.Type;
import stanhebben.zenscript.compiler.*;
import stanhebben.zenscript.expression.*;
import stanhebben.zenscript.expression.partial.*;
import stanhebben.zenscript.type.*;
import stanhebben.zenscript.util.*;
import java.util.*;
public class SymbolCaptured implements IZenSymbol {
private final String fieldName;
private final String lambdaClassName;
private final Expression evaluated;
public SymbolCaptured(Expression original, String fieldName, String clsName) {
this.evaluated = original;
this.fieldName = fieldName;
this.lambdaClassName = clsName;
}
public ZenType getType() {
return evaluated.getType();
}
@Override
public IPartialExpression instance(ZenPosition position) {
return new Expression(position) {
@Override
public void compile(boolean result, IEnvironmentMethod environment) {
if(!result)
return;
final MethodOutput output = environment.getOutput();
if(lambdaClassName == null || fieldName == null || evaluated == null) {
throw new IllegalStateException(String.format(Locale.ENGLISH, "Captured variable with name %s in class %s and evaluated obj %s has at least one null info", fieldName, lambdaClassName, evaluated));
}
output.loadObject(0);
output.getField(lambdaClassName, fieldName, Type.getDescriptor(getType().toJavaClass()));
}
@Override
public ZenType getType() {
return SymbolCaptured.this.getType();
}
};
}
public Expression getEvaluated() {
return evaluated;
}
public String getFieldName() {
return fieldName;
}
}