From 249f43ad346880cdb2ab5986ad10f1ed661cdbe2 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Thu, 19 Nov 2015 10:09:55 +0200 Subject: [PATCH] translate and interpret new instructions --- lib/arm/translator.rb | 28 ++++++++++++++++++++++------ lib/register/interpreter.rb | 30 ++++++++++++++++++++++++++++++ test/soml/parfait/test_word.rb | 11 +++++++++++ 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/lib/arm/translator.rb b/lib/arm/translator.rb index cbed59ae..0ad7737b 100644 --- a/lib/arm/translator.rb +++ b/lib/arm/translator.rb @@ -31,6 +31,12 @@ module Arm ArmMachine.str( :lr , code.register , arm_index(code) ) end + def translate_RegisterTransfer code + # Register machine convention is from => to + # But arm has the receiver/result as the first + ArmMachine.mov( code.to , code.from) + end + def translate_GetSlot code # times 4 because arm works in bytes, but vm in words if(code.index.is_a? Numeric) @@ -40,12 +46,6 @@ module Arm end end - def translate_RegisterTransfer code - # Register machine convention is from => to - # But arm has the receiver/result as the first - ArmMachine.mov( code.to , code.from) - end - def translate_SetSlot code # times 4 because arm works in bytes, but vm in words if(code.index.is_a? Numeric) @@ -55,6 +55,22 @@ module Arm end end + def translate_GetByte code + if(code.index.is_a? Numeric) + ArmMachine.ldrb( code.register , code.array , arm_index(code) ) + else + ArmMachine.ldrb( code.register , code.array , code.index ) + end + end + + def translate_SetByte code + if(code.index.is_a? Numeric) + ArmMachine.strb( code.register , code.array , arm_index(code) ) + else + ArmMachine.strb( code.register , code.array , code.index ) + end + end + def translate_FunctionCall code ArmMachine.b( code.method.instructions ) end diff --git a/lib/register/interpreter.rb b/lib/register/interpreter.rb index 952ce501..4111f751 100644 --- a/lib/register/interpreter.rb +++ b/lib/register/interpreter.rb @@ -148,6 +148,36 @@ module Register true end + def execute_GetByte + object = get_register( @instruction.array ) + if( @instruction.index.is_a?(Numeric) ) + index = @instruction.index + else + index = get_register(@instruction.index) + end + if object.is_a?(Symbol) + raise "Unsupported action, must convert symbol to word:#{object}" + else + value = object.get_internal_byte( index ) + end + #value = value.object_id unless value.is_a? Fixnum + set_register( @instruction.register , value ) + true + end + + def execute_SetByte + value = get_register( @instruction.register ) + object = get_register( @instruction.array ) + if( @instruction.index.is_a?(Numeric) ) + index = @instruction.index + else + index = get_register(@instruction.index) + end + object.set_internal_byte( index , value ) + trigger(:object_changed, @instruction.array , index / 4 ) + true + end + def execute_RegisterTransfer value = get_register @instruction.from set_register @instruction.to , value diff --git a/test/soml/parfait/test_word.rb b/test/soml/parfait/test_word.rb index 2ed691e4..8d3bc905 100644 --- a/test/soml/parfait/test_word.rb +++ b/test/soml/parfait/test_word.rb @@ -28,6 +28,7 @@ return w.char_at(1) HERE check_return 32 end + def test_after_add_get_works @main = <