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 =======================================================================
42 * @brief Call standard procedure
45 /** Process call to a standard proc. */
46 void standard(word nrproc)
48 word t1, t2, t3, t5, t6;
60 fprintf(stderr, "standard procedure %d\n", nrproc);
63 switch ((int) nrproc) {
66 newarry(param[1]. xword, param[0].xword, param[2].xword,
67 ¶m[3].xvirt, ¶m[4].xword);
91 /* unpack:function(s:string):arrayof char */
93 t1 = strings+param[0].xword+1;
94 /* length of the string */
98 newarry((word) 1, t6, (word)AINT, ¶m[1].xvirt, &t5);
100 cp = (char *) &M[t1];
106 param[1].xvirt.addr = 0;
107 param[1].xvirt.mark = 0;
110 /* random:function:real */
112 param[0].xreal = (real)prandom();
114 /* time:function:integer */
117 param[0].xword = tim;
119 /* sqrt:function(x:real):real */
121 param[1].xreal = (real)sqrt((double) param[0].xreal);
123 /* entier:function(x:real):integer */
125 param[1].xword = entier((double) param[0].xreal);
127 /* round:function(x:real):integer */
129 param[1].xword = entier((double) (param[0].xreal + 0.5));
133 /* intrinsic procedure */
137 /* imin:function(x, y:integer):integer */
139 param[2].xword = min(param[0].xword, param[1].xword);
141 /* imax:function(x, y:integer):integer */
143 param[2].xword = max(param[0].xword, param[1].xword);
145 /* imin3:function(x, y, z:integer):integer */
147 t1 = min(param[0].xword, param[1].xword);
148 param[3].xword = min(t1, param[2].xword);
150 /* imax3:function(x, y, z:integer):integer */
152 t1 = max(param[0].xword, param[1].xword);
153 param[3].xword = max(t1, param[2].xword);
155 /* sin:function(x:real):real */
157 param[1].xreal = (real)sin((double) param[0].xreal);
159 /* cos:function(x:real):real */
161 param[1].xreal = (real)cos((double) param[0].xreal);
163 /* tan:function(x:real):real */
165 r = cos((double) param[0].xreal);
168 param[1].xreal = (real)sin((double) param[0].xreal) / r;
170 /* exp:function(x:real):real */
172 param[1].xreal = (real)exp((double) param[0].xreal);
174 /* ln:function(x:real):real */
176 param[1].xreal = (real)log((double) param[0].xreal);
178 /* atan:function(x:real):real */
180 param[1].xreal = (real)atan((double) param[0].xreal);
182 /* endrun:procedure */
186 /* ranset:procedure(x:real) */
210 param[0].xbool = lbool(testeof(stdin));
214 loadfile((word) UNKNOWN, &t1, &t2, &fp);
216 if (t3 == READING || t3 == UPDATING)
217 param[0].xbool = lbool(testeof(fp));
227 loadfile((word) READING, &t1, &t2, &fp);
234 param[0].xword = read_char();
238 loadfile((word) READING, &t1, &t2, &fp);
241 if ((ch = getc(fp)) == EOF)
248 param[0].xword = atoi(s);
251 case 46: /* readint(f) */
252 loadfile((word) READING, &t1, &t2, &fp);
255 param[0].xword = readint(fp);
260 param[0].xreal = (real)atof(s);
264 loadfile((word) READING, &t1, &t2, &fp);
267 param[0].xreal = (real)readreal(fp);
271 loadfile((word) READING, &t1, &t2, &fp);
274 if ((ch = getc(fp)) == EOF)
280 loadfile((word) READING, &t1, &t2, &fp);
283 n = fread((char *) ¶m[ 0 ].xword, sizeof(word), 1, fp);
289 loadfile((word) READING, &t1, &t2, &fp);
292 n = fread((char *) ¶m[0].xreal, sizeof(real), 1, fp);
302 loadfile((word) WRITING, &t1, &t2, &fp);
305 ch = (char) param[ 0 ].xword;
306 if (putc(ch, fp) == EOF)
311 loadfile((word) WRITING, &t1, &t2, &fp);
314 n = fwrite((char *) ¶m[ 0 ].xword, sizeof(word), 1, fp);
320 loadfile((word) WRITING, &t1, &t2, &fp);
323 n = fwrite((char *) ¶m[ 0 ].xreal, sizeof(real), 1, fp);
335 loadfile((word) WRITING, &t1, &t2, &fp);
338 if (putc('\n', fp) == EOF)
349 loadfile((word) WRITING, &t1, &t2, &fp);
352 if (putc((char) param[0].xword, fp) == EOF)
357 write_char((char) param[0].xword);
361 loadfile((word) WRITING, &t1, &t2, &fp);
364 writeint(param[0].xword, param[1].xword, fp);
368 writeint(param[0].xword, param[1].xword, stdout);
376 loadfile((word) WRITING, &t1, &t2, &fp);
379 writereal((double) param[0].xreal, param[1].xword,
388 writereal((double) param[0].xreal, param[1].xword,
389 param[2].xword, stdout);
393 loadfile((word) WRITING, &t1, &t2, &fp);
396 writestring(param[0].xword, param[1].xword, fp);
400 writestring(param[0].xword, param[1].xword, stdout);
402 /* open temporary file */
404 genfileobj(TRUE, param[1].xword, tempfilename(),
405 ¶m[0].xvirt, &t1);
407 /* open external file */
409 genfileobj(FALSE, param[1].xword, asciiz(¶m[2].xvirt),
410 ¶m[0].xvirt, &t1);
414 param[0].xbool = lbool(testeoln(stdin));
418 loadfile((word) READING, &t1, &t2, &fp);
419 if (t1 != TEXTF) errsignal(RTEILLIO);
420 param[0].xbool = lbool(testeoln(fp));
424 loadvirt(param[0].xvirt,
425 thisp->prochead + M[thisp->prochead] + CHD);
434 p.mark = thisp->mark;
435 mess2obj(thisp, &p, &v);
439 /* reset:procedure(f:file) */
441 if (member(¶m[0].xvirt, &t2))
446 /* rewrite:procedure(f:file) */
448 if (member(¶m[0].xvirt, &t2))
453 /* unlink:procedure(f:file) */
455 delete(¶m[0].xvirt);
457 /* seek:procedure(f:file, offset, base:integer) */
459 storevirt(param[0].xvirt, currfile);
460 loadfile((word) UPDATING, &t1, &t2, &fp);
463 if (fseek(fp, (long) param[1].xword, (int) param[2].xword))
466 /* getrec(f, a, n) */
468 loadfile((word) UPDATING, &t1, &t2, &fp);
471 param[1].xword = directio(¶m[0].xvirt, param[1].xword,
472 (int (*)())fread, fp);
474 /* putrec(f, a, n) */
476 loadfile((word) UPDATING, &t1, &t2, &fp);
477 if (t1 != DIRECT) errsignal(RTEILLIO);
478 param[1].xword = directio(¶m[0].xvirt, param[1].xword,
479 (int (*)())fwrite, fp);
481 /* position:function(f:file):real */
483 storevirt(param[0].xvirt, currfile);
484 loadfile((word) UPDATING, &t1, &t2, &fp);
487 param[1].xword =(int) ftell(fp);
489 /* memavail:function:integer */
491 param[0].xword = memavail();
493 /* exec:function(c:arrayof char):integer */
495 cp = asciiz(¶m[0].xvirt);
496 param[1].xword = system(cp);