diff --git a/lib/risc.rb b/lib/risc.rb index 7bb1654f..62a9646e 100644 --- a/lib/risc.rb +++ b/lib/risc.rb @@ -37,5 +37,5 @@ end require_relative "risc/instruction" require_relative "risc/risc_value" require_relative "risc/text_writer" -require_relative "risc/builtin/space" +require_relative "risc/builtin" require_relative "risc/builder" diff --git a/lib/risc/boot.rb b/lib/risc/boot.rb index f1315fc6..49e62c18 100644 --- a/lib/risc/boot.rb +++ b/lib/risc/boot.rb @@ -60,7 +60,7 @@ module Risc Parfait.set_object_space( space ) #puts Rfx.write(space) - boot_functions( space ) + Builtin.boot_functions( ) end # types is where the snake bites its tail. Every chain ends at a type and then it @@ -159,36 +159,5 @@ module Risc } end - # classes have booted, now create a minimal set of functions - # minimal means only that which can not be coded in ruby - # Methods are grabbed from respective modules by sending the method name. This should return the - # implementation of the method (ie a method object), not actually try to implement it - # (as that's impossible in ruby) - def boot_functions( space ) - # very fiddly chicken 'n egg problem. Functions need to be in the right order, and in fact we - # have to define some dummies, just for the others to compile - # TODO go through the virtual parfait layer and adjust function names to what they really are - space_class = space.get_class - space_class.instance_type.add_method Builtin::Space.send(:main, nil) - - obj = space.get_class_by_name(:Object) - [ :get_internal_word , :set_internal_word , :_method_missing, - :exit , :__init__].each do |f| - obj.instance_type.add_method Builtin::Object.send(f , nil) - end - - obj = space.get_class_by_name(:Word) - [:putstring , :get_internal_byte , :set_internal_byte ].each do |f| - obj.instance_type.add_method Builtin::Word.send(f , nil) - end - - obj = space.get_class_by_name(:Integer) - Risc.operators.each do |op| - obj.instance_type.add_method Builtin::Integer.operator_method(op) - end - [:putint, :div4, :div10 , :<,:<= , :>=, :>].each do |f| #div4 is just a forward declaration - obj.instance_type.add_method Builtin::Integer.send(f , nil) - end - end end end diff --git a/lib/risc/builtin.rb b/lib/risc/builtin.rb new file mode 100644 index 00000000..feb2fd77 --- /dev/null +++ b/lib/risc/builtin.rb @@ -0,0 +1,44 @@ +require_relative "builtin/compile_helper" +require_relative "builtin/space" +require_relative "builtin/integer" +require_relative "builtin/object" +require_relative "builtin/word" + +module Risc + module Builtin + # classes have booted, now create a minimal set of functions + # minimal means only that which can not be coded in ruby + # Methods are grabbed from respective modules by sending the method name. + # This should return the implementation of the method (ie a method object), + # not actually try to implement it(as that's impossible in ruby) + # + def self.boot_functions( ) + space = Parfait.object_space + # very fiddly chicken 'n egg problem. Functions need to be in the right order, and in fact we + # have to define some dummies, just for the others to compile + # TODO go through the virtual parfait layer and adjust function names to what they really are + space_class = space.get_class + space_class.instance_type.add_method Builtin::Space.send(:main, nil) + + obj = space.get_class_by_name(:Object) + [ :get_internal_word , :set_internal_word , :_method_missing, + :exit , :__init__].each do |f| + obj.instance_type.add_method Builtin::Object.send(f , nil) + end + + obj = space.get_class_by_name(:Word) + [:putstring , :get_internal_byte , :set_internal_byte ].each do |f| + obj.instance_type.add_method Builtin::Word.send(f , nil) + end + + obj = space.get_class_by_name(:Integer) + Risc.operators.each do |op| + obj.instance_type.add_method Builtin::Integer.operator_method(op) + end + [:putint, :div4, :div10 , :<,:<= , :>=, :>].each do |f| #div4 is just a forward declaration + obj.instance_type.add_method Builtin::Integer.send(f , nil) + end + end + + end +end diff --git a/lib/risc/builtin/space.rb b/lib/risc/builtin/space.rb index ccfe9758..3a236fb3 100644 --- a/lib/risc/builtin/space.rb +++ b/lib/risc/builtin/space.rb @@ -1,11 +1,8 @@ -require "ast/sexp" -require_relative "compile_helper" module Risc module Builtin class Space module ClassMethods - include AST::Sexp include CompileHelper # main entry point, ie __init__ calls this @@ -21,7 +18,3 @@ module Risc end end end - -require_relative "integer" -require_relative "object" -require_relative "word"