adding the blocks to virtual machine and store instructions in array not list

This commit is contained in:
Torsten Ruger
2014-08-13 11:59:51 +03:00
parent c2ae184e6e
commit 200228a33d
16 changed files with 196 additions and 207 deletions

View File

@ -95,7 +95,7 @@ module Ast
class VariableExpression < NameExpression
def compile method , message
method.add Virtual::ObjectGet.new(name)
method.add_code Virtual::ObjectGet.new(name)
Virtual::Return.new( Virtual::Mystery.new )
end
end

View File

@ -37,7 +37,7 @@ module Ast
end
function = Virtual::Function.new(name , me , args )
clazz.add_function function
clazz.add_code_function function
parent_locals = context.locals
parent_function = context.function

View File

@ -6,21 +6,21 @@ module Ast
# is.is_false(frame,method)
# TODO should/will use different branches for different conditions.
branch = Virtual::ImplicitBranch.new "if_merge"
method.add branch
method.add_code branch
last = is
if_true.each do |part|
last = part.compile(method,message )
raise part.inspect if last.nil?
end
merge = Virtual::Label.new(branch.name)
method.add merge
method.add_code merge
branch.swap
method.current = branch
if_false.each do |part|
last = part.compile(method,message )
raise part.inspect if last.nil?
end
method.add merge
method.add_code merge
branch.swap
method.current = merge
#TODO should return the union of the true and false types

View File

@ -3,12 +3,12 @@ module Ast
# attr_reader :condition, :body
def compile method , message
start = Virtual::Label.new("while_start")
method.add start
method.add_code start
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
method.add_code branch
last = is
body.each do |part|
last = part.compile(method,message )