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

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

View File

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

View File

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

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