當前位置: 首頁>>代碼示例>>Python>>正文


Python compiler.NS_VAR類代碼示例

本文整理匯總了Python中pixie.vm.compiler.NS_VAR的典型用法代碼示例。如果您正苦於以下問題:Python NS_VAR類的具體用法?Python NS_VAR怎麽用?Python NS_VAR使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了NS_VAR類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: inner_invoke

    def inner_invoke(self, args):
        import pixie.vm.rt as rt
        import pixie.vm.persistent_vector as vector

        with with_ns(u"user"):
            NS_VAR.deref().include_stdlib()

        acc = vector.EMPTY
        for x in self._argv:
            acc = rt.conj(acc, rt.wrap(x))

        PROGRAM_ARGUMENTS.set_root(acc)

        with with_ns(u"user"):
            try:
                f = None
                if self._file == '-':
                    f, _, _ = create_stdio()
                else:
                    if not path.isfile(self._file):
                        print "Error: Cannot open '" + self._file + "'"
                        os._exit(1)
                    f = open(self._file)
                data = f.read()
                f.close()

                if data.startswith("#!"):
                    newline_pos = data.find("\n")
                    if newline_pos > 0:
                        data = data[newline_pos:]

                rt.load_reader(StringReader(unicode_from_utf8(data)))
            except WrappedException as ex:
                print "Error: ", ex._ex.__repr__()
                os._exit(1)
開發者ID:gigasquid,項目名稱:pixie,代碼行數:35,代碼來源:target.py

示例2: inner_invoke

    def inner_invoke(self, args):
        import pixie.vm.rt as rt

        with with_ns(u"user"):
            NS_VAR.deref().include_stdlib()

            interpret(compile(read(StringReader(unicode(self._expr)), True)))
開發者ID:devn,項目名稱:pixie,代碼行數:7,代碼來源:target.py

示例3: inner_invoke

    def inner_invoke(self, args):
        from pixie.vm.keyword import keyword
        import pixie.vm.rt as rt
        from pixie.vm.string import String
        import pixie.vm.persistent_vector as vector

        with with_ns(u"user"):
            NS_VAR.deref().include_stdlib()

        acc = vector.EMPTY
        for x in self._argv:
            acc = rt.conj(acc, rt.wrap(x))

        PROGRAM_ARGUMENTS.set_root(acc)


        rdr = MetaDataReader(PromptReader())
        with with_ns(u"user"):
            while True:
                try:
                    val = read(rdr, False)
                    if val is eof:
                        break
                    val = interpret(compile(val))
                except WrappedException as ex:
                    print "Error: ", ex._ex.__repr__()
                    rdr.reset_line()
                    continue
                if val is keyword(u"exit-repl"):
                    break
                val = rt.str(val)
                assert isinstance(val, String), "str should always return a string"
                print val._str
開發者ID:squaremo,項目名稱:pixie,代碼行數:33,代碼來源:target.py

示例4: in_ns

def in_ns(ns_name):
    from pixie.vm.compiler import NS_VAR

    NS_VAR.set_value(code._ns_registry.find_or_make(rt.name(ns_name)))
    NS_VAR.deref().include_stdlib()

    return nil
開發者ID:nooga,項目名稱:pixie,代碼行數:7,代碼來源:stdlib.py

示例5: inner_invoke

    def inner_invoke(self, args):
        import pixie.vm.rt as rt
        import pixie.vm.persistent_vector as vector

        with with_ns(u"user"):
            NS_VAR.deref().include_stdlib()

        acc = vector.EMPTY
        for x in self._argv:
            acc = rt.conj(acc, rt.wrap(x))

        PROGRAM_ARGUMENTS.set_root(acc)

        with with_ns(u"user"):
            if self._file == '-':
                stdin, _, _ = create_stdio()
                code = stdin.read()
                interpret(compile(read(StringReader(unicode(code)), True)))
            else:
                rt.load_file(rt.wrap(self._file))
開發者ID:foodhype,項目名稱:pixie,代碼行數:20,代碼來源:target.py

示例6: repl

def repl():
    from pixie.vm.keyword import keyword
    import pixie.vm.rt as rt
    from pixie.vm.string import String

    with with_ns(u"user"):
        NS_VAR.deref().include_stdlib()

    rdr = PromptReader()
    while True:
        with with_ns(u"user"):
            try:
                val = interpret(compile(read(rdr, True)))
            except WrappedException as ex:
                print "Error: ", ex._ex.__repr__()
                continue
            if val is keyword(u"exit-repl"):
                break
            val = rt.str(val)
            assert isinstance(val, String), "str should always return a string"
            print val._str
開發者ID:cloudshill,項目名稱:pixie,代碼行數:21,代碼來源:target.py

示例7: _defprotocol

def _defprotocol(name, methods):
    from pixie.vm.compiler import NS_VAR
    from pixie.vm.persistent_vector import PersistentVector
    from pixie.vm.symbol import Symbol
    affirm(isinstance(name, Symbol), u"protocol name must be a symbol")
    affirm(isinstance(methods, PersistentVector), u"protocol methods must be a vector of symbols")
    method_list = []
    for i in range(0, rt.count(methods)):
        method_sym = rt.nth(methods, rt.wrap(i))
        affirm(isinstance(method_sym, Symbol), u"protocol methods must be a vector of symbols")
        method_list.append(rt.name(method_sym))

    proto =  Protocol(rt.name(name))
    ns = rt.name(NS_VAR.deref())
    intern_var(ns, rt.name(name)).set_root(proto)
    for method in method_list:
        method = unicode(method)
        poly = PolymorphicFn(method,  proto)
        intern_var(ns, method).set_root(poly)

    return name
開發者ID:discoverfly,項目名稱:pixie,代碼行數:21,代碼來源:stdlib.py

示例8: interpret


#.........這裏部分代碼省略.........
            continue

        if inst == code.POP:
            frame.pop()
            continue

        if inst == code.DEREF_VAR:
            debug_ip = frame.ip
            var = frame.pop()
            if not isinstance(var, code.Var):
                affirm(False, u"Can't deref " + var.type()._name)
            try:
                frame.push(var.deref())
                continue
            except WrappedException as ex:
                dp = frame.debug_points.get(debug_ip - 1, None)
                if dp:
                    ex._ex._trace.append(dp)
                raise


        if inst == code.RECUR:
            argc = frame.get_inst()
            args = frame.pop_n(argc)

            frame = Frame(frame.code_obj, args, frame.self_obj)

            jitdriver.can_enter_jit(bc=frame.bc,
                                  ip=frame.ip,
                                  sp=frame.sp,
                                  base_code=frame.base_code,
                                  frame=frame,
                                  is_continuation=frame._is_continuation)
            continue

        if inst == code.PUSH_SELF:
            frame.push(frame.self_obj)
            continue

        if inst == code.DUP_NTH:
            n = frame.nth(frame.get_inst())
            frame.push(n)
            continue

        if inst == code.POP_UP_N:
            val = frame.pop()
            num = frame.get_inst()
            frame.pop_n(num)
            frame.push(val)
            continue

        if inst == code.LOOP_RECUR:
            argc = frame.get_inst()
            stack_depth = frame.get_inst()
            ip = frame.get_inst()

            args = frame.pop_n(argc)
            frame.pop_n(stack_depth)
            frame.pop_n(argc)
            frame.push_n(args, argc)
            frame.ip = ip


            jitdriver.can_enter_jit(bc=frame.bc,
                                  ip=frame.ip,
                                  sp=frame.sp,
                                  base_code=frame.base_code,
                                  frame=frame,
                                  is_continuation=frame._is_continuation)
            continue

        if inst == code.MAKE_MULTI_ARITY:
            frame.push(make_multi_arity(frame, frame.get_inst()))

            continue

        if inst == code.MAKE_VARIADIC:
            code_object = frame.pop()
            required_arity = frame.get_inst()
            frame.push(code.VariadicCode(code_object, required_arity))

            continue

        if inst == code.YIELD:
            if not frame.is_continuation():
                frame.set_continuation()
                #frame = jit.hint(frame, force_virtualizable=True)
                k = ShallowContinuation(frame, frame.pop())
                return k
            else:
                return frame.pop()

        if inst == code.PUSH_NS:
            from pixie.vm.compiler import NS_VAR
            frame.push(NS_VAR.deref())
            continue


        affirm(False, u"NO DISPATCH FOR: " + unicode(code.BYTECODES[inst]))
        raise Exception()
開發者ID:delonnewman,項目名稱:pixie,代碼行數:101,代碼來源:interpreter.py


注:本文中的pixie.vm.compiler.NS_VAR類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。