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)
|
raise "source must be vool" unless source.is_a?(Vool::Statement)
|
||||||
end
|
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
|
raise "create_method #{type.inspect} is not a Type" unless type.is_a? Parfait::Type
|
||||||
type.create_method( @name , @args_type , @frame_type)
|
type.create_method( @name , @args_type , @frame_type)
|
||||||
end
|
end
|
||||||
|
@ -11,9 +11,13 @@ module Vool
|
|||||||
ClassStatement.new(@name , @super_class_name, @body&.normalize )
|
ClassStatement.new(@name , @super_class_name, @body&.normalize )
|
||||||
end
|
end
|
||||||
|
|
||||||
# there is no mom equivalent for a class, this should never be called
|
|
||||||
def to_mom( _ )
|
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
|
end
|
||||||
|
|
||||||
def each(&block)
|
def each(&block)
|
||||||
@ -21,13 +25,6 @@ module Vool
|
|||||||
@body.each(&block) if @body
|
@body.each(&block) if @body
|
||||||
end
|
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
|
def create_class_object
|
||||||
@clazz = Parfait.object_space.get_class_by_name(@name )
|
@clazz = Parfait.object_space.get_class_by_name(@name )
|
||||||
if(@clazz)
|
if(@clazz)
|
||||||
|
@ -8,10 +8,16 @@ module Vool
|
|||||||
@clazz = clazz
|
@clazz = clazz
|
||||||
end
|
end
|
||||||
|
|
||||||
# there is no mom equivalent for a method definition, only a vool/parfait one
|
def to_mom(clazz)
|
||||||
# Only the source of gets momed, this should never be called
|
@clazz = clazz
|
||||||
def to_mom( _ )
|
raise "no class" unless clazz
|
||||||
raise "should not be called (call create_objects)"
|
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
|
end
|
||||||
|
|
||||||
def each(&block)
|
def each(&block)
|
||||||
@ -23,20 +29,6 @@ module Vool
|
|||||||
MethodStatement.new( @name , @args , @body.normalize)
|
MethodStatement.new( @name , @args , @body.normalize)
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def make_type( )
|
def make_type( )
|
||||||
|
@ -6,7 +6,7 @@ module Vool
|
|||||||
def self.ruby_to_vool( ruby_source )
|
def self.ruby_to_vool( ruby_source )
|
||||||
statements = RubyCompiler.compile( ruby_source )
|
statements = RubyCompiler.compile( ruby_source )
|
||||||
statements = statements.normalize
|
statements = statements.normalize
|
||||||
statements.create_objects
|
statements.to_mom(nil)
|
||||||
statements
|
statements
|
||||||
end
|
end
|
||||||
def self.ruby_to_mom(source)
|
def self.ruby_to_mom(source)
|
||||||
|
@ -4,7 +4,7 @@ module Risc
|
|||||||
class TestPadding < MiniTest::Test
|
class TestPadding < MiniTest::Test
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Risc.machine.boot unless Risc.machine.booted
|
Risc.machine.boot
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_small
|
def test_small
|
||||||
|
@ -26,7 +26,7 @@ module MomCompile
|
|||||||
# but here we return the intermediate mom instructions that are otherwise not available
|
# but here we return the intermediate mom instructions that are otherwise not available
|
||||||
statements = Vool::RubyCompiler.compile as_test_main( input )
|
statements = Vool::RubyCompiler.compile as_test_main( input )
|
||||||
statements = statements.normalize
|
statements = statements.normalize
|
||||||
res = statements.create_objects
|
res = statements.to_mom(nil)
|
||||||
assert_equal Parfait::Class , statements.clazz.class , statements
|
assert_equal Parfait::Class , statements.clazz.class , statements
|
||||||
@method = statements.clazz.get_method(:main)
|
@method = statements.clazz.get_method(:main)
|
||||||
assert_equal Parfait::VoolMethod , @method.class
|
assert_equal Parfait::VoolMethod , @method.class
|
||||||
|
Loading…
Reference in New Issue
Block a user