Fix div10 without method_missing
but reanimate infer_type to auto create the needed regsiters also some helpers
This commit is contained in:
@ -24,6 +24,20 @@ module Risc
|
||||
@source_used = false
|
||||
end
|
||||
|
||||
# especially for the macros (where register allocation is often manual)
|
||||
# register need to be created. And since the code is "ported" we create
|
||||
# them with the old names, which used the infer_type to infer the type
|
||||
#
|
||||
# Return the RegisterValue with given name and inferred type, compiler set
|
||||
def register( name )
|
||||
RegisterValue.new(name , infer_type(name) ).set_compiler(compiler)
|
||||
end
|
||||
|
||||
# create an add a RegisterTransfer instruction with to and from
|
||||
def transfer(to , from)
|
||||
add_code Risc.transfer(@source, to , from)
|
||||
end
|
||||
|
||||
# Infer the type from a symbol. In the simplest case the symbol is the class name.
|
||||
# But in building, sometimes variations are needed, so next_message or caller work
|
||||
# too (and both return "Message")
|
||||
@ -90,8 +104,8 @@ module Risc
|
||||
return ins
|
||||
end
|
||||
|
||||
def load_object(object)
|
||||
@compiler.load_object(object)
|
||||
def load_object(object , into = nil)
|
||||
@compiler.load_object(object , into)
|
||||
end
|
||||
|
||||
# for some methods that return an integer it is beneficial to pre allocate the
|
||||
|
@ -93,8 +93,9 @@ module Risc
|
||||
# Load a constant, meaning create a LoadConstant instruction for the constant
|
||||
# add the instruction to the code and return the register_value that was created
|
||||
# for further use
|
||||
def load_object( object )
|
||||
ins = Risc.load_constant("load to #{object}" , object)
|
||||
# register may be passed in (epecially in mcro building) as second arg
|
||||
def load_object( object , into = nil)
|
||||
ins = Risc.load_constant("load to #{object}" , object , into)
|
||||
ins.register.set_compiler(self)
|
||||
add_code ins
|
||||
# todo for constants (not objects)
|
||||
|
@ -32,18 +32,21 @@ module Risc
|
||||
end
|
||||
end
|
||||
end
|
||||
def self.load_constant( source , constant )
|
||||
|
||||
def self.load_constant( source , constant , register = nil)
|
||||
value = constant
|
||||
case constant
|
||||
when Parfait::Object
|
||||
type = constant.get_type
|
||||
when Label
|
||||
type = constant.address.get_type
|
||||
else
|
||||
type = constant.ct_type
|
||||
value = constant.value
|
||||
unless register
|
||||
case constant
|
||||
when Parfait::Object
|
||||
type = constant.get_type
|
||||
when Label
|
||||
type = constant.address.get_type
|
||||
else
|
||||
type = constant.ct_type
|
||||
value = constant.value
|
||||
end
|
||||
register = RegisterValue.new( "id_#{value.object_id}".to_sym , type )
|
||||
end
|
||||
register = RegisterValue.new( "id_#{value.object_id}".to_sym , type )
|
||||
LoadConstant.new( source , constant , register )
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user