本文整理汇总了Python中pycket.values.to_list函数的典型用法代码示例。如果您正苦于以下问题:Python to_list函数的具体用法?Python to_list怎么用?Python to_list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了to_list函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: regexp_match
def regexp_match(w_re, w_str, inp_start, inp_end, output_port, prefix):
start = inp_start.value
if inp_end is values.w_false:
end = sys.maxint
elif isinstance(inp_end, values.W_Fixnum):
end = inp_end.value
else:
raise SchemeException("regexp-match: expected fixnum or #f for argument 3")
assert output_port is values.w_false, "output port not supported yet"
result = match(w_re, w_str, start, end)
if result is None:
return values.w_false
elif (isinstance(w_str, values_string.W_String) or \
isinstance(w_str, values.W_StringInputPort)) \
and \
(isinstance(w_re, values_regex.W_PRegexp) or \
isinstance(w_re, values_regex.W_Regexp) or \
isinstance(w_re, values_string.W_String)):
return values.to_list([values_string.W_String.fromstr_utf8(r)
if r else values.w_false
for r in result])
else:
return values.to_list([values.W_Bytes.from_string(r)
if r else values.w_false
for r in result])
示例2: cms_context
def cms_context(marks):
from pycket.values_string import W_String
# TODO: Pycket does not have a mark to denote context. We need to fix that.
k = marks.cont
n = 0
# find out the length
while isinstance(k, Cont):
if is_ast_cont_with_surrounding_lambda(k):
n += 1
k = k.get_previous_continuation()
# second traversal saves us from reversing it later
ls = [None]*n
k = marks.cont
i = n-1
while isinstance(k, Cont):
if is_ast_cont_with_surrounding_lambda(k):
surrounding_lam = k.get_ast().surrounding_lambda
lam_str = W_String.make(surrounding_lam.tostring())
ls[i] = values.W_Cons.make(lam_str, values.w_false)
i -= 1
k = k.get_previous_continuation()
return values.to_list(ls)
示例3: attach_prop
def attach_prop(self, props, idx, is_checked, env, cont):
from pycket.interpreter import return_multi_vals
if idx < len(props):
(prop, prop_val, sub_prop) = props[idx]
if sub_prop is not None:
for p in props:
if p[0] is sub_prop:
return prop_val.call([p[1]], env,
self.save_prop_value(props, idx, False, env, cont))
assert isinstance(prop, W_StructProperty)
if not is_checked and prop.guard.iscallable():
return prop.guard.call([prop_val, values.to_list(self.struct_type_info())],
env, self.save_prop_value(props, idx, True, env, cont))
if prop.isinstance(w_prop_procedure):
self.prop_procedure = prop_val
self.props.append((prop, prop_val))
return self.attach_prop(props, idx + 1, False, env, cont)
# at this point all properties are saved, next step is to copy
# propertyes from super types
struct_type = self.super
while isinstance(struct_type, W_StructType):
self.props = self.props + struct_type.props
if not self.prop_procedure and struct_type.prop_procedure:
self.prop_procedure = struct_type.prop_procedure
self.procedure_source = struct_type.procedure_source
struct_type = struct_type.super
struct_tuple = self.make_struct_tuple()
return return_multi_vals(values.Values.make(struct_tuple), env, cont)
示例4: regexp_match
def regexp_match(w_re, w_str):
result = match(w_re, w_str)
if result is None:
return values.w_false
elif (isinstance(w_str, values_string.W_String) or \
isinstance(w_str, values.W_StringInputPort)) \
and \
(isinstance(w_re, values_regex.W_PRegexp) or \
isinstance(w_re, values_regex.W_Regexp) or \
isinstance(w_re, values_string.W_String)):
return values.to_list([values_string.W_String.fromascii(r)
if r else values.w_false
for r in result])
else:
return values.to_list([values.W_Bytes.from_string(r)
if r else values.w_false
for r in result])
示例5: time_apply_cont
def time_apply_cont(initial, env, cont, vals):
from pycket.interpreter import return_multi_vals
final = time.clock()
ms = values.W_Fixnum(int((final - initial) * 1000))
vals_l = vals._get_full_list()
results = values.Values.make([values.to_list(vals_l),
ms, ms, values.W_Fixnum(0)])
return return_multi_vals(results, env, cont)
示例6: rmp
def rmp(pat, input):
matches = match_positions(pat, input)
xs = []
for start, end in matches:
s = values.W_Fixnum(start)
e = values.W_Fixnum(end)
xs.append(values.W_Cons.make(s, e))
return values.to_list(xs)
示例7: to_value
def to_value(json):
dbgprint("to_value", json)
if json is pycket_json.json_false:
return values.w_false
elif json is pycket_json.json_true:
return values.w_true
if json.is_object:
# The json-object should only contain one element
obj = json.value_object()
if "vector" in obj:
return vector.W_Vector.fromelements([to_value(v) for v in obj["vector"].value_array()], immutable=True)
if "struct" in obj:
key = to_value(obj["prefab-key"])
fields = [to_value(v) for v in obj["struct"].value_array()]
return values_struct.W_Struct.make_prefab(key, fields)
if "box" in obj:
return values.W_IBox(to_value(obj["box"]))
if "number" in obj:
return _to_num(obj["number"])
if "path" in obj:
return values.W_Path(obj["path"].value_string())
if "char" in obj:
return values.W_Character.make(unichr(int(obj["char"].value_string())))
if "hash-keys" in obj and "hash-vals" in obj:
return W_EqualHashTable(
[to_value(i) for i in obj["hash-keys"].value_array()],
[to_value(i) for i in obj["hash-vals"].value_array()],
immutable=True)
if "regexp" in obj:
return values_regex.W_Regexp(obj["regexp"].value_string())
if "byte-regexp" in obj:
arr = decode_byte_array(obj["byte-regexp"])
return values_regex.W_ByteRegexp("".join(arr))
if "pregexp" in obj:
return values_regex.W_PRegexp(obj["pregexp"].value_string())
if "byte-pregexp" in obj:
arr = decode_byte_array(obj["byte-pregexp"])
return values_regex.W_BytePRegexp("".join(arr))
if "bytes" in obj:
arr = decode_byte_array(obj["bytes"])
return values.W_ImmutableBytes(arr)
if "string" in obj:
return values_string.W_String.make(str(obj["string"].value_string()))
if "keyword" in obj:
return values.W_Keyword.make(str(obj["keyword"].value_string()))
if "improper" in obj:
improper = obj["improper"].value_array()
return values.to_improper([to_value(v) for v in improper[0].value_array()], to_value(improper[1]))
if "void" in obj:
return values.w_void
for i in ["lexical", "module", "source-name", "toplevel"]:
if i in obj:
return values.W_Symbol.make(obj[i].value_string())
if json.is_array:
return values.to_list([to_value(j) for j in json.value_array()])
assert 0, "Unexpected json value: %s" % json.tostring()
示例8: list_tail
def list_tail(lst, pos):
start_pos = pos.value
if start_pos == 0:
return lst
else:
if isinstance(lst, values.W_Cons):
assert start_pos > 0
return values.to_list(values.from_list(lst)[start_pos:])
else:
return values.w_null
示例9: do_procedure_arity
def do_procedure_arity(proc):
result = []
(ls, at_least) = proc.get_arity()
for item in ls:
result.append(values.W_Fixnum(item))
if at_least != -1:
result.append(values_struct.W_Struct.make([values.W_Fixnum(at_least)],\
arity_at_least))
if len(result) == 1:
return result[0]
return values.to_list(result[:])
示例10: 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)
示例11: struct_type_info
def struct_type_info(self):
name = values.W_Symbol.make(self.name)
init_field_cnt = values.W_Fixnum(self.init_field_cnt)
auto_field_cnt = values.W_Fixnum(self.auto_field_cnt)
immutable_k_list = values.to_list([values.W_Fixnum(i) for i in self.immutables])
# TODO: value of the super variable should be a structure type descriptor
# for the most specific ancestor of the type that is controlled by the current inspector,
# or #f if no ancestor is controlled by the current inspector
super = self.super
# TODO: #f if the seventh result is the most specific ancestor type or
# if the type has no supertype, #t otherwise
skipped = values.w_false
return [name, init_field_cnt, auto_field_cnt, self.acc, self.mut,
immutable_k_list, super, skipped]
示例12: key
def key(self):
key = []
key.append(values.W_Symbol.make(self.name))
key.append(values.W_Fixnum.make(self.init_field_cnt))
if self.auto_field_cnt > 0:
key.append(values.to_list(
[values.W_Fixnum.make(self.auto_field_cnt), self.auto_v]))
mutables = []
for i in self.mutables:
mutables.append(values.W_Fixnum.make(i))
if mutables:
key.append(values_vector.W_Vector.fromelements(mutables))
if self.super_key:
key.extend(self.super_key.key())
return key
示例13: from_raw_key
def from_raw_key(w_key, total_field_cnt=0):
init_field_cnt = -1
auto_field_cnt = 0
auto_v = values.w_false
super_key = None
mutables = []
if isinstance(w_key, values.W_Symbol):
name = w_key.utf8value
init_field_cnt = total_field_cnt
else:
key = values.from_list(w_key)
w_name = key[0]
assert isinstance(w_name, values.W_Symbol)
name = w_name.utf8value
idx = 1
w_init_field_cnt = key[idx]
if isinstance(w_init_field_cnt, values.W_Fixnum):
init_field_cnt = w_init_field_cnt.value
idx += 1
if len(key) > idx:
w_auto = key[idx]
if isinstance(w_auto, values.W_Cons):
auto = values.from_list(w_auto)
w_auto_field_cnt = auto[0]
assert isinstance(w_auto_field_cnt, values.W_Fixnum)
auto_field_cnt = w_auto_field_cnt.value
auto_v = auto[1]
idx += 1
if len(key) > idx:
v = key[idx]
if isinstance(v, values_vector.W_Vector):
for i in range(v.len):
mutable = v.ref(i)
assert isinstance(mutable, values.W_Fixnum)
mutables.append(mutable.value)
idx += 1
if len(key) > idx:
w_super_key = values.to_list(key[idx:])
super_key = W_PrefabKey.from_raw_key(w_super_key)
if init_field_cnt == -1:
init_field_cnt = total_field_cnt
s_key = super_key
while s_key:
super_name, super_init_field_cnt, super_auto_field_cnt,\
super_auto_v, super_mutables, s_key = s_key.make_key_tuple()
init_field_cnt -= super_init_field_cnt
return W_PrefabKey.make(name, init_field_cnt, auto_field_cnt, auto_v,
mutables, super_key)
示例14: struct_type_info
def struct_type_info(self):
name = values.W_Symbol.make(self.name)
init_field_cnt = values.W_Fixnum.make(self.init_field_cnt)
auto_field_cnt = values.W_Fixnum.make(self.auto_field_cnt)
immutable_k_list = values.to_list(
[values.W_Fixnum.make(i) for i in self.immutables])
super = values.w_false
typ = self.super
while isinstance(typ, W_StructType):
if current_inspector.has_control(typ):
super = typ
typ = typ.super
skipped = values.W_Bool.make(super is values.w_false and
isinstance(self.super, W_StructType))
return [name, init_field_cnt, auto_field_cnt, self.accessor,
self.mutator, immutable_k_list, super, skipped]
示例15: make_prefab
def make_prefab(prefab_key):
if prefab_key in W_StructType.unbound_prefab_types:
w_struct_type = W_StructType.unbound_prefab_types[prefab_key]
else:
name, init_field_cnt, auto_field_cnt, auto_v, mutables, super_key =\
prefab_key.make_key_tuple()
super_type = W_StructType.make_prefab(super_key) if super_key else\
values.w_false
immutables = []
for i in range(init_field_cnt):
if i not in mutables:
immutables.append(values.W_Fixnum.make(i))
w_struct_type = W_StructType.make_simple(values.W_Symbol.make(name),
super_type, values.W_Fixnum.make(init_field_cnt),
values.W_Fixnum.make(auto_field_cnt), auto_v, values.w_null,
PREFAB, values.w_false, values.to_list(immutables))
W_StructType.unbound_prefab_types[prefab_key] = w_struct_type
return w_struct_type