def interpret(self): self.continuation.context.restart() task_context = TaskContext(self.continuation.context, self) task_context.bind_tasklocal_identifier("spawn", LambdaFunction(lambda x: self.spawn_func(x[0], x[1]))) task_context.bind_tasklocal_identifier("spawn_exec", LambdaFunction(lambda x: self.spawn_exec_func(x[0], x[1], x[2]))) task_context.bind_tasklocal_identifier("__star__", LambdaFunction(lambda x: self.lazy_dereference(x[0]))) task_context.bind_tasklocal_identifier("int", SafeLambdaFunction(lambda x: int(x[0]), self)) task_context.bind_tasklocal_identifier("range", SafeLambdaFunction(lambda x: range(*x), self)) task_context.bind_tasklocal_identifier("len", SafeLambdaFunction(lambda x: len(x[0]), self)) task_context.bind_tasklocal_identifier("has_key", SafeLambdaFunction(lambda x: x[1] in x[0], self)) task_context.bind_tasklocal_identifier("get_key", SafeLambdaFunction(lambda x: x[0][x[1]] if x[1] in x[0] else x[2], self)) task_context.bind_tasklocal_identifier("exec", LambdaFunction(lambda x: self.exec_func(x[0], x[1], x[2]))) task_context.bind_tasklocal_identifier("ref", LambdaFunction(lambda x: self.make_reference(x))) #task_context.bind_tasklocal_identifier("is_future", LambdaFunction(lambda x: self.is_future(x[0]))) #task_context.bind_tasklocal_identifier("is_error", LambdaFunction(lambda x: self.is_error(x[0]))) #task_context.bind_tasklocal_identifier("abort", LambdaFunction(lambda x: self.abort_production(x[0]))) #task_context.bind_tasklocal_identifier("task_details", LambdaFunction(lambda x: self.get_task_details(x[0]))) #task_context.bind_tasklocal_identifier("select", LambdaFunction(lambda x: self.select_func(x[0]) if len(x) == 1 else self.select_func(x[0], x[1]))) visitor = StatementExecutorVisitor(task_context) try: self.result = visitor.visit(self.continuation.task_stmt, self.continuation.stack, 0) # XXX: This is for the unusual case that we have a task fragment that runs to completion without returning anything. # Could maybe use an ErrorRef here, but this might not be erroneous if, e.g. the interactive shell is used. if self.result is None: self.result = SWErrorReference(self.expected_outputs[0], 'NO_RETURN_VALUE', 'null') except SelectException, se: local_select_group = se.select_group timeout = se.timeout select_group = map(self.continuation.resolve_tasklocal_reference_with_ref, local_select_group) cont_task_id = self.create_spawned_task_name() cont_task_descriptor = {'task_id': str(cont_task_id), 'handler': 'swi', 'dependencies': {}, 'select_group': select_group, 'select_timeout': timeout, 'expected_outputs': map(str, self.expected_outputs), 'save_continuation': self.save_continuation} self.save_continuation = False self.spawn_list.append(SpawnListEntry(cont_task_id, cont_task_descriptor, self.continuation))
def call(self, args_list, stack, stack_base, context): safe_args = self.interpreter.do_eager_thunks(args_list) return LambdaFunction.call(self, safe_args, stack, stack_base, context)
def __init__(self, function, interpreter): LambdaFunction.__init__(self, function) self.interpreter = interpreter