make method creation class methods in MethodCompiler
and pass the wish to use main explicitly, which is really a test feature
This commit is contained in:
@ -56,7 +56,7 @@ module Vm
|
||||
# Helper function to create a new compiler and compie the statement(s)
|
||||
# Statement must be and AST::Node as generated by s expressions
|
||||
def self.compile_ast( statement )
|
||||
compiler = MethodCompiler.new
|
||||
compiler = MethodCompiler.new(:main)
|
||||
code = Vm.ast_to_code statement
|
||||
compiler.process code
|
||||
end
|
||||
@ -66,15 +66,15 @@ module Vm
|
||||
include Vm.const_get( mod.camelize )
|
||||
end
|
||||
|
||||
def initialize( method = nil )
|
||||
def initialize( method )
|
||||
@regs = []
|
||||
if method
|
||||
@method = method
|
||||
@type = method.for_type
|
||||
else
|
||||
if method == :main
|
||||
@type = Parfait.object_space.get_type()
|
||||
@method = @type.get_method( :main )
|
||||
@method = @type.create_method( :main ,{}) unless @method
|
||||
else
|
||||
@method = method
|
||||
@type = method.for_type
|
||||
end
|
||||
@current = @method.instructions
|
||||
end
|
||||
@ -107,7 +107,7 @@ module Vm
|
||||
|
||||
# create the method, do some checks and set it as the current method to be added to
|
||||
# class_name and method_name are pretty clear, args are given as a ruby array
|
||||
def create_method( class_name , method_name , args = {})
|
||||
def self.create_method( class_name , method_name , args = {})
|
||||
raise "create_method #{class_name}.#{class_name.class}" unless class_name.is_a? Symbol
|
||||
clazz = Parfait.object_space.get_class_by_name! class_name
|
||||
create_method_for( clazz.instance_type , method_name , args)
|
||||
@ -118,13 +118,12 @@ module Vm
|
||||
# args a hash that will be converted to a type
|
||||
# the created method is set as the current and the given type too
|
||||
# return the compiler (for chaining)
|
||||
def create_method_for( type , method_name , args )
|
||||
@type = type
|
||||
def self.create_method_for( type , method_name , args )
|
||||
raise "create_method #{type.inspect} is not a Type" unless type.is_a? Parfait::Type
|
||||
raise "Args must be Hash #{args}" unless args.is_a?(Hash)
|
||||
raise "create_method #{method_name}.#{method_name.class}" unless method_name.is_a? Symbol
|
||||
@method = type.create_method( method_name , args)
|
||||
self
|
||||
method = type.create_method( method_name , args)
|
||||
self.new(method)
|
||||
end
|
||||
|
||||
# add method entry and exit code. Mainly save_return for the enter and
|
||||
|
Reference in New Issue
Block a user