rubyx/stash/soml/expressions/helper.rb

35 lines
922 B
Ruby
Raw Normal View History

require_relative '../../helper'
2014-06-25 14:20:46 +02:00
require 'parslet/convenience'
2015-10-23 13:22:55 +02:00
Soml::Compiler.class_eval do
2015-10-14 14:17:33 +02:00
def set_main main
2015-10-22 17:16:29 +02:00
@clazz = Register.machine.space.get_class_by_name :Object
2015-10-14 14:17:33 +02:00
@method = main
2015-10-28 20:40:48 +01:00
@current = main.instructions.next
2015-10-14 14:17:33 +02:00
end
end
2015-11-07 11:18:08 +01:00
module ExpressionHelper
2015-07-02 09:44:44 +02:00
2015-10-14 12:48:42 +02:00
def set_main compiler
2015-10-22 17:16:29 +02:00
compiler.set_main Register.machine.space.get_main
2015-10-14 12:48:42 +02:00
end
2015-10-10 09:02:28 +02:00
def check
2015-10-22 17:16:29 +02:00
machine = Register.machine
machine.boot unless machine.booted
2015-10-10 09:02:28 +02:00
parser = Parser::Salama.new
parser = parser.send @root
2015-11-19 09:10:13 +01:00
syntax = parser.parse_with_debug(@string_input, reporter: Parslet::ErrorReporter::Deepest.new)
2015-10-10 09:02:28 +02:00
parts = Parser::Transform.new.apply(syntax)
codes = Soml.ast_to_code parts
2015-10-10 09:02:28 +02:00
#puts parts.inspect
2015-10-23 13:22:55 +02:00
compiler = Soml::Compiler.new
2015-10-14 12:48:42 +02:00
set_main(compiler)
produced = compiler.process( codes )
2015-10-10 09:02:28 +02:00
assert @output , "No output given"
assert_equal produced.class, @output , "Wrong class"
produced
end
2015-10-10 09:02:28 +02:00
end