From 4cd979e3e9d448bd529fd6cf8a89e7cc48aba64c Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Thu, 8 Dec 2016 19:39:16 +0200 Subject: [PATCH] remove soml parser from tests --- stash/soml/fragments/test_word.rb | 2 +- {test => stash}/test_runner.rb | 2 ++ test/elf/test_hello.rb | 17 ++++++++++++- test/register/interpreter/helper.rb | 6 ++--- test/register/interpreter/test_add.rb | 12 +++++++++ test/register/interpreter/test_if.rb | 34 ++++++++++++++++++++++++++ test/register/interpreter/test_mult.rb | 13 ++++++++++ test/register/interpreter/test_plus.rb | 12 +++++++++ test/register/interpreter/test_puts.rb | 13 ++++++++++ 9 files changed, 105 insertions(+), 6 deletions(-) rename {test => stash}/test_runner.rb (91%) diff --git a/stash/soml/fragments/test_word.rb b/stash/soml/fragments/test_word.rb index 6ba6a64b..02508823 100644 --- a/stash/soml/fragments/test_word.rb +++ b/stash/soml/fragments/test_word.rb @@ -1,6 +1,6 @@ require_relative 'helper' -module Soml +module Typed class TestWord < MiniTest::Test include Fragments diff --git a/test/test_runner.rb b/stash/test_runner.rb similarity index 91% rename from test/test_runner.rb rename to stash/test_runner.rb index c35f3ed4..0a787b3a 100644 --- a/test/test_runner.rb +++ b/stash/test_runner.rb @@ -21,6 +21,8 @@ class TestRunner < MiniTest::Test string = File.read(file) parser = Parser::Salama.new object_space = Register::Program.new "Arm" + #TODO : files would have to include s-expressions now + # those can be obtained with to_code utility in soml-parser syntax = parser.parse_with_debug(string, reporter: Parslet::ErrorReporter::Deepest.new) assert syntax parts = Parser::Transform.new.apply(syntax) diff --git a/test/elf/test_hello.rb b/test/elf/test_hello.rb index 3fdb69fd..4f4c4386 100644 --- a/test/elf/test_hello.rb +++ b/test/elf/test_hello.rb @@ -1,10 +1,11 @@ require_relative "../helper" class HelloTest < MiniTest::Test + include AST::Sexp def check machine = Register.machine.boot - machine.parse_and_compile @string_input + Typed.compile( @input ) machine.collect machine.translate_arm writer = Elf::ObjectWriter.new @@ -19,6 +20,20 @@ class Object end end HERE + @input = s(:statements, + s(:class, :Object, + s(:derives, nil), + s(:statements, + s(:function, :Integer, + s(:name, :main), + s(:parameters), + s(:statements, + s(:return, + s(:call, + s(:name, :putstring), + s(:arguments), + s(:receiver, + s(:string, "Hello again\\n"))))))))) check end end diff --git a/test/register/interpreter/helper.rb b/test/register/interpreter/helper.rb index b87d817f..92a087ca 100644 --- a/test/register/interpreter/helper.rb +++ b/test/register/interpreter/helper.rb @@ -2,13 +2,11 @@ require_relative "../../helper" require "register/interpreter" module Ticker + include AST::Sexp def setup machine = Register.machine.boot - syntax = Parser::Salama.new.parse_with_debug(@string_input, reporter: Parslet::ErrorReporter::Deepest.new) - parts = Parser::Transform.new.apply(syntax) - #puts parts.inspect - Typed.compile( parts ) + Typed.compile( @input ) machine.collect @interpreter = Register::Interpreter.new @interpreter.start Register.machine.init diff --git a/test/register/interpreter/test_add.rb b/test/register/interpreter/test_add.rb index 8c130e04..3c83c0b1 100644 --- a/test/register/interpreter/test_add.rb +++ b/test/register/interpreter/test_add.rb @@ -11,6 +11,18 @@ class Space end end HERE + @input = s(:statements, + s(:class, :Space, + s(:derives, nil), + s(:statements, + s(:function, :Integer, + s(:name, :main), + s(:parameters), + s(:statements, + s(:return, + s(:operator_value, :+, + s(:int, 5), + s(:int, 7)))))))) super end diff --git a/test/register/interpreter/test_if.rb b/test/register/interpreter/test_if.rb index c381b210..4ab3501d 100644 --- a/test/register/interpreter/test_if.rb +++ b/test/register/interpreter/test_if.rb @@ -19,6 +19,40 @@ class Space end end HERE + @input = s(:statements, + s(:class, :Space, + s(:derives, nil), + s(:statements, + s(:function, :Integer, + s(:name, :itest), + s(:parameters, + s(:parameter, :Integer, :n)), + s(:statements, + s(:if_statement, :zero, + s(:condition, + s(:operator_value, :-, + s(:name, :n), + s(:int, 12))), + s(:true_statements, + s(:call, + s(:name, :putstring), + s(:arguments), + s(:receiver, + s(:string, "then")))), + s(:false_statements, + s(:call, + s(:name, :putstring), + s(:arguments), + s(:receiver, + s(:string, "else"))))))), + s(:function, :Integer, + s(:name, :main), + s(:parameters), + s(:statements, + s(:call, + s(:name, :itest), + s(:arguments, + s(:int, 20)))))))) super end diff --git a/test/register/interpreter/test_mult.rb b/test/register/interpreter/test_mult.rb index 14a6aa51..4603acef 100644 --- a/test/register/interpreter/test_mult.rb +++ b/test/register/interpreter/test_mult.rb @@ -11,7 +11,20 @@ class Space return #{2**31} * #{2**31} end end + HERE + @input = s(:statements, + s(:class, :Space, + s(:derives, nil), + s(:statements, + s(:function, :Integer, + s(:name, :main), + s(:parameters), + s(:statements, + s(:return, + s(:operator_value, :*, + s(:int, 2147483648), + s(:int, 2147483648)))))))) super end diff --git a/test/register/interpreter/test_plus.rb b/test/register/interpreter/test_plus.rb index 5d46515d..bdc488ce 100644 --- a/test/register/interpreter/test_plus.rb +++ b/test/register/interpreter/test_plus.rb @@ -11,6 +11,18 @@ class Space end end HERE + @input = s(:statements, + s(:class, :Space, + s(:derives, nil), + s(:statements, + s(:function, :Integer, + s(:name, :main), + s(:parameters), + s(:statements, + s(:return, + s(:operator_value, :+, + s(:int, 4611686018427387903), + s(:int, 1)))))))) super end diff --git a/test/register/interpreter/test_puts.rb b/test/register/interpreter/test_puts.rb index dc3891f4..b076c387 100644 --- a/test/register/interpreter/test_puts.rb +++ b/test/register/interpreter/test_puts.rb @@ -11,6 +11,19 @@ class Space end end HERE + @input = s(:statements, + s(:class, :Space, + s(:derives, nil), + s(:statements, + s(:function, :Integer, + s(:name, :main), + s(:parameters), + s(:statements, + s(:call, + s(:name, :putstring), + s(:arguments), + s(:receiver, + s(:string, "Hello again")))))))) super end