Пример #1
0
 def method_module_eval(self,
                        space,
                        string=None,
                        filename=None,
                        w_lineno=None,
                        block=None):
     if string is not None and block is not None:
         raise space.error(space.w_ArgumentError,
                           "wrong number of arguments")
     if string is not None:
         if filename is None:
             filename = "module_eval"
         if w_lineno is not None:
             lineno = space.int_w(w_lineno)
         else:
             lineno = 1
         return space.execute(string,
                              self,
                              lexical_scope=StaticScope(self, None),
                              filepath=filename,
                              initial_lineno=lineno)
     elif block is None:
         raise space.error(space.w_ArgumentError, "block not supplied")
     else:
         return space.invoke_block(
             block.copy(space,
                        w_self=self,
                        lexical_scope=StaticScope(self,
                                                  block.lexical_scope)), [])
Пример #2
0
    def EVALUATE_MODULE(self, space, bytecode, frame, pc):
        space.getexecutioncontext().last_instr = pc
        w_bytecode = frame.pop()
        w_mod = frame.pop()
        assert isinstance(w_bytecode, W_CodeObject)

        event = "class" if space.is_kind_of(w_mod, space.w_class) else "module"
        space.getexecutioncontext().invoke_trace_proc(space,
                                                      event,
                                                      None,
                                                      None,
                                                      frame=frame)
        sub_frame = space.create_frame(w_bytecode,
                                       w_mod,
                                       StaticScope(w_mod, frame.lexical_scope),
                                       block=frame.block)
        with space.getexecutioncontext().visit_frame(sub_frame):
            w_res = space.execute_frame(sub_frame, w_bytecode)

        space.getexecutioncontext().invoke_trace_proc(space,
                                                      "end",
                                                      None,
                                                      None,
                                                      frame=frame)
        frame.push(w_res)
Пример #3
0
 def method_module_exec(self, space, args_w, block):
     if block is None:
         raise space.error(space.w_LocalJumpError, "no block given")
     return space.invoke_block(
         block.copy(space,
                    w_self=self,
                    lexical_scope=StaticScope(self, None)), args_w)
Пример #4
0
 def method_instance_exec(self, space, args_w, block):
     if block is None:
         raise space.error(space.w_LocalJumpError, "no block given")
     return space.invoke_block(
         block.copy(space,
                    w_self=self,
                    lexical_scope=StaticScope(space.getsingletonclass(self),
                                              block.lexical_scope)), args_w)
Пример #5
0
 def method_instance_eval(self, space, string=None, filename=None, w_lineno=None, block=None):
     if string is not None:
         if filename is None:
             filename = "instance_eval"
         if w_lineno is not None:
             lineno = space.int_w(w_lineno)
         else:
             lineno = 1
         return space.execute(string, self, StaticScope(space.getclass(self), None), filename, lineno)
     else:
         if block is not None:
             return space.invoke_block(block.copy(space, w_self=self), [])
         else:
             raise space.error(space.w_ArgumentError, "block not supplied")
Пример #6
0
    def method_instance_exec(self, space, args_w, block):
        if block is None:
            raise space.error(space.w_LocalJumpError, "no block given")

        if space.is_kind_of(self, space.w_symbol) or space.is_kind_of(
                self, space.w_numeric):
            self_klass = None
        else:
            self_klass = space.getsingletonclass(self)

        return space.invoke_block(
            block.copy(space,
                       w_self=self,
                       lexical_scope=StaticScope(self_klass,
                                                 block.lexical_scope)), args_w)
Пример #7
0
    def load_feature(space, path, orig_path, wrap=False):
        if not os.path.exists(path):
            raise space.error(space.w_LoadError, orig_path)

        try:
            f = open_file_as_stream(path, buffering=0)
            try:
                contents = f.readall()
            finally:
                f.close()
        except OSError as e:
            raise error_for_oserror(space, e)

        if wrap:
            lexical_scope = StaticScope(space.newmodule("Anonymous"), None)
        else:
            lexical_scope = None
        space.execute(contents, filepath=path, lexical_scope=lexical_scope)