fix mom tests
and always have a list inside a class
This commit is contained in:
parent
5b87133df2
commit
8d7a2fe4d6
@ -9,10 +9,14 @@ module RubyX
|
|||||||
vool
|
vool
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.ruby_to_mom( ruby_source )
|
||||||
|
vool = self.ruby_to_vool(ruby_source)
|
||||||
|
vool.to_mom(nil)
|
||||||
|
end
|
||||||
|
|
||||||
def self.ruby_to_binary(source , platform = :arm)
|
def self.ruby_to_binary(source , platform = :arm)
|
||||||
machine = Risc.machine.boot
|
machine = Risc.machine.boot
|
||||||
vool = self.ruby_to_vool(source)
|
ruby_to_mom(source)
|
||||||
vool.to_mom(nil).class
|
|
||||||
machine.translate(platform)
|
machine.translate(platform)
|
||||||
machine.position_all
|
machine.position_all
|
||||||
machine.create_binary
|
machine.create_binary
|
||||||
|
@ -4,11 +4,22 @@ module Vool
|
|||||||
attr_reader :clazz
|
attr_reader :clazz
|
||||||
|
|
||||||
def initialize( name , supe , body)
|
def initialize( name , supe , body)
|
||||||
@name , @super_class_name , @body = name , supe , body
|
@name , @super_class_name = name , supe
|
||||||
|
case body
|
||||||
|
when MethodStatement
|
||||||
|
@body = Statements.new([body])
|
||||||
|
when Statements
|
||||||
|
@body = body
|
||||||
|
when nil
|
||||||
|
@body = Statements.new([])
|
||||||
|
else
|
||||||
|
raise "what body #{body}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize
|
def normalize
|
||||||
ClassStatement.new(@name , @super_class_name, @body&.normalize )
|
meths = body.statements.collect{|meth| meth.normalize}
|
||||||
|
ClassStatement.new(@name , @super_class_name, Statements.new(meths) )
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_mom( _ )
|
def to_mom( _ )
|
||||||
|
@ -30,7 +30,7 @@ module Vool
|
|||||||
|
|
||||||
# create mom instructions
|
# create mom instructions
|
||||||
def to_mom( method )
|
def to_mom( method )
|
||||||
raise "Empty list ? #{statements.length}" unless @statements[0]
|
raise "Empty list ? #{statements.length}" if empty?
|
||||||
flat = @statements.shift.to_mom(method)
|
flat = @statements.shift.to_mom(method)
|
||||||
while( nekst = @statements.shift )
|
while( nekst = @statements.shift )
|
||||||
flat.append nekst.to_mom(method)
|
flat.append nekst.to_mom(method)
|
||||||
|
@ -38,19 +38,20 @@ module Risc
|
|||||||
|
|
||||||
def test_creates_method_statement_in_class
|
def test_creates_method_statement_in_class
|
||||||
clazz = RubyX::RubyXCompiler.ruby_to_vool in_Test("def meth; @ivar = 5 ;end")
|
clazz = RubyX::RubyXCompiler.ruby_to_vool in_Test("def meth; @ivar = 5 ;end")
|
||||||
assert_equal Vool::MethodStatement , clazz.body.class
|
assert_equal Vool::Statements , clazz.body.class
|
||||||
|
assert_equal Vool::MethodStatement , clazz.body.first.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_method_statement_has_class
|
def test_method_statement_has_class
|
||||||
vool = RubyX::RubyXCompiler.ruby_to_vool in_Test("def meth; @ivar = 5;end")
|
vool = RubyX::RubyXCompiler.ruby_to_vool in_Test("def meth; @ivar = 5;end")
|
||||||
clazz = vool.to_mom(nil)
|
clazz = vool.to_mom(nil)
|
||||||
assert vool.body.clazz
|
assert vool.body.first.clazz
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_parfait_class_creation
|
def test_parfait_class_creation
|
||||||
vool = RubyX::RubyXCompiler.ruby_to_vool in_Test("def meth; @ivar = 5;end")
|
vool = RubyX::RubyXCompiler.ruby_to_vool in_Test("def meth; @ivar = 5;end")
|
||||||
clazz = vool.to_mom(nil)
|
clazz = vool.to_mom(nil)
|
||||||
assert_equal Parfait::Class , vool.body.clazz.class
|
assert_equal Parfait::Class , vool.body.first.clazz.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_typed_method_instance_type
|
def test_typed_method_instance_type
|
||||||
|
@ -8,6 +8,9 @@ module RubyX
|
|||||||
def ruby_to_vool(input)
|
def ruby_to_vool(input)
|
||||||
RubyXCompiler.ruby_to_vool(input)
|
RubyXCompiler.ruby_to_vool(input)
|
||||||
end
|
end
|
||||||
|
def ruby_to_mom(input)
|
||||||
|
RubyXCompiler.ruby_to_mom(input)
|
||||||
|
end
|
||||||
def compile_in_test input
|
def compile_in_test input
|
||||||
vool = ruby_to_vool in_Test(input)
|
vool = ruby_to_vool in_Test(input)
|
||||||
vool.to_mom(nil)
|
vool.to_mom(nil)
|
||||||
|
@ -22,7 +22,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_compile_class_body
|
def test_compile_class_body
|
||||||
assert_nil @lst.body
|
assert @lst.body.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -31,13 +31,13 @@ module Vool
|
|||||||
include RubyTests
|
include RubyTests
|
||||||
|
|
||||||
def test_compile_one_method
|
def test_compile_one_method
|
||||||
lst = compile( in_Test("@ivar = 4") )
|
lst = compile( as_test_main("@ivar = 4") )
|
||||||
assert_equal IvarAssignment , lst.body.class
|
assert_equal IvarAssignment , lst.body.first.body.class
|
||||||
end
|
end
|
||||||
def test_compile_two_methods
|
def test_compile_two_stats
|
||||||
lst = compile( in_Test("false; true;") )
|
lst = compile( as_test_main("false; true;") )
|
||||||
assert_equal ScopeStatement , lst.body.class
|
assert_equal ScopeStatement , lst.body.first.body.class
|
||||||
assert_equal TrueConstant , lst.body.statements[1].class
|
assert_equal TrueConstant , lst.body.first.body.statements[1].class
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -24,7 +24,8 @@ module RubyX
|
|||||||
|
|
||||||
def test_class_body_is_scope
|
def test_class_body_is_scope
|
||||||
clazz = ruby_to_vool in_Test("def meth; @ivar = 5 ;end")
|
clazz = ruby_to_vool in_Test("def meth; @ivar = 5 ;end")
|
||||||
assert_equal Vool::MethodStatement , clazz.body.class
|
assert_equal Vool::Statements , clazz.body.class
|
||||||
|
assert_equal Vool::MethodStatement , clazz.body.first.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_space_is_unchanged_by_compile
|
def test_space_is_unchanged_by_compile
|
||||||
|
@ -1,34 +1,24 @@
|
|||||||
require_relative "../helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module RubyX
|
module RubyX
|
||||||
class TestVoolCompiler < MiniTest::Test
|
class TestVoolCompiler < MiniTest::Test
|
||||||
include ScopeHelper
|
include ScopeHelper
|
||||||
|
include RubyXHelper
|
||||||
def setup
|
|
||||||
Risc.machine.boot
|
|
||||||
end
|
|
||||||
def ruby_to_vool(input)
|
|
||||||
RubyXCompiler.ruby_to_vool(input)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_creates_class_without_deriviation
|
def test_creates_class_without_deriviation
|
||||||
vool = ruby_to_vool "class Testing ; end"
|
ruby_to_mom "class Testing ; end"
|
||||||
vool.to_mom(nil)
|
|
||||||
clazz = Parfait.object_space.get_class_by_name(:Testing)
|
clazz = Parfait.object_space.get_class_by_name(:Testing)
|
||||||
assert clazz , "No classes created"
|
assert clazz , "No classes created"
|
||||||
assert_equal :Object , clazz.super_class_name
|
assert_equal :Object , clazz.super_class_name
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_creates_class_deriviation
|
def test_creates_class_deriviation
|
||||||
vool = ruby_to_vool "class Testing ; end"
|
mom = ruby_to_mom "class Testing ; end"
|
||||||
mom = vool.to_mom(nil)
|
assert mom , "No classes created"
|
||||||
assert_equal Vool::ClassStatement , vool.class
|
|
||||||
#assert mom , "No classes created"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_creates_class_with_deriviation
|
def test_creates_class_with_deriviation
|
||||||
vool = ruby_to_vool "class Test2 < List ;end"
|
ruby_to_mom "class Test2 < List ;end"
|
||||||
vool.to_mom(nil)
|
|
||||||
clazz = Parfait.object_space.get_class_by_name(:Test2)
|
clazz = Parfait.object_space.get_class_by_name(:Test2)
|
||||||
assert clazz, "No classes created"
|
assert clazz, "No classes created"
|
||||||
assert_equal :List , clazz.super_class_name
|
assert_equal :List , clazz.super_class_name
|
||||||
|
Loading…
Reference in New Issue
Block a user