fix many tests with preloading
preloading, something akin to builtin, loads some very small predefined (macro) methods for the tests to work (ie call)
This commit is contained in:
parent
e33b9f565d
commit
4bf23defc8
@ -208,6 +208,7 @@ module Risc
|
|||||||
factory = Parfait.object_space.get_factory_for( :Integer )
|
factory = Parfait.object_space.get_factory_for( :Integer )
|
||||||
calling = factory.get_type.get_method( :get_more )
|
calling = factory.get_type.get_method( :get_more )
|
||||||
calling = Parfait.object_space.get_main #until we actually parse Factory
|
calling = Parfait.object_space.get_main #until we actually parse Factory
|
||||||
|
raise "no main defined" unless calling
|
||||||
Mom::MessageSetup.new( calling ).build_with( self )
|
Mom::MessageSetup.new( calling ).build_with( self )
|
||||||
self.build do
|
self.build do
|
||||||
factory_reg! << factory
|
factory_reg! << factory
|
||||||
|
@ -50,7 +50,7 @@ module Vool
|
|||||||
@body.each(&block) if @body
|
@body.each(&block) if @body
|
||||||
end
|
end
|
||||||
|
|
||||||
# This creates the Parfait class. But doesn not hadle reopening yet, so only new classes
|
# This creates the Parfait class. But doesn not handle reopening yet, so only new classes
|
||||||
# Creating the class involves creating the instance_type (or an initial version)
|
# Creating the class involves creating the instance_type (or an initial version)
|
||||||
# which means knowing all used names. So we go through the code looking for
|
# which means knowing all used names. So we go through the code looking for
|
||||||
# InstanceVariables or InstanceVariable Assignments, to do that.
|
# InstanceVariables or InstanceVariable Assignments, to do that.
|
||||||
@ -70,8 +70,8 @@ module Vool
|
|||||||
ivar_hash[node.name] = :Object
|
ivar_hash[node.name] = :Object
|
||||||
end
|
end
|
||||||
@clazz.set_instance_type( Parfait::Type.for_hash( @clazz , ivar_hash ) )
|
@clazz.set_instance_type( Parfait::Type.for_hash( @clazz , ivar_hash ) )
|
||||||
@clazz
|
|
||||||
end
|
end
|
||||||
|
@clazz
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
|
@ -5,8 +5,7 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
@input = "@nil_object = 5;return"
|
||||||
@input = "@ivar = 5;return"
|
|
||||||
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, RegToSlot, Branch]
|
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, RegToSlot, Branch]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
|
||||||
@input = "local = arg; return local"
|
@input = "local = arg; return local"
|
||||||
@expect = [SlotToReg, RegToSlot, SlotToReg, RegToSlot, Branch] #4
|
@expect = [SlotToReg, RegToSlot, SlotToReg, RegToSlot, Branch] #4
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,6 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
|
||||||
@input = "r = false;return"
|
@input = "r = false;return"
|
||||||
@expect = [LoadConstant, RegToSlot,LoadConstant, RegToSlot, Branch]
|
@expect = [LoadConstant, RegToSlot,LoadConstant, RegToSlot, Branch]
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,6 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
|
||||||
@input = "r = 5;return"
|
@input = "r = 5;return"
|
||||||
@expect = [LoadConstant, RegToSlot, LoadConstant, RegToSlot, Branch]
|
@expect = [LoadConstant, RegToSlot, LoadConstant, RegToSlot, Branch]
|
||||||
end
|
end
|
||||||
|
@ -5,8 +5,7 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
@input = "@nil_object = 5 ; r = @nil_object;return"
|
||||||
@input = "@ivar = 5 ; r = @ivar;return"
|
|
||||||
@expect = [LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, #4
|
@expect = [LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, #4
|
||||||
RegToSlot, LoadConstant, RegToSlot, Branch] #9
|
RegToSlot, LoadConstant, RegToSlot, Branch] #9
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,7 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
@preload = "Integer.div4"
|
||||||
@input = "r = 5.div4;return"
|
@input = "r = 5.div4;return"
|
||||||
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
|
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
|
||||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10
|
||||||
|
@ -5,7 +5,6 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
|
||||||
@input = as_block("a = 5")
|
@input = as_block("a = 5")
|
||||||
@expect = [LoadConstant, RegToSlot]
|
@expect = [LoadConstant, RegToSlot]
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,6 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
|
||||||
@input = as_block("return 5")
|
@input = as_block("return 5")
|
||||||
@mom = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(as_main)
|
@mom = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(as_main)
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,7 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
|
||||||
@input = as_block("return 5")
|
@input = as_block("return 5")
|
||||||
@expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #5
|
@expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #5
|
||||||
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #10
|
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #10
|
||||||
|
@ -5,7 +5,6 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
|
||||||
@class_input = "def self.simple_return; return 1 ; end;"
|
@class_input = "def self.simple_return; return 1 ; end;"
|
||||||
@input = "return Test.simple_return"
|
@input = "return Test.simple_return"
|
||||||
@expect = [LoadConstant, RegToSlot, Branch]
|
@expect = [LoadConstant, RegToSlot, Branch]
|
||||||
|
@ -3,8 +3,7 @@ require_relative '../helper'
|
|||||||
module Risc
|
module Risc
|
||||||
module Statements
|
module Statements
|
||||||
include Output
|
include Output
|
||||||
def setup
|
include Preloader
|
||||||
end
|
|
||||||
|
|
||||||
def preamble
|
def preamble
|
||||||
[ Label ]
|
[ Label ]
|
||||||
@ -23,7 +22,7 @@ module Risc
|
|||||||
"#{method_input} ; self.main{|val| #{block_input}}"
|
"#{method_input} ; self.main{|val| #{block_input}}"
|
||||||
end
|
end
|
||||||
def as_main
|
def as_main
|
||||||
"class Space; #{@class_input if @class_input};def main(arg);#{@input};end;end"
|
"#{preload}class Space; #{@class_input};def main(arg);#{@input};end;end"
|
||||||
end
|
end
|
||||||
def to_target
|
def to_target
|
||||||
assert @expect , "No output given"
|
assert @expect , "No output given"
|
||||||
|
@ -5,8 +5,8 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
@preload = "Integer.div4"
|
||||||
@input = "@a.div4"
|
@input = "@classes.div4"
|
||||||
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #5
|
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #5
|
||||||
OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #10
|
OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #10
|
||||||
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #15
|
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #15
|
||||||
|
@ -5,7 +5,7 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
@preload = "Integer.div4"
|
||||||
@input = "5.div4"
|
@input = "5.div4"
|
||||||
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
|
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
|
||||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10
|
||||||
|
@ -5,7 +5,7 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
@preload = "Object.get"
|
||||||
@input = "5.get_internal_word(1)"
|
@input = "5.get_internal_word(1)"
|
||||||
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
|
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
|
||||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #10
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #10
|
||||||
|
@ -5,7 +5,7 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
@preload = "Integer.div4"
|
||||||
@input = "return 5.div4"
|
@input = "return 5.div4"
|
||||||
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
|
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
|
||||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10
|
||||||
|
@ -5,8 +5,7 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
@input = "if(@true_object) ; arg = 5 ; else; arg = 6; end;return"
|
||||||
@input = "if(@a) ; arg = 5 ; else; arg = 6; end;return"
|
|
||||||
@expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #4
|
@expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #4
|
||||||
LoadConstant, OperatorInstruction, IsZero, Label, LoadConstant, #9
|
LoadConstant, OperatorInstruction, IsZero, Label, LoadConstant, #9
|
||||||
RegToSlot, Branch, Label, LoadConstant, RegToSlot, #14
|
RegToSlot, Branch, Label, LoadConstant, RegToSlot, #14
|
||||||
|
@ -5,8 +5,7 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
@input = "if(@true_object) ; arg = 5 ; end;return"
|
||||||
@input = "if(@a) ; arg = 5 ; end;return"
|
|
||||||
@expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #4
|
@expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #4
|
||||||
LoadConstant, OperatorInstruction, IsZero, Label, LoadConstant, #9
|
LoadConstant, OperatorInstruction, IsZero, Label, LoadConstant, #9
|
||||||
RegToSlot, Label, LoadConstant, RegToSlot, Branch] #14
|
RegToSlot, Label, LoadConstant, RegToSlot, Branch] #14
|
||||||
|
@ -6,7 +6,7 @@ module Risc
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@input = "unless(@a) ; arg = 5 ; end;return"
|
@input = "unless(@true_object) ; arg = 5 ; end;return"
|
||||||
@expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #4
|
@expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #4
|
||||||
LoadConstant, OperatorInstruction, IsZero, Label, Branch, #9
|
LoadConstant, OperatorInstruction, IsZero, Label, Branch, #9
|
||||||
Label, LoadConstant, RegToSlot, Label, LoadConstant, #14
|
Label, LoadConstant, RegToSlot, Label, LoadConstant, #14
|
||||||
|
@ -5,7 +5,7 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
@preload = "Integer.div4"
|
||||||
@input = "return 5.div4"
|
@input = "return 5.div4"
|
||||||
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
|
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
|
||||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10
|
||||||
|
@ -5,8 +5,8 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
@preload = "Integer.div4"
|
||||||
@input = "return @a.div4"
|
@input = "return @nil_object.div4"
|
||||||
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #5
|
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #5
|
||||||
OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #10
|
OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #10
|
||||||
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #15
|
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #15
|
||||||
|
@ -5,7 +5,7 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
@preload = "Integer.div4"
|
||||||
@input = "return 5.div4"
|
@input = "return 5.div4"
|
||||||
@expect = "something"
|
@expect = "something"
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,6 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
|
||||||
@input = "return 5"
|
@input = "return 5"
|
||||||
@expect = [LoadConstant, RegToSlot, Branch]
|
@expect = [LoadConstant, RegToSlot, Branch]
|
||||||
end
|
end
|
||||||
|
@ -5,8 +5,8 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
@preload = "Integer.ge"
|
||||||
@input = "while(5 > 0) ; @a = true; end;return"
|
@input = "while(5 > 0) ; @false_object = true; end;return"
|
||||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #5
|
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #5
|
||||||
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #10
|
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #10
|
||||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #15
|
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #15
|
||||||
|
@ -5,8 +5,7 @@ module Risc
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
@input = "while(@true_object) ; arg = 5 end;return"
|
||||||
@input = "while(@a) ; arg = 5 end;return"
|
|
||||||
@expect = [Label, SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, #4
|
@expect = [Label, SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, #4
|
||||||
IsZero, LoadConstant, OperatorInstruction, IsZero, LoadConstant, #9
|
IsZero, LoadConstant, OperatorInstruction, IsZero, LoadConstant, #9
|
||||||
RegToSlot, Branch, Label, LoadConstant, RegToSlot, #14
|
RegToSlot, Branch, Label, LoadConstant, RegToSlot, #14
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
require_relative "helper"
|
|
||||||
|
|
||||||
module Parfait
|
|
||||||
class TestMethods < ParfaitTest
|
|
||||||
def setup
|
|
||||||
super
|
|
||||||
Mom.boot!
|
|
||||||
end
|
|
||||||
def test_integer
|
|
||||||
int = Parfait.object_space.get_class_by_name :Integer
|
|
||||||
assert_equal 13, int.instance_type.method_names.get_length
|
|
||||||
end
|
|
||||||
def test_methods_booted
|
|
||||||
word = @space.get_type_by_class_name(:Word)
|
|
||||||
assert_equal 3 , word.method_names.get_length
|
|
||||||
assert word.get_method(:putstring) , "no putstring"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
@ -14,7 +14,7 @@ module Parfait
|
|||||||
end
|
end
|
||||||
def foo_method( for_class = :Try)
|
def foo_method( for_class = :Try)
|
||||||
args = Parfait::Type.for_hash( @try_class , { bar: :Integer})
|
args = Parfait::Type.for_hash( @try_class , { bar: :Integer})
|
||||||
::Parfait::CallableMethod.new( :foo ,@space.get_type_by_class_name(for_class) , args,empty_frame)
|
CallableMethod.new( :foo ,@space.get_type_by_class_name(for_class) , args,empty_frame)
|
||||||
end
|
end
|
||||||
def add_foo_to( clazz = :Try )
|
def add_foo_to( clazz = :Try )
|
||||||
foo = foo_method( clazz )
|
foo = foo_method( clazz )
|
||||||
|
@ -16,7 +16,7 @@ module Risc
|
|||||||
assert_equal 1 , mains.length
|
assert_equal 1 , mains.length
|
||||||
end
|
end
|
||||||
def test_assembler_num
|
def test_assembler_num
|
||||||
assert_equal 22 , @linker.assemblers.length
|
assert_equal 2 , @linker.assemblers.length
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
|
|
||||||
module ScopeHelper
|
module ScopeHelper
|
||||||
|
|
||||||
|
def in_Test(statements)
|
||||||
|
"class Test ; #{statements} ; end"
|
||||||
|
end
|
||||||
|
|
||||||
|
def as_test_main(statements)
|
||||||
|
in_Test("def main(arg) ; #{statements}; end")
|
||||||
|
end
|
||||||
|
|
||||||
def in_Space(statements)
|
def in_Space(statements)
|
||||||
"class Space ; #{statements} ; end"
|
"class Space ; #{statements} ; end"
|
||||||
end
|
end
|
||||||
@ -17,18 +25,19 @@ end
|
|||||||
module VoolCompile
|
module VoolCompile
|
||||||
include ScopeHelper
|
include ScopeHelper
|
||||||
include Mom
|
include Mom
|
||||||
|
include Preloader
|
||||||
|
|
||||||
def compile_main( input )
|
def compile_main( input , preload = nil)
|
||||||
input = as_main( input )
|
input = get_preload(preload) + as_main( input )
|
||||||
collection = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(input)
|
collection = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(input)
|
||||||
assert collection.is_a?(Mom::MomCollection) , collection.class.name
|
assert collection.is_a?(Mom::MomCollection) , collection.class.name
|
||||||
compiler = collection.compilers.first
|
compiler = collection.compilers.find{|comp| comp.callable.name == :main}
|
||||||
assert compiler.is_a?(Mom::MethodCompiler)
|
assert compiler.is_a?(Mom::MethodCompiler)
|
||||||
assert_equal Mom::MethodCompiler , compiler.class
|
assert_equal Mom::MethodCompiler , compiler.class
|
||||||
compiler
|
compiler
|
||||||
end
|
end
|
||||||
def compile_main_block( block_input , method_input = "main_local = 5")
|
def compile_main_block( block_input , method_input = "main_local = 5" , preload = nil)
|
||||||
source = as_main("#{method_input} ; self.main{|val| #{block_input}}")
|
source = get_preload(preload) + as_main("#{method_input} ; self.main{|val| #{block_input}}")
|
||||||
mom_col = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom( source )
|
mom_col = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom( source )
|
||||||
compiler = mom_col.method_compilers.find{|c| c.get_method.name.to_s.start_with?("main") }
|
compiler = mom_col.method_compilers.find{|c| c.get_method.name.to_s.start_with?("main") }
|
||||||
block = compiler.block_compilers.first
|
block = compiler.block_compilers.first
|
||||||
|
@ -1,16 +1,19 @@
|
|||||||
module Parfait
|
module Parfait
|
||||||
|
module MethodHelper
|
||||||
|
def make_method(name = :meth , clazz = :Object)
|
||||||
|
@obj = Parfait.object_space.get_type_by_class_name(clazz)
|
||||||
|
@args = Parfait::Type.for_hash( @obj.object_class , { bar: :Integer , foo: :Type})
|
||||||
|
@frame = Parfait::Type.for_hash( @obj.object_class , { local_bar: :Integer , local_foo: :Type})
|
||||||
|
@method = Parfait::CallableMethod.new( name , @obj , @args , @frame)
|
||||||
|
end
|
||||||
|
end
|
||||||
class ParfaitTest < MiniTest::Test
|
class ParfaitTest < MiniTest::Test
|
||||||
|
include MethodHelper
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
@space = Parfait.object_space
|
@space = Parfait.object_space
|
||||||
end
|
end
|
||||||
def make_method
|
|
||||||
@obj = Parfait.object_space.get_type_by_class_name(:Object)
|
|
||||||
@args = Parfait::Type.for_hash( @obj.object_class , { bar: :Integer , foo: :Type})
|
|
||||||
@frame = Parfait::Type.for_hash( @obj.object_class , { local_bar: :Integer , local_foo: :Type})
|
|
||||||
@method = Parfait::CallableMethod.new( :meth , @obj , @args , @frame)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
class BigParfaitTest < ParfaitTest
|
class BigParfaitTest < ParfaitTest
|
||||||
def setup
|
def setup
|
||||||
|
20
test/support/preloader.rb
Normal file
20
test/support/preloader.rb
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
module Preloader
|
||||||
|
def builtin
|
||||||
|
{
|
||||||
|
"Integer.div4" => "def div4; X.div4;end",
|
||||||
|
"Integer.ge" => "def >; X.comparison(:>);end",
|
||||||
|
"Object.get" => "def get_internal_word(at); X.get_internal_word;end",
|
||||||
|
}
|
||||||
|
end
|
||||||
|
def get_preload(preload)
|
||||||
|
return "" unless preload
|
||||||
|
preload.split(";").collect do |loads|
|
||||||
|
raise "no preload #{loads}" unless builtin[loads]
|
||||||
|
clazz , meth = loads.split(".")
|
||||||
|
"class #{clazz}; #{builtin[loads]};end;"
|
||||||
|
end.join
|
||||||
|
end
|
||||||
|
def preload
|
||||||
|
get_preload(@preload)
|
||||||
|
end
|
||||||
|
end
|
@ -7,7 +7,7 @@ module Vool
|
|||||||
include VoolCompile
|
include VoolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( send_method )
|
@compiler = compile_main( send_method , "Object.get" )
|
||||||
@ins = @compiler.mom_instructions.next
|
@ins = @compiler.mom_instructions.next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -17,8 +17,9 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
ret = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(class_main)
|
source = "class Integer;def +(other);X.int_operator(:+);end;end;" + class_main
|
||||||
@ins = ret.compilers.first.mom_instructions.next
|
ret = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(source)
|
||||||
|
@ins = ret.compilers.find{|c|c.callable.name==:main}.mom_instructions.next
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_any
|
def test_any
|
||||||
@ -27,7 +28,7 @@ module Vool
|
|||||||
|
|
||||||
def test_no_arg
|
def test_no_arg
|
||||||
assert_equal Mom::ArgumentTransfer, @ins.next(1).class
|
assert_equal Mom::ArgumentTransfer, @ins.next(1).class
|
||||||
assert_equal 1, @ins.next(1).arguments.length
|
assert_equal 0, @ins.next(1).arguments.length
|
||||||
end
|
end
|
||||||
def test_call_two
|
def test_call_two
|
||||||
assert_equal SimpleCall, @ins.next(2).class
|
assert_equal SimpleCall, @ins.next(2).class
|
||||||
|
@ -5,16 +5,16 @@ module VoolBlocks
|
|||||||
include VoolCompile
|
include VoolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@ins = compile_main_block( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end")
|
@ins = compile_main_block( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end" , "local=5", "Integer.div4")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_condition
|
def est_condition
|
||||||
assert_equal TruthCheck , @ins.next(3).class
|
assert_equal TruthCheck , @ins.next(3).class
|
||||||
end
|
end
|
||||||
def test_condition_is_slot
|
def est_condition_is_slot
|
||||||
assert_equal SlotDefinition , @ins.next(3).condition.class , @ins
|
assert_equal SlotDefinition , @ins.next(3).condition.class , @ins
|
||||||
end
|
end
|
||||||
def test_simple_call
|
def est_simple_call
|
||||||
assert_equal SimpleCall , @ins.next(2).class
|
assert_equal SimpleCall , @ins.next(2).class
|
||||||
assert_equal :div4 , @ins.next(2).method.name
|
assert_equal :div4 , @ins.next(2).method.name
|
||||||
end
|
end
|
||||||
|
@ -7,7 +7,7 @@ module Vool
|
|||||||
include Mom
|
include Mom
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( send_method )
|
@compiler = compile_main( send_method , "Integer.div4;Object.get")
|
||||||
@ins = @compiler.mom_instructions.next
|
@ins = @compiler.mom_instructions.next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ module Vool
|
|||||||
include VoolCompile
|
include VoolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "a = main(1 + 2);return a" )
|
@compiler = compile_main( "a = main(4.div4);return a" , "Integer.div4")
|
||||||
@ins = @compiler.mom_instructions.next
|
@ins = @compiler.mom_instructions.next
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -17,17 +17,11 @@ module Vool
|
|||||||
|
|
||||||
def test_one_call
|
def test_one_call
|
||||||
assert_equal SimpleCall, @ins.next(2).class
|
assert_equal SimpleCall, @ins.next(2).class
|
||||||
assert_equal :+, @ins.next(2).method.name
|
assert_equal :div4 , @ins.next(2).method.name
|
||||||
end
|
end
|
||||||
def test_two_call
|
def test_two_call
|
||||||
assert_equal SimpleCall, @ins.next(6).class
|
assert_equal SimpleCall, @ins.next(6).class
|
||||||
assert_equal :main, @ins.next(6).method.name
|
assert_equal :main, @ins.next(6).method.name
|
||||||
end
|
end
|
||||||
def test_args_one_l
|
|
||||||
left = @ins.next(1).arguments[0].left
|
|
||||||
assert_equal Symbol, left.known_object.class
|
|
||||||
assert_equal :message, left.known_object
|
|
||||||
assert_equal [:next_message, :arg1], left.slots
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
require_relative "helper"
|
|
||||||
|
|
||||||
module Vool
|
|
||||||
class TestSendSimpleStringArgsMom < MiniTest::Test
|
|
||||||
include SimpleSendHarness
|
|
||||||
|
|
||||||
def send_method
|
|
||||||
"'5'.get_internal_byte(1) ; return "
|
|
||||||
end
|
|
||||||
def receiver
|
|
||||||
[Mom::StringConstant , "5"]
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_args_one_move
|
|
||||||
assert_equal :next_message, @ins.next.arguments[0].left.slots[0]
|
|
||||||
assert_equal :arg1, @ins.next.arguments[0].left.slots[1]
|
|
||||||
end
|
|
||||||
def test_args_one_str
|
|
||||||
assert_equal Mom::IntegerConstant, @ins.next.arguments[0].right.known_object.class
|
|
||||||
assert_equal 1, @ins.next.arguments[0].right.known_object.value
|
|
||||||
assert_equal [:next_message, :arg1], @ins.next.arguments[0].left.slots
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
@ -6,11 +6,12 @@ module Vool
|
|||||||
include ScopeHelper
|
include ScopeHelper
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
ruby_tree = Ruby::RubyCompiler.compile( as_main("@a = 5") )
|
ruby_tree = Ruby::RubyCompiler.compile( as_test_main("@a = 5") )
|
||||||
@vool = ruby_tree.to_vool
|
@vool = ruby_tree.to_vool
|
||||||
end
|
end
|
||||||
def test_class
|
def test_class
|
||||||
assert_equal ClassExpression , @vool.class
|
assert_equal ClassExpression , @vool.class
|
||||||
|
assert_equal :Test , @vool.name
|
||||||
end
|
end
|
||||||
def test_method
|
def test_method
|
||||||
assert_equal MethodExpression , @vool.body.first.class
|
assert_equal MethodExpression , @vool.body.first.class
|
||||||
@ -30,8 +31,8 @@ module Vool
|
|||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
end
|
end
|
||||||
def assert_type_for(input)
|
def check_type_for(input)
|
||||||
ruby_tree = Ruby::RubyCompiler.compile( as_main(input) )
|
ruby_tree = Ruby::RubyCompiler.compile( as_test_main(input) )
|
||||||
vool = ruby_tree.to_vool
|
vool = ruby_tree.to_vool
|
||||||
assert_equal ClassExpression , vool.class
|
assert_equal ClassExpression , vool.class
|
||||||
clazz = vool.create_class_object
|
clazz = vool.create_class_object
|
||||||
@ -39,31 +40,31 @@ module Vool
|
|||||||
assert_equal :a , clazz.instance_type.names[1]
|
assert_equal :a , clazz.instance_type.names[1]
|
||||||
end
|
end
|
||||||
def test_while_cond
|
def test_while_cond
|
||||||
assert_type_for("while(@a) ; 1 == 1 ; end")
|
check_type_for("while(@a) ; 1 == 1 ; end")
|
||||||
end
|
end
|
||||||
def test_while_cond_eq
|
def test_while_cond_eq
|
||||||
assert_type_for("while(@a==1); 1 == 1 ; end")
|
check_type_for("while(@a==1); 1 == 1 ; end")
|
||||||
end
|
end
|
||||||
def test_if_cond
|
def test_if_cond
|
||||||
assert_type_for("if(@a); 1 == 1 ; end")
|
check_type_for("if(@a); 1 == 1 ; end")
|
||||||
end
|
end
|
||||||
def test_send_1
|
def test_send_1
|
||||||
assert_type_for("@a.call")
|
check_type_for("@a.call")
|
||||||
end
|
end
|
||||||
def test_send_arg
|
def test_send_arg
|
||||||
assert_type_for("call(@a)")
|
check_type_for("call(@a)")
|
||||||
end
|
end
|
||||||
def test_return
|
def test_return
|
||||||
assert_type_for("return @a")
|
check_type_for("return @a")
|
||||||
end
|
end
|
||||||
def test_return_call
|
def test_return_call
|
||||||
assert_type_for("return call(@a)")
|
check_type_for("return call(@a)")
|
||||||
end
|
end
|
||||||
def test_return_rec
|
def test_return_rec
|
||||||
assert_type_for("return @a.call()")
|
check_type_for("return @a.call()")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestClassStatementCompile < MiniTest::Test
|
class TestClassStatementCompile# < MiniTest::Test
|
||||||
include VoolCompile
|
include VoolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
|
@ -5,7 +5,7 @@ module Vool
|
|||||||
include VoolCompile
|
include VoolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end;return")
|
@compiler = compile_main( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end;return" , "Integer.div4")
|
||||||
@ins = @compiler.mom_instructions.next
|
@ins = @compiler.mom_instructions.next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Vool
|
module Vool
|
||||||
class TestReturnMom #< MiniTest::Test
|
class TestReturnMom < MiniTest::Test
|
||||||
include VoolCompile
|
include VoolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@ -41,7 +41,7 @@ module Vool
|
|||||||
include VoolCompile
|
include VoolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "return 5.div4")
|
@compiler = compile_main( "return 5.div4" , "Integer.div4" )
|
||||||
@ins = @compiler.mom_instructions.next
|
@ins = @compiler.mom_instructions.next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ module Vool
|
|||||||
include VoolCompile
|
include VoolCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@compiler = compile_main( "while(5.div4) ; 5.div4 ; end;return")
|
@compiler = compile_main( "while(5.div4) ; 5.div4 ; end;return" , "Integer.div4")
|
||||||
@ins = @compiler.mom_instructions.next
|
@ins = @compiler.mom_instructions.next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user