|
@@ -340,7 +340,7 @@ class AnalysisState(object):
|
|
|
tree_ir.ReadDictionaryValueInstruction(
|
|
|
user_root.create_load(),
|
|
|
tree_ir.LiteralInstruction('globals')),
|
|
|
- var_id.create_load()))
|
|
|
+ var_name.create_load()))
|
|
|
|
|
|
err_block = tree_ir.SelectInstruction(
|
|
|
tree_ir.BinaryInstruction(
|
|
@@ -390,7 +390,7 @@ class AnalysisState(object):
|
|
|
tree_ir.CreateNodeInstruction())))
|
|
|
|
|
|
def analyze_global(self, instruction_id):
|
|
|
- """Tries to analyze the given 'global' (declaration) function."""
|
|
|
+ """Tries to analyze the given 'global' (declaration) instruction."""
|
|
|
var_id, = yield [("RD", [instruction_id, "var"])]
|
|
|
|
|
|
# To resolve a variable, we'll do something along the
|
|
@@ -445,8 +445,46 @@ class AnalysisState(object):
|
|
|
var_name.create_load(),
|
|
|
global_var.create_load())),
|
|
|
tree_ir.EmptyInstruction())),
|
|
|
- global_var.create_load())
|
|
|
- )
|
|
|
+ global_var.create_load()))
|
|
|
+
|
|
|
+ def analyze_assign(self, instruction_id):
|
|
|
+ """Tries to analyze the given 'assign' instruction."""
|
|
|
+ var_id, value_id = yield [("RD", [instruction_id, "var"]),
|
|
|
+ ("RD", [instruction_id, "value"])]
|
|
|
+
|
|
|
+ try:
|
|
|
+ gen = self.analyze_all([var_id, value_id])
|
|
|
+ inp = None
|
|
|
+ while True:
|
|
|
+ inp = yield gen.send(inp)
|
|
|
+ except primitive_functions.PrimitiveFinished as ex:
|
|
|
+ var_r, value_r = ex.result
|
|
|
+
|
|
|
+ # Assignments work like this:
|
|
|
+ #
|
|
|
+ # value_link = yield [("RDE", [variable, "value"])]
|
|
|
+ # _, _ = yield [("CD", [variable, "value", value]),
|
|
|
+ # ("DE", [value_link])]
|
|
|
+
|
|
|
+ variable = tree_ir.StoreLocalInstruction('variable', var_r)
|
|
|
+ value = tree_ir.StoreLocalInstruction('value', value_r)
|
|
|
+ value_link = tree_ir.StoreLocalInstruction(
|
|
|
+ 'value_link',
|
|
|
+ tree_ir.ReadDictionaryEdgeInstruction(
|
|
|
+ variable.create_load(),
|
|
|
+ tree_ir.LiteralInstruction('value')))
|
|
|
+
|
|
|
+ raise primitive_functions.PrimitiveFinished(
|
|
|
+ tree_ir.create_block(
|
|
|
+ variable,
|
|
|
+ value,
|
|
|
+ value_link,
|
|
|
+ tree_ir.CreateDictionaryEdgeInstruction(
|
|
|
+ variable.create_load(),
|
|
|
+ tree_ir.LiteralInstruction('value'),
|
|
|
+ value.create_load()),
|
|
|
+ tree_ir.DeleteEdgeInstruction(
|
|
|
+ value_link.create_load())))
|
|
|
|
|
|
instruction_analyzers = {
|
|
|
'if' : analyze_if,
|
|
@@ -456,6 +494,7 @@ class AnalysisState(object):
|
|
|
'resolve' : analyze_resolve,
|
|
|
'declare' : analyze_declare,
|
|
|
'global' : analyze_global,
|
|
|
+ 'assign' : analyze_assign,
|
|
|
'output' : analyze_output
|
|
|
}
|
|
|
|