-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASTId.java
More file actions
48 lines (40 loc) · 1.25 KB
/
Copy pathASTId.java
File metadata and controls
48 lines (40 loc) · 1.25 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
public class ASTId implements ASTNode {
String id;
public ASTId(String id) {
this.id = id;
}
public String getId() {
return id;
}
@Override
public IValue eval(Environment<IValue> env) throws InterpreterError {
IValue v = env.find(id);
if (v instanceof VMut mut) {
try {
return ASTLet.mem.memrd(mut.getAddr());
} catch (MemoryPanicError ex) {
throw new InterpreterError("mut: " + ex.getMessage());
}
}
return v;
}
public IValue evalLValue(Environment<IValue> env) throws InterpreterError {
return env.find(id);
}
// Rule Γ, x : mut(A) ⊢ x : A
@Override
public ASTType typecheck(Environment<ASTType> env) throws TypeCheckError, InterpreterError {
ASTType t = env.find(id);
if (t instanceof ASTTMut mut) {
return ASTTypeDef.unfold(mut.getInner(), env);
}
return ASTTypeDef.unfold(t, env);
}
public ASTType typecheckLValue(Environment<ASTType> env) throws TypeCheckError, InterpreterError {
return env.find(id);
}
@Override
public boolean isFreeOutsideLambda(String id) {
return this.id.equals(id);
}
}