From 8d7b353f337503ab514798fbbc72cde38a07a42c Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 25 Jul 2014 10:49:34 +0300 Subject: [PATCH] pass message to compile, not frame --- lib/ast/basic_expressions.rb | 26 +++++++++++++------------- lib/ast/call_site_expression.rb | 8 ++++---- lib/ast/expression_list.rb | 4 ++-- lib/ast/function_expression.rb | 6 +++--- lib/ast/if_expression.rb | 8 ++++---- lib/ast/operator_expressions.rb | 4 ++-- lib/ast/while_expression.rb | 6 +++--- 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/ast/basic_expressions.rb b/lib/ast/basic_expressions.rb index 14619424..8dd542c5 100644 --- a/lib/ast/basic_expressions.rb +++ b/lib/ast/basic_expressions.rb @@ -4,25 +4,25 @@ module Ast class IntegerExpression < Expression # attr_reader :value - def compile method , frame + def compile method , message Virtual::IntegerConstant.new value end end class TrueExpression - def compile method , frame + def compile method , message Virtual::TrueValue.new end end class FalseExpression - def compile method , frame + def compile method , message Virtual::FalseValue.new end end class NilExpression - def compile method , frame + def compile method , message Virtual::NilValue.new end end @@ -33,19 +33,19 @@ module Ast # 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 ussued. # this makes the namespace static, ie when eval and co are implemented method needs recompilation - def compile method , frame + def compile method , message return Virtual::Self.new( Virtual::Mystery.new ) if name == :self if method.has_var(name) - frame.compile_get(method , name ) + message.compile_get(method , name ) else - frame.compile_send( method , name , Virtual::Self.new( Virtual::Mystery.new ) ) + message.compile_send( method , name , Virtual::Self.new( Virtual::Mystery.new ) ) end end end class ModuleName < NameExpression - def compile method , frame + def compile method , message clazz = ::Virtual::Object.space.get_or_create_class name raise "uups #{clazz}.#{name}" unless clazz #class qualifier, means call from metaclass @@ -56,7 +56,7 @@ module Ast class StringExpression < Expression # attr_reader :string - def compile method , frame + def compile method , message value = Virtual::StringConstant.new(string) ::Virtual::Object.space.add_object value value @@ -65,10 +65,10 @@ module Ast class AssignmentExpression < Expression #attr_reader :left, :right - def compile method , frame + def compile method , message raise "must assign to NameExpression , not #{left}" unless left.instance_of? NameExpression - r = right.compile(method,frame) - frame.compile_set( method , left.name , r ) + r = right.compile(method,message) + message.compile_set( method , left.name , r ) end def old_scratch if operator == "=" # assignment, value based @@ -93,7 +93,7 @@ module Ast end class VariableExpression < NameExpression - def compile method , frame + def compile method , message method.add Virtual::ObjectGet.new(name) Virtual::Return.new( Virtual::Mystery.new ) end diff --git a/lib/ast/call_site_expression.rb b/lib/ast/call_site_expression.rb index e066f2bf..046e70ae 100644 --- a/lib/ast/call_site_expression.rb +++ b/lib/ast/call_site_expression.rb @@ -4,10 +4,10 @@ module Ast class CallSiteExpression < Expression # attr_reader :name, :args , :receiver @@counter = 0 - def compile method , frame - me = receiver.compile( method, frame ) - with = args.collect{|a| a.compile( method,frame)} - frame.compile_send( method , name , me , with ) + def compile method , message + me = receiver.compile( method, message ) + with = args.collect{|a| a.compile( method,message)} + message.compile_send( method , name , me , with ) end def scratch diff --git a/lib/ast/expression_list.rb b/lib/ast/expression_list.rb index beec1e80..dc7e8a48 100644 --- a/lib/ast/expression_list.rb +++ b/lib/ast/expression_list.rb @@ -1,8 +1,8 @@ module Ast class ExpressionList < Expression # attr_reader :expressions - def compile method , frame - expressions.collect { |part| part.compile( method, frame ) } + def compile method , message + expressions.collect { |part| part.compile( method, message ) } end end end \ No newline at end of file diff --git a/lib/ast/function_expression.rb b/lib/ast/function_expression.rb index 2d567613..ea901094 100644 --- a/lib/ast/function_expression.rb +++ b/lib/ast/function_expression.rb @@ -1,17 +1,17 @@ module Ast class FunctionExpression < Expression # attr_reader :name, :params, :body , :receiver - def compile method , frame + def compile method , message args = params.collect do |p| raise "error, arguemnt must be a identifier, not #{p}" unless p.is_a? NameExpression Virtual::Argument.new( p.name , Virtual::Mystery.new ) end - r = receiver ? receiver.compile(method,frame) : Virtual::SelfReference.new + r = receiver ? receiver.compile(method,message) : Virtual::SelfReference.new method = Virtual::MethodDefinition.new(name , args , r ) #frame = frame.new_frame return_type = nil body.each do |ex| - return_type = ex.compile(method,frame ) + return_type = ex.compile(method,message ) raise return_type.inspect if return_type.is_a? Virtual::Instruction end method.return_type = return_type diff --git a/lib/ast/if_expression.rb b/lib/ast/if_expression.rb index 042bb9c6..6c4a8506 100644 --- a/lib/ast/if_expression.rb +++ b/lib/ast/if_expression.rb @@ -1,15 +1,15 @@ module Ast class IfExpression < Expression # attr_reader :cond, :if_true, :if_false - def compile method , frame - is = cond.compile(method,frame) + def compile method , message + is = cond.compile(method,message) # is.is_false(frame,method) # TODO should/will use different branches for different conditions. branch = Virtual::ImplicitBranch.new "if_merge" method.add branch last = is if_true.each do |part| - last = part.compile(method,frame ) + last = part.compile(method,message ) raise part.inspect if last.nil? end merge = Virtual::Label.new(branch.name) @@ -17,7 +17,7 @@ module Ast branch.swap method.current = branch if_false.each do |part| - last = part.compile(method,frame ) + last = part.compile(method,message ) raise part.inspect if last.nil? end method.add merge diff --git a/lib/ast/operator_expressions.rb b/lib/ast/operator_expressions.rb index fca8ca26..4bffb891 100644 --- a/lib/ast/operator_expressions.rb +++ b/lib/ast/operator_expressions.rb @@ -1,9 +1,9 @@ module Ast class OperatorExpression < Expression # attr_reader :operator, :left, :right - def compile method , frame + def compile method , message call = CallSiteExpression.new( operator , [right] , left ) - call.compile(method,frame) + call.compile(method,message) end end end \ No newline at end of file diff --git a/lib/ast/while_expression.rb b/lib/ast/while_expression.rb index a0537f9c..da47887a 100644 --- a/lib/ast/while_expression.rb +++ b/lib/ast/while_expression.rb @@ -1,17 +1,17 @@ module Ast class WhileExpression < Expression # attr_reader :condition, :body - def compile method , frame + def compile method , message start = Virtual::Label.new("while_start") method.add start - is = condition.compile(method,frame) + is = condition.compile(method,message) branch = Virtual::ImplicitBranch.new "while" merge = Virtual::Label.new(branch.name) branch.other = merge #false jumps to end of while method.add branch last = is body.each do |part| - last = part.compile(method,frame ) + last = part.compile(method,message ) raise part.inspect if last.nil? end # unconditionally brnach to the start