diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-10-17 16:59:05 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-10-17 16:59:05 +0100 |
| commit | a97acb1a85c588a38a4a8a8b761beddb71cb960a (patch) | |
| tree | 658f878936c3fcdbca452feb8dc972ac3449b21b /src/main/java/org/zwobble/couscous/interpreter/Environment.java | |
| parent | 886358792f8b2bee4fb2a2e16b8f34162be50cfe (diff) | |
Use String instead of int for declaration IDs
Diffstat (limited to 'src/main/java/org/zwobble/couscous/interpreter/Environment.java')
| -rw-r--r-- | src/main/java/org/zwobble/couscous/interpreter/Environment.java | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/main/java/org/zwobble/couscous/interpreter/Environment.java b/src/main/java/org/zwobble/couscous/interpreter/Environment.java index 9a884f3..675cfda 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/Environment.java +++ b/src/main/java/org/zwobble/couscous/interpreter/Environment.java @@ -19,7 +19,7 @@ import lombok.val; public class Environment { private final Project project; private final Optional<InterpreterValue> thisValue; - private final Map<Integer, VariableEntry> stackFrame; + private final Map<String, VariableEntry> stackFrame; public Environment( Project project, @@ -38,13 +38,13 @@ public class Environment { return thisValue; } - public InterpreterValue get(int variableId) { + public InterpreterValue get(String variableId) { checkVariableIsInScope(variableId); val entry = stackFrame.get(variableId); return entry.getValue().orElseThrow(() -> new UnboundVariable(variableId)); } - public void put(int variableId, InterpreterValue value) { + public void put(String variableId, InterpreterValue value) { checkVariableIsInScope(variableId); checkVariableType(variableId, value); stackFrame.get(variableId).setValue(Optional.of(value)); @@ -62,13 +62,13 @@ public class Environment { return new Environment(project, thisValue, stackFrame); } - private void checkVariableIsInScope(int variableId) { + private void checkVariableIsInScope(String variableId) { if (!stackFrame.containsKey(variableId)) { throw new VariableNotInScope(variableId); } } - private void checkVariableType(int variableId, InterpreterValue value) { + private void checkVariableType(String variableId, InterpreterValue value) { val variableType = stackFrame.get(variableId).getType(); InterpreterTypes.checkIsInstance(variableType, value); } |
