-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASTStructTuple.java
More file actions
43 lines (37 loc) · 1.19 KB
/
Copy pathASTStructTuple.java
File metadata and controls
43 lines (37 loc) · 1.19 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
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class ASTStructTuple implements ASTNode {
String tag;
List<ASTNode> exps;
public ASTStructTuple(String tag, List<ASTNode> exps) {
this.tag = tag;
this.exps = exps;
}
@Override
public IValue eval(Environment<IValue> e) throws InterpreterError
{
List<IValue> values = new ArrayList<>();
for (ASTNode exp : exps) {
values.add(exp.eval(e));
}
return new VStructTuple(tag, values);
}
@Override
public ASTType typecheck(Environment<ASTType> e) throws TypeCheckError, InterpreterError {
List<ASTType> fieldTypes = new ArrayList<>();
for (ASTNode exp : exps) {
ASTType t = exp.typecheck(e);
fieldTypes.add(t);
}
List<Map.Entry<String, List<ASTType>>> options = new ArrayList<>();
options.add(new java.util.AbstractMap.SimpleEntry<>(tag, fieldTypes));
return new ASTTEnum(options);
}
@Override
public boolean isFreeOutsideLambda(String id) {
for (ASTNode e : exps)
if (e.isFreeOutsideLambda(id)) return true;
return false;
}
}