rebooting tests for small compiles
This commit is contained in:
parent
7b1e89effb
commit
b83f50c57c
@ -71,10 +71,6 @@ module Virtual
|
||||
@codes.inject(0){|count , instruction| count += instruction.byte_length }
|
||||
end
|
||||
|
||||
def to_s
|
||||
Sof.write(self)
|
||||
end
|
||||
|
||||
private
|
||||
# helper for determining reachable blocks
|
||||
def add_next ret
|
||||
|
@ -9,9 +9,6 @@ module Virtual
|
||||
# instructions, thus defining a minimal set of instructions needed to implement oo.
|
||||
|
||||
class Instruction
|
||||
def to_s
|
||||
Sof.write(self)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -128,13 +128,6 @@ module Parfait
|
||||
old_length = old_length - 1
|
||||
end
|
||||
end
|
||||
|
||||
def to_s
|
||||
Sof.write(self)
|
||||
end
|
||||
def inspect
|
||||
to_s
|
||||
end
|
||||
end
|
||||
class List
|
||||
def to_sof_node(writer , level , ref )
|
||||
|
@ -1,8 +1,8 @@
|
||||
|
||||
require_relative "test_foo"
|
||||
require_relative "test_if"
|
||||
#require_relative "test_functions"
|
||||
#require_relative "test_hello"
|
||||
#require_relative "test_if"
|
||||
#require_relative "test_putint"
|
||||
#require_relative "test_recursive_fibo"
|
||||
#require_relative "test_while_fibo"
|
||||
|
@ -5,7 +5,7 @@ class TestFoo < MiniTest::Test
|
||||
|
||||
def test_foo2
|
||||
@string_input = <<HERE
|
||||
def foo(x)
|
||||
def foo2(x)
|
||||
a = 5
|
||||
end
|
||||
3.foo( 4 )
|
||||
|
@ -3,7 +3,19 @@ require_relative 'helper'
|
||||
class TestIf < MiniTest::Test
|
||||
include Fragments
|
||||
|
||||
def test_if
|
||||
def test_if_basic
|
||||
@string_input = <<HERE
|
||||
if( n < 12)
|
||||
3
|
||||
else
|
||||
4
|
||||
end
|
||||
HERE
|
||||
@expect = [Virtual::Return ]
|
||||
check
|
||||
end
|
||||
|
||||
def ttest_if_function
|
||||
@string_input = <<HERE
|
||||
def itest(n)
|
||||
if( n < 12)
|
||||
@ -15,11 +27,7 @@ end
|
||||
|
||||
itest(20)
|
||||
HERE
|
||||
@should = [0x0,0x40,0x2d,0xe9,0xc,0x0,0x53,0xe3,0x3,0x0,0x0,0xba,0x34,0x20,0x8f,0xe2,0x8,0x30,0xa0,0xe3,0xd4,0xff,0xff,0xeb,0x2,0x0,0x0,0xea,0x2c,0x20,0x8f,0xe2,0x8,0x30,0xa0,0xe3,0xd0,0xff,0xff,0xeb,0x0,0x80,0xbd,0xe8]
|
||||
@output = "else "
|
||||
@target = [:Object , :itest]
|
||||
parse
|
||||
write "if"
|
||||
@expect = [Virtual::Return ]
|
||||
check
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,7 +1,16 @@
|
||||
require_relative "virtual_helper"
|
||||
|
||||
|
||||
class TestBasic < MiniTest::Test
|
||||
include VirtualHelper
|
||||
def check
|
||||
expressions = Virtual.machine.boot.compile_main @string_input
|
||||
if( expressions.first.is_a? Virtual::Self )
|
||||
expressions.first.type.instance_variable_set :@of_class , nil
|
||||
end
|
||||
is = Sof.write(expressions)
|
||||
#puts is
|
||||
assert_equal @output , is
|
||||
end
|
||||
|
||||
def test_number
|
||||
@string_input = '42 '
|
||||
|
@ -1,16 +1,38 @@
|
||||
require_relative "virtual_helper"
|
||||
|
||||
class TestMethods < MiniTest::Test
|
||||
include VirtualHelper
|
||||
#TODO need to rethink this approach
|
||||
# Sof working as well as it is will serialize the whole space as everythink is reachable from a
|
||||
# method. Even ignoring the size and readability issues, it make sthe test to fragile:
|
||||
# any small object change anywhere in parfait will cause a different output
|
||||
def ttest_simplest_function
|
||||
@string_input = <<HERE
|
||||
module Virtual
|
||||
class TestMethods < MiniTest::Test
|
||||
|
||||
def check
|
||||
Virtual.machine.boot.compile_main @string_input
|
||||
produced = Virtual.machine.space.get_main.source
|
||||
assert @output , "No output given"
|
||||
assert_equal @output.length , produced.blocks.length , "Block length"
|
||||
produced.blocks.each_with_index do |b,i|
|
||||
codes = @output[i]
|
||||
assert codes , "No codes for block #{i}"
|
||||
assert_equal b.codes.length , codes.length , "Code length for block #{i}"
|
||||
b.codes.each_with_index do |c , ii |
|
||||
assert_equal codes[ii] , c.class , "Block #{i} , code #{ii}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_simplest_function
|
||||
@string_input = <<HERE
|
||||
def foo(x)
|
||||
5
|
||||
end
|
||||
HERE
|
||||
@output = [[MethodEnter] ,[MethodReturn]]
|
||||
check
|
||||
end
|
||||
|
||||
def ttest_second_simplest_function
|
||||
@string_input = <<HERE
|
||||
def foo(x)
|
||||
x
|
||||
end
|
||||
HERE
|
||||
@output = nil
|
||||
check
|
||||
@ -142,3 +164,4 @@ HERE
|
||||
check
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,37 +1,13 @@
|
||||
require_relative '../helper'
|
||||
require 'parslet/convenience'
|
||||
require "yaml"
|
||||
|
||||
Parfait::Object.class_eval do
|
||||
def secret_layout_hammer
|
||||
internal_object_set(Parfait::Object::LAYOUT_INDEX , nil)
|
||||
end
|
||||
end
|
||||
|
||||
module VirtualHelper
|
||||
# need a code generator, for arm
|
||||
def setup
|
||||
@machine = Virtual.machine.boot
|
||||
end
|
||||
|
||||
def check
|
||||
expressions = @machine.compile_main @string_input
|
||||
if( expressions.first.is_a? Parfait::Method )
|
||||
# stops the whole objectspace beeing tested
|
||||
# with the class comes superclass and all methods
|
||||
expressions.first.instance_variable_set :@for_class , nil
|
||||
expressions.first.secret_layout_hammer
|
||||
expressions.first.code.secret_layout_hammer
|
||||
end
|
||||
if( expressions.first.is_a? Virtual::Self )
|
||||
# stops the whole objectspace beeing tested
|
||||
# with the class comes superclass and all methods
|
||||
expressions.first.type.instance_variable_set :@of_class , nil
|
||||
end
|
||||
is = Sof.write(expressions)
|
||||
#puts is
|
||||
is.gsub!("\n" , "*^*")
|
||||
assert_equal @output , is
|
||||
Virtual.machine.boot.compile_main @string_input
|
||||
produced = Virtual.machine.space.get_main.source
|
||||
assert_equal @output , produced
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user