mirror of
https://github.com/PeterCamilleri/fOOrth
synced 2024-11-16 07:47:56 +01:00
Added the )vm method for debug.
This commit is contained in:
parent
2047973598
commit
0efdd00332
8 changed files with 55 additions and 7 deletions
|
@ -45,5 +45,11 @@ module XfOOrth
|
|||
|
||||
'>' * vm.context.depth + '"' * vm.quotes
|
||||
end
|
||||
|
||||
#What is the source of this text?
|
||||
def source_name
|
||||
"The console."
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,6 +11,7 @@ module XfOOrth
|
|||
#<br>Parameters:
|
||||
#* name - The name of the file with the fOOrth source code.
|
||||
def initialize(name)
|
||||
@name = name
|
||||
@file = File.new(name, "r")
|
||||
@read_step = @file.each_line
|
||||
super()
|
||||
|
@ -22,6 +23,11 @@ module XfOOrth
|
|||
super()
|
||||
end
|
||||
|
||||
#What is the source of this text?
|
||||
def source_name
|
||||
"A file: #{@name}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -6,6 +6,9 @@ module XfOOrth
|
|||
#This module is used to facilitate the reading
|
||||
#of source code text from a buffer.
|
||||
module ReadPoint
|
||||
#Get the current line of text being read.
|
||||
attr_reader :read_buffer
|
||||
|
||||
#Reset the read point to the initial conditions. Namely,
|
||||
#no text in the buffer and not at end of line,
|
||||
def reset_read_point
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
require_relative 'debug/display_abort'
|
||||
require_relative 'debug/dbg_puts'
|
||||
require_relative 'debug/context_dump'
|
||||
require_relative 'debug/vm_dump'
|
||||
|
||||
#Set up the default debug conduit.
|
||||
$foorth_dbg = $stdout
|
||||
|
|
26
lib/fOOrth/debug/vm_dump.rb
Normal file
26
lib/fOOrth/debug/vm_dump.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
# coding: utf-8
|
||||
|
||||
#* debug/vm_dump.rb - Debug support for the virtual machine.
|
||||
module XfOOrth
|
||||
|
||||
#Debug support for the virtual machine.
|
||||
class VirtualMachine
|
||||
|
||||
#Dump the virtual machine to the console for debug.
|
||||
def debug_dump
|
||||
puts "\n#{self.foorth_name}"
|
||||
puts " Ruby = #{self.to_s}"
|
||||
puts " Stack = #{@data_stack.inspect}"
|
||||
puts " Nesting = #{@context.depth}"
|
||||
puts " Quotes = #{@quotes}"
|
||||
puts " Debug = #{@debug}"
|
||||
puts " Show = #{@show_stack}"
|
||||
puts " Force = #{@force}"
|
||||
puts " Start = #{@start_time}"
|
||||
puts " Source = #{@parser.source.source_name}"
|
||||
puts " Buffer = #{@parser.source.read_buffer.inspect}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -39,6 +39,10 @@ module XfOOrth
|
|||
|
||||
#Dump the virtual machine.
|
||||
VirtualMachine.create_shared_method(')vm', VmSpec, [],
|
||||
&lambda {|vm| vm.debug_dump })
|
||||
|
||||
#Dump the virtual machine right NOW!
|
||||
VirtualMachine.create_shared_method(')vm!', VmSpec, [:immediate],
|
||||
&lambda {|vm| pp vm })
|
||||
|
||||
#Map a symbol entry
|
||||
|
@ -53,11 +57,6 @@ module XfOOrth
|
|||
puts "#{str} <= #{(SymbolMap.unmap(str.to_sym).to_s)}"
|
||||
})
|
||||
|
||||
|
||||
#Dump the virtual machine right NOW!
|
||||
VirtualMachine.create_shared_method(')vm!', VmSpec, [:immediate],
|
||||
&lambda {|vm| pp vm })
|
||||
|
||||
#Load the file as source code.
|
||||
VirtualMachine.create_shared_method(')load"', VmSpec, [], &lambda{|vm|
|
||||
start_time = Time.now
|
||||
|
|
6
reek.txt
6
reek.txt
|
@ -1,2 +1,4 @@
|
|||
|
||||
0 total warnings
|
||||
lib/fOOrth/debug/vm_dump.rb -- 2 warnings:
|
||||
[20, 21]:XfOOrth::VirtualMachine#debug_dump calls @parser.source twice (DuplicateMethodCall)
|
||||
[10]:XfOOrth::VirtualMachine#debug_dump has approx 11 statements (TooManyStatements)
|
||||
2 total warnings
|
||||
|
|
5
test.foorth
Normal file
5
test.foorth
Normal file
|
@ -0,0 +1,5 @@
|
|||
// A general test file for fOOrth.
|
||||
// Used in non-specific interactive tests.
|
||||
|
||||
)vm cr cr )vm! cr
|
||||
|
Loading…
Reference in a new issue