diff --git a/lib/mom/builtin.rb b/lib/mom/builtin.rb index 4b66bc55..e444d266 100644 --- a/lib/mom/builtin.rb +++ b/lib/mom/builtin.rb @@ -26,7 +26,7 @@ module Mom # # We create an empty main for init to jump to, if no code is compiled, that just returns # See Builtin directory readme and module - def self.boot_functions() + def self.boot_functions( options = {}) # TODO go through the virtual parfait layer and adjust function names # to what they really are compilers = [] diff --git a/lib/mom/mom.rb b/lib/mom/mom.rb index 22e0dbfb..392d7fac 100644 --- a/lib/mom/mom.rb +++ b/lib/mom/mom.rb @@ -13,8 +13,8 @@ module Mom # boot bubiltin function (subject to change) - def self.boot! - Builtin.boot_functions + def self.boot!(options = {}) + Builtin.boot_functions(options) end end diff --git a/lib/mom/mom_collection.rb b/lib/mom/mom_collection.rb index cdb6df5f..5b432aa5 100644 --- a/lib/mom/mom_collection.rb +++ b/lib/mom/mom_collection.rb @@ -42,6 +42,5 @@ module Mom Risc::RiscCollection.new(riscs) end - end end diff --git a/lib/risc.rb b/lib/risc.rb index e2a4c31c..e983631c 100644 --- a/lib/risc.rb +++ b/lib/risc.rb @@ -15,7 +15,7 @@ end # See risc/Readme module Risc # module method to reset, and init - def self.boot! + def self.boot!(options = {}) Position.clear_positions end end diff --git a/lib/ruby/README.md b/lib/ruby/README.md index dc4ef9a0..2c4a9b37 100644 --- a/lib/ruby/README.md +++ b/lib/ruby/README.md @@ -19,11 +19,18 @@ thus "typing" the syntax tree, and making it concrete. ## to Vool -In our nice layers, we are ont the way down to Vool, a simplified version of oo. +In our nice layers, we are on the way down to Vool, a simplified version of oo. It has proven handy to have this layer, so the code for transforming each object is in the class representing that object. (As one does in oo, again imho). +## compile_time_expansions + +We do some expansions at compile time that are in fact methods calls in real ruby. + +First among those will be require (+ require_relative) , but attribute readers +will surely follow. + ## Parfait objects The compilation process ends up creating (parfait) objects to represent diff --git a/lib/rubyx/rubyx_compiler.rb b/lib/rubyx/rubyx_compiler.rb index 25952c0d..3b3e4a4a 100644 --- a/lib/rubyx/rubyx_compiler.rb +++ b/lib/rubyx/rubyx_compiler.rb @@ -25,13 +25,14 @@ module RubyX # class RubyXCompiler - attr_reader :vool + attr_reader :vool , :options # initialize boots Parfait and Risc (ie load Builin) def initialize(options) + @options = options Parfait.boot!(options[:parfait] || {}) - Mom.boot! - Risc.boot! + Mom.boot!(options[:mom] || {}) + Risc.boot!(options[:risc] || {}) end # The highest level function creates binary code for the given ruby code diff --git a/test/mom/test_mom_collection.rb b/test/mom/test_mom_collection.rb index 2adfb8e6..2bd3d00f 100644 --- a/test/mom/test_mom_collection.rb +++ b/test/mom/test_mom_collection.rb @@ -32,7 +32,6 @@ module Mom include MomCompile def setup - Parfait.boot!(Parfait.default_test_options) @comp = compile_mom( "class Test ; def main(); return 'Hi'; end; end;") @collection = @comp.to_risc() end diff --git a/test/vool/class_send/helper.rb b/test/vool/class_send/helper.rb index d1864cc9..9cbfb409 100644 --- a/test/vool/class_send/helper.rb +++ b/test/vool/class_send/helper.rb @@ -7,8 +7,6 @@ module Vool include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) - Risc.boot! @compiler = compile_first_method( send_method ) @ins = @compiler.mom_instructions.next end diff --git a/test/vool/lambdas/test_assign.rb b/test/vool/lambdas/test_assign.rb index e6addf0c..46bd5dcf 100644 --- a/test/vool/lambdas/test_assign.rb +++ b/test/vool/lambdas/test_assign.rb @@ -5,7 +5,6 @@ module VoolBlocks include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) @ins = compile_first_block( "local = 5" ) end def test_block_compiles @@ -31,7 +30,6 @@ module VoolBlocks class TestAssignMomInstanceToLocal < MiniTest::Test include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) @ins = compile_first_block( "local = @a" , "@a = 5") #second arg in method scope end def test_class_compiles @@ -49,7 +47,6 @@ module VoolBlocks include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) @ins = compile_first_block( "arg = 5") end @@ -67,7 +64,6 @@ module VoolBlocks class TestAssignMomToInstance < MiniTest::Test include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) end def test_assigns_const @ins = compile_first_block( "@a = 5") diff --git a/test/vool/lambdas/test_if_condition.rb b/test/vool/lambdas/test_if_condition.rb index 3bd7666c..69b74f9e 100644 --- a/test/vool/lambdas/test_if_condition.rb +++ b/test/vool/lambdas/test_if_condition.rb @@ -5,8 +5,6 @@ module VoolBlocks include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) - Mom::Builtin.boot_functions @ins = compile_first_block( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end") end diff --git a/test/vool/lambdas/test_while_simple.rb b/test/vool/lambdas/test_while_simple.rb index 4219d408..2fbc1ca4 100644 --- a/test/vool/lambdas/test_while_simple.rb +++ b/test/vool/lambdas/test_while_simple.rb @@ -5,7 +5,6 @@ module VoolBlocks include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) @ins = compile_first_block( "while(@a) ; @a = 5 ; end") end diff --git a/test/vool/send/helper.rb b/test/vool/send/helper.rb index b38c46dc..3b455509 100644 --- a/test/vool/send/helper.rb +++ b/test/vool/send/helper.rb @@ -7,8 +7,6 @@ module Vool include Mom def setup - Parfait.boot!(Parfait.default_test_options) - Mom.boot! @compiler = compile_first_method( send_method ) @ins = @compiler.mom_instructions.next end diff --git a/test/vool/send/test_not_found.rb b/test/vool/send/test_not_found.rb index d6ff8134..de62fbf7 100644 --- a/test/vool/send/test_not_found.rb +++ b/test/vool/send/test_not_found.rb @@ -5,7 +5,6 @@ module Vool include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) @compiler = compile_first_method( "5.div8") @ins = @compiler.mom_instructions.next end diff --git a/test/vool/send/test_send_args_send.rb b/test/vool/send/test_send_args_send.rb index 713a9fe6..d847909b 100644 --- a/test/vool/send/test_send_args_send.rb +++ b/test/vool/send/test_send_args_send.rb @@ -5,8 +5,6 @@ module Vool include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) - Risc.boot! @compiler = compile_first_method( "a = main(1 + 2);return a" ) @ins = @compiler.mom_instructions.next end diff --git a/test/vool/test_assignment.rb b/test/vool/test_assignment.rb index 7fe8d1af..89396473 100644 --- a/test/vool/test_assignment.rb +++ b/test/vool/test_assignment.rb @@ -5,7 +5,6 @@ module Vool include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) @compiler = compile_first_method( "local = 5;return") @ins = @compiler.mom_instructions.next end @@ -34,7 +33,6 @@ module Vool class TestAssignMomInstanceToLocal < MiniTest::Test include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) @compiler = compile_first_method( "@a = 5 ; local = @a;return") @ins = @compiler.mom_instructions.next end @@ -48,7 +46,6 @@ module Vool include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) @compiler = compile_first_method( "arg = 5;return") @ins = @compiler.mom_instructions.next end diff --git a/test/vool/test_if_no_else.rb b/test/vool/test_if_no_else.rb index 6e3ba96a..7921839f 100644 --- a/test/vool/test_if_no_else.rb +++ b/test/vool/test_if_no_else.rb @@ -6,7 +6,6 @@ module Vool include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) @compiler = compile_first_method( "if(@a) ; @a = 5 ; end;return") @ins = @compiler.mom_instructions.next end diff --git a/test/vool/test_if_no_if.rb b/test/vool/test_if_no_if.rb index 0b744f3d..1e764d9a 100644 --- a/test/vool/test_if_no_if.rb +++ b/test/vool/test_if_no_if.rb @@ -6,7 +6,6 @@ module Vool include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) @compiler = compile_first_method( "unless(@a) ; @a = 5 ; end;return") @ins = @compiler.mom_instructions.next end diff --git a/test/vool/test_if_simple.rb b/test/vool/test_if_simple.rb index 07e19c2b..b5d97ded 100644 --- a/test/vool/test_if_simple.rb +++ b/test/vool/test_if_simple.rb @@ -6,7 +6,6 @@ module Vool include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) @compiler = compile_first_method( "if(@a) ; @a = 5 ; else; @a = 6 ; end;return") @ins = @compiler.mom_instructions.next end diff --git a/test/vool/test_if_statement.rb b/test/vool/test_if_statement.rb index 108a1d9e..cc3944bc 100644 --- a/test/vool/test_if_statement.rb +++ b/test/vool/test_if_statement.rb @@ -5,7 +5,6 @@ module Vool include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) @compiler = compile_first_method( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end;return") @ins = @compiler.mom_instructions.next end diff --git a/test/vool/test_ivar.rb b/test/vool/test_ivar.rb index 63818ecb..0e33cb0f 100644 --- a/test/vool/test_ivar.rb +++ b/test/vool/test_ivar.rb @@ -5,7 +5,6 @@ module Vool include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) @compiler = compile_first_method( "@a = 5") @ins = @compiler.mom_instructions.next end diff --git a/test/vool/test_local_assignment.rb b/test/vool/test_local_assignment.rb index af706a37..80b203bb 100644 --- a/test/vool/test_local_assignment.rb +++ b/test/vool/test_local_assignment.rb @@ -5,7 +5,6 @@ module Vool include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) @compiler = compile_first_method( "a = 5") @ins = @compiler.mom_instructions.next end diff --git a/test/vool/test_return.rb b/test/vool/test_return.rb index 49cf292a..ab88e041 100644 --- a/test/vool/test_return.rb +++ b/test/vool/test_return.rb @@ -5,7 +5,6 @@ module Vool include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) @compiler = compile_first_method( "return 5") @ins = @compiler.mom_instructions.next end @@ -42,7 +41,6 @@ module Vool include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) @compiler = compile_first_method( "return 5.div4") @ins = @compiler.mom_instructions.next end diff --git a/test/vool/test_while_statement.rb b/test/vool/test_while_statement.rb index 63a393ec..7fbe5048 100644 --- a/test/vool/test_while_statement.rb +++ b/test/vool/test_while_statement.rb @@ -5,7 +5,6 @@ module Vool include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) @compiler = compile_first_method( "while(@a) ; @a = 5 ; end;return") @ins = @compiler.mom_instructions.next end diff --git a/test/vool/test_while_statement1.rb b/test/vool/test_while_statement1.rb index 494d18c4..1119b59d 100644 --- a/test/vool/test_while_statement1.rb +++ b/test/vool/test_while_statement1.rb @@ -6,7 +6,6 @@ module Vool include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) @compiler = compile_first_method( "while(5.div4) ; 5.div4 ; end;return") @ins = @compiler.mom_instructions.next end diff --git a/test/vool/test_yield_statement.rb b/test/vool/test_yield_statement.rb index 9304f26d..1d03e546 100644 --- a/test/vool/test_yield_statement.rb +++ b/test/vool/test_yield_statement.rb @@ -5,7 +5,6 @@ module Vool include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) @compiler = compile_first_method( "return yield(1)" ) @ins = @compiler.mom_instructions.next end @@ -70,7 +69,6 @@ module Vool include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) @compiler = compile_first_method( "return yield(some.extra.calls)" ) @ins = @compiler.mom_instructions.next end