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 /* Utility routines */
43 * Compute entier (floor)
58 if ((double)i <= x) return(i); else return(i-1);
65 word shift(word x, word n)
67 if (n == 0) return (x);
68 if (n > 0) return (x << n);
69 else return ( (x >> -n) & ~(~(word)0 << (8*sizeof(word)+n)) );
74 * Get ASCIIZ string from arrayof char
76 char *asciiz(virtaddr *virt)
82 if (member(virt, &am))
84 len = M[ am ]-3; /* length of the string */
85 cp = ballocate(len+1); /* allocate buffer for the string */
86 if (cp == NULL) errsignal(RTEMEMOV);
87 for (i = 0; i < len; i++) cp[ i ] = (char) M[ am+3+i ];
88 cp[ len ] = '\0'; /* terminate string with 0 byte */
91 else errsignal(RTEREFTN); /* reference to none */
95 * Add extension to a file name
97 void addext(char *fname, char *ext)
102 while (*cp != '\0' && *cp != '.') cp++;
111 * Print error message and abort
113 void abend(char *msg)
115 fprintf(stderr, "Error: %s\n", msg);
120 /* Pseudo random number generator */
122 static int ranpat1 = 7, ranpat2 = 503, ranpat3 = 15661;
125 * Initialize generator
132 ranpat1 = tim % 30269;
133 ranpat2 = tim % 30307;
134 ranpat3 = tim % 30323;
138 * Produce next pseudo random number
145 ranpat1 = 171*(ranpat1 % 177)- 2*(ranpat1 / 177);
146 if (ranpat1 < 0) ranpat1 += 30269;
147 ranpat2 = 172*(ranpat2 % 176)-35*(ranpat2 / 176);
148 if (ranpat2 < 0) ranpat2 += 30307;
149 ranpat3 = 170*(ranpat3 % 178)-63*(ranpat3 / 178);
150 if (ranpat3 < 0) ranpat3 += 30323;
151 r = ranpat1/30269.0 + ranpat2/30307.0 + ranpat3/30323.0;
157 * Copy a block of memory
159 void moveblock(char *from, char *to, word len)
166 /**************************************************************
169 void dump(pix, from, len)
176 M = process[ pix ].M;
179 printf("%6ld: ", (long) from);
180 for (i = 0; i < LINE; i++) printf("%7ld", (long)M[from++]);
186 **************************************************************/