From 303b7eb1f8a394d5a111ae48f921b56bb19bc714 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 16 Nov 2015 18:03:29 +0200 Subject: [PATCH] putstring unfolds length MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit which means sys call doesn’t need to and also interpreter sometimes gets a symbol length --- lib/arm/translator.rb | 5 ++--- lib/interpreter/interpreter.rb | 10 +++++++++- lib/register/builtin/word.rb | 3 +++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/arm/translator.rb b/lib/arm/translator.rb index f2e14f4f..cbed59ae 100644 --- a/lib/arm/translator.rb +++ b/lib/arm/translator.rb @@ -128,14 +128,13 @@ module Arm end def putstring int_code - codes = ArmMachine.ldr( :r2 , :r1 , 8 ) # String length - codes.append ArmMachine.add( :r1 , :r1 , 12 ) # adjust for object header + codes = ArmMachine.add( :r1 , :r1 , 12 ) # adjust for object header codes.append ArmMachine.mov( :r0 , 1 ) # write to stdout == 1 syscall(int_code , codes ) end def exit int_code - codes = Register::Label.new(nil , "exit") + codes = ArmMachine.ldr( :r0 , :r0 , arm_index(Register.resolve_index(:Message , :return_value)) ) syscall int_code , codes end diff --git a/lib/interpreter/interpreter.rb b/lib/interpreter/interpreter.rb index def917eb..22f7aab5 100644 --- a/lib/interpreter/interpreter.rb +++ b/lib/interpreter/interpreter.rb @@ -121,7 +121,15 @@ module Interpreter else index = get_register(@instruction.index) end - value = object.get_internal( index ) + if object.is_a?(Symbol) + if( index == 2 ) + value = object.to_s.length + else + raise "Unsupported action, must convert symbol to word:#{object}" + end + else + value = object.get_internal( index ) + end #value = value.object_id unless value.is_a? Fixnum set_register( @instruction.register , value ) true diff --git a/lib/register/builtin/word.rb b/lib/register/builtin/word.rb index cf52754e..392f0820 100644 --- a/lib/register/builtin/word.rb +++ b/lib/register/builtin/word.rb @@ -5,6 +5,9 @@ module Register def putstring context compiler = Soml::Compiler.new.create_method(:Word , :putstring ).init_method compiler.add_code Register.get_slot( "putstring" , :message , :receiver , :new_message ) + index = Parfait::Word.get_length_index + reg = RegisterValue.new(:r2 , :Integer) + compiler.add_code Register.get_slot( "putstring" , :new_message , index , reg ) Kernel.emit_syscall( compiler , :putstring ) compiler.method end