Added the )vm method for debug.

This commit is contained in:
Peter Camilleri 2015-01-29 13:59:39 -05:00
parent 2047973598
commit 0efdd00332
8 changed files with 55 additions and 7 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View 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

View file

@ -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

View file

@ -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
View file

@ -0,0 +1,5 @@
// A general test file for fOOrth.
// Used in non-specific interactive tests.
)vm cr cr )vm! cr