From 22b1fea587bb005451d6f2415af6958101d92f54 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 1 Jul 2018 11:59:07 +0300 Subject: [PATCH] use rubyc_compiler as instance not as before class methods so we can carry the state around --- lib/rubyx/rubyx_compiler.rb | 22 ++++++++++++++-------- test/rubyx/helper.rb | 5 +++-- test/support/compiling.rb | 9 +++++++-- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/lib/rubyx/rubyx_compiler.rb b/lib/rubyx/rubyx_compiler.rb index 99f9a759..ff8d262f 100644 --- a/lib/rubyx/rubyx_compiler.rb +++ b/lib/rubyx/rubyx_compiler.rb @@ -2,24 +2,30 @@ require_relative "ruby_compiler" module RubyX class RubyXCompiler + attr_reader :source - def self.ruby_to_vool( ruby_source ) - vool = RubyCompiler.compile( ruby_source ) + def initialize(source) + @source = source + end + + def ruby_to_vool + vool = RubyCompiler.compile( source ) vool = vool.normalize vool end - def self.ruby_to_mom( ruby_source ) - vool = self.ruby_to_vool(ruby_source) + def ruby_to_mom + vool = ruby_to_vool vool.to_mom(nil) end - def self.ruby_to_binary(source , platform = :arm) + def ruby_to_binary(platform = :arm) Parfait.boot! machine = Risc.machine.boot - mom = ruby_to_mom(source) - #mom.translate(platform) - machine.translate(platform) + mom = ruby_to_mom + puts "MOM #{mom.class}" + mom.translate(platform) + #machine.translate(platform) machine.position_all machine.create_binary end diff --git a/test/rubyx/helper.rb b/test/rubyx/helper.rb index 2605b0e0..574e9628 100644 --- a/test/rubyx/helper.rb +++ b/test/rubyx/helper.rb @@ -8,13 +8,14 @@ module RubyX end def ruby_to_risc(input , platform) mom = ruby_to_mom(input) + puts "MOM #{mom.class}" mom.translate(platform) end def ruby_to_vool(input) - RubyXCompiler.ruby_to_vool(input) + RubyXCompiler.new(input).ruby_to_vool end def ruby_to_mom(input) - RubyXCompiler.ruby_to_mom(input) + RubyXCompiler.new(input).ruby_to_mom end def compile_in_test input vool = ruby_to_vool in_Test(input) diff --git a/test/support/compiling.rb b/test/support/compiling.rb index 2fe2931d..0c77d72a 100644 --- a/test/support/compiling.rb +++ b/test/support/compiling.rb @@ -22,7 +22,7 @@ module MomCompile include ScopeHelper def compile_mom(input) - statements = RubyX::RubyXCompiler.ruby_to_vool input + statements = RubyX::RubyXCompiler.new(input).ruby_to_vool res = statements.to_mom(nil) assert_equal Parfait::Class , statements.clazz.class , statements @method = statements.clazz.get_method(:main) @@ -31,7 +31,12 @@ module MomCompile end def compile_first_method( input ) res = compile_mom( as_test_main( input )) - res.clazz.instance_methods.first.compile_to_mom(res.clazz.instance_type) + method = res.clazz.instance_methods.first + compile_to_mom(method , res.clazz.instance_type) + end + def compile_to_mom(method , for_type) + typed_method = create_typed_method(for_type) + source.to_mom( typed_method ) end def check_array( should , is )