diff --git a/lib/boot/meta_class.rb b/lib/boot/meta_class.rb index 97cc43fb..d77a1553 100644 --- a/lib/boot/meta_class.rb +++ b/lib/boot/meta_class.rb @@ -19,7 +19,7 @@ module Boot # in a non-booting version this should map to _add_singleton_method def add_function function - raise "not a function #{function}" unless function.is_a? Function + raise "not a function #{function}" unless function.is_a? Vm::Function raise "syserr " unless function.name.is_a? Symbol @functions << function end diff --git a/lib/boot/object.rb b/lib/boot/object.rb index e8c85f9b..52ada4d2 100644 --- a/lib/boot/object.rb +++ b/lib/boot/object.rb @@ -10,6 +10,11 @@ module Boot return index_function end + def self.layout + layout_function = Vm::Function.new(:layout , Vm::Reference , [ ] , Vm::Reference ) + layout_function.at_index 2 + layout_function + end # in ruby, how this goes is # def _get_instance_variable var diff --git a/lib/kernel/string.rb b/lib/kernel/string.rb index c7584c76..f9aeda93 100644 --- a/lib/kernel/string.rb +++ b/lib/kernel/string.rb @@ -1,7 +1,7 @@ module Crystal module Kernel def self.putstring context - function = Vm::Function.new(:putstring , Vm::Integer , [] ) + function = Vm::Function.new(:putstring , Vm::Reference , [] ) ret = Vm::RegisterMachine.instance.write_stdout(function) function.set_return ret function diff --git a/lib/vm/function.rb b/lib/vm/function.rb index 2384161b..95cc243b 100644 --- a/lib/vm/function.rb +++ b/lib/vm/function.rb @@ -28,13 +28,14 @@ module Vm class Function < Code - def initialize(name , receiver = Vm::Integer , args = [] , return_type = Vm::Integer) + def initialize(name , receiver = Vm::Reference , args = [] , return_type = Vm::Reference) super() @name = name.to_sym if receiver.is_a?(Value) @receiver = receiver raise "arg in non std register #{receiver.inspect}" unless RegisterMachine.instance.receiver_register == receiver.register_symbol else + puts receiver.inspect @receiver = receiver.new(RegisterMachine.instance.receiver_register) end @@ -63,7 +64,7 @@ module Vm @insert_at end def set_return type_or_value - @return_type = type_or_value || Vm::Integer + @return_type = type_or_value || Vm::Reference if @return_type.is_a?(Value) raise "return in non std register #{@return_type.inspect}" unless RegisterMachine.instance.return_register == @return_type.register_symbol else diff --git a/lib/vm/values/integer.rb b/lib/vm/values/integer.rb index 0239d738..9d880f11 100644 --- a/lib/vm/values/integer.rb +++ b/lib/vm/values/integer.rb @@ -1,7 +1,7 @@ module Vm class Integer < Word # needs to be here as Word's constructor is private (to make it abstract) - def initilize reg + def initialize reg super end @@ -33,7 +33,7 @@ module Vm block.sub( self , left , right ) self end - def left_shift block , first , right + def left_shift block , left , right block.mov( self , left , shift_lsr: right ) self end diff --git a/lib/vm/values/reference.rb b/lib/vm/values/reference.rb index 11740850..a2c86772 100644 --- a/lib/vm/values/reference.rb +++ b/lib/vm/values/reference.rb @@ -1,7 +1,7 @@ module Vm - class Reference + class Reference < Word # needs to be here as Word's constructor is private (to make it abstract) - def initilize reg + def initialize reg super end