aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/couscous/interpreter/Environment.java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-10-06 16:24:37 +0100
committerMichael Williamson <mike@zwobble.org>2015-10-06 16:24:37 +0100
commite6f463257720bee91a1b4954d97684dbb3398cbf (patch)
treec8d1f04dfe8928d33361108aefee7e7572dae1c7 /src/main/java/org/zwobble/couscous/interpreter/Environment.java
parent9685c8fb7fa14d5b75d828f8443dd948715ac4af (diff)
Add support for constructors and fields
Diffstat (limited to 'src/main/java/org/zwobble/couscous/interpreter/Environment.java')
-rw-r--r--src/main/java/org/zwobble/couscous/interpreter/Environment.java15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/main/java/org/zwobble/couscous/interpreter/Environment.java b/src/main/java/org/zwobble/couscous/interpreter/Environment.java
index 6da54ce..0bbc808 100644
--- a/src/main/java/org/zwobble/couscous/interpreter/Environment.java
+++ b/src/main/java/org/zwobble/couscous/interpreter/Environment.java
@@ -19,16 +19,25 @@ import lombok.val;
public class Environment {
private final Project project;
+ private final Optional<InterpreterValue> thisValue;
private final Map<Integer, VariableEntry> stackFrame;
- public Environment(Project project, Map<VariableDeclaration, Optional<InterpreterValue>> stackFrame) {
+ public Environment(
+ Project project,
+ Optional<InterpreterValue> thisValue,
+ Map<VariableDeclaration, Optional<InterpreterValue>> stackFrame) {
this.project = project;
+ this.thisValue = thisValue;
this.stackFrame = stackFrame.entrySet()
.stream()
.collect(toMap(
entry -> entry.getKey().getId(),
entry -> VariableEntry.of(entry.getKey().getType(), entry.getValue())));
}
+
+ public Optional<InterpreterValue> getThis() {
+ return thisValue;
+ }
public InterpreterValue get(int variableId) {
checkVariableIsInScope(variableId);
@@ -51,8 +60,8 @@ public class Environment {
return project.findClass(className);
}
- public Environment withStackFrame(Map<VariableDeclaration, Optional<InterpreterValue>> stackFrame) {
- return new Environment(project, stackFrame);
+ public Environment withStackFrame(Optional<InterpreterValue> thisValue, Map<VariableDeclaration, Optional<InterpreterValue>> stackFrame) {
+ return new Environment(project, thisValue, stackFrame);
}
private void checkVariableIsInScope(int variableId) {