mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-27 13:00:28 +00:00
Apply clang-format update to repo (#1154)
Commit bc6c183
introduced a bunch of discrepancies between what files
look like in the repo and what clang-format says they should look like.
However, there were already a few discrepancies prior to that. Most of
these discrepancies seemed to be unintentional, but a few of them were
load-bearing (e.g., a #include that violated header ordering needing
something to have been #defined by a 'later' #include.)
I opted to take what I hope is a relatively smooth-brained approach: I
reverted the .clang-format change, ran clang-format on the whole repo,
reapplied the .clang-format change, reran clang-format again, and then
reverted the commit that contained the first run. Thus the full effect
of this PR should only be to apply the changed formatting rules to the
repo, and from skimming the results, this seems to be the case.
My work can be checked by applying the short, manual commits, and then
rerunning the command listed in the autogenerated commits (those whose
messages I have prefixed auto:) and seeing if your results agree.
It might be that the other diffs should be fixed at some point but I'm
leaving that aside for now.
fd '\.c(c|pp)?$' --print0| xargs -0 clang-format -i
This commit is contained in:
parent
342d0c81e5
commit
6e6fc38935
863 changed files with 9201 additions and 4627 deletions
|
@ -24,9 +24,12 @@ pureconst bool IsHex(int c) {
|
|||
}
|
||||
|
||||
pureconst int GetDiglet(int c) {
|
||||
if (IsDigit(c)) return c - L'0';
|
||||
if (IsUpper(c)) return c - L'A' + 10;
|
||||
if (IsLower(c)) return c - L'a' + 10;
|
||||
if (IsDigit(c))
|
||||
return c - L'0';
|
||||
if (IsUpper(c))
|
||||
return c - L'A' + 10;
|
||||
if (IsLower(c))
|
||||
return c - L'a' + 10;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,20 +50,29 @@
|
|||
int Cmp(int x, int y) {
|
||||
int c;
|
||||
dword t, u;
|
||||
if (x == y) return 0;
|
||||
if (x == y)
|
||||
return 0;
|
||||
if (x > 1 && y > 1) {
|
||||
if (LO(Get(x)) < LO(Get(x))) return -1;
|
||||
if (LO(Get(x)) > LO(Get(x))) return +1;
|
||||
if (LO(Get(x)) < LO(Get(x)))
|
||||
return -1;
|
||||
if (LO(Get(x)) > LO(Get(x)))
|
||||
return +1;
|
||||
}
|
||||
for (;; x = Cdr(x), y = Cdr(y)) {
|
||||
if (x == y) return 0;
|
||||
if (!x) return -1;
|
||||
if (!y) return +1;
|
||||
if (x == y)
|
||||
return 0;
|
||||
if (!x)
|
||||
return -1;
|
||||
if (!y)
|
||||
return +1;
|
||||
if (x < 0) {
|
||||
if (y >= 0) return +1;
|
||||
if ((c = Cmp(Car(x), Car(y)))) return c;
|
||||
if (y >= 0)
|
||||
return +1;
|
||||
if ((c = Cmp(Car(x), Car(y))))
|
||||
return c;
|
||||
} else {
|
||||
if (y < 0) return -1;
|
||||
if (y < 0)
|
||||
return -1;
|
||||
for (;;) {
|
||||
t = x != 1 ? Get(x) : MAKE(L'T', TERM);
|
||||
u = y != 1 ? Get(y) : MAKE(L'T', TERM);
|
||||
|
@ -72,9 +81,12 @@ int Cmp(int x, int y) {
|
|||
}
|
||||
x = HI(t);
|
||||
y = HI(u);
|
||||
if (x == y) return 0;
|
||||
if (x == TERM) return -1;
|
||||
if (y == TERM) return +1;
|
||||
if (x == y)
|
||||
return 0;
|
||||
if (x == TERM)
|
||||
return -1;
|
||||
if (y == TERM)
|
||||
return +1;
|
||||
}
|
||||
if (Car(x) != Car(y)) {
|
||||
return Car(x) < Car(y) ? -1 : +1;
|
||||
|
|
|
@ -38,7 +38,8 @@ int Shadow(int p, int s) {
|
|||
|
||||
int GetCommonCons(int x, int y) {
|
||||
if (!y) {
|
||||
if (!x) return -1;
|
||||
if (!x)
|
||||
return -1;
|
||||
if (x > 0 && cFrost < -1 && IsUpper(LO(Get(x))) && HI(Get(x)) == TERM) {
|
||||
return kConsAlphabet[LO(Get(x)) - L'A'];
|
||||
}
|
||||
|
@ -48,7 +49,8 @@ int GetCommonCons(int x, int y) {
|
|||
|
||||
int ShareCons(int x, int y) {
|
||||
int i;
|
||||
if ((i = GetCommonCons(x, y))) return i;
|
||||
if ((i = GetCommonCons(x, y)))
|
||||
return i;
|
||||
#if 0
|
||||
t = MAKE(x, y);
|
||||
for (i = cx, n = MIN(0, i + 64); i < n; ++i) {
|
||||
|
|
|
@ -19,7 +19,9 @@
|
|||
#include "tool/plinko/lib/plinko.h"
|
||||
|
||||
nosideeffect int CountAtoms(int x, int max, int res) {
|
||||
if (!x || res >= max) return res;
|
||||
if (x > 0) return res + 1;
|
||||
if (!x || res >= max)
|
||||
return res;
|
||||
if (x > 0)
|
||||
return res + 1;
|
||||
return CountAtoms(Cdr(x), max, CountAtoms(Car(x), max, res));
|
||||
}
|
||||
|
|
|
@ -36,8 +36,10 @@ int Define(int e, int a) {
|
|||
struct Gc *G;
|
||||
int k, v, x, r, o;
|
||||
DCHECK_EQ(kDefine, Car(e));
|
||||
if (Cdr(e) >= 0) Error("bad define: %S", e);
|
||||
if (Cadr(e) <= 0) Error("scheme define: %S", e);
|
||||
if (Cdr(e) >= 0)
|
||||
Error("bad define: %S", e);
|
||||
if (Cadr(e) <= 0)
|
||||
Error("scheme define: %S", e);
|
||||
if (Cddr(e) >= 0 || Caddr(e) == kLambda) {
|
||||
/*
|
||||
* compatibility with sectorlisp friendly branch, e.g.
|
||||
|
|
|
@ -55,7 +55,8 @@ struct T DispatchYcombine(dword ea, dword tm, dword r, dword p1, dword p2,
|
|||
lambda = recurse(MAKE(Cadr(ea), HI(ea)), p1, p2);
|
||||
closure =
|
||||
recurse(MAKE(Caddr(ycomb), Alist(Car(Cadr(ycomb)), lambda, 0)), 0, 0);
|
||||
if (Car(lambda) == kClosure) lambda = Car(Cdr(lambda));
|
||||
if (Car(lambda) == kClosure)
|
||||
lambda = Car(Cdr(lambda));
|
||||
DCHECK_EQ(kClosure, Car(closure));
|
||||
DCHECK_EQ(kLambda, Car(lambda));
|
||||
DCHECK_EQ(kLambda, Car(Car(Cdr(closure))));
|
||||
|
|
|
@ -51,7 +51,8 @@ relegated wontreturn void StackOverflow(void) {
|
|||
}
|
||||
|
||||
relegated wontreturn void React(int e, int x, int k) {
|
||||
if (!sp || e != LO(GetCurrentFrame())) Push(e);
|
||||
if (!sp || e != LO(GetCurrentFrame()))
|
||||
Push(e);
|
||||
Push(x);
|
||||
Raise(k);
|
||||
}
|
||||
|
|
|
@ -20,8 +20,10 @@
|
|||
#include "tool/plinko/lib/plinko.h"
|
||||
|
||||
int Evlis(int x, int a, dword p1, dword p2) {
|
||||
if (!x) return x;
|
||||
if (x > 0) return FasterRecurse(x, a, p1, p2);
|
||||
if (!x)
|
||||
return x;
|
||||
if (x > 0)
|
||||
return FasterRecurse(x, a, p1, p2);
|
||||
int y = FasterRecurse(Car(x), a, p1, p2);
|
||||
return Cons(y, Evlis(Cdr(x), a, p1, p2));
|
||||
}
|
||||
|
|
|
@ -26,8 +26,10 @@
|
|||
|
||||
int Exlis(int x, int a) {
|
||||
int y;
|
||||
if (!x) return x;
|
||||
if (x > 0) return expand(x, a);
|
||||
if (!x)
|
||||
return x;
|
||||
if (x > 0)
|
||||
return expand(x, a);
|
||||
y = expand(Car(x), a);
|
||||
return Keep(x, Cons(y, Exlis(Cdr(x), a)));
|
||||
}
|
||||
|
@ -37,10 +39,13 @@ static int Expander(int e, int a) {
|
|||
for (s = 0;;) {
|
||||
DCHECK_LT(e, TERM);
|
||||
DCHECK_LE(a, 0);
|
||||
if (e >= 0) return e;
|
||||
if (e >= 0)
|
||||
return e;
|
||||
if ((f = Car(e)) > 0) {
|
||||
if (f == kQuote) return e;
|
||||
if (f == kClosure) return e;
|
||||
if (f == kQuote)
|
||||
return e;
|
||||
if (f == kClosure)
|
||||
return e;
|
||||
if (f == kTrace) {
|
||||
START_TRACE;
|
||||
x = Cadr(e);
|
||||
|
@ -49,14 +54,17 @@ static int Expander(int e, int a) {
|
|||
END_TRACE;
|
||||
return e;
|
||||
}
|
||||
if (HasAtom(f, s)) return e;
|
||||
if (HasAtom(f, s))
|
||||
return e;
|
||||
s = Cons(f, s);
|
||||
}
|
||||
e = Exlis(e, a);
|
||||
if (f >= 0) {
|
||||
if (!(f = Assoc(f, a))) return e;
|
||||
if (!(f = Assoc(f, a)))
|
||||
return e;
|
||||
f = Cdr(f);
|
||||
if (f >= 0) return e;
|
||||
if (f >= 0)
|
||||
return e;
|
||||
}
|
||||
if (Car(f) == kClosure) {
|
||||
u = Cddr(f);
|
||||
|
@ -64,7 +72,8 @@ static int Expander(int e, int a) {
|
|||
} else {
|
||||
u = a;
|
||||
}
|
||||
if (Head(f) != kMacro) return e;
|
||||
if (Head(f) != kMacro)
|
||||
return e;
|
||||
e = eval(Caddr(f), pairlis(Cadr(f), Cdr(e), u));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,8 @@ struct Gc *NewGc(int A) {
|
|||
struct Gc *G;
|
||||
DCHECK_LE(B, A);
|
||||
DCHECK_LE(A, 0);
|
||||
if (B < cHeap) cHeap = B;
|
||||
if (B < cHeap)
|
||||
cHeap = B;
|
||||
n = ROUNDUP(A - B, DWBITS) / DWBITS;
|
||||
G = Addr(BANE);
|
||||
bzero(G->M, n * sizeof(G->M[0]));
|
||||
|
@ -65,7 +66,8 @@ void Marker(const dword M[], int A, int x) {
|
|||
dword t;
|
||||
do {
|
||||
i = ~(x - A);
|
||||
if (HasBit(M, i)) return;
|
||||
if (HasBit(M, i))
|
||||
return;
|
||||
SetBit((void *)M, i);
|
||||
if (HI(GetShadow(x)) < A) {
|
||||
Marker(M, A, HI(GetShadow(x)));
|
||||
|
@ -118,7 +120,8 @@ int Relocater(const dword M[], const unsigned P[], int A, int x) {
|
|||
void Sweep(struct Gc *G) {
|
||||
dword m;
|
||||
int a, b, d, i, j;
|
||||
if (G->noop) return;
|
||||
if (G->noop)
|
||||
return;
|
||||
i = 0;
|
||||
b = d = G->A;
|
||||
for (; i < G->n; ++i) {
|
||||
|
@ -146,7 +149,8 @@ void Sweep(struct Gc *G) {
|
|||
|
||||
int MarkSweep(int A, int x) {
|
||||
struct Gc *G;
|
||||
if (x >= A) return cx = A, x;
|
||||
if (x >= A)
|
||||
return cx = A, x;
|
||||
G = NewGc(A);
|
||||
Mark(G, x);
|
||||
Census(G);
|
||||
|
|
|
@ -19,7 +19,9 @@
|
|||
#include "tool/plinko/lib/plinko.h"
|
||||
|
||||
nosideeffect bool HasAtom(int v, int x) {
|
||||
if (!x) return false;
|
||||
if (x > 0) return v == x;
|
||||
if (!x)
|
||||
return false;
|
||||
if (x > 0)
|
||||
return v == x;
|
||||
return HasAtom(v, Car(x)) || HasAtom(v, Cdr(x));
|
||||
}
|
||||
|
|
|
@ -27,10 +27,12 @@ void PrintHistogram(int fd, const char *s, const long *h, size_t n) {
|
|||
int j, p, m;
|
||||
char buf[101];
|
||||
size_t i, logos;
|
||||
if (!(t = GetLongSum(h, n))) return;
|
||||
if (!(t = GetLongSum(h, n)))
|
||||
return;
|
||||
Fprintf(fd, "%s%n", s);
|
||||
for (i = 0; i < n; ++i) {
|
||||
if (!h[i]) continue;
|
||||
if (!h[i])
|
||||
continue;
|
||||
p = h[i] * 1000000 / t;
|
||||
assert(0 <= p && p <= 1000000);
|
||||
for (j = 0, m = p / 10000; j < m; ++j) {
|
||||
|
|
|
@ -28,16 +28,20 @@
|
|||
*/
|
||||
int IsCar(int x_) {
|
||||
dword w_;
|
||||
if (x_ >= 0) return 0;
|
||||
if (x_ >= 0)
|
||||
return 0;
|
||||
w_ = Get(x_); // (⍅ X)
|
||||
int ax_ = LO(w_);
|
||||
int dx_ = HI(w_);
|
||||
if (ax_ != kCar) return 0;
|
||||
if (dx_ >= 0) return 0;
|
||||
if (ax_ != kCar)
|
||||
return 0;
|
||||
if (dx_ >= 0)
|
||||
return 0;
|
||||
w_ = Get(dx_); // (X)
|
||||
int adx_ = LO(w_);
|
||||
int ddx_ = HI(w_);
|
||||
int X = adx_;
|
||||
if (ddx_) return 0;
|
||||
if (ddx_)
|
||||
return 0;
|
||||
return X;
|
||||
}
|
||||
|
|
|
@ -28,16 +28,20 @@
|
|||
*/
|
||||
int IsCdr(int x_) {
|
||||
dword w_;
|
||||
if (x_ >= 0) return 0;
|
||||
if (x_ >= 0)
|
||||
return 0;
|
||||
w_ = Get(x_); // (⍆ X)
|
||||
int ax_ = LO(w_);
|
||||
int dx_ = HI(w_);
|
||||
if (ax_ != kCdr) return 0;
|
||||
if (dx_ >= 0) return 0;
|
||||
if (ax_ != kCdr)
|
||||
return 0;
|
||||
if (dx_ >= 0)
|
||||
return 0;
|
||||
w_ = Get(dx_); // (X)
|
||||
int adx_ = LO(w_);
|
||||
int ddx_ = HI(w_);
|
||||
int X = adx_;
|
||||
if (ddx_) return 0;
|
||||
if (ddx_)
|
||||
return 0;
|
||||
return X;
|
||||
}
|
||||
|
|
|
@ -20,9 +20,13 @@
|
|||
|
||||
pureconst bool IsConstant(int e) {
|
||||
unsigned f = LO(GetShadow(e));
|
||||
if (f == EncodeDispatchFn(DispatchNil)) return true;
|
||||
if (f == EncodeDispatchFn(DispatchTrue)) return true;
|
||||
if (f == EncodeDispatchFn(DispatchPrecious)) return true;
|
||||
if (f == EncodeDispatchFn(DispatchQuote)) return true;
|
||||
if (f == EncodeDispatchFn(DispatchNil))
|
||||
return true;
|
||||
if (f == EncodeDispatchFn(DispatchTrue))
|
||||
return true;
|
||||
if (f == EncodeDispatchFn(DispatchPrecious))
|
||||
return true;
|
||||
if (f == EncodeDispatchFn(DispatchQuote))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -30,25 +30,32 @@
|
|||
*/
|
||||
int IsDelegate(int x_) {
|
||||
dword w_;
|
||||
if (x_ >= 0) return 0;
|
||||
if (x_ >= 0)
|
||||
return 0;
|
||||
w_ = Get(x_); // (λ V (F . V) . Q)
|
||||
int ax_ = LO(w_);
|
||||
int dx_ = HI(w_);
|
||||
if (ax_ != kLambda) return 0;
|
||||
if (dx_ >= 0) return 0;
|
||||
if (ax_ != kLambda)
|
||||
return 0;
|
||||
if (dx_ >= 0)
|
||||
return 0;
|
||||
w_ = Get(dx_); // (V (F . V) . Q)
|
||||
int adx_ = LO(w_);
|
||||
int ddx_ = HI(w_);
|
||||
int V = adx_;
|
||||
if (V <= 0) return 0;
|
||||
if (ddx_ >= 0) return 0;
|
||||
if (V <= 0)
|
||||
return 0;
|
||||
if (ddx_ >= 0)
|
||||
return 0;
|
||||
w_ = Get(ddx_); // ((F . V) . Q)
|
||||
int addx_ = LO(w_);
|
||||
if (addx_ >= 0) return 0;
|
||||
if (addx_ >= 0)
|
||||
return 0;
|
||||
w_ = Get(addx_); // (F . V)
|
||||
int aaddx_ = LO(w_);
|
||||
int daddx_ = HI(w_);
|
||||
int F = aaddx_;
|
||||
if (daddx_ != V) return 0;
|
||||
if (daddx_ != V)
|
||||
return 0;
|
||||
return F;
|
||||
}
|
||||
|
|
|
@ -28,36 +28,46 @@
|
|||
*/
|
||||
struct qword IsIf(int x_) {
|
||||
dword w_;
|
||||
if (x_ >= 0) return ZERO4;
|
||||
if (x_ >= 0)
|
||||
return ZERO4;
|
||||
w_ = Get(x_); // (ζ (X Y) (Z))
|
||||
int ax_ = LO(w_);
|
||||
int dx_ = HI(w_);
|
||||
if (ax_ != kCond) return ZERO4;
|
||||
if (dx_ >= 0) return ZERO4;
|
||||
if (ax_ != kCond)
|
||||
return ZERO4;
|
||||
if (dx_ >= 0)
|
||||
return ZERO4;
|
||||
w_ = Get(dx_); // ((X Y) (Z))
|
||||
int adx_ = LO(w_);
|
||||
int ddx_ = HI(w_);
|
||||
if (adx_ >= 0) return ZERO4;
|
||||
if (adx_ >= 0)
|
||||
return ZERO4;
|
||||
w_ = Get(adx_); // (X Y)
|
||||
int aadx_ = LO(w_);
|
||||
int dadx_ = HI(w_);
|
||||
if (ddx_ >= 0) return ZERO4;
|
||||
if (ddx_ >= 0)
|
||||
return ZERO4;
|
||||
w_ = Get(ddx_); // ((Z))
|
||||
int addx_ = LO(w_);
|
||||
int dddx_ = HI(w_);
|
||||
int X = aadx_;
|
||||
if (addx_ >= 0) return ZERO4;
|
||||
if (addx_ >= 0)
|
||||
return ZERO4;
|
||||
w_ = Get(addx_); // (Z)
|
||||
int aaddx_ = LO(w_);
|
||||
int daddx_ = HI(w_);
|
||||
if (dadx_ >= 0) return ZERO4;
|
||||
if (dadx_ >= 0)
|
||||
return ZERO4;
|
||||
w_ = Get(dadx_); // (Y)
|
||||
int adadx_ = LO(w_);
|
||||
int ddadx_ = HI(w_);
|
||||
if (dddx_) return ZERO4;
|
||||
if (dddx_)
|
||||
return ZERO4;
|
||||
int Y = adadx_;
|
||||
int Z = aaddx_;
|
||||
if (ddadx_) return ZERO4;
|
||||
if (daddx_) return ZERO4;
|
||||
if (ddadx_)
|
||||
return ZERO4;
|
||||
if (daddx_)
|
||||
return ZERO4;
|
||||
return MAKE4(X, Y, Z, 0);
|
||||
}
|
||||
|
|
|
@ -34,138 +34,190 @@
|
|||
*/
|
||||
bool IsYcombinator(int x_) {
|
||||
dword w_;
|
||||
if (x_ >= 0) return false;
|
||||
if (x_ >= 0)
|
||||
return false;
|
||||
w_ = Get(x_);
|
||||
int ax_ = LO(w_);
|
||||
int dx_ = HI(w_);
|
||||
if (ax_ != kClosure) return false;
|
||||
if (dx_ >= 0) return false;
|
||||
if (ax_ != kClosure)
|
||||
return false;
|
||||
if (dx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(dx_); // ((λ (N) ((λ (W) (W W)) (λ (V) (N (λ M ((V V) . M)))))) . Q)
|
||||
int adx_ = LO(w_);
|
||||
if (adx_ >= 0) return false;
|
||||
if (adx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(adx_); // (λ (N) ((λ (W) (W W)) (λ (V) (N (λ M ((V V) . M))))))
|
||||
int aadx_ = LO(w_);
|
||||
int dadx_ = HI(w_);
|
||||
if (aadx_ != kLambda) return false;
|
||||
if (dadx_ >= 0) return false;
|
||||
if (aadx_ != kLambda)
|
||||
return false;
|
||||
if (dadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(dadx_); // ((N) ((λ (W) (W W)) (λ (V) (N (λ M ((V V) . M))))))
|
||||
int adadx_ = LO(w_);
|
||||
int ddadx_ = HI(w_);
|
||||
if (adadx_ >= 0) return false;
|
||||
if (adadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(adadx_); // (N)
|
||||
int aadadx_ = LO(w_);
|
||||
int dadadx_ = HI(w_);
|
||||
if (ddadx_ >= 0) return false;
|
||||
if (ddadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(ddadx_); // (((λ (W) (W W)) (λ (V) (N (λ M ((V V) . M))))))
|
||||
int addadx_ = LO(w_);
|
||||
int dddadx_ = HI(w_);
|
||||
int N = aadadx_;
|
||||
if (N <= 0) return false;
|
||||
if (addadx_ >= 0) return false;
|
||||
if (N <= 0)
|
||||
return false;
|
||||
if (addadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(addadx_); // ((λ (W) (W W)) (λ (V) (N (λ M ((V V) . M)))))
|
||||
int aaddadx_ = LO(w_);
|
||||
int daddadx_ = HI(w_);
|
||||
if (dadadx_) return false;
|
||||
if (dddadx_) return false;
|
||||
if (aaddadx_ >= 0) return false;
|
||||
if (dadadx_)
|
||||
return false;
|
||||
if (dddadx_)
|
||||
return false;
|
||||
if (aaddadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(aaddadx_); // (λ (W) (W W))
|
||||
int aaaddadx_ = LO(w_);
|
||||
int daaddadx_ = HI(w_);
|
||||
if (daddadx_ >= 0) return false;
|
||||
if (daddadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(daddadx_); // ((λ (V) (N (λ M ((V V) . M)))))
|
||||
int adaddadx_ = LO(w_);
|
||||
int ddaddadx_ = HI(w_);
|
||||
if (aaaddadx_ != kLambda) return false;
|
||||
if (adaddadx_ >= 0) return false;
|
||||
if (aaaddadx_ != kLambda)
|
||||
return false;
|
||||
if (adaddadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(adaddadx_); // (λ (V) (N (λ M ((V V) . M))))
|
||||
int aadaddadx_ = LO(w_);
|
||||
int dadaddadx_ = HI(w_);
|
||||
if (daaddadx_ >= 0) return false;
|
||||
if (daaddadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(daaddadx_); // ((W) (W W))
|
||||
int adaaddadx_ = LO(w_);
|
||||
int ddaaddadx_ = HI(w_);
|
||||
if (ddaddadx_) return false;
|
||||
if (adaaddadx_ >= 0) return false;
|
||||
if (ddaddadx_)
|
||||
return false;
|
||||
if (adaaddadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(adaaddadx_); // (W)
|
||||
int aadaaddadx_ = LO(w_);
|
||||
int dadaaddadx_ = HI(w_);
|
||||
if (aadaddadx_ != kLambda) return false;
|
||||
if (ddaaddadx_ >= 0) return false;
|
||||
if (aadaddadx_ != kLambda)
|
||||
return false;
|
||||
if (ddaaddadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(ddaaddadx_); // ((W W))
|
||||
int addaaddadx_ = LO(w_);
|
||||
int dddaaddadx_ = HI(w_);
|
||||
if (dadaddadx_ >= 0) return false;
|
||||
if (dadaddadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(dadaddadx_); // ((V) (N (λ M ((V V) . M))))
|
||||
int adadaddadx_ = LO(w_);
|
||||
int ddadaddadx_ = HI(w_);
|
||||
int W = aadaaddadx_;
|
||||
if (W <= 0) return false;
|
||||
if (adadaddadx_ >= 0) return false;
|
||||
if (W <= 0)
|
||||
return false;
|
||||
if (adadaddadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(adadaddadx_); // (V)
|
||||
int aadadaddadx_ = LO(w_);
|
||||
int dadadaddadx_ = HI(w_);
|
||||
if (addaaddadx_ >= 0) return false;
|
||||
if (addaaddadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(addaaddadx_); // (W W)
|
||||
int aaddaaddadx_ = LO(w_);
|
||||
int daddaaddadx_ = HI(w_);
|
||||
if (ddadaddadx_ >= 0) return false;
|
||||
if (ddadaddadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(ddadaddadx_); // ((N (λ M ((V V) . M))))
|
||||
int addadaddadx_ = LO(w_);
|
||||
int dddadaddadx_ = HI(w_);
|
||||
if (dadaaddadx_) return false;
|
||||
if (dadaaddadx_)
|
||||
return false;
|
||||
int V = aadadaddadx_;
|
||||
if (V <= 0) return false;
|
||||
if (dddaaddadx_) return false;
|
||||
if (addadaddadx_ >= 0) return false;
|
||||
if (V <= 0)
|
||||
return false;
|
||||
if (dddaaddadx_)
|
||||
return false;
|
||||
if (addadaddadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(addadaddadx_); // (N (λ M ((V V) . M)))
|
||||
int aaddadaddadx_ = LO(w_);
|
||||
int daddadaddadx_ = HI(w_);
|
||||
if (aaddaaddadx_ != W) return false;
|
||||
if (dadadaddadx_) return false;
|
||||
if (daddaaddadx_ >= 0) return false;
|
||||
if (aaddaaddadx_ != W)
|
||||
return false;
|
||||
if (dadadaddadx_)
|
||||
return false;
|
||||
if (daddaaddadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(daddaaddadx_); // (W)
|
||||
int adaddaaddadx_ = LO(w_);
|
||||
int ddaddaaddadx_ = HI(w_);
|
||||
if (dddadaddadx_) return false;
|
||||
if (adaddaaddadx_ != W) return false;
|
||||
if (aaddadaddadx_ != N) return false;
|
||||
if (ddaddaaddadx_) return false;
|
||||
if (daddadaddadx_ >= 0) return false;
|
||||
if (dddadaddadx_)
|
||||
return false;
|
||||
if (adaddaaddadx_ != W)
|
||||
return false;
|
||||
if (aaddadaddadx_ != N)
|
||||
return false;
|
||||
if (ddaddaaddadx_)
|
||||
return false;
|
||||
if (daddadaddadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(daddadaddadx_); // ((λ M ((V V) . M)))
|
||||
int adaddadaddadx_ = LO(w_);
|
||||
int ddaddadaddadx_ = HI(w_);
|
||||
if (adaddadaddadx_ >= 0) return false;
|
||||
if (adaddadaddadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(adaddadaddadx_); // (λ M ((V V) . M))
|
||||
int aadaddadaddadx_ = LO(w_);
|
||||
int dadaddadaddadx_ = HI(w_);
|
||||
if (ddaddadaddadx_) return false;
|
||||
if (aadaddadaddadx_ != kLambda) return false;
|
||||
if (dadaddadaddadx_ >= 0) return false;
|
||||
if (ddaddadaddadx_)
|
||||
return false;
|
||||
if (aadaddadaddadx_ != kLambda)
|
||||
return false;
|
||||
if (dadaddadaddadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(dadaddadaddadx_); // (M ((V V) . M))
|
||||
int adadaddadaddadx_ = LO(w_);
|
||||
int ddadaddadaddadx_ = HI(w_);
|
||||
int M = adadaddadaddadx_;
|
||||
if (M <= 0) return false;
|
||||
if (ddadaddadaddadx_ >= 0) return false;
|
||||
if (M <= 0)
|
||||
return false;
|
||||
if (ddadaddadaddadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(ddadaddadaddadx_); // (((V V) . M))
|
||||
int addadaddadaddadx_ = LO(w_);
|
||||
int dddadaddadaddadx_ = HI(w_);
|
||||
if (addadaddadaddadx_ >= 0) return false;
|
||||
if (addadaddadaddadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(addadaddadaddadx_); // ((V V) . M)
|
||||
int aaddadaddadaddadx_ = LO(w_);
|
||||
int daddadaddadaddadx_ = HI(w_);
|
||||
if (dddadaddadaddadx_) return false;
|
||||
if (aaddadaddadaddadx_ >= 0) return false;
|
||||
if (dddadaddadaddadx_)
|
||||
return false;
|
||||
if (aaddadaddadaddadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(aaddadaddadaddadx_); // (V V)
|
||||
int aaaddadaddadaddadx_ = LO(w_);
|
||||
int daaddadaddadaddadx_ = HI(w_);
|
||||
if (daddadaddadaddadx_ != M) return false;
|
||||
if (aaaddadaddadaddadx_ != V) return false;
|
||||
if (daaddadaddadaddadx_ >= 0) return false;
|
||||
if (daddadaddadaddadx_ != M)
|
||||
return false;
|
||||
if (aaaddadaddadaddadx_ != V)
|
||||
return false;
|
||||
if (daaddadaddadaddadx_ >= 0)
|
||||
return false;
|
||||
w_ = Get(daaddadaddadaddadx_); // (V)
|
||||
int adaaddadaddadaddadx_ = LO(w_);
|
||||
int ddaaddadaddadaddadx_ = HI(w_);
|
||||
if (adaaddadaddadaddadx_ != V) return false;
|
||||
if (ddaaddadaddadaddadx_) return false;
|
||||
if (adaaddadaddadaddadx_ != V)
|
||||
return false;
|
||||
if (ddaaddadaddadaddadx_)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -21,14 +21,18 @@
|
|||
bool MakesClosures(int x) {
|
||||
int h;
|
||||
if (x < 0 && (h = Car(x)) != kQuote && h != kClosure) {
|
||||
if (h == kMacro) return true;
|
||||
if (h == kLambda) return true;
|
||||
if (h == kMacro)
|
||||
return true;
|
||||
if (h == kLambda)
|
||||
return true;
|
||||
if (h == kCond) {
|
||||
while ((x = Cdr(x)) < 0) {
|
||||
if ((h = Car(x)) < 0) {
|
||||
if (MakesClosures(Car(h))) return true;
|
||||
if (MakesClosures(Car(h)))
|
||||
return true;
|
||||
if ((h = Cdr(h)) < 0) {
|
||||
if (MakesClosures(Car(h))) return true;
|
||||
if (MakesClosures(Car(h)))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,10 @@
|
|||
#include "tool/plinko/lib/plinko.h"
|
||||
|
||||
int Pairlis(int x, int y, int a) {
|
||||
if (!x) return a;
|
||||
if (x > 0) return Alist(x, y, a);
|
||||
if (!x)
|
||||
return a;
|
||||
if (x > 0)
|
||||
return Alist(x, y, a);
|
||||
if (y <= 0) {
|
||||
a = pairlis(Cdr(x), Cdr(y), a);
|
||||
return Car(x) ? pairlis(Car(x), Car(y), a) : a;
|
||||
|
|
|
@ -28,9 +28,12 @@
|
|||
nosideeffect int CountSimpleParameters(int x) {
|
||||
int i;
|
||||
for (i = 0; x; ++i, x = Cdr(x)) {
|
||||
if (x > 0) return -1; // variadic args aren't simple
|
||||
if (!Car(x)) return -1; // nil parameters aren't simple
|
||||
if (Car(x) < 0) return -1; // destructured parameters aren't simple
|
||||
if (x > 0)
|
||||
return -1; // variadic args aren't simple
|
||||
if (!Car(x))
|
||||
return -1; // nil parameters aren't simple
|
||||
if (Car(x) < 0)
|
||||
return -1; // destructured parameters aren't simple
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
@ -38,157 +41,201 @@ nosideeffect int CountSimpleParameters(int x) {
|
|||
nosideeffect int CountSimpleArguments(int x) {
|
||||
int i;
|
||||
for (i = 0; x; ++i, x = Cdr(x)) {
|
||||
if (x > 0) return -1; // apply isn't simple
|
||||
if (x > 0)
|
||||
return -1; // apply isn't simple
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
static dword PlanQuote(int e, int a, int s) {
|
||||
if (Cdr(e) >= 0) React(e, e, kQuote); // one normal parameter required
|
||||
if (Cdr(e) >= 0)
|
||||
React(e, e, kQuote); // one normal parameter required
|
||||
return MAKE(DF(DispatchQuote), Cadr(e)); // >1 prms is sectorlisp comment
|
||||
}
|
||||
|
||||
static dword PlanCar(int e, int a, int s) {
|
||||
if (!Cdr(e)) return DF(DispatchNil); // (⍅) ⟺ (⍅ ⊥)
|
||||
if (Cddr(e)) React(e, e, kCar); // too many args
|
||||
if (!Cadr(e)) return DF(DispatchNil);
|
||||
if (!Cdr(e))
|
||||
return DF(DispatchNil); // (⍅) ⟺ (⍅ ⊥)
|
||||
if (Cddr(e))
|
||||
React(e, e, kCar); // too many args
|
||||
if (!Cadr(e))
|
||||
return DF(DispatchNil);
|
||||
return MAKE(DF(DispatchCar), Cadr(e));
|
||||
}
|
||||
|
||||
static dword PlanCdr(int e, int a, int s) {
|
||||
if (!Cdr(e)) return DF(DispatchNil); // (⍆) ⟺ (⍆ ⊥)
|
||||
if (Cddr(e)) React(e, e, kCdr); // too many args
|
||||
if (!ARG1(e)) return DF(DispatchNil);
|
||||
if (!Cdr(e))
|
||||
return DF(DispatchNil); // (⍆) ⟺ (⍆ ⊥)
|
||||
if (Cddr(e))
|
||||
React(e, e, kCdr); // too many args
|
||||
if (!ARG1(e))
|
||||
return DF(DispatchNil);
|
||||
return MAKE(DF(DispatchCdr), Cadr(e));
|
||||
}
|
||||
|
||||
static dword PlanAtom(int e, int a, int s) {
|
||||
if (CountSimpleArguments(Cdr(e)) != 1) React(e, e, kAtom);
|
||||
if (CountSimpleArguments(Cdr(e)) != 1)
|
||||
React(e, e, kAtom);
|
||||
return MAKE(DF(DispatchAtom), Cadr(e));
|
||||
}
|
||||
|
||||
static dword PlanEq(int e, int a, int s) {
|
||||
int n = CountSimpleArguments(Cdr(e));
|
||||
if (n != 2 && n != 1) React(e, e, kAtom); // (≡ 𝑥) is our (null 𝑥)
|
||||
if (n != 2 && n != 1)
|
||||
React(e, e, kAtom); // (≡ 𝑥) is our (null 𝑥)
|
||||
return MAKE(DF(DispatchEq), Caddr(e));
|
||||
}
|
||||
|
||||
static dword PlanCmp(int e, int a, int s) {
|
||||
if (CountSimpleArguments(Cdr(e)) != 2) React(e, e, kCmp);
|
||||
if (CountSimpleArguments(Cdr(e)) != 2)
|
||||
React(e, e, kCmp);
|
||||
return MAKE(DF(DispatchCmp), Caddr(e));
|
||||
}
|
||||
|
||||
static dword PlanOrder(int e, int a, int s) {
|
||||
if (CountSimpleArguments(Cdr(e)) != 2) React(e, e, kOrder);
|
||||
if (CountSimpleArguments(Cdr(e)) != 2)
|
||||
React(e, e, kOrder);
|
||||
return MAKE(DF(DispatchOrder), Caddr(e));
|
||||
}
|
||||
|
||||
static dword PlanCons(int e, int a, int s) {
|
||||
int p = CountSimpleArguments(Cdr(e));
|
||||
if (p == -1) Error("cons dot arg");
|
||||
if (p > 2) Error("too many args");
|
||||
if (p == -1)
|
||||
Error("cons dot arg");
|
||||
if (p > 2)
|
||||
Error("too many args");
|
||||
return MAKE(DF(DispatchCons), Caddr(e));
|
||||
}
|
||||
|
||||
static dword PlanLambda(int e, int a, int s) {
|
||||
if (CountSimpleArguments(Cdr(e)) == -1) Error("bad lambda: %S", e);
|
||||
if (CountSimpleArguments(Cdr(e)) == -1)
|
||||
Error("bad lambda: %S", e);
|
||||
return DF(DispatchLambda);
|
||||
}
|
||||
|
||||
static dword PlanCond(int e, int a, int s) {
|
||||
int x;
|
||||
if (!Cdr(e)) return DF(DispatchNil); // (ζ) ⟺ ⊥
|
||||
if (!Cdr(e))
|
||||
return DF(DispatchNil); // (ζ) ⟺ ⊥
|
||||
for (x = e; (x = Cdr(x));) {
|
||||
if (x > 0) React(e, e, kCond); // (ζ . 𝑣) not allowed
|
||||
if (Car(x) >= 0) React(e, e, kCond); // (ζ 𝑣) not allowed
|
||||
if (Cdr(Car(x)) > 0) React(e, e, kCond); // (ζ (𝑥 . 𝑣)) not allowed
|
||||
if (x > 0)
|
||||
React(e, e, kCond); // (ζ . 𝑣) not allowed
|
||||
if (Car(x) >= 0)
|
||||
React(e, e, kCond); // (ζ 𝑣) not allowed
|
||||
if (Cdr(Car(x)) > 0)
|
||||
React(e, e, kCond); // (ζ (𝑥 . 𝑣)) not allowed
|
||||
}
|
||||
return MAKE(DF(DispatchCond), Cdr(e));
|
||||
}
|
||||
|
||||
static dword PlanProgn(int e, int a, int s) {
|
||||
if (!Cdr(e)) return DF(DispatchNil); // (progn) ⟺ ⊥
|
||||
if (CountSimpleArguments(Cdr(e)) == -1) React(e, e, kProgn);
|
||||
if (!Cdr(e))
|
||||
return DF(DispatchNil); // (progn) ⟺ ⊥
|
||||
if (CountSimpleArguments(Cdr(e)) == -1)
|
||||
React(e, e, kProgn);
|
||||
return MAKE(DF(DispatchProgn), Cdr(e));
|
||||
}
|
||||
|
||||
static dword PlanQuiet(int e, int a, int s) {
|
||||
if (Cdr(e) > 0) React(e, e, kQuiet); // apply not allowed
|
||||
if (!Cdr(e)) React(e, e, kQuiet); // zero args not allowed
|
||||
if (Cdr(Cdr(e))) React(e, e, kQuiet); // >1 args not allowed
|
||||
if (Cdr(e) > 0)
|
||||
React(e, e, kQuiet); // apply not allowed
|
||||
if (!Cdr(e))
|
||||
React(e, e, kQuiet); // zero args not allowed
|
||||
if (Cdr(Cdr(e)))
|
||||
React(e, e, kQuiet); // >1 args not allowed
|
||||
return DF(DispatchQuiet);
|
||||
}
|
||||
|
||||
static dword PlanTrace(int e, int a, int s) {
|
||||
if (Cdr(e) > 0) React(e, e, kTrace); // apply not allowed
|
||||
if (!Cdr(e)) React(e, e, kTrace); // zero args not allowed
|
||||
if (Cdr(Cdr(e))) React(e, e, kTrace); // >1 args not allowed
|
||||
if (Cdr(e) > 0)
|
||||
React(e, e, kTrace); // apply not allowed
|
||||
if (!Cdr(e))
|
||||
React(e, e, kTrace); // zero args not allowed
|
||||
if (Cdr(Cdr(e)))
|
||||
React(e, e, kTrace); // >1 args not allowed
|
||||
return DF(DispatchTrace);
|
||||
}
|
||||
|
||||
static dword PlanFtrace(int e, int a, int s) {
|
||||
if (Cdr(e) > 0) React(e, e, kFtrace); // apply not allowed
|
||||
if (!Cdr(e)) React(e, e, kFtrace); // zero args not allowed
|
||||
if (Cdr(Cdr(e))) React(e, e, kFtrace); // >1 args not allowed
|
||||
if (Cdr(e) > 0)
|
||||
React(e, e, kFtrace); // apply not allowed
|
||||
if (!Cdr(e))
|
||||
React(e, e, kFtrace); // zero args not allowed
|
||||
if (Cdr(Cdr(e)))
|
||||
React(e, e, kFtrace); // >1 args not allowed
|
||||
return DF(DispatchFtrace);
|
||||
}
|
||||
|
||||
static dword PlanFunction(int e, int a, int s) {
|
||||
if (CountSimpleArguments(Cdr(e)) != 1) Raise(kFunction);
|
||||
if (CountSimpleArguments(Cdr(e)) != 1)
|
||||
Raise(kFunction);
|
||||
return MAKE(DF(DispatchFunction), Cadr(e));
|
||||
}
|
||||
|
||||
static dword PlanBeta(int e, int a, int s) {
|
||||
if (CountSimpleArguments(Cdr(e)) != 1) Raise(kBeta);
|
||||
if (CountSimpleArguments(Cdr(e)) != 1)
|
||||
Raise(kBeta);
|
||||
return MAKE(DF(DispatchBeta), Cadr(e));
|
||||
}
|
||||
|
||||
static dword PlanIgnore(int e, int a, int s) {
|
||||
if (!Cdr(e)) return DF(DispatchIgnore0);
|
||||
if (Cdr(e) > 0) React(e, e, kIgnore); // apply not allowed
|
||||
if (!Cdr(e)) React(e, e, kIgnore); // zero args not allowed
|
||||
if (Cdr(Cdr(e))) React(e, e, kIgnore); // >1 args not allowed
|
||||
if (!Cdr(e))
|
||||
return DF(DispatchIgnore0);
|
||||
if (Cdr(e) > 0)
|
||||
React(e, e, kIgnore); // apply not allowed
|
||||
if (!Cdr(e))
|
||||
React(e, e, kIgnore); // zero args not allowed
|
||||
if (Cdr(Cdr(e)))
|
||||
React(e, e, kIgnore); // >1 args not allowed
|
||||
return DF(DispatchIgnore1);
|
||||
}
|
||||
|
||||
static dword PlanExpand(int e, int a, int s) {
|
||||
if (CountSimpleArguments(Cdr(e)) != 1) React(e, e, kExpand);
|
||||
if (CountSimpleArguments(Cdr(e)) != 1)
|
||||
React(e, e, kExpand);
|
||||
return MAKE(DF(DispatchExpand), Cadr(e));
|
||||
}
|
||||
|
||||
static dword PlanPrint(int e, int a, int s) {
|
||||
if (CountSimpleArguments(Cdr(e)) == -1) React(e, e, kPrint);
|
||||
if (CountSimpleArguments(Cdr(e)) == -1)
|
||||
React(e, e, kPrint);
|
||||
return DF(DispatchPrint);
|
||||
}
|
||||
|
||||
static dword PlanGensym(int e, int a, int s) {
|
||||
if (CountSimpleArguments(Cdr(e))) React(e, e, kGensym);
|
||||
if (CountSimpleArguments(Cdr(e)))
|
||||
React(e, e, kGensym);
|
||||
return DF(DispatchGensym);
|
||||
}
|
||||
|
||||
static dword PlanPprint(int e, int a, int s) {
|
||||
if (CountSimpleArguments(Cdr(e)) == -1) React(e, e, kPprint);
|
||||
if (CountSimpleArguments(Cdr(e)) == -1)
|
||||
React(e, e, kPprint);
|
||||
return DF(DispatchPprint);
|
||||
}
|
||||
|
||||
static dword PlanPrintheap(int e, int a, int s) {
|
||||
int p = CountSimpleArguments(Cdr(e));
|
||||
if (p != 0 && p != 1) React(e, e, kPrintheap);
|
||||
if (p != 0 && p != 1)
|
||||
React(e, e, kPrintheap);
|
||||
return DF(DispatchPrintheap);
|
||||
}
|
||||
|
||||
static dword PlanGc(int e, int a, int s) {
|
||||
if (CountSimpleArguments(Cdr(e)) != 1) React(e, e, kGc);
|
||||
if (CountSimpleArguments(Cdr(e)) != 1)
|
||||
React(e, e, kGc);
|
||||
return MAKE(DF(DispatchGc), Cadr(e));
|
||||
}
|
||||
|
||||
static dword PlanPrinc(int e, int a, int s) {
|
||||
if (CountSimpleArguments(Cdr(e)) == -1) React(e, e, kPrinc);
|
||||
if (CountSimpleArguments(Cdr(e)) == -1)
|
||||
React(e, e, kPrinc);
|
||||
return DF(DispatchPrinc);
|
||||
}
|
||||
|
||||
static dword PlanFlush(int e, int a, int s) {
|
||||
if (CountSimpleArguments(Cdr(e)) == -1) React(e, e, kFlush);
|
||||
if (CountSimpleArguments(Cdr(e)) == -1)
|
||||
React(e, e, kFlush);
|
||||
return DF(DispatchFlush);
|
||||
}
|
||||
|
||||
|
@ -197,12 +244,14 @@ static dword PlanError(int e, int a, int s) {
|
|||
}
|
||||
|
||||
static dword PlanExit(int e, int a, int s) {
|
||||
if (Cdr(e)) React(e, e, kExit);
|
||||
if (Cdr(e))
|
||||
React(e, e, kExit);
|
||||
return DF(DispatchExit);
|
||||
}
|
||||
|
||||
static dword PlanRead(int e, int a, int s) {
|
||||
if (Cdr(e)) React(e, e, kRead);
|
||||
if (Cdr(e))
|
||||
React(e, e, kRead);
|
||||
return DF(DispatchRead);
|
||||
}
|
||||
|
||||
|
@ -216,16 +265,20 @@ static dword PlanClosure(int e, int a, int s) {
|
|||
|
||||
static dword PlanLet(int e, int a, int s) {
|
||||
int n;
|
||||
if ((n = CountSimpleArguments(Cdr(e))) == -1) return DF(DispatchFuncall);
|
||||
if (CountSimpleArguments(Car(e)) < 3) React(e, e, kLambda); // need (λ 𝑥 𝑦)
|
||||
if ((n = CountSimpleArguments(Cdr(e))) == -1)
|
||||
return DF(DispatchFuncall);
|
||||
if (CountSimpleArguments(Car(e)) < 3)
|
||||
React(e, e, kLambda); // need (λ 𝑥 𝑦)
|
||||
switch (CountSimpleParameters(Cadr(Car(e)))) {
|
||||
case -1:
|
||||
return DF(DispatchFuncall);
|
||||
case 0:
|
||||
if (n != 0) Error("let argument count mismatch: %S", e);
|
||||
if (n != 0)
|
||||
Error("let argument count mismatch: %S", e);
|
||||
return MAKE(DF(DispatchShortcut), Caddr(Car(e))); // ((λ ⊥ 𝑦)) becomes 𝑦
|
||||
case 1:
|
||||
if (n != 1) Error("let argument count mismatch: %S", e);
|
||||
if (n != 1)
|
||||
Error("let argument count mismatch: %S", e);
|
||||
return MAKE(DF(DispatchLet1), Cdar(e));
|
||||
default:
|
||||
return MAKE(DF(DispatchFuncall), 0);
|
||||
|
@ -234,37 +287,68 @@ static dword PlanLet(int e, int a, int s) {
|
|||
|
||||
static dontinline dword PlanPrecious(int e, int a, int s, int f) {
|
||||
DCHECK_GT(f, 0);
|
||||
if (f == kCar) return PlanCar(e, a, s);
|
||||
if (f == kCdr) return PlanCdr(e, a, s);
|
||||
if (f == kGc) return PlanGc(e, a, s);
|
||||
if (f == kEq) return PlanEq(e, a, s);
|
||||
if (f == kCmp) return PlanCmp(e, a, s);
|
||||
if (f == kBeta) return PlanBeta(e, a, s);
|
||||
if (f == kCond) return PlanCond(e, a, s);
|
||||
if (f == kAtom) return PlanAtom(e, a, s);
|
||||
if (f == kCons) return PlanCons(e, a, s);
|
||||
if (f == kExit) return PlanExit(e, a, s);
|
||||
if (f == kRead) return PlanRead(e, a, s);
|
||||
if (f == kOrder) return PlanOrder(e, a, s);
|
||||
if (f == kQuote) return PlanQuote(e, a, s);
|
||||
if (f == kProgn) return PlanProgn(e, a, s);
|
||||
if (f == kQuiet) return PlanQuiet(e, a, s);
|
||||
if (f == kTrace) return PlanTrace(e, a, s);
|
||||
if (f == kPrint) return PlanPrint(e, a, s);
|
||||
if (f == kPrinc) return PlanPrinc(e, a, s);
|
||||
if (f == kFlush) return PlanFlush(e, a, s);
|
||||
if (f == kError) return PlanError(e, a, s);
|
||||
if (f == kMacro) return PlanLambda(e, a, s);
|
||||
if (f == kFtrace) return PlanFtrace(e, a, s);
|
||||
if (f == kLambda) return PlanLambda(e, a, s);
|
||||
if (f == kGensym) return PlanGensym(e, a, s);
|
||||
if (f == kPprint) return PlanPprint(e, a, s);
|
||||
if (f == kIgnore) return PlanIgnore(e, a, s);
|
||||
if (f == kExpand) return PlanExpand(e, a, s);
|
||||
if (f == kDefine) return PlanDefine(e, a, s);
|
||||
if (f == kClosure) return PlanClosure(e, a, s);
|
||||
if (f == kFunction) return PlanFunction(e, a, s);
|
||||
if (f == kPrintheap) return PlanPrintheap(e, a, s);
|
||||
if (f == kCar)
|
||||
return PlanCar(e, a, s);
|
||||
if (f == kCdr)
|
||||
return PlanCdr(e, a, s);
|
||||
if (f == kGc)
|
||||
return PlanGc(e, a, s);
|
||||
if (f == kEq)
|
||||
return PlanEq(e, a, s);
|
||||
if (f == kCmp)
|
||||
return PlanCmp(e, a, s);
|
||||
if (f == kBeta)
|
||||
return PlanBeta(e, a, s);
|
||||
if (f == kCond)
|
||||
return PlanCond(e, a, s);
|
||||
if (f == kAtom)
|
||||
return PlanAtom(e, a, s);
|
||||
if (f == kCons)
|
||||
return PlanCons(e, a, s);
|
||||
if (f == kExit)
|
||||
return PlanExit(e, a, s);
|
||||
if (f == kRead)
|
||||
return PlanRead(e, a, s);
|
||||
if (f == kOrder)
|
||||
return PlanOrder(e, a, s);
|
||||
if (f == kQuote)
|
||||
return PlanQuote(e, a, s);
|
||||
if (f == kProgn)
|
||||
return PlanProgn(e, a, s);
|
||||
if (f == kQuiet)
|
||||
return PlanQuiet(e, a, s);
|
||||
if (f == kTrace)
|
||||
return PlanTrace(e, a, s);
|
||||
if (f == kPrint)
|
||||
return PlanPrint(e, a, s);
|
||||
if (f == kPrinc)
|
||||
return PlanPrinc(e, a, s);
|
||||
if (f == kFlush)
|
||||
return PlanFlush(e, a, s);
|
||||
if (f == kError)
|
||||
return PlanError(e, a, s);
|
||||
if (f == kMacro)
|
||||
return PlanLambda(e, a, s);
|
||||
if (f == kFtrace)
|
||||
return PlanFtrace(e, a, s);
|
||||
if (f == kLambda)
|
||||
return PlanLambda(e, a, s);
|
||||
if (f == kGensym)
|
||||
return PlanGensym(e, a, s);
|
||||
if (f == kPprint)
|
||||
return PlanPprint(e, a, s);
|
||||
if (f == kIgnore)
|
||||
return PlanIgnore(e, a, s);
|
||||
if (f == kExpand)
|
||||
return PlanExpand(e, a, s);
|
||||
if (f == kDefine)
|
||||
return PlanDefine(e, a, s);
|
||||
if (f == kClosure)
|
||||
return PlanClosure(e, a, s);
|
||||
if (f == kFunction)
|
||||
return PlanFunction(e, a, s);
|
||||
if (f == kPrintheap)
|
||||
return PlanPrintheap(e, a, s);
|
||||
if (!a) {
|
||||
Push(e);
|
||||
Push(f);
|
||||
|
@ -280,26 +364,34 @@ dontinline dword Plan(int e, int a, int s) {
|
|||
if ((x1 = IsCar(e))) {
|
||||
if ((x2 = IsCar(x1))) {
|
||||
if ((x3 = IsCar(x2))) {
|
||||
if ((x4 = IsCar(x3))) return MAKE(DF(DispatchCaaaar), x4);
|
||||
if ((x4 = IsCdr(x3))) return MAKE(DF(DispatchCaaadr), x4);
|
||||
if ((x4 = IsCar(x3)))
|
||||
return MAKE(DF(DispatchCaaaar), x4);
|
||||
if ((x4 = IsCdr(x3)))
|
||||
return MAKE(DF(DispatchCaaadr), x4);
|
||||
return MAKE(DF(DispatchCaaar), x3);
|
||||
}
|
||||
if ((x3 = IsCdr(x2))) {
|
||||
if ((x4 = IsCar(x3))) return MAKE(DF(DispatchCaadar), x4);
|
||||
if ((x4 = IsCdr(x3))) return MAKE(DF(DispatchCaaddr), x4);
|
||||
if ((x4 = IsCar(x3)))
|
||||
return MAKE(DF(DispatchCaadar), x4);
|
||||
if ((x4 = IsCdr(x3)))
|
||||
return MAKE(DF(DispatchCaaddr), x4);
|
||||
return MAKE(DF(DispatchCaaar), x3);
|
||||
}
|
||||
return MAKE(DF(DispatchCaar), x2);
|
||||
}
|
||||
if ((x2 = IsCdr(x1))) {
|
||||
if ((x3 = IsCar(x2))) {
|
||||
if ((x4 = IsCar(x3))) return MAKE(DF(DispatchCadaar), x4);
|
||||
if ((x4 = IsCdr(x3))) return MAKE(DF(DispatchCadadr), x4);
|
||||
if ((x4 = IsCar(x3)))
|
||||
return MAKE(DF(DispatchCadaar), x4);
|
||||
if ((x4 = IsCdr(x3)))
|
||||
return MAKE(DF(DispatchCadadr), x4);
|
||||
return MAKE(DF(DispatchCadar), x3);
|
||||
}
|
||||
if ((x3 = IsCdr(x2))) {
|
||||
if ((x4 = IsCar(x3))) return MAKE(DF(DispatchCaddar), x4);
|
||||
if ((x4 = IsCdr(x3))) return MAKE(DF(DispatchCadddr), x4);
|
||||
if ((x4 = IsCar(x3)))
|
||||
return MAKE(DF(DispatchCaddar), x4);
|
||||
if ((x4 = IsCdr(x3)))
|
||||
return MAKE(DF(DispatchCadddr), x4);
|
||||
return MAKE(DF(DispatchCaddr), x3);
|
||||
}
|
||||
return MAKE(DF(DispatchCadr), x2);
|
||||
|
@ -310,26 +402,34 @@ dontinline dword Plan(int e, int a, int s) {
|
|||
if ((x1 = IsCdr(e))) {
|
||||
if ((x2 = IsCar(x1))) {
|
||||
if ((x3 = IsCar(x2))) {
|
||||
if ((x4 = IsCar(x3))) return MAKE(DF(DispatchCdaaar), x4);
|
||||
if ((x4 = IsCdr(x3))) return MAKE(DF(DispatchCdaadr), x4);
|
||||
if ((x4 = IsCar(x3)))
|
||||
return MAKE(DF(DispatchCdaaar), x4);
|
||||
if ((x4 = IsCdr(x3)))
|
||||
return MAKE(DF(DispatchCdaadr), x4);
|
||||
return MAKE(DF(DispatchCdaar), x3);
|
||||
}
|
||||
if ((x3 = IsCdr(x2))) {
|
||||
if ((x4 = IsCar(x3))) return MAKE(DF(DispatchCdadar), x4);
|
||||
if ((x4 = IsCdr(x3))) return MAKE(DF(DispatchCdaddr), x4);
|
||||
if ((x4 = IsCar(x3)))
|
||||
return MAKE(DF(DispatchCdadar), x4);
|
||||
if ((x4 = IsCdr(x3)))
|
||||
return MAKE(DF(DispatchCdaddr), x4);
|
||||
return MAKE(DF(DispatchCdadr), x3);
|
||||
}
|
||||
return MAKE(DF(DispatchCdar), x2);
|
||||
}
|
||||
if ((x2 = IsCdr(x1))) {
|
||||
if ((x3 = IsCar(x2))) {
|
||||
if ((x4 = IsCar(x3))) return MAKE(DF(DispatchCddaar), x4);
|
||||
if ((x4 = IsCdr(x3))) return MAKE(DF(DispatchCddadr), x4);
|
||||
if ((x4 = IsCar(x3)))
|
||||
return MAKE(DF(DispatchCddaar), x4);
|
||||
if ((x4 = IsCdr(x3)))
|
||||
return MAKE(DF(DispatchCddadr), x4);
|
||||
return MAKE(DF(DispatchCddar), x3);
|
||||
}
|
||||
if ((x3 = IsCdr(x2))) {
|
||||
if ((x4 = IsCar(x3))) return MAKE(DF(DispatchCdddar), x4);
|
||||
if ((x4 = IsCdr(x3))) return MAKE(DF(DispatchCddddr), x4);
|
||||
if ((x4 = IsCar(x3)))
|
||||
return MAKE(DF(DispatchCdddar), x4);
|
||||
if ((x4 = IsCdr(x3)))
|
||||
return MAKE(DF(DispatchCddddr), x4);
|
||||
return MAKE(DF(DispatchCdddr), x3);
|
||||
}
|
||||
return MAKE(DF(DispatchCddr), x2);
|
||||
|
|
|
@ -83,8 +83,10 @@ static void Backtrace(int S) {
|
|||
|
||||
forceinline bool ShouldIgnoreGarbage(int A) {
|
||||
static unsigned cadence;
|
||||
if (DEBUG_GARBAGE) return false;
|
||||
if (!(++cadence & AVERSIVENESS)) return false;
|
||||
if (DEBUG_GARBAGE)
|
||||
return false;
|
||||
if (!(++cadence & AVERSIVENESS))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -101,13 +103,16 @@ static relegated dontinline int ErrorExpr(void) {
|
|||
}
|
||||
|
||||
static int Order(int x, int y) {
|
||||
if (x < y) return -1;
|
||||
if (x > y) return +1;
|
||||
if (x < y)
|
||||
return -1;
|
||||
if (x > y)
|
||||
return +1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Append(int x, int y) {
|
||||
if (!x) return y;
|
||||
if (!x)
|
||||
return y;
|
||||
return Cons(Car(x), Append(Cdr(x), y));
|
||||
}
|
||||
|
||||
|
@ -129,21 +134,25 @@ static int ReconstructAlist(int a) {
|
|||
static bool AtomEquals(int x, const char *s) {
|
||||
dword t;
|
||||
do {
|
||||
if (!*s) return false;
|
||||
if (!*s)
|
||||
return false;
|
||||
t = Get(x);
|
||||
if (LO(t) != *s++) return false; // xxx: ascii
|
||||
if (LO(t) != *s++)
|
||||
return false; // xxx: ascii
|
||||
} while ((x = HI(t)) != TERM);
|
||||
return !*s;
|
||||
}
|
||||
|
||||
static pureconst int LastCons(int x) {
|
||||
while (Cdr(x)) x = Cdr(x);
|
||||
while (Cdr(x))
|
||||
x = Cdr(x);
|
||||
return x;
|
||||
}
|
||||
|
||||
static pureconst int LastChar(int x) {
|
||||
dword e;
|
||||
do e = Get(x);
|
||||
do
|
||||
e = Get(x);
|
||||
while ((x = HI(e)) != TERM);
|
||||
return LO(e);
|
||||
}
|
||||
|
@ -157,13 +166,16 @@ forceinline pureconst bool IsQuote(int x) {
|
|||
}
|
||||
|
||||
static int Quote(int x) {
|
||||
if (IsClosure(x)) return x;
|
||||
if (IsPrecious(x)) return x;
|
||||
if (IsClosure(x))
|
||||
return x;
|
||||
if (IsPrecious(x))
|
||||
return x;
|
||||
return List(kQuote, x);
|
||||
}
|
||||
|
||||
static int QuoteList(int x) {
|
||||
if (!x) return x;
|
||||
if (!x)
|
||||
return x;
|
||||
return Cons(Quote(Car(x)), QuoteList(Cdr(x)));
|
||||
}
|
||||
|
||||
|
@ -171,7 +183,8 @@ static int GetAtom(const char *s) {
|
|||
int x, y;
|
||||
ax = y = TERM;
|
||||
x = *s++ & 255;
|
||||
if (*s) y = GetAtom(s);
|
||||
if (*s)
|
||||
y = GetAtom(s);
|
||||
return Intern(x, y);
|
||||
}
|
||||
|
||||
|
@ -182,7 +195,8 @@ static int Gensym(void) {
|
|||
n = 0;
|
||||
x = g++;
|
||||
B[n++] = L'G';
|
||||
do B[n++] = L'0' + (x & 7);
|
||||
do
|
||||
B[n++] = L'0' + (x & 7);
|
||||
while ((x >>= 3));
|
||||
B[n] = 0;
|
||||
for (a = 1, b = n - 1; a < b; ++a, --b) {
|
||||
|
@ -195,8 +209,10 @@ static int Gensym(void) {
|
|||
|
||||
static nosideeffect bool Member(int v, int x) {
|
||||
while (x) {
|
||||
if (x > 0) return v == x;
|
||||
if (v == Car(x)) return true;
|
||||
if (x > 0)
|
||||
return v == x;
|
||||
if (v == Car(x))
|
||||
return true;
|
||||
x = Cdr(x);
|
||||
}
|
||||
return false;
|
||||
|
@ -216,8 +232,10 @@ static int GetBindings(int x, int a) {
|
|||
|
||||
static int Lambda(int e, int a, dword p1, dword p2) {
|
||||
int u;
|
||||
if (p1) a = Alist(LO(p1), HI(p1), a);
|
||||
if (p2) a = Alist(LO(p2), HI(p2), a);
|
||||
if (p1)
|
||||
a = Alist(LO(p1), HI(p1), a);
|
||||
if (p2)
|
||||
a = Alist(LO(p2), HI(p2), a);
|
||||
if (DEBUG_CLOSURE || logc) {
|
||||
u = FindFreeVariables(e, 0, 0);
|
||||
a = GetBindings(u, a);
|
||||
|
@ -227,8 +245,10 @@ static int Lambda(int e, int a, dword p1, dword p2) {
|
|||
|
||||
static int Function(int e, int a, dword p1, dword p2) {
|
||||
int u;
|
||||
if (e < 0 && Car(e) == kLambda) e = Lambda(e, a, p1, p2);
|
||||
if (e >= 0 || Car(e) != kClosure) Error("not a closure");
|
||||
if (e < 0 && Car(e) == kLambda)
|
||||
e = Lambda(e, a, p1, p2);
|
||||
if (e >= 0 || Car(e) != kClosure)
|
||||
Error("not a closure");
|
||||
a = Cddr(e);
|
||||
e = Cadr(e);
|
||||
u = FindFreeVariables(e, 0, 0);
|
||||
|
@ -421,8 +441,10 @@ struct T DispatchLookup(dword ea, dword tm, dword r, dword p1, dword p2,
|
|||
DCHECK(!IsPrecious(e));
|
||||
DCHECK_GT(e, 0);
|
||||
DCHECK_LE(a, 0);
|
||||
if (LO(p1) == LO(ea)) return Ret(MAKE(HI(p1), 0), tm, r);
|
||||
if (LO(p2) == LO(ea)) return Ret(MAKE(HI(p2), 0), tm, r);
|
||||
if (LO(p1) == LO(ea))
|
||||
return Ret(MAKE(HI(p1), 0), tm, r);
|
||||
if (LO(p2) == LO(ea))
|
||||
return Ret(MAKE(HI(p2), 0), tm, r);
|
||||
if ((kv = Assoc(e, a))) {
|
||||
return Ret(MAKE(Cdr(kv), 0), tm, r); // (eval 𝑘 (…(𝑘 𝑣)…)) ⟹ 𝑣
|
||||
} else {
|
||||
|
@ -473,10 +495,12 @@ struct T DispatchOrder(dword ea, dword tm, dword r, dword p1, dword p2,
|
|||
struct T DispatchCons(dword ea, dword tm, dword r, dword p1, dword p2,
|
||||
dword d) {
|
||||
int x;
|
||||
if (cx < cHeap) cHeap = cx;
|
||||
if (cx < cHeap)
|
||||
cHeap = cx;
|
||||
x = Car(Cdr(LO(ea)));
|
||||
x = FasterRecurse(x, HI(ea), p1, p2);
|
||||
if (!HI(d)) return Ret(MAKE(Cons(x, 0), 0), tm, r);
|
||||
if (!HI(d))
|
||||
return Ret(MAKE(Cons(x, 0), 0), tm, r);
|
||||
if (~r & NEED_POP) {
|
||||
r |= NEED_POP;
|
||||
Push(LO(ea));
|
||||
|
@ -720,7 +744,8 @@ struct T DispatchExpand(dword ea, dword tm, dword r, dword p1, dword p2,
|
|||
}
|
||||
|
||||
static int GrabArgs(int x, int a, dword p1, dword p2) {
|
||||
if (x >= 0) return x;
|
||||
if (x >= 0)
|
||||
return x;
|
||||
return Cons(recurse(MAKE(Car(x), a), p1, p2), GrabArgs(Cdr(x), a, p1, p2));
|
||||
}
|
||||
|
||||
|
@ -991,7 +1016,8 @@ int Plinko(int argc, char *argv[]) {
|
|||
kTail[5] = DispatchTailGc;
|
||||
kTail[6] = DispatchTailImpossible;
|
||||
kTail[7] = DispatchTailTmcGc;
|
||||
if (trace) EnableTracing();
|
||||
if (trace)
|
||||
EnableTracing();
|
||||
|
||||
cx = -1;
|
||||
cFrost = cx;
|
||||
|
@ -1006,7 +1032,8 @@ int Plinko(int argc, char *argv[]) {
|
|||
if (!(x = setjmp(crash))) {
|
||||
x = Read(0);
|
||||
x = expand(x, globals);
|
||||
if (stats) ResetStats();
|
||||
if (stats)
|
||||
ResetStats();
|
||||
if (x < 0 && Car(x) == kDefine) {
|
||||
globals = Define(x, globals);
|
||||
cFrost = cx;
|
||||
|
|
|
@ -25,7 +25,8 @@
|
|||
|
||||
static int CopyTree(int x) {
|
||||
int a, b;
|
||||
if (x >= 0) return x;
|
||||
if (x >= 0)
|
||||
return x;
|
||||
b = CopyTree(Cdr(x));
|
||||
a = CopyTree(Car(x));
|
||||
return Cons(a, b);
|
||||
|
@ -33,7 +34,8 @@ static int CopyTree(int x) {
|
|||
|
||||
static int PreplanCond(int e, int a, int s) {
|
||||
int f, g;
|
||||
if (!(e = Cdr(e))) return 0;
|
||||
if (!(e = Cdr(e)))
|
||||
return 0;
|
||||
if ((f = Car(e)) < 0) {
|
||||
if ((g = Cdr(f)) < 0) {
|
||||
f = List(Preplan(Car(f), a, s), Preplan(Car(g), a, s));
|
||||
|
@ -45,14 +47,16 @@ static int PreplanCond(int e, int a, int s) {
|
|||
}
|
||||
|
||||
static int PreplanList(int e, int a, int s) {
|
||||
if (e >= 0) return e;
|
||||
if (e >= 0)
|
||||
return e;
|
||||
return Cons(Preplan(Car(e), a, s), PreplanList(Cdr(e), a, s));
|
||||
}
|
||||
|
||||
int Preplan(int e, int a, int s) {
|
||||
int f, x;
|
||||
struct qword q;
|
||||
if (e >= 0) return e;
|
||||
if (e >= 0)
|
||||
return e;
|
||||
f = Car(e);
|
||||
if (f != kQuote) {
|
||||
if (f == kClosure) {
|
||||
|
|
|
@ -85,15 +85,18 @@ static void PrettyPrintList(int fd, int x, int n) {
|
|||
if (y >= 0) {
|
||||
argwidth += PrintSpace(fd);
|
||||
argwidth += PrintAtom(fd, y);
|
||||
if (!once) n += argwidth;
|
||||
if (!once)
|
||||
n += argwidth;
|
||||
} else {
|
||||
if (once && (y < 0 || mode)) {
|
||||
mode = 1;
|
||||
PrintNewline(fd);
|
||||
if (depth >= 0) PrintDepth(fd, depth);
|
||||
if (depth >= 0)
|
||||
PrintDepth(fd, depth);
|
||||
PrintIndent(fd, n);
|
||||
} else {
|
||||
if (y < 0) mode = 1;
|
||||
if (y < 0)
|
||||
mode = 1;
|
||||
PrintSpace(fd);
|
||||
}
|
||||
once = 1;
|
||||
|
|
|
@ -25,15 +25,18 @@ int PrintChar(int fd, int s) {
|
|||
unsigned c;
|
||||
int d, e, i, n;
|
||||
c = s & 0xffffffff;
|
||||
if (bp[fd] + 6 > sizeof(g_buffer[fd])) Flush(fd);
|
||||
if (bp[fd] + 6 > sizeof(g_buffer[fd]))
|
||||
Flush(fd);
|
||||
if (c < 0200) {
|
||||
g_buffer[fd][bp[fd]++] = c;
|
||||
if (c == L'\n') Flush(fd);
|
||||
if (c == L'\n')
|
||||
Flush(fd);
|
||||
} else {
|
||||
d = c;
|
||||
e = kTpEnc[bsrl(d) - 7];
|
||||
i = n = e & 255;
|
||||
do g_buffer[fd][bp[fd] + i--] = 0200 | (d & 077);
|
||||
do
|
||||
g_buffer[fd][bp[fd] + i--] = 0200 | (d & 077);
|
||||
while (d >>= 6, i);
|
||||
g_buffer[fd][bp[fd]] = d | e >> 8;
|
||||
bp[fd] += n + 1;
|
||||
|
|
|
@ -27,7 +27,8 @@
|
|||
#include "tool/plinko/lib/print.h"
|
||||
|
||||
static inline long GetVarInt(va_list va, signed char t) {
|
||||
if (t <= 0) return va_arg(va, int);
|
||||
if (t <= 0)
|
||||
return va_arg(va, int);
|
||||
return va_arg(va, long);
|
||||
}
|
||||
|
||||
|
@ -35,7 +36,8 @@ static int PrintStr(int fd, const char *s, int cols) {
|
|||
int n, k = 0, i = 0;
|
||||
n = strlen(s);
|
||||
k += PrintIndent(fd, +cols - n);
|
||||
while (i < n) k += PrintChar(fd, s[i++]);
|
||||
while (i < n)
|
||||
k += PrintChar(fd, s[i++]);
|
||||
k += PrintIndent(fd, -cols - n);
|
||||
return k;
|
||||
}
|
||||
|
@ -85,7 +87,8 @@ int Vfnprintf(const char *f, va_list va, int fd, int n) {
|
|||
++recursive;
|
||||
for (ansi = 0;;) {
|
||||
for (;;) {
|
||||
if (!(c = *f++ & 0377) || c == L'%') break;
|
||||
if (!(c = *f++ & 0377) || c == L'%')
|
||||
break;
|
||||
if (c >= 0300) {
|
||||
for (b = 0200; c & b; b >>= 1) {
|
||||
c ^= b;
|
||||
|
@ -123,7 +126,8 @@ int Vfnprintf(const char *f, va_list va, int fd, int n) {
|
|||
EmitFormatByte:
|
||||
PrintChar(fd, c);
|
||||
}
|
||||
if (!c) break;
|
||||
if (!c)
|
||||
break;
|
||||
prec = 0;
|
||||
pdot = 0;
|
||||
cols = 0;
|
||||
|
@ -221,7 +225,8 @@ int Vfnprintf(const char *f, va_list va, int fd, int n) {
|
|||
}
|
||||
break;
|
||||
case L'p':
|
||||
if (simpler) goto SimplePrint;
|
||||
if (simpler)
|
||||
goto SimplePrint;
|
||||
// fallthrough
|
||||
case L'P':
|
||||
n += PrettyPrint(fd, va_arg(va, int),
|
||||
|
@ -251,7 +256,8 @@ int Vfnprintf(const char *f, va_list va, int fd, int n) {
|
|||
PrintChar(fd, L'(');
|
||||
for (;;) {
|
||||
n += Print(fd, Car(Car(b)));
|
||||
if ((b = Cdr(b)) >= 0) break;
|
||||
if ((b = Cdr(b)) >= 0)
|
||||
break;
|
||||
PrintChar(fd, L' ');
|
||||
}
|
||||
PrintChar(fd, L')');
|
||||
|
@ -279,7 +285,8 @@ int Vfnprintf(const char *f, va_list va, int fd, int n) {
|
|||
break;
|
||||
case L's':
|
||||
s = va_arg(va, const char *);
|
||||
if (!s) s = "NULL";
|
||||
if (!s)
|
||||
s = "NULL";
|
||||
n += PrintStr(fd, s, cols * sign);
|
||||
break;
|
||||
case L'c':
|
||||
|
|
|
@ -40,7 +40,8 @@ static const char *GetElfSymbol(uintptr_t funcaddr) {
|
|||
static const char *GetDispatchName(int x) {
|
||||
const char *s;
|
||||
s = GetElfSymbol(LO(GetShadow(x)));
|
||||
if (startswith(s, "Dispatch")) s += 8;
|
||||
if (startswith(s, "Dispatch"))
|
||||
s += 8;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,8 @@ int PrintInt(int fd, long x, int cols, char quot, char zero, int base,
|
|||
i = j = 0;
|
||||
y = x < 0 && issigned ? -x : x;
|
||||
do {
|
||||
if (quot && j == 3) z[i++ & 31] = quot, j = 0;
|
||||
if (quot && j == 3)
|
||||
z[i++ & 31] = quot, j = 0;
|
||||
z[i++ & 31] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[y % base];
|
||||
} while (++j, (y /= base));
|
||||
k = i + (x < 0 && issigned);
|
||||
|
@ -38,8 +39,10 @@ int PrintInt(int fd, long x, int cols, char quot, char zero, int base,
|
|||
} else {
|
||||
n = PrintIndent(fd, +cols - k);
|
||||
}
|
||||
if (x < 0 && issigned) n += PrintChar(fd, L'-');
|
||||
while (i) n += PrintChar(fd, z[--i & 31]);
|
||||
if (x < 0 && issigned)
|
||||
n += PrintChar(fd, L'-');
|
||||
while (i)
|
||||
n += PrintChar(fd, z[--i & 31]);
|
||||
PrintIndent(fd, -cols - n);
|
||||
return n;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
#include "tool/plinko/lib/print.h"
|
||||
|
||||
int PrintArgs(int fd, int keys, int vals, int n) {
|
||||
if (!keys) return n;
|
||||
if (!keys)
|
||||
return n;
|
||||
if (keys > 0) {
|
||||
if (!(vals < 0 && Car(vals) == kClosure)) {
|
||||
if (n) {
|
||||
|
@ -46,6 +47,7 @@ int PrintArgs(int fd, int keys, int vals, int n) {
|
|||
} else {
|
||||
n += PrintArgs(fd, Car(keys), Car(vals), n);
|
||||
}
|
||||
if (!Cdr(keys)) return n;
|
||||
if (!Cdr(keys))
|
||||
return n;
|
||||
return PrintArgs(fd, Cdr(keys), Cdr(vals), n);
|
||||
}
|
||||
|
|
|
@ -66,7 +66,8 @@ dontinstrument int ReadSpaces(int fd) {
|
|||
|
||||
dontinstrument int ReadByte(int fd) {
|
||||
int c;
|
||||
if ((c = g_buffer[fd][bp[fd]++] & 255)) return c;
|
||||
if ((c = g_buffer[fd][bp[fd]++] & 255))
|
||||
return c;
|
||||
return ReadSpaces(fd);
|
||||
}
|
||||
|
||||
|
@ -77,7 +78,8 @@ dontinstrument int ReadChar(int fd) {
|
|||
if (dx != ';') {
|
||||
break;
|
||||
} else {
|
||||
do b = ReadByte(fd);
|
||||
do
|
||||
b = ReadByte(fd);
|
||||
while ((b != '\n'));
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +102,8 @@ dontinstrument int ReadChar(int fd) {
|
|||
static int ReadListItem(int fd, int closer, int f(int)) {
|
||||
int x, y;
|
||||
if ((x = f(fd)) > 0) {
|
||||
if (Get(x) == MAKE(closer, TERM)) return -0;
|
||||
if (Get(x) == MAKE(closer, TERM))
|
||||
return -0;
|
||||
if (Get(x) == MAKE(L'.', TERM)) {
|
||||
x = f(fd);
|
||||
if ((y = ReadListItem(fd, closer, Read1))) {
|
||||
|
@ -138,16 +141,20 @@ static void ConsumeComment(int fd) {
|
|||
int c, t = 1;
|
||||
for (;;) {
|
||||
c = ReadChar(fd);
|
||||
if (c == '#' && dx == '|') ++t;
|
||||
if (!t) return;
|
||||
if (c == '|' && dx == '#') --t;
|
||||
if (c == '#' && dx == '|')
|
||||
++t;
|
||||
if (!t)
|
||||
return;
|
||||
if (c == '|' && dx == '#')
|
||||
--t;
|
||||
}
|
||||
}
|
||||
|
||||
static int ReadAtomRest(int fd, int x) {
|
||||
int y;
|
||||
ax = y = TERM;
|
||||
if (x == L'\\') x = ReadChar(fd);
|
||||
if (x == L'\\')
|
||||
x = ReadChar(fd);
|
||||
if (!IsSpace(dx) && !IsParen(dx) && !IsMathAlnum(x) && !IsMathAlnum(dx)) {
|
||||
y = ReadAtomRest(fd, ReadChar(fd));
|
||||
}
|
||||
|
@ -157,7 +164,8 @@ static int ReadAtomRest(int fd, int x) {
|
|||
static int ReadAtom(int fd) {
|
||||
int a, s, x;
|
||||
x = ReadChar(fd);
|
||||
if ((s = Desymbolize(x)) != -1) return s;
|
||||
if ((s = Desymbolize(x)) != -1)
|
||||
return s;
|
||||
a = ReadAtomRest(fd, x);
|
||||
if (LO(Get(a)) == L'T' && HI(Get(a)) == TERM) {
|
||||
a = 1;
|
||||
|
@ -194,7 +202,8 @@ static int TokenizeComplicated(int fd) {
|
|||
|
||||
static int Read2(int fd) {
|
||||
int r, l;
|
||||
while (IsSpace((l = dx))) ReadChar(fd);
|
||||
while (IsSpace((l = dx)))
|
||||
ReadChar(fd);
|
||||
switch (dx) {
|
||||
case L'#':
|
||||
r = TokenizeComplicated(fd);
|
||||
|
@ -263,13 +272,15 @@ static int ReadLambda(int fd, int n) {
|
|||
} else {
|
||||
q = List(q, r);
|
||||
}
|
||||
if (!n && dx == L')') break;
|
||||
if (!n && dx == L')')
|
||||
break;
|
||||
} while (!IsSpace(dx));
|
||||
return q;
|
||||
}
|
||||
|
||||
static int Read1(int fd) {
|
||||
while (IsSpace(dx)) ReadChar(fd);
|
||||
while (IsSpace(dx))
|
||||
ReadChar(fd);
|
||||
// todo: fix horrible i/o
|
||||
if (dx == 0xCE && (g_buffer[fd][bp[fd]] & 255) == 0xbb) {
|
||||
return ReadLambda(fd, 0);
|
||||
|
|
|
@ -19,92 +19,139 @@
|
|||
#include "tool/plinko/lib/plinko.h"
|
||||
|
||||
pureconst int Symbolize(int x) {
|
||||
if (literally) return -1;
|
||||
if (x == TERM) return -1;
|
||||
if (literally)
|
||||
return -1;
|
||||
if (x == TERM)
|
||||
return -1;
|
||||
DCHECK_LT(x, TERM);
|
||||
switch (LO(Get(x))) {
|
||||
case L'A':
|
||||
if (x == kAtom) return L'α';
|
||||
if (x == kAnd) return L'∧';
|
||||
if (x == kAppend) return L'║';
|
||||
if (x == kAtom)
|
||||
return L'α';
|
||||
if (x == kAnd)
|
||||
return L'∧';
|
||||
if (x == kAppend)
|
||||
return L'║';
|
||||
return -1;
|
||||
case L'B':
|
||||
if (x == kBeta) return L'β';
|
||||
if (x == kBecause) return L'∵';
|
||||
if (x == kBeta)
|
||||
return L'β';
|
||||
if (x == kBecause)
|
||||
return L'∵';
|
||||
return -1;
|
||||
case L'C':
|
||||
if (x == kCar) return L'⍅';
|
||||
if (x == kCdr) return L'⍆';
|
||||
if (x == kClosure) return L'⅄';
|
||||
if (x == kCond) return L'ζ';
|
||||
if (x == kCons) return L'ℶ';
|
||||
if (x == kCmp) return L'≷';
|
||||
if (x == kCycle) return L'⟳';
|
||||
if (x == kCar)
|
||||
return L'⍅';
|
||||
if (x == kCdr)
|
||||
return L'⍆';
|
||||
if (x == kClosure)
|
||||
return L'⅄';
|
||||
if (x == kCond)
|
||||
return L'ζ';
|
||||
if (x == kCons)
|
||||
return L'ℶ';
|
||||
if (x == kCmp)
|
||||
return L'≷';
|
||||
if (x == kCycle)
|
||||
return L'⟳';
|
||||
return -1;
|
||||
case L'D':
|
||||
if (x == kDefine) return L'≝';
|
||||
if (x == kDefmacro) return L'Ψ';
|
||||
if (x == kDefun) return L'Λ';
|
||||
if (x == kDefine)
|
||||
return L'≝';
|
||||
if (x == kDefmacro)
|
||||
return L'Ψ';
|
||||
if (x == kDefun)
|
||||
return L'Λ';
|
||||
return -1;
|
||||
case L'E':
|
||||
if (x == kEq) return L'≡';
|
||||
if (x == kExpand) return L'ə';
|
||||
if (x == kEq)
|
||||
return L'≡';
|
||||
if (x == kExpand)
|
||||
return L'ə';
|
||||
return -1;
|
||||
case L'F':
|
||||
if (x == kFunction) return L'𝑓';
|
||||
if (x == kFork) return L'⋔';
|
||||
if (x == kFunction)
|
||||
return L'𝑓';
|
||||
if (x == kFork)
|
||||
return L'⋔';
|
||||
return -1;
|
||||
case L'P':
|
||||
if (x == kPartial) return L'∂';
|
||||
if (x == kPartial)
|
||||
return L'∂';
|
||||
return -1;
|
||||
case L'I':
|
||||
if (x == kIff) return L'⟺';
|
||||
if (x == kImplies) return L'⟶';
|
||||
if (x == kIntegrate) return L'∫';
|
||||
if (x == kIntersection) return L'∩';
|
||||
if (x == kIff)
|
||||
return L'⟺';
|
||||
if (x == kImplies)
|
||||
return L'⟶';
|
||||
if (x == kIntegrate)
|
||||
return L'∫';
|
||||
if (x == kIntersection)
|
||||
return L'∩';
|
||||
return -1;
|
||||
case L'L':
|
||||
if (x == kLambda) return L'λ';
|
||||
if (x == kList) return L'ℒ';
|
||||
if (x == kLambda)
|
||||
return L'λ';
|
||||
if (x == kList)
|
||||
return L'ℒ';
|
||||
return -1;
|
||||
case L'M':
|
||||
if (x == kMacro) return L'ψ';
|
||||
if (x == kMember) return L'∊';
|
||||
if (x == kMacro)
|
||||
return L'ψ';
|
||||
if (x == kMember)
|
||||
return L'∊';
|
||||
return -1;
|
||||
case L'N':
|
||||
if (!x) return L'⊥';
|
||||
if (x == kNand) return L'⊼';
|
||||
if (x == kNor) return L'⊽';
|
||||
if (x == kNot) return L'¬';
|
||||
if (!x)
|
||||
return L'⊥';
|
||||
if (x == kNand)
|
||||
return L'⊼';
|
||||
if (x == kNor)
|
||||
return L'⊽';
|
||||
if (x == kNot)
|
||||
return L'¬';
|
||||
return -1;
|
||||
case L'O':
|
||||
if (x == kOr) return L'∨';
|
||||
if (x == kOrder) return L'⊙';
|
||||
if (x == kOr)
|
||||
return L'∨';
|
||||
if (x == kOrder)
|
||||
return L'⊙';
|
||||
return -1;
|
||||
case L'Q':
|
||||
if (x == kQuote) return L'Ω';
|
||||
if (x == kQuote)
|
||||
return L'Ω';
|
||||
return -1;
|
||||
case L'R':
|
||||
if (x == kReverse) return L'Я';
|
||||
if (x == kReverse)
|
||||
return L'Я';
|
||||
return -1;
|
||||
case L'S':
|
||||
if (x == kSqrt) return L'√';
|
||||
if (x == kSubset) return L'⊂';
|
||||
if (x == kSuperset) return L'⊃';
|
||||
if (x == kSqrt)
|
||||
return L'√';
|
||||
if (x == kSubset)
|
||||
return L'⊂';
|
||||
if (x == kSuperset)
|
||||
return L'⊃';
|
||||
return -1;
|
||||
case L'T':
|
||||
if (x == 1) return L'⊤';
|
||||
if (x == kTherefore) return L'∴';
|
||||
if (x == 1)
|
||||
return L'⊤';
|
||||
if (x == kTherefore)
|
||||
return L'∴';
|
||||
return -1;
|
||||
case L'U':
|
||||
if (x == kUnion) return L'∪';
|
||||
if (x == kImpossible) return L'∅';
|
||||
if (x == kUnion)
|
||||
return L'∪';
|
||||
if (x == kImpossible)
|
||||
return L'∅';
|
||||
return -1;
|
||||
case L'X':
|
||||
if (x == kXor) return L'⊻';
|
||||
if (x == kXor)
|
||||
return L'⊻';
|
||||
return -1;
|
||||
case L'Y':
|
||||
if (x == kYcombinator) return L'𝕐';
|
||||
if (x == kYcombinator)
|
||||
return L'𝕐';
|
||||
return -1;
|
||||
default:
|
||||
return -1;
|
||||
|
|
|
@ -31,9 +31,12 @@ int Nod(int E, int L, int R, int C) {
|
|||
|
||||
static void CheckTreeImpl(int N) {
|
||||
int p, L, R;
|
||||
if (N >= 0) Error("N is atom: %S", N);
|
||||
if (Car(N) >= 0) Error("Car(N) is an atom: %S", N);
|
||||
if (Cdr(N) & ~1) Error("Cdr(N) is non-bool: %S", N);
|
||||
if (N >= 0)
|
||||
Error("N is atom: %S", N);
|
||||
if (Car(N) >= 0)
|
||||
Error("Car(N) is an atom: %S", N);
|
||||
if (Cdr(N) & ~1)
|
||||
Error("Cdr(N) is non-bool: %S", N);
|
||||
if ((L = Lit(N))) {
|
||||
if ((p = Cmp(Key(Ent(L)), Key(Ent(N)))) != -1) {
|
||||
Error("Cmp(Key(L), Key(N)) != -1%n"
|
||||
|
@ -65,7 +68,8 @@ static void CheckTreeImpl(int N) {
|
|||
static int CheckTree(int N) {
|
||||
#if DEBUG_TREE
|
||||
if (N) {
|
||||
if (Red(N)) Error("tree root is red%n%T", N);
|
||||
if (Red(N))
|
||||
Error("tree root is red%n%T", N);
|
||||
CheckTreeImpl(N);
|
||||
}
|
||||
#endif
|
||||
|
@ -163,11 +167,15 @@ static int InsTree(int E, int N, int KEEP) {
|
|||
if (N) {
|
||||
P = Cmp(Key(E), Key(Ent(N)));
|
||||
if (P < 0) {
|
||||
if ((L = InsTree(E, Lit(N), KEEP)) > 0) return L; // rethrow
|
||||
if (L != Lit(N)) N = BalTree(Ent(N), L, Rit(N), Tail(N));
|
||||
if ((L = InsTree(E, Lit(N), KEEP)) > 0)
|
||||
return L; // rethrow
|
||||
if (L != Lit(N))
|
||||
N = BalTree(Ent(N), L, Rit(N), Tail(N));
|
||||
} else if (P > 0) {
|
||||
if ((R = InsTree(E, Rit(N), KEEP)) > 0) return R; // rethrow
|
||||
if (R != Rit(N)) N = BalTree(Ent(N), Lit(N), R, Tail(N));
|
||||
if ((R = InsTree(E, Rit(N), KEEP)) > 0)
|
||||
return R; // rethrow
|
||||
if (R != Rit(N))
|
||||
N = BalTree(Ent(N), Lit(N), R, Tail(N));
|
||||
} else if (KEEP < 0 || (!KEEP && !Equal(Val(E), Val(Ent(N))))) {
|
||||
N = Cons(Cons(E, Chl(N)), Red(N));
|
||||
} else if (KEEP > 1) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue