putint works, work on syntax goes on

This commit is contained in:
Torsten Ruger 2014-05-19 15:44:12 +03:00
parent 76ce9aa654
commit 285988f173
4 changed files with 25 additions and 24 deletions

View File

@ -35,13 +35,6 @@ module Arm
to
end
def string_load block , str_lit , reg
block << add( "r#{reg}".to_sym , str_lit , nil ) #right is pc, implicit
#second arg is a hack to get the stringlength without coding
block << mov( "r#{reg+1}".to_sym , str_lit.length )
str_lit
end
def function_call into , call
raise "Not CallSite #{call.inspect}" unless call.is_a? Vm::CallSite
raise "Not linked #{call.inspect}" unless call.function

View File

@ -39,15 +39,16 @@ module Core
int = putint_function.args.first
moved_int = Vm::Integer.new(1)
utoa = context.program.get_or_create_function(:utoa)
putint_function.body.instance_eval do
mov( moved_int , int ) #move arg up
add( int , buffer ,nil ) # string to write to
add( int , int , (buffer.length-3))
call( utoa )
b = putint_function.body
b.mov( moved_int , int ) #move arg up
#b.a buffer => int # string to write to
b.add( int , buffer ,nil ) # string to write to
b.a int + (buffer.length-3) => int
b.call( utoa )
# And now we "just" have to print it, using the write_stdout
add( int , buffer , nil ) # string to write to
mov( moved_int , buffer.length )
end
b.add( int , buffer , nil ) # string to write to
b.mov( moved_int , buffer.length )
Vm::CMachine.instance.write_stdout(putint_function.body)
putint_function
end
@ -64,13 +65,12 @@ module Core
remainder = Vm::Integer.new( number.register + 1)
Vm::CMachine.instance.div10( utoa_function.body , number , remainder )
# make char out of digit (by using ascii encoding) 48 == "0"
utoa_function.body.instance_eval do
add( remainder , remainder , 48 )
strb( remainder, right: str_addr )
sub( str_addr, str_addr , 1 )
cmp( number , 0 )
callne( utoa_function )
end
b = utoa_function.body
b.a remainder + 48 => remainder
b.strb( remainder, right: str_addr )
b.sub( str_addr, str_addr , 1 )
b.cmp( number , 0 )
b.callne( utoa_function )
return utoa_function
end
end

View File

@ -34,12 +34,19 @@ module Vm
end
def add_code(kode)
if kode.is_a? Hash
raise "Hack only for 1 element #{inspect} #{kode.inspect}" unless kode.length == 1
instruction , result = kode.first
instruction.result = result
kode = instruction
end
raise "alarm #{kode}" if kode.is_a? Word
raise "alarm #{kode}" unless kode.is_a? Code
@codes << kode
self
end
alias :<< :add_code
alias :a :add_code
def link_at pos , context
@position = pos
@ -67,6 +74,7 @@ module Vm
# sugar to create instructions easily. Any method with one arg is sent to the machine and the result
# (hopefully an instruction) added as code
def method_missing(meth, *args, &block)
raise "hallo" if( meth.to_s[-1] == "=")
add_code CMachine.instance.send(meth , *args)
end

View File

@ -33,8 +33,8 @@ module Vm
@string = str + "\x00" * pad
end
def load reg_num
Machine.instance.string_load self , reg_num
def result= value
class_for(MoveInstruction).new(value , self , :opcode => :mov)
end
# the strings length plus padding