2015-07-19 11:31:57 +02:00
|
|
|
require_relative "compiler_helper"
|
|
|
|
|
|
|
|
|
|
|
|
class CompilerTest < MiniTest::Test
|
2015-09-20 16:33:05 +02:00
|
|
|
include AST::Sexp
|
2015-07-19 11:31:57 +02:00
|
|
|
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-09-20 16:33:05 +02:00
|
|
|
assert res.is_a?(Virtual::Slot) , "compiler must compile to slot, not #{res.inspect}"
|
2015-07-19 11:31:57 +02:00
|
|
|
end
|
2015-09-20 16:33:05 +02:00
|
|
|
def ttest_if_expression
|
|
|
|
#TODO review constant : all expressions return a slot
|
|
|
|
@expression = s(:if,
|
|
|
|
s(:condition,
|
|
|
|
s(:int, 0)),
|
|
|
|
s(:if_true,
|
|
|
|
s(:int, 42)),
|
|
|
|
s(:if_false, nil))
|
2015-07-19 11:31:57 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
def test_function_expression
|
2015-09-20 16:33:05 +02:00
|
|
|
@expression = s(:function, :int, s(:name, :foo),
|
|
|
|
s(:parameters, s(:parameter, :ref, :x)),
|
|
|
|
s(:expressions, s(:int, 5)))
|
2015-07-19 11:31:57 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
end
|