本文整理汇总了Python中pycket.interpreter.return_value函数的典型用法代码示例。如果您正苦于以下问题:Python return_value函数的具体用法?Python return_value怎么用?Python return_value使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了return_value函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_is_struct
def do_is_struct(v, env, cont):
from pycket.interpreter import return_value
current_inspector = values_struct.current_inspector_param.get(cont)
if isinstance(v, values_struct.W_RootStruct):
if current_inspector.has_control(v.struct_type()):
return return_value(values.w_true, env, cont)
return return_value(values.w_false, env, cont)
示例2: read_bytes_avail_bang
def read_bytes_avail_bang(w_bstr, w_port, w_start, w_end, env, cont):
# FIXME: discern the available from the non-available form
from pycket.interpreter import return_value
# FIXME: custom ports
if w_bstr.immutable():
raise SchemeException("read-bytes-avail!: given immutable byte string")
if w_port is None:
w_port = current_in_param.get(cont)
start = w_start.value
stop = len(w_bstr.value) if w_end is None else w_end.value
if stop == start:
return return_value(values.W_Fixnum(0), env, cont)
# FIXME: assert something on indices
assert start >= 0 and stop <= len(w_bstr.value)
n = stop - start
res = w_port.read(n)
reslen = len(res)
# shortcut without allocation when complete replace
if start == 0 and stop == len(w_bstr.value) and reslen == n:
w_bstr.value = list(res)
return return_value(values.W_Fixnum(reslen), env, cont)
if reslen == 0:
return return_value(values.eof_object, env, cont)
for i in range(0, reslen):
w_bstr.value[start + i] = res[i]
return return_value(values.W_Fixnum(reslen), env, cont)
示例3: proc_arity_cont
def proc_arity_cont(arity, env, cont, _vals):
from pycket.interpreter import check_one_val, return_value
val = check_one_val(_vals)
if not arity.arity_list:
return return_value(val, env, cont)
result = make_arity_list(arity, val)
return return_value(result, env, cont)
示例4: do_read_one
def do_read_one(w_port, as_bytes, peek, env, cont):
from pycket.interpreter import return_value
if peek:
c = w_port.peek()
else:
c = w_port.read(1)
if len(c) == 0:
return return_value(values.eof_object, env, cont)
i = ord(c[0])
if as_bytes:
return return_value(values.W_Fixnum(i), env, cont)
else:
# hmpf, poking around in internals
needed = runicode.utf8_code_length[i]
if peek:
old = w_port.tell()
c = w_port.read(needed)
w_port.seek(old)
elif needed > 1:
c += w_port.read(needed - 1)
c = c.decode("utf-8")
assert len(c) == 1
return return_value(values.W_Character(c[0]), env, cont)
示例5: datum_to_correlated
def datum_to_correlated(ignored, datum, _srcloc, env, cont):
if isinstance(datum, W_Correlated):
return return_value(datum, env, cont)
else:
from pycket.prims.general import srcloc
srcloc_const = srcloc.constructor
if isinstance(_srcloc, W_Vector):
#unerase = _srcloc.get_strategy().unerase
#vector_contents = unerase(_srcloc.storage)
v_ref = _srcloc.get_strategy().ref
return srcloc_const.call([v_ref(_srcloc, 0),
v_ref(_srcloc, 1),
v_ref(_srcloc, 2),
v_ref(_srcloc, 3),
v_ref(_srcloc, 4)],
env, datum_to_corr_cont(datum, env, cont))
elif isinstance(_srcloc, W_List):
return srcloc_const.call([_srcloc.car(),
_srcloc.cdr().car(),
_srcloc.cdr().cdr().car(),
_srcloc.cdr().cdr().cdr().car(),
_srcloc.cdr().cdr().cdr().cdr().car()],
env, datum_to_corr_cont(datum, env, cont))
elif isinstance(_srcloc, W_Correlated):
raise Exception("FIXME NYI datum->syntax _srcloc is a correlated")
else:
if _srcloc is not w_false:
raise Exception("FIXME, unhandled srcloc type %s" % _srcloc.tostring())
srcloc = _srcloc
return return_value(W_Correlated(datum, srcloc, {}), env, cont)
示例6: write_bytes_avail
def write_bytes_avail(w_bstr, w_port, w_start, w_end, env, cont):
# FIXME: discern the available from the non-available form
from pycket.interpreter import return_value
# FIXME: custom ports
if w_port is None:
w_port = current_out_param.get(cont)
start = w_start.value
stop = len(w_bstr.value) if w_end is None else w_end.value
if start == stop:
w_port.flush()
return return_value(values.W_Fixnum(0), env, cont)
if start == 0 and stop == len(w_bstr.value):
to_write = w_bstr.value
else:
slice_stop = stop - 1
assert start >= 0 and slice_stop < len(w_bstr.value)
assert slice_stop >= 0
to_write = w_bstr.value[start:slice_stop]
# FIXME: we fake here
w_port.write("".join(to_write))
return return_value(values.W_Fixnum(stop - start), env, cont)
示例7: hash_copy
def hash_copy(src, env, cont):
from pycket.interpreter import return_value
new = src.make_empty()
if isinstance(src, W_ImmutableHashTable):
return return_value(new, env, cont)
if src.length() == 0:
return return_value(new, env, cont)
return hash_copy_loop(src.hash_items(), 0, src, new, env, cont)
示例8: hash_ref_cont
def hash_ref_cont(default, env, cont, _vals):
from pycket.interpreter import return_value, check_one_val
val = check_one_val(_vals)
if val is not w_missing:
return return_value(val, env, cont)
if default is None:
raise SchemeException("key not found")
if default.iscallable():
return default.call([], env, cont)
return return_value(default, env, cont)
示例9: arity_to_value
def arity_to_value(arity, env, cont):
from pycket.interpreter import return_value
if arity.at_least != -1:
val = [values.W_Fixnum(arity.at_least)]
constructor = arity_at_least.constructor
return constructor.call(val, env, proc_arity_cont(arity, env, cont))
if len(arity.arity_list) == 1:
item = values.W_Fixnum(arity.arity_list[0])
return return_value(item, env, cont)
result = make_arity_list(arity)
return return_value(result, env, cont)
示例10: hash_for_each_cont
def hash_for_each_cont(f, ht, index, env, cont, _vals):
from pycket.interpreter import return_value
nextindex = index + 1
try:
w_key, w_value = ht.get_item(index)
except KeyError:
return return_value(values.w_void, env,
hash_for_each_cont(f, ht, nextindex, env, cont))
except IndexError:
return return_value(values.w_void, env, cont)
after = hash_for_each_cont(f, ht, nextindex, env, cont)
return f.call([w_key, w_value], env, after)
示例11: do_procedure_arity
def do_procedure_arity(proc, env, cont):
from pycket.interpreter import return_value
result = []
arity = proc.get_arity()
for item in arity.arity_list:
result.append(values.W_Fixnum(item))
if arity.at_least != -1:
val = [values.W_Fixnum(arity.at_least)]
return arity_at_least.constr.call(val, env, proc_arity_cont(result, env, cont))
if len(result) == 1:
return return_value(result[0], env, cont)
return return_value(values.to_list(result[:]), env, cont)
示例12: ormap_cont
def ormap_cont(f, ls, env, cont, vals):
# XXX this is currently not properly jitted
from pycket.interpreter import return_value, check_one_val
val = check_one_val(vals)
if val is values.w_true:
return return_value(val, env, cont)
for l in ls:
if l is values.w_null:
return return_value(values.w_false, env, cont)
cars = [l.car() for l in ls]
cdrs = [l.cdr() for l in ls]
return f.call(cars, env, ormap_cont(f, cdrs, env, cont))
示例13: do_extract_struct_info
def do_extract_struct_info(v, env, cont):
assert is_struct_info(v)
from pycket.interpreter import return_value
if isinstance(v, values.W_Cons):
return return_value(v, env, cont)
elif isinstance(v, values.W_Prim):
return v.call([], env, cont)
else:
# TODO: it can be also:
# 1. a structure with the prop:struct-info property
# 2. a structure type derived from struct:struct-info or
# with prop:struct-info and wrapped with make-set!-transformer
return return_value(values.w_void, env, cont)
示例14: call
def call(self, args, env, cont):
from pycket.interpreter import return_value
if len(args) == 0:
return return_value(self.get(cont), env, cont)
elif len(args) == 1:
cell = find_param_cell(cont, self)
assert isinstance(cell, values.W_ThreadCell)
if self.guard:
return self.guard.call([args[0]], env, param_set_cont(cell, env, cont))
else:
cell.set(args[0])
return return_value(values.w_void, env, cont)
else:
raise SchemeException("wrong number of arguments to parameter")
示例15: call_with_extra_info
def call_with_extra_info(self, arg, fail, env, cont, app):
from pycket.interpreter import return_value
if isinstance(arg, W_StructType):
w_val = arg.read_prop_precise(self.property)
if w_val is not None:
return return_value(w_val, env, cont)
elif arg.struct_type() is not None:
return arg.get_prop(self.property, env, cont)
elif fail is not None:
if fail.iscallable():
return fail.call_with_extra_info([], env, cont, app)
return return_value(fail, env, cont)
raise SchemeException("%s-accessor: expected %s? but got %s" %
(self.property.name, self.property.name, arg.tostring()))