rewrite new_int with builder
This commit is contained in:
parent
86462e238a
commit
55bc9c5273
@ -50,12 +50,12 @@ module Risc
|
||||
# infer the type from a symbol. In the simplest case the sybbol is the class name
|
||||
# But in building sometimes variations are needed, so next_message or caller work
|
||||
# too (and return Message)
|
||||
# A general "_reg" or "_obj" at the end of the name will be removed
|
||||
# A general "_reg"/"_obj" or "_tmp" at the end of the name will be removed
|
||||
# An error is raised if the symbol/object can not be inferred
|
||||
def infer_type( name )
|
||||
as_string = name.to_s
|
||||
parts = as_string.split("_")
|
||||
if(parts.last == "reg" or parts.last == "obj")
|
||||
if(parts.last == "reg" or parts.last == "obj" or parts.last == "tmp")
|
||||
parts.pop
|
||||
as_string = parts.join("_")
|
||||
end
|
||||
@ -97,6 +97,7 @@ module Risc
|
||||
@names[left] = r
|
||||
@names[right] = l
|
||||
end
|
||||
|
||||
# build code using dsl (see __init__ or MessageSetup for examples)
|
||||
# names (that ruby would resolve to a variable/method) are converted
|
||||
# to registers. << means assignment and [] is supported both on
|
||||
@ -123,23 +124,15 @@ module Risc
|
||||
# move a machine int from register "from" to a Parfait::Integer in register "to"
|
||||
# have to grab an integer from space and stick it in the "to" register first.
|
||||
def add_new_int( source , from, to )
|
||||
source += "add_new_int "
|
||||
space = compiler.use_reg(:Space)
|
||||
int = compiler.use_reg(:Integer)
|
||||
space_i = space.resolve_index(:next_integer)
|
||||
add_load_constant( source + "space" , Parfait.object_space , space )
|
||||
add_slot_to_reg( source + "next_i1" , space , space_i , to)
|
||||
add_slot_to_reg( source + "next_i2" , to , int.resolve_index(:next_integer) , int)
|
||||
add_reg_to_slot( source + "store link" , int , space , space_i )
|
||||
add_reg_to_slot( source + "store value" , from , to , Parfait::Integer.integer_index)
|
||||
# build do
|
||||
# space << Parfait.object_space
|
||||
# to << space[:next_integer]
|
||||
# integer << to[:next_integer]
|
||||
# space[:next_integer] << integer
|
||||
# to[Parfait::Integer.integer_index] << from
|
||||
# end
|
||||
|
||||
to.builder = self # esecially div10 comes in without having used builder
|
||||
from.builder = self # not named regs, different regs ==> silent errors
|
||||
build do
|
||||
space << Parfait.object_space
|
||||
to << space[:next_integer]
|
||||
integer_tmp << to[:next_integer]
|
||||
space[:next_integer] << integer_tmp
|
||||
to[Parfait::Integer.integer_index] << from
|
||||
end
|
||||
end
|
||||
|
||||
# for computationally building code (ie writing assembler) these short cuts
|
||||
|
@ -34,6 +34,14 @@ module Risc
|
||||
assert_equal 2 , get_return
|
||||
end
|
||||
|
||||
def test_load_space
|
||||
load_ins = main_ticks 55
|
||||
assert_load load_ins, Parfait::Space
|
||||
end
|
||||
def test_load_to
|
||||
to = main_ticks 56
|
||||
assert_slot_to_reg to , :r5 , 5 ,:r2
|
||||
end
|
||||
def test_load_25
|
||||
load_ins = main_ticks 9
|
||||
assert_equal LoadConstant , load_ins.class
|
||||
|
@ -12,35 +12,35 @@ module Risc
|
||||
def test_chain
|
||||
#show_main_ticks # get output of what is
|
||||
check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
||||
SlotToReg, SlotToReg, SlotToReg, OperatorInstruction, IsZero,
|
||||
SlotToReg, SlotToReg, SlotToReg, Branch, LoadConstant,
|
||||
RegToSlot, LoadConstant, LoadConstant, SlotToReg, SlotToReg,
|
||||
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
|
||||
OperatorInstruction, IsZero, Branch, SlotToReg, Branch,
|
||||
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
|
||||
OperatorInstruction, IsZero, Branch, SlotToReg, Branch,
|
||||
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
|
||||
OperatorInstruction, IsZero, Branch, SlotToReg, Branch,
|
||||
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
|
||||
OperatorInstruction, IsZero, Branch, SlotToReg, Branch,
|
||||
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
|
||||
OperatorInstruction, IsZero, Branch, SlotToReg, Branch,
|
||||
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
|
||||
OperatorInstruction, IsZero, RegToSlot, Branch, LoadConstant,
|
||||
SlotToReg, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
|
||||
RegToSlot, RegToSlot, RegToSlot, SlotToReg, SlotToReg,
|
||||
SlotToReg, RegToSlot, Branch, LoadConstant, SlotToReg,
|
||||
RegToSlot, SlotToReg, LoadConstant, SlotToReg, DynamicJump,
|
||||
SlotToReg, SlotToReg, LoadData, OperatorInstruction, LoadConstant,
|
||||
SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot,
|
||||
SlotToReg, SlotToReg, RegToSlot, Branch, LoadConstant,
|
||||
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg,
|
||||
SlotToReg, FunctionReturn, SlotToReg, SlotToReg, RegToSlot,
|
||||
SlotToReg, SlotToReg, RegToSlot, Branch, Branch,
|
||||
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
||||
RegToSlot, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
|
||||
FunctionReturn, Transfer, SlotToReg, SlotToReg, Syscall,
|
||||
NilClass]
|
||||
SlotToReg, SlotToReg, SlotToReg, OperatorInstruction, IsZero, # 10
|
||||
SlotToReg, SlotToReg, SlotToReg, Branch, LoadConstant,
|
||||
RegToSlot, LoadConstant, LoadConstant, SlotToReg, SlotToReg, # 20
|
||||
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
|
||||
OperatorInstruction, IsZero, Branch, SlotToReg, Branch, # 30
|
||||
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
|
||||
OperatorInstruction, IsZero, Branch, SlotToReg, Branch, # 40
|
||||
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
|
||||
OperatorInstruction, IsZero, Branch, SlotToReg, Branch, # 50
|
||||
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
|
||||
OperatorInstruction, IsZero, Branch, SlotToReg, Branch, # 60
|
||||
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
|
||||
OperatorInstruction, IsZero, Branch, SlotToReg, Branch, # 70
|
||||
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
|
||||
OperatorInstruction, IsZero, RegToSlot, Branch, LoadConstant, # 80
|
||||
SlotToReg, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
|
||||
RegToSlot, RegToSlot, RegToSlot, SlotToReg, SlotToReg, # 90
|
||||
SlotToReg, RegToSlot, Branch, LoadConstant, SlotToReg,
|
||||
RegToSlot, SlotToReg, LoadConstant, SlotToReg, DynamicJump, # 100
|
||||
SlotToReg, SlotToReg, LoadData, OperatorInstruction, LoadConstant,
|
||||
SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, # 110
|
||||
SlotToReg, SlotToReg, RegToSlot, Branch, LoadConstant,
|
||||
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg, # 120
|
||||
SlotToReg, FunctionReturn, SlotToReg, SlotToReg, RegToSlot,
|
||||
SlotToReg, SlotToReg, RegToSlot, Branch, Branch, # 130
|
||||
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
||||
RegToSlot, RegToSlot, SlotToReg, SlotToReg, SlotToReg, # 140
|
||||
FunctionReturn, Transfer, SlotToReg, SlotToReg, Syscall,
|
||||
NilClass, ]
|
||||
assert_equal Fixnum , get_return.class
|
||||
assert_equal 1 , get_return
|
||||
end
|
||||
|
@ -25,6 +25,9 @@ module Risc
|
||||
def test_caller_reg
|
||||
assert_equal :Message , @builder.infer_type(:caller_reg).class_name
|
||||
end
|
||||
def test_caller_tmp
|
||||
assert_equal :Message , @builder.infer_type(:caller_tmp).class_name
|
||||
end
|
||||
def test_caller_obj
|
||||
assert_equal :Message , @builder.infer_type(:caller_obj).class_name
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user