static pic_value weak_call(pic_state *pic) { pic_value key, val, weak; int n; n = pic_get_args(pic, "o|o", &key, &val); if (! pic_obj_p(pic, key)) { pic_error(pic, "attempted to set a non-object key", 1, key); } weak = pic_closure_ref(pic, 0); if (n == 1) { if (! pic_weak_has(pic, weak, key)) { return pic_false_value(pic); } return pic_cons(pic, key, pic_weak_ref(pic, weak, key)); } else { if (pic_undef_p(pic, val)) { if (pic_weak_has(pic, weak, key)) { pic_weak_del(pic, weak, key); } } else { pic_weak_set(pic, weak, key, val); } return pic_undef_value(pic); } }
static pic_value reg_set(pic_state *pic, struct pic_reg *reg, void *key, pic_value val) { if (pic_undef_p(val)) { if (pic_reg_has(pic, reg, key)) { pic_reg_del(pic, reg, key); } } else { pic_reg_set(pic, reg, key, val); } return pic_undef_value(); }
const char * pic_errmsg(pic_state *pic) { pic_str *str; assert(! pic_undef_p(pic->err)); if (! pic_error_p(pic->err)) { str = pic_format(pic, "~s", pic->err); } else { str = pic_error_ptr(pic->err)->msg; } return pic_str_cstr(str); }
void pic_load_stdlib(pic_state *pic) { static const char *fn = "piclib/built-in.scm"; FILE *file; int n, i; pic_value v, vs; struct pic_proc *proc; file = fopen(fn, "r"); if (file == NULL) { fputs("fatal error: could not read built-in.scm", stderr); abort(); } n = pic_parse_file(pic, file, &vs); if (n <= 0) { fputs("fatal error: built-in.scm broken", stderr); abort(); } for (i = 0; i < n; ++i, vs = pic_cdr(pic, vs)) { v = pic_car(pic, vs); proc = pic_codegen(pic, v); if (proc == NULL) { fputs(pic->errmsg, stderr); fputs("fatal error: built-in.scm compilation failure", stderr); abort(); } v = pic_apply(pic, proc, pic_nil_value()); if (pic_undef_p(v)) { fputs(pic->errmsg, stderr); fputs("fatal error: built-in.scm evaluation failure", stderr); abort(); } } #if DEBUG puts("successfully loaded stdlib"); #endif }
static pic_value pic_dict_dictionary_set(pic_state *pic) { struct pic_dict *dict; pic_sym *key; pic_value val; pic_get_args(pic, "dmo", &dict, &key, &val); if (pic_undef_p(val)) { if (pic_dict_has(pic, dict, key)) { pic_dict_del(pic, dict, key); } } else { pic_dict_set(pic, dict, key, val); } return pic_undef_value(); }