Program * null_program(void) { static Program *p = 0; Var code, errors; if (!p) { code = new_list(0); p = parse_list_as_program(code, &errors); if (!p) panic("Can't create the null program!"); free_var(code); free_var(errors); } return p; }
static package bf_eval(Var arglist, Byte next, void *data, Objid progr) { package p; if (next == 1) { if (!is_programmer(progr)) { free_var(arglist); p = make_error_pack(E_PERM); } else { Var errors; Program *program = parse_list_as_program(arglist, &errors); free_var(arglist); if (program) { free_var(errors); if (setup_activ_for_eval(program)) p = make_call_pack(2, 0); else { free_program(program); p = make_error_pack(E_MAXREC); } } else { Var r; r = new_list(2); r.v.list[1].type = TYPE_INT; r.v.list[1].v.num = 0; r.v.list[2] = errors; p = make_var_pack(r); } } } else { /* next == 2 */ Var r; r = new_list(2); r.v.list[1].type = TYPE_INT; r.v.list[1].v.num = 1; r.v.list[2] = arglist; p = make_var_pack(r); } return p; }
static package bf_set_verb_code(Var arglist, Byte next, void *vdata, Objid progr) { /* (object, verb-desc, code) */ Objid oid = arglist.v.list[1].v.obj; Var desc = arglist.v.list[2]; Var code = arglist.v.list[3]; int i; Program *program; db_verb_handle h; Var errors; enum error e; for (i = 1; i <= code.v.list[0].v.num; i++) if (code.v.list[i].type != TYPE_STR) { free_var(arglist); return make_error_pack(E_TYPE); } if ((e = validate_verb_descriptor(desc)) != E_NONE || (e = E_INVARG, !valid(oid))) { free_var(arglist); return make_error_pack(e); } h = find_described_verb(oid, desc); if (!h.ptr) { free_var(arglist); return make_error_pack(E_VERBNF); } else if (!is_programmer(progr) || !db_verb_allows(h, progr, VF_WRITE)) { free_var(arglist); return make_error_pack(E_PERM); } program = parse_list_as_program(code, &errors); if (program) { if (task_timed_out) free_program(program); else db_set_verb_program(h, program); } free_var(arglist); return make_var_pack(errors); }