diff --git a/lib/bosl/compiler/basic_expressions.rb b/lib/bosl/compiler/basic_expressions.rb index 1de04629..e10b9f39 100644 --- a/lib/bosl/compiler/basic_expressions.rb +++ b/lib/bosl/compiler/basic_expressions.rb @@ -48,8 +48,8 @@ module Bosl # attr_reader :string def self.compile_string expression , method # Clearly a TODO here to implement strings rather than reusing symbols - value = expression.string.to_sym - to = Virtual::Return.new(Reference , value) + value = expression.first.to_sym + to = Virtual::Return.new(Virtual::Reference , value) method.source.constants << value method.source.add_code Virtual::Set.new( value , to ) to diff --git a/lib/bosl/compiler/callsite_expression.rb b/lib/bosl/compiler/callsite_expression.rb index 36c9dbeb..a9d3e82e 100644 --- a/lib/bosl/compiler/callsite_expression.rb +++ b/lib/bosl/compiler/callsite_expression.rb @@ -8,8 +8,11 @@ module Bosl name , arguments , receiver = *expession name = name.to_a.first - me = Compiler.compile( receiver.to_a.first , method ) - + if receiver + me = Compiler.compile( receiver.to_a.first , method ) + else + me = Virtual::Self.new + end ## need two step process, compile and save to frame # then move from frame to new message method.source.add_code Virtual::NewMessage.new diff --git a/lib/bosl/compiler/if_expression.rb b/lib/bosl/compiler/if_expression.rb index 8561ccdb..f7fd1f2b 100644 --- a/lib/bosl/compiler/if_expression.rb +++ b/lib/bosl/compiler/if_expression.rb @@ -3,6 +3,8 @@ module Bosl # if - attr_reader :cond, :if_true, :if_false def self.compile_if expression , method + condition , if_true , if_false = *expression + condition = condition.first # to execute the logic as the if states it, the blocks are the other way around # so we can the jump over the else if true , # and the else joins unconditionally after the true_block @@ -11,27 +13,27 @@ module Bosl false_block = method.source.new_block "if_false" # directly next in order, ie if we don't jump we land here - is = Compiler.compile(expression.cond, method ) + is = Compiler.compile(condition, method ) # TODO should/will use different branches for different conditions. # just a scetch : cond_val = cond_val.is_true?(method) unless cond_val.is_a? BranchCondition - method.source.add_code IsTrueBranch.new( true_block ) + method.source.add_code Virtual::IsTrueBranch.new( true_block ) # compile the true block (as we think of it first, even it is second in sequential order) method.source.current true_block last = is - expression.if_true.each do |part| + if_true.each do |part| last = Compiler.compile(part,method ) raise part.inspect if last.nil? end # compile the false block method.source.current false_block - expression.if_false.each do |part| + if_false.each do |part| #puts "compiling in if false #{part}" last = Compiler.compile(part,method ) raise part.inspect if last.nil? end - method.source.add_code UnconditionalBranch.new( merge_block ) + method.source.add_code Virtual::UnconditionalBranch.new( merge_block ) #puts "compiled if: end" method.source.current merge_block diff --git a/lib/bosl/compiler/operator_expressions.rb b/lib/bosl/compiler/operator_expressions.rb index f9da2d80..2140be60 100644 --- a/lib/bosl/compiler/operator_expressions.rb +++ b/lib/bosl/compiler/operator_expressions.rb @@ -2,8 +2,8 @@ module Bosl module Compiler # operator attr_reader :operator, :left, :right def self.compile_operator expression, method - call = Ast::CallSiteExpression.new(expression.operator , [expression.right] , expression.left ) - Compiler.compile(call, method) + operator , left , right = *expression + nil end def self.compile_assign expression, method diff --git a/test/fragments/test_if.rb b/test/fragments/test_if.rb index 629e9034..cf0e162a 100644 --- a/test/fragments/test_if.rb +++ b/test/fragments/test_if.rb @@ -26,7 +26,7 @@ HERE def test_if_function @string_input = <