Skip to content

Commit

Permalink
Adding reading method
Browse files Browse the repository at this point in the history
Add:  	- Reading null variables and instances
	- Using step interpreter to interpretation


Signed-off-by: Florian Deljarry <[email protected]>
  • Loading branch information
Delja committed Jun 12, 2018
1 parent b8892a6 commit 9b5774b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/interpreter/interpreter.nit
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
# Interpretation of Nit programs
module interpreter

import naive_interpreter
import step_interpreter
import dynamic_loading_ffi
20 changes: 20 additions & 0 deletions src/interpreter/naive_interpreter.nit
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,33 @@ 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
var f = frames.first.as(InterpreterFrame)
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]

Expand Down

0 comments on commit 9b5774b

Please sign in to comment.