1 /* Loglan82 Compiler&Interpreter
2 Copyright (C) 1981-1993 Institute of Informatics, University of Warsaw
3 Copyright (C) 1993, 1994 LITA, Pau
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 contacts: Andrzej.Salwicki@univ-pau.fr
22 LITA Departement d'Informatique
24 Avenue de l'Universite
26 tel. ++33 59923154 fax. ++33 59841696
28 =======================================================================
40 /* Call standard procedure */
42 void standard(nrproc) /* Process call to a standard proc. */
45 word t1, t2, t3, t5, t6;
57 fprintf( stderr, "standard procedure %d\n", nrproc );
62 case 1 : /* new array */
63 newarry(param[ 1 ].xword, param[ 0 ].xword, param[ 2 ].xword,
64 ¶m[ 3 ].xvirt, ¶m[ 4 ].xword);
75 case 10 : /* assout */
79 case 11 : /* unpack:function(s:string):arrayof char */
80 t1 = strings+param[ 0 ].xword+1;
81 t6 = M[ t1-1 ]; /* length of the string */
82 if (t6 > 0) /* string not null */
84 newarry((word) 1, t6, (word) AINT, ¶m[ 1 ].xvirt, &t5);
86 cp = (char *) &M[ t1 ];
87 while (t6-- > 0) M[ t5++ ] = *cp++;
89 else /* null string */
91 param[ 1 ].xvirt.addr = 0;
92 param[ 1 ].xvirt.mark = 0;
96 case 12 : /* random:function:real */
97 param[ 0 ].xreal = (real)prandom();
100 case 13 : /* time:function:integer */
102 param[ 0 ].xword = tim;
105 case 14 : /* sqrt:function(x:real):real */
106 param[ 1 ].xreal = (real)sqrt((double) param[ 0 ].xreal);
109 case 15 : /* entier:function(x:real):integer */
110 param[ 1 ].xword = entier((double) param[ 0 ].xreal);
113 case 16 : /* round:function(x:real):integer */
114 param[ 1 ].xword = entier((double) (param[ 0 ].xreal+0.5));
117 case 17 : /* unused */
118 case 18 : /* intrinsic procedure */
122 case 19 : /* imin:function(x, y:integer):integer */
123 param[ 2 ].xword = min(param[ 0 ].xword, param[ 1 ].xword);
126 case 20 : /* imax:function(x, y:integer):integer */
127 param[ 2 ].xword = max(param[ 0 ].xword, param[ 1 ].xword);
130 case 21 : /* imin3:function(x, y, z:integer):integer */
131 t1 = min(param[ 0 ].xword, param[ 1 ].xword);
132 param[ 3 ].xword = min(t1, param[ 2 ].xword);
135 case 22 : /* imax3:function(x, y, z:integer):integer */
136 t1 = max(param[ 0 ].xword, param[ 1 ].xword);
137 param[ 3 ].xword = max(t1, param[ 2 ].xword);
140 case 23 : /* sin:function(x:real):real */
141 param[ 1 ].xreal = (real)sin((double) param[ 0 ].xreal);
144 case 24 : /* cos:function(x:real):real */
145 param[ 1 ].xreal = (real)cos((double) param[ 0 ].xreal);
148 case 25 : /* tan:function(x:real):real */
149 r = cos((double) param[ 0 ].xreal);
150 if (r == 0.0) errsignal(RTEDIVBZ);
151 param[ 1 ].xreal = (real)sin((double) param[ 0 ].xreal) / r;
154 case 26 : /* exp:function(x:real):real */
155 param[ 1 ].xreal = (real)exp((double) param[ 0 ].xreal);
158 case 27 : /* ln:function(x:real):real */
159 param[ 1 ].xreal = (real)log((double) param[ 0 ].xreal);
162 case 28 : /* atan:function(x:real):real */
163 param[ 1 ].xreal = (real)atan((double) param[ 0 ].xreal);
166 case 29 : /* endrun:procedure */
170 case 30 : /* ranset:procedure(x:real) */
174 case 31 : /* clock */
175 case 32 : /* option */
177 case 34 : /* unlock */
178 case 35 : /* sched, boy! */
180 case 37 : /* execpar */
181 case 38 : /* test&set */
186 param[ 0 ].xbool = lbool(testeof(stdin));
189 case 40 : /* eof(f) */
190 loadfile((word) UNKNOWN, &t1, &t2, &fp);
192 if (t3 == READING || t3 == UPDATING)
193 param[ 0 ].xbool = lbool(testeof(fp));
194 else errsignal(RTEILLIO);
197 case 41 : /* readln */
201 case 42 : /* readln(f) */
202 loadfile((word) READING, &t1, &t2, &fp);
203 if (t1 != TEXTF) errsignal(RTEILLIO);
207 case 43 : /* readchar */
208 param[ 0 ].xword = read_char();
211 case 44 : /* readchar(f) */
212 loadfile((word) READING, &t1, &t2, &fp);
213 if (t1 != TEXTF) errsignal(RTEILLIO);
214 if ((ch = getc(fp)) == EOF) errsignal(RTEIOERR);
215 param[ 0 ].xword = ch;
218 case 45 : /* readint */
220 param[ 0 ].xword = atoi(s);
223 case 46 : /* readint(f) */
224 loadfile((word) READING, &t1, &t2, &fp);
225 if (t1 != TEXTF) errsignal(RTEILLIO);
226 param[ 0 ].xword = readint(fp);
229 case 47 : /* readreal */
231 param[ 0 ].xreal = (real)atof(s);
234 case 48 : /* readreal(f) */
235 loadfile((word) READING, &t1, &t2, &fp);
236 if (t1 != TEXTF) errsignal(RTEILLIO);
237 param[ 0 ].xreal = (real)readreal(fp);
240 case 49 : /* getchar(f) */
241 loadfile((word) READING, &t1, &t2, &fp);
242 if (t1 != CHARF) errsignal(RTEILLIO);
243 if ((ch = getc(fp)) == EOF) errsignal(RTEIOERR);
244 param[ 0 ].xword = ch;
247 case 50 : /* getint(f) */
248 loadfile((word) READING, &t1, &t2, &fp);
249 if (t1 != INTF) errsignal(RTEILLIO);
250 n = fread((char *) ¶m[ 0 ].xword, sizeof(word), 1, fp);
251 if (n != 1) errsignal(RTEIOERR);
254 case 51 : /* getreal(f) */
255 loadfile((word) READING, &t1, &t2, &fp);
256 if (t1 != REALF) errsignal(RTEILLIO);
257 n = fread((char *) ¶m[ 0 ].xreal, sizeof(real), 1, fp);
258 if (n != 1) errsignal(RTEIOERR);
261 case 52 : /* getobject(f) */
265 case 53 : /* putchar(f) */
266 loadfile((word) WRITING, &t1, &t2, &fp);
267 if (t1 != CHARF) errsignal(RTEILLIO);
268 ch = (char) param[ 0 ].xword;
269 if (putc(ch, fp) == EOF) errsignal(RTEIOERR);
272 case 54 : /* putint(f) */
273 loadfile((word) WRITING, &t1, &t2, &fp);
274 if (t1 != INTF) errsignal(RTEILLIO);
275 n = fwrite((char *) ¶m[ 0 ].xword, sizeof(word), 1, fp);
276 if (n != 1) errsignal(RTEIOERR);
279 case 55 : /* putreal(f) */
280 loadfile((word) WRITING, &t1, &t2, &fp);
281 if (t1 != REALF) errsignal(RTEILLIO);
282 n = fwrite((char *) ¶m[ 0 ].xreal, sizeof(real), 1, fp);
283 if (n != 1) errsignal(RTEIOERR);
286 case 56 : /* putobject(f) */
287 case 57 : /* putstring(f) */
291 case 58 : /* writeln(f) */
292 loadfile((word) WRITING, &t1, &t2, &fp);
293 if (t1 != TEXTF) errsignal(RTEILLIO);
294 if (putc('\n', fp) == EOF) errsignal(RTEIOERR);
295 if (fflush(fp)) errsignal(RTEIOERR);
298 case 59 : /* writeln */
302 case 60 : /* writechar(f) */
303 loadfile((word) WRITING, &t1, &t2, &fp);
304 if (t1 != TEXTF) errsignal(RTEILLIO);
305 if (putc((char) param[ 0 ].xword, fp) == EOF)
309 case 61 : /* writechar */
310 write_char((char) param[ 0 ].xword);
313 case 62 : /* writeint(f) */
314 loadfile((word) WRITING, &t1, &t2, &fp);
315 if (t1 != TEXTF) errsignal(RTEILLIO);
316 writeint(param[ 0 ].xword, param[ 1 ].xword, fp);
319 case 63 : /* writeint */
320 writeint(param[ 0 ].xword, param[ 1 ].xword, stdout);
323 case 64 : /* writereal0(f) */
324 case 66 : /* writereal1(f) */
325 case 68 : /* writereal2(f) */
326 loadfile((word) WRITING, &t1, &t2, &fp);
327 if (t1 != TEXTF) errsignal(RTEILLIO);
328 writereal((double) param[ 0 ].xreal, param[ 1 ].xword,
329 param[ 2 ].xword, fp);
332 case 65 : /* writereal0 */
333 case 67 : /* writereal1 */
334 case 69 : /* writereal2 */
335 writereal((double) param[ 0 ].xreal, param[ 1 ].xword,
336 param[ 2 ].xword, stdout);
339 case 70 : /* writestring(f) */
340 loadfile((word) WRITING, &t1, &t2, &fp);
341 if (t1 != TEXTF) errsignal(RTEILLIO);
342 writestring(param[ 0 ].xword, param[ 1 ].xword, fp);
345 case 71 : /* writestring */
346 writestring(param[ 0 ].xword, param[ 1 ].xword, stdout);
349 case 72 : /* open temporary file */
350 genfileobj(TRUE , param[ 1 ].xword, tempfilename(),
351 ¶m[ 0 ].xvirt, &t1);
354 case 73 : /* open external file */
355 genfileobj(FALSE, param[ 1 ].xword, asciiz(¶m[ 2 ].xvirt),
356 ¶m[ 0 ].xvirt, &t1);
360 param[ 0 ].xbool = lbool(testeoln(stdin));
363 case 75 : /* eoln(f) */
364 loadfile((word) READING, &t1, &t2, &fp);
365 if (t1 != TEXTF) errsignal(RTEILLIO);
366 param[ 0 ].xbool = lbool(testeoln(fp));
369 case 76 : /* this coroutine */
370 loadvirt(param[ 0 ].xvirt,
371 thisp->prochead+M[ thisp->prochead ]+CHD);
374 case 77 : /* this process */
380 p.mark = thisp->mark;
381 mess2obj( thisp, &p, &v );
382 param[ 0 ].xvirt = v;
386 case 78 : /* reset:procedure(f:file) */
387 if (member(¶m[ 0 ].xvirt, &t2))
389 else errsignal(RTEREFTN);
392 case 79 : /* rewrite:procedure(f:file) */
393 if (member(¶m[ 0 ].xvirt, &t2))
395 else errsignal(RTEREFTN);
398 case 80 : /* unlink:procedure(f:file) */
399 delete(¶m[ 0 ].xvirt);
402 case 81 : /* seek:procedure(f:file, offset, base:integer) */
403 storevirt(param[ 0 ].xvirt, currfile);
404 loadfile((word) UPDATING, &t1, &t2, &fp);
405 if (t1 != DIRECT) errsignal(RTEILLIO);
406 if (fseek(fp, (long) param[ 1 ].xword, (int) param[ 2 ].xword))
410 case 82 : /* getrec(f, a, n) */
411 loadfile((word) UPDATING, &t1, &t2, &fp);
412 if (t1 != DIRECT) errsignal(RTEILLIO);
413 param[ 1 ].xword = directio(
421 case 83 : /* putrec(f, a, n) */
422 loadfile((word) UPDATING, &t1, &t2, &fp);
423 if (t1 != DIRECT) errsignal(RTEILLIO);
424 param[ 1 ].xword = directio(
432 case 84 : /* position:function(f:file):real */
433 storevirt(param[ 0 ].xvirt, currfile);
434 loadfile((word) UPDATING, &t1, &t2, &fp);
435 if (t1 != DIRECT) errsignal(RTEILLIO);
436 param[ 1 ].xword =(int) ftell(fp);
439 case 98 : /* memavail:function:integer */
440 param[ 0 ].xword = memavail();
443 case 99 : /* exec:function(c:arrayof char):integer */
444 cp = asciiz(¶m[ 0 ].xvirt);
445 param[ 1 ].xword = system(cp);
456 if (absent) errsignal(RTEUNSTP);