Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/core/kernel.nit
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ interface Object
#
# Without redefinition, `hash` is based on the `object_id` of the instance.
fun hash: Int do return object_id

# Method catch by the interpreter to display the object value and to start the step-by-step execution.
#
# This method MUST not be used by programs, it is here for debugging in the interpreter
fun inspect_o is intern
end

# The main class of the program.
Expand Down
5 changes: 5 additions & 0 deletions share/man/nit.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ Each time a method is invoked for the first time, its information is printed on

This option helps the user to have a simplified but humanly readable overview of the behavior of a particular program execution.

### `--break`
Start the program to indicate the breakpoints for the interpretation.

Print the menu to add or remove some breakpoint

## DEBUGGER OPTIONS

### `-d`
Expand Down
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
23 changes: 23 additions & 0 deletions src/interpreter/naive_interpreter.nit
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ private import frontend::explain_assert_api
redef class ToolContext
# --discover-call-trace
var opt_discover_call_trace = new OptionBool("Trace calls of the first invocation of methods", "--discover-call-trace")
# --stop-at
var opt_stop = new OptionBool("Start the program to indicate the breakpoints for the interpretation","--break")

redef init
do
super
self.option_context.add_option(self.opt_discover_call_trace)
self.option_context.add_option(self.opt_stop)
end
end

Expand Down Expand Up @@ -446,13 +449,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
Loading