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 =======================================================================
38 * Initialize memory structures for objects, main object and a few goodies more.
45 for (i = 0; i < MAXPROCESS; i++ ) /* initialize process descriptors */
47 process[ i ].used = FALSE; /* not used */
48 process[ i ].mark = -1; /* initial mark for processes */
49 process[ i ].M = NULL; /* memory not allocated */
50 process[ i ].hash = NULL;
52 process[ 0 ].M = M; /* always contains code */
53 dispoff = VIRTSC-(lastprot+1); /* DISPLAY offset in process object */
54 disp2off = dispoff-(lastprot+1); /* indirect DISPLAY offset */
55 ready = qinit(); /* initialize Round-Robin queue */
56 ranset(); /* init pseudo-random no. generator */
61 DosGetInfoSeg(&gsel, &lsel);
62 ginf = MAKEPGINFOSEG(gsel);
66 if (!remote) /* create main process */
68 father.node = 0; /* dummy DL for generated process */
71 thispix = 0; /* current process index */
72 thisp = &process[ thispix ]; /* current process descr pointer */
73 initprocess((word) 0, (word) MAINBLOCK, &father);
74 mainprog = thisp->prochead; /* am of main */
75 c1 = thisp->c1; /* pointers to current object */
77 ic = thisp->ic; /* instruction counter */
78 param = thisp->param; /* parameter vector */
79 apt = mainprog+M[ mainprog ]; /* LWA+1 of main */
80 display = apt+dispoff; /* DISPLAY in main */
81 display2 = apt+disp2off; /* indirect DISPLAY in main */
82 mnoff = 2; /* offset of variable mainprog */
83 storevirt(thisp->procref, mainprog+mnoff); /* init variable main */
84 M[ apt+STATSL ]++; /* flag main included in SL chain */
85 thisp->status = STOPPED;
86 activate(thispix); /* activate main process */
90 thispix = 0; /* a dirty trick: set junk current
92 thisp = &process[ thispix ];/* process for first
94 } /* (must save 'context' somewhere) */
101 * Initialize process descriptor
103 void initprocess(word pix, word prot, procaddr *father)
107 word i, j, ah, am, apt;
110 fprintf(stderr,"new process(n,p,m) (%d,%d,%d)",0,pix,process[pix].mark);
111 fprintf(stderr," from (%d,%d,%d)\n",father->node,father->pix,father->mark);
119 p->used = TRUE; /* process descriptor is used */
120 p->prot = prot; /* prototype number */
121 p->freeitem = 0; /* null list of free dictionary items */
122 p->upper = memorysize-1; /* highest memory address */
123 p->lower = freem; /* lowest address for data */
124 p->headk = p->lower; /* head of killed objects list */
125 p->M[ p->headk ] = MAXAPPT; /* maximum appetite sentinel */
127 ah = p->upper-1; /* dict. item for process itself */
128 p->lastitem = ah; /* first word used by dictionary */
129 ptr = prototype[ prot ];
130 if (p->upper - p->lower - ptr->appetite < 512)
131 if (prot == MAINBLOCK)
132 abend("Memory size too small (use /m option)\n");
133 else errsignal(RTEMEMOV);
135 /* generate process object */
136 p->lastused = p->lower+ptr->appetite;
138 p->M[ am ] = ptr->appetite;
139 p->M[ am+PROTNUM ] = prot;
140 for (i = PROTNUM+1; i < ptr->appetite; i++)
145 p->procref.addr = ah;
147 p->c1 = am; /* initialize current object ptrs */
148 p->c2 = am+ptr->span;
149 apt = am+ptr->appetite;
150 p->M[ apt+CHD ] = ah; /* initialize coroutine head ptr */
151 p->M[ apt+CHD+1 ] = 0;
152 p->M[ apt+SL ] = DUMMY; /* dummy SL for process */
153 p->M[ 1 ] = 1; /* absolute none */
154 for (i = MAINBLOCK; i <= lastprot; i++) /* initialize DISPLAY */
155 p->M[ apt+dispoff+i ] = 0;
156 p->M[ apt+disp2off+MAINBLOCK ] = DUMMY; /* dummmy entry for MAIN */
157 j = ptr->preflist; /* set DISPLAY entries for process */
159 for (i = j+ptr->lthpreflist-1; i >= j; i--)
161 p->M[ apt+dispoff+M[ i ] ] = am; /* physical address */
162 p->M[ apt+disp2off+M[ i ] ] = ah; /* indirect address */
167 mess2obj( p, father, &v );
168 p->M[ apt+DL ] = v.addr;
169 p->M[ apt+DL+1 ] = v.mark;
171 p->msgqueue = qinit();
172 p->rpcwait = qinit();
173 p->rpcmask = sinit();
174 pushmask(pix); /* initialy all RPCs are disabled */
175 p->trlnumber = 0; /* trace line number */
176 i = ptr->preflist; /* search for executable prefix */
177 while (prototype[ p->M[ i ] ]->kind == RECORD) i++;
178 p->ic = prototype[ M[ i ] ]->codeaddr; /* first instruction address */
179 p->force_compactification=FALSE;
186 bool member(virtaddr *virt, word *am)
188 *am = M[ virt->addr ];
189 /* if (virt->mark == M[ virt->addr+1] ) fprintf(stderr, "Yes");
190 else {fprintf(stderr, "No");}; */
191 return (virt->mark == M[ virt->addr+1 ]);
197 void update(word am, word ah)
199 word t1, t2, t3, t4, t5, t6;
205 M[ t1+STATSL ]++; /* flag object included in SL */
206 ptr = prototype[ M[ am+PROTNUM ] ];
208 t3 = t2+ptr->lthpreflist-1;
209 for (t4 = t3; t4 >= t2; t4-- )
213 if (M[ t5 ] == 0) /* entry to be updated */
216 M[ display2+t6 ] = ah;
220 if (ah == DUMMY) break;
221 if (M[ ah+1 ] != M[ t1+SL+1 ]) errsignal(RTESLCOF);
237 ptr = prototype[ M[ t1+PROTNUM ] ];
239 for (t3 = t2+ptr->lthpreflist-1; t3 >= t2; t3-- )
240 M[ display+M[ t3 ] ] = 0;
242 M[ t3+STATSL ]--; /* flag object removed from SL */
243 t1 = M[ t3+SL ]; /* ah of SL */
244 if (t1 == DUMMY) break; /* still not main */
245 t1 = M[ t1 ]; /* am of SL */
250 * To count trace messages in line
252 static int tracecnt = 0;
255 * Trace the program if debug mode
257 void trace(word lineno)
259 thisp->trlnumber = lineno;
260 if (debug && lineno > 0)
263 if (tracecnt == MAXTRACNT) /* change line */
266 fprintf(tracefile, "\n");
268 fprintf(tracefile, "%6ld", (long) lineno);
270 trapmsg(); /* check for waiting message */
271 rpc2(); /* check for RPC message */
277 void endrun(int status)
283 if (debug) fclose(tracefile);
286 msg.msg_type = MSG_INT;
287 msg.param.pword[0] = INT_EXITING;
288 strcpy(msg.param.pstr,ProgName);
289 write(internal_sock,&msg,sizeof(MESSAGE));
290 m.msg_type = MSG_GRAPH;
291 m.param.pword[0] = GRAPH_FREE;
292 write(graph_sock,&m,sizeof(G_MESSAGE));
293 close(internal_sock);
300 if (DirConn[i]!=-1) close(DirConn[i]);