repv property_cache_ref (repv id, repv prop) { unsigned int h, i; if (cache_vec == rep_NULL) return rep_NULL; h = CACHE_HASH (id, prop) * CACHE_ASSOC; DB (("prop ref: 0x%x,%s (%d) -> ", id, rep_STR (rep_SYM (prop)->name), h)); for (i = h; i < h + CACHE_ASSOC; i++) { if (cache_ids[i] == id && cache_props[i] == prop) { cache_hits++; DB (("hit\n")); cache_ages[i] = ++cache_clock; return cache_values[i]; } } DB (("miss\n")); cache_misses++; return rep_NULL; }
char *gh_symbol2newstr(repv sym, size_t *lenp) { if (!rep_SYMBOLP (sym)) return NULL; return gh_scm2newstr (rep_SYM (sym)->name, lenp); }
void property_cache_set (repv id, repv prop, repv value, int invals) { unsigned int h, i, oldest, oldest_age; if (cache_vec == rep_NULL) { cache_vec = Fmake_vector (rep_MAKE_INT (CACHE_SIZE * 3), Qnil); rep_mark_static (&cache_vec); cache_ids = rep_VECT (cache_vec)->array; cache_props = cache_ids + CACHE_SIZE; cache_values = cache_props + CACHE_SIZE; } h = CACHE_HASH (id, prop) * CACHE_ASSOC; oldest_age = UINT_MAX; oldest = -1; for (i = h; i < h + CACHE_ASSOC; i++) { if (cache_ids[i] == id && cache_props[i] == prop) { cache_values[i] = value; cache_updates[i] += invals; return; } if (cache_ages[i] <= oldest_age) { oldest_age = cache_ages[i]; oldest = i; } } assert (oldest != -1); if (cache_ids[oldest] != 0) DB (("prop eject: 0x%x (%d)\n", cache_ids[oldest], oldest)); cache_ids[oldest] = id; cache_props[oldest] = prop; cache_values[oldest] = value; cache_ages[oldest] = ++cache_clock; cache_updates[oldest] = invals; DB (("set: 0x%x,%s (%d)\n", id, rep_STR (rep_SYM (prop)->name), oldest)); }
static char * completion_generator (char *word, int state) { if (state == 0) { repv fun = completion_fun; if (fun == Qnil) /* backwards compatibility, ugh */ fun = Fsymbol_value (Qrl_completion_generator, Qt); if (Ffunctionp (fun) != Qnil) { completions = (rep_call_with_barrier (Ffuncall, rep_list_2 (fun, rep_string_dup (word)), rep_TRUE, 0, 0, 0)); } else { repv re = Fquote_regexp (rep_string_dup (word)); repv boundp = Fsymbol_value (Qboundp, Qt); completions = Fapropos (rep_concat2("^", rep_STR(re)), boundp, Qnil); } if (completions == rep_NULL) completions = Qnil; } if (completions != Qnil && rep_CONSP(completions) && (rep_SYMBOLP(rep_CAR(completions)) || rep_STRINGP(rep_CAR(completions)))) { repv string = rep_CAR(completions); if (rep_SYMBOLP(string)) string = rep_SYM(string)->name; completions = rep_CDR(completions); return strdup (rep_STR(string)); } else return 0; }
static void datum_print (repv stream, repv arg) { if (arg == Qnil) { DEFSTRING (eol, "()"); rep_stream_puts (stream, rep_PTR (rep_VAL (&eol)), 2, rep_TRUE); } else { repv printer = Fassq (DATUM_ID (arg), printer_alist); if (printer && rep_CONSP (printer) && rep_CDR (printer) != Qnil) rep_call_lisp2 (rep_CDR (printer), arg, stream); else if (rep_SYMBOLP (DATUM_ID (arg))) { rep_stream_puts (stream, "#<datum ", -1, rep_FALSE); rep_stream_puts (stream, rep_PTR (rep_SYM (DATUM_ID (arg))->name), -1, rep_TRUE); rep_stream_putc (stream, '>'); } else rep_stream_puts (stream, "#<datum>", -1, rep_FALSE); } }