get plus (+) working

alas, new integer is not created yet
This commit is contained in:
Torsten Ruger 2018-03-31 19:37:24 +03:00
parent a2173645b3
commit 5b92b6b785
3 changed files with 48 additions and 29 deletions

View File

@ -19,6 +19,11 @@ module Parfait
def self.integer_index
3 # 1 type, 2 next_i
end
def get_internal_word( index )
return super(index) unless index == Integer.integer_index
return @value
end
# :integer?, :odd?, :even?, :upto, :downto, :times, :succ, :next, :pred, :chr, :ord, :to_i, :to_int, :floor,
# :ceil, :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize,
# :singleton_method_added, :coerce, :i, :+@, :-@, :fdiv, :div, :divmod, :%, :modulo, :remainder, :abs, :magnitude,

View File

@ -20,8 +20,8 @@ module Risc
compiler = compiler_for(:Integer,:+ ,{other: :Integer})
me , other = self_and_int_arg(compiler,source + "1")
# reduce me and other to integers
compiler.add_slot_to_reg( source + "2" , me , 2 , me)
compiler.add_slot_to_reg( source + "3", other , 2 , other)
compiler.add_slot_to_reg( source + "2" , me , Parfait::Integer.integer_index , me)
compiler.add_slot_to_reg( source + "3", other , Parfait::Integer.integer_index , other)
compiler.add_code Risc.op( source + "4", :+ , me , other)
#TODO must get an Integer and put the value there then return the integer (object not value)
# and put it back into the return value

View File

@ -5,12 +5,12 @@ module Risc
include Ticker
def setup
@string_input = as_main("a = 5 + 5")
@string_input = as_main("a = 5 + 5;return a")
super
end
def est_add
show_ticks # get output of what is
#show_ticks # get output of what is
check_chain [Branch, Label, LoadConstant, SlotToReg, LoadConstant,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
@ -20,40 +20,54 @@ module Risc
LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, SlotToReg, SlotToReg,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, SlotToReg]
#assert_equal 10 , get_return
LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, RegToSlot, SlotToReg, LoadConstant, FunctionCall,
Label, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
SlotToReg, OperatorInstruction, RegToSlot, Label, NilClass]
assert_equal 10 , get_return
end
def est_slot3
sl = ticks( 49 )
assert_equal SlotToReg , sl.class
assert_equal :r2 , sl.array.symbol #load from message
assert_equal 9 , sl.index
assert_equal :r3 , sl.register.symbol
def test_load_5
lod = ticks( 46 )
assert_equal LoadConstant , lod.class
assert_equal Parfait::Integer , lod.constant.class
assert_equal 5 , lod.constant.value
end
def est_slot2 #load arg from args
sl = ticks( 48 )
assert_equal SlotToReg , sl.class
assert_equal :r2 , sl.array.symbol #load from message
assert_equal 9 , sl.index
assert_equal :r3 , sl.register.symbol
end
def est_slot1 #load args from message
sl = ticks( 47 )
def test_slot_receiver #load receiver from message
sl = ticks( 57 )
assert_equal SlotToReg , sl.class
assert_equal :r0 , sl.array.symbol #load from message
assert_equal 3 , sl.index
assert_equal :r1 , sl.register.symbol
end
def test_slot_args #load args from message
sl = ticks( 58 )
assert_equal SlotToReg , sl.class
assert_equal :r0 , sl.array.symbol #load from message
assert_equal 9 , sl.index
assert_equal :r2 , sl.register.symbol
end
def test_slot_arg #load arg 1, destructively from args
sl = ticks( 59 )
assert_equal SlotToReg , sl.class
assert_equal :r2 , sl.array.symbol #load from message
assert_equal 2 , sl.index
assert_equal :r2 , sl.register.symbol
end
def est_load_2
lod = ticks( 46 )
assert_equal LoadConstant , lod.class
assert_equal 5 , lod.constant.value
def test_slot_int1 #load int from object
sl = ticks( 60 )
assert_equal SlotToReg , sl.class
assert_equal :r1 , sl.array.symbol #load from message
assert_equal 3 , sl.index
assert_equal :r1 , sl.register.symbol
end
def pest_zero
ticks( 12 )
assert @interpreter.flags[:zero]
def test_op
op = ticks(62)
assert_equal OperatorInstruction , op.class
assert_equal :r1 , op.left.symbol
assert_equal :r2 , op.right.symbol
assert_equal 5 , @interpreter.get_register(:r2)
assert_equal 10 , @interpreter.get_register(:r1)
end
end
end