|
@@ -316,6 +316,7 @@ class AnalysisState(object):
|
|
def analyze_resolve(self, instruction_id):
|
|
def analyze_resolve(self, instruction_id):
|
|
"""Tries to analyze the given 'resolve' instruction."""
|
|
"""Tries to analyze the given 'resolve' instruction."""
|
|
var_id, = yield [("RD", [instruction_id, "var"])]
|
|
var_id, = yield [("RD", [instruction_id, "var"])]
|
|
|
|
+ var_name, = yield [("RV", [var_id])]
|
|
|
|
|
|
# To resolve a variable, we'll do something along the
|
|
# To resolve a variable, we'll do something along the
|
|
# lines of:
|
|
# lines of:
|
|
@@ -323,10 +324,8 @@ class AnalysisState(object):
|
|
# if 'local_var' in locals():
|
|
# if 'local_var' in locals():
|
|
# tmp = local_var
|
|
# tmp = local_var
|
|
# else:
|
|
# else:
|
|
- # _globals, var_name = yield [("RD", [user_root, "globals"]),
|
|
|
|
- # ("RV", [var_id])
|
|
|
|
- # ]
|
|
|
|
- # global_var = yield [("RD", [_globals, var_name])]
|
|
|
|
|
|
+ # _globals, = yield [("RD", [user_root, "globals"])]
|
|
|
|
+ # global_var, = yield [("RD", [_globals, var_name])]
|
|
#
|
|
#
|
|
# if global_var is None:
|
|
# if global_var is None:
|
|
# raise Exception("Runtime error: global '%s' not found" % (var_name))
|
|
# raise Exception("Runtime error: global '%s' not found" % (var_name))
|
|
@@ -334,18 +333,13 @@ class AnalysisState(object):
|
|
# tmp = global_var
|
|
# tmp = global_var
|
|
|
|
|
|
user_root = self.retrieve_user_root()
|
|
user_root = self.retrieve_user_root()
|
|
- var_name = tree_ir.StoreLocalInstruction(
|
|
|
|
- 'var_name',
|
|
|
|
- tree_ir.ReadValueInstruction(
|
|
|
|
- tree_ir.LiteralInstruction(var_id)))
|
|
|
|
-
|
|
|
|
global_var = tree_ir.StoreLocalInstruction(
|
|
global_var = tree_ir.StoreLocalInstruction(
|
|
'global_var',
|
|
'global_var',
|
|
tree_ir.ReadDictionaryValueInstruction(
|
|
tree_ir.ReadDictionaryValueInstruction(
|
|
tree_ir.ReadDictionaryValueInstruction(
|
|
tree_ir.ReadDictionaryValueInstruction(
|
|
user_root.create_load(),
|
|
user_root.create_load(),
|
|
tree_ir.LiteralInstruction('globals')),
|
|
tree_ir.LiteralInstruction('globals')),
|
|
- var_name.create_load()))
|
|
|
|
|
|
+ tree_ir.LiteralInstruction(var_name)))
|
|
|
|
|
|
err_block = tree_ir.SelectInstruction(
|
|
err_block = tree_ir.SelectInstruction(
|
|
tree_ir.BinaryInstruction(
|
|
tree_ir.BinaryInstruction(
|
|
@@ -355,10 +349,8 @@ class AnalysisState(object):
|
|
tree_ir.RaiseInstruction(
|
|
tree_ir.RaiseInstruction(
|
|
tree_ir.CallInstruction(
|
|
tree_ir.CallInstruction(
|
|
tree_ir.LoadLocalInstruction('Exception'),
|
|
tree_ir.LoadLocalInstruction('Exception'),
|
|
- [tree_ir.BinaryInstruction(
|
|
|
|
- tree_ir.LiteralInstruction("Runtime error: global '%s' not found"),
|
|
|
|
- '%',
|
|
|
|
- var_name.create_load())
|
|
|
|
|
|
+ [tree_ir.LiteralInstruction(
|
|
|
|
+ "Runtime error: global '%s' not found" % var_name)
|
|
])),
|
|
])),
|
|
tree_ir.EmptyInstruction())
|
|
tree_ir.EmptyInstruction())
|
|
|
|
|
|
@@ -370,7 +362,6 @@ class AnalysisState(object):
|
|
tree_ir.CompoundInstruction(
|
|
tree_ir.CompoundInstruction(
|
|
tree_ir.create_block(
|
|
tree_ir.create_block(
|
|
user_root,
|
|
user_root,
|
|
- var_name,
|
|
|
|
global_var,
|
|
global_var,
|
|
err_block),
|
|
err_block),
|
|
global_var.create_load())))
|
|
global_var.create_load())))
|
|
@@ -397,13 +388,12 @@ class AnalysisState(object):
|
|
def analyze_global(self, instruction_id):
|
|
def analyze_global(self, instruction_id):
|
|
"""Tries to analyze the given 'global' (declaration) instruction."""
|
|
"""Tries to analyze the given 'global' (declaration) instruction."""
|
|
var_id, = yield [("RD", [instruction_id, "var"])]
|
|
var_id, = yield [("RD", [instruction_id, "var"])]
|
|
|
|
+ var_name, = yield [("RV", [var_id])]
|
|
|
|
|
|
# To resolve a variable, we'll do something along the
|
|
# To resolve a variable, we'll do something along the
|
|
# lines of:
|
|
# lines of:
|
|
#
|
|
#
|
|
- # _globals, var_name = yield [("RD", [user_root, "globals"]),
|
|
|
|
- # ("RV", [var_id])
|
|
|
|
- # ]
|
|
|
|
|
|
+ # _globals, = yield [("RD", [user_root, "globals"])]
|
|
# global_var = yield [("RD", [_globals, var_name])]
|
|
# global_var = yield [("RD", [_globals, var_name])]
|
|
#
|
|
#
|
|
# if global_var is None:
|
|
# if global_var is None:
|
|
@@ -413,11 +403,6 @@ class AnalysisState(object):
|
|
# tmp = global_var
|
|
# tmp = global_var
|
|
|
|
|
|
user_root = self.retrieve_user_root()
|
|
user_root = self.retrieve_user_root()
|
|
- var_name = tree_ir.StoreLocalInstruction(
|
|
|
|
- 'var_name',
|
|
|
|
- tree_ir.ReadValueInstruction(
|
|
|
|
- tree_ir.LiteralInstruction(var_id)))
|
|
|
|
-
|
|
|
|
_globals = tree_ir.StoreLocalInstruction(
|
|
_globals = tree_ir.StoreLocalInstruction(
|
|
'_globals',
|
|
'_globals',
|
|
tree_ir.ReadDictionaryValueInstruction(
|
|
tree_ir.ReadDictionaryValueInstruction(
|
|
@@ -428,13 +413,12 @@ class AnalysisState(object):
|
|
'global_var',
|
|
'global_var',
|
|
tree_ir.ReadDictionaryValueInstruction(
|
|
tree_ir.ReadDictionaryValueInstruction(
|
|
_globals.create_load(),
|
|
_globals.create_load(),
|
|
- var_name.create_load()))
|
|
|
|
|
|
+ tree_ir.LiteralInstruction(var_name)))
|
|
|
|
|
|
raise primitive_functions.PrimitiveFinished(
|
|
raise primitive_functions.PrimitiveFinished(
|
|
tree_ir.CompoundInstruction(
|
|
tree_ir.CompoundInstruction(
|
|
tree_ir.create_block(
|
|
tree_ir.create_block(
|
|
user_root,
|
|
user_root,
|
|
- var_name,
|
|
|
|
_globals,
|
|
_globals,
|
|
global_var,
|
|
global_var,
|
|
tree_ir.SelectInstruction(
|
|
tree_ir.SelectInstruction(
|
|
@@ -447,7 +431,7 @@ class AnalysisState(object):
|
|
tree_ir.CreateNodeInstruction()),
|
|
tree_ir.CreateNodeInstruction()),
|
|
tree_ir.CreateDictionaryEdgeInstruction(
|
|
tree_ir.CreateDictionaryEdgeInstruction(
|
|
_globals.create_load(),
|
|
_globals.create_load(),
|
|
- var_name.create_load(),
|
|
|
|
|
|
+ tree_ir.LiteralInstruction(var_name),
|
|
global_var.create_load())),
|
|
global_var.create_load())),
|
|
tree_ir.EmptyInstruction())),
|
|
tree_ir.EmptyInstruction())),
|
|
global_var.create_load()))
|
|
global_var.create_load()))
|