From 849a92a9097804ded1e2d9836894b98c809c41b9 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 19 Jul 2015 12:31:35 +0300 Subject: [PATCH] splitting out the compile_name expression --- Gemfile.lock | 2 +- lib/virtual/compiler.rb | 1 + lib/virtual/compiler/basic_expressions.rb | 21 ------------------- lib/virtual/compiler/name_expression.rb | 25 +++++++++++++++++++++++ 4 files changed, 27 insertions(+), 22 deletions(-) create mode 100644 lib/virtual/compiler/name_expression.rb diff --git a/Gemfile.lock b/Gemfile.lock index 185599b1..29d2a634 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,7 +12,7 @@ GIT GIT remote: git://github.com/salama/salama-reader.git - revision: f790b5d76a2c3473d2503bca65e998985b3e67cc + revision: 841592c667acea1e796f950851262e6938b231bc specs: salama-reader (0.2.0) parslet (~> 1.7.0) diff --git a/lib/virtual/compiler.rb b/lib/virtual/compiler.rb index f3771eeb..60a09094 100644 --- a/lib/virtual/compiler.rb +++ b/lib/virtual/compiler.rb @@ -33,6 +33,7 @@ module Virtual end require_relative "compiler/basic_expressions" +require_relative "compiler/name_expression" require_relative "compiler/callsite_expression" require_relative "compiler/compound_expressions" require_relative "compiler/if_expression" diff --git a/lib/virtual/compiler/basic_expressions.rb b/lib/virtual/compiler/basic_expressions.rb index 2481dc20..2e9173a0 100644 --- a/lib/virtual/compiler/basic_expressions.rb +++ b/lib/virtual/compiler/basic_expressions.rb @@ -37,27 +37,6 @@ module Virtual to end - # attr_reader :name - # compiling name needs to check if it's a variable and if so resolve it - # otherwise it's a method without args and a send is issued. - # whichever way this goes the result is stored in the return slot (as all compiles) - def self.compile_name expression , method - return Self.new( Reference.new(method.for_class)) if expression.name == :self - name = expression.name.to_sym - if method.has_var(name) - # either an argument, so it's stored in message - if( index = method.has_arg(name)) - method.source.add_code Set.new( MessageSlot.new(expression.name) , Return.new) - else # or a local so it is in the frame - method.source.add_code FrameGet.new(expression.name , index) - end - else - call = Ast::CallSiteExpression.new(expression.name , [] ) #receiver self is implicit - Compiler.compile(call, method) - end - end - - def self.compile_module expression , method clazz = Space.space.get_class_by_name name raise "uups #{clazz}.#{name}" unless clazz diff --git a/lib/virtual/compiler/name_expression.rb b/lib/virtual/compiler/name_expression.rb new file mode 100644 index 00000000..abbd4446 --- /dev/null +++ b/lib/virtual/compiler/name_expression.rb @@ -0,0 +1,25 @@ +module Virtual + module Compiler + + # attr_reader :name + # compiling name needs to check if it's a variable and if so resolve it + # otherwise it's a method without args and a send is issued. + # whichever way this goes the result is stored in the return slot (as all compiles) + def self.compile_name expression , method + return Self.new( Reference.new(method.for_class)) if expression.name == :self + name = expression.name.to_sym + if method.has_var(name) + # either an argument, so it's stored in message + if( index = method.has_arg(name)) + method.source.add_code Set.new( MessageSlot.new(expression.name) , Return.new) + else # or a local so it is in the frame + method.source.add_code FrameGet.new(expression.name , index) + end + else + call = Ast::CallSiteExpression.new(expression.name , [] ) #receiver self is implicit + Compiler.compile(call, method) + end + end + + end #module +end