generalize get_main and get_init to get_method

to get at those know methods that really
__must__ exists, hence the bang, raise if don't
about to add method missing and raise to the list
This commit is contained in:
2019-09-15 12:58:43 +03:00
parent b36ba42990
commit 7ee57f2b08
12 changed files with 100 additions and 77 deletions

View File

@ -2,6 +2,8 @@ module Mom
class Init < Macro
def to_risc(compiler)
builder = compiler.builder(compiler.source)
main = Parfait.object_space.get_method!(:Space, :main)
builder.build do
factory! << Parfait.object_space.get_factory_for(:Message)
message << factory[:next_object]
@ -9,7 +11,7 @@ module Mom
factory[:next_object] << next_message
end
builder.reset_names
Mom::MessageSetup.new(Parfait.object_space.get_main).build_with( builder )
Mom::MessageSetup.new(main).build_with( builder )
builder.build do
message << message[:next_message]
@ -22,7 +24,7 @@ module Mom
builder.build do
ret_tmp << exit_label
message[:return_address] << ret_tmp
add_code Risc.function_call( "__init__ issue call" , Parfait.object_space.get_main)
add_code Risc.function_call( "__init__ issue call" , main)
add_code exit_label
end
compiler.reset_regs

View File

@ -113,16 +113,15 @@ module Parfait
methods
end
# shortcut to get the main method. main is defined on Space
def get_main
space = get_class_by_name :Space
space.instance_type.get_method :main
end
# shortcut to get the __init__ method, which is defined on Object
def get_init
object = get_class_by_name :Object
object.instance_type.get_method :__init__
# shortcut to get at known methods that are used in the compiler
# arguments are class and method names
# returns method or raises (!)
def get_method!( clazz_name , method_name )
clazz = get_class_by_name( clazz_name )
raise "No such class #{clazz_name}" unless clazz
method = clazz.instance_type.get_method(method_name)
raise "No such Method #{method_name}, in #{clazz_name}" unless method
method
end
# get the current instance_typ of the class with the given name

View File

@ -19,6 +19,7 @@ module Risc
# call build with a block to build
def initialize(compiler, for_source)
raise "no compiler" unless compiler
raise "no source" unless for_source
@compiler = compiler
@source = for_source
@source_used = false
@ -207,7 +208,7 @@ module Risc
def call_get_more
factory = Parfait.object_space.get_factory_for( :Integer )
calling = factory.get_type.get_method( :get_more )
calling = Parfait.object_space.get_main #until we actually parse Factory
calling = Parfait.object_space.get_method!(:Space,:main) #until we actually parse Factory
raise "no main defined" unless calling
Mom::MessageSetup.new( calling ).build_with( self )
self.build do

View File

@ -14,6 +14,7 @@ module Risc
# Must pass the callable (method/block)
# Also start instuction, usually a label is mandatory
def initialize( callable , mom_label)
raise "No method" unless callable
@callable = callable
@regs = []
@constants = []