def define_struct(name, super=values.w_null, fields=[]): struct_type, struct_constr, struct_pred, struct_acc, struct_mut = \ values_struct.W_StructType.make_simple(values.W_Symbol.make(name), super, values.W_Fixnum(len(fields)), values.W_Fixnum(0), values.w_false, values.w_null, values.w_false).make_struct_tuple() expose_val("struct:" + name, struct_type) expose_val(name, struct_constr) # this is almost always also provided expose_val("make-" + name, struct_constr) expose_val(name + "?", struct_pred) for field, field_name in enumerate(fields): w_num = values.W_Fixnum(field) w_name = values.W_Symbol.make(field_name) acc = values_struct.W_StructFieldAccessor(struct_acc, w_num, w_name) expose_val(name + "-" + field_name, acc) return struct_type
def define_struct(name, super=values.w_null, fields=[]): immutables = range(len(fields)) symname = values.W_Symbol.make(name) struct_type, struct_constr, struct_pred, struct_acc, struct_mut = \ values_struct.W_StructType.make_simple( symname, super, len(fields), 0, values.w_false, values.w_null, values.w_false, values.w_false, immutables).make_struct_tuple() expose_val("struct:" + name, struct_type) expose_val(name, struct_constr) # this is almost always also provided expose_val("make-" + name, struct_constr) expose_val(name + "?", struct_pred) for field, field_name in enumerate(fields): w_num = field w_name = values.W_Symbol.make(field_name) acc = values_struct.W_StructFieldAccessor(struct_acc, w_num, w_name) expose_val(name + "-" + field_name, acc) return struct_type
def define_struct(name, super=values.w_null, fields=[]): immutables = [] for i in range(len(fields)): immutables.append(values.W_Fixnum(i)) struct_type, struct_constr, struct_pred, struct_acc, struct_mut = \ values_struct.W_StructType.make_simple(values.W_Symbol.make(name), super, values.W_Fixnum(len(fields)), values.W_Fixnum(0), values.w_false, values.w_null, values.w_false, values.w_false, values.to_list(immutables)).make_struct_tuple() expose_val("struct:" + name, struct_type) expose_val(name, struct_constr) # this is almost always also provided expose_val("make-" + name, struct_constr) expose_val(name + "?", struct_pred) for field, field_name in enumerate(fields): w_num = values.W_Fixnum(field) w_name = values.W_Symbol.make(field_name) acc = values_struct.W_StructFieldAccessor(struct_acc, w_num, w_name) expose_val(name + "-" + field_name, acc) return struct_type
def set_callback(self, h, proc): self.callbacks[h] = proc def set_weak_callback(self, h, proc): self.weak_callbacks[h] = proc 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)
handler = args[0] args = [] if frames: cont = call_handler_cont(handler, args, env, cont) return unwind_frames(frames, env, cont) return handler.call(args, env, cont) expose("abort-current-continuation", simple=False)(abort_current_continuation) @make_procedure("default-error-escape-handler", [], simple=False) def default_error_escape_handler(env, cont): from pycket.prims.general import do_void args = [values.w_default_continuation_prompt_tag, do_void.w_prim] return abort_current_continuation(args, env, cont) expose_val("error-escape-handler", values_parameter.W_Parameter(default_error_escape_handler)) @make_procedure("default-continuation-prompt-handler", [procedure], simple=False) def default_continuation_prompt_handler(proc, env, cont): return proc.call([], env, cont) @expose("call-with-continuation-prompt", simple=False, arity=Arity.geq(1)) def call_with_continuation_prompt(args, env, cont): if not args: raise SchemeException("call-with-continuation-prompt: not given enough values") parser = ArgParser("call-with-continuation-prompt", args) tag = values.w_default_continuation_prompt_tag handler = values.w_false fun = parser.object() try:
parser = ArgParser("extend-parameterization", args, start_at=1) while parser.has_more(): param = parser.parameter() key = parser.object() config = config.extend([param], [key]) return config def call_with_parameterization(f, args, paramz, env, cont): cont.update_cm(values.parameterization_key, paramz) return f.call(args, env, cont) @expose("call-with-parameterization", [values.W_Object, values_parameter.W_Parameterization], simple=False) def call_w_paramz(f, paramz, env, cont): return call_with_parameterization(f, [], paramz, env, cont) def call_with_extended_paramz(f, args, keys, vals, env, cont): from pycket.values import parameterization_key # XXX seems untested? paramz = cont.get_mark_first(parameterization_key) assert isinstance(paramz, values_parameter.W_Parameterization) # XXX is this always right? paramz_new = paramz.extend(keys, vals) return call_with_parameterization(f, args, paramz_new, env, cont) expose_val("parameterization-key", values.parameterization_key) expose_val("print-mpair-curly-braces", values_parameter.W_Parameter(values.w_false)) expose_val("print-pair-curly-braces", values_parameter.W_Parameter(values.w_false))
#! /usr/bin/env python # -*- coding: utf-8 -*- from pycket.prims.expose import expose, expose_val, make_call_method, make_procedure from pycket.error import SchemeException from pycket import impersonators as imp from pycket import values from pycket import values_struct expose_val("unsafe-undefined", values.w_unsafe_undefined) @expose("check-not-unsafe-undefined", [values.W_Object, values.W_Symbol]) def cnuu(obj, sym): if obj is values.w_unsafe_undefined: raise SchemeException("%s: undefined; use before initialization" % sym.utf8value) return obj @expose("check-not-unsafe-undefined/assign", [values.W_Object, values.W_Symbol]) def cnuua(obj, sym): if obj is values.w_unsafe_undefined: raise SchemeException("%s: undefined; assignment before initialization" % sym.utf8value) return obj def make_accessor(acc, i): idx = values.W_Fixnum(i) sym = values.W_Symbol.make("<internal-accessor>") return values_struct.W_StructFieldAccessor(acc, idx, sym) def make_mutator(mut, i): idx = values.W_Fixnum(i) sym = values.W_Symbol.make("<internal-mutator>") return values_struct.W_StructFieldMutator(mut, idx, sym)
def call_with_extended_paramz(f, args, keys, vals, env, cont): from pycket.values import parameterization_key paramz = cont.get_mark_first(parameterization_key) assert isinstance(paramz, values_parameter.W_Parameterization) return paramz.extend(keys, vals, env, call_with_paramz_cont(f, args, env, cont)) @make_procedure("eval-jit-enabled-guard", [values.W_Object], simple=False) def eval_jit_enabled_guard(arg, env, cont): from pycket.interpreter import return_value # never disable the jit return return_value(values.w_void, env, cont) expose_val("compile-enforce-module-constants", values_parameter.W_Parameter(values.w_true)) # compilation should avoid function-call inlining and other optimizations that may cause information to be lost from stack traces expose_val("compile-context-preservation-enabled", values_parameter.W_Parameter(values.w_true)) expose_val("compile-allow-set!-undefined", values_parameter.W_Parameter(values.w_false)) current_cmd_args_param = values_parameter.W_Parameter( vector.W_Vector.fromelements([])) expose_val("current-command-line-arguments", current_cmd_args_param) expose_val("eval-jit-enabled", values_parameter.W_Parameter(values.w_true, eval_jit_enabled_guard)) expose_val("exnh", values_parameter.W_Parameter(values.w_false)) expose_val("load-on-demand-enabled",
def call_with_parameterization(f, args, paramz, env, cont): cont.update_cm(values.parameterization_key, paramz) return f.call(args, env, cont) @expose("call-with-parameterization", [values.W_Object, values_parameter.W_Parameterization], simple=False) def call_w_paramz(f, paramz, env, cont): return call_with_parameterization(f, [], paramz, env, cont) def call_with_extended_paramz(f, args, keys, vals, env, cont): from pycket.values import parameterization_key # XXX seems untested? paramz = cont.get_mark_first(parameterization_key) assert isinstance( paramz, values_parameter.W_Parameterization) # XXX is this always right? paramz_new = paramz.extend(keys, vals) return call_with_parameterization(f, args, paramz_new, env, cont) expose_val("parameterization-key", values.parameterization_key) expose_val("print-mpair-curly-braces", values_parameter.W_Parameter(values.w_false)) expose_val("print-pair-curly-braces", values_parameter.W_Parameter(values.w_false))
@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")) @expose(["syntax-line", "syntax-column", "syntax-position", "syntax-span"], [values.W_Syntax]) def syntax_numbers(stx): # XXX Obviously not correct return values.w_false expose_val("null", values.w_null) expose_val("true", values.w_true) expose_val("false", values.w_false) expose_val("break-enabled-key", values.break_enabled_key) expose_val("exception-handler-key", values.exn_handler_key) # FIXME: need stronger guards for all of these for name in ["prop:evt", "prop:impersonator-of", "prop:method-arity-error", "prop:exn:srclocs", "prop:custom-print-quotable"]: expose_val(name, values_struct.W_StructProperty( values.W_Symbol.make(name), values.w_false)) expose_val("prop:procedure", values_struct.w_prop_procedure)
raise ExitException(v) else: raise ExitException(values.W_Fixnum(0)) @continuation def force_exit_cont(v, env, cont, _vals): return _force_exit(v) @make_procedure("initial-exit-handler", [values.W_Object], arity=Arity.ZERO, simple=False) def initial_exit_handler(v, env, cont): from pycket.prims.plumber import do_plumber_flush_all root_plumber = current_plumber_param.get(cont) ## ?? return do_plumber_flush_all(root_plumber, env , force_exit_cont(v, env, cont)) exit_handler_param = values_parameter.W_Parameter(initial_exit_handler) expose_val("exit-handler", exit_handler_param) @continuation def exit_cont(env, cont, _vals): from pycket.interpreter import return_value return return_value(values.w_void, env, cont) @expose("exit", [default(values.W_Object, values.w_true)], simple=False) def exit(v, env, cont): exit_handler = exit_handler_param.get(cont) return exit_handler.call([v], env, exit_cont(env, cont)) @make_procedure("default-error-escape-handler", [], simple=False) def default_error_escape_handler(env, cont): from pycket.prims.general import do_void args = [values.w_default_continuation_prompt_tag, do_void.w_prim]
def set_callback(self, h, proc): self.callbacks[h] = proc def set_weak_callback(self, h, proc): self.weak_callbacks[h] = proc 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:
def expose_ctype(name, size, alignment, *extra_names): basetype = values.W_Symbol.make(name) ctype = W_PrimitiveCType(basetype, size, alignment) expose_val("_" + name, ctype) for name in extra_names: expose_val("_" + name, ctype)
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)
@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)
return self.bundle_mapping def tostring(self): mapping = self.bundle_mapping return "BUNDLE : %s" % mapping.tostring() our_vm_bytes = values.W_Bytes.from_string("pycket") @expose("linklet-virtual-machine-bytes", []) def vm_bytes(): return our_vm_bytes w_pycket_sym = values.W_Symbol.make("pycket") # FIXME: control initialization of this from command line using -W expose_val("current-compile-target-machine", values_parameter.W_Parameter(w_pycket_sym)) @expose("compile-target-machine?", [values.W_Symbol]) def compile_machine_target_p(v): return values.W_Bool.make(v is w_pycket_sym) @expose("hash->linklet-bundle", [W_Object]) def hash_to_linklet_bundle(content): return W_LinkletBundle(content) @expose("linklet-bundle->hash", [W_LinkletBundle]) def linklet_bundle_to_hash(linkl_bundle): return linkl_bundle.bundle_mapping class W_LinkletDirectory(W_Object):
@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])
#! /usr/bin/env python # -*- coding: utf-8 -*- from pycket import impersonators as imp from pycket import values from pycket import values_parameter, values_struct from pycket.arity import Arity from pycket.error import SchemeException from pycket.prims.expose import unsafe, default, expose, expose_val expose_val("current-inspector", values_struct.current_inspector_param) expose_val("current-code-inspector", values_struct.current_inspector_param) @expose("make-inspector", [default(values_struct.W_StructInspector, None)], simple=False) def do_make_instpector(inspector, env, cont): from pycket.interpreter import return_value if inspector is None: inspector = values_struct.current_inspector_param.get(cont) new_inspector = values_struct.W_StructInspector.make(inspector) return return_value(new_inspector, env, cont) @expose("make-sibling-inspector", [default(values_struct.W_StructInspector, None)], simple=False) def do_make_sibling_instpector(inspector, env, cont): from pycket.interpreter import return_value if inspector is None: inspector = values_struct.current_inspector_param.get(cont)
return call_with_parameterization(f, args, paramz, env, cont) # only used in input_output.py def call_with_extended_paramz(f, args, keys, vals, env, cont): from pycket.values import parameterization_key paramz = cont.get_mark_first(parameterization_key) assert isinstance(paramz, values_parameter.W_Parameterization) return paramz.extend(keys, vals, env, call_with_paramz_cont(f, args, env, cont)) @make_procedure("eval-jit-enabled-guard", [values.W_Object], simple=False) def eval_jit_enabled_guard(arg, env, cont): from pycket.interpreter import return_value # never disable the jit return return_value(values.w_void, env, cont) expose_val("compile-enforce-module-constants", values_parameter.W_Parameter(values.w_true)) # compilation should avoid function-call inlining and other optimizations that may cause information to be lost from stack traces expose_val("compile-context-preservation-enabled", values_parameter.W_Parameter(values.w_true)) expose_val("compile-allow-set!-undefined", values_parameter.W_Parameter(values.w_false)) current_cmd_args_param = values_parameter.W_Parameter(vector.W_Vector.fromelements([])) expose_val("current-command-line-arguments", current_cmd_args_param) expose_val("eval-jit-enabled", values_parameter.W_Parameter(values.w_true, eval_jit_enabled_guard)) expose_val("exnh", values_parameter.W_Parameter(values.w_false)) expose_val("load-on-demand-enabled", values_parameter.W_Parameter(values.w_true)) expose_val("read-on-demand-source", values_parameter.W_Parameter(values.w_true)) expose_val("parameterization-key", values.parameterization_key) expose_val("print-mpair-curly-braces", values_parameter.W_Parameter(values.w_false)) expose_val("print-pair-curly-braces", values_parameter.W_Parameter(values.w_false))
mapping = self.bundle_mapping return "BUNDLE : %s" % mapping.tostring() our_vm_bytes = values.W_Bytes.from_string("pycket") @expose("linklet-virtual-machine-bytes", []) def vm_bytes(): return our_vm_bytes w_pycket_sym = values.W_Symbol.make("pycket") # FIXME: control initialization of this from command line using -W expose_val("current-compile-target-machine", values_parameter.W_Parameter(w_pycket_sym)) @expose("compile-target-machine?", [values.W_Symbol]) def compile_machine_target_p(v): return values.W_Bool.make(v is w_pycket_sym) @expose("hash->linklet-bundle", [W_Object]) def hash_to_linklet_bundle(content): return W_LinkletBundle(content) @expose("linklet-bundle->hash", [W_LinkletBundle]) def linklet_bundle_to_hash(linkl_bundle): return linkl_bundle.bundle_mapping
stop = len(bytes) if w_end is None else w_end.value n = write_bytes_avail(bytes, w_port, start, stop) return return_value(values.W_Fixnum(n), env, cont) # FIXME: @expose("custom-write?", [values.W_Object]) def do_has_custom_write(v): return values.w_false def shutdown(env): # called before the interpreter exits stdout_port.flush() ############################ Values and Parameters expose_val("eof", values.eof_object) current_print_param = values_parameter.W_Parameter(standard_printer) expose_val("current-print", current_print_param) # line buffer stdout stdout_port = values.W_FileOutputPort(sio.fdopen_as_stream(1, "w", buffering=1)) stderr_port = values.W_FileOutputPort(sio.fdopen_as_stream(2, "w", buffering=1)) stdin_port = values.W_FileInputPort(sio.fdopen_as_stream(0, "r")) current_out_param = values_parameter.W_Parameter(stdout_port) current_error_param = values_parameter.W_Parameter(stderr_port) current_in_param = values_parameter.W_Parameter(stdin_port) expose_val("current-output-port", current_out_param) expose_val("current-error-port", current_error_param) expose_val("current-input-port", current_in_param)
return stx.val define_nyi("datum->syntax") # @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): # raise NotImplementedError() # assert isinstance(ctxt, values.W_Syntax) or ctxt is values.w_false # return values.W_Syntax(v) @expose("compiled-module-expression?", [values.W_Object]) def compiled_module_expression(v): return values.w_false expose_val("null", values.w_null) expose_val("true", values.w_true) expose_val("false", values.w_false) expose_val("break-enabled-key", values.break_enabled_key) expose_val("exception-handler-key", values.exn_handler_key) expose_val("parameterization-key", values.parameterization_key) expose_val("print-mpair-curly-braces", values.W_Parameter(values.w_false)) expose_val("print-pair-curly-braces", values.W_Parameter(values.w_false)) # FIXME: need stronger guards for all of these for name in ["prop:evt", "prop:output-port", "prop:impersonator-of", "prop:method-arity-error", "prop:exn:srclocs", "prop:custom-print-quotable"]:
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)
#! /usr/bin/env python # -*- coding: utf-8 -*- # XXX: This whole module is wrong from pycket import values from pycket.prims.expose import default, expose, expose_val, procedure expose_val("_int8" , values.W_Fixnum.make(0)) 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)
#! /usr/bin/env python # -*- coding: utf-8 -*- from pycket import impersonators as imp from pycket import values from pycket import values_parameter, values_struct from pycket.arity import Arity from pycket.error import SchemeException from pycket.prims.expose import unsafe, default, expose, expose_val expose_val("current-inspector", values_struct.current_inspector_param) @expose("make-inspector", [default(values_struct.W_StructInspector, None)], simple=False) def do_make_instpector(inspector, env, cont): from pycket.interpreter import return_value if inspector is None: inspector = values_struct.current_inspector_param.get(cont) new_inspector = values_struct.W_StructInspector.make(inspector) return return_value(new_inspector, env, cont) @expose("make-sibling-inspector", [default(values_struct.W_StructInspector, None)], simple=False) def do_make_sibling_instpector(inspector, env, cont): from pycket.interpreter import return_value if inspector is None: inspector = values_struct.current_inspector_param.get(cont) new_inspector = values_struct.W_StructInspector.make(inspector, issibling=True) return return_value(new_inspector, env, cont) @expose("struct?", [values.W_Object], simple=False) def do_is_struct(v, env, cont): from pycket.interpreter import return_value current_inspector = values_struct.current_inspector_param.get(cont)
#! /usr/bin/env python # -*- coding: utf-8 -*- from pycket.prims.expose import expose, expose_val, make_call_method, make_procedure from pycket.error import SchemeException from pycket import impersonators as imp from pycket import values from pycket import values_struct expose_val("unsafe-undefined", values.w_unsafe_undefined) @expose("check-not-unsafe-undefined", [values.W_Object, values.W_Symbol]) def cnuu(obj, sym): if obj is values.w_unsafe_undefined: raise SchemeException("%s: undefined; use before initialization" % sym.utf8value) return obj @expose("check-not-unsafe-undefined/assign", [values.W_Object, values.W_Symbol]) def cnuua(obj, sym): if obj is values.w_unsafe_undefined: raise SchemeException( "%s: undefined; assignment before initialization" % sym.utf8value) return obj def make_accessor(acc, i): sym = values.W_Symbol.make("<internal-accessor>") return values_struct.W_StructFieldAccessor(acc, i, sym)
def force_exit_cont(v, env, cont, _vals): return _force_exit(v) @make_procedure("initial-exit-handler", [values.W_Object], arity=Arity.ZERO, simple=False) def initial_exit_handler(v, env, cont): from pycket.prims.plumber import do_plumber_flush_all root_plumber = current_plumber_param.get(cont) ## ?? return do_plumber_flush_all(root_plumber, env, force_exit_cont(v, env, cont)) exit_handler_param = values_parameter.W_Parameter(initial_exit_handler) expose_val("exit-handler", exit_handler_param) @continuation def exit_cont(env, cont, _vals): from pycket.interpreter import return_value return return_value(values.w_void, env, cont) @expose("exit", [default(values.W_Object, values.w_true)], simple=False) def exit(v, env, cont): exit_handler = exit_handler_param.get(cont) return exit_handler.call([v], env, exit_cont(env, cont)) @make_procedure("default-error-escape-handler", [], simple=False)
from pycket import impersonators as imp from pycket import values from pycket import values_struct from pycket.arity import Arity from pycket.hash.base import W_HashTable from pycket.error import SchemeException from pycket.prims.expose import expose, expose_val from pycket.prims.equal import equal_func, equal_func_unroll_n, EqualInfo from rpython.rlib import jit expose_val("impersonator-prop:application-mark", imp.w_impersonator_prop_application_mark) # Used to find the first impersonator-property @jit.unroll_safe def find_prop_start_index(args): for i, v in enumerate(args): if isinstance(v, imp.W_ImpPropertyDescriptor): return i return len(args) @jit.unroll_safe def unpack_properties(args, name): idx = find_prop_start_index(args) if idx == len(args): props = None prop_len = 0 else:
cont = call_handler_cont(handler, args, env, cont) return unwind_frames(frames, env, cont) return handler.call(args, env, cont) expose("abort-current-continuation", simple=False)(abort_current_continuation) @make_procedure("default-error-escape-handler", [], simple=False) def default_error_escape_handler(env, cont): from pycket.prims.general import do_void args = [values.w_default_continuation_prompt_tag, do_void.w_prim] return abort_current_continuation(args, env, cont) expose_val("error-escape-handler", values_parameter.W_Parameter(default_error_escape_handler)) @make_procedure("default-continuation-prompt-handler", [procedure], simple=False) def default_continuation_prompt_handler(proc, env, cont): return proc.call([], env, cont) @expose("call-with-continuation-prompt", simple=False, arity=Arity.geq(1)) def call_with_continuation_prompt(args, env, cont): if not args: raise SchemeException( "call-with-continuation-prompt: not given enough values") parser = ArgParser("call-with-continuation-prompt", args) tag = values.w_default_continuation_prompt_tag
from pycket import impersonators as imp from pycket import values from pycket import values_struct from pycket.arity import Arity from pycket.hash.base import W_HashTable from pycket.error import SchemeException from pycket.prims.expose import expose, expose_val from pycket.prims.equal import equal_func, EqualInfo from rpython.rlib import jit expose_val("impersonator-prop:application-mark", imp.w_impersonator_prop_application_mark) # Used to find the first impersonator-property @jit.unroll_safe def find_prop_start_index(args): for i, v in enumerate(args): if isinstance(v, imp.W_ImpPropertyDescriptor): return i return len(args) @jit.unroll_safe def unpack_properties(args, name): idx = find_prop_start_index(args) if idx == len(args): props = None prop_len = 0 else: args, props = args[:idx], args[idx:] prop_len = len(props)