renaming and small fixes
This commit is contained in:
parent
e7bb774da0
commit
fbcfa844de
@ -25,9 +25,7 @@ module Ast
|
||||
|
||||
parent_locals = context.locals
|
||||
parent_function = context.function
|
||||
puts "Locals #{locals.keys.join('-')}, #{locals.object_id}"
|
||||
context.locals = locals
|
||||
puts "Locals #{context.locals.keys.join('-')}, #{context.locals.object_id}"
|
||||
context.function = function
|
||||
|
||||
into = function.body
|
||||
|
@ -5,7 +5,6 @@ module Ast
|
||||
while_block = into.new_block "#{into.name}_while"
|
||||
ret = while_block.new_block "#{into.name}_return"
|
||||
puts "compiling while condition #{condition}"
|
||||
puts "Locals #{context.locals.keys.join('-')}, #{context.locals.object_id}"
|
||||
cond_val = condition.compile(context , while_block)
|
||||
while_block.b ret , condition_code: cond_val.not_operator
|
||||
last = nil
|
||||
|
@ -23,11 +23,13 @@ module Boot
|
||||
var_name = get_function.args.first
|
||||
return_to = get_function.return_type
|
||||
index_function = context.object_space.get_or_create_class(:Object).get_or_create_function(:index_of)
|
||||
b = get_function.body
|
||||
b.push( [me] )
|
||||
b.call( index_function )
|
||||
b.pop([me])
|
||||
return_to.at_index( get_function.body , me , return_to )
|
||||
body = get_function.body
|
||||
body.push( [me] )
|
||||
body.call( index_function )
|
||||
after_body = body.new_block("#{body.name}_a")
|
||||
body.insert_at after_body
|
||||
after_body.pop([me])
|
||||
return_to.at_index( after_body , me , return_to )
|
||||
get_function.set_return return_to
|
||||
return get_function
|
||||
end
|
||||
|
@ -39,17 +39,19 @@ module Core
|
||||
int = putint_function.receiver
|
||||
moved_int = putint_function.new_local
|
||||
utoa = context.object_space.get_or_create_class(:Object).get_or_create_function(:utoa)
|
||||
b = putint_function.body
|
||||
b.mov( moved_int , int ) #move arg up
|
||||
#b.a buffer => int # string to write to
|
||||
body = putint_function.body
|
||||
body.mov( moved_int , int ) #move arg up
|
||||
#body.a buffer => int # string to write to
|
||||
|
||||
b.add( int , buffer ,nil ) # string to write to
|
||||
b.add(int , int , buffer.length - 3)
|
||||
b.call( utoa )
|
||||
body.add( int , buffer ,nil ) # string to write to
|
||||
body.add(int , int , buffer.length - 3)
|
||||
body.call( utoa )
|
||||
after = body.new_block("#{body.name}_a")
|
||||
body.insert_at after
|
||||
# And now we "just" have to print it, using the write_stdout
|
||||
b.add( int , buffer , nil ) # string to write to
|
||||
b.mov( moved_int , buffer.length )
|
||||
Vm::RegisterMachine.instance.write_stdout(putint_function.body)
|
||||
after.add( int , buffer , nil ) # string to write to
|
||||
after.mov( moved_int , buffer.length )
|
||||
Vm::RegisterMachine.instance.write_stdout(after)
|
||||
putint_function
|
||||
end
|
||||
|
||||
@ -65,12 +67,12 @@ module Core
|
||||
remainder = utoa_function.new_local
|
||||
Vm::RegisterMachine.instance.div10( utoa_function.body , number , remainder )
|
||||
# make char out of digit (by using ascii encoding) 48 == "0"
|
||||
b = utoa_function.body
|
||||
b.add(remainder , remainder , 48)
|
||||
b.strb( remainder, str_addr )
|
||||
b.sub( str_addr, str_addr , 1 )
|
||||
b.cmp( number , 0 )
|
||||
b.callne( utoa_function )
|
||||
body = utoa_function.body
|
||||
body.add(remainder , remainder , 48)
|
||||
body.strb( remainder, str_addr )
|
||||
body.sub( str_addr, str_addr , 1 )
|
||||
body.cmp( number , 0 )
|
||||
body.callne( utoa_function )
|
||||
return utoa_function
|
||||
end
|
||||
|
||||
@ -85,15 +87,15 @@ module Core
|
||||
count = fibo_function.new_local
|
||||
f1 = fibo_function.new_local
|
||||
f2 = fibo_function.new_local
|
||||
b = fibo_function.body
|
||||
body = fibo_function.body
|
||||
|
||||
b.cmp int , 1
|
||||
b.mov( result, int , condition_code: :le)
|
||||
b.mov( :pc , :lr , condition_code: :le)
|
||||
b.push [ count , f1 , f2 , :lr]
|
||||
b.mov f1 , 1
|
||||
b.mov f2 , 0
|
||||
b.sub count , int , 2
|
||||
body.cmp int , 1
|
||||
body.mov( result, int , condition_code: :le)
|
||||
body.mov( :pc , :lr , condition_code: :le)
|
||||
body.push [ count , f1 , f2 , :lr]
|
||||
body.mov f1 , 1
|
||||
body.mov f2 , 0
|
||||
body.sub count , int , 2
|
||||
|
||||
l = fibo_function.body.new_block("loop")
|
||||
|
||||
|
@ -7,9 +7,9 @@ class TestIf < MiniTest::Test
|
||||
@string_input = <<HERE
|
||||
def itest(n)
|
||||
if( n < 12)
|
||||
putstring("then")
|
||||
"then".putstring()
|
||||
else
|
||||
putstring("else")
|
||||
"else".putstring()
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -11,11 +11,16 @@ def fibonaccir( n )
|
||||
else
|
||||
a = fibonaccir( n - 1 )
|
||||
b = fibonaccir( n - 2 )
|
||||
c = fibonaccir( n - 3 )
|
||||
return a + b
|
||||
end
|
||||
end
|
||||
fib = fibonaccir( 10 )
|
||||
fib.putint()
|
||||
end
|
||||
def fib_print(n)
|
||||
fib = fibonaccir( n )
|
||||
fib.putint()
|
||||
end
|
||||
|
||||
fib_print(10)
|
||||
HERE
|
||||
@should = [0x0,0x40,0x2d,0xe9,0x1,0x0,0x51,0xe3,0xe,0x0,0x0,0xda,0x1,0x20,0x41,0xe2,0x6,0x0,0x2d,0xe9,0x2,0x10,0xa0,0xe1,0xf8,0xff,0xff,0xeb,0x6,0x0,0xbd,0xe8,0x7,0x30,0xa0,0xe1,0x2,0x40,0x41,0xe2,0x1e,0x0,0x2d,0xe9,0x4,0x10,0xa0,0xe1,0xf2,0xff,0xff,0xeb,0x1e,0x0,0xbd,0xe8,0x7,0x50,0xa0,0xe1,0x5,0x60,0x83,0xe0,0x6,0x70,0xa0,0xe1,0x0,0x0,0x0,0xea,0x1,0x70,0xa0,0xe1,0x0,0x80,0xbd,0xe8,0x0,0x40,0x2d,0xe9,0x1,0x0,0x51,0xe3,0xe,0x0,0x0,0xda,0x1,0x20,0x41,0xe2,0x6,0x0,0x2d,0xe9,0x2,0x10,0xa0,0xe1,0xf8,0xff,0xff,0xeb,0x6,0x0,0xbd,0xe8,0x7,0x30,0xa0,0xe1,0x2,0x40,0x41,0xe2,0x1e,0x0,0x2d,0xe9,0x4,0x10,0xa0,0xe1,0xf2,0xff,0xff,0xeb,0x1e,0x0,0xbd,0xe8,0x7,0x50,0xa0,0xe1,0x5,0x60,0x83,0xe0,0x6,0x70,0xa0,0xe1,0x0,0x0,0x0,0xea,0x1,0x70,0xa0,0xe1,0x0,0x80,0xbd,0xe8]
|
||||
@output = " 55 "
|
||||
|
Loading…
Reference in New Issue
Block a user