introducing references
This commit is contained in:
parent
4db54a760e
commit
a68d84a781
@ -19,7 +19,7 @@ module Boot
|
|||||||
|
|
||||||
# in a non-booting version this should map to _add_singleton_method
|
# in a non-booting version this should map to _add_singleton_method
|
||||||
def add_function function
|
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
|
raise "syserr " unless function.name.is_a? Symbol
|
||||||
@functions << function
|
@functions << function
|
||||||
end
|
end
|
||||||
|
@ -10,6 +10,11 @@ module Boot
|
|||||||
return index_function
|
return index_function
|
||||||
end
|
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
|
# in ruby, how this goes is
|
||||||
# def _get_instance_variable var
|
# def _get_instance_variable var
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
module Crystal
|
module Crystal
|
||||||
module Kernel
|
module Kernel
|
||||||
def self.putstring context
|
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)
|
ret = Vm::RegisterMachine.instance.write_stdout(function)
|
||||||
function.set_return ret
|
function.set_return ret
|
||||||
function
|
function
|
||||||
|
@ -28,13 +28,14 @@ module Vm
|
|||||||
|
|
||||||
class Function < Code
|
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()
|
super()
|
||||||
@name = name.to_sym
|
@name = name.to_sym
|
||||||
if receiver.is_a?(Value)
|
if receiver.is_a?(Value)
|
||||||
@receiver = receiver
|
@receiver = receiver
|
||||||
raise "arg in non std register #{receiver.inspect}" unless RegisterMachine.instance.receiver_register == receiver.register_symbol
|
raise "arg in non std register #{receiver.inspect}" unless RegisterMachine.instance.receiver_register == receiver.register_symbol
|
||||||
else
|
else
|
||||||
|
puts receiver.inspect
|
||||||
@receiver = receiver.new(RegisterMachine.instance.receiver_register)
|
@receiver = receiver.new(RegisterMachine.instance.receiver_register)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -63,7 +64,7 @@ module Vm
|
|||||||
@insert_at
|
@insert_at
|
||||||
end
|
end
|
||||||
def set_return type_or_value
|
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)
|
if @return_type.is_a?(Value)
|
||||||
raise "return in non std register #{@return_type.inspect}" unless RegisterMachine.instance.return_register == @return_type.register_symbol
|
raise "return in non std register #{@return_type.inspect}" unless RegisterMachine.instance.return_register == @return_type.register_symbol
|
||||||
else
|
else
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
module Vm
|
module Vm
|
||||||
class Integer < Word
|
class Integer < Word
|
||||||
# needs to be here as Word's constructor is private (to make it abstract)
|
# needs to be here as Word's constructor is private (to make it abstract)
|
||||||
def initilize reg
|
def initialize reg
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ module Vm
|
|||||||
block.sub( self , left , right )
|
block.sub( self , left , right )
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
def left_shift block , first , right
|
def left_shift block , left , right
|
||||||
block.mov( self , left , shift_lsr: right )
|
block.mov( self , left , shift_lsr: right )
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
module Vm
|
module Vm
|
||||||
class Reference
|
class Reference < Word
|
||||||
# needs to be here as Word's constructor is private (to make it abstract)
|
# needs to be here as Word's constructor is private (to make it abstract)
|
||||||
def initilize reg
|
def initialize reg
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user