summaryrefslogtreecommitdiff
path: root/appl/alphabet/typesets
diff options
context:
space:
mode:
Diffstat (limited to 'appl/alphabet/typesets')
-rw-r--r--appl/alphabet/typesets/abc.b180
-rw-r--r--appl/alphabet/typesets/abctypes.b229
-rw-r--r--appl/alphabet/typesets/fs.b226
-rw-r--r--appl/alphabet/typesets/fstypes.b230
-rw-r--r--appl/alphabet/typesets/grid.b160
-rw-r--r--appl/alphabet/typesets/gridtypes.b230
-rw-r--r--appl/alphabet/typesets/mkfile34
7 files changed, 1289 insertions, 0 deletions
diff --git a/appl/alphabet/typesets/abc.b b/appl/alphabet/typesets/abc.b
new file mode 100644
index 00000000..d2a060fd
--- /dev/null
+++ b/appl/alphabet/typesets/abc.b
@@ -0,0 +1,180 @@
+# warning: autogenerated code; don't bother to change this, change mktypeset.b or abc.b instead
+implement Abc;
+include "sys.m";
+ sys: Sys;
+include "draw.m";
+include "sh.m";
+include "alphabet/reports.m";
+include "alphabet.m";
+include "abc.m";
+mkabc(a: Alphabet): ref Value.VA
+{
+ r := chan[1] of int;
+ r <-= 1;
+ return ref Value.VA((r, a));
+}
+
+valuec := array[] of {
+ tagof(Value.Vm) => 'm',
+ tagof(Value.Vt) => 't',
+ tagof(Value.VA) => 'A',
+ tagof(Value.Vw) => 'w',
+ tagof(Value.Vc) => 'c',
+ tagof(Value.Vr) => 'r',
+ tagof(Value.Vf) => 'f',
+ tagof(Value.Vs) => 's',
+};
+
+init()
+{
+ sys = load Sys Sys->PATH;
+}
+
+Value.type2s(c: int): string
+{
+ case c {
+ 'm' =>
+ return "vmods";
+ 't' =>
+ return "vtypes";
+ 'A' =>
+ return "abc";
+ 'w' =>
+ return "wfd";
+ 'c' =>
+ return "cmd";
+ 'r' =>
+ return "status";
+ 'f' =>
+ return "fd";
+ 's' =>
+ return "string";
+ * =>
+ return sys->sprint("unknowntype('%c')", c);
+ }
+}
+
+typeerror(tc: int, v: ref Value): string
+{
+ sys->fprint(sys->fildes(2), "fs: bad type conversion, expected %s, was actually %s\n", Value.type2s(tc), Value.type2s(valuec[tagof v]));
+ return "type conversion error";
+}
+
+Value.m(v: self ref Value): ref Value.Vm
+{
+ pick xv := v {Vm => return xv;}
+ raise typeerror('m', v);
+}
+
+Value.t(v: self ref Value): ref Value.Vt
+{
+ pick xv := v {Vt => return xv;}
+ raise typeerror('t', v);
+}
+
+Value.A(v: self ref Value): ref Value.VA
+{
+ pick xv := v {VA => return xv;}
+ raise typeerror('A', v);
+}
+
+Value.w(v: self ref Value): ref Value.Vw
+{
+ pick xv := v {Vw => return xv;}
+ raise typeerror('w', v);
+}
+
+Value.c(v: self ref Value): ref Value.Vc
+{
+ pick xv := v {Vc => return xv;}
+ raise typeerror('c', v);
+}
+
+Value.r(v: self ref Value): ref Value.Vr
+{
+ pick xv := v {Vr => return xv;}
+ raise typeerror('r', v);
+}
+
+Value.f(v: self ref Value): ref Value.Vf
+{
+ pick xv := v {Vf => return xv;}
+ raise typeerror('f', v);
+}
+
+Value.s(v: self ref Value): ref Value.Vs
+{
+ pick xv := v {Vs => return xv;}
+ raise typeerror('s', v);
+}
+
+Value.typec(v: self ref Value): int
+{
+ return valuec[tagof v];
+}
+
+Value.dup(xv: self ref Value): ref Value
+{
+ if(xv == nil)
+ return nil;
+ pick v := xv {
+ Vm =>
+ v = nil;
+ xv = v;
+ Vt =>
+ v = nil;
+ xv = v;
+ VA =>
+ a := v.A().i;
+ a.refcount <-= <-a.refcount + 1;
+ xv = v;
+ Vw =>
+ v = nil;
+ xv = v;
+ Vr =>
+ v = nil;
+ xv = v;
+ Vf =>
+ v = nil;
+ xv = v;
+ }
+ return xv;
+}
+
+Value.free(xv: self ref Value, used: int)
+{
+ if(xv == nil)
+ return;
+ pick v := xv {
+ Vm =>
+ if(!used){
+ v.i.abc.free(0);
+ }
+ Vt =>
+ if(!used){
+ v.i.abc.free(0);
+ }
+ VA =>
+ r := v.i.refcount <-= <-v.i.refcount - 1;
+ if(r == 0){
+ v.i.alphabet->quit();
+ v.i.alphabet = nil;
+ v.i.refcount = nil;
+ }
+ Vw =>
+ if(!used){
+ <-v.i;
+ v.i <-= nil;
+ }
+ Vr =>
+ if(!used){
+ v.i <-= "stop";
+ }
+ Vf =>
+ if(!used){
+ <-v.i;
+ v.i <-= nil;
+ }
+ }
+}
+
diff --git a/appl/alphabet/typesets/abctypes.b b/appl/alphabet/typesets/abctypes.b
new file mode 100644
index 00000000..4fd5d24d
--- /dev/null
+++ b/appl/alphabet/typesets/abctypes.b
@@ -0,0 +1,229 @@
+# warning: autogenerated code; don't bother to change this, change mktypeset.b or abc.b instead
+implement Abctypes;
+include "sys.m";
+ sys: Sys;
+include "alphabet/reports.m";
+include "draw.m";
+include "sh.m";
+include "alphabet.m";
+ extvalues: Extvalues;
+ Values: import extvalues;
+ proxymod: Proxy;
+ Typescmd, Modulecmd: import Proxy;
+include "abc.m";
+ abc: Abc;
+ Value: import abc;
+include "abctypes.m";
+
+Pcontext: adt {
+ cvt: ref Abccvt;
+ ctxt: ref Context;
+
+ loadtypes: fn(ctxt: self ref Pcontext, name: string): (chan of ref Proxy->Typescmd[ref Value], string);
+ type2s: fn(ctxt: self ref Pcontext, tc: int): string;
+ alphabet: fn(ctxt: self ref Pcontext): string;
+ modules: fn(ctxt: self ref Pcontext, r: chan of string);
+ find: fn(ctxt: self ref Pcontext, s: string): (ref Module, string);
+ getcvt: fn(ctxt: self ref Pcontext): ref Abccvt;
+};
+
+proxy(): chan of ref Typescmd[ref Alphabet->Value]
+{
+ return proxy0().t0;
+}
+
+proxy0(): (
+ chan of ref Typescmd[ref Alphabet->Value],
+ chan of (string, chan of ref Typescmd[ref Abc->Value]),
+ ref Abccvt
+ )
+{
+ sys = load Sys Sys->PATH;
+ extvalues = checkload(load Extvalues Extvalues->PATH, Extvalues->PATH);
+ proxymod = checkload(load Proxy Proxy->PATH, Proxy->PATH);
+ abc = checkload(load Abc Abc->PATH, Abc->PATH);
+ abc->init();
+ cvt := ref Abccvt(Values[ref Value].new());
+ (t, newts) := proxymod->proxy(ref Pcontext(cvt, Context.new()));
+ return (t, newts, cvt);
+}
+
+include "readdir.m";
+Context: adt {
+ modules: fn(ctxt: self ref Context, r: chan of string);
+ loadtypes: fn(ctxt: self ref Context, name: string)
+ : (chan of ref Proxy->Typescmd[ref Value], string);
+ find: fn(ctxt: self ref Context, s: string): (ref Module, string);
+ new: fn(): ref Context;
+};
+Module: adt {
+ m: Abcmodule;
+ run: fn(m: self ref Module, ctxt: ref Draw->Context, r: ref Reports->Report,
+ errorc: chan of string, opts: list of (int, list of ref Value),
+ args: list of ref Value): ref Value;
+ typesig: fn(m: self ref Module): string;
+ quit: fn(m: self ref Module);
+};
+Context.new(): ref Context
+{
+ return nil;
+}
+Context.loadtypes(nil: self ref Context, name: string): (chan of ref Typescmd[ref Value], string)
+{
+ p := "/dis/alphabet/abc/"+name+"types.dis";
+ types := load Abcsubtypes p;
+ if(types == nil)
+ return (nil, sys->sprint("cannot load %q: %r", p));
+ return (types->proxy(), nil);
+}
+Context.modules(nil: self ref Context, r: chan of string)
+{
+ if((readdir := load Readdir Readdir->PATH) != nil){
+ (a, nil) := readdir->init("/dis/alphabet/abc", Readdir->NAME|Readdir->COMPACT);
+ for(i := 0; i < len a; i++){
+ m := a[i].name;
+ if((a[i].mode & Sys->DMDIR) == 0 && len m > 4 && m[len m - 4:] == ".dis")
+ r <-= m[0:len m - 4];
+ }
+ }
+ r <-= nil;
+}
+Context.find(nil: self ref Context, s: string): (ref Module, string)
+{
+ p := "/dis/alphabet/abc/"+s+".dis";
+ m := load Abcmodule p;
+ if(m == nil)
+ return (nil, sys->sprint("cannot load %q: %r", p));
+ {
+ m->init();
+ } exception e {
+ "fail:*" =>
+ return (nil, "init failed: " + e[5:]);
+ }
+ return (ref Module(m), nil);
+}
+Module.run(m: self ref Module, nil: ref Draw->Context, r: ref Reports->Report, errorc: chan of string,
+ opts: list of (int, list of ref Value), args: list of ref Value): ref Value
+{
+ return m.m->run(errorc, r, opts, args);
+}
+Module.typesig(m: self ref Module): string
+{
+ return m.m->types();
+}
+Module.quit(nil: self ref Module)
+{
+}
+Pcontext.type2s(nil: self ref Pcontext, tc: int): string
+{
+ return Value.type2s(tc);
+}
+
+Pcontext.alphabet(nil: self ref Pcontext): string
+{
+ return "mtAwcrfs";
+}
+
+Pcontext.getcvt(ctxt: self ref Pcontext): ref Abccvt
+{
+ return ctxt.cvt;
+}
+
+Pcontext.find(ctxt: self ref Pcontext, s: string): (ref Module, string)
+{
+ return ctxt.ctxt.find(s);
+}
+
+Pcontext.modules(ctxt: self ref Pcontext, r: chan of string)
+{
+ ctxt.ctxt.modules(r);
+}
+
+Pcontext.loadtypes(ctxt: self ref Pcontext, name: string): (chan of ref Typescmd[ref Value], string)
+{
+ return ctxt.ctxt.loadtypes(name);
+}
+
+Abccvt.int2ext(cvt: self ref Abccvt, gv: ref Value): ref Alphabet->Value
+{
+ if(gv == nil)
+ return nil;
+ pick v := gv {
+ Vw =>
+ return ref (Alphabet->Value).Vw(v.i);
+ Vf =>
+ return ref (Alphabet->Value).Vf(v.i);
+ Vr =>
+ return ref (Alphabet->Value).Vr(v.i);
+ Vs =>
+ return ref (Alphabet->Value).Vs(v.i);
+ Vc =>
+ return ref (Alphabet->Value).Vc(v.i);
+ * =>
+ id := cvt.values.add(gv);
+ return ref (Alphabet->Value).Vz((gv.typec(), id));
+ }
+}
+
+Abccvt.ext2int(cvt: self ref Abccvt, ev: ref Alphabet->Value): ref Value
+{
+ if(ev == nil)
+ return nil;
+ pick v := ev {
+ Vd =>
+ return nil; # can't happen
+ Vw =>
+ return ref Value.Vw(v.i);
+ Vf =>
+ return ref Value.Vf(v.i);
+ Vr =>
+ return ref Value.Vr(v.i);
+ Vs =>
+ return ref Value.Vs(v.i);
+ Vc =>
+ return ref Value.Vc(v.i);
+ Vz =>
+ x := cvt.values.v[v.i.id].t1;
+ if(x == nil){
+ sys->print("abctypes: bad id %d, type %c\n", v.i.id, v.i.typec);
+ return nil;
+ }
+ return x;
+ }
+}
+
+Abccvt.free(cvt: self ref Abccvt, gv: ref Alphabet->Value, used: int)
+{
+ pick v := gv {
+ Vz =>
+ id := v.i.id;
+ cvt.values.v[id].t1.free(used);
+ cvt.values.del(id);
+ }
+}
+
+Abccvt.dup(cvt: self ref Abccvt, gv: ref Alphabet->Value): ref Alphabet->Value
+{
+ pick ev := gv {
+ Vz =>
+ id := ev.i.id;
+ v := cvt.values.v[id].t1;
+ nv := v.dup();
+ if(nv == nil)
+ return nil;
+ if(nv != v)
+ return ref (Alphabet->Value).Vz((ev.i.typec, cvt.values.add(nv)));
+ cvt.values.inc(id);
+ return ev;
+ * =>
+ return nil;
+ }
+}
+
+checkload[T](m: T, path: string): T
+{
+ if(m != nil)
+ return m;
+ sys->fprint(sys->fildes(2), "abctypes: cannot load %s: %r\n", path);
+ raise "fail:bad module";
+}
diff --git a/appl/alphabet/typesets/fs.b b/appl/alphabet/typesets/fs.b
new file mode 100644
index 00000000..9b50d13f
--- /dev/null
+++ b/appl/alphabet/typesets/fs.b
@@ -0,0 +1,226 @@
+# warning: autogenerated code; don't bother to change this, change mktypeset.b or fs.b instead
+implement Fs;
+include "sys.m";
+ sys: Sys;
+include "draw.m";
+include "sh.m";
+include "alphabet/reports.m";
+include "fs.m";
+sendnulldir(c: Fschan): int
+{
+ reply := chan of int;
+ c <-= ((ref Sys->nulldir, nil), reply);
+ if((r := <-reply) == Down){
+ c <-= ((nil, nil), reply);
+ if(<-reply != Quit)
+ return Quit;
+ return Next;
+ }
+ return r;
+}
+# copy the contents (not the entry itself) of a directory from src to dst.
+copy(src, dst: Fschan): int
+{
+ indent := 1;
+ myreply := chan of int;
+ for(;;){
+ (d, reply) := <-src;
+ dst <-= (d, myreply);
+ r := <-myreply;
+ case reply <-= r {
+ Quit =>
+ return Quit;
+ Next =>
+ if(d.dir == nil && d.data == nil)
+ if(--indent == 0)
+ return Next;
+ Skip =>
+ if(--indent == 0)
+ return Next;
+ Down =>
+ if(d.dir != nil || d.data != nil)
+ indent++;
+ }
+ }
+}
+
+valuec := array[] of {
+ tagof(Value.Vr) => 'r',
+ tagof(Value.Vd) => 'd',
+ tagof(Value.Vc) => 'c',
+ tagof(Value.Vf) => 'f',
+ tagof(Value.Vs) => 's',
+ tagof(Value.Vm) => 'm',
+ tagof(Value.Vp) => 'p',
+ tagof(Value.Vt) => 't',
+ tagof(Value.Vx) => 'x',
+};
+
+init()
+{
+ sys = load Sys Sys->PATH;
+}
+
+Value.type2s(c: int): string
+{
+ case c {
+ 'r' =>
+ return "status";
+ 'd' =>
+ return "data";
+ 'c' =>
+ return "command";
+ 'f' =>
+ return "fd";
+ 's' =>
+ return "string";
+ 'm' =>
+ return "selector";
+ 'p' =>
+ return "gate";
+ 't' =>
+ return "entries";
+ 'x' =>
+ return "fs";
+ * =>
+ return sys->sprint("unknowntype('%c')", c);
+ }
+}
+
+typeerror(tc: int, v: ref Value): string
+{
+ sys->fprint(sys->fildes(2), "fs: bad type conversion, expected %s, was actually %s\n", Value.type2s(tc), Value.type2s(valuec[tagof v]));
+ return "type conversion error";
+}
+
+Value.r(v: self ref Value): ref Value.Vr
+{
+ pick xv := v {Vr => return xv;}
+ raise typeerror('r', v);
+}
+
+Value.d(v: self ref Value): ref Value.Vd
+{
+ pick xv := v {Vd => return xv;}
+ raise typeerror('d', v);
+}
+
+Value.c(v: self ref Value): ref Value.Vc
+{
+ pick xv := v {Vc => return xv;}
+ raise typeerror('c', v);
+}
+
+Value.f(v: self ref Value): ref Value.Vf
+{
+ pick xv := v {Vf => return xv;}
+ raise typeerror('f', v);
+}
+
+Value.s(v: self ref Value): ref Value.Vs
+{
+ pick xv := v {Vs => return xv;}
+ raise typeerror('s', v);
+}
+
+Value.m(v: self ref Value): ref Value.Vm
+{
+ pick xv := v {Vm => return xv;}
+ raise typeerror('m', v);
+}
+
+Value.p(v: self ref Value): ref Value.Vp
+{
+ pick xv := v {Vp => return xv;}
+ raise typeerror('p', v);
+}
+
+Value.t(v: self ref Value): ref Value.Vt
+{
+ pick xv := v {Vt => return xv;}
+ raise typeerror('t', v);
+}
+
+Value.x(v: self ref Value): ref Value.Vx
+{
+ pick xv := v {Vx => return xv;}
+ raise typeerror('x', v);
+}
+
+Value.typec(v: self ref Value): int
+{
+ return valuec[tagof v];
+}
+
+Value.dup(xv: self ref Value): ref Value
+{
+ if(xv == nil)
+ return nil;
+ pick v := xv {
+ Vr =>
+ v = nil;
+ xv = v;
+ Vd =>
+ v = nil;
+ xv = v;
+ Vf =>
+ v = nil;
+ xv = v;
+ Vm =>
+ v = nil;
+ xv = v;
+ Vp =>
+ v = nil;
+ xv = v;
+ Vt =>
+ v = nil;
+ xv = v;
+ Vx =>
+ v = nil;
+ xv = v;
+ }
+ return xv;
+}
+
+Value.free(xv: self ref Value, used: int)
+{
+ if(xv == nil)
+ return;
+ pick v := xv {
+ Vr =>
+ if(!used){
+ v.i <-= "stop";
+ }
+ Vd =>
+ if(!used){
+ alt{
+ v.i.stop <-= 1 =>
+ ;
+ * =>
+ ;
+ }
+ }
+ Vf =>
+ if(!used){
+ <-v.i;
+ v.i <-= nil;
+ }
+ Vm =>
+ if(!used){
+ v.i <-= (nil, nil, nil);
+ }
+ Vp =>
+ if(!used){
+ v.i <-= (Nilentry, nil);
+ }
+ Vt =>
+ if(!used){
+ v.i.sync <-= 0;
+ }
+ Vx =>
+ if(!used){
+ (<-v.i).t1 <-= Quit;
+ }
+ }
+}
+
diff --git a/appl/alphabet/typesets/fstypes.b b/appl/alphabet/typesets/fstypes.b
new file mode 100644
index 00000000..086b2089
--- /dev/null
+++ b/appl/alphabet/typesets/fstypes.b
@@ -0,0 +1,230 @@
+# warning: autogenerated code; don't bother to change this, change mktypeset.b or fs.b instead
+implement Fstypes;
+include "sys.m";
+ sys: Sys;
+include "alphabet/reports.m";
+include "draw.m";
+include "sh.m";
+include "alphabet.m";
+ extvalues: Extvalues;
+ Values: import extvalues;
+ proxymod: Proxy;
+ Typescmd, Modulecmd: import Proxy;
+include "fs.m";
+ fs: Fs;
+ Value: import fs;
+include "fstypes.m";
+
+Pcontext: adt {
+ cvt: ref Fscvt;
+ ctxt: ref Context;
+
+ loadtypes: fn(ctxt: self ref Pcontext, name: string): (chan of ref Proxy->Typescmd[ref Value], string);
+ type2s: fn(ctxt: self ref Pcontext, tc: int): string;
+ alphabet: fn(ctxt: self ref Pcontext): string;
+ modules: fn(ctxt: self ref Pcontext, r: chan of string);
+ find: fn(ctxt: self ref Pcontext, s: string): (ref Module, string);
+ getcvt: fn(ctxt: self ref Pcontext): ref Fscvt;
+};
+
+proxy(): chan of ref Typescmd[ref Alphabet->Value]
+{
+ return proxy0().t0;
+}
+
+proxy0(): (
+ chan of ref Typescmd[ref Alphabet->Value],
+ chan of (string, chan of ref Typescmd[ref Fs->Value]),
+ ref Fscvt
+ )
+{
+ sys = load Sys Sys->PATH;
+ extvalues = checkload(load Extvalues Extvalues->PATH, Extvalues->PATH);
+ proxymod = checkload(load Proxy Proxy->PATH, Proxy->PATH);
+ fs = checkload(load Fs Fs->PATH, Fs->PATH);
+ fs->init();
+ cvt := ref Fscvt(Values[ref Value].new());
+ (t, newts) := proxymod->proxy(ref Pcontext(cvt, Context.new()));
+ return (t, newts, cvt);
+}
+
+include "readdir.m";
+Context: adt {
+ modules: fn(ctxt: self ref Context, r: chan of string);
+ loadtypes: fn(ctxt: self ref Context, name: string)
+ : (chan of ref Proxy->Typescmd[ref Value], string);
+ find: fn(ctxt: self ref Context, s: string): (ref Module, string);
+ new: fn(): ref Context;
+};
+Module: adt {
+ m: Fsmodule;
+ run: fn(m: self ref Module, ctxt: ref Draw->Context, r: ref Reports->Report,
+ errorc: chan of string, opts: list of (int, list of ref Value),
+ args: list of ref Value): ref Value;
+ typesig: fn(m: self ref Module): string;
+ quit: fn(m: self ref Module);
+};
+Context.new(): ref Context
+{
+ return nil;
+}
+Context.loadtypes(nil: self ref Context, name: string): (chan of ref Typescmd[ref Value], string)
+{
+ p := "/dis/alphabet/fs/"+name+"types.dis";
+ types := load Fssubtypes p;
+ if(types == nil)
+ return (nil, sys->sprint("cannot load %q: %r", p));
+ return (types->proxy(), nil);
+}
+Context.modules(nil: self ref Context, r: chan of string)
+{
+ if((readdir := load Readdir Readdir->PATH) != nil){
+ (a, nil) := readdir->init("/dis/alphabet/fs", Readdir->NAME|Readdir->COMPACT);
+ for(i := 0; i < len a; i++){
+ m := a[i].name;
+ if((a[i].mode & Sys->DMDIR) == 0 && len m > 4 && m[len m - 4:] == ".dis")
+ r <-= m[0:len m - 4];
+ }
+ }
+ r <-= nil;
+}
+Context.find(nil: self ref Context, s: string): (ref Module, string)
+{
+ p := "/dis/alphabet/fs/"+s+".dis";
+ m := load Fsmodule p;
+ if(m == nil)
+ return (nil, sys->sprint("cannot load %q: %r", p));
+ {
+ m->init();
+ } exception e {
+ "fail:*" =>
+ return (nil, "init failed: " + e[5:]);
+ }
+ return (ref Module(m), nil);
+}
+Module.run(m: self ref Module, ctxt: ref Draw->Context, r: ref Reports->Report, nil: chan of string,
+ opts: list of (int, list of ref Value), args: list of ref Value): ref Value
+{
+ # add errorc
+ return m.m->run(ctxt, r, opts, args);
+}
+Module.typesig(m: self ref Module): string
+{
+ return m.m->types();
+}
+Module.quit(nil: self ref Module)
+{
+}
+Pcontext.type2s(nil: self ref Pcontext, tc: int): string
+{
+ return Value.type2s(tc);
+}
+
+Pcontext.alphabet(nil: self ref Pcontext): string
+{
+ return "rdcfsmptx";
+}
+
+Pcontext.getcvt(ctxt: self ref Pcontext): ref Fscvt
+{
+ return ctxt.cvt;
+}
+
+Pcontext.find(ctxt: self ref Pcontext, s: string): (ref Module, string)
+{
+ return ctxt.ctxt.find(s);
+}
+
+Pcontext.modules(ctxt: self ref Pcontext, r: chan of string)
+{
+ ctxt.ctxt.modules(r);
+}
+
+Pcontext.loadtypes(ctxt: self ref Pcontext, name: string): (chan of ref Typescmd[ref Value], string)
+{
+ return ctxt.ctxt.loadtypes(name);
+}
+
+Fscvt.int2ext(cvt: self ref Fscvt, gv: ref Value): ref Alphabet->Value
+{
+ if(gv == nil)
+ return nil;
+ pick v := gv {
+ Vd =>
+ return ref (Alphabet->Value).Vd(v.i);
+ Vf =>
+ return ref (Alphabet->Value).Vf(v.i);
+ Vr =>
+ return ref (Alphabet->Value).Vr(v.i);
+ Vs =>
+ return ref (Alphabet->Value).Vs(v.i);
+ Vc =>
+ return ref (Alphabet->Value).Vc(v.i);
+ * =>
+ id := cvt.values.add(gv);
+ return ref (Alphabet->Value).Vz((gv.typec(), id));
+ }
+}
+
+Fscvt.ext2int(cvt: self ref Fscvt, ev: ref Alphabet->Value): ref Value
+{
+ if(ev == nil)
+ return nil;
+ pick v := ev {
+ Vd =>
+ return ref Value.Vd(v.i);
+ Vw =>
+ return nil; # can't happen
+ Vf =>
+ return ref Value.Vf(v.i);
+ Vr =>
+ return ref Value.Vr(v.i);
+ Vs =>
+ return ref Value.Vs(v.i);
+ Vc =>
+ return ref Value.Vc(v.i);
+ Vz =>
+ x := cvt.values.v[v.i.id].t1;
+ if(x == nil){
+ sys->print("fstypes: bad id %d, type %c\n", v.i.id, v.i.typec);
+ return nil;
+ }
+ return x;
+ }
+}
+
+Fscvt.free(cvt: self ref Fscvt, gv: ref Alphabet->Value, used: int)
+{
+ pick v := gv {
+ Vz =>
+ id := v.i.id;
+ cvt.values.v[id].t1.free(used);
+ cvt.values.del(id);
+ }
+}
+
+Fscvt.dup(cvt: self ref Fscvt, gv: ref Alphabet->Value): ref Alphabet->Value
+{
+ pick ev := gv {
+ Vz =>
+ id := ev.i.id;
+ v := cvt.values.v[id].t1;
+ nv := v.dup();
+ if(nv == nil)
+ return nil;
+ if(nv != v)
+ return ref (Alphabet->Value).Vz((ev.i.typec, cvt.values.add(nv)));
+ cvt.values.inc(id);
+ return ev;
+ * =>
+ return nil;
+ }
+}
+
+checkload[T](m: T, path: string): T
+{
+ if(m != nil)
+ return m;
+ sys->fprint(sys->fildes(2), "fstypes: cannot load %s: %r\n", path);
+ raise "fail:bad module";
+}
diff --git a/appl/alphabet/typesets/grid.b b/appl/alphabet/typesets/grid.b
new file mode 100644
index 00000000..cba8366c
--- /dev/null
+++ b/appl/alphabet/typesets/grid.b
@@ -0,0 +1,160 @@
+# warning: autogenerated code; don't bother to change this, change mktypeset.b or grid.b instead
+implement Grid;
+include "sys.m";
+ sys: Sys;
+include "draw.m";
+include "sh.m";
+include "alphabet/reports.m";
+include "alphabet/endpoints.m";
+include "grid.m";
+endpoints: Endpoints;
+
+valuec := array[] of {
+ tagof(Value.Vb) => 'b',
+ tagof(Value.Ve) => 'e',
+ tagof(Value.Vw) => 'w',
+ tagof(Value.Vc) => 'c',
+ tagof(Value.Vr) => 'r',
+ tagof(Value.Vf) => 'f',
+ tagof(Value.Vs) => 's',
+};
+
+init()
+{
+ sys = load Sys Sys->PATH;
+ endpoints = load Endpoints Endpoints->PATH;
+ endpoints->init();
+}
+
+Value.type2s(c: int): string
+{
+ case c {
+ 'b' =>
+ return "records";
+ 'e' =>
+ return "endpoint";
+ 'w' =>
+ return "wfd";
+ 'c' =>
+ return "cmd";
+ 'r' =>
+ return "status";
+ 'f' =>
+ return "fd";
+ 's' =>
+ return "string";
+ * =>
+ return sys->sprint("unknowntype('%c')", c);
+ }
+}
+
+typeerror(tc: int, v: ref Value): string
+{
+ sys->fprint(sys->fildes(2), "fs: bad type conversion, expected %s, was actually %s\n", Value.type2s(tc), Value.type2s(valuec[tagof v]));
+ return "type conversion error";
+}
+
+Value.b(v: self ref Value): ref Value.Vb
+{
+ pick xv := v {Vb => return xv;}
+ raise typeerror('b', v);
+}
+
+Value.e(v: self ref Value): ref Value.Ve
+{
+ pick xv := v {Ve => return xv;}
+ raise typeerror('e', v);
+}
+
+Value.w(v: self ref Value): ref Value.Vw
+{
+ pick xv := v {Vw => return xv;}
+ raise typeerror('w', v);
+}
+
+Value.c(v: self ref Value): ref Value.Vc
+{
+ pick xv := v {Vc => return xv;}
+ raise typeerror('c', v);
+}
+
+Value.r(v: self ref Value): ref Value.Vr
+{
+ pick xv := v {Vr => return xv;}
+ raise typeerror('r', v);
+}
+
+Value.f(v: self ref Value): ref Value.Vf
+{
+ pick xv := v {Vf => return xv;}
+ raise typeerror('f', v);
+}
+
+Value.s(v: self ref Value): ref Value.Vs
+{
+ pick xv := v {Vs => return xv;}
+ raise typeerror('s', v);
+}
+
+Value.typec(v: self ref Value): int
+{
+ return valuec[tagof v];
+}
+
+Value.dup(xv: self ref Value): ref Value
+{
+ if(xv == nil)
+ return nil;
+ pick v := xv {
+ Vb =>
+ v = nil;
+ xv = v;
+ Ve =>
+ v = nil;
+ xv = v;
+ Vw =>
+ v = nil;
+ xv = v;
+ Vr =>
+ v = nil;
+ xv = v;
+ Vf =>
+ v = nil;
+ xv = v;
+ }
+ return xv;
+}
+
+Value.free(xv: self ref Value, used: int)
+{
+ if(xv == nil)
+ return;
+ pick v := xv {
+ Vb =>
+ if(!used){
+ <-v.i;
+ v.i <-= nil;
+ }
+ Ve =>
+ if(!used){
+ ep := <-v.i;
+ if(ep.addr != nil)
+ endpoints->open(nil, ep); # open and discard
+ }
+ Vw =>
+ if(!used){
+ <-v.i;
+ v.i <-= nil;
+ }
+ Vr =>
+ if(!used){
+ v.i <-= "stop";
+ }
+ Vf =>
+ if(!used){
+ <-v.i;
+ v.i <-= nil;
+ }
+ }
+}
+
diff --git a/appl/alphabet/typesets/gridtypes.b b/appl/alphabet/typesets/gridtypes.b
new file mode 100644
index 00000000..05fc1bce
--- /dev/null
+++ b/appl/alphabet/typesets/gridtypes.b
@@ -0,0 +1,230 @@
+# warning: autogenerated code; don't bother to change this, change mktypeset.b or grid.b instead
+implement Gridtypes;
+include "sys.m";
+ sys: Sys;
+include "alphabet/reports.m";
+include "draw.m";
+include "sh.m";
+include "alphabet.m";
+ extvalues: Extvalues;
+ Values: import extvalues;
+ proxymod: Proxy;
+ Typescmd, Modulecmd: import Proxy;
+include "alphabet/endpoints.m";
+include "grid.m";
+ grid: Grid;
+ Value: import grid;
+include "gridtypes.m";
+
+Pcontext: adt {
+ cvt: ref Gridcvt;
+ ctxt: ref Context;
+
+ loadtypes: fn(ctxt: self ref Pcontext, name: string): (chan of ref Proxy->Typescmd[ref Value], string);
+ type2s: fn(ctxt: self ref Pcontext, tc: int): string;
+ alphabet: fn(ctxt: self ref Pcontext): string;
+ modules: fn(ctxt: self ref Pcontext, r: chan of string);
+ find: fn(ctxt: self ref Pcontext, s: string): (ref Module, string);
+ getcvt: fn(ctxt: self ref Pcontext): ref Gridcvt;
+};
+
+proxy(): chan of ref Typescmd[ref Alphabet->Value]
+{
+ return proxy0().t0;
+}
+
+proxy0(): (
+ chan of ref Typescmd[ref Alphabet->Value],
+ chan of (string, chan of ref Typescmd[ref Grid->Value]),
+ ref Gridcvt
+ )
+{
+ sys = load Sys Sys->PATH;
+ extvalues = checkload(load Extvalues Extvalues->PATH, Extvalues->PATH);
+ proxymod = checkload(load Proxy Proxy->PATH, Proxy->PATH);
+ grid = checkload(load Grid Grid->PATH, Grid->PATH);
+ grid->init();
+ cvt := ref Gridcvt(Values[ref Value].new());
+ (t, newts) := proxymod->proxy(ref Pcontext(cvt, Context.new()));
+ return (t, newts, cvt);
+}
+
+include "readdir.m";
+Context: adt {
+ modules: fn(ctxt: self ref Context, r: chan of string);
+ loadtypes: fn(ctxt: self ref Context, name: string)
+ : (chan of ref Proxy->Typescmd[ref Value], string);
+ find: fn(ctxt: self ref Context, s: string): (ref Module, string);
+ new: fn(): ref Context;
+};
+Module: adt {
+ m: Gridmodule;
+ run: fn(m: self ref Module, ctxt: ref Draw->Context, r: ref Reports->Report,
+ errorc: chan of string, opts: list of (int, list of ref Value),
+ args: list of ref Value): ref Value;
+ typesig: fn(m: self ref Module): string;
+ quit: fn(m: self ref Module);
+};
+Context.new(): ref Context
+{
+ return nil;
+}
+Context.loadtypes(nil: self ref Context, name: string): (chan of ref Typescmd[ref Value], string)
+{
+ p := "/dis/alphabet/grid/"+name+"types.dis";
+ types := load Gridsubtypes p;
+ if(types == nil)
+ return (nil, sys->sprint("cannot load %q: %r", p));
+ return (types->proxy(), nil);
+}
+Context.modules(nil: self ref Context, r: chan of string)
+{
+ if((readdir := load Readdir Readdir->PATH) != nil){
+ (a, nil) := readdir->init("/dis/alphabet/grid", Readdir->NAME|Readdir->COMPACT);
+ for(i := 0; i < len a; i++){
+ m := a[i].name;
+ if((a[i].mode & Sys->DMDIR) == 0 && len m > 4 && m[len m - 4:] == ".dis")
+ r <-= m[0:len m - 4];
+ }
+ }
+ r <-= nil;
+}
+Context.find(nil: self ref Context, s: string): (ref Module, string)
+{
+ p := "/dis/alphabet/grid/"+s+".dis";
+ m := load Gridmodule p;
+ if(m == nil)
+ return (nil, sys->sprint("cannot load %q: %r", p));
+ {
+ m->init();
+ } exception e {
+ "fail:*" =>
+ return (nil, "init failed: " + e[5:]);
+ }
+ return (ref Module(m), nil);
+}
+Module.run(m: self ref Module, nil: ref Draw->Context, r: ref Reports->Report, errorc: chan of string,
+ opts: list of (int, list of ref Value), args: list of ref Value): ref Value
+{
+ return m.m->run(errorc, r, opts, args);
+}
+Module.typesig(m: self ref Module): string
+{
+ return m.m->types();
+}
+Module.quit(nil: self ref Module)
+{
+}
+Pcontext.type2s(nil: self ref Pcontext, tc: int): string
+{
+ return Value.type2s(tc);
+}
+
+Pcontext.alphabet(nil: self ref Pcontext): string
+{
+ return "bewcrfs";
+}
+
+Pcontext.getcvt(ctxt: self ref Pcontext): ref Gridcvt
+{
+ return ctxt.cvt;
+}
+
+Pcontext.find(ctxt: self ref Pcontext, s: string): (ref Module, string)
+{
+ return ctxt.ctxt.find(s);
+}
+
+Pcontext.modules(ctxt: self ref Pcontext, r: chan of string)
+{
+ ctxt.ctxt.modules(r);
+}
+
+Pcontext.loadtypes(ctxt: self ref Pcontext, name: string): (chan of ref Typescmd[ref Value], string)
+{
+ return ctxt.ctxt.loadtypes(name);
+}
+
+Gridcvt.int2ext(cvt: self ref Gridcvt, gv: ref Value): ref Alphabet->Value
+{
+ if(gv == nil)
+ return nil;
+ pick v := gv {
+ Vw =>
+ return ref (Alphabet->Value).Vw(v.i);
+ Vf =>
+ return ref (Alphabet->Value).Vf(v.i);
+ Vr =>
+ return ref (Alphabet->Value).Vr(v.i);
+ Vs =>
+ return ref (Alphabet->Value).Vs(v.i);
+ Vc =>
+ return ref (Alphabet->Value).Vc(v.i);
+ * =>
+ id := cvt.values.add(gv);
+ return ref (Alphabet->Value).Vz((gv.typec(), id));
+ }
+}
+
+Gridcvt.ext2int(cvt: self ref Gridcvt, ev: ref Alphabet->Value): ref Value
+{
+ if(ev == nil)
+ return nil;
+ pick v := ev {
+ Vd =>
+ return nil; # can't happen
+ Vw =>
+ return ref Value.Vw(v.i);
+ Vf =>
+ return ref Value.Vf(v.i);
+ Vr =>
+ return ref Value.Vr(v.i);
+ Vs =>
+ return ref Value.Vs(v.i);
+ Vc =>
+ return ref Value.Vc(v.i);
+ Vz =>
+ x := cvt.values.v[v.i.id].t1;
+ if(x == nil){
+ sys->print("gridtypes: bad id %d, type %c\n", v.i.id, v.i.typec);
+ return nil;
+ }
+ return x;
+ }
+}
+
+Gridcvt.free(cvt: self ref Gridcvt, gv: ref Alphabet->Value, used: int)
+{
+ pick v := gv {
+ Vz =>
+ id := v.i.id;
+ cvt.values.v[id].t1.free(used);
+ cvt.values.del(id);
+ }
+}
+
+Gridcvt.dup(cvt: self ref Gridcvt, gv: ref Alphabet->Value): ref Alphabet->Value
+{
+ pick ev := gv {
+ Vz =>
+ id := ev.i.id;
+ v := cvt.values.v[id].t1;
+ nv := v.dup();
+ if(nv == nil)
+ return nil;
+ if(nv != v)
+ return ref (Alphabet->Value).Vz((ev.i.typec, cvt.values.add(nv)));
+ cvt.values.inc(id);
+ return ev;
+ * =>
+ return nil;
+ }
+}
+
+checkload[T](m: T, path: string): T
+{
+ if(m != nil)
+ return m;
+ sys->fprint(sys->fildes(2), "gridtypes: cannot load %s: %r\n", path);
+ raise "fail:bad module";
+}
diff --git a/appl/alphabet/typesets/mkfile b/appl/alphabet/typesets/mkfile
new file mode 100644
index 00000000..dc0a0a81
--- /dev/null
+++ b/appl/alphabet/typesets/mkfile
@@ -0,0 +1,34 @@
+<../../../mkconfig
+
+TARG=\
+ mktypeset.dis\
+ abc.dis\
+ abctypes.dis\
+ fs.dis\
+ fstypes.dis\
+ grid.dis\
+ gridtypes.dis\
+
+SYSMODULES=\
+ alphabet.m\
+ alphabet/endpoints.m\
+ alphabet/reports.m\
+ draw.m\
+ readdir.m\
+ sh.m\
+ sys.m\
+ alphabet/abc.m\
+ alphabet/abctypes.m\
+ alphabet/fs.m\
+ alphabet/fstypes.m\
+ alphabet/grid.m\
+ alphabet/gridtypes.m\
+
+DISBIN=$ROOT/dis/alphabet
+
+<$ROOT/mkfiles/mkdis
+
+LIMBOFLAGS=$LIMBOFLAGS -i -F
+
+#%.b %types.b %.m %types.m: %.typeset
+# mktypeset $stem.typeset