2015-07-19 11:31:57 +02:00
|
|
|
require_relative "compiler_helper"
|
|
|
|
|
|
|
|
|
|
|
|
class CompilerTest < MiniTest::Test
|
|
|
|
def setup
|
|
|
|
Virtual.machine.boot
|
|
|
|
end
|
|
|
|
def check
|
2015-09-19 17:56:18 +02:00
|
|
|
res = Bosl::Compiler.compile( @expression , Virtual.machine.space.get_main )
|
2015-07-19 11:31:57 +02:00
|
|
|
assert res.is_a?(Virtual::Slot) , "compiler must compile to slot, not #{res.class}"
|
|
|
|
end
|
|
|
|
def true_ex
|
|
|
|
Ast::TrueExpression.new
|
|
|
|
end
|
|
|
|
def name_ex
|
|
|
|
Ast::NameExpression.new("name#{rand(100)}")
|
|
|
|
end
|
|
|
|
def list
|
|
|
|
[true_ex]
|
|
|
|
end
|
|
|
|
def test_if_expression
|
|
|
|
@expression = Ast::IfExpression.new( true_ex , list , list)
|
|
|
|
check
|
|
|
|
end
|
|
|
|
def test_function_expression
|
|
|
|
@expression = Ast::FunctionExpression.new( "name", [] , [true_ex] ,nil)
|
|
|
|
check
|
|
|
|
end
|
|
|
|
end
|