static obj_t dylan_sovec_element_setter(obj_t value, obj_t sovec, obj_t index) { int i = fixnum_value(index); if (0 <= i && i < SOVEC(sovec)->length) SOVEC(sovec)->contents[i] = value; else error("No element %= in %=", index, sovec); return value; }
static obj_t dylan_sovec_element(obj_t sovec, obj_t index, obj_t def) { int i = fixnum_value(index); if (0 <= i && i < SOVEC(sovec)->length) return SOVEC(sovec)->contents[i]; else if (def != obj_Unbound) return def; else { error("No element %= in %=", index, sovec); return NULL; } }
obj_t make_vector(int length, obj_t *contents) { obj_t res = alloc(obj_SimpleObjectVectorClass, sizeof(struct sovec) + sizeof(obj_t)*(length-1)); SOVEC(res)->length = length; if (contents) memcpy(SOVEC(res)->contents, contents, sizeof(obj_t) * length); return res; }
static void verror(char *msg, va_list ap) { int nargs = count_format_args(msg); int i; struct thread *thread = thread_current(); if (error_system_enabled) { *thread->sp++ = error_var->value; *thread->sp++ = make_byte_string(msg); for (i = 0; i < nargs; i++) *thread->sp++ = va_arg(ap, obj_t); invoke(thread, nargs+1); go_on(); } else if (thread) { obj_t cond = make_vector(nargs+1, NULL); SOVEC(cond)->contents[0] = make_byte_string(msg); for (i = 1; i <= nargs; i++) SOVEC(cond)->contents[i] = va_arg(ap, obj_t); thread_debuggered(thread, cond); } else { obj_t cond = make_vector(nargs, NULL); for (i = 0; i < nargs; i++) SOVEC(cond)->contents[i] = va_arg(ap, obj_t); printf("error: "); vformat(msg, SOVEC(cond)->contents, nargs); putchar('\n'); exit(1); } }
static obj_t dylan_sovec_size(obj_t sovec) { return make_fixnum(SOVEC(sovec)->length); }