2014-05-21 20:13:12 +02:00
|
|
|
require_relative '../helper'
|
|
|
|
|
2015-07-18 13:33:09 +02:00
|
|
|
# simple tests to check parsing pworks and the first classes come out right.
|
|
|
|
#
|
|
|
|
# build up from small to check larger expressions are correct
|
2014-05-21 20:37:04 +02:00
|
|
|
|
2014-05-21 20:13:12 +02:00
|
|
|
module Fragments
|
|
|
|
|
2015-07-18 13:33:09 +02:00
|
|
|
def check
|
2015-10-05 23:27:13 +02:00
|
|
|
expressions = Virtual.machine.boot.parse_and_compile @string_input
|
2015-07-18 13:33:09 +02:00
|
|
|
@expect.each_with_index do | should , i |
|
2015-09-19 17:56:18 +02:00
|
|
|
exp_i = expressions[i]
|
|
|
|
assert exp_i.is_a?(Virtual::Slot) , "compiles should return #{should}, not #{exp_i}"
|
|
|
|
assert_equal should , exp_i.class
|
2014-05-21 20:13:12 +02:00
|
|
|
end
|
2015-07-19 10:15:38 +02:00
|
|
|
# Virtual.machine.run_passes
|
2014-05-21 20:13:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# helper to write the file
|
|
|
|
def write name
|
2015-05-16 11:53:10 +02:00
|
|
|
writer = Elf::ObjectWriter.new(@object_machine , Elf::Constants::TARGET_ARM)
|
2014-05-21 20:13:12 +02:00
|
|
|
assembly = writer.text
|
2015-05-16 11:53:10 +02:00
|
|
|
writer.save("#{name}.o")
|
|
|
|
function = @object_machine.classes[@target[0]]
|
2014-06-05 15:27:25 +02:00
|
|
|
assert function , "no class #{@target[0]}"
|
2014-06-05 12:02:36 +02:00
|
|
|
function = function.get_function(@target[1])
|
2014-06-05 15:27:25 +02:00
|
|
|
assert function , "no function #{@target[1]} for class #{@target[0]}"
|
2014-06-05 12:02:36 +02:00
|
|
|
io = StringIO.new
|
|
|
|
function.assemble io
|
|
|
|
assembly = io.string
|
2015-05-16 11:53:10 +02:00
|
|
|
# use this for getting the bytes to compare to :
|
2014-06-12 08:07:03 +02:00
|
|
|
puts bytes(assembly)
|
2014-06-05 12:02:36 +02:00
|
|
|
assembly.bytes.each_with_index do |byte , index|
|
2014-05-21 20:13:12 +02:00
|
|
|
is = @should[index]
|
|
|
|
assert_equal Fixnum , is.class , "@#{index.to_s(16)} = #{is}"
|
|
|
|
assert_equal byte , is , "@#{index.to_s(16)} #{byte.to_s(16)} != #{is.to_s(16)}"
|
|
|
|
end
|
2014-05-28 13:55:13 +02:00
|
|
|
if( RbConfig::CONFIG["build_cpu"] == "arm")
|
|
|
|
system "ld -N #{name}.o"
|
|
|
|
result = %x[./a.out]
|
|
|
|
assert_equal @output , result
|
|
|
|
end
|
2014-05-21 20:13:12 +02:00
|
|
|
end
|
2014-06-05 12:02:36 +02:00
|
|
|
def bytes string
|
|
|
|
"[" + string.bytes.collect{|b| "0x"+ b.to_s(16)}.join(",") + "]"
|
|
|
|
end
|
2015-05-16 11:53:10 +02:00
|
|
|
|
2014-05-21 20:13:12 +02:00
|
|
|
end
|