本文整理汇总了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)
示例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)))
示例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
示例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
示例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))
示例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
示例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
示例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()