rename a bit

This commit is contained in:
Torsten Ruger 2018-06-29 13:03:19 +03:00
parent d50893bb0f
commit 3dffebed3f
5 changed files with 16 additions and 26 deletions

View File

@ -3,10 +3,10 @@ module Risc
module Builtin module Builtin
module CompileHelper module CompileHelper
def compiler_for( type , method_name , arguments , locals = {}) def compiler_for( clazz_name , method_name , arguments , locals = {})
frame = Parfait::NamedList.type_for( locals ) frame = Parfait::NamedList.type_for( locals )
args = Parfait::NamedList.type_for( arguments ) args = Parfait::NamedList.type_for( arguments )
Risc::MethodCompiler.create_method(type , method_name , args, frame ) Risc::MethodCompiler.compiler_for_class(clazz_name , method_name , args, frame )
end end
end end

View File

@ -41,11 +41,12 @@ module Risc
emit_syscall( compiler.builder(true, compiler.method) , :exit ) emit_syscall( compiler.builder(true, compiler.method) , :exit )
return compiler.method return compiler.method
end end
# this is the really really first place the machine starts (apart from the jump here) # this is the really really first place the machine starts (apart from the jump here)
# it isn't really a function, ie it is jumped to (not called), exits and may not return # it isn't really a function, ie it is jumped to (not called), exits and may not return
# so it is responsible for initial setup # so it is responsible for initial setup
def __init__ context def __init__ context
compiler = Risc::MethodCompiler.create_method(:Object,:__init__ , compiler = MethodCompiler.compiler_for_class(:Object,:__init__ ,
Parfait::NamedList.type_for({}) , Parfait::NamedList.type_for({})) Parfait::NamedList.type_for({}) , Parfait::NamedList.type_for({}))
builder = compiler.builder(true, compiler.method) builder = compiler.builder(true, compiler.method)
builder.build do builder.build do

View File

@ -8,32 +8,30 @@ module Risc
def initialize( method ) def initialize( method )
@regs = [] @regs = []
if method == :main @method = method
@type = Parfait.object_space.get_type() @type = method.for_type
@method = @type.get_method( :main )
@method = @type.create_method( :main ,{}) unless @method
else
@method = method
@type = method.for_type
end
@current = @method.risc_instructions @current = @method.risc_instructions
end end
attr_reader :type , :method attr_reader :type , :method
# 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 # helper method for builtin mainly
def self.create_method( class_name , method_name , args , frame ) # the class_name is a symbol, which is resolved to the instance_type of that class
#
# return compiler_for_type with the resolved type
#
def self.compiler_for_class( class_name , method_name , args , frame )
raise "create_method #{class_name}.#{class_name.class}" unless class_name.is_a? Symbol raise "create_method #{class_name}.#{class_name.class}" unless class_name.is_a? Symbol
clazz = Parfait.object_space.get_class_by_name! class_name clazz = Parfait.object_space.get_class_by_name! class_name
create_method_for( clazz.instance_type , method_name , args , frame) compiler_for_type( clazz.instance_type , method_name , args , frame)
end end
# create a method for the given type ( Parfait type object) # create a method for the given type ( Parfait type object)
# method_name is a Symbol # method_name is a Symbol
# args a hash that will be converted to a type # args a hash that will be converted to a type
# the created method is set as the current and the given type too # the created method is set as the current and the given type too
# return the compiler (for chaining) # return the compiler
def self.create_method_for( type , method_name , args , frame) def self.compiler_for_type( type , method_name , args , frame)
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
raise "Args must be Type #{args}" unless args.is_a?(Parfait::Type) raise "Args must be Type #{args}" unless args.is_a?(Parfait::Type)
raise "create_method #{method_name}.#{method_name.class}" unless method_name.is_a? Symbol raise "create_method #{method_name}.#{method_name.class}" unless method_name.is_a? Symbol

View File

@ -2,7 +2,6 @@ require_relative '../helper'
module Risc module Risc
module Statements module Statements
include CleanCompile
def setup def setup
Risc.machine.boot # force boot to reset main Risc.machine.boot # force boot to reset main

View File

@ -61,14 +61,6 @@ module MomCompile
end end
module CleanCompile
def clean_compile(clazz_name , method_name , args , statements)
compiler = Vm::MethodCompiler.create_method(clazz_name,method_name,args )
compiler.process( Vm.ast_to_code( statements ) )
end
end
class Ignored class Ignored