all green

That fixes all existing tests. Operation successful

Off course there is tests missing :-(
This commit is contained in:
Torsten Ruger
2015-05-20 17:29:08 +03:00
parent 2ec9ee90f9
commit 422ec64105
9 changed files with 34 additions and 30 deletions

View File

@ -46,13 +46,13 @@ module Virtual
# whichever way this goes the result is stored in the return slot (as all compiles)
def self.compile_name expression , method
return Self.new( Mystery ) if expression.name == :self
name = expression.name
if method.has_var(expression.name)
name = Virtual.new_word expression.name.to_s
if method.has_var(name)
# either an argument, so it's stored in message
if( index = method.has_arg(name))
method.info.add_code MessageGet.new(name , index)
method.info.add_code MessageGet.new(expression.name , index)
else # or a local so it is in the frame
method.info.add_code FrameGet.new(name , index)
method.info.add_code FrameGet.new(expression.name , index)
end
else
call = Ast::CallSiteExpression.new(expression.name , [] ) #receiver self is implicit
@ -83,11 +83,11 @@ module Virtual
raise "must assign to NameExpression , not #{expression.left}" unless expression.left.instance_of? Ast::NameExpression
r = Compiler.compile(expression.right , method )
raise "oh noo, nil from where #{expression.right.inspect}" unless r
index = method.has_arg(name)
index = method.has_arg(Virtual.new_word name)
if index
method.info.add_code Set.new(Return.new , MessageSlot.new(index , r,type , r ))
else
index = method.ensure_local(expression.left.name)
index = method.ensure_local(Virtual.new_word expression.left.name)
method.info.add_code Set.new(Return.new , FrameSlot.new(index , r.type , r ))
end
r

View File

@ -5,18 +5,18 @@ module Virtual
def self.compile_if expression , method
# 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
merge_block = method.new_block "if_merge" # last one, created first
true_block = method.new_block "if_true" # second, linked in after current, before merge
false_block = method.new_block "if_false" # directly next in order, ie if we don't jump we land here
merge_block = method.info.new_block "if_merge" # last one, created first
true_block = method.info.new_block "if_true" # second, linked in after current, before merge
false_block = method.info.new_block "if_false" # directly next in order, ie if we don't jump we land here
is = Compiler.compile(expression.cond, 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.add_code IsTrueBranch.new( true_block )
method.info.add_code IsTrueBranch.new( true_block )
# compile the true block (as we think of it first, even it is second in sequential order)
method.current true_block
method.info.current true_block
last = is
expression.if_true.each do |part|
last = Compiler.compile(part,method )
@ -24,16 +24,16 @@ module Virtual
end
# compile the false block
method.current false_block
method.info.current false_block
expression.if_false.each do |part|
#puts "compiling in if false #{part}"
last = Compiler.compile(part,method )
raise part.inspect if last.nil?
end
method.add_code UnconditionalBranch.new( merge_block )
method.info.add_code UnconditionalBranch.new( merge_block )
#puts "compiled if: end"
method.current merge_block
method.info.current merge_block
#TODO should return the union of the true and false types
last