pass parfait method to to_mom

previously it was the toll incarnation, and that is almost the same
But for the type of self. This s by definition only known in the
parfait method
And we need it off course for type checking/dispatch
This commit is contained in:
Torsten Ruger 2018-03-16 11:03:29 +05:30
parent 3909bdcc7d
commit ea882f403a
8 changed files with 20 additions and 18 deletions

View File

@ -1,6 +1,8 @@
module Vool
class Constant < Expression
#gobble it up
def each(&block)
end
end
class IntegerConstant < Constant

View File

@ -8,23 +8,24 @@ module Vool
end
def normalize
ClassStatement.new(@name , @super_class_name, @body.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
# there is no mom equivalent for a class, this should never be called
def to_mom( _ )
@body.to_mom()
raise "should not be called (call create_objects)"
end
def each(&block)
block.call(self)
@body.each(&block)
@body.each(&block) if @body
end
def create_objects
create_class_object
self.each {|node| node.create_objects(@clazz) if node.is_a?(MethodStatement) }
mom = nil #return mom for test purpose
self.each {|node| mom = node.create_objects(@clazz) if node.is_a?(MethodStatement) }
mom
end
def create_class_object

View File

@ -8,7 +8,7 @@ module Vool
end
def to_mom( method )
if method.args_type.variable_index(@name)
if method.arguments.variable_index(@name)
type = :arguments
else
type = :frame

View File

@ -8,12 +8,10 @@ module Vool
@clazz = clazz
end
# compile to mom instructions. methods themselves do no result in instructions (yet)
# instead the resulting instruction tree is saved into the method object that
# represents the method
# there is no mom equivalent for a method definition, only a vool/parfait one
# Only the source of gets momed, this should never be called
def to_mom( _ )
method = @clazz.get_method( @name )
@body.to_mom(method)
raise "should not be called (call create_objects)"
end
def each(&block)
@ -33,9 +31,10 @@ module Vool
method = Parfait::VoolMethod.new(name , args_type , frame_type , body )
@clazz.add_method( method )
typed_method = method.create_parfait_method(clazz.instance_type)
head = @body.to_mom( typed_method )
compiler = Risc::MethodCompiler.new( typed_method ).init_method
head = @body.to_mom( method )
compiler.add_mom(head)
head # return for testing
end
private

View File

@ -38,7 +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)
@receiver = SelfExpression.new(in_method.for_type) if @receiver.is_a?(SelfExpression)
if(@receiver.ct_type)
simple_call(in_method)
else

View File

@ -11,7 +11,7 @@ module Vool
class LocalVariable < Expression
include Named
def slot_definition(method)
if method.args_type.variable_index(@name)
if method.arguments.variable_index(@name)
type = :arguments
else
type = :frame

View File

@ -26,7 +26,7 @@ module MomCompile
assert_equal Parfait::Class , lst.clazz.class , lst
@method = lst.clazz.get_method(:main)
assert_equal Parfait::VoolMethod , @method.class
res = lst.to_mom( nil )
res = lst.create_objects
#puts "#{res.class}"
res
end

View File

@ -34,7 +34,7 @@ module Vool
def test_class_body_is_scope
clazz = VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5 ;end")
assert_equal ScopeStatement , clazz.body.class
assert_equal MethodStatement , clazz.body.class
end
def test_creates_class_without_deriviation