fix set_internal_word register

This commit is contained in:
Torsten 2020-03-12 21:39:01 +02:00
parent 5c13ea1433
commit 504fc3509e
3 changed files with 15 additions and 18 deletions

View File

@ -2,11 +2,9 @@ module SlotMachine
class SetInternalWord < Macro class SetInternalWord < Macro
def to_risc(compiler) def to_risc(compiler)
compiler.builder(compiler.source).build do compiler.builder(compiler.source).build do
object! << message[:receiver] integer = message[:arg1].to_reg.reduce_int(false)
integer! << message[:arg1] # "index" object_reg = message[:arg2].to_reg
object_reg! << message[:arg2]#"value" message[:receiver][integer] << object_reg
integer.reduce_int
object[integer] << object_reg
message[:return_value] << object_reg message[:return_value] << object_reg
end end
return compiler return compiler

View File

@ -2,7 +2,7 @@ require_relative "helper"
module SlotMachine module SlotMachine
module Builtin module Builtin
class TestWordGetRisc < BootTest class TestGetInternalByte < BootTest
def setup def setup
super super
@method = get_compiler("Word",:get_byte) @method = get_compiler("Word",:get_byte)

View File

@ -14,22 +14,21 @@ module SlotMachine
assert_equal Risc::MethodCompiler , @method.to_risc.class assert_equal Risc::MethodCompiler , @method.to_risc.class
end end
def test_risc_length def test_risc_length
assert_equal 20 , @method.to_risc.risc_instructions.length assert_equal 18 , @method.to_risc.risc_instructions.length
end end
def test_all def test_all
assert_slot_to_reg risc(1),:r0 , 2 , :r1 assert_slot_to_reg 1 ,:message , 9 , "message.arg1"
assert_slot_to_reg risc(2),:r0 , 10 , :r2 assert_slot_to_reg 2 ,"message.arg1" , 2 , "message.arg1.data_1"
assert_reg_to_slot risc(3) , :r2 , :r0 , 5 assert_slot_to_reg 3 ,:message , 10 , "message.arg2"
assert_slot_to_reg risc(4),:r0 , 9 , :r3 assert_slot_to_reg 4 ,:message , 2 , "message.receiver"
assert_slot_to_reg risc(5),:r3 , 2 , :r3 assert_reg_to_slot 5 , "message.arg2" , "message.receiver" , :"message.arg1.data_1"
assert_slot_to_reg risc(6),:r2 , 2 , :r2 assert_reg_to_slot 6 , "message.arg2" , :message , 5
assert_equal Risc::RegToByte , risc(7).class assert_slot_to_reg 7 ,:message , 5 , :"message.return_value"
assert_slot_to_reg risc(8),:r0 , 5 , :r2 assert_reg_to_slot 8 , "message.return_value" , :message , 5
assert_reg_to_slot risc(9) , :r2 , :r0 , 5 assert_branch 9 , "return_label"
assert_branch risc(10) , "return_label"
end end
def test_return def test_return
assert_return(11) assert_return(10)
end end
end end
end end