more fragment tests
This commit is contained in:
parent
31d825df7b
commit
d7c9245bb3
@ -37,8 +37,8 @@ module Virtual
|
||||
to
|
||||
end
|
||||
|
||||
def self.compile_module expression , method
|
||||
clazz = Space.space.get_class_by_name name
|
||||
def self.compile_modulename expression , method
|
||||
clazz = Parfait::Space.object_space.get_class_by_name expression.name
|
||||
raise "uups #{clazz}.#{name}" unless clazz
|
||||
to = Return.new(Reference , clazz )
|
||||
method.source.add_code Set.new( clazz , to )
|
||||
|
@ -7,10 +7,10 @@ module Virtual
|
||||
p.name
|
||||
end
|
||||
if expression.receiver
|
||||
#Do something clever instead of
|
||||
# compiler will always return slot. with known value or not
|
||||
r = Compiler.compile(expression.receiver, method )
|
||||
if( r.is_a? Parfait::Class )
|
||||
class_name = r.name
|
||||
if( r.value.is_a? Parfait::Class )
|
||||
class_name = r.value.name
|
||||
else
|
||||
raise "unimplemented #{r}"
|
||||
end
|
||||
|
@ -7,7 +7,7 @@ module Virtual
|
||||
|
||||
def self.compile_class expression , method
|
||||
clazz = Parfait::Space.object_space.get_class_by_name! expression.name
|
||||
puts "Created class #{clazz.name.inspect}"
|
||||
puts "Compiling class #{clazz.name.inspect}"
|
||||
expression_value = nil
|
||||
expression.expressions.each do |expr|
|
||||
# check if it's a function definition and add
|
||||
|
@ -2,7 +2,8 @@
|
||||
require_relative "test_foo"
|
||||
require_relative "test_if"
|
||||
require_relative "test_functions"
|
||||
require_relative "test_string_class"
|
||||
#require_relative "test_hello"
|
||||
#require_relative "test_putint"
|
||||
#require_relative "test_recursive_fibo"
|
||||
#require_relative "test_while_fibo"
|
||||
require_relative "test_recursive_fibo"
|
||||
require_relative "test_while_fibo"
|
||||
|
@ -7,9 +7,9 @@ class TestRecursinveFibo < MiniTest::Test
|
||||
@string_input = <<HERE
|
||||
def fibonaccir( n )
|
||||
if( n <= 1 )
|
||||
return n
|
||||
return n
|
||||
else
|
||||
a = fibonaccir( n - 1 )
|
||||
a = fibonaccir( n - 1 )
|
||||
b = fibonaccir( n - 2 )
|
||||
return a + b
|
||||
end
|
||||
@ -21,11 +21,7 @@ end
|
||||
|
||||
fib_print(10)
|
||||
HERE
|
||||
@should = [0x0,0x40,0x2d,0xe9,0x1,0x0,0x53,0xe3,0xd,0x0,0x0,0xda,0x1,0x40,0x43,0xe2,0x8,0x0,0x2d,0xe9,0x4,0x30,0xa0,0xe1,0xf8,0xff,0xff,0xeb,0x8,0x0,0xbd,0xe8,0x0,0x50,0xa0,0xe1,0x2,0x60,0x43,0xe2,0x28,0x0,0x2d,0xe9,0x6,0x30,0xa0,0xe1,0xf2,0xff,0xff,0xeb,0x28,0x0,0xbd,0xe8,0x0,0x70,0xa0,0xe1,0x7,0x0,0x85,0xe0,0x0,0x0,0x0,0xea,0x3,0x0,0xa0,0xe1,0x0,0x80,0xbd,0xe8]
|
||||
@output = " 55 "
|
||||
@target = [:Object , :fibonaccir]
|
||||
parse
|
||||
write "recursive_fibo"
|
||||
@expect = [Virtual::Return ]
|
||||
check
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -67,27 +67,8 @@ class String
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@should = [0x0,0xb0,0xa0,0xe3,0x2a,0x10,0xa0,0xe3,0x13,0x0,0x0,0xeb,0x1,0x70,0xa0,0xe3,0x0,0x0,0x0,0xef,0x0,0x70,0xa0,0xe1,0x0,0x40,0x2d,0xe9,0xa,0x30,0x42,0xe2,0x22,0x21,0x42,0xe0,0x22,0x22,0x82,0xe0,0x22,0x24,0x82,0xe0,0x22,0x28,0x82,0xe0,0xa2,0x21,0xa0,0xe1,0x2,0x41,0x82,0xe0,0x84,0x30,0x53,0xe0,0x1,0x20,0x82,0x52,0xa,0x30,0x83,0x42,0x30,0x30,0x83,0xe2,0x0,0x30,0xc1,0xe5,0x1,0x10,0x41,0xe2,0x0,0x0,0x52,0xe3,0xef,0xff,0xff,0x1b,0x0,0x80,0xbd,0xe8,0x0,0x40,0x2d,0xe9,0x1,0x20,0xa0,0xe1,0x20,0x10,0x8f,0xe2,0x9,0x10,0x81,0xe2,0xe9,0xff,0xff,0xeb,0x14,0x10,0x8f,0xe2,0xc,0x20,0xa0,0xe3,0x1,0x0,0xa0,0xe3,0x4,0x70,0xa0,0xe3,0x0,0x0,0x0,0xef,0x0,0x70,0xa0,0xe1,0x0,0x80,0xbd,0xe8,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20]
|
||||
@output = " 42 "
|
||||
parse
|
||||
@target = [:Word , :plus]
|
||||
write "class"
|
||||
end
|
||||
|
||||
def parse
|
||||
parser = Parser::Salama.new
|
||||
syntax = parser.parse_with_debug(@string_input)
|
||||
parts = Parser::Transform.new.apply(syntax)
|
||||
# file is a list of expressions, all but the last must be a function
|
||||
# and the last is wrapped as a main
|
||||
parts.each_with_index do |part,index|
|
||||
if index == (parts.length - 1)
|
||||
expr = part.compile( @object_space.context )
|
||||
else
|
||||
expr = part.compile( @object_space.context )
|
||||
raise "should be function definition for now, not #{part.inspect}#{expr.inspect}" unless expr.is_a? Boot::BootClass
|
||||
end
|
||||
end
|
||||
@expect = [Virtual::Return ]
|
||||
check
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -11,26 +11,23 @@ def fibonaccit(n) # n == r0
|
||||
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
|
||||
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
|
||||
b.putint()
|
||||
return b
|
||||
end # r0 <- r5
|
||||
|
||||
fibonaccit( 10 )
|
||||
HERE
|
||||
@should = [0x0,0x40,0x2d,0xe9,0x0,0x40,0xa0,0xe3,0x1,0x50,0xa0,0xe3,0x1,0x0,0x53,0xe3,0x4,0x0,0x0,0xda,0x4,0x60,0xa0,0xe1,0x5,0x40,0xa0,0xe1,0x5,0x50,0x86,0xe0,0x1,0x30,0x43,0xe2,0xf8,0xff,0xff,0xea,0x20,0x0,0x2d,0xe9,0x5,0x20,0xa0,0xe1,0xd4,0xff,0xff,0xeb,0x20,0x0,0xbd,0xe8,0x5,0x0,0xa0,0xe1,0x0,0x80,0xbd,0xe8]
|
||||
@output = " 55 "
|
||||
@target = [:Object , :fibonaccit]
|
||||
parse
|
||||
write "while"
|
||||
@expect = [Virtual::Return ]
|
||||
check
|
||||
end
|
||||
|
||||
# a hand coded version of the fibonachi numbers (moved to kernel to be able to call it)
|
||||
# not my hand off course, found in the net from a basic introduction
|
||||
def test_kernel_fibo
|
||||
int = Register::Integer.new(Virtual::RegisterMachine.instance.receiver_register)
|
||||
def ttest_kernel_fibo
|
||||
int = Register::Integer.new(Virtual::RegisterMachine.instance.receiver_register)
|
||||
fibo = @object_space.get_class_by_name(:Object).resolve_method(:fibo)
|
||||
main = @object_space.main
|
||||
main.mov int , 10
|
||||
@ -44,4 +41,3 @@ HERE
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user