// (method 'msg 'obj) -> fun any doMethod(any ex) { any x; cell c1; x = cdr(ex), Push(c1, EVAL(car(x))); NeedSym(ex,data(c1)); x = cdr(x), x = EVAL(car(x)); NeedSym(ex,x); Fetch(ex,x); TheKey = Pop(c1); return method(x)? : Nil; }
// (send 'msg 'obj ['any ..]) -> any any doSend(any ex) { any x, y; cell c1, c2; x = cdr(ex), Push(c1, EVAL(car(x))); NeedSym(ex,data(c1)); x = cdr(x), Push(c2, EVAL(car(x))); NeedSym(ex,data(c2)); Fetch(ex,data(c2)); TheKey = data(c1), TheCls = NULL; if (y = method(data(c2))) { x = evMethod(data(c2), y, cdr(x)); drop(c1); return x; } err(ex, TheKey, "Bad message"); }
static void redefine(any ex, any s, any x) { NeedSym(ex,s); CheckVar(ex,s); if (!isNil(val(s)) && s != val(s) && !equal(x,val(s))) redefMsg(s, NULL); val(s) = x; putSrc(s, NULL); }
// (with 'sym . prg) -> any any doWith(any ex) { any x; bindFrame f; x = cdr(ex); if (isNil(x = EVAL(car(x)))) return Nil; NeedSym(ex,x); Bind(This,f), val(This) = x; x = prog(cddr(ex)); Unbind(f); return x; }
// (meth 'obj ['any ..]) -> any any doMeth(any ex) { any x, y; cell c1; x = cdr(ex), Push(c1, EVAL(car(x))); NeedSym(ex,data(c1)); Fetch(ex,data(c1)); for (TheKey = car(ex); ; TheKey = val(TheKey)) { if (!isSym(TheKey)) err(ex, TheKey, "Bad message"); if (isNum(val(TheKey))) { TheCls = NULL; if (y = method(data(c1))) { x = evMethod(data(c1), y, cdr(x)); drop(c1); return x; } err(ex, TheKey, "Bad message"); } } }
// (tmr-decode 'sym) -> num any tmr_decode(any ex) { char* pend; long res; any x, y; x = cdr(ex), y = EVAL(car(x)); NeedSym(ex, y); char key[bufSize(y)]; bufString(y, key); if (strlen(key) > MAX_VTIMER_NAME_LEN || strlen(key) < MIN_VTIMER_NAME_LEN) return box(0); if (strncmp(key, "VIRT", 4)) return box(0); res = strtol(key + 4, &pend, 10); if (*pend != '\0') return box(0); if (res >= VTMR_NUM_TIMERS) return box(0); return box(res + VTMR_FIRST_ID); }
// (try 'msg 'obj ['any ..]) -> any any doTry(any ex) { any x, y; cell c1, c2; x = cdr(ex), Push(c1, EVAL(car(x))); NeedSym(ex,data(c1)); x = cdr(x), Push(c2, EVAL(car(x))); if (isSym(data(c2))) { if (isExt(data(c2))) { if (!isLife(data(c2))) return Nil; db(ex,data(c2),1); } TheKey = data(c1), TheCls = NULL; if (y = method(data(c2))) { x = evMethod(data(c2), y, cdr(x)); drop(c1); return x; } } drop(c1); return Nil; }
// (def 'sym 'any) -> sym // (def 'sym 'sym 'any) -> sym any doDef(any ex) { any x, y; cell c1, c2, c3; x = cdr(ex), Push(c1, EVAL(car(x))); NeedSym(ex,data(c1)); CheckVar(ex,data(c1)); Touch(ex,data(c1)); x = cdr(x), Push(c2, EVAL(car(x))); if (!isCell(cdr(x))) { if (!isNil(y = val(data(c1))) && y != data(c1) && !equal(data(c2), y)) redefMsg(data(c1), NULL); val(data(c1)) = data(c2); putSrc(data(c1), NULL); } else { x = cdr(x), Push(c3, EVAL(car(x))); if (!isNil(y = get(data(c1), data(c2))) && !equal(data(c3), y)) redefMsg(data(c1), data(c2)); put(data(c1), data(c2), data(c3)); putSrc(data(c1), data(c2)); } return Pop(c1); }