From c9bf89dd6c62dfd77dfae30bfe515a89d168aa13 Mon Sep 17 00:00:00 2001 From: Peter Camilleri Date: Wed, 29 Oct 2014 15:43:12 -0400 Subject: [PATCH] Core refactor for VM. --- integration/class_library_tests.rb | 2 +- integration/vm_library_tests.rb | 33 ++++++++++++++++++++++++++++++ lib/fOOrth/core.rb | 2 -- lib/fOOrth/library.rb | 1 + lib/fOOrth/library/vm_library.rb | 15 ++++++++++++++ rakefile.rb | 2 ++ 6 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 integration/vm_library_tests.rb create mode 100644 lib/fOOrth/library/vm_library.rb diff --git a/integration/class_library_tests.rb b/integration/class_library_tests.rb index 73bc44e..4136bec 100644 --- a/integration/class_library_tests.rb +++ b/integration/class_library_tests.rb @@ -22,7 +22,7 @@ class ClassLibraryTester < MiniTest::Unit::TestCase super(*all) end - def test_that_the_object_class_is_available + def test_that_the_class_class_is_available foorth_equal("Class", [XfOOrth.class_class]) end diff --git a/integration/vm_library_tests.rb b/integration/vm_library_tests.rb new file mode 100644 index 0000000..1ff3ff4 --- /dev/null +++ b/integration/vm_library_tests.rb @@ -0,0 +1,33 @@ +# coding: utf-8 + +require_relative '../lib/foorth' +require_relative 'support/foorth_testing' +require 'minitest/autorun' + +#Test the standard fOOrth library. +class VMLibraryTester < MiniTest::Unit::TestCase + + include XfOOrthTestExtensions + + #Special initialize to track rake progress. + def initialize(*all) + $do_this_only_one_time = "" unless defined? $do_this_only_one_time + + if $do_this_only_one_time != __FILE__ + puts + puts "Running test file: #{File.split(__FILE__)[1]}" + $do_this_only_one_time = __FILE__ + end + + super(*all) + end + + def test_that_the_VM_class_and_instance_are_available + foorth_equal("VirtualMachine", [XfOOrth::VirtualMachine]) + + vm = XfOOrth.virtual_machine + foorth_equal("vm", [vm]) + end + + +end diff --git a/lib/fOOrth/core.rb b/lib/fOOrth/core.rb index 31304b6..6c0ea6d 100644 --- a/lib/fOOrth/core.rb +++ b/lib/fOOrth/core.rb @@ -72,8 +72,6 @@ module XfOOrth #Everything after this point should be re-factored elsewhere! - @object_class.create_shared_method('VirtualMachine', MacroWordSpec, - ["vm.push(VirtualMachine); "]) #========================================================================== # Define some core methods. diff --git a/lib/fOOrth/library.rb b/lib/fOOrth/library.rb index 7c0f3f8..2d4accd 100644 --- a/lib/fOOrth/library.rb +++ b/lib/fOOrth/library.rb @@ -2,6 +2,7 @@ require_relative 'library/object_library' require_relative 'library/class_library' +require_relative 'library/vm_library' require_relative 'library/compile_library' require_relative 'library/standard_library' require_relative 'library/ctrl_struct_library' diff --git a/lib/fOOrth/library/vm_library.rb b/lib/fOOrth/library/vm_library.rb new file mode 100644 index 0000000..b025a50 --- /dev/null +++ b/lib/fOOrth/library/vm_library.rb @@ -0,0 +1,15 @@ +# coding: utf-8 + +#* library/class_library.rb - The fOOrth Class class library. +module XfOOrth + + #Create a macro to get at the Virtual Machine class. + @object_class.create_shared_method('VirtualMachine', MacroWordSpec, + ["vm.push(VirtualMachine); "]) + + #Create a macro to get at the current virtual machine instance. + VirtualMachine.create_shared_method('vm', MacroWordSpec, + ["vm.push(vm); "]) + + +end diff --git a/rakefile.rb b/rakefile.rb index 0561229..b679a57 100644 --- a/rakefile.rb +++ b/rakefile.rb @@ -31,6 +31,7 @@ RDoc::Task.new do |rdoc| "lib/fOOrth/library.rb", "lib/fOOrth/library/object_library.rb", "lib/fOOrth/library/class_library.rb", + "lib/fOOrth/library/vm_library.rb", "lib/fOOrth/library/compile_library.rb", "lib/fOOrth/library/standard_library.rb", "lib/fOOrth/library/ctrl_struct_library.rb", @@ -101,6 +102,7 @@ Rake::TestTask.new(:integration) do |t| #List out all the test files. t.test_files = ["integration/object_library_tests.rb", "integration/class_library_tests.rb", + "integration/vm_library_tests.rb", "integration/standard_library_tests.rb", "integration/ctrl_struct_library_tests.rb", "integration/compile_library_tests.rb",