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 def self.integer_index
3 # 1 type, 2 next_i 3 # 1 type, 2 next_i
end 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, # :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, # :ceil, :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize,
# :singleton_method_added, :coerce, :i, :+@, :-@, :fdiv, :div, :divmod, :%, :modulo, :remainder, :abs, :magnitude, # :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}) compiler = compiler_for(:Integer,:+ ,{other: :Integer})
me , other = self_and_int_arg(compiler,source + "1") me , other = self_and_int_arg(compiler,source + "1")
# reduce me and other to integers # reduce me and other to integers
compiler.add_slot_to_reg( source + "2" , me , 2 , me) compiler.add_slot_to_reg( source + "2" , me , Parfait::Integer.integer_index , me)
compiler.add_slot_to_reg( source + "3", other , 2 , other) compiler.add_slot_to_reg( source + "3", other , Parfait::Integer.integer_index , other)
compiler.add_code Risc.op( source + "4", :+ , me , 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) #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 # and put it back into the return value

View File

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