|
@@ -151,15 +151,37 @@ class AnalysisState(object):
|
|
|
true_r,
|
|
|
false_r))
|
|
|
|
|
|
+ def analyze_while(self, instruction_id):
|
|
|
+ """Tries to analyze the given 'while' instruction."""
|
|
|
+ cond, body = yield [
|
|
|
+ ("RD", [instruction_id, "cond"]),
|
|
|
+ ("RD", [instruction_id, "body"])]
|
|
|
+
|
|
|
+ gen = self.analyze_all([cond, body])
|
|
|
+ try:
|
|
|
+ inp = None
|
|
|
+ while True:
|
|
|
+ inp = yield gen.send(inp)
|
|
|
+ except primitive_functions.PrimitiveFinished as e:
|
|
|
+ cond_r, body_r = e.result
|
|
|
+ raise primitive_functions.PrimitiveFinished(
|
|
|
+ tree_ir.LoopInstruction(
|
|
|
+ tree_ir.CompoundInstruction(
|
|
|
+ tree_ir.SelectInstruction(
|
|
|
+ tree_ir.ReadValueInstruction(cond_r),
|
|
|
+ tree_ir.BreakInstruction(),
|
|
|
+ tree_ir.EmptyInstruction()),
|
|
|
+ body_r)))
|
|
|
+
|
|
|
def analyze_constant(self, instruction_id):
|
|
|
"""Tries to analyze the given 'constant' (literal) instruction."""
|
|
|
-
|
|
|
node_id, = yield [("RD", [instruction_id, "node"])]
|
|
|
raise primitive_functions.PrimitiveFinished(
|
|
|
tree_ir.LiteralInstruction(node_id))
|
|
|
|
|
|
instruction_analyzers = {
|
|
|
'if' : analyze_if,
|
|
|
+ 'while' : analyze_while,
|
|
|
'return' : analyze_return,
|
|
|
'constant' : analyze_constant
|
|
|
}
|