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 * Initialize memory structures for objects, main object and a few goodies more.
49 /* initialize process descriptors */
50 for (i = 0; i < MAXPROCESS; i++) {
52 process[i].used = FALSE;
53 /* initial mark for processes */
55 /* memory not allocated */
57 process[i].hash = NULL;
59 /* always contains code */
61 /* DISPLAY offset in process object */
62 dispoff = VIRTSC - (lastprot + 1);
63 /* indirect DISPLAY offset */
64 disp2off = dispoff - (lastprot + 1);
65 /* initialize Round-Robin queue */
67 /* init pseudo-random no. generator */
73 DosGetInfoSeg(&gsel, &lsel);
74 ginf = MAKEPGINFOSEG(gsel);
78 /* create main process */
80 /* dummy DL for generated process */
84 /* current process index */
86 /* current process descr pointer */
87 thisp = &process[thispix];
88 initprocess((word) 0, (word) MAINBLOCK, &father);
90 mainprog = thisp->prochead;
91 /* pointers to current object */
94 /* instruction counter */
96 /* parameter vector */
99 apt = mainprog + M[mainprog];
100 /* DISPLAY in main */
101 display = apt + dispoff;
102 /* indirect DISPLAY in main */
103 display2 = apt + disp2off;
104 /* offset of variable mainprog */
106 /* init variable main */
107 storevirt(thisp->procref, mainprog + mnoff);
108 /* flag main included in SL chain */
110 thisp->status = STOPPED;
111 /* activate main process */
116 /* a dirty trick: set junk current */
118 /* process for first transfer() */
119 thisp = &process[thispix];
120 /* (must save 'context' somewhere) */
128 * Initialize process descriptor
130 void initprocess(word pix, word prot, procaddr *father)
134 word i, j, ah, am, apt;
137 fprintf(stderr, "new process(n,p,m) (%d,%d,%d)", 0, pix,
139 fprintf(stderr, " from (%d,%d,%d)\n", father->node, father->pix,
148 /* process descriptor is used */
150 /* prototype number */
152 /* null list of free dictionary items */
154 /* highest memory address */
155 p->upper = memorysize - 1;
156 /* lowest address for data */
158 /* head of killed objects list */
160 /* maximum appetite sentinel */
161 p->M[ p->headk ] = MAXAPPT;
163 /* dict. item for process itself */
165 /* first word used by dictionary */
167 ptr = prototype[prot];
168 if (p->upper - p->lower - ptr->appetite < 512)
169 if (prot == MAINBLOCK)
170 abend("Memory size too small (use /m option)\n");
171 else errsignal(RTEMEMOV);
173 /* generate process object */
174 p->lastused = p->lower + ptr->appetite;
176 p->M[am] = ptr->appetite;
177 p->M[am + PROTNUM] = prot;
178 for (i = PROTNUM + 1; i < ptr->appetite; i++)
183 p->procref.addr = ah;
185 /* initialize current object ptrs */
187 p->c2 = am + ptr->span;
188 apt = am + ptr->appetite;
189 /* initialize coroutine head ptr */
190 p->M[apt + CHD] = ah;
191 p->M[apt + CHD + 1] = 0;
192 /* dummy SL for process */
193 p->M[apt + SL] = DUMMY;
196 /* initialize DISPLAY */
197 for (i = MAINBLOCK; i <= lastprot; i++) {
198 /* dummmy entry for MAIN */
199 p->M[apt + dispoff + i] = 0;
201 p->M[apt + disp2off + MAINBLOCK] = DUMMY;
202 /* set DISPLAY entries for process */
205 for (i = j + ptr->lthpreflist - 1; i >= j; i--) {
206 /* physical address */
207 p->M[apt + dispoff + M[i]] = am;
208 /* indirect address */
209 p->M[apt + disp2off + M[i]] = ah;
214 mess2obj(p, father, &v);
215 p->M[apt + DL] = v.addr;
216 p->M[apt + DL + 1] = v.mark;
218 p->msgqueue = qinit();
219 p->rpcwait = qinit();
220 p->rpcmask = sinit();
221 /* initialy all RPCs are disabled */
223 /* trace line number */
225 /* search for executable prefix */
227 while (prototype[p->M[i]]->kind == RECORD)
230 /* first instruction address */
231 p->ic = prototype[M[i]]->codeaddr;
232 p->force_compactification = FALSE;
239 bool member(virtaddr *virt, word *am)
243 if (virt->mark == M[virt->addr + 1])
244 fprintf(stderr, "Yes");
246 fprintf(stderr, "No");
249 return (virt->mark == M[virt->addr + 1]);
255 void update(word am, word ah)
257 word t1, t2, t3, t4, t5, t6;
262 /* flag object included in SL */
264 ptr = prototype[M[am + PROTNUM]];
266 t3 = t2 + ptr->lthpreflist - 1;
267 for (t4 = t3; t4 >= t2; t4--) {
270 /* entry to be updated */
273 M[display2 + t6] = ah;
280 if (M[ah + 1] != M[t1 + SL + 1])
297 ptr = prototype[M[t1 + PROTNUM]];
299 for (t3 = t2 + ptr->lthpreflist - 1; t3 >= t2; t3--)
300 M[display + M[t3]] = 0;
302 /* flag object removed from SL */
315 * To count trace messages in line
317 static int tracecnt = 0;
320 * Trace the program if debug mode
322 void trace(word lineno)
324 thisp->trlnumber = lineno;
325 if (debug && lineno > 0) {
328 if (tracecnt == MAXTRACNT) {
330 fprintf(tracefile, "\n");
332 fprintf(tracefile, "%6ld", (long) lineno);
334 /* check for waiting message */
336 /* check for RPC message */
343 void endrun(int status)
352 msg.msg_type = MSG_INT;
353 msg.param.pword[0] = INT_EXITING;
354 strcpy(msg.param.pstr, ProgName);
355 write(internal_sock, &msg, sizeof(MESSAGE));
356 m.msg_type = MSG_GRAPH;
357 m.param.pword[0] = GRAPH_FREE;
358 write(graph_sock, &m, sizeof(G_MESSAGE));
359 close(internal_sock);
365 for(i = 0; i < 255; i++)
366 if (DirConn[i] != -1)