/* lambda_type -- abstract over a list of given set names in a type */ PUBLIC type lambda_type(env bv, type t) { type at; int i; for (i = 0; i < n_cached; i++) if (type_cache[i].conc == t) { #ifdef DEBUG if (debug('t')) grind(stdout, "Cache hit for type %t at %x\n", t, t); #endif return type_cache[i].abs; } if (bv != NULL && bv->e_ndefs > MAX_ARGS) panic("lambda_type - too many type variables"); at = lambda_ty(bv, t, arid); if (n_cached < VAR_SIZE) { type_cache[n_cached].conc = t; type_cache[n_cached].abs = at; n_cached++; #ifdef DEBUG if (debug('t')) grind(stdout, "Cached type %t at %x\n", t, t); #endif } return at; }
/* panic -- print a message and force a core dump */ PUBLIC void panic(char *fmt, ...) { va_list a; grind(errout, "\nPanic: "); va_begin(a, fmt); do_grind(errout, fmt, &a); va_end(a); grind(errout, "\n"); fflush(errout); abort(); }
/* tc_e_etc -- further details of type error */ PUBLIC void tc_e_etc(char *fmt, ...) { va_list a; #ifdef DEBUG if (! in_error) panic("tc_e_etc"); #endif grind(errout, "> "); va_begin(a, fmt); do_grind(errout, fmt, &a); va_end(a); grind(errout, "\n"); fflush(errout); }
/* tc_e_end -- end of error message and supporting lines */ PUBLIC void tc_e_end(void) { #ifdef DEBUG if (! in_error) panic("tc_e_end"); in_error = FALSE; #endif grind(errout, "\n"); fflush(errout); }
PUBLIC type tc_expr(tree t, env e) { type result; level++; result = the_real_tc_expr(t, e); level--; if (debug('e')) grind(stdout, "Expr: %j%z ==> %t\n", level, t, result); return result; }
/* report_error -- Print first line of error message */ PRIVATE void report_error(int kind, int line, char *fmt, va_list *a) { char buf[128]; #ifdef DEBUG if (in_error) panic("report_error"); in_error = TRUE; #endif if (kind != WARNING && ++n_errors >= MAX_ERRORS) { fprintf(errout, "fuzz: too many errors - giving up\n"); fflush(errout); exit(1); } /* Fix bison's canned error messages, among others */ strcpy(buf, fmt); if (islower(buf[0])) buf[0] = toupper(buf[0]); grind(errout, "\"%s\", line %d: ", file_name, line); if (kind == WARNING) grind(errout, "Warning - "); do_grind(errout, buf, a); if (kind == SYNTAX) { if (yychar == 0) grind(errout, " at end of file"); else if (yychar == NL) grind(errout, " at \"\\\\\" or \"\\also\""); else if (yytext[0] != '\0') grind(errout, " at symbol \"%s\"", yytext); } grind(errout, "\n"); }
void inventory::form_from_map(game *g, point origin, int range) { items.clear(); for (int x = origin.x - range; x <= origin.x + range; x++) { for (int y = origin.y - range; y <= origin.y + range; y++) { for (int i = 0; i < g->m.i_at(x, y).size(); i++) if (!g->m.i_at(x, y)[i].made_of(LIQUID)) add_item(g->m.i_at(x, y)[i]); // Kludge for now! if (g->m.field_at(x, y).type == fd_fire) { item fire(g->itypes[itm_fire], 0); fire.charges = 1; add_item(fire); } if (g->m.ter(x, y) == t_forge) { item forge(g->itypes[itm_forge], 0); forge.charges = 1; add_item(forge); } if (g->m.ter(x, y) == t_grindstone) { item grind(g->itypes[itm_grindstone], 0); grind.charges = 1; add_item(grind); } if (g->m.ter(x, y) == t_watertub) { item water(g->itypes[itm_forgewater], 0); water.charges = 1; add_item(water); } if (g->m.ter(x, y) == t_crucible) { item crucible(g->itypes[itm_hot_crucible], 0); crucible.charges = 1; add_item(crucible); } if (g->m.ter(x, y) == t_anvil) { item anvil(g->itypes[itm_anvil], 0); anvil.charges = 1; add_item(anvil); } } } }
static void dotest(void) { unsigned i, me; pid_t pids[BRANCHES]; int t; me = 0; for (i=0; i<BRANCHES; i++) { pids[i] = dofork(); if (pids[i] == 0) { me += 1U<<i; } grind(); t = trace(); if (t == right[i]) { tsay("Stage %u #%u done: %d\n", i, me, trace()); } else { tsay("Stage %u #%u FAILED: got %d, expected %d\n", i, me, t, right[i]); success(TEST161_FAIL, SECRET, "/testbin/bigfork"); failures++; } TEST161_TPROGRESS(0); } for (i=BRANCHES; i-- > 0; ) { dowait(pids[i]); } if (failures > 0) { tprintf("%u failures.\n", failures); success(TEST161_FAIL, SECRET, "/testbin/bigfork"); } else { tprintf("Done.\n"); success(TEST161_SUCCESS, SECRET, "/testbin/bigfork"); } }
PRIVATE type lambda_ty(env bv, type t, frame f) { #ifdef DEBUG if (debug('t')) grind(stdout, "lambda_ty(%x)\n", t); #endif if (t == NULL) panic("lambda_ty"); if (f == arid && is_perm((univ) t)) { /* It's lambda bv . t[NULL] where t is already permanent. This means that t contains no bound vars: return t */ #ifdef DEBUG if (debug('t')) grind(stdout, "Reused type %t\n", t); #endif return t; } switch (t->t_kind) { case GIVENT: /* lambda bv . v[f] -- look for v among the bv's */ return var_rep(bv, t); case TYPEVAR: /* lambda bv . Vi[f] = lambda bv. fi[NULL] */ return lambda_ty(bv, tv_val(t, f), arid); case POWERT: /* lambda bv . (P t)[f] = P (lambda bv . t[f]) */ return mk_power(lambda_ty(bv, t->t_base, f)); case CPRODUCT: { /* lambda bv . (t1 x ... x tn)[f] = (lambda bv . t1[f]) x ... x (lambda bv . tn[f]) */ type a[MAX_ARGS]; int i; if (t->t_nfields > MAX_ARGS) panic("lambda_ty - too many fields"); for (i = 0; i < t->t_nfields; i++) a[i] = lambda_ty(bv, t->t_field[i], f); return mk_cproduct(t->t_nfields, a); } case SPRODUCT: { /* lambda bv . <| x1: t1; ... |>[f] = <| x1: lambda bv. t1[f]; ... |> */ schema s = t->t_schema; int n = s->z_ncomps; schema s1 = alloc_schema(n); int i; for (i = 0; i < n; i++) { s1->z_comp[i].z_name = s->z_comp[i].z_name; s1->z_comp[i].z_type = lambda_ty(bv, s->z_comp[i].z_type, f); } return mk_sproduct(s1); } case MOLECULE: /* lambda bv . (MOLECULE t f')[f] = lambda bv . t[f'] */ return lambda_ty(bv, t->t_mtype, t->t_mframe); case ABBREV: { /* lambda bv . (ABBREV d {t1 t2 ... tn})[f] = ABBREV d {(lambda bv . t1[f]) ... } */ frame p = t->t_params; frame pp = mk_frame(fsize(p)); int i; for (i = 0; i < fsize(p); i++) pp->f_var[i] = lambda_ty(bv, p->f_var[i], f); return mk_abbrev(t->t_def, pp); } default: bad_tag("lambda_ty", t->t_kind); return (type) NULL; } }