From 0efdd00332faf50a41200522d3e59dc6046d71e1 Mon Sep 17 00:00:00 2001 From: Peter Camilleri Date: Thu, 29 Jan 2015 13:59:39 -0500 Subject: [PATCH] Added the )vm method for debug. --- lib/fOOrth/compiler/console.rb | 6 ++++++ lib/fOOrth/compiler/file_source.rb | 6 ++++++ lib/fOOrth/compiler/read_point.rb | 3 +++ lib/fOOrth/debug.rb | 1 + lib/fOOrth/debug/vm_dump.rb | 26 ++++++++++++++++++++++++++ lib/fOOrth/library/command_library.rb | 9 ++++----- reek.txt | 6 ++++-- test.foorth | 5 +++++ 8 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 lib/fOOrth/debug/vm_dump.rb create mode 100644 test.foorth diff --git a/lib/fOOrth/compiler/console.rb b/lib/fOOrth/compiler/console.rb index f9f66b8..d69c505 100644 --- a/lib/fOOrth/compiler/console.rb +++ b/lib/fOOrth/compiler/console.rb @@ -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 diff --git a/lib/fOOrth/compiler/file_source.rb b/lib/fOOrth/compiler/file_source.rb index a17751e..4e3f37d 100644 --- a/lib/fOOrth/compiler/file_source.rb +++ b/lib/fOOrth/compiler/file_source.rb @@ -11,6 +11,7 @@ module XfOOrth #
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 diff --git a/lib/fOOrth/compiler/read_point.rb b/lib/fOOrth/compiler/read_point.rb index 529869c..172451f 100644 --- a/lib/fOOrth/compiler/read_point.rb +++ b/lib/fOOrth/compiler/read_point.rb @@ -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 diff --git a/lib/fOOrth/debug.rb b/lib/fOOrth/debug.rb index 30dc59a..2bf1d8b 100644 --- a/lib/fOOrth/debug.rb +++ b/lib/fOOrth/debug.rb @@ -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 diff --git a/lib/fOOrth/debug/vm_dump.rb b/lib/fOOrth/debug/vm_dump.rb new file mode 100644 index 0000000..6dd78e0 --- /dev/null +++ b/lib/fOOrth/debug/vm_dump.rb @@ -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 diff --git a/lib/fOOrth/library/command_library.rb b/lib/fOOrth/library/command_library.rb index 0e0eebd..0e36345 100644 --- a/lib/fOOrth/library/command_library.rb +++ b/lib/fOOrth/library/command_library.rb @@ -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 diff --git a/reek.txt b/reek.txt index e6a2c9f..9660196 100644 --- a/reek.txt +++ b/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 diff --git a/test.foorth b/test.foorth new file mode 100644 index 0000000..4a4ebbe --- /dev/null +++ b/test.foorth @@ -0,0 +1,5 @@ +// A general test file for fOOrth. +// Used in non-specific interactive tests. + +)vm cr cr )vm! cr +