remove to_mom / create_objects dichotomy
wsa supposed to be clearer, but even to me seems confusing now.
This commit is contained in:
parent
c6a903073a
commit
f0ba863721
@ -22,7 +22,7 @@ module Parfait
|
||||
raise "source must be vool" unless source.is_a?(Vool::Statement)
|
||||
end
|
||||
|
||||
def create_parfait_method( type )
|
||||
def create_typed_method( type )
|
||||
raise "create_method #{type.inspect} is not a Type" unless type.is_a? Parfait::Type
|
||||
type.create_method( @name , @args_type , @frame_type)
|
||||
end
|
||||
|
@ -11,9 +11,13 @@ module Vool
|
||||
ClassStatement.new(@name , @super_class_name, @body&.normalize )
|
||||
end
|
||||
|
||||
# there is no mom equivalent for a class, this should never be called
|
||||
def to_mom( _ )
|
||||
raise "should not be called (call create_objects)"
|
||||
create_class_object
|
||||
mom = nil #return mom for test purpose
|
||||
self.each do |node|
|
||||
mom = node.to_mom(@clazz) if node.is_a?(MethodStatement)
|
||||
end
|
||||
mom
|
||||
end
|
||||
|
||||
def each(&block)
|
||||
@ -21,13 +25,6 @@ module Vool
|
||||
@body.each(&block) if @body
|
||||
end
|
||||
|
||||
def create_objects
|
||||
create_class_object
|
||||
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
|
||||
@clazz = Parfait.object_space.get_class_by_name(@name )
|
||||
if(@clazz)
|
||||
|
@ -8,10 +8,16 @@ module Vool
|
||||
@clazz = clazz
|
||||
end
|
||||
|
||||
# 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( _ )
|
||||
raise "should not be called (call create_objects)"
|
||||
def to_mom(clazz)
|
||||
@clazz = clazz
|
||||
raise "no class" unless clazz
|
||||
method = Parfait::VoolMethod.new(name , make_type , make_frame , body )
|
||||
@clazz.add_method( method )
|
||||
typed_method = method.create_typed_method(clazz.instance_type)
|
||||
head = @body.to_mom( typed_method )
|
||||
compiler = Risc::MethodCompiler.new( typed_method )
|
||||
compiler.add_mom(head)
|
||||
head # return for testing
|
||||
end
|
||||
|
||||
def each(&block)
|
||||
@ -23,20 +29,6 @@ module Vool
|
||||
MethodStatement.new( @name , @args , @body.normalize)
|
||||
end
|
||||
|
||||
def create_objects(clazz)
|
||||
@clazz = clazz
|
||||
raise "no class" unless clazz
|
||||
args_type = make_type
|
||||
frame_type = make_frame
|
||||
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 )
|
||||
compiler.add_mom(head)
|
||||
head # return for testing
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def make_type( )
|
||||
|
@ -6,7 +6,7 @@ module Vool
|
||||
def self.ruby_to_vool( ruby_source )
|
||||
statements = RubyCompiler.compile( ruby_source )
|
||||
statements = statements.normalize
|
||||
statements.create_objects
|
||||
statements.to_mom(nil)
|
||||
statements
|
||||
end
|
||||
def self.ruby_to_mom(source)
|
||||
|
@ -4,7 +4,7 @@ module Risc
|
||||
class TestPadding < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Risc.machine.boot unless Risc.machine.booted
|
||||
Risc.machine.boot
|
||||
end
|
||||
|
||||
def test_small
|
||||
|
@ -26,7 +26,7 @@ module MomCompile
|
||||
# but here we return the intermediate mom instructions that are otherwise not available
|
||||
statements = Vool::RubyCompiler.compile as_test_main( input )
|
||||
statements = statements.normalize
|
||||
res = statements.create_objects
|
||||
res = statements.to_mom(nil)
|
||||
assert_equal Parfait::Class , statements.clazz.class , statements
|
||||
@method = statements.clazz.get_method(:main)
|
||||
assert_equal Parfait::VoolMethod , @method.class
|
||||
|
Loading…
Reference in New Issue
Block a user