本文整理汇总了Python中pycket.prims.expose.default函数的典型用法代码示例。如果您正苦于以下问题:Python default函数的具体用法?Python default怎么用?Python default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: make_callable_label
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from pycket import impersonators as imp
from pycket import values
from pycket import vector
from pycket.cont import call_cont, Cont
from pycket.error import SchemeException
from pycket.prims.expose import default, expose, make_callable_label, procedure
# Can use this to promote a get_cmk operation to a callable function.
CMKSetToListHandler = make_callable_label([values.W_Object])
@expose("current-continuation-marks",
[default(values.W_ContinuationPromptTag, values.w_default_continuation_prompt_tag)],
simple=False)
def current_cont_marks(prompt_tag, env, cont):
from pycket.interpreter import return_value
return return_value(values.W_ContinuationMarkSet(cont, prompt_tag), env, cont)
@expose("continuation-marks",
[values.W_Continuation,
default(values.W_ContinuationPromptTag, values.w_default_continuation_prompt_tag)])
def continuation_marks(cont, prompt_tag):
# TODO Prompt tag
return values.W_ContinuationMarkSet(cont.cont, prompt_tag)
@expose("continuation-mark-set->list",
[values.W_ContinuationMarkSet, values.W_Object,
default(values.W_ContinuationPromptTag, None)],
simple=False)
开发者ID:pycket,项目名称:pycket,代码行数:31,代码来源:continuation_marks.py
示例2: default
topic = values.w_false
parent = values.w_false
propagate_level = DEBUG
try:
topic = parser.symbol_or_false()
parent = parser.logger_or_false()
propagate_level = parser.log_level()
except EndOfInput:
pass
# Any remaining arguments are propagate topics
propagate_topic = parser._symbol_or_false()
return values.W_Logger(topic, parent, propagate_level, propagate_topic)
@expose("log-level?", [values.W_Object, values.W_Object, default(values.W_Object, values.w_false)])
def log_level(logger, level, topic):
# TODO: Actual implementation
return values.w_false
@expose("log-message", arity=Arity.oneof(4, 5, 6))
def log_message(args):
# TODO: Actual implementation
return
w_current_logger = values_parameter.W_Parameter(w_default_logger)
expose_val("current-logger", w_current_logger)
开发者ID:rjnw,项目名称:pycket,代码行数:28,代码来源:logging.py
示例3: make_pred
return linkl, config
"""
(define-values (1/read-compiled-linklet) (hash-ref linklet-primitive-table 'read-compiled-linklet #f))
(define-values (1/instance-unset-variable!) (hash-ref linklet-primitive-table 'instance-unset-variable! #f))
(define-values (1/variable-reference?) (hash-ref linklet-primitive-table 'variable-reference? #f))
(define-values (1/variable-reference-constant?) (hash-ref linklet-primitive-table 'variable-reference-constant? #f))
"""
make_pred("linklet?", W_Linklet)
make_pred("instance?", W_LinkletInstance)
@expose("compile-linklet", [W_Object, default(W_Object, w_false), default(W_Object, w_false), default(W_Object, w_false), default(W_Object, w_false)], simple=False)
def compile_linklet(form, name, import_keys, get_import, options, env, cont):
from pycket.util import console_log
console_log("compiling linklet : %s %s\n import_keys : %s -- get_import : %s" % (name.tostring(), form.tostring(), import_keys.tostring(), get_import.tostring()), 5)
with PerfRegionCPS("compile-linklet"):
cont_ = finish_perf_region_cont("compile-linklet", env, cont)
return do_compile_linklet(form, name, import_keys, get_import, options, env, cont_)
def do_compile_linklet(form, name, import_keys, get_import, options, env, cont):
from pycket.util import console_log
if isinstance(form, W_WrappedConsProper): # s-expr
# read it and create an AST, put it in a W_Linklet and return
if not isinstance(form.car(), W_Symbol) or "linklet" != form.car().tostring():
raise SchemeException("Malformed s-expr. Expected a linklet, got %s" % form.tostring())
else:
w_name = W_Symbol.make("ad-hoc") if name is w_false else name
开发者ID:pycket,项目名称:pycket,代码行数:30,代码来源:linklet.py
示例4: vector
from pycket.prims.expose import unsafe, default, expose, subclass_unsafe
@expose("vector")
def vector(args):
return values_vector.W_Vector.fromelements(args)
@expose("flvector")
def flvector(args):
return values_vector.W_FlVector.fromelements(args)
# FIXME: immutable
@expose("vector-immutable")
def vector_immutable(args):
return values_vector.W_Vector.fromelements(args, immutable=True)
@expose("make-vector", [values.W_Fixnum, default(values.W_Object, values.W_Fixnum(0))])
def make_vector(w_size, w_val):
size = w_size.value
if size < 0:
raise SchemeException("make-vector: expected a positive fixnum")
return values_vector.W_Vector.fromelement(w_val, size)
@expose("make-flvector", [values.W_Fixnum, default(values.W_Flonum, values.W_Flonum(0.0))])
def make_vector(w_size, w_val):
size = w_size.value
if size < 0:
raise SchemeException("make-flvector: expected a positive fixnum")
return values_vector.W_FlVector.fromelement(w_val, size)
@expose("vector-length", [values_vector.W_MVector])
def vector_length(v):
开发者ID:rrnewton,项目名称:pycket,代码行数:31,代码来源:vector.py
示例5: SchemeException
raise SchemeException("make-ctype: expected (or/c #f procedure) in argument 2 got %s" %
ctr.tostring())
return W_DerivedCType(ctype, rtc, ctr)
def validate_alignment(ctx, arg, align):
if align is values.w_false:
return -1
if isinstance(align, values.W_Fixnum) and align.value in (1, 2, 4, 8, 16):
return align.value
msg = ("%s: expected (or/c #f 1 2 4 8 16) in argument %d got %s" %
(ctx, arg, align.tostring()))
raise SchemeException(msg)
@expose("make-cstruct-type",
[values.W_List,
default(values.W_Object, values.w_false),
default(values.W_Object, values.w_false)])
def make_cstruct_type(types, abi, _alignment):
alignment = validate_alignment("make-cstruct-type", 2, _alignment)
if types.is_proper_list():
types_list = []
for ctype in values.from_list_iter(types):
if not isinstance(ctype, W_CType):
break
types_list.append(ctype)
else:
return W_CStructType(types_list[:], abi, alignment)
msg = "make-cstruct-type: expected (listof ctype?) in argument 0 got %s" % types.tostring()
raise SchemeException(msg)
开发者ID:pycket,项目名称:pycket,代码行数:31,代码来源:foreign.py
示例6: receive_first_field
receive_first_field(proc, v, v1, v2, env, cont))
return proc.call([v, v1, v2], env, cont)
################################################################
# printing
@expose("current-logger", [])
def current_logger():
return values.current_logger
@expose("make-logger", [values.W_Symbol, values.W_Logger])
def make_logger(name, parent):
return values.W_Logger()
@expose("make-parameter",
[values.W_Object, default(values.W_Object, values.w_false)])
def make_parameter(init, guard):
return values.W_Parameter(init, guard)
@expose("system-library-subpath", [default(values.W_Object, values.w_false)])
def sys_lib_subpath(mode):
return values.W_Path("x86_64-linux") # FIXME
@expose("primitive-closure?", [values.W_Object])
def prim_clos(v):
return values.w_false
################################################################
# built-in struct types
def define_struct(name, super=values.w_null, fields=[]):
开发者ID:antongulenko,项目名称:pycket,代码行数:31,代码来源:general.py
示例7: default
from pycket import values
from pycket import values_parameter
from pycket.argument_parser import ArgParser, EndOfInput
from pycket.arity import Arity
from pycket.base import W_Object
from pycket.error import SchemeException
from pycket.prims.expose import expose, expose_val, default, procedure
@expose("make-parameter",
[values.W_Object, default(values.W_Object, values.w_false)])
def make_parameter(init, guard):
return values_parameter.W_Parameter(init, guard)
@expose("make-derived-parameter",
[values_parameter.W_BaseParameter, procedure, procedure])
def make_derived_parameter(param, guard, wrap):
return values_parameter.W_DerivedParameter(param, guard, wrap)
@expose("extend-parameterization", arity=Arity.geq(1))
def scheme_extend_parameterization(args):
if len(args) == 0:
raise SchemeException("extend-parameterization: expected 1 or more arguments")
config = args[0]
argc = len(args)
if argc < 2 or not isinstance(config, values_parameter.W_Parameterization) or argc % 2 != 1:
return config
parser = ArgParser("extend-parameterization", args, start_at=1)
开发者ID:uternet,项目名称:pycket,代码行数:30,代码来源:parameter.py
示例8: flrandom
@expose(["flrandom", "unsafe-flrandom"], [values.W_PseudoRandomGenerator])
def flrandom(gen):
return values.W_Flonum(rng.random())
@expose("random-seed", [values.W_Fixnum])
def random_seed(seed):
key = [rarithmetic.r_uint(seed.value)]
rng.init_by_array(key)
return values.w_void
@expose("make-pseudo-random-generator", [])
def make_pseudo_random_generator():
return values.W_PseudoRandomGenerator()
current_pseudo_random_generator = values_parameter.W_Parameter(values.W_PseudoRandomGenerator())
expose_val("current-pseudo-random-generator", current_pseudo_random_generator)
@expose("pseudo-random-generator->vector", [values.W_PseudoRandomGenerator])
def pseudo_random_generator_to_vector(gen):
return values_vector.W_Vector.fromelements([])
@expose("vector->pseudo-random-generator", [values.W_PseudoRandomGenerator, default(values.W_MVector, None)])
def vector_to_pseudo_random_generator(gen, vec):
return values.W_PseudoRandomGenerator()
@expose("pseudo-random-generator-vector?", [values.W_Object])
def pseudo_random_generator_vector_huh(vec):
return values.W_Bool.make(isinstance(vec, values.W_MVector) and vec.length() == 0)
开发者ID:8l,项目名称:pycket,代码行数:28,代码来源:random.py
示例9: unsafe_unbox
@expose("unsafe-unbox", [subclass_unsafe(values.W_Box)], simple=False)
def unsafe_unbox(b, env, cont):
return b.unbox(env, cont)
@expose("set-box!", [values.W_Box, values.W_Object], simple=False)
def set_box(box, v, env, cont):
return box.set_box(v, env, cont)
@expose("unsafe-set-box!", [subclass_unsafe(values.W_Box), values.W_Object], simple=False)
def unsafe_set_box(box, v, env, cont):
return box.set_box(v, env, cont)
# This implementation makes no guarantees about atomicity
@expose("box-cas!", [values.W_MBox, values.W_Object, values.W_Object])
def box_cas(box, old, new):
if eq_prims.eqp_logic(box.value, old):
box.value = new
return values.w_true
return values.w_false
@expose("make-weak-box", [values.W_Object])
def make_weak_box(val):
return values.W_WeakBox(val)
@expose("weak-box-value",
[values.W_WeakBox, default(values.W_Object, values.w_false)])
def weak_box_value(wb, default):
v = wb.get()
return v if v is not None else default
开发者ID:8l,项目名称:pycket,代码行数:29,代码来源:box.py
示例10: correlated_to_datum
else:
return e
# [core:correlated->datum syntax->datum]
@expose("syntax->datum", [W_Object])
def correlated_to_datum(e):
return correlated_to_datum_inner(e)
@continuation
def datum_to_corr_cont(datum, env, cont, _vals):
srcloc_object = check_one_val(_vals)
return return_value(W_Correlated(datum, srcloc_object, {}), env, cont)
# [core:datum->correlated datum->syntax]
@expose("datum->syntax", [W_Object, W_Object, default(W_Object, w_false)], simple=False)
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),
开发者ID:pycket,项目名称:pycket,代码行数:31,代码来源:correlated.py
示例11: syntax_tainted
def syntax_tainted(v):
return values.w_false
@expose("syntax->datum", [values.W_Syntax])
def syntax_to_datum(stx):
return stx.val
@expose("syntax-e", [values.W_Syntax])
def syntax_e(stx):
# XXX Obviously not correct
print "NOT YET IMPLEMENTED: syntax-e"
return stx.val
# FIXME: not implemented
@expose("datum->syntax", [values.W_Object, values.W_Object,
default(values.W_Object, None), default(values.W_Object, None),
default(values.W_Object, None)])
def datum_to_syntax(ctxt, v, srcloc, prop, ignored):
print "NOT YET IMPLEMENTED: datum->syntax"
assert isinstance(ctxt, values.W_Syntax) or ctxt is values.w_false
return values.W_Syntax(v)
@expose("syntax-source", [values.W_Syntax])
def syntax_source(stx):
# XXX Obviously not correct
return values.w_false
@expose("syntax-source-module", [values.W_Syntax, default(values.W_Object, values.w_false)])
def syntax_source_module(stx, src):
# XXX Obviously not correct
return values.W_ResolvedModulePath(values.W_Symbol.make("fake symbol"))
开发者ID:vishesh,项目名称:pycket,代码行数:31,代码来源:general.py
示例12: make_fixedtype_cmps
("<=", "le"),
(">", "gt"),
(">=", "ge"),
("=", "eq"),
]:
make_fixedtype_cmps(*args)
@expose("unsafe-flsqrt", [unsafe(values.W_Flonum)])
def flsqrt(f):
return f.arith_sqrt()
@expose("add1", [values.W_Number])
def add1(v):
return v.arith_add(values.W_Fixnum(1))
@expose("atan", [values.W_Number, default(values.W_Number, None)])
def atan(y, x):
if x is not None:
# FIXME: signs determine the quadrant of the result
# and care about NaNs and precision
if x.arith_zerop() is values.w_false:
z = y.arith_div(x)
else:
# we should raise exn_fail_contract_divide_by_zero
raise SchemeException("zero_divisor")
else:
z = y
return getattr(z, "arith_atan")()
def make_unary_arith(name, methname, flversion=False, fxversion=False, unwrap_type=values.W_Number):
开发者ID:antongulenko,项目名称:pycket,代码行数:31,代码来源:numeric.py
示例13: remove_handle
def remove_handle(self, handle):
if handle in self.callbacks:
del(self.callbacks[handle])
if handle in self.weak_callbacks:
del(self.weak_callbacks[handle])
current_plumber_param = values_parameter.W_Parameter(W_Plumber())
expose_val("current-plumber", current_plumber_param)
@expose("make-plumber", [])
def make_plumber():
return W_Plumber()
@expose("plumber-add-flush!", [W_Plumber, procedure, default(values.W_Bool, values.w_false)])
def plumber_add_flush_bang(p, proc, is_weak):
# create a new handle
h = W_PlumberFlushHandle(p)
# put the new handle into p's callbacks with the given proc
if is_weak is values.w_true:
p.set_weak_callback(h, proc)
else:
p.set_callback(h, proc)
return h
@continuation
def plumber_flush_loop_cont(handlers_callbacks, index, env, cont, _vals):
开发者ID:pycket,项目名称:pycket,代码行数:30,代码来源:plumber.py
示例14: reversed
for start, end in reversed(lst):
s = values.W_Fixnum(start)
e = values.W_Fixnum(end)
elem = values.W_Cons.make(s, e)
acc = values.W_Cons.make(elem, acc)
return acc, end
EMPTY_BYTES = values.W_Bytes.from_string("")
NO_MATCH = values.Values.make([values.w_false, values.w_false])
ZERO = values.W_Fixnum.make(0)
ONE = values.W_Fixnum.make(1)
RMP_ARGS = [
values.W_Object,
values.W_Object,
default(values.W_Fixnum, ZERO),
default(values.W_Object, values.w_false),
default(values.W_Object, values.w_false),
default(values.W_Bytes, EMPTY_BYTES)]
@expose("regexp-match-positions", RMP_ARGS)
@jit.unroll_safe
def rmp(pat, input, 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-positions: expected fixnum or #f for argument 3")
assert output_port is values.w_false, "output port not supported yet"
开发者ID:krono,项目名称:pycket,代码行数:31,代码来源:regexp.py
示例15: SchemeException
pass
else:
raise SchemeException("regexp-match: unknown kind of regexp")
if isinstance(w_str, values_string.W_String):
s = w_str.as_str_ascii() # XXX for now
result = w_re.match_string(s)
return result
if isinstance(w_str, values.W_Bytes):
result = w_re.match_string(w_str.as_str())
return result
if isinstance(w_str, values.W_InputPort):
result = w_re.match_port(w_str)
return result
raise SchemeException("regexp-match: can't deal with this type")
@expose("regexp-match?", [values.W_Object, values.W_Object])
def regexp_matchp(w_r, w_o):
result = match(w_r, w_o)
if result:
return values.w_true
else:
return values.w_false
# FIXME: implementation
define_nyi("regexp-replace", [values.W_Object, values.W_Object, values.W_Object,
default(values.W_Bytes, None)])
# def regexp_replace(pattern, input, insert, input_prefix):
# raise NotImplementedError()
# return input
开发者ID:rrnewton,项目名称:pycket,代码行数:30,代码来源:regexp.py
示例16: default
from pycket import values
from pycket import values_parameter
from pycket.argument_parser import ArgParser, EndOfInput
from pycket.arity import Arity
from pycket.base import W_Object
from pycket.error import SchemeException
from pycket.prims.expose import expose, expose_val, default, procedure
from rpython.rlib import jit
@expose("make-parameter", [values.W_Object, default(values.W_Object, values.w_false)])
def make_parameter(init, guard):
return values_parameter.W_Parameter(init, guard)
@expose("make-derived-parameter", [values_parameter.W_BaseParameter, procedure, procedure])
def make_derived_parameter(param, guard, wrap):
return values_parameter.W_DerivedParameter(param, guard, wrap)
@expose("extend-parameterization", arity=Arity.geq(1))
@jit.unroll_safe
def scheme_extend_parameterization(args):
if len(args) == 0:
raise SchemeException("extend-parameterization: expected 1 or more arguments")
config = args[0]
argc = len(args)
if argc < 2 or not isinstance(config, values_parameter.W_Parameterization) or argc % 2 != 1:
return config
开发者ID:vishesh,项目名称:pycket,代码行数:31,代码来源:parameter.py
示例17: make_fixedtype_cmps
("<=", "le"),
(">", "gt"),
(">=", "ge"),
("=", "eq"),
]:
make_fixedtype_cmps(*args)
@expose("unsafe-flsqrt", [unsafe(values.W_Flonum)])
def flsqrt(f):
return f.arith_sqrt()
@expose("add1", [values.W_Number])
def add1(v):
return v.arith_add(values.W_Fixnum.ONE)
@expose("atan", [values.W_Number, default(values.W_Number, None)])
def atan(y, x):
if x is not None:
# FIXME: signs determine the quadrant of the result
# and care about NaNs and precision
if x.arith_zerop() is values.w_false:
z = y.arith_div(x)
else:
# we should raise exn_fail_contract_divide_by_zero
raise SchemeException("zero_divisor")
else:
z = y
return getattr(z, "arith_atan")()
def make_unary_arith(name, methname, flversion=False, fxversion=False,
开发者ID:pycket,项目名称:pycket,代码行数:31,代码来源:numeric.py
示例18: default
from rpython.rlib.rstring import ParseStringError, ParseStringOverflowError
try:
s = w_s.as_str_utf8()
if "." in s:
return values.W_Flonum(rfloat.string_to_float(s))
else:
try:
return values.W_Fixnum(rarithmetic.string_to_int(s, base=0))
except ParseStringOverflowError:
return values.W_Bignum(rbigint.rbigint.fromstr(s))
except ParseStringError as e:
return values.w_false
@expose("number->string",
[values.W_Number, default(values.W_Fixnum, values.W_Fixnum(10))])
def num2str(a, radix):
from rpython.rlib.rbigint import BASE8, BASE16
if radix.value == 10:
return W_String.fromascii(a.tostring())
else:
if isinstance(a, values.W_Fixnum):
if radix.value == 16:
res = hex(a.value)
if a.value >= 0:
res = res[2:]
else:
res = "-" + res[3:]
return W_String.fromascii(res)
#elif radix.value == 8:
# return W_String.fromascii(oct(a.value))
开发者ID:8l,项目名称:pycket,代码行数:31,代码来源:string.py
示例19: BooleanToken
if c2 == "t":
return BooleanToken(values.w_true)
if c2 == "f":
return BooleanToken(values.w_false)
if c2 in ["(", "[", "{"]:
return LParenToken("#" + c2)
if c2 == "\\":
s = f.read(1)
if not s:
raise SchemeException("unexpected end of file")
c = ord(s[0]) # XXX deal with unicode
return CharToken(values.W_Character.make(unichr(c)))
raise SchemeException("bad token in read: %s" % c2)
raise SchemeException("bad token in read: %s" % c)
@expose("read", [default(values.W_InputPort, None)], simple=False)
def read(port, env, cont):
from pycket.interpreter import return_value
if port is None:
port = current_in_param.get(cont)
v = read_stream(port)
return return_value(v, env, cont)
def read_stream(stream):
next_token = read_token(stream)
if isinstance(next_token, SpecialToken):
v = read_stream(stream)
return next_token.finish(v)
if isinstance(next_token, DelimToken):
if not isinstance(next_token, LParenToken):
raise SchemeException("read: unexpected %s"%next_token.str)
开发者ID:krono,项目名称:pycket,代码行数:31,代码来源:input_output.py
示例20: expose_val
expose_val("_int16" , values.W_Fixnum.make(1))
expose_val("_int32" , values.W_Fixnum.make(2))
expose_val("_int64" , values.W_Fixnum.make(3))
expose_val("_uint8" , values.W_Fixnum.make(4))
expose_val("_uint16" , values.W_Fixnum.make(5))
expose_val("_uint32" , values.W_Fixnum.make(6))
expose_val("_uint64" , values.W_Fixnum.make(7))
expose_val("_bytes" , values.W_Fixnum.make(8))
expose_val("_path" , values.W_Fixnum.make(9))
expose_val("_void" , values.W_Fixnum.make(10))
expose_val("_pointer" , values.W_Fixnum.make(11))
expose_val("_fpointer" , values.W_Fixnum.make(12))
ctype = values.W_Fixnum
@expose("make-ctype", [ctype, default(values.W_Object, values.w_false), default(values.W_Object, values.w_false)])
def make_c_type(typ, rtc, ctr):
return values.W_Fixnum(0)
@expose("compiler-sizeof", [values.W_Object])
def compiler_sizeof(sym):
return values.W_Fixnum(8)
@expose("make-stubborn-will-executor", [])
def make_stub_will_executor():
return values.w_false
@expose("ctype-sizeof", [ctype])
def ctype_sizeof(c):
return values.W_Fixnum(8)
开发者ID:krono,项目名称:pycket,代码行数:30,代码来源:foreign.py
注:本文中的pycket.prims.expose.default函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论