adding returns to all builtins

This commit is contained in:
Torsten Ruger 2018-04-01 15:17:16 +03:00
parent def67205f0
commit 972cf47c8b
5 changed files with 22 additions and 8 deletions

View File

@ -20,6 +20,7 @@ module Risc
end
def putint(context)
compiler = compiler_for(:Integer,:putint ,{})
compiler.add_mom( Mom::ReturnSequence.new)
return compiler.method
end

View File

@ -15,12 +15,13 @@ module Risc
compiler.add_slot_to_reg( source , me , index , me)
# and put it back into the return value
compiler.add_reg_to_slot( source , me , :message , :return_value)
compiler.add_mom( Mom::ReturnSequence.new)
return compiler.method
end
# self[index] = val basically. Index is the first arg , value the second
# no return
def set_internal_word context
def set_internal_word( context )
compiler = compiler_for(:Object , :set_internal_word , {at: :Integer, :value => :Object} )
source = "set_internal_word"
me , index = compiler.self_and_int_arg(source)
@ -28,6 +29,7 @@ module Risc
# do the set
compiler.add_reg_to_slot( source , value , me , index)
compiler.add_mom( Mom::ReturnSequence.new)
return compiler.method
end

View File

@ -10,8 +10,9 @@ module Risc
# main entry point, ie __init__ calls this
# defined here as empty, to be redefined
def main context
def main(context)
compiler = compiler_for(:Space , :main ,{args: :Integer})
compiler.add_mom( Mom::ReturnSequence.new)
return compiler.method
end

View File

@ -4,19 +4,20 @@ module Risc
module ClassMethods
include CompileHelper
def putstring context
def putstring( context)
compiler = compiler_for(:Word , :putstring ,{})
compiler.add_slot_to_reg( "putstring" , :message , :receiver , :new_message )
index = Parfait::Word.get_length_index
reg = RiscValue.new(:r2 , :Integer)
compiler.add_slot_to_reg( "putstring" , :new_message , index , reg )
Kernel.emit_syscall( compiler , :putstring )
compiler.add_mom( Mom::ReturnSequence.new)
compiler.method
end
# self[index] basically. Index is the first arg > 0
# return (and word sized int) is stored in return_value
def get_internal_byte context
def get_internal_byte( context)
compiler = compiler_for(:Word , :get_internal_byte , {at: :Integer})
source = "get_internal_byte"
me , index = compiler.self_and_int_arg(source)
@ -24,13 +25,14 @@ module Risc
compiler.add_byte_to_reg( source , me , index , me)
# and put it back into the return value
compiler.add_reg_to_slot( source , me , :message , :return_value)
compiler.add_mom( Mom::ReturnSequence.new)
return compiler.method
end
# self[index] = val basically. Index is the first arg ( >0),
# value the second
# no return
def set_internal_byte context
def set_internal_byte( context)
compiler = compiler_for(:Word, :set_internal_byte , {at: :Integer , :value => :Integer} )
args = compiler.method.arguments
len = args.instance_length
@ -40,6 +42,7 @@ module Risc
value = compiler.load_int_arg_at(source , 2 )
# do the set
compiler.add_reg_to_byte( source , value , me , index)
compiler.add_mom( Mom::ReturnSequence.new)
return compiler.method
end
@ -50,11 +53,12 @@ module Risc
# ( ie the snake bites it's tail)
# This method is just a placeholder until boot is over and the real method is
# parsed.
def resolve_method context
def resolve_method( context)
compiler = compiler_for(:Word, :resolve_method , {:value => :Object} )
args = compiler.method.arguments
len = args.instance_length
raise "Compiler arg number mismatch, method=#{args} " if len != 2
compiler.add_mom( Mom::ReturnSequence.new)
return compiler.method
end

View File

@ -24,8 +24,14 @@ module Risc
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
SlotToReg, LoadConstant, FunctionCall, Label, Label,
NilClass]
SlotToReg, LoadConstant, FunctionCall, Label, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, FunctionReturn,
SlotToReg, LoadConstant, RegToSlot, Label, LoadConstant,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
SlotToReg]
#assert_equal 1 , get_return
end