gets the if coded, but test fail die to instruction being a graph now
This commit is contained in:
parent
4185758532
commit
ba15f352db
@ -3,12 +3,27 @@ module Ast
|
|||||||
# attr_reader :cond, :if_true, :if_false
|
# attr_reader :cond, :if_true, :if_false
|
||||||
def compile frame , method
|
def compile frame , method
|
||||||
is = cond.compile(frame , method)
|
is = cond.compile(frame , method)
|
||||||
# is.is_false(frame,method)
|
# is.is_false(frame,method)
|
||||||
|
# TODO should/will use different branches for different conditions.
|
||||||
|
branch = Virtual::ImplicitBranch.new
|
||||||
|
method.add branch
|
||||||
last = is
|
last = is
|
||||||
if_true.each do |part|
|
if_true.each do |part|
|
||||||
last = part.compile(frame,method )
|
last = part.compile(frame,method )
|
||||||
raise part.inspect if last.nil?
|
raise part.inspect if last.nil?
|
||||||
end
|
end
|
||||||
|
label = Virtual::Label.new
|
||||||
|
method.add label
|
||||||
|
branch.swap
|
||||||
|
method.current = branch
|
||||||
|
if_false.each do |part|
|
||||||
|
last = part.compile(frame,method )
|
||||||
|
raise part.inspect if last.nil?
|
||||||
|
end
|
||||||
|
method.add label
|
||||||
|
branch.swap
|
||||||
|
method.current = label
|
||||||
|
#TODO should return the union of the true and false types
|
||||||
last
|
last
|
||||||
end
|
end
|
||||||
def old
|
def old
|
||||||
|
@ -25,13 +25,44 @@ module Virtual
|
|||||||
# it is indeed the first instruction as just this instruction is the smallest possible programm for the machine.
|
# it is indeed the first instruction as just this instruction is the smallest possible programm for the machine.
|
||||||
# As such it is the next instruction for any first instruction that we generate.
|
# As such it is the next instruction for any first instruction that we generate.
|
||||||
class Halt < Instruction
|
class Halt < Instruction
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# following classes are stubs. currently in brainstorming mode, so anything may change anytime
|
# following classes are stubs. currently in brainstorming mode, so anything may change anytime
|
||||||
class MethodDefinitionEnter < Instruction
|
class MethodEnter < Instruction
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#resolves to nothing, but allows forward definition
|
||||||
|
class Label < Instruction
|
||||||
|
end
|
||||||
|
|
||||||
|
# the next instruction represents the true branch and the other is the .... other
|
||||||
|
# could have been the false, but false is a keyword and is asymetric to next anyway
|
||||||
|
# this is an abstract base class (though no measures are taken to prevent instantiation) and derived
|
||||||
|
# class names indicate the actual test
|
||||||
|
class Branch < Instruction
|
||||||
|
def initialize nex = nil , other = nil
|
||||||
|
super(nex)
|
||||||
|
@other = other
|
||||||
|
end
|
||||||
|
attr_reader :other
|
||||||
|
def attributes
|
||||||
|
[:other] + super
|
||||||
|
end
|
||||||
|
# so code can be "poured in" in the same way as normal, we swap the braches around in after the true condition
|
||||||
|
# and swap them back after
|
||||||
|
def swap
|
||||||
|
tmp = @other
|
||||||
|
@other = @next
|
||||||
|
@next = tmp
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# implicit means there is no explcit test involved.
|
||||||
|
# normal ruby rules are false and nil are false, EVERYTHING else is true (and that includes 0)
|
||||||
|
class ImplicitBranch < Branch
|
||||||
|
end
|
||||||
|
|
||||||
|
# A note: future branch conditions include OverflowBranch and other non-c
|
||||||
class FrameGet < Instruction
|
class FrameGet < Instruction
|
||||||
def initialize name , nex = nil
|
def initialize name , nex = nil
|
||||||
super(nex)
|
super(nex)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user