Copy risc compiler stuff to mom
Start to separate the layers. wip, just checkin in to see the following changes better
This commit is contained in:
85
test/mom/test_block_compiler.rb
Normal file
85
test/mom/test_block_compiler.rb
Normal file
@ -0,0 +1,85 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Mom
|
||||
class TestBlockCompiler < MiniTest::Test
|
||||
include MomCompile
|
||||
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
@ins = compile_first_block( "local = 5")
|
||||
end
|
||||
|
||||
def test_block_compiles
|
||||
assert_equal Mom::SlotLoad , @ins.class , @ins
|
||||
end
|
||||
def test_slot_is_set
|
||||
assert @ins.left
|
||||
end
|
||||
def test_slot_starts_at_message
|
||||
assert_equal :message , @ins.left.known_object
|
||||
end
|
||||
def test_slots_left
|
||||
assert_equal [:frame , :local] , @ins.left.slots
|
||||
end
|
||||
def test_slot_assigns_something
|
||||
assert @ins.right
|
||||
end
|
||||
def test_slot_assigns_int
|
||||
assert_equal Mom::IntegerConstant , @ins.right.known_object.class
|
||||
end
|
||||
end
|
||||
|
||||
class TestAssignMomInstanceToLocal < MiniTest::Test
|
||||
include MomCompile
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
@ins = compile_first_block( "local = @a" , "@a = 5") #second arg in method scope
|
||||
end
|
||||
def test_class_compiles
|
||||
assert_equal Mom::SlotLoad , @ins.class , @ins
|
||||
end
|
||||
def test_slots_left
|
||||
assert_equal [:frame, :local] , @ins.left.slots
|
||||
end
|
||||
def test_slots_right
|
||||
assert_equal [:receiver, :a] , @ins.right.slots
|
||||
end
|
||||
end
|
||||
|
||||
class TestAssignToArg < MiniTest::Test
|
||||
include MomCompile
|
||||
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
@ins = compile_first_block( "arg = 5")
|
||||
end
|
||||
|
||||
def test_class_compiles
|
||||
assert_equal Mom::SlotLoad , @ins.class , @ins
|
||||
end
|
||||
def test_slot_is_set
|
||||
assert @ins.left
|
||||
end
|
||||
def test_slots_left
|
||||
assert_equal [:caller,:caller, :arguments, :arg] , @ins.left.slots
|
||||
end
|
||||
end
|
||||
|
||||
class TestAssignMomToInstance < MiniTest::Test
|
||||
include MomCompile
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
end
|
||||
def test_assigns_const
|
||||
@ins = compile_first_block( "@a = 5")
|
||||
assert_equal Mom::SlotLoad , @ins.class , @ins
|
||||
assert_equal Mom::IntegerConstant , @ins.right.known_object.class , @ins
|
||||
end
|
||||
def test_assigns_move
|
||||
@ins = compile_first_block( "@a = arg")
|
||||
assert_equal Mom::SlotLoad , @ins.class , @ins
|
||||
assert_equal Mom::SlotDefinition , @ins.right.class , @ins
|
||||
end
|
||||
end
|
||||
|
||||
end
|
40
test/mom/test_method_compiler.rb
Normal file
40
test/mom/test_method_compiler.rb
Normal file
@ -0,0 +1,40 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
class TestMethodCompiler < MiniTest::Test
|
||||
include MomCompile
|
||||
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
@comp = compile_mom( "class Test ; def main(); return 'Hi'; end; end;")
|
||||
end
|
||||
|
||||
def test_class
|
||||
assert_equal MomCompiler , @comp.class
|
||||
end
|
||||
def test_compilers
|
||||
assert_equal 23 , @comp.compilers.length
|
||||
end
|
||||
def test_boot_compilers
|
||||
assert_equal 22 , @comp.boot_compilers.length
|
||||
end
|
||||
def test_compilers_bare
|
||||
assert_equal 22 , MomCompiler.new.compilers.length
|
||||
end
|
||||
def test_returns_constants
|
||||
assert_equal Array , @comp.constants.class
|
||||
end
|
||||
def test_has_constant
|
||||
assert_equal "Hi" , @comp.constants[1].to_string
|
||||
end
|
||||
def test_has_translate
|
||||
assert @comp.translate(:interpreter)
|
||||
end
|
||||
def test_append_class
|
||||
assert_equal MomCompiler, (@comp.append @comp).class
|
||||
end
|
||||
def test_append_length
|
||||
assert_equal 2 , @comp.append(@comp).method_compilers.length
|
||||
end
|
||||
end
|
||||
end
|
40
test/mom/test_mom_collection.rb
Normal file
40
test/mom/test_mom_collection.rb
Normal file
@ -0,0 +1,40 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
class TestMomCollection < MiniTest::Test
|
||||
include MomCompile
|
||||
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
@comp = compile_mom( "class Test ; def main(); return 'Hi'; end; end;")
|
||||
end
|
||||
|
||||
def test_class
|
||||
assert_equal MomCompiler , @comp.class
|
||||
end
|
||||
def test_compilers
|
||||
assert_equal 23 , @comp.compilers.length
|
||||
end
|
||||
def test_boot_compilers
|
||||
assert_equal 22 , @comp.boot_compilers.length
|
||||
end
|
||||
def test_compilers_bare
|
||||
assert_equal 22 , MomCompiler.new.compilers.length
|
||||
end
|
||||
def test_returns_constants
|
||||
assert_equal Array , @comp.constants.class
|
||||
end
|
||||
def test_has_constant
|
||||
assert_equal "Hi" , @comp.constants[1].to_string
|
||||
end
|
||||
def test_has_translate
|
||||
assert @comp.translate(:interpreter)
|
||||
end
|
||||
def test_append_class
|
||||
assert_equal MomCompiler, (@comp.append @comp).class
|
||||
end
|
||||
def test_append_length
|
||||
assert_equal 2 , @comp.append(@comp).method_compilers.length
|
||||
end
|
||||
end
|
||||
end
|
@ -17,6 +17,26 @@ module ScopeHelper
|
||||
in_Test("def main(arg) ; #{statements}; end")
|
||||
end
|
||||
end
|
||||
module VoolCompile
|
||||
include ScopeHelper
|
||||
|
||||
def compile_method(input)
|
||||
statements = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(input)
|
||||
assert statements.is_a?(Mom::MomCollection)
|
||||
ret = statements.to_mom(nil)
|
||||
assert_equal Parfait::Class , statements.clazz.class , statements
|
||||
@method = statements.clazz.get_method(:main)
|
||||
assert_equal Parfait::VoolMethod , @method.class
|
||||
ret
|
||||
end
|
||||
def compile_first_method( input )
|
||||
ret = compile_method( as_test_main( input ))
|
||||
assert_equal Mom::MomCompiler , ret.class
|
||||
compiler = ret.method_compilers.find{|c| c.get_method.name == :main and c.get_method.self_type.object_class.name == :Test}
|
||||
assert_equal Risc::MethodCompiler , compiler.class
|
||||
@method.source.to_mom( compiler )
|
||||
end
|
||||
end
|
||||
|
||||
module MomCompile
|
||||
include ScopeHelper
|
||||
@ -78,27 +98,3 @@ module MomCompile
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
class Ignored
|
||||
def == other
|
||||
return false unless other.class == self.class
|
||||
Sof::Util.attributes(self).each do |a|
|
||||
begin
|
||||
left = send(a)
|
||||
rescue NoMethodError
|
||||
next # not using instance variables that are not defined as attr_readers for equality
|
||||
end
|
||||
begin
|
||||
right = other.send(a)
|
||||
rescue NoMethodError
|
||||
return false
|
||||
end
|
||||
return false unless left.class == right.class
|
||||
return false unless left == right
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
29
test/vool/test_class_statement.rb
Normal file
29
test/vool/test_class_statement.rb
Normal file
@ -0,0 +1,29 @@
|
||||
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestClassStatement < MiniTest::Test
|
||||
include VoolCompile
|
||||
|
||||
def setup
|
||||
@ins = compile_first_method( "if(@a) ; @a = 5 ; else; @a = 6 ; end")
|
||||
end
|
||||
|
||||
def test_condition_compiles_to_check
|
||||
assert_equal TruthCheck , @ins.class , @ins
|
||||
end
|
||||
def test_condition_is_slot
|
||||
assert_equal SlotDefinition , @ins.condition.class , @ins
|
||||
end
|
||||
def test_label_after_check
|
||||
assert_equal Label , @ins.next.class , @ins
|
||||
end
|
||||
def test_label_last
|
||||
assert_equal Label , @ins.last.class , @ins
|
||||
end
|
||||
def test_array
|
||||
check_array [TruthCheck, Label, SlotLoad, Jump, Label, SlotLoad ,
|
||||
Label] , @ins
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user