From a97acb1a85c588a38a4a8a8b761beddb71cb960a Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 17 Oct 2015 16:59:05 +0100 Subject: Use String instead of int for declaration IDs --- .../java/org/zwobble/couscous/interpreter/Environment.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/main/java/org/zwobble/couscous/interpreter/Environment.java') 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 thisValue; - private final Map stackFrame; + private final Map 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); } -- cgit v1.2.3