static pic_value cont_call(pic_state *pic) { struct pic_proc *self = pic_get_proc(pic); int argc; pic_value *argv; int id; struct pic_cont *cc, *cont; pic_get_args(pic, "*", &argc, &argv); id = pic_int(pic_proc_env_ref(pic, self, "id")); /* check if continuation is alive */ for (cc = pic->cc; cc != NULL; cc = cc->prev) { if (cc->id == id) { break; } } if (cc == NULL) { pic_errorf(pic, "calling dead escape continuation"); } cont = pic_data_ptr(pic_proc_env_ref(pic, self, "escape"))->data; cont->results = pic_list_by_array(pic, argc, argv); pic_load_point(pic, cont); PIC_LONGJMP(pic, cont->jmp, 1); PIC_UNREACHABLE(); }
pic_value pic_native_exception_handler(pic_state *pic) { pic_value err; struct pic_proc *cont; pic_get_args(pic, "o", &err); pic->err = err; cont = pic_proc_ptr(pic_proc_env_ref(pic, pic_get_proc(pic), "cont")); pic_apply1(pic, cont, pic_false_value()); PIC_UNREACHABLE(); }
static pic_value cont_call(pic_state *pic) { size_t argc; pic_value *argv; struct pic_data *e; pic_get_args(pic, "*", &argc, &argv); e = pic_data_ptr(pic_proc_env_ref(pic, pic_get_proc(pic), "escape")); ((struct pic_cont *)e->data)->results = pic_list_by_array(pic, argc, argv); pic_load_point(pic, e->data); PIC_LONGJMP(pic, ((struct pic_cont *)e->data)->jmp.buf, 1); PIC_UNREACHABLE(); }
static pic_value reg_call(pic_state *pic) { struct pic_proc *self = pic_get_proc(pic); struct pic_reg *reg; pic_value key, val; int n; n = pic_get_args(pic, "o|o", &key, &val); if (! pic_obj_p(key)) { pic_errorf(pic, "attempted to set a non-object key '~s' in a register", key); } reg = pic_reg_ptr(pic_proc_env_ref(pic, self, "reg")); if (n == 1) { return reg_get(pic, reg, pic_obj_ptr(key)); } else { return reg_set(pic, reg, pic_obj_ptr(key), val); } }