ref: 8527cab75ec4a90abf10f869c9ba9d85a1147757
parent: 8b19a7124fd21a5268b78ef26051da29f41398bf
author: spew <spew@palas>
date: Sat Feb 8 18:00:48 EST 2025
Revert ccc changes
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2017 Benjamin Scher Purcell <benjapurcell@gmail.com>
+Copyright (c) 2025 Benjamin Scher Purcell <ben@cbza.org>
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
--- a/rat.c
+++ b/rat.c
@@ -7,7 +7,7 @@
{
vlong t;
- while(b != 0) {
+ while(b != 0){
t = b;
b = a % b;
a = t;
@@ -22,10 +22,10 @@
vlong g;
g = gcd(n, d);
- if(d > 0) {
+ if(d > 0){
r.num = n/g;
r.den = d/g;
- } else {
+ }else{
r.num = -n/g;
r.den = -d/g;
}
@@ -40,7 +40,7 @@
t = a.num;
a.num = a.den;
a.den = t;
- if(a.den < 0) {
+ if(a.den < 0){
a.num = -a.num;
a.den = -a.den;
}
--- a/rat.h
+++ b/rat.h
@@ -1,5 +1,4 @@
-typedef struct Rat Rat;
-
+typedef struct Rat Rat;
struct Rat
{
vlong num;
@@ -8,11 +7,11 @@
#pragma varargck type "R" Rat
-Rat ratmk(vlong, vlong);
-Rat ratrecip(Rat);
-Rat ratneg(Rat);
-Rat ratadd(Rat, Rat);
-Rat ratsub(Rat, Rat);
-Rat ratmul(Rat, Rat);
-Rat ratpow(Rat, int);
-void ratfmtinstall(void);
+Rat ratmk(vlong, vlong);
+Rat ratrecip(Rat);
+Rat ratneg(Rat);
+Rat ratadd(Rat, Rat);
+Rat ratsub(Rat, Rat);
+Rat ratmul(Rat, Rat);
+Rat ratpow(Rat, int);
+void ratfmtinstall(void);
--- a/squint.c
+++ b/squint.c
@@ -4,28 +4,30 @@
#include "rat.h"
#include "queue.h"
+int debug;
+int threadcount;
+
enum
{
- STK = 8192
+ TMAX = 1000,
+ STK = 2048
};
typedef struct Ps Ps;
struct Ps
{
- char @close;
- char @req;
- Rat @dat;
+ Channel *close;
+ Channel *req;
+ Channel *dat;
};
-int debug;
-int threadcount;
-
Rat
getr(Ps *f)
{
- Rat r;
- f->req @= 0;
- r = @f->dat;
+ Rat r;
+
+ send(f->req, nil);
+ recv(f->dat, &r);
return r;
}
@@ -35,9 +37,9 @@
Ps *d;
d = malloc(sizeof(*d));
- chanset(d->close, 0);
- chanset(d->req, 0);
- chanset(d->dat, nel);
+ d->close = chancreate(1, 0);
+ d->req = chancreate(1, 0);
+ d->dat = chancreate(sizeof(Rat), nel);
return d;
}
@@ -50,69 +52,129 @@
free(d);
}
-
static void
-_split(Ps *f, Ps *s, Rat @qchan, char @close)
+_split(void *a)
{
+ void **argv;
+ Ps *f, *s;
+ Channel *qchan, *close;
Queue q;
- Rat r;
+ Rat r;
+ enum{
+ REQ,
+ QCHAN,
+ CLOSE,
+ NALT
+ };
+ Alt alts[NALT+1];
+ argv = a;
+ f = argv[0];
+ s = argv[1];
+ qchan = argv[2];
+ close = argv[3];
+
+ alts[REQ].c = s->req;
+ alts[REQ].v = nil;
+ alts[REQ].op = CHANRCV;
+ alts[QCHAN].c = qchan;
+ alts[QCHAN].v = &r;
+ alts[QCHAN].op = CHANRCV;
+ alts[CLOSE].c = s->close;
+ alts[CLOSE].v = nil;
+ alts[CLOSE].op = CHANRCV;
+ alts[NALT].op = CHANEND;
+
queueset(&q);
- for(;;) switch @{
- alt @s->req:
- if(q.front == nil) {
- r = getr(f);
- qchan @= r;
- s->dat @= r;
- } else
- s->dat @= delete(&q);
- break;
- alt r = @qchan:
- insert(&q, r);
- break;
- alt @s->close:
- while(q.front != nil)
- delete(&q);
- psfree(s);
- if(chanclosing(qchan) == -1) {
- if(close != nil) {
- close @= 0;
- chanfree(close);
+ for(;;){
+ switch(alt(alts)){
+ case REQ:
+ if(q.front == nil){
+ r = getr(f);
+ send(qchan, &r);
+ send(s->dat, &r);
+ }else{
+ r = delete(&q);
+ send(s->dat, &r);
}
- chanclose(qchan);
- } else {
- chanfree(qchan);
- f->close @= 0;
+ break;
+ case QCHAN:
+ insert(&q, r);
+ break;
+ case CLOSE:
+ while(q.front != nil)
+ delete(&q);
+ psfree(s);
+ if(chanclosing(qchan) == -1){
+ if(close != nil){
+ send(close, nil);
+ chanfree(close);
+ }
+ chanclose(qchan);
+ }else{
+ chanfree(qchan);
+ send(f->close, nil);
+ }
+ if(debug) threadcount--;
+ threadexits(0);
}
- if(debug) threadcount--;
- threadexits(0);
}
}
void
-split(Ps *f, Ps *s[2], char @splitclose)
+split(Ps *f, Ps *s[2], Channel *splitclose)
{
- Rat @q;
- int i;
+ void *argv[2][4];
+ Channel *q;
+ int i;
- chanset(q, 0);
- for(i = 0; i < 2; i++) {
+ q = chancreate(sizeof(Rat), 0);
+ for(i = 0; i < 2; i++){
s[i] = psmk(0);
- cothread(_split(f, s[i], q, splitclose), STK);
+ argv[i][0] = f;
+ argv[i][1] = s[i];
+ argv[i][2] = q;
+ argv[i][3] = splitclose;
+ threadcreate(_split, argv[i], STK);
if(debug) threadcount++;
+ yield();
}
}
static void
-_mkconst(Rat c, Ps *o)
+_mkconst(void *a)
{
- for(;;) switch @{
- alt @o->req:
- o->dat @= c;
- break;
- alt @o->close:
- if(debug) threadcount--;
- threadexits(0);
+ void **argv;
+ Ps *o;
+ Rat c;
+ enum{
+ REQ,
+ CLOSE,
+ NALT
+ };
+ Alt alts[NALT+1];
+
+ argv = a;
+ c = *(Rat*)argv[0];
+ o = argv[1];
+
+ alts[REQ].c = o->req;
+ alts[REQ].v = nil;
+ alts[REQ].op = CHANRCV;
+ alts[CLOSE].c = o->close;
+ alts[CLOSE].v = nil;
+ alts[CLOSE].op = CHANRCV;
+ alts[NALT].op = CHANEND;
+
+ for(;;){
+ switch(alt(alts)){
+ case REQ:
+ send(o->dat, &c);
+ break;
+ case CLOSE:
+ if(debug) threadcount--;
+ threadexits(0);
+ }
}
}
@@ -119,38 +181,71 @@
Ps*
mkconst(Rat c)
{
- Ps *o;
+ void *argv[2];
+ Ps *o;
o = psmk(0);
- cothread(_mkconst(c, o), STK);
+ argv[0] = &c;
+ argv[1] = o;
+ threadcreate(_mkconst, argv, STK);
if(debug) threadcount++;
+ yield();
return o;
}
Ps*
-binop(void (*oper)(Ps*, Ps*, Ps*), Ps *f, Ps *g)
+binop(void (*oper)(void*), Ps *f, Ps *g)
{
- Ps *o;
+ Ps *argv[3], *o;
o = psmk(0);
- cothread(oper(f, g, o), STK);
+ argv[0] = f;
+ argv[1] = g;
+ argv[2] = o;
+ threadcreate(oper, argv, STK);
if(debug) threadcount++;
+ yield();
return o;
}
static void
-_psadd(Ps *f, Ps *g, Ps *s)
+_psadd(void *a)
{
- for(;;) switch @{
- alt @s->req:
- s->dat @= ratadd(getr(f), getr(g));
- break;
- alt @s->close:
- psfree(s);
- f->close @= 0;
- g->close @= 0;
- if(debug) threadcount--;
- threadexits(0);
+ Ps **argv, *f, *g, *s;
+ Rat r;
+ enum{
+ REQ,
+ CLOSE,
+ NALT
+ };
+ Alt alts[NALT+1];
+
+ argv = a;
+ f = argv[0];
+ g = argv[1];
+ s = argv[2];
+
+ alts[REQ].c = s->req;
+ alts[REQ].v = nil;
+ alts[REQ].op = CHANRCV;
+ alts[CLOSE].c = s->close;
+ alts[CLOSE].v = nil;
+ alts[CLOSE].op = CHANRCV;
+ alts[NALT].op = CHANEND;
+
+ for(;;){
+ switch(alt(alts)){
+ case REQ:
+ r = ratadd(getr(f), getr(g));
+ send(s->dat, &r);
+ break;
+ case CLOSE:
+ psfree(s);
+ send(f->close, nil);
+ send(g->close, nil);
+ if(debug) threadcount--;
+ threadexits(0);
+ }
}
}
@@ -161,21 +256,41 @@
}
static void
-_psderiv(Ps *f, Ps *d)
+_psderiv(void *a)
{
- Rat r;
- int i;
+ Ps **argv, *f, *d;
+ Rat t, r;
+ int i;
+ enum{
+ REQ,
+ CLOSE,
+ NALT
+ };
+ Alt alts[NALT+1];
+ argv = a;
+ f = argv[0];
+ d = argv[1];
+
+ alts[REQ].c = d->req;
+ alts[REQ].v = nil;
+ alts[REQ].op = CHANRCV;
+ alts[CLOSE].c = d->close;
+ alts[CLOSE].v = nil;
+ alts[CLOSE].op = CHANRCV;
+ alts[NALT].op = CHANEND;
+
getr(f);
- for(i = 1;; i++) {
- switch @{
- alt @d->req:
+ for(i = 1;; i++){
+ switch(alt(alts)){
+ case REQ:
r = getr(f);
- d->dat @= ratmk(i * r.num, r.den);
+ t = ratmk(i * r.num, r.den);
+ send(d->dat, &t);
break;
- alt @d->close:
+ case CLOSE:
psfree(d);
- f->close @= 0;
+ send(f->close, nil);
if(debug) threadcount--;
threadexits(0);
}
@@ -185,11 +300,13 @@
Ps*
psderiv(Ps *f)
{
- Ps *d;
+ Ps *argv[2], *d = psmk(0);
- d = psmk(0);
- cothread(_psderiv(f, d), STK);
+ argv[0] = f;
+ argv[1] = d;
+ threadcreate(_psderiv, argv, STK);
if(debug) threadcount++;
+ yield();
return d;
}
@@ -205,29 +322,51 @@
}
static void
-_psinteg(Ps *f, Rat c, Ps *i)
+_psinteg(void *a)
{
- int j;
+ void **argv = a;
+ Ps *f, *i;
+ Rat c, out;
+ int j;
+ enum{
+ REQ,
+ CLOSE,
+ NALT
+ };
+ Alt alts[NALT+1];
- switch @{
- alt @i->req:
- i->dat @= c;
+ f = argv[0];
+ c = *(Rat*)argv[1];
+ i = argv[2];
+
+ alts[REQ].c = i->req;
+ alts[REQ].v = nil;
+ alts[REQ].op = CHANRCV;
+ alts[CLOSE].c = i->close;
+ alts[CLOSE].v = nil;
+ alts[CLOSE].op = CHANRCV;
+ alts[NALT].op = CHANEND;
+
+ switch(alt(alts)){
+ case REQ:
+ send(i->dat, &c);
break;
- alt @i->close:
+ case CLOSE:
goto End;
}
- for(j = 1;; j++) {
- switch @{
- alt @i->req:
- i->dat @= ratmul(getr(f), ratmk(1, j));
+ for(j = 1;; j++){
+ switch(alt(alts)){
+ case REQ:
+ out = ratmul(getr(f), ratmk(1, j));
+ send(i->dat, &out);
break;
- alt @i->close:
+ case CLOSE:
goto End;
}
}
End:
psfree(i);
- f->close @= 0;
+ send(f->close, nil);
if(debug) threadcount--;
threadexits(0);
}
@@ -236,26 +375,55 @@
Ps*
psinteg(Ps *ps, Rat c)
{
- Ps *i;
+ void *argv[3];
+ Ps *i = psmk(0);
- i = psmk(0);
- cothread(_psinteg(ps, c, i), STK);
+ argv[0] = ps;
+ argv[1] = &c;
+ argv[2] = i;
+ threadcreate(_psinteg, argv, STK);
if(debug) threadcount++;
+ yield();
return i;
}
static void
-_pscmul(Ps *f, Rat c, Ps *o)
+_pscmul(void *a)
{
- for(;;) switch @{
- alt @o->req:
- o->dat @= ratmul(c, getr(f));
- break;
- alt @o->close:
- psfree(o);
- f->close @= 0;
- if(debug) threadcount--;
- threadexits(0);
+ void **argv = a;
+ Ps *f, *o;
+ Rat c, p;
+ enum{
+ REQ,
+ CLOSE,
+ NALT
+ };
+ Alt alts[NALT+1];
+
+ f = argv[0];
+ c = *(Rat*)argv[1];
+ o = argv[2];
+
+ alts[REQ].c = o->req;
+ alts[REQ].v = nil;
+ alts[REQ].op = CHANRCV;
+ alts[CLOSE].c = o->close;
+ alts[CLOSE].v = nil;
+ alts[CLOSE].op = CHANRCV;
+ alts[NALT].op = CHANEND;
+
+ for(;;){
+ switch(alt(alts)){
+ case REQ:
+ p = ratmul(c, getr(f));
+ send(o->dat, &p);
+ break;
+ case CLOSE:
+ psfree(o);
+ send(f->close, nil);
+ if(debug) threadcount--;
+ threadexits(0);
+ }
}
}
@@ -262,47 +430,73 @@
Ps*
pscmul(Rat c, Ps* f)
{
- Ps *o;
+ void *argv[3];
+ Ps *o = psmk(0);
- o = psmk(0);
- cothread(_pscmul(f, c, o), STK);
+ argv[0] = f;
+ argv[1] = &c;
+ argv[2] = o;
+ threadcreate(_pscmul, argv, STK);
if(debug) threadcount++;
+ yield();
return o;
}
static void
-_psmul(Ps *f, Ps *g, Ps *p)
+_psmul(void *a)
{
+ Ps **argv, *f, *g, *p;
Queue fq, gq;
Node *fnode, *gnode;
- Rat sum;
+ Rat sum;
+ enum{
+ REQ,
+ CLOSE,
+ NALT
+ };
+ Alt alts[NALT+1];
+ argv = a;
+ f = argv[0];
+ g = argv[1];
+ p = argv[2];
+
+ alts[REQ].c = p->req;
+ alts[REQ].v = nil;
+ alts[REQ].op = CHANRCV;
+ alts[CLOSE].c = p->close;
+ alts[CLOSE].v = nil;
+ alts[CLOSE].op = CHANRCV;
+ alts[NALT].op = CHANEND;
+
queueset(&fq);
queueset(&gq);
- for(;;) switch @{
- alt @p->req:
- insert(&fq, getr(f));
- frontinsert(&gq, getr(g));
- fnode = fq.front;
- gnode = gq.front;
- sum = ratmk(0, 1);
- while(fnode != nil) {
- sum = ratadd(sum, ratmul(fnode->val, gnode->val));
- fnode = fnode->link;
- gnode = gnode->link;
+ for(;;){
+ switch(alt(alts)){
+ case REQ:
+ insert(&fq, getr(f));
+ frontinsert(&gq, getr(g));
+ fnode = fq.front;
+ gnode = gq.front;
+ sum = ratmk(0, 1);
+ while(fnode != nil){
+ sum = ratadd(sum, ratmul(fnode->val, gnode->val));
+ fnode = fnode->link;
+ gnode = gnode->link;
+ }
+ send(p->dat, &sum);
+ break;
+ case CLOSE:
+ psfree(p);
+ while(fq.front != nil)
+ delete(&fq);
+ while(gq.front != nil)
+ delete(&gq);
+ send(f->close, nil);
+ send(g->close, nil);
+ if(debug) threadcount--;
+ threadexits(0);
}
- p->dat @= sum;
- break;
- alt @p->close:
- psfree(p);
- while(fq.front != nil)
- delete(&fq);
- while(gq.front != nil)
- delete(&gq);
- f->close @= 0;
- g->close @= 0;
- if(debug) threadcount--;
- threadexits(0);
}
}
@@ -313,32 +507,57 @@
}
static void
-_psrecip(Ps *f, Ps *r, Ps *rr, char @close)
+_psrecip(void *a)
{
- Ps *recip;
- Rat g;
+ void **argv;
+ Ps *f, *r, *rr, *recip;
+ Channel *close;
+ Rat g;
+ enum{
+ REQ,
+ CLOSE,
+ NALT
+ };
+ Alt alts[NALT+1];
- switch @{
- alt @r->req:
+ argv = a;
+ f = argv[0];
+ r = argv[1];
+ rr = argv[2];
+ close = argv[3];
+
+ alts[REQ].c = r->req;
+ alts[REQ].v = nil;
+ alts[REQ].op = CHANRCV;
+ alts[CLOSE].c = close;
+ alts[CLOSE].v = nil;
+ alts[CLOSE].op = CHANRCV;
+ alts[NALT].op = CHANEND;
+
+ switch(alt(alts)){
+ case REQ:
g = ratrecip(getr(f));
- r->dat @= g;
+ send(r->dat, &g);
break;
- alt @close:
- rr->close @= 0;
- f->close @= 0;
+ case CLOSE:
+ send(rr->close, nil);
+ send(f->close, nil);
goto End;
}
recip = pscmul(ratneg(g), psmul(f, rr));
- for(;;) switch @{
- alt @r->req:
- r->dat @= getr(recip);
- break;
- alt @close:
- recip->close @= 0;
- goto End;
+ for(;;){
+ switch(alt(alts)){
+ case REQ:
+ g = getr(recip);
+ send(r->dat, &g);
+ break;
+ case CLOSE:
+ send(recip->close, nil);
+ goto End;
+ }
}
End:
- @r->close;
+ recv(r->close, nil);
psfree(r);
if(debug) threadcount--;
threadexits(0);
@@ -347,46 +566,72 @@
Ps*
psrecip(Ps *f)
{
- Ps *rr[2], *r;
- char @close;
+ void *argv[4];
+ Ps *rr[2], *r = psmk(0);
+ Channel *close = chancreate(1, 0);
- r = psmk(0);
- chanset(close, 0);
-
split(r, rr, close);
- cothread(_psrecip(f, r, rr[0], close), STK);
+ argv[0] = f;
+ argv[1] = r;
+ argv[2] = rr[0];
+ argv[3] = close;
+ threadcreate(_psrecip, argv, STK);
if(debug) threadcount++;
+ yield();
return rr[1];
}
static void
-_psmsubst(Ps *f, Rat c, int deg, Ps *m)
+_psmsubst(void *a)
{
- Rat zero;
- int i, j;
+ void **argv;
+ Ps *f, *m;
+ Rat c, zero, r;
+ int deg, i, j;
+ enum{
+ REQ,
+ CLOSE,
+ NALT
+ };
+ Alt alts[NALT+1];
+ argv = a;
+ f = argv[0];
+ c = *(Rat*)argv[1];
+ deg = *(int*)argv[2];
+ m = argv[3];
+
+ alts[REQ].c = m->req;
+ alts[REQ].v = nil;
+ alts[REQ].op = CHANRCV;
+ alts[CLOSE].c = m->close;
+ alts[CLOSE].v = nil;
+ alts[CLOSE].op = CHANRCV;
+ alts[NALT].op = CHANEND;
+
zero = ratmk(0, 1);
- for(i = 0;; i++) {
- switch @{
- alt @m->req:
- m->dat @= ratmul(getr(f), ratpow(c, i));
+ for(i = 0;; i++){
+ switch(alt(alts)){
+ case REQ:
+ r = ratmul(getr(f), ratpow(c, i));
+ send(m->dat, &r);
for(j = 0; j < deg - 1; j++){
- switch @{
- alt @m->req:
- m->dat @= zero;
+ switch(alt(alts)){
+ case REQ:
+ send(m->dat, &zero);
break;
- alt @m->close:
+ case CLOSE:
goto End;
}
}
break;
- alt @m->close:
+ case CLOSE:
goto End;
}
}
End:
psfree(m);
- f->close @= 0;
+ send(f->close, nil);
if(debug) threadcount--;
threadexits(0);
}
@@ -394,11 +639,17 @@
Ps*
psmsubst(Ps *f, Rat c, int deg)
{
- Ps *m;
+ void *argv[4];
+ Ps *m;
m = psmk(0);
- cothread(_psmsubst(f, c, deg, m), STK);
+ argv[0] = f;
+ argv[1] = &c;
+ argv[2] = °
+ argv[3] = m;
+ threadcreate(_psmsubst, argv, STK);
if(debug) threadcount++;
+ yield();
return m;
}
@@ -405,18 +656,39 @@
Ps *pssubst(Ps*, Ps*);
static void
-_pssubst(Ps *f, Ps *g, Ps *o)
+_pssubst(void *a)
{
- Ps *gg[2], *subst;
+ Ps **argv, *gg[2], *f, *g, *o, *subst;
+ Rat r;
+ enum{
+ REQ,
+ CLOSE,
+ NALT
+ };
+ Alt alts[NALT+1];
- switch @{
- alt @o->req:
- o->dat @= getr(f);
+ argv = a;
+ f = argv[0];
+ g = argv[1];
+ o = argv[2];
+
+ alts[REQ].c = o->req;
+ alts[REQ].v = nil;
+ alts[REQ].op = CHANRCV;
+ alts[CLOSE].c = o->close;
+ alts[CLOSE].v = nil;
+ alts[CLOSE].op = CHANRCV;
+ alts[NALT].op = CHANEND;
+
+ switch(alt(alts)){
+ case REQ:
+ r = getr(f);
+ send(o->dat, &r);
break;
- alt @o->close:
+ case CLOSE:
psfree(o);
- f->close @= 0;
- g->close @= 0;
+ send(f->close, nil);
+ send(g->close, nil);
if(debug) threadcount--;
threadexits(0);
}
@@ -423,15 +695,18 @@
split(g, gg, nil);
getr(gg[0]);
subst = psmul(gg[0], pssubst(f, gg[1]));
- for(;;) switch @{
- alt @o->req:
- o->dat @= getr(subst);
- break;
- alt @o->close:
- psfree(o);
- subst->close @= 0;
- if(debug) threadcount--;
- threadexits(0);
+ for(;;){
+ switch(alt(alts)){
+ case REQ:
+ r = getr(subst);
+ send(o->dat, &r);
+ break;
+ case CLOSE:
+ psfree(o);
+ send(subst->close, nil);
+ if(debug) threadcount--;
+ threadexits(0);
+ }
}
}
@@ -442,33 +717,58 @@
}
static void
-_psrev(Ps *f, Ps *r, Ps *rr, char @close)
+_psrev(void *a)
{
- Ps *rever;
- Rat g;
+ void **argv;
+ Ps *f, *r, *rr, *rever;
+ Channel *close;
+ Rat g;
+ enum{
+ REQ,
+ CLOSE,
+ NALT
+ };
+ Alt alts[NALT+1];
+ argv = a;
+ f = argv[0];
+ r = argv[1];
+ rr = argv[2];
+ close = argv[3];
+
+ alts[REQ].c = r->req;
+ alts[REQ].v = nil;
+ alts[REQ].op = CHANRCV;
+ alts[CLOSE].c = close;
+ alts[CLOSE].v = nil;
+ alts[CLOSE].op = CHANRCV;
+ alts[NALT].op = CHANEND;
+
g = ratmk(0, 1);
- switch @{
- alt @r->req:
- r->dat @= g;
+ switch(alt(alts)){
+ case REQ:
+ send(r->dat, &g);
break;
- alt @close:
- rr->close @= 0;
- f->close @= 0;
+ case CLOSE:
+ send(rr->close, nil);
+ send(f->close, nil);
goto End;
}
getr(f);
rever = psrecip(pssubst(f, rr));
- for(;;) switch @{
- alt @r->req:
- r->dat @= getr(rever);
- break;
- alt @close:
- rever->close @= 0;
- goto End;
+ for(;;){
+ switch(alt(alts)){
+ case REQ:
+ g = getr(rever);
+ send(r->dat, &g);
+ break;
+ case CLOSE:
+ send(rever->close, nil);
+ goto End;
+ }
}
End:
- @r->close;
+ recv(r->close, nil);
psfree(r);
if(debug) threadcount--;
threadexits(0);
@@ -477,24 +777,30 @@
Ps*
psrev(Ps *f)
{
- Ps *rr[2], *r;
- char @close;
+ void *argv[4];
+ Ps *rr[2], *r;
+ Channel *close = chancreate(1,0);
- chanset(close, 0);
r = psmk(0);
split(r, rr, close);
- cothread(_psrev(f, r, rr[0], close), STK);
+ argv[0] = f;
+ argv[1] = r;
+ argv[2] = rr[0];
+ argv[3] = close;
+ threadcreate(_psrev, argv, STK);
if(debug) threadcount++;
+ yield();
return rr[1];
}
void
-threadmain(int, char **)
+threadmain(int argc, char *argv[])
{
Ps *ps1, *ps2, *pssum, *ints, *tanx, *pspair[2];
Rat one, zero;
- debug = 1;
+ USED(argc);
+ USED(argv);
ratfmtinstall();
zero = ratmk(0, 1);
@@ -501,7 +807,6 @@
one = ratmk(1, 1);
ps1 = mkconst(one);
- print("1/1-x\n");
print("1 1 1 1 1 1 1 1 1 1\n");
psprint(ps1, 10);
print("\n");
@@ -508,7 +813,6 @@
ps2 = mkconst(one);
pssum = psadd(ps1, ps2);
- print("1/1-x + 1/1-x\n");
print("2 2 2 2 2 2 2 2 2 2\n");
psprint(pssum, 10);
print("\n");
@@ -516,7 +820,6 @@
ps1 = mkconst(one);
ints = psderiv(ps1);
- print("d/dx(1/1-x)\n");
print("1 2 3 4 5 6 7 8 9 10\n");
psprint(ints, 10);
print("\n");
@@ -524,7 +827,6 @@
ps1 = mkconst(one);
ps2 = psinteg(ps1, one);
- print("integral of 1/1-x\n");
print("1 1 1/2 1/3 1/4 1/5 1/6 1/7 1/8 1/9\n");
psprint(ps2, 10);
print("\n");
@@ -533,7 +835,6 @@
ps1 = mkconst(one);
ints = psderiv(ps1);
split(ints, pspair, nil);
- print("d/dx(1/1-x) split into two streams\n");
print("1 2 3 4 5 6 7 8 9 10\n");
print("1 2 3 4 5 6 7 8 9 10\n");
psprint(pspair[0], 10);
@@ -544,7 +845,6 @@
ps1 = mkconst(one);
ps2 = pscmul(ratmk(2, 1), ps1);
- print("2*(1/1-x)\n");
print("2 2 2 2 2 2 2 2 2 2\n");
psprint(ps2, 10);
print("\n");
@@ -553,7 +853,6 @@
ps1 = mkconst(one);
split(ps1, pspair, nil);
ps2 = psmul(pspair[0], pspair[1]);
- print("1/1-x split into two streams and then multiplied\n");
print("1 2 3 4 5 6 7 8 9 10\n");
psprint(ps2, 10);
print("\n");
@@ -561,7 +860,6 @@
ps1 = mkconst(one);
ps2 = psrecip(ps1);
- print("1/(1/1-x)\n");
print("1 -1 0 0 0 0 0 0 0 0\n");
psprint(ps2, 10);
print("\n");
@@ -569,9 +867,9 @@
ps1 = mkconst(one);
tanx = psrev(psinteg(psmsubst(ps1, ratmk(-1, 1), 2), zero));
- print("tan(x)\n");
print("0 1 0 1/3 0 2/15 0 17/315 0 62/2835 0 1382/155925\n");
psprint(tanx, 12);
send(tanx->close, nil);
+
threadexitsall(0);
}