From 5add9c42f24baf4febe0c6ce368d3d98d2a160e7 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 30 Jul 2014 21:07:48 +0300 Subject: [PATCH] juggle into the machine --- lib/virtual/machine.rb | 11 +++++++++++ test/virtual/virtual_helper.rb | 6 ++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/virtual/machine.rb b/lib/virtual/machine.rb index 4c26dea3..90805766 100644 --- a/lib/virtual/machine.rb +++ b/lib/virtual/machine.rb @@ -33,11 +33,22 @@ module Virtual class Machine def initialize + @parser = Parser::Salama.new the_end = Halt.new @message = Message.new(the_end , the_end , :Object) end attr_reader :message + def self.boot + machine = Machine.new + machine.boot + end + + def read string + syntax = @parser.parse_with_debug(string) + Parser::Transform.new.apply(syntax) + 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 d8fed242..7bb8cc0b 100644 --- a/test/virtual/virtual_helper.rb +++ b/test/virtual/virtual_helper.rb @@ -7,11 +7,9 @@ module VirtualHelper # @object_space = Boot::BootSpace.new "Arm" end - def check - parser = Parser::Salama.new - syntax = parser.parse_with_debug(@string_input) - parts = Parser::Transform.new.apply(syntax) + def check machine = Virtual::Machine.new + parts = machine.read @string_input main = Virtual::MethodDefinition.main expressions = parts.compile( main, machine.message ) should = YAML.load(@output.gsub("RETURN_MARKER" , "\n"))