From 9b5774bc2a562c89fd4706a6c1b93923686e7a42 Mon Sep 17 00:00:00 2001 From: Florian Deljarry Date: Tue, 12 Jun 2018 11:11:00 -0400 Subject: [PATCH] Adding reading method Add: - Reading null variables and instances - Using step interpreter to interpretation Signed-off-by: Florian Deljarry --- src/interpreter/interpreter.nit | 2 +- src/interpreter/naive_interpreter.nit | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/interpreter/interpreter.nit b/src/interpreter/interpreter.nit index 63e3ac3387..a000f9a187 100644 --- a/src/interpreter/interpreter.nit +++ b/src/interpreter/interpreter.nit @@ -15,5 +15,5 @@ # Interpretation of Nit programs module interpreter -import naive_interpreter +import step_interpreter import dynamic_loading_ffi diff --git a/src/interpreter/naive_interpreter.nit b/src/interpreter/naive_interpreter.nit index 799c413a0a..7cdceb480f 100644 --- a/src/interpreter/naive_interpreter.nit +++ b/src/interpreter/naive_interpreter.nit @@ -446,6 +446,14 @@ class NaiveInterpreter return f.map[v] end + # Retrieve the value of the variable in the current frame + fun read_null_variable(v: Variable):nullable Instance + do + var f = frames.first.as(InterpreterFrame) + if f.map.has_key(v) then return f.map[v] + return null + end + # Assign the value of the variable in the current frame fun write_variable(v: Variable, value: Instance) do @@ -453,6 +461,18 @@ class NaiveInterpreter f.map[v] = value end + # Retrieve the variable of the Instance in the current frame + fun read_instance(i: nullable Instance): nullable Variable + do + if i != null then + var f = frames.first.as(InterpreterFrame) + for key, value in f.map do + if value == i then return key + end + end + return null + end + # Store known methods, used to trace methods as they are reached var discover_call_trace: Set[MMethodDef] = new HashSet[MMethodDef]