-
-
Notifications
You must be signed in to change notification settings - Fork 85
/
modula-2.scroll
446 lines (400 loc) · 10.7 KB
/
modula-2.scroll
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
import ../code/conceptPage.scroll
id modula-2
name Modula-2
appeared 1978
creators Niklaus Wirth
tags pl
blog https://freepages.modula2.org/oldnew.html
download https://www.modula2.org/adwm2/download.php
gdbSupport true
fileExtensions mod m2 def MOD DEF mi md
fileType text
documentation https://www.modula2.org/tutor/introduction.php
rosettaCode http://www.rosettacode.org/wiki/Category:Modula-2
centralPackageRepositoryCount 0
country Switzerland
originCommunity ETH Zurich
helloWorldCollection Modula-2
(* Hello World in Modula-2 *)
MODULE HelloWorld;
FROM InOut IMPORT WriteString,WriteLn;
BEGIN
WriteString("Hello World!");
WriteLn;
END HelloWorld.
pygmentsHighlighter Modula-2
filename modula2.py
fileExtensions def mod
leachim6 Modula 2
filepath m/Modula 2.mod
example
MODULE HelloWorld;
FROM Terminal2 IMPORT WriteString, WriteLn;
BEGIN
WriteString("Hello World");
WriteLn;
END HelloWorld.
multiLineCommentTokens (* *)
printToken WriteString
stringToken "
booleanTokens TRUE FALSE
hasComments true
hasLineComments false
hasPointers true
hasOperatorOverloading false
hasMultiLineComments true
(* A comment
*)
hasPrintDebugging true
hasSemanticIndentation false
hasCaseInsensitiveIdentifiers false
hasStrings true
"Hello world"
hasBooleans true
wikipedia https://en.wikipedia.org/wiki/Modula-2
example
ABS EXCL LONGINT REAL
BITSET FALSE LONGREAL SIZE
BOOLEAN FLOAT MAX TRUE
CAP HALT MIN TRUNC
CARDINAL HIGH NIL VAL
CHAR INC ODD
CHR INCL ORD
DEC INTEGER PROC
related modula mesa pascal modula-3 oberon ada lua seed7 zonnon isbn
summary Modula-2 is a computer programming language designed and developed between 1977 and 1985 by Niklaus Wirth at the Swiss Federal Institute of Technology in Zurich (ETH Zurich) as a revision of Pascal to serve as the sole programming language for the operating system and application software for the personal workstation Lilith. The principal concepts were: The module as a compilation unit for separate compilation The coroutine as the basic building block for concurrent processes Types and procedures that allow access to machine-specific data. Modula-2 was viewed by Niklaus Wirth as a successor to his earlier programming languages Pascal and Modula. The language design was also influenced by the Mesa language and the new programming possibilities of the early personal computer Xerox Alto, both from Xerox, that Wirth saw during his 1976 sabbatical year at Xerox PARC. The computer magazine BYTE devoted the August 1984 issue to the language and its surrounding environment.
pageId 24102707
dailyPageViews 87
created 2002
backlinksCount 211
revisionCount 508
appeared 1978
fileExtensions mod m2 def MOD DEF mi md
hopl https://hopl.info/showlanguage.prx?exp=817
tiobe Modula-2
githubBigQuery Modula-2
repos 115
users 103
linguistGrammarRepo https://github.com/harogaston/Sublime-Modula-2
firstCommit 2014
lastCommit 2015
committerCount 4
commitCount 27
sampleCount 1
example
IMPLEMENTATION MODULE HuffChan;
(*
This module shows how to redefine standard IO file functions. It provides
functions for reading and writing packed files opened in Raw mode.
*)
IMPORT IOChan, IOLink, ChanConsts, IOConsts, SYSTEM, Strings;
FROM Storage IMPORT ALLOCATE, DEALLOCATE;
CONST
rbldFrq = 512; (* means: every 512 bytes rebuild table *)
TYPE
charTap = POINTER TO ARRAY [0..MAX(INTEGER)-1] OF CHAR;
smbTp = POINTER TO smbT;
smbT = RECORD (* Huffman's tree *)
ch : CHAR;
n : CARDINAL; (* frequncy of char ch *)
left,right,next : smbTp;
END;
tblT = RECORD (* bit sequence for code *)
vl : CARDINAL; (* bit sequence *)
cnt : INTEGER; (* it length *)
END;
lclDataT = RECORD (* channel's local data *)
tRoot : smbTp;
htbl : ARRAY [0..255] OF tblT; (* code -> bit sequence table *)
ftbl : ARRAY [0..255] OF CARDINAL; (* frequncey table *)
wBf,rb1,rb2 : CARDINAL;
wbc,rbc,smc : INTEGER;
chid : IOChan.ChanId;
END;
lclDataTp = POINTER TO lclDataT;
charp = POINTER TO CHAR;
VAR
did : IOLink.DeviceId;
ldt : lclDataTp;
PROCEDURE Shf(a:CARDINAL; b : INTEGER) : CARDINAL; (* shl a,b (or shr) *)
BEGIN
RETURN SYSTEM.CAST(CARDINAL,SYSTEM.SHIFT(SYSTEM.CAST(BITSET,a),b));
END Shf;
PROCEDURE wrDword(a:CARDINAL); (* write 4 bytes to file *)
BEGIN
IOChan.RawWrite(ldt^.chid,SYSTEM.ADR(a),4);
END wrDword;
PROCEDURE rdDword() : CARDINAL; (* read 4 bytes from file *)
VAR
a,z : CARDINAL;
BEGIN
a:=0;
IOChan.RawRead(ldt^.chid,SYSTEM.ADR(a),4,z);
RETURN a;
END rdDword;
PROCEDURE wrSmb(ch : CHAR); (* write bit sequence for code ch *)
VAR
v,h : CARDINAL;
b,c : INTEGER;
BEGIN
WITH ldt^ DO
v:=htbl[ORD(ch)].vl;
c:=htbl[ORD(ch)].cnt;
IF c+wbc<=32 THEN
wBf:=Shf(wBf,c);
wBf:=wBf+v;
wbc:=wbc+c;
IF wbc=32 THEN
wrDword(wBf);
wBf:=0; wbc:=0;
END;
RETURN;
END;
b:=c+wbc-32;
h:=Shf(v,-b);
wBf:=Shf(wBf,32-wbc)+h;
wrDword(wBf);
wBf:=v-Shf(h,b);
wbc:=b;
END;
END wrSmb;
PROCEDURE flush(); (* write data in buffer *)
BEGIN
WITH ldt^ DO
wBf:=Shf(wBf,32-wbc);
wrDword(wBf);
END;
END flush;
PROCEDURE getSym() : CHAR; (* find code for first bit sequence in buffer *)
VAR
t,i : CARDINAL;
b : INTEGER;
BEGIN
WITH ldt^ DO
IF rbc<=32 THEN
rb2:=rdDword();
t:=Shf(rb2,-rbc);
IF rbc=32 THEN t:=0; END;
rb1:=rb1+t;
rb2:=Shf(rb2,32-rbc);
IF rbc=0 THEN rb2:=0; END;
rbc:=rbc+32;
END;
FOR i:=0 TO 255 DO
t:=Shf(rb1,htbl[i].cnt-32);
IF t=htbl[i].vl THEN
rb1:=Shf(rb1,htbl[i].cnt);
b:=32-htbl[i].cnt;
t:=Shf(rb2,-b);
rb1:=rb1+t;
rb2:=Shf(rb2,32-b);
rbc:=rbc+b-32;
RETURN CHR(i);
END;
END;
END;
END getSym;
PROCEDURE Insert(s : smbTp); (* insert new character in Huffman's tree *)
VAR
cr : smbTp;
BEGIN
WITH ldt^ DO
IF tRoot=NIL THEN
cr:=tRoot;
tRoot:=s;
s^.next:=cr;
RETURN;
ELSIF tRoot^.n<=s^.n THEN
cr:=tRoot;
tRoot:=s;
s^.next:=cr;
RETURN;
END;
cr:=tRoot;
WHILE (cr^.next<>NIL) & (cr^.next^.n>s^.n) DO
cr:=cr^.next;
END;
s^.next:=cr^.next;
cr^.next:=s;
END;
END Insert;
PROCEDURE BuildTree(); (* build Huffman's tree *)
VAR
cr,ocr,ncr : smbTp;
BEGIN
WITH ldt^ DO
LOOP
ocr:=NIL; cr:=tRoot;
WHILE cr^.next^.next<>NIL DO
ocr:=cr; cr:=cr^.next;
END;
NEW(ncr);
ncr^.n:=cr^.n+cr^.next^.n;
ncr^.left:=cr;
ncr^.right:=cr^.next;
IF ocr<>NIL THEN
ocr^.next:=NIL;
Insert(ncr);
ELSE
tRoot:=NIL;
Insert(ncr);
EXIT;
END;
END;
END;
END BuildTree;
PROCEDURE BuildTable(cr: smbTp; vl,n: CARDINAL); (* build table: code -> bit sequence *)
BEGIN
WITH ldt^ DO
IF cr^.left=NIL THEN
htbl[ORD(cr^.ch)].vl:=vl;
htbl[ORD(cr^.ch)].cnt:=n;
DISPOSE(cr);
RETURN;
END;
vl:=vl*2;
BuildTable(cr^.left,vl,n+1);
BuildTable(cr^.right,vl+1,n+1);
DISPOSE(cr);
END;
END BuildTable;
PROCEDURE clcTab(); (* build code/bitseq. table from frequency table *)
VAR
i : CARDINAL;
s : smbTp;
BEGIN
WITH ldt^ DO
tRoot:=NIL;
FOR i:=0 TO 255 DO
NEW(s);
s^.ch:=CHR(i);
s^.n:=ftbl[i];
s^.left:=NIL; s^.right:=NIL; s^.next:=NIL;
Insert(s);
END;
BuildTree();
BuildTable(tRoot,0,0);
END;
END clcTab;
PROCEDURE iniHuf();
VAR
i : CARDINAL;
BEGIN
WITH ldt^ DO
FOR i:=0 TO 255 DO
ftbl[i]:=1;
END;
wBf:=0; wbc:=0; rb1:=0; rb2:=0; rbc:=0;
smc:=0;
clcTab();
END;
END iniHuf;
PROCEDURE RawWrite(x: IOLink.DeviceTablePtr; buf: SYSTEM.ADDRESS;
len: CARDINAL);
VAR
i : CARDINAL;
ch : CHAR;
cht : charTap;
BEGIN
IF len = 0 THEN RETURN; END;
ldt:=SYSTEM.CAST(lclDataTp,x^.cd);
cht:=SYSTEM.CAST(charTap,buf);
WITH ldt^ DO
FOR i:=0 TO len-1 DO
ch:=cht^[i];
wrSmb(ch);
IF ch = 377C THEN wrSmb(ch); END;
ftbl[ORD(ch)]:=ftbl[ORD(ch)]+1; smc:=smc+1;
IF smc=rbldFrq THEN
clcTab();
smc:=0;
END;
END;
END;
x^.result:=IOChan.ReadResult(ldt^.chid);
END RawWrite;
PROCEDURE RawRead(x: IOLink.DeviceTablePtr; buf: SYSTEM.ADDRESS;
blen: CARDINAL; VAR len: CARDINAL);
VAR
i : CARDINAL;
cht : charTap;
ch : CHAR;
BEGIN
ldt:=SYSTEM.CAST(lclDataTp,x^.cd);
cht:=SYSTEM.CAST(charTap,buf);
IF (blen=0) OR (x^.result<>IOConsts.allRight) THEN len:=0; RETURN; END;
WITH ldt^ DO
FOR i:=0 TO blen-1 DO
ch:=getSym();
IF ch = 377C THEN
ch:=getSym();
IF ch = 0C THEN
x^.result:=IOConsts.endOfInput;
len:=i; cht^[i]:=0C;
RETURN;
END;
END;
cht^[i]:=ch;
ftbl[ORD(ch)]:=ftbl[ORD(ch)]+1; smc:=smc+1;
IF smc=rbldFrq THEN
clcTab();
smc:=0;
END;
END;
len:=blen;
END;
END RawRead;
PROCEDURE CreateAlias(VAR cid: ChanId; io: ChanId; VAR res: OpenResults);
VAR
x : IOLink.DeviceTablePtr;
BEGIN
IOLink.MakeChan(did,cid);
IF cid = IOChan.InvalidChan() THEN
res:=ChanConsts.outOfChans
ELSE
NEW(ldt);
IF ldt=NIL THEN
IOLink.UnMakeChan(did,cid);
res:=ChanConsts.outOfChans;
RETURN;
END;
x:=IOLink.DeviceTablePtrValue(cid,did,IOChan.notAvailable,"");
ldt^.chid:=io;
x^.cd:=ldt;
x^.doRawWrite:=RawWrite;
x^.doRawRead:=RawRead;
res:=ChanConsts.opened;
iniHuf();
x^.result:=IOConsts.allRight;
END;
END CreateAlias;
PROCEDURE DeleteAlias(VAR cid: ChanId);
VAR
x : IOLink.DeviceTablePtr;
BEGIN
x:=IOLink.DeviceTablePtrValue(cid,did,IOChan.notAvailable,"");
ldt:=x^.cd;
IF ldt^.rbc=0 THEN
wrSmb(377C);
wrSmb(0C);
flush();
END;
DISPOSE(ldt);
IOLink.UnMakeChan(did,cid);
END DeleteAlias;
BEGIN
IOLink.AllocateDeviceId(did);
END HuffChan.
isbndb 1
year|publisher|title|authors|isbn13
1985|Springer-Verlag|Programming in Modula-2 (Texts and monographs in computer science)|Wirth, Niklaus|9780387150789
githubLanguage Modula-2
fileExtensions mod
trendingProjectsCount 0
type programming
aceMode text
tmScope source.modula2
repos 306
indeedJobs modula-2 developer
2022 0
semanticScholar 0