diff --git a/lib/fOOrth/compiler.rb b/lib/fOOrth/compiler.rb index 8ac456b..1bf8a84 100644 --- a/lib/fOOrth/compiler.rb +++ b/lib/fOOrth/compiler.rb @@ -52,7 +52,7 @@ module XfOOrth #Append text to the compile buffer. def <<(text) - puts " Append=#{text.inspect}" if @debug + dbg_puts " Append=#{text.inspect}" @buffer << text end diff --git a/lib/fOOrth/compiler/modes.rb b/lib/fOOrth/compiler/modes.rb index c90c31c..31e01c8 100644 --- a/lib/fOOrth/compiler/modes.rb +++ b/lib/fOOrth/compiler/modes.rb @@ -13,7 +13,7 @@ module XfOOrth #
Note: #* Adds a nested context level to be un-nested at a later point. def begin_compile_mode(ctrl, defs={}, &action) - puts " begin_compile_mode" if debug + dbg_puts " begin_compile_mode" @context.check_set(:mode, [:execute]) @context = Context.new(@context, mode: :compile, ctrl: ctrl, action: action) @context.merge(defs) @@ -29,7 +29,7 @@ module XfOOrth #
Note: #* Un-nests a context level. def end_compile_mode(ctrls, tags) - puts " end_compile_mode" if debug + dbg_puts " end_compile_mode" @context.check_set(:ctrl, ctrls) source, @buffer = "lambda {|vm| #{@buffer} }", nil result = instance_exec(self, source, tags, &@context[:action]) @@ -43,7 +43,7 @@ module XfOOrth #
Note: #* Adds a nested context level to be un-nested at a later point. def suspend_compile_mode(ctrl) - puts " suspend_compile_mode" if debug + dbg_puts " suspend_compile_mode" @context.check_set(:mode, [:compile]) @context = Context.new(@context, mode: :execute, ctrl: ctrl) end @@ -55,7 +55,7 @@ module XfOOrth #
Note: #* Un-nests a context level. def resume_compile_mode(ctrls) - puts " resume_compile_mode" if debug + dbg_puts " resume_compile_mode" @context.check_set(:ctrl, ctrls) @context = @context.previous end @@ -69,7 +69,7 @@ module XfOOrth #
Note: #* Adds a nested context level to be un-nested at a later point. def suspend_execute_mode(text, ctrl) - puts " suspend_execute_mode" if debug + dbg_puts " suspend_execute_mode" @context = Context.new(@context, ctrl: ctrl) if @context[:mode] == :execute @@ -98,7 +98,7 @@ module XfOOrth #
Note: #* Un-nests a context level. def resume_execute_mode(text, ctrls) - puts " resume_execute_mode" if debug + dbg_puts " resume_execute_mode" check_deferred_mode(text, ctrls) @context = @context.previous diff --git a/lib/fOOrth/compiler/process.rb b/lib/fOOrth/compiler/process.rb index cf64cdc..9507cfb 100644 --- a/lib/fOOrth/compiler/process.rb +++ b/lib/fOOrth/compiler/process.rb @@ -13,7 +13,7 @@ module XfOOrth save, @parser = @parser, Parser.new(source) while (token = get_token) - puts token.to_s if @debug + dbg_puts token.to_s code = token.code if (@context[:mode] == :execute) || ((token.has_tag?(:immediate)) && (!@force)) diff --git a/lib/fOOrth/debug.rb b/lib/fOOrth/debug.rb index 36a288e..e8a213c 100644 --- a/lib/fOOrth/debug.rb +++ b/lib/fOOrth/debug.rb @@ -1,3 +1,8 @@ # coding: utf-8 require_relative 'debug/display_abort' +require_relative 'debug/dbg_puts' + +#Set up the default debug conduit. +$foorth_dbg = $stdout + diff --git a/lib/fOOrth/debug/dbg_puts.rb b/lib/fOOrth/debug/dbg_puts.rb new file mode 100644 index 0000000..e2f77ed --- /dev/null +++ b/lib/fOOrth/debug/dbg_puts.rb @@ -0,0 +1,15 @@ +# coding: utf-8 + +#* dbg_puts.rb - Display diagnostic/debug information if enabled. +module XfOOrth + + #* dbg_puts.rb - Display diagnostic/debug information if enabled. + class VirtualMachine + def dbg_puts(*args) + $foorth_dbg.puts(*args) if debug + end + + end + +end + diff --git a/lib/fOOrth/library/compile_library.rb b/lib/fOOrth/library/compile_library.rb index 825d1e4..097e640 100644 --- a/lib/fOOrth/library/compile_library.rb +++ b/lib/fOOrth/library/compile_library.rb @@ -13,7 +13,7 @@ module XfOOrth type = VmSpec begin_compile_mode(':', vm: vm, &lambda {|vm, src, tags| - puts "#{name} => #{src}" if vm.debug + vm.dbg_puts "#{name} => #{src}" target.create_shared_method(name, type, tags, &eval(src)) }) @@ -30,7 +30,7 @@ module XfOOrth type = XfOOrth.name_to_type(name) vm.begin_compile_mode('.:', cls: target, &lambda {|vm, src, tags| - puts "#{target.name} #{name} => #{src}" if vm.debug + vm.dbg_puts "#{target.foorth_name} #{name} => #{src}" target.create_shared_method(name, type, tags, &eval(src)) }) @@ -46,7 +46,7 @@ module XfOOrth type = XfOOrth.name_to_type(name) vm.begin_compile_mode('.::', obj: target, &lambda {|vm, src, tags| - puts "#{target.name} #{name} => #{src}" if vm.debug + vm.dbg_puts "#{target.foorth_name} {name} => #{src}" target.create_exclusive_method(name, type, tags, &eval(src)) }) diff --git a/reek.txt b/reek.txt index 9234575..e6a2c9f 100644 --- a/reek.txt +++ b/reek.txt @@ -1,3 +1,2 @@ -lib/fOOrth/compiler/modes.rb -- 1 warning: - [16, 32, 46, 58, 72, 101]:XfOOrth::VirtualMachine tests debug at least 6 times (RepeatedConditional) -1 total warning + +0 total warnings