introducing references

This commit is contained in:
Torsten Ruger
2014-06-14 23:48:12 +03:00
parent 4db54a760e
commit a68d84a781
6 changed files with 14 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -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