From 1a19683e7df5391e51d9eba2c07855a501068c4f Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 1 Apr 2018 21:59:06 +0300 Subject: [PATCH] fix RegToByte seems to work, but does not end in syscall --- lib/risc/builtin/word.rb | 11 ++- test/risc/interpreter/test_set_byte.rb | 44 ++++++++++++ test/risc/interpreter/wip/test_byte_to_reg.rb | 67 ------------------- 3 files changed, 49 insertions(+), 73 deletions(-) create mode 100644 test/risc/interpreter/test_set_byte.rb delete mode 100644 test/risc/interpreter/wip/test_byte_to_reg.rb diff --git a/lib/risc/builtin/word.rb b/lib/risc/builtin/word.rb index 5ea8db99..0d3dd055 100644 --- a/lib/risc/builtin/word.rb +++ b/lib/risc/builtin/word.rb @@ -31,17 +31,16 @@ module Risc # self[index] = val basically. Index is the first arg ( >0), # value the second - # no return - def set_internal_byte( context) + # return self + def set_internal_byte( context ) compiler = compiler_for(:Word, :set_internal_byte , {at: :Integer , :value => :Integer} ) - args = compiler.method.arguments - len = args.instance_length - raise "Compiler arg number mismatch, method=#{args} " if len != 3 source = "set_internal_byte" me , index = compiler.self_and_int_arg(source) value = compiler.load_int_arg_at(source , 2 ) - # do the set + compiler.reduce_int( source + " fix me", value ) + compiler.reduce_int( source + " fix arg", index ) compiler.add_reg_to_byte( source , value , me , index) + compiler.add_reg_to_slot( source , me , :message , :return_value) compiler.add_mom( Mom::ReturnSequence.new) return compiler.method end diff --git a/test/risc/interpreter/test_set_byte.rb b/test/risc/interpreter/test_set_byte.rb new file mode 100644 index 00000000..277df926 --- /dev/null +++ b/test/risc/interpreter/test_set_byte.rb @@ -0,0 +1,44 @@ +require_relative "helper" + +module Risc + class InterpretSetByte < MiniTest::Test + include Ticker + + def setup + @string_input = as_main("'Hello'.set_internal_byte(1,75)") + super + end + + def test_chain + #show_ticks # get output of what is + check_chain [Branch, Label, LoadConstant, SlotToReg, LoadConstant, + SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, + SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, + SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot, + SlotToReg, RegToSlot, LoadConstant, RegToSlot, FunctionCall, + Label, LoadConstant, SlotToReg, SlotToReg, RegToSlot, + LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, + RegToSlot, LoadConstant, SlotToReg, SlotToReg, SlotToReg, + SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, + LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant, + SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, + RegToSlot, SlotToReg, LoadConstant, FunctionCall, Label, + SlotToReg, SlotToReg, SlotToReg, SlotToReg, SlotToReg, + SlotToReg, SlotToReg, RegToByte, RegToSlot, SlotToReg, + SlotToReg, RegToSlot, SlotToReg, SlotToReg, FunctionReturn, + Label, NilClass] + assert_equal Parfait::Word , get_return.class + assert_equal "Kello" , get_return.to_string + end + def test_reg_to_byte + done = ticks(68) + assert_equal RegToByte , done.class + assert_equal "K".ord , @interpreter.get_register(done.register) + end + def test_exit + done = ticks(77) + assert_equal NilClass , done.class + end + + end +end diff --git a/test/risc/interpreter/wip/test_byte_to_reg.rb b/test/risc/interpreter/wip/test_byte_to_reg.rb deleted file mode 100644 index f3cd8b48..00000000 --- a/test/risc/interpreter/wip/test_byte_to_reg.rb +++ /dev/null @@ -1,67 +0,0 @@ -require_relative "../helper" - -module Risc - class TestInterpretRegToByte < MiniTest::Test - include Ticker - - def setup - @string_input = <