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:
parent
3909bdcc7d
commit
ea882f403a
@ -1,6 +1,8 @@
|
|||||||
module Vool
|
module Vool
|
||||||
class Constant < Expression
|
class Constant < Expression
|
||||||
|
#gobble it up
|
||||||
|
def each(&block)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class IntegerConstant < Constant
|
class IntegerConstant < Constant
|
||||||
|
@ -8,23 +8,24 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
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
|
# there is no mom equivalent for a class, this should never be called
|
||||||
# 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()
|
raise "should not be called (call create_objects)"
|
||||||
end
|
end
|
||||||
|
|
||||||
def each(&block)
|
def each(&block)
|
||||||
block.call(self)
|
block.call(self)
|
||||||
@body.each(&block)
|
@body.each(&block) if @body
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_objects
|
def create_objects
|
||||||
create_class_object
|
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
|
end
|
||||||
|
|
||||||
def create_class_object
|
def create_class_object
|
||||||
|
@ -8,7 +8,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_mom( method )
|
def to_mom( method )
|
||||||
if method.args_type.variable_index(@name)
|
if method.arguments.variable_index(@name)
|
||||||
type = :arguments
|
type = :arguments
|
||||||
else
|
else
|
||||||
type = :frame
|
type = :frame
|
||||||
|
@ -8,12 +8,10 @@ module Vool
|
|||||||
@clazz = clazz
|
@clazz = clazz
|
||||||
end
|
end
|
||||||
|
|
||||||
# compile to mom instructions. methods themselves do no result in instructions (yet)
|
# there is no mom equivalent for a method definition, only a vool/parfait one
|
||||||
# instead the resulting instruction tree is saved into the method object that
|
# Only the source of gets momed, this should never be called
|
||||||
# represents the method
|
|
||||||
def to_mom( _ )
|
def to_mom( _ )
|
||||||
method = @clazz.get_method( @name )
|
raise "should not be called (call create_objects)"
|
||||||
@body.to_mom(method)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def each(&block)
|
def each(&block)
|
||||||
@ -33,9 +31,10 @@ module Vool
|
|||||||
method = Parfait::VoolMethod.new(name , args_type , frame_type , body )
|
method = Parfait::VoolMethod.new(name , args_type , frame_type , body )
|
||||||
@clazz.add_method( method )
|
@clazz.add_method( method )
|
||||||
typed_method = method.create_parfait_method(clazz.instance_type)
|
typed_method = method.create_parfait_method(clazz.instance_type)
|
||||||
|
head = @body.to_mom( typed_method )
|
||||||
compiler = Risc::MethodCompiler.new( typed_method ).init_method
|
compiler = Risc::MethodCompiler.new( typed_method ).init_method
|
||||||
head = @body.to_mom( method )
|
|
||||||
compiler.add_mom(head)
|
compiler.add_mom(head)
|
||||||
|
head # return for testing
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -38,7 +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)
|
@receiver = SelfExpression.new(in_method.for_type) if @receiver.is_a?(SelfExpression)
|
||||||
if(@receiver.ct_type)
|
if(@receiver.ct_type)
|
||||||
simple_call(in_method)
|
simple_call(in_method)
|
||||||
else
|
else
|
||||||
|
@ -11,7 +11,7 @@ module Vool
|
|||||||
class LocalVariable < Expression
|
class LocalVariable < Expression
|
||||||
include Named
|
include Named
|
||||||
def slot_definition(method)
|
def slot_definition(method)
|
||||||
if method.args_type.variable_index(@name)
|
if method.arguments.variable_index(@name)
|
||||||
type = :arguments
|
type = :arguments
|
||||||
else
|
else
|
||||||
type = :frame
|
type = :frame
|
||||||
|
@ -26,7 +26,7 @@ module MomCompile
|
|||||||
assert_equal Parfait::Class , lst.clazz.class , lst
|
assert_equal Parfait::Class , lst.clazz.class , lst
|
||||||
@method = lst.clazz.get_method(:main)
|
@method = lst.clazz.get_method(:main)
|
||||||
assert_equal Parfait::VoolMethod , @method.class
|
assert_equal Parfait::VoolMethod , @method.class
|
||||||
res = lst.to_mom( nil )
|
res = lst.create_objects
|
||||||
#puts "#{res.class}"
|
#puts "#{res.class}"
|
||||||
res
|
res
|
||||||
end
|
end
|
||||||
|
@ -34,7 +34,7 @@ module Vool
|
|||||||
|
|
||||||
def test_class_body_is_scope
|
def test_class_body_is_scope
|
||||||
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 ScopeStatement , clazz.body.class
|
assert_equal MethodStatement , clazz.body.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_creates_class_without_deriviation
|
def test_creates_class_without_deriviation
|
||||||
|
Loading…
x
Reference in New Issue
Block a user