method tests working again

This commit is contained in:
Torsten Ruger 2018-03-16 10:32:11 +05:30
parent 1def69c783
commit 3909bdcc7d
7 changed files with 30 additions and 31 deletions

View File

@ -36,14 +36,14 @@ module Vool
raise "Not implemented for #{self}"
end
def ct_type
nil
end
end
class Expression
def ct_type
nil
end
def normalize
raise "should not be normalized #{self}"
end

View File

@ -43,13 +43,16 @@ module Vool
end
end
class SelfExpression < Expression
attr_reader :clazz
attr_reader :my_type
def initialize(type = nil)
@my_type = type
end
def to_mom(in_method)
@clazz = in_method.clazz
Mom::SlotDefinition.new(:message , [:receiver])
end
def ct_type
@clazz.instance_type
@my_type
end
end
class SuperExpression < Statement

View File

@ -10,10 +10,11 @@ module Vool
def normalize
ClassStatement.new(@name , @super_class_name, @body.normalize )
end
# compilation to the next layer, mom
# context coming in for class is nil, also for methods, henceafter a method is passed down
def to_mom( _ )
@body.to_mom(nil)
@body.to_mom()
end
def each(&block)

View File

@ -38,6 +38,7 @@ module Vool
# 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
def to_mom( in_method )
@receiver = SelfExpression.new(in_method.for_class.instance_type) if @receiver.is_a?(SelfExpression)
if(@receiver.ct_type)
simple_call(in_method)
else
@ -67,7 +68,7 @@ module Vool
# - check the cached type and if neccessary update
# - call the cached 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
# check that current type is the cached type
@ -77,10 +78,9 @@ module Vool
# if cached_type != current_type
# cached_type = current_type
# cached_method = current_type.resolve_method(method.name)
if_true = Mom::Statements.new(build_type_cache_update)
if_true.add_array build_method_cache_update(in_method)
#@if_true.to_mom( in_method ) #find and assign
[Mom::IfStatement.new( build_condition , if_true )]
check = build_condition
check << build_type_cache_update
check << build_method_cache_update(in_method)
end
# 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)
end
def build_type_cache_update
[Mom::SlotMove.new([@dynamic, :cached_type] , [:receiver , :type])]
Mom::SlotLoad.new([@dynamic, :cached_type] , [:receiver , :type])
end
def build_method_cache_update(in_method)
receiver = StringConstant.new(@name)
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
end
end

View File

@ -27,9 +27,6 @@ module Vool
@statements << o
self
end
def add_array(a)
@statements += a
end
# create machine instructions
def to_mom( method )

View File

@ -16,8 +16,7 @@ module Vool
def test_method_has_source
method = create_method
assert_equal ScopeStatement , method.source.class
assert_equal IvarAssignment , method.source.statements.first.class
assert_equal IvarAssignment , method.source.class
end
def test_method_has_no_locals
@ -38,22 +37,22 @@ module Vool
def test_creates_method_statement_in_class
clazz = VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5 ;end")
assert_equal MethodStatement , clazz.body.statements.first.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
assert_equal MethodStatement , clazz.body.class
end
def test_method_statement_has_class
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
def test_method_statement_has_class_in_main
clazz = VoolCompiler.ruby_to_vool as_main("def meth; @ivar = 5;end")
assert clazz.body.statements.first.clazz
clazz = VoolCompiler.ruby_to_vool in_Space("def meth; @ivar = 5;end")
assert clazz.body.clazz
end
def test_method_has_one_local

View File

@ -8,14 +8,13 @@ module Vool
def setup
Risc.machine.boot
@stats = compile_first_method( "5.mod4").first
@first = @stats.first
@ins = compile_first_method( "5.mod4")
end
def receiver
[Mom::IntegerConstant , 5]
end
def test_call_has_right_method
assert_equal :mod4, @stats[2].method.name
assert_equal :mod4, @ins.next(3).method.name
end
end