From 9680ff2a71f7cd4da13c608738837ce43ef727b1 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 4 Aug 2015 21:46:33 +0300 Subject: [PATCH] fxes for add test --- Gemfile | 4 ++-- Gemfile.lock | 13 ++++++------- lib/register/builtin/integer.rb | 8 ++++++++ lib/virtual/compiler/function_expression.rb | 2 +- lib/virtual/instructions/message_send.rb | 4 ++++ lib/virtual/machine.rb | 1 + lib/virtual/passes/send_implementation.rb | 7 ++++++- lib/virtual/slots/slot.rb | 3 +++ test/compiler/test_methods.rb | 13 +++++++++++-- 9 files changed, 42 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index 6ffe0bab..c4cc378d 100644 --- a/Gemfile +++ b/Gemfile @@ -4,8 +4,8 @@ gem "salama" , :path => "." gem "rake" -gem "salama-reader" , :github => "salama/salama-reader" -#gem "salama-reader" , :path => "../salama-reader" +#gem "salama-reader" , :github => "salama/salama-reader" +gem "salama-reader" , :path => "../salama-reader" gem "salama-object-file" , :github => "salama/salama-object-file" #gem "salama-object-file" , :path => "../salama-object-file" gem "salama-arm" , :github => "salama/salama-arm" diff --git a/Gemfile.lock b/Gemfile.lock index f71d9a4d..d2473b78 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,13 +10,6 @@ GIT specs: salama-object-file (0.2.0) -GIT - remote: git://github.com/salama/salama-reader.git - revision: 841592c667acea1e796f950851262e6938b231bc - specs: - salama-reader (0.2.0) - parslet (~> 1.7.0) - PATH remote: . specs: @@ -24,6 +17,12 @@ PATH salama-object-file (~> 0.2) salama-reader (~> 0.2) +PATH + remote: ../salama-reader + specs: + salama-reader (0.2.0) + parslet (~> 1.7.0) + GEM remote: http://rubygems.org/ specs: diff --git a/lib/register/builtin/integer.rb b/lib/register/builtin/integer.rb index e3173dbd..58ef7a6e 100644 --- a/lib/register/builtin/integer.rb +++ b/lib/register/builtin/integer.rb @@ -3,6 +3,14 @@ module Register module Builtin module Integer module ClassMethods + def plus c + plus_function = Virtual::MethodSource.create_method(:Integer,:plus , [Virtual::Integer] ) + plus_function.source.return_type = Virtual::Integer + plus_function.source.receiver = Virtual::Integer + plus_function.source.add_code Register::Math.new( plus_function, :add , 0 ) + + return plus_function + end # The conversion to base10 is quite a bit more complicated than i thought. # The bulk of it is in div10 # We set up variables, do the devision and write the result to the string diff --git a/lib/virtual/compiler/function_expression.rb b/lib/virtual/compiler/function_expression.rb index 859f5fd1..4bc81cc7 100644 --- a/lib/virtual/compiler/function_expression.rb +++ b/lib/virtual/compiler/function_expression.rb @@ -12,7 +12,7 @@ module Virtual if( r.value.is_a? Parfait::Class ) class_name = r.value.name else - raise "unimplemented #{r}" + raise "unimplemented case in function #{r}" end else r = Self.new() diff --git a/lib/virtual/instructions/message_send.rb b/lib/virtual/instructions/message_send.rb index d3902a28..65526ce8 100644 --- a/lib/virtual/instructions/message_send.rb +++ b/lib/virtual/instructions/message_send.rb @@ -7,6 +7,10 @@ module Virtual @args = args end attr_reader :name , :me , :args + + def to_s + "MessageSend.new(:#{name} , #{me} , #{args})" + end end end diff --git a/lib/virtual/machine.rb b/lib/virtual/machine.rb index 41b60b02..19736996 100644 --- a/lib/virtual/machine.rb +++ b/lib/virtual/machine.rb @@ -134,6 +134,7 @@ module Virtual def compile_main bytes syntax = @parser.parse_with_debug(bytes) parts = Parser::Transform.new.apply(syntax) + #puts parts.to_s Compiler.compile( parts , @space.get_main ) end diff --git a/lib/virtual/passes/send_implementation.rb b/lib/virtual/passes/send_implementation.rb index 688c9f8e..b1b32b63 100644 --- a/lib/virtual/passes/send_implementation.rb +++ b/lib/virtual/passes/send_implementation.rb @@ -19,7 +19,7 @@ module Virtual if(ref.value) me = ref.value if( me.is_a? Parfait::Class ) - raise "unimplemented #{code}" + raise "unimplemented #{code} me is #{me}" elsif( me.is_a? Parfait::Object ) # get the function from my class. easy peasy puts "Me is #{me.class}" @@ -31,6 +31,11 @@ module Virtual method = Virtual.machine.space.get_class_by_name(:Word).get_instance_method(code.name) raise "Method not implemented #{me.class}.#{code.name}" unless method new_codes << MethodCall.new( method ) + elsif( me.is_a? Fixnum ) + # get the function from my class. easy peasy + method = Virtual.machine.space.get_class_by_name(:Integer).get_instance_method(code.name) + raise "Method not implemented #{me.class}.#{code.name}" unless method + new_codes << MethodCall.new( method ) else # note: this is the current view: call internal send, even the method name says else # but send is "special" and accesses the internal method name and resolves. diff --git a/lib/virtual/slots/slot.rb b/lib/virtual/slots/slot.rb index a83f5d5a..df2af5ea 100644 --- a/lib/virtual/slots/slot.rb +++ b/lib/virtual/slots/slot.rb @@ -27,6 +27,9 @@ module Virtual attr_accessor :type , :value + def to_s + "#{self.class.name}.new(#{type}, #{value})" + end private #abstract base class def initialize type , value diff --git a/test/compiler/test_methods.rb b/test/compiler/test_methods.rb index ac923051..17a7412e 100644 --- a/test/compiler/test_methods.rb +++ b/test/compiler/test_methods.rb @@ -81,13 +81,22 @@ HERE check end - def ttest_function_ops_simple + def test_function_ops_simple @string_input = <