start testing the previous runners more rigourusly
This commit is contained in:
parent
bc278a61eb
commit
741c55cba3
43
test/fragments/helper.rb
Normal file
43
test/fragments/helper.rb
Normal file
@ -0,0 +1,43 @@
|
||||
require_relative '../helper'
|
||||
|
||||
#test the generation of code fragments.
|
||||
# ie parse assumes @string_input
|
||||
# compile
|
||||
# assemble/write assume a @should array with the bytes in it
|
||||
|
||||
module Fragments
|
||||
# need a code generator, for arm
|
||||
def setup
|
||||
@program = Vm::Program.new "Arm"
|
||||
end
|
||||
|
||||
def parse
|
||||
parser = Parser::Crystal.new
|
||||
syntax = parser.parse_with_debug(@string_input)
|
||||
parts = Parser::Transform.new.apply(syntax)
|
||||
# file is a list of expressions, all but the last must be a function
|
||||
# and the last is wrapped as a main
|
||||
parts.each_with_index do |part,index|
|
||||
if index == (parts.length - 1)
|
||||
expr = part.compile( @program.context , @program.main )
|
||||
else
|
||||
expr = part.compile( @program.context , nil )
|
||||
raise "should be function definition for now" unless expr.is_a? Vm::Function
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# helper to write the file
|
||||
def write name
|
||||
writer = Elf::ObjectWriter.new(@program , Elf::Constants::TARGET_ARM)
|
||||
assembly = writer.text
|
||||
# use this for getting the bytes to compare to :
|
||||
#puts assembly
|
||||
writer.save("#{name}_test.o")
|
||||
assembly.text.bytes.each_with_index do |byte , index|
|
||||
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
|
||||
end
|
||||
end
|
16
test/fragments/test_hello.rb
Normal file
16
test/fragments/test_hello.rb
Normal file
@ -0,0 +1,16 @@
|
||||
require_relative 'helper'
|
||||
require 'parslet/convenience'
|
||||
|
||||
class TestHello < MiniTest::Test
|
||||
include Fragments
|
||||
|
||||
def test_hello
|
||||
@string_input = <<HERE
|
||||
putstring( "Hello Raisa, I am crystksdfkljsncjncn" )
|
||||
HERE
|
||||
@should = [0x0,0xb0,0xa0,0xe3,0xe,0x0,0x2d,0xe9,0x28,0x0,0xaf,0xe3,0x2,0x0,0x0,0xeb,0xe,0x0,0xbd,0xe8,0x1,0x70,0xa0,0xe3,0x0,0x0,0x0,0xef,0x0,0x40,0x2d,0xe9,0x1,0x20,0xa0,0xe1,0x0,0x10,0xa0,0xe1,0x1,0x0,0xa0,0xe3,0x4,0x70,0xa0,0xe3,0x0,0x0,0x0,0xef,0x0,0x80,0xbd,0xe8,0x48,0x65,0x6c,0x6c,0x6f,0x20,0x52,0x61,0x69,0x73,0x61,0x2c,0x20,0x49,0x20,0x61,0x6d,0x20,0x63,0x72,0x79,0x73,0x74,0x6b,0x73,0x64,0x66,0x6b,0x6c,0x6a,0x73,0x6e,0x63,0x6a,0x6e,0x63,0x6e,0x0,0x0,0x0]
|
||||
parse
|
||||
write "hello"
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user