adding returns to all builtins
This commit is contained in:
parent
def67205f0
commit
972cf47c8b
@ -20,6 +20,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
def putint(context)
|
def putint(context)
|
||||||
compiler = compiler_for(:Integer,:putint ,{})
|
compiler = compiler_for(:Integer,:putint ,{})
|
||||||
|
compiler.add_mom( Mom::ReturnSequence.new)
|
||||||
return compiler.method
|
return compiler.method
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -15,12 +15,13 @@ module Risc
|
|||||||
compiler.add_slot_to_reg( source , me , index , me)
|
compiler.add_slot_to_reg( source , me , index , me)
|
||||||
# and put it back into the return value
|
# and put it back into the return value
|
||||||
compiler.add_reg_to_slot( source , me , :message , :return_value)
|
compiler.add_reg_to_slot( source , me , :message , :return_value)
|
||||||
|
compiler.add_mom( Mom::ReturnSequence.new)
|
||||||
return compiler.method
|
return compiler.method
|
||||||
end
|
end
|
||||||
|
|
||||||
# self[index] = val basically. Index is the first arg , value the second
|
# self[index] = val basically. Index is the first arg , value the second
|
||||||
# no return
|
# no return
|
||||||
def set_internal_word context
|
def set_internal_word( context )
|
||||||
compiler = compiler_for(:Object , :set_internal_word , {at: :Integer, :value => :Object} )
|
compiler = compiler_for(:Object , :set_internal_word , {at: :Integer, :value => :Object} )
|
||||||
source = "set_internal_word"
|
source = "set_internal_word"
|
||||||
me , index = compiler.self_and_int_arg(source)
|
me , index = compiler.self_and_int_arg(source)
|
||||||
@ -28,6 +29,7 @@ module Risc
|
|||||||
|
|
||||||
# do the set
|
# do the set
|
||||||
compiler.add_reg_to_slot( source , value , me , index)
|
compiler.add_reg_to_slot( source , value , me , index)
|
||||||
|
compiler.add_mom( Mom::ReturnSequence.new)
|
||||||
return compiler.method
|
return compiler.method
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -10,8 +10,9 @@ module Risc
|
|||||||
|
|
||||||
# main entry point, ie __init__ calls this
|
# main entry point, ie __init__ calls this
|
||||||
# defined here as empty, to be redefined
|
# defined here as empty, to be redefined
|
||||||
def main context
|
def main(context)
|
||||||
compiler = compiler_for(:Space , :main ,{args: :Integer})
|
compiler = compiler_for(:Space , :main ,{args: :Integer})
|
||||||
|
compiler.add_mom( Mom::ReturnSequence.new)
|
||||||
return compiler.method
|
return compiler.method
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -4,19 +4,20 @@ module Risc
|
|||||||
module ClassMethods
|
module ClassMethods
|
||||||
include CompileHelper
|
include CompileHelper
|
||||||
|
|
||||||
def putstring context
|
def putstring( context)
|
||||||
compiler = compiler_for(:Word , :putstring ,{})
|
compiler = compiler_for(:Word , :putstring ,{})
|
||||||
compiler.add_slot_to_reg( "putstring" , :message , :receiver , :new_message )
|
compiler.add_slot_to_reg( "putstring" , :message , :receiver , :new_message )
|
||||||
index = Parfait::Word.get_length_index
|
index = Parfait::Word.get_length_index
|
||||||
reg = RiscValue.new(:r2 , :Integer)
|
reg = RiscValue.new(:r2 , :Integer)
|
||||||
compiler.add_slot_to_reg( "putstring" , :new_message , index , reg )
|
compiler.add_slot_to_reg( "putstring" , :new_message , index , reg )
|
||||||
Kernel.emit_syscall( compiler , :putstring )
|
Kernel.emit_syscall( compiler , :putstring )
|
||||||
|
compiler.add_mom( Mom::ReturnSequence.new)
|
||||||
compiler.method
|
compiler.method
|
||||||
end
|
end
|
||||||
|
|
||||||
# self[index] basically. Index is the first arg > 0
|
# self[index] basically. Index is the first arg > 0
|
||||||
# return (and word sized int) is stored in return_value
|
# 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})
|
compiler = compiler_for(:Word , :get_internal_byte , {at: :Integer})
|
||||||
source = "get_internal_byte"
|
source = "get_internal_byte"
|
||||||
me , index = compiler.self_and_int_arg(source)
|
me , index = compiler.self_and_int_arg(source)
|
||||||
@ -24,13 +25,14 @@ module Risc
|
|||||||
compiler.add_byte_to_reg( source , me , index , me)
|
compiler.add_byte_to_reg( source , me , index , me)
|
||||||
# and put it back into the return value
|
# and put it back into the return value
|
||||||
compiler.add_reg_to_slot( source , me , :message , :return_value)
|
compiler.add_reg_to_slot( source , me , :message , :return_value)
|
||||||
|
compiler.add_mom( Mom::ReturnSequence.new)
|
||||||
return compiler.method
|
return compiler.method
|
||||||
end
|
end
|
||||||
|
|
||||||
# self[index] = val basically. Index is the first arg ( >0),
|
# self[index] = val basically. Index is the first arg ( >0),
|
||||||
# value the second
|
# value the second
|
||||||
# no return
|
# no return
|
||||||
def set_internal_byte context
|
def set_internal_byte( context)
|
||||||
compiler = compiler_for(:Word, :set_internal_byte , {at: :Integer , :value => :Integer} )
|
compiler = compiler_for(:Word, :set_internal_byte , {at: :Integer , :value => :Integer} )
|
||||||
args = compiler.method.arguments
|
args = compiler.method.arguments
|
||||||
len = args.instance_length
|
len = args.instance_length
|
||||||
@ -40,6 +42,7 @@ module Risc
|
|||||||
value = compiler.load_int_arg_at(source , 2 )
|
value = compiler.load_int_arg_at(source , 2 )
|
||||||
# do the set
|
# do the set
|
||||||
compiler.add_reg_to_byte( source , value , me , index)
|
compiler.add_reg_to_byte( source , value , me , index)
|
||||||
|
compiler.add_mom( Mom::ReturnSequence.new)
|
||||||
return compiler.method
|
return compiler.method
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -50,11 +53,12 @@ module Risc
|
|||||||
# ( ie the snake bites it's tail)
|
# ( ie the snake bites it's tail)
|
||||||
# This method is just a placeholder until boot is over and the real method is
|
# This method is just a placeholder until boot is over and the real method is
|
||||||
# parsed.
|
# parsed.
|
||||||
def resolve_method context
|
def resolve_method( context)
|
||||||
compiler = compiler_for(:Word, :resolve_method , {:value => :Object} )
|
compiler = compiler_for(:Word, :resolve_method , {:value => :Object} )
|
||||||
args = compiler.method.arguments
|
args = compiler.method.arguments
|
||||||
len = args.instance_length
|
len = args.instance_length
|
||||||
raise "Compiler arg number mismatch, method=#{args} " if len != 2
|
raise "Compiler arg number mismatch, method=#{args} " if len != 2
|
||||||
|
compiler.add_mom( Mom::ReturnSequence.new)
|
||||||
return compiler.method
|
return compiler.method
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -24,8 +24,14 @@ module Risc
|
|||||||
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
|
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
|
||||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
||||||
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
|
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
|
||||||
SlotToReg, LoadConstant, FunctionCall, Label, Label,
|
SlotToReg, LoadConstant, FunctionCall, Label, SlotToReg,
|
||||||
NilClass]
|
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
|
#assert_equal 1 , get_return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user