more test working

operator wip
This commit is contained in:
Torsten Ruger
2015-09-20 16:52:26 +03:00
parent 77f0a08060
commit 5f628744d6
10 changed files with 42 additions and 49 deletions

View File

@ -8,7 +8,6 @@ module Fragments
def check
expressions = Virtual.machine.boot.compile_main @string_input
puts expressions
@expect.each_with_index do | should , i |
exp_i = expressions[i]
assert exp_i.is_a?(Virtual::Slot) , "compiles should return #{should}, not #{exp_i}"

View File

@ -1,9 +1,9 @@
require_relative "test_foo"
require_relative "test_if"
require_relative "test_hello"
require_relative "test_putint"
require_relative "test_functions"
require_relative "test_recursive_fibo"
require_relative "test_while_fibo"
#require_relative "test_string_class"
#require_relative "test_hello"
#require_relative "test_putint"
#require_relative "test_recursive_fibo"
#require_relative "test_while_fibo"

View File

@ -3,14 +3,11 @@ require_relative 'helper'
class TestPutint < MiniTest::Test
include Fragments
def ttest_putint
def test_putint
@string_input = <<HERE
42.putint()
HERE
@should = [0x0,0x40,0x2d,0xe9,0x2,0x30,0xa0,0xe1,0x78,0x20,0x8f,0xe2,0x9,0x20,0x82,0xe2,0xe2,0xff,0xff,0xeb,0x6c,0x20,0x8f,0xe2,0xc,0x30,0xa0,0xe3,0x1,0x0,0xa0,0xe3,0x2,0x10,0xa0,0xe1,0x3,0x20,0xa0,0xe1,0x4,0x70,0xa0,0xe3,0x0,0x0,0x0,0xef,0x0,0x80,0xbd,0xe8]
@output = " 42 "
@target = [:Object , :putint]
parse
write "putint"
@expect = []
check
end
end

View File

@ -5,19 +5,21 @@ class TestRecursinveFibo < MiniTest::Test
def test_recursive_fibo
@string_input = <<HERE
def fibonaccir( n )
if( n <= 1 )
return n
else
a = fibonaccir( n - 1 )
b = fibonaccir( n - 2 )
return a + b
end
end
def fib_print(n)
int fib_print(int n)
fib = fibonaccir( n )
fib.putint()
end
int fibonaccir( int n )
if( n <= 1 )
return n
else
int tmp = n - 1
a = fibonaccir( tmp )
tmp = n - 2
b = fibonaccir( tmp )
return a + b
end
end
fib_print(10)
HERE

View File

@ -5,18 +5,18 @@ class TestWhileFragment < MiniTest::Test
def test_while_fibo
@string_input = <<HERE
def fibonaccit(n) # n == r0
a = 0 # a == r1
b = 1 # b = r2
while( n > 1 ) do #BUG comment lines + comments behind function calls
tmp = a # r3 <- r1
a = b # r1 <- r2
b = tmp + b # r4 = r2 + r3 (r4 transient) r2 <- r4
n = n - 1 # r0 <- r2 for call, #call ok
end #r5 <- r0 - 1 n=n-1 through r5 tmp
int fibonaccit(int n)
int a = 0
int b = 1
while( n > 1 )
int tmp = a
a = b
b = tmp + b
n = n - 1
end
b.putint()
return b
end # r0 <- r5
end
fibonaccit( 10 )
HERE