polish sources

This commit is contained in:
Torsten Ruger 2015-10-29 22:31:28 +02:00
parent 7d7b7ca995
commit 7e24f63327
5 changed files with 16 additions and 14 deletions

View File

@ -6,21 +6,22 @@ module Register
# it isn't really a function, ie it is jumped to (not called), exits and may not return
# so it is responsible for initial setup
def __init__ context
source = "Kernel.__init__"
compiler = Soml::Compiler.new.create_method(:Kernel,:__init__ , [])
# no method enter or return (automatically added), remove
new_start = Label.new("__init__" , "__init__" )
new_start = Label.new(source , source )
compiler.method.instructions = new_start
compiler.set_current new_start
#Set up the Space as self upon init
space = Parfait::Space.object_space
space_reg = Register.tmp_reg(:Space)
compiler.add_code LoadConstant.new("__init__", space , space_reg)
compiler.add_code LoadConstant.new(source, space , space_reg)
message_ind = Register.resolve_index( :space , :first_message )
# Load the message to new message register (r1)
compiler.add_code Register.get_slot( "__init__" , space_reg , message_ind , :new_message)
compiler.add_code Register.get_slot( source , space_reg , message_ind , :new_message)
# And store the space as the new self (so the call can move it back as self)
compiler.add_code Register.set_slot( "__init__", space_reg , :new_message , :receiver)
compiler.add_code Register.set_slot( source, space_reg , :new_message , :receiver)
# now we are set up to issue a call to the main
Register.issue_call( compiler , Register.machine.space.get_main)
emit_syscall( compiler , :exit )
@ -36,7 +37,7 @@ module Register
def emit_syscall compiler , name
save_message( compiler )
compiler.add_code Syscall.new("emit_syscall", name )
compiler.add_code Syscall.new("emit_syscall(#{name})", name )
restore_message(compiler)
end

View File

@ -3,7 +3,6 @@ module Register
# collect anything that is in the space but and reachable from init
module Collector
def collect
# init= Parfait::Space.object_space.get_class_by_name("Kernel").get_instance_method "__init__"
self.objects.clear
keep Parfait::Space.object_space , 0
constants.each {|o| keep(o,0)}

View File

@ -16,9 +16,10 @@ module Register
end
def self.issue_call compiler , callee
source = "_issue_call(#{callee.name})"
# move the current new_message to message
compiler.add_code RegisterTransfer.new("__call__", Register.new_message_reg , Register.message_reg )
compiler.add_code RegisterTransfer.new(source, Register.new_message_reg , Register.message_reg )
# do the register call
compiler.add_code FunctionCall.new( "__call__" , callee )
compiler.add_code FunctionCall.new( source , callee )
end
end

View File

@ -63,7 +63,7 @@ module Register
def boot
boot_parfait!
@init = Branch.new( "__init__" , self.space.get_init.instructions )
@init = Branch.new( "__initial_branch__" , self.space.get_init.instructions )
@booted = true
self
end

View File

@ -82,16 +82,17 @@ module Soml
# message shuffle and FunctionReturn for the return
# return self for chaining
def init_method
@method.instructions = Register::Label.new("_init_method_", "#{method.for_class.name}_#{method.name}")
source = "Complier.init_method"
@method.instructions = Register::Label.new(source, "#{method.for_class.name}_#{method.name}")
@current = method.instructions
add_code enter = Register.save_return("_init_method_", :message , :return_address)
add_code Register::Label.new( "_init_method_", "return")
add_code enter = Register.save_return(source, :message , :return_address)
add_code Register::Label.new( source, "return")
# move the current message to new_message
add_code Register::RegisterTransfer.new("_init_method_", Register.message_reg , Register.new_message_reg )
add_code Register::RegisterTransfer.new(source, Register.message_reg , Register.new_message_reg )
# and restore the message from saved value in new_message
add_code Register.get_slot("_init_method_",:new_message , :caller , :message )
#load the return address into pc, affecting return. (other cpus have commands for this, but not arm)
add_code Register::FunctionReturn.new( "_init_method_" , Register.new_message_reg , Register.resolve_index(:message , :return_address) )
add_code Register::FunctionReturn.new( source , Register.new_message_reg , Register.resolve_index(:message , :return_address) )
@current = enter
self
end