just moving code around

This commit is contained in:
Torsten Ruger 2014-06-24 19:34:36 +03:00
parent 98de7404ef
commit 3771f44e62
3 changed files with 28 additions and 24 deletions

View File

@ -6,7 +6,7 @@ module Boot
# set/get instance variable use it. # set/get instance variable use it.
# This is just a placeholder, as we code this in ruby, but the instance methods need the definition before. # This is just a placeholder, as we code this in ruby, but the instance methods need the definition before.
def index_of context , name = Vm::Integer def index_of context , name = Vm::Integer
index_function = Vm::Function.new(:index_of , Vm::Integer , [Vm::Integer] , Vm::Integer ) index_function = Vm::Function.new(:index_of , Vm::Reference , [Vm::Reference] , Vm::Integer )
return index_function return index_function
end end
@ -21,26 +21,29 @@ module Boot
# i = self.index_of(var) # i = self.index_of(var)
# return at_index(i) # return at_index(i)
# end # end
# The at_index is just "below" the api, somehting we need but don't want to expose, so we can't code the above in ruby # The at_index is just "below" the api, something we need but don't want to expose, so we can't code the above in ruby
def _get_instance_variable context , name = Vm::Integer def _get_instance_variable context , name = Vm::Integer
get_function = Vm::Function.new(:_get_instance_variable , Vm::Integer , [ Vm::Integer ] , Vm::Integer ) get_function = Vm::Function.new(:_get_instance_variable , Vm::Reference , [ Vm::Reference ] , Vm::Mystery )
me = get_function.receiver me = get_function.receiver
var_name = get_function.args.first var_name = get_function.args.first
return_to = get_function.return_type return_to = get_function.return_type
index_function = context.object_space.get_or_create_class(:Object).resolve_function(:index_of) index_function = context.object_space.get_or_create_class(:Object).resolve_function(:index_of)
get_function.push( [me] ) get_function.push( [me] )
get_function.call( index_function ) index = get_function.call( index_function )
after_body = get_function.new_block("after_index")
after_body = get_function.new_block("after_index")
get_function.insert_at after_body get_function.insert_at after_body
get_function.pop([me]) get_function.pop([me])
return_to.at_index( get_function , me , return_to ) return_to.at_index( get_function , me , return_to )
get_function.set_return return_to get_function.set_return return_to
return get_function return get_function
end end
def _set_instance_variable(context , name = Vm::Integer , value = Vm::Integer ) def _set_instance_variable(context , name = Vm::Integer , value = Vm::Integer )
set_function = Vm::Function.new(:_set_instance_variable , Vm::Integer , [ Vm::Integer , Vm::Integer] , Vm::Integer ) set_function = Vm::Function.new(:_set_instance_variable , Vm::Reference ,[Vm::Reference ,Vm::Reference], Vm::Mystery )
me = set_function.receiver me = set_function.receiver
var_name = set_function.args.first var_name = set_function.args.first
return_to = set_function.return_type return_to = set_function.return_type

View File

@ -21,10 +21,6 @@ module Vm
block.cmp( self , right ) block.cmp( self , right )
Vm::BranchCondition.new :lt Vm::BranchCondition.new :lt
end end
def at_index block , left , right
block.ldr( self , left , right )
self
end
def plus block , first , right def plus block , first , right
block.add( self , left , right ) block.add( self , left , right )
self self
@ -42,20 +38,6 @@ module Vm
Vm::BranchCondition.new :eq Vm::BranchCondition.new :eq
end end
def load block , right
if(right.is_a? IntegerConstant)
block.mov( self , right ) #move the value
elsif right.is_a? StringConstant
block.add( self , right , nil) #move the address, by "adding" to pc, ie pc relative
block.mov( Integer.new(self.register.next_reg_use) , right.length ) #and the length HACK TODO
elsif right.is_a?(Boot::BootClass) or right.is_a?(Boot::MetaClass)
block.add( self , right , nil) #move the address, by "adding" to pc, ie pc relative
else
raise "unknown #{right.inspect}"
end
self
end
def is_true? function def is_true? function
function.cmp( self , 0 ) function.cmp( self , 0 )
Vm::BranchCondition.new :ne Vm::BranchCondition.new :ne

View File

@ -7,5 +7,24 @@ module Vm
end end
attr_accessor :clazz attr_accessor :clazz
def load block , right
if(right.is_a? IntegerConstant)
block.mov( self , right ) #move the value
elsif right.is_a? StringConstant
block.add( self , right , nil) #move the address, by "adding" to pc, ie pc relative
block.mov( Integer.new(self.register.next_reg_use) , right.length ) #and the length HACK TODO
elsif right.is_a?(Boot::BootClass) or right.is_a?(Boot::MetaClass)
block.add( self , right , nil) #move the address, by "adding" to pc, ie pc relative
else
raise "unknown #{right.inspect}"
end
self
end
def at_index block , left , right
block.ldr( self , left , right )
self
end
end end
end end