diff --git a/lib/ast/basic_expressions.rb b/lib/ast/basic_expressions.rb index 8e8238b0..14619424 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 frame , method + def compile method , frame Virtual::IntegerConstant.new value end end class TrueExpression - def compile frame , method + def compile method , frame Virtual::TrueValue.new end end class FalseExpression - def compile frame , method + def compile method , frame Virtual::FalseValue.new end end class NilExpression - def compile frame , method + def compile method , frame Virtual::NilValue.new end end @@ -33,7 +33,7 @@ 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 frame , method + def compile method , frame return Virtual::Self.new( Virtual::Mystery.new ) if name == :self if method.has_var(name) frame.compile_get(method , name ) @@ -45,7 +45,7 @@ module Ast class ModuleName < NameExpression - def compile frame , method + def compile method , frame 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 frame , method + def compile method , frame value = Virtual::StringConstant.new(string) ::Virtual::Object.space.add_object value value @@ -65,9 +65,9 @@ module Ast class AssignmentExpression < Expression #attr_reader :left, :right - def compile frame , method + def compile method , frame raise "must assign to NameExpression , not #{left}" unless left.instance_of? NameExpression - r = right.compile(frame , method) + r = right.compile(method,frame) frame.compile_set( method , left.name , r ) end def old_scratch @@ -93,7 +93,7 @@ module Ast end class VariableExpression < NameExpression - def compile frame ,method + def compile method , frame 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 a24a3bcb..e066f2bf 100644 --- a/lib/ast/call_site_expression.rb +++ b/lib/ast/call_site_expression.rb @@ -4,9 +4,9 @@ module Ast class CallSiteExpression < Expression # attr_reader :name, :args , :receiver @@counter = 0 - def compile frame , method - me = receiver.compile(frame , method ) - with = args.collect{|a| a.compile(frame , method)} + def compile method , frame + me = receiver.compile( method, frame ) + with = args.collect{|a| a.compile( method,frame)} frame.compile_send( method , name , me , with ) end diff --git a/lib/ast/expression_list.rb b/lib/ast/expression_list.rb index 99537710..beec1e80 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 binding , method - expressions.collect { |part| part.compile( binding , method ) } + def compile method , frame + expressions.collect { |part| part.compile( method, frame ) } end end end \ No newline at end of file diff --git a/lib/ast/function_expression.rb b/lib/ast/function_expression.rb index 7be2efa4..4cbe53d1 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 frame , method + def compile method , frame 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(frame,method) : Virtual::SelfReference.new + r = receiver ? receiver.compile(method,frame) : 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(frame , method ) + return_type = ex.compile(method,frame ) 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 a9297d88..042bb9c6 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 frame , method - is = cond.compile(frame , method) + def compile method , frame + is = cond.compile(method,frame) # 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(frame,method ) + last = part.compile(method,frame ) 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(frame,method ) + last = part.compile(method,frame ) 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 ac4b08a6..fca8ca26 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 frame , method + def compile method , frame call = CallSiteExpression.new( operator , [right] , left ) - call.compile(frame , method) + call.compile(method,frame) end end end \ No newline at end of file diff --git a/lib/ast/return_expression.rb b/lib/ast/return_expression.rb index 1654cbd4..fcf820d5 100644 --- a/lib/ast/return_expression.rb +++ b/lib/ast/return_expression.rb @@ -1,7 +1,7 @@ module Ast class ReturnExpression < Expression # attr_reader :expression - def compile frame ,method + def compile scope ,method Virtual::Reference.new end def sc diff --git a/lib/ast/while_expression.rb b/lib/ast/while_expression.rb index 9a02b429..a0537f9c 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 frame , method + def compile method , frame start = Virtual::Label.new("while_start") method.add start - is = condition.compile(frame , method) + is = condition.compile(method,frame) 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(frame,method ) + last = part.compile(method,frame ) raise part.inspect if last.nil? end # unconditionally brnach to the start diff --git a/test/virtual/virtual_helper.rb b/test/virtual/virtual_helper.rb index c34a290d..5d529efa 100644 --- a/test/virtual/virtual_helper.rb +++ b/test/virtual/virtual_helper.rb @@ -13,7 +13,7 @@ module VirtualHelper parts = Parser::Transform.new.apply(syntax) machine = Virtual::Machine.new main = Virtual::MethodDefinition.main - expressions = parts.compile(machine.frame , main ) + expressions = parts.compile( main, machine.frame ) should = YAML.load(@output.gsub("RETURN_MARKER" , "\n")) assert_equal should , expressions , expressions.to_yaml.gsub("\n" , "RETURN_MARKER") + "\n" + expressions.to_yaml end