start on reworking sys calls

This commit is contained in:
Torsten Ruger
2015-06-22 22:48:42 +03:00
parent 9c21f4274d
commit 2aba926f1f
7 changed files with 56 additions and 4 deletions

View File

@ -17,7 +17,7 @@ module Builtin
end
def putstring context
function = Virtual::CompiledMethodInfo.create_method(:Kernel , :putstring , [] )
return function
emit_syscall( function , :putstring )
ret = Virtual::RegisterMachine.instance.write_stdout(function)
function.set_return ret
function
@ -35,6 +35,39 @@ module Builtin
function.info.return_type = Virtual::Integer
return function
end
private
def emit_syscall function , name
save_message( function )
function.info.add_code Register::Syscall.new( name )
restore_message(function)
end
# save the current message, as the syscall destroys all context
#
# currently HACKED into the space as a temporary varaible. As the space is a globally
# unique object we can retrieve it from there
# TODO : fix this to use global (later per thread) variable
def save_message(function)
space_tmp = Register::RegisterReference.tmp_reg
ind = Parfait::Space.object_space.get_layout().index_of( :syscall_message )
raise "index not found for :syscall_message" unless ind
function.info.add_code LoadConstant.new( space_tmp , Parfait::Space.object_space )
function.info.add_code << SetSlot.new( Virtual::Slot::MESSAGE_REGISTER , space_tmp , ind)
end
def restore_message(function)
# get the sys return out of the way
return_tmp = Register::RegisterReference.tmp_reg
# load the space into the base register
function.info.add_code RegisterTransfer.new( Virtual::Slot::MESSAGE_REGISTER , return_tmp )
# find the stored message
ind = Parfait::Space.object_space.get_layout().index_of( :syscall_message )
raise "index not found for #{kind}.#{kind.class}" unless ind
# and load it into the base RegisterMachine
function.info.add_code GetSlot.new( Virtual::Slot::MESSAGE_REGISTER , ind , Virtual::Slot::MESSAGE_REGISTER )
# and "unroll" self and frame
function.info.add_code GetSlot.new( slot::MESSAGE_REGISTER , Virtual::SELF_INDEX, slot::SELF_REGISTER )
function.info.add_code GetSlot.new( slot::MESSAGE_REGISTER , Virtual::FRAME_INDEX, slot::FRAME_REGISTER )
end
end
extend ClassMethods
end