refoactor call site some

This commit is contained in:
Torsten Ruger 2016-12-09 12:22:37 +02:00
parent 224670e449
commit 395fd2d701
4 changed files with 32 additions and 20 deletions

View File

@ -1,5 +1,7 @@
module Typed
class CallSite < Expression
attr_accessor :name , :receiver , :arguments
module Tree
class CallSite < Expression
attr_accessor :name , :receiver , :arguments
end
end
end

View File

@ -117,7 +117,7 @@ module Typed
def on_call statement
name_s , arguments , receiver = *statement
w = CallSite.new()
w = Tree::CallSite.new()
w.name = name_s.children.first
w.arguments = process_all(arguments)
w.receiver = process(receiver)

View File

@ -1,4 +1,6 @@
require_relative "compiler/name_expression"
["call_site", "name_expression"].each do |mod|
require_relative "compiler/" + mod
end
module Typed
# Compiling is the conversion of the AST into 2 things:
@ -40,6 +42,7 @@ module Typed
class Compiler
include NameExpression
include CallSite
def initialize( method = nil )
@regs = []
@ -183,7 +186,6 @@ require_relative "ast_helper"
require_relative "ast/code"
require_relative "compiler/assignment"
require_relative "compiler/basic_values"
require_relative "compiler/call_site"
require_relative "compiler/class_field"
require_relative "compiler/class_statement"
require_relative "compiler/collections"

View File

@ -1,26 +1,15 @@
module Typed
Compiler.class_eval do
module CallSite
def on_CallSite statement
#puts statement
def on_CallSite( statement )
# name_s , arguments , receiver = *statement
raise "not inside method " unless @method
reset_regs
#move the new message (that we need to populate to make a call) to std register
new_message = Register.resolve_to_register(:new_message)
add_code Register.get_slot(statement, :message , :next_message , new_message )
if statement.receiver
me = process( statement.receiver )
else
me = use_reg @method.for_class.name
add_code Register.get_slot(statement, :message , :receiver , me )
end
if(me.type == :MetaClass)
clazz = me.value.meta
else
# now we have to resolve the method name (+ receiver) into a callable method
clazz = Register.machine.space.get_class_by_name(me.type)
end
me = get_me( statement )
clazz = get_clazz(me)
# move our receiver there
add_code Register.set_slot( statement , me , :new_message , :receiver)
@ -35,6 +24,25 @@ module Typed
end
private
def get_me( statement )
if statement.receiver
me = process( statement.receiver )
else
me = use_reg @method.for_class.name
add_code Register.get_slot(statement, :message , :receiver , me )
end
me
end
def get_clazz( me )
if(me.type == :MetaClass)
clazz = me.value.meta
else
# now we have to resolve the method name (+ receiver) into a callable method
clazz = Register.machine.space.get_class_by_name(me.type)
end
clazz
end
def do_call clazz , statement
name = statement.name
#puts "clazz #{clazz.name}"