From 8effcc866a62eb544eeeb8959244c0834d574554 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 30 Jul 2014 21:43:12 +0300 Subject: [PATCH] more machinery to the machine --- lib/parfait/object.rb | 2 ++ lib/virtual/machine.rb | 19 ++++++++++++++++--- test/virtual/virtual_helper.rb | 6 ++---- 3 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 lib/parfait/object.rb diff --git a/lib/parfait/object.rb b/lib/parfait/object.rb new file mode 100644 index 00000000..5ac0e951 --- /dev/null +++ b/lib/parfait/object.rb @@ -0,0 +1,2 @@ +class Object +end diff --git a/lib/virtual/machine.rb b/lib/virtual/machine.rb index 90805766..442d8241 100644 --- a/lib/virtual/machine.rb +++ b/lib/virtual/machine.rb @@ -42,13 +42,26 @@ module Virtual def self.boot machine = Machine.new machine.boot + machine end - def read string - syntax = @parser.parse_with_debug(string) - Parser::Transform.new.apply(syntax) + def boot + # read all the files needed for a minimal system at compile + classes = ["object"] + classes.each do |clazz| + bytes = File.read(File.join( File.dirname( __FILE__ ) , ".." , "parfait" , "#{clazz}.rb") ) +# expression = compile_main(bytes) + end end + def compile_main bytes + syntax = @parser.parse_with_debug(bytes) + parts = Parser::Transform.new.apply(syntax) + main = Virtual::MethodDefinition.main + expressions = parts.compile( main , self.message ) + end + + # run the instruction stream given. Instructions are a graph and executing means traversing it. # If there is no next instruction the machine stops def run instruction diff --git a/test/virtual/virtual_helper.rb b/test/virtual/virtual_helper.rb index 7bb8cc0b..05787c5c 100644 --- a/test/virtual/virtual_helper.rb +++ b/test/virtual/virtual_helper.rb @@ -8,10 +8,8 @@ module VirtualHelper end def check - machine = Virtual::Machine.new - parts = machine.read @string_input - main = Virtual::MethodDefinition.main - expressions = parts.compile( main, machine.message ) + machine = Virtual::Machine.boot + expressions = machine.compile_main @string_input should = YAML.load(@output.gsub("RETURN_MARKER" , "\n")) assert_equal should , expressions , expressions.to_yaml.gsub("\n" , "RETURN_MARKER") + "\n" + expressions.to_yaml end