stop pinning self and frame
before: r0-message , r1-self , r2-frame , r3-new_message , r4 + tmps now: r0-message , r1-new_message , r2 + tmps programs got smaller, less fuss also fix in return implementation that got the address from the wrong message
This commit is contained in:
@ -3,6 +3,7 @@ module Register
|
||||
module Builtin
|
||||
module Integer
|
||||
module ClassMethods
|
||||
include AST::Sexp
|
||||
def plus c
|
||||
plus_function = Virtual::MethodSource.create_method(:Integer,:Integer,:plus , [:Integer] )
|
||||
plus_function.source.set_return_type :Integer
|
||||
@ -11,8 +12,12 @@ module Register
|
||||
tmp = Register.tmp_reg :Integer
|
||||
index = Register.arg_index 1
|
||||
plus_function.source.add_code Register.get_slot( plus_function , :message , index , tmp )
|
||||
add = Register::OperatorInstruction.new( plus_function, :add , Register.self_reg(:Integer) , tmp )
|
||||
|
||||
me = Register.tmp_reg :Integer
|
||||
plus_function.source.add_code Register.get_slot(plus_function , :message , :receiver , me )
|
||||
add = Register::OperatorInstruction.new( plus_function, :add , me , tmp )
|
||||
plus_function.source.add_code add
|
||||
plus_function.source.add_code Register.set_slot(plus_function , me , :message , :return_value )
|
||||
return plus_function
|
||||
end
|
||||
|
||||
|
@ -13,12 +13,13 @@ module Register
|
||||
function.source.blocks.last.codes.pop # no Method return
|
||||
#Set up the Space as self upon init
|
||||
space = Parfait::Space.object_space
|
||||
function.source.add_code LoadConstant.new(function, space , Register.self_reg(:Space))
|
||||
space_reg = Register.tmp_reg(:Space)
|
||||
function.source.add_code LoadConstant.new(function, space , space_reg)
|
||||
message_ind = Register.resolve_index( :space , :first_message )
|
||||
# Load the message to new message register (r3)
|
||||
function.source.add_code Register.get_slot( function , :self , message_ind , :new_message)
|
||||
# Load the message to new message register (r1)
|
||||
function.source.add_code Register.get_slot( function , space_reg , message_ind , :new_message)
|
||||
# And store the space as the new self (so the call can move it back as self)
|
||||
function.source.add_code Register.set_slot( function, :self , :new_message , :receiver)
|
||||
function.source.add_code Register.set_slot( function, space_reg , :new_message , :receiver)
|
||||
# now we are set up to issue a call to the main
|
||||
function.source.add_code Virtual::MethodCall.new(Virtual.machine.space.get_main)
|
||||
emit_syscall( function , :exit )
|
||||
@ -63,8 +64,6 @@ module Register
|
||||
# save the return value into the message
|
||||
function.source.add_code Register.set_slot( function, return_tmp , :message , :return_value )
|
||||
# and "unroll" self and frame
|
||||
function.source.add_code Register.get_slot(function, :message , :receiver, :self )
|
||||
function.source.add_code Register.get_slot(function, :message , :frame , :frame)
|
||||
end
|
||||
end
|
||||
extend ClassMethods
|
||||
|
@ -4,6 +4,7 @@ module Register
|
||||
module ClassMethods
|
||||
def putstring context
|
||||
function = Virtual::MethodSource.create_method(:Word,:Integer , :putstring , [] )
|
||||
function.source.add_code Register.get_slot( function , :message , :receiver , :new_message )
|
||||
Kernel.emit_syscall( function , :putstring )
|
||||
function
|
||||
end
|
||||
|
Reference in New Issue
Block a user