From 001af3f8b676466ffd51f0121275c278d15d3b2f Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 5 May 2015 14:04:37 +0300 Subject: [PATCH] reviving more tests --- lib/compiler.rb | 9 +++++++-- lib/compiler/basic_expressions.rb | 6 +++--- lib/virtual/slot.rb | 6 +++--- test/test_all.rb | 2 +- test/virtual/test_all.rb | 2 +- test/virtual/test_basic.rb | 21 +++++++++++---------- test/virtual/virtual_helper.rb | 10 ++++------ 7 files changed, 30 insertions(+), 26 deletions(-) diff --git a/lib/compiler.rb b/lib/compiler.rb index ce186997..fc89c5df 100644 --- a/lib/compiler.rb +++ b/lib/compiler.rb @@ -2,8 +2,13 @@ module Compiler def self.compile expression , method , message exp_name = expression.class.name.split("::").last.sub("Expression","").downcase - puts "Expression #{exp_name}" - self.send "compile_#{exp_name}".to_sym , expression, method , message + #puts "Expression #{exp_name}" + begin + self.send "compile_#{exp_name}".to_sym , expression, method , message + rescue NoMethodError => e + puts exp_name + raise e + end end end diff --git a/lib/compiler/basic_expressions.rb b/lib/compiler/basic_expressions.rb index c5ed1a7a..6b935e3b 100644 --- a/lib/compiler/basic_expressions.rb +++ b/lib/compiler/basic_expressions.rb @@ -12,7 +12,7 @@ module Compiler # attr_reader :value def self.compile_integer expession , method , message - int = Virtual::IntegerConstant.new(value) + int = Virtual::IntegerConstant.new(expession.value) to = Virtual::NewReturn.new(Virtual::Integer , int) method.add_code Virtual::Set.new( to , int) to @@ -41,14 +41,14 @@ module Compiler # attr_reader :name # compiling name needs to check if it's a variable and if so resolve it - # otherwise it's a method without args and a send is ussued. + # otherwise it's a method without args and a send is usued. # this makes the namespace static, ie when eval and co are implemented method needs recompilation def self.compile_name expession , method , message return Virtual::Self.new( Virtual::Mystery ) if expession.name == :self if method.has_var(expession.name) message.compile_get(method , expession.name ) else - raise "Unimplemented #{self}" + raise "TODO unimplemented branch #{expession.class}(#{expession})" message.compile_send( method , expession.name , Virtual::Self.new( Virtual::Mystery ) ) end end diff --git a/lib/virtual/slot.rb b/lib/virtual/slot.rb index 1cc8f101..a4c82294 100644 --- a/lib/virtual/slot.rb +++ b/lib/virtual/slot.rb @@ -5,10 +5,10 @@ module Virtual # - the frame of the method that is executing (local variables): FrameSlot # - self as an object: SelfSlot # - a message that will be sent, NewMessageSlot - + # additionally frame, self and return are slots in Message and NewMessage - class Slot + class Slot < Object MESSAGE_REGISTER = :r0 SELF_REGISTER = :r1 FRAME_REGISTER = :r2 @@ -31,7 +31,7 @@ module Virtual @value = value end end - + class MessageSlot < Slot def initialize index , type = Mystery , value = nil super(index ,type , value ) diff --git a/test/test_all.rb b/test/test_all.rb index c9558b3a..bde765c7 100644 --- a/test/test_all.rb +++ b/test/test_all.rb @@ -2,4 +2,4 @@ require_relative "arm/test_all" require "parfait/hash_test" -#require_relative "virtual/test_all" +require_relative "virtual/test_all" diff --git a/test/virtual/test_all.rb b/test/virtual/test_all.rb index a5131f50..ece649a6 100644 --- a/test/virtual/test_all.rb +++ b/test/virtual/test_all.rb @@ -1,2 +1,2 @@ require_relative "test_basic" -require_relative "test_methods" +#require_relative "test_methods" diff --git a/test/virtual/test_basic.rb b/test/virtual/test_basic.rb index 706728b2..b92d3d40 100644 --- a/test/virtual/test_basic.rb +++ b/test/virtual/test_basic.rb @@ -5,27 +5,28 @@ class TestBasic < MiniTest::Test def test_number @string_input = '42 ' - @output = "---RETURN_MARKER- !ruby/object:Virtual::IntegerConstantRETURN_MARKER integer: 42RETURN_MARKER" + @output = "-Virtual::NewReturn(:index => 5, :type => Virtual::Integer)*^* :value Virtual::IntegerConstant(:integer => 42)" check end def test_true @string_input = 'true ' - @output = "---RETURN_MARKER- !ruby/object:Virtual::TrueConstant {}RETURN_MARKER" + @output = "-Virtual::Return(:index => 5, :type => Virtual::Reference)*^* :value Virtual::TrueConstant(:length => -1)" check end def test_false @string_input = 'false ' - @output = "---RETURN_MARKER- !ruby/object:Virtual::FalseConstant {}RETURN_MARKER" + @output = "-Virtual::Return(:index => 5, :type => Virtual::Reference)*^* :value Virtual::FalseConstant(:length => -1)" check end def test_nil @string_input = 'nil ' - @output = "---RETURN_MARKER- !ruby/object:Virtual::NilConstant {}RETURN_MARKER" + @output = "-Virtual::Return(:index => 5, :type => Virtual::Reference)*^* :value Virtual::NilConstant(:length => -1)" check end - def test_name + def pest_name + #TODO @string_input = 'foo ' @output = "---RETURN_MARKER- !ruby/object:Virtual::ReturnRETURN_MARKER name: :returnRETURN_MARKER type: !ruby/class 'Virtual::Mystery'RETURN_MARKER" check @@ -33,17 +34,17 @@ class TestBasic < MiniTest::Test def test_self @string_input = 'self ' - @output = "---RETURN_MARKER- !ruby/object:Virtual::SelfRETURN_MARKER name: :selfRETURN_MARKER type: !ruby/object:Virtual::Mystery {}RETURN_MARKER" + @output = "-Virtual::Self(:index => 3, :type => Virtual::Mystery)" check end def test_instance_variable @string_input = '@foo_bar ' - @output = "---RETURN_MARKER- !ruby/object:Virtual::ReturnRETURN_MARKER name: :returnRETURN_MARKER type: !ruby/object:Virtual::Mystery {}RETURN_MARKER" + @output = "-Virtual::NewReturn(:index => 5, :type => Virtual::Mystery)" check end - def test_module_name + def pest_module_name @string_input = 'FooBar ' @output = "---RETURN_MARKER- &1 !ruby/object:Boot::BootClassRETURN_MARKER instance_methods: []RETURN_MARKER name: :FooBarRETURN_MARKER super_class_name: :ObjectRETURN_MARKER meta_class: !ruby/object:Boot::MetaClassRETURN_MARKER functions: []RETURN_MARKER me_self: *1RETURN_MARKER" check @@ -51,8 +52,8 @@ class TestBasic < MiniTest::Test def test_string @string_input = "\"hello\"" - @output = "---RETURN_MARKER- !ruby/object:Virtual::StringConstantRETURN_MARKER string: helloRETURN_MARKER" + @output = "-Virtual::Return(:index => 5, :type => Virtual::Reference)*^* :value Virtual::StringConstant(:string => 'hello')" check end -end \ No newline at end of file +end diff --git a/test/virtual/virtual_helper.rb b/test/virtual/virtual_helper.rb index 867fc3c0..7e927ec2 100644 --- a/test/virtual/virtual_helper.rb +++ b/test/virtual/virtual_helper.rb @@ -3,7 +3,7 @@ require 'parslet/convenience' require "yaml" module VirtualHelper - # need a code generator, for arm + # need a code generator, for arm def setup # @object_space = Boot::BootSpace.new "Arm" end @@ -11,10 +11,8 @@ module VirtualHelper def check 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" + Sof::Writer.write(expressions) - puts "" - puts Sof::Writer.write(expressions) + is = Sof::Writer.write(expressions).gsub("\n" , "*^*") + assert_equal is , @output end - + end