-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisInstance.java
More file actions
38 lines (29 loc) · 813 Bytes
/
DisInstance.java
File metadata and controls
38 lines (29 loc) · 813 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
28
29
30
31
32
33
34
35
36
37
38
package dev.alephpt.Dis;
import java.util.HashMap;
import java.util.Map;
class DisInstance {
private DisObj obj;
private final Map<String, Object> fields = new HashMap<>();
DisInstance(DisObj obj) {
this.obj = obj;
}
Object get(Token name) {
if (fields.containsKey(name.lexeme)) {
return fields.get(name.lexeme);
}
DisOp method = obj.findMethod(name.lexeme);
if (method != null) {
return method.bind(this);
}
throw new RuntimeError(name, "Undefined object property '" + name.lexeme + "'.");
}
void set(Token name, Object value) {
fields.put(name.lexeme, value);
}
@Override
public String toString() {
if (obj.name != null) { return "<" + obj.name + " instance>"; }
DisC.error(null, "instance name is null");
return null;
}
}