method tests working again
This commit is contained in:
parent
1def69c783
commit
3909bdcc7d
@ -36,14 +36,14 @@ module Vool
|
|||||||
raise "Not implemented for #{self}"
|
raise "Not implemented for #{self}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def ct_type
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Expression
|
class Expression
|
||||||
|
|
||||||
|
def ct_type
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
def normalize
|
def normalize
|
||||||
raise "should not be normalized #{self}"
|
raise "should not be normalized #{self}"
|
||||||
end
|
end
|
||||||
|
@ -43,13 +43,16 @@ module Vool
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
class SelfExpression < Expression
|
class SelfExpression < Expression
|
||||||
attr_reader :clazz
|
attr_reader :my_type
|
||||||
|
def initialize(type = nil)
|
||||||
|
@my_type = type
|
||||||
|
end
|
||||||
def to_mom(in_method)
|
def to_mom(in_method)
|
||||||
@clazz = in_method.clazz
|
@clazz = in_method.clazz
|
||||||
Mom::SlotDefinition.new(:message , [:receiver])
|
Mom::SlotDefinition.new(:message , [:receiver])
|
||||||
end
|
end
|
||||||
def ct_type
|
def ct_type
|
||||||
@clazz.instance_type
|
@my_type
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class SuperExpression < Statement
|
class SuperExpression < Statement
|
||||||
|
@ -10,10 +10,11 @@ module Vool
|
|||||||
def normalize
|
def normalize
|
||||||
ClassStatement.new(@name , @super_class_name, @body.normalize )
|
ClassStatement.new(@name , @super_class_name, @body.normalize )
|
||||||
end
|
end
|
||||||
|
|
||||||
# compilation to the next layer, mom
|
# compilation to the next layer, mom
|
||||||
# context coming in for class is nil, also for methods, henceafter a method is passed down
|
# context coming in for class is nil, also for methods, henceafter a method is passed down
|
||||||
def to_mom( _ )
|
def to_mom( _ )
|
||||||
@body.to_mom(nil)
|
@body.to_mom()
|
||||||
end
|
end
|
||||||
|
|
||||||
def each(&block)
|
def each(&block)
|
||||||
|
@ -38,6 +38,7 @@ module Vool
|
|||||||
# in a not so distant future, temporary variables will have to be created
|
# in a not so distant future, temporary variables will have to be created
|
||||||
# and complex statements hoisted to assign to them. pps: same as in conditions
|
# and complex statements hoisted to assign to them. pps: same as in conditions
|
||||||
def to_mom( in_method )
|
def to_mom( in_method )
|
||||||
|
@receiver = SelfExpression.new(in_method.for_class.instance_type) if @receiver.is_a?(SelfExpression)
|
||||||
if(@receiver.ct_type)
|
if(@receiver.ct_type)
|
||||||
simple_call(in_method)
|
simple_call(in_method)
|
||||||
else
|
else
|
||||||
@ -67,7 +68,7 @@ module Vool
|
|||||||
# - check the cached type and if neccessary update
|
# - check the cached type and if neccessary update
|
||||||
# - call the cached method
|
# - call the cached method
|
||||||
def cached_call(in_method)
|
def cached_call(in_method)
|
||||||
Mom::Statements.new( cache_check(in_method) + call_cached_method(in_method) )
|
cache_check(in_method) << call_cached_method(in_method)
|
||||||
end
|
end
|
||||||
|
|
||||||
# check that current type is the cached type
|
# check that current type is the cached type
|
||||||
@ -77,10 +78,9 @@ module Vool
|
|||||||
# if cached_type != current_type
|
# if cached_type != current_type
|
||||||
# cached_type = current_type
|
# cached_type = current_type
|
||||||
# cached_method = current_type.resolve_method(method.name)
|
# cached_method = current_type.resolve_method(method.name)
|
||||||
if_true = Mom::Statements.new(build_type_cache_update)
|
check = build_condition
|
||||||
if_true.add_array build_method_cache_update(in_method)
|
check << build_type_cache_update
|
||||||
#@if_true.to_mom( in_method ) #find and assign
|
check << build_method_cache_update(in_method)
|
||||||
[Mom::IfStatement.new( build_condition , if_true )]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# this may look like a simple_call, but the difference is that we don't know
|
# this may look like a simple_call, but the difference is that we don't know
|
||||||
@ -97,12 +97,12 @@ module Vool
|
|||||||
Mom::NotSameCheck.new(cached_type , current_type)
|
Mom::NotSameCheck.new(cached_type , current_type)
|
||||||
end
|
end
|
||||||
def build_type_cache_update
|
def build_type_cache_update
|
||||||
[Mom::SlotMove.new([@dynamic, :cached_type] , [:receiver , :type])]
|
Mom::SlotLoad.new([@dynamic, :cached_type] , [:receiver , :type])
|
||||||
end
|
end
|
||||||
def build_method_cache_update(in_method)
|
def build_method_cache_update(in_method)
|
||||||
receiver = StringConstant.new(@name)
|
receiver = StringConstant.new(@name)
|
||||||
resolve = SendStatement.new(:resolve_method , receiver , [SelfExpression.new])
|
resolve = SendStatement.new(:resolve_method , receiver , [SelfExpression.new])
|
||||||
move_method = Mom::SlotMove.new([@dynamic, :cached_method] , [:receiver , :return])
|
move_method = Mom::SlotLoad.new([@dynamic, :cached_method] , [:receiver , :return])
|
||||||
resolve.to_mom(in_method) << move_method
|
resolve.to_mom(in_method) << move_method
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -27,9 +27,6 @@ module Vool
|
|||||||
@statements << o
|
@statements << o
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
def add_array(a)
|
|
||||||
@statements += a
|
|
||||||
end
|
|
||||||
|
|
||||||
# create machine instructions
|
# create machine instructions
|
||||||
def to_mom( method )
|
def to_mom( method )
|
||||||
|
@ -16,8 +16,7 @@ module Vool
|
|||||||
|
|
||||||
def test_method_has_source
|
def test_method_has_source
|
||||||
method = create_method
|
method = create_method
|
||||||
assert_equal ScopeStatement , method.source.class
|
assert_equal IvarAssignment , method.source.class
|
||||||
assert_equal IvarAssignment , method.source.statements.first.class
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_method_has_no_locals
|
def test_method_has_no_locals
|
||||||
@ -38,22 +37,22 @@ module Vool
|
|||||||
|
|
||||||
def test_creates_method_statement_in_class
|
def test_creates_method_statement_in_class
|
||||||
clazz = VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5 ;end")
|
clazz = VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5 ;end")
|
||||||
assert_equal MethodStatement , clazz.body.statements.first.class
|
assert_equal MethodStatement , clazz.body.class
|
||||||
end
|
|
||||||
|
|
||||||
def test_parfait_class_creation
|
|
||||||
clazz = VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5;end")
|
|
||||||
assert_equal Parfait::Class , clazz.body.statements.first.clazz.class
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_method_statement_has_class
|
def test_method_statement_has_class
|
||||||
clazz = VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5;end")
|
clazz = VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5;end")
|
||||||
assert clazz.body.statements.first.clazz
|
assert clazz.body.clazz
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_parfait_class_creation
|
||||||
|
clazz = VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5;end")
|
||||||
|
assert_equal Parfait::Class , clazz.body.clazz.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_method_statement_has_class_in_main
|
def test_method_statement_has_class_in_main
|
||||||
clazz = VoolCompiler.ruby_to_vool as_main("def meth; @ivar = 5;end")
|
clazz = VoolCompiler.ruby_to_vool in_Space("def meth; @ivar = 5;end")
|
||||||
assert clazz.body.statements.first.clazz
|
assert clazz.body.clazz
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_method_has_one_local
|
def test_method_has_one_local
|
||||||
|
@ -8,14 +8,13 @@ module Vool
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
Risc.machine.boot
|
Risc.machine.boot
|
||||||
@stats = compile_first_method( "5.mod4").first
|
@ins = compile_first_method( "5.mod4")
|
||||||
@first = @stats.first
|
|
||||||
end
|
end
|
||||||
def receiver
|
def receiver
|
||||||
[Mom::IntegerConstant , 5]
|
[Mom::IntegerConstant , 5]
|
||||||
end
|
end
|
||||||
def test_call_has_right_method
|
def test_call_has_right_method
|
||||||
assert_equal :mod4, @stats[2].method.name
|
assert_equal :mod4, @ins.next(3).method.name
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user