mirror of https://github.com/ademakov/libjit
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
750 B
35 lines
750 B
16 years ago
|
module JitAssertions
|
||
|
def assert_function_result(args, &block)
|
||
|
result_type = nil
|
||
|
expected_result = nil
|
||
|
param_types = []
|
||
|
params = []
|
||
|
|
||
|
args.each do |k, v|
|
||
|
case k.to_s
|
||
|
when /^arg(\d+)$/
|
||
|
n = $1.to_i
|
||
|
param_types[n] = v[0]
|
||
|
params[n] = v[1]
|
||
|
when 'result'
|
||
|
result_type = v[0]
|
||
|
expected_result = v[1]
|
||
|
else
|
||
|
raise "Bad arg #{arg}"
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function = nil
|
||
|
JIT::Context.build do |context|
|
||
|
signature = JIT::Type.create_signature(
|
||
|
JIT::ABI::CDECL,
|
||
|
result_type,
|
||
|
param_types)
|
||
|
function = JIT::Function.compile(context, signature, &block)
|
||
|
end
|
||
|
|
||
|
assert_equal(expected_result, function.apply(*params))
|
||
|
end
|
||
|
end
|
||
|
|