1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
implement Newtypeset, Abcmodule;
include "sys.m";
sys: Sys;
include "draw.m";
include "sh.m";
include "alphabet/reports.m";
reports: Reports;
report: import reports;
include "bufio.m";
bufio: Bufio;
Iobuf: import bufio;
include "alphabet.m";
include "alphabet/abc.m";
abc: Abc;
Value, Vtype: import abc;
# types abc -> types
# returns a set of types defined in terms of the types and modules in $1
# stdtypes types -> types
# adds the standard root types to $1
# newtype [-u] types string string cmd -> types
# adds a new type named $2 to $1; the underlying type will be $3, and the destructor $4.
# -u flag implies values of this type cannot be duplicated.
# modules types -> modules
# returns a value suitable for defining modules in terms of types defined in $1,
# containing no module definitions.
# module modules string string cmd -> modules
# newtypeset abc string modules -> abc
# declares adds some autoconversions:
#
# autoconvert abc types "{| types}
# autoconvert types modules "{| modules}
#
# declares "{(abc)
# autodeclare 1 |
# newtypeset $1 /images {
# abc |
# autoconvert 1 |
# newtype image /fd "{} |
# newmodule read '/fd -> image' "{
# | /filter "{canonimage}
# } |
# newmodule rotate 'image -> image' "{
# | /filter "{rotate}
# } |
# newmodule display 'image -> /status' "{
# | /filter "{showimage} | /create /dev/null
# }
# } |
# type /images/image |
# import /images/rotate |
# autoconvert /string /fd "{|/read} |
# autoconvert /fd image "{|/images/read} |
# autoconvert image /status "{|/images/display}
# }
#
# -{rotate x.bit}
Newtypeset: module {};
types(): string
{
return "AAsm";
}
init()
{
sys = load Sys Sys->PATH;
reports = checkload(load Reports Reports->PATH, Reports->PATH);
abc = checkload(load Abc Abc->PATH, Abc->PATH);
abc->init();
}
quit()
{
}
run(errorc: chan of string, nil: ref Reports->Report,
nil: list of (int, list of ref Value),
args: list of ref Value
): ref Value
{
a := (hd args).A().i.alphabet;
d := (hd tl args).s().i;
path := "/dis/alphabet/" + d + "/alphabet"
iob := bufio->open(, Sys->OREAD);
if(iob == nil){
report(errorc, sys->sprint("scripttypeset: cannot open %q: %r", path));
return nil;
}
{
(types, decls) := parse(iob);
alphabet := load Alphabet Alphabet->PATH;
if(alphabet == nil){
report(errorc, sys->sprint("scripttypeset: cannot load %q: %r", Alphabet->PATH));
return nil;
}
declares := load Declares Declares->PATH;
if(declares == nil){
report(errorc, sys->sprint("scripttypeset: cannot load %q: %r", Alphabet->PATH));
return nil;
}
if((err := declares->declares(alphabet, decls, errorc)) != nil){
report(errorc, "scripttypeset: error on declarations: "+err);
return nil;
}
declares->quit();
declares = nil;
if(checktypes(alphabet, types, errorc) == -1)
return nil;
spawn scripttypesetproc(alphabet, types, c := chan of ref Proxy->Typescmd[ref Alphabet->Value]);
if((err := a->loadtypeset(d, c, errorc)) != nil){
c <-= nil;
return nil;
}
return (hd args).dup();
} exception e {
"parse:*" =>
report(errorc, sys->sprint("scripttypeset: error parsing %q: %s", path, e[6:]));
return nil;
}
}
checktypes(alphabet: Alphabet, types: list of ref Type, errorc: chan of string): int
{
for(; types != nil; types = tl types){
t := hd types;
if(t.destructor != nil){
report(errorc, "destructors not supported yet");
}
}
}
scripttypesetproc(alphabet: Alphabet, types: list of ref Type, c: chan of Proxy->Typescmd[ref Alphabet->Value])
{
while((gr := <-c) != nil){
pick r := gr {
Alphabet =>
Load =>
checkload[T](m: T, path: string): T
{
if(m != nil)
return m;
raise sys->sprint("fail:cannot load %s: %r", path);
}
|