more expressions and if test
This commit is contained in:
parent
9bacb07f1c
commit
3a885a8e46
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -26,7 +26,7 @@ HERE
|
||||
|
||||
def test_if_function
|
||||
@string_input = <<HERE
|
||||
def itest(n)
|
||||
int itest(int n)
|
||||
if( n < 12)
|
||||
"then".putstring()
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user