more fragment tests

This commit is contained in:
Torsten Ruger 2015-07-19 13:31:13 +03:00
parent 31d825df7b
commit d7c9245bb3
7 changed files with 22 additions and 48 deletions

View File

@ -37,8 +37,8 @@ module Virtual
to to
end end
def self.compile_module expression , method def self.compile_modulename expression , method
clazz = Space.space.get_class_by_name name clazz = Parfait::Space.object_space.get_class_by_name expression.name
raise "uups #{clazz}.#{name}" unless clazz raise "uups #{clazz}.#{name}" unless clazz
to = Return.new(Reference , clazz ) to = Return.new(Reference , clazz )
method.source.add_code Set.new( clazz , to ) method.source.add_code Set.new( clazz , to )

View File

@ -7,10 +7,10 @@ module Virtual
p.name p.name
end end
if expression.receiver if expression.receiver
#Do something clever instead of # compiler will always return slot. with known value or not
r = Compiler.compile(expression.receiver, method ) r = Compiler.compile(expression.receiver, method )
if( r.is_a? Parfait::Class ) if( r.value.is_a? Parfait::Class )
class_name = r.name class_name = r.value.name
else else
raise "unimplemented #{r}" raise "unimplemented #{r}"
end end

View File

@ -7,7 +7,7 @@ module Virtual
def self.compile_class expression , method def self.compile_class expression , method
clazz = Parfait::Space.object_space.get_class_by_name! expression.name 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_value = nil
expression.expressions.each do |expr| expression.expressions.each do |expr|
# check if it's a function definition and add # check if it's a function definition and add

View File

@ -2,7 +2,8 @@
require_relative "test_foo" require_relative "test_foo"
require_relative "test_if" require_relative "test_if"
require_relative "test_functions" require_relative "test_functions"
require_relative "test_string_class"
#require_relative "test_hello" #require_relative "test_hello"
#require_relative "test_putint" #require_relative "test_putint"
#require_relative "test_recursive_fibo" require_relative "test_recursive_fibo"
#require_relative "test_while_fibo" require_relative "test_while_fibo"

View File

@ -21,11 +21,7 @@ end
fib_print(10) fib_print(10)
HERE 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] @expect = [Virtual::Return ]
@output = " 55 " check
@target = [:Object , :fibonaccir]
parse
write "recursive_fibo"
end end
end end

View File

@ -67,27 +67,8 @@ class String
end end
end end
HERE 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] @expect = [Virtual::Return ]
@output = " 42 " check
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
end end
end end

View File

@ -20,16 +20,13 @@ end # r0 <- r5
fibonaccit( 10 ) fibonaccit( 10 )
HERE 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] @expect = [Virtual::Return ]
@output = " 55 " check
@target = [:Object , :fibonaccit]
parse
write "while"
end end
# a hand coded version of the fibonachi numbers (moved to kernel to be able to call it) # 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 # not my hand off course, found in the net from a basic introduction
def test_kernel_fibo def ttest_kernel_fibo
int = Register::Integer.new(Virtual::RegisterMachine.instance.receiver_register) int = Register::Integer.new(Virtual::RegisterMachine.instance.receiver_register)
fibo = @object_space.get_class_by_name(:Object).resolve_method(:fibo) fibo = @object_space.get_class_by_name(:Object).resolve_method(:fibo)
main = @object_space.main main = @object_space.main
@ -44,4 +41,3 @@ HERE
end end
end end