fixing basic and field access to return register

as that is the new way, drop a layer, code to registers
This commit is contained in:
Torsten Ruger
2015-10-13 16:42:53 +03:00
parent 80d58ee03c
commit f506f95cbf
6 changed files with 48 additions and 45 deletions

View File

@ -5,11 +5,13 @@ module CompilerHelper
Phisol::Compiler.class_eval do
def set_main
@clazz = Virtual.machine.space.get_class_by_name :Object
@method = Virtual.machine.space.get_main
end
end
def check
machine = Virtual.machine.boot
machine = Virtual.machine
machine.boot unless machine.booted
parser = Parser::Salama.new
parser = parser.send @root
syntax = parser.parse_with_debug(@string_input)
@ -18,13 +20,8 @@ module CompilerHelper
compiler = Phisol::Compiler.new
compiler.set_main
produced = compiler.process( parts )
produced = [produced] unless produced.is_a? Array
assert @output , "No output given"
assert_equal produced.length, @output.length , "Block length"
produced.each_with_index do |b,i|
codes = @output[i]
assert_equal codes , b.class , "Class #{i} "
end
assert_equal produced.class, @output , "Wrong class"
end
end

View File

@ -1,4 +1,3 @@
require_relative "test_basic"
require_relative "test_hello"
require_relative "test_compiler"
require_relative "test_field_access"

View File

@ -6,7 +6,7 @@ class TestBasic < MiniTest::Test
def setup
@root = :basic_type
@output = [Virtual::Return]
@output = Register::RegisterValue
end
def test_number
@ -15,7 +15,7 @@ class TestBasic < MiniTest::Test
end
def test_true
@string_input = 'true '
@string_input = 'true'
check
end
def test_false
@ -30,12 +30,13 @@ class TestBasic < MiniTest::Test
def test_var
@string_input = 'int foo '
@root = :field_def
@output = AST::Node
check
end
def test_self
@string_input = 'self '
@output = [Virtual::Self]
@output = Virtual::Self
check
end

View File

@ -1,24 +1,30 @@
require_relative "compiler_helper"
require_relative "code_checker"
module Virtual
class TestFoo < MiniTest::Test
include CodeChecker
class TestFields < MiniTest::Test
include CompilerHelper
def test_foo3
@string_input = <<HERE
class Object
field int a
int foo(int x)
int b = self.a
return b +x
end
end
HERE
@output = [ [Virtual::MethodEnter] , [Virtual::MethodReturn] ]
check
def setup
Virtual.machine.boot
end
def test_field_not_defined
@root = :field_access
@string_input = <<HERE
self.a
HERE
assert_raises(RuntimeError) { check }
end
def test_field
Virtual.machine.space.get_class_by_name(:Object).object_layout.add_instance_variable(:bro)
@root = :field_access
@string_input = <<HERE
self.bro
HERE
@output = Register::RegisterValue
check
end
end
end