putstring unfolds length

which means sys call doesn’t need to
and also interpreter sometimes gets a symbol length
This commit is contained in:
Torsten Ruger 2015-11-16 18:03:29 +02:00
parent f92ea36fe5
commit 303b7eb1f8
3 changed files with 14 additions and 4 deletions

View File

@ -128,14 +128,13 @@ module Arm
end end
def putstring int_code def putstring int_code
codes = ArmMachine.ldr( :r2 , :r1 , 8 ) # String length codes = ArmMachine.add( :r1 , :r1 , 12 ) # adjust for object header
codes.append ArmMachine.add( :r1 , :r1 , 12 ) # adjust for object header
codes.append ArmMachine.mov( :r0 , 1 ) # write to stdout == 1 codes.append ArmMachine.mov( :r0 , 1 ) # write to stdout == 1
syscall(int_code , codes ) syscall(int_code , codes )
end end
def exit int_code 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 syscall int_code , codes
end end

View File

@ -121,7 +121,15 @@ module Interpreter
else else
index = get_register(@instruction.index) index = get_register(@instruction.index)
end 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 #value = value.object_id unless value.is_a? Fixnum
set_register( @instruction.register , value ) set_register( @instruction.register , value )
true true

View File

@ -5,6 +5,9 @@ module Register
def putstring context def putstring context
compiler = Soml::Compiler.new.create_method(:Word , :putstring ).init_method compiler = Soml::Compiler.new.create_method(:Word , :putstring ).init_method
compiler.add_code Register.get_slot( "putstring" , :message , :receiver , :new_message ) 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 ) Kernel.emit_syscall( compiler , :putstring )
compiler.method compiler.method
end end