def build_spawn_continuation(self, spawn_expr, args): spawned_task_stmt = ast.Return(ast.SpawnedFunction(spawn_expr, args)) cont = SWContinuation(spawned_task_stmt, SimpleContext()) # Now need to build the reference table for the spawned task. local_reference_indices = set() # Local references in the arguments. for leaf in filter(lambda x: isinstance(x, SWLocalReference), all_leaf_values(args)): local_reference_indices.add(leaf.index) # Local references captured in the lambda/function. for leaf in filter(lambda x: isinstance(x, SWLocalReference), all_leaf_values(spawn_expr.captured_bindings)): local_reference_indices.add(leaf.index) if len(local_reference_indices) > 0: cont.current_local_id_index = max(local_reference_indices) + 1 # Actually build the new reference table. # TODO: This would be better if we compressed the table, but might take a while. # So let's assume that we won't run out of indices in a normal run :). for index in local_reference_indices: cont.reference_table[index] = self.continuation.reference_table[index] return cont
def values(self): """ Returns a list of all primitive values reachable in the current context. """ for context in self.contexts: for binding_group in context: for value in binding_group: for leaf in all_leaf_values(value): yield leaf