-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASTAddr.java
More file actions
27 lines (22 loc) · 812 Bytes
/
Copy pathASTAddr.java
File metadata and controls
27 lines (22 loc) · 812 Bytes
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
public class ASTAddr implements ASTNode {
private final String id;
public ASTAddr(String id) {
this.id = id;
}
@Override
public IValue eval(Environment<IValue> e) throws InterpreterError {
IValue v = e.find(id);
if (!(v instanceof VMut mut))
throw new InterpreterError("&: " + id + " is not a mut variable");
return mut.getAddr();
}
@Override
public ASTType typecheck(Environment<ASTType> e) throws TypeCheckError, InterpreterError {
ASTType t = e.find(id);
t = ASTTypeDef.unfold(t, e);
if (!(t instanceof ASTTMut mut))
throw new TypeCheckError("&: " + id + " is not a mut variable");
int varDepth = e.getScopeDepth(id);
return new ASTTAddr(mut.getInner(), varDepth);
}
}