1 /* Loglan82 Compiler&Interpreter
2 Copyright (C) 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 =======================================================================
44 /* IIUW LOGLAN-82 Executor */
45 /* Written in PASCAL by P.Gburzynski and A.Litwiniuk. */
46 /* Modified by J.Findeisen, T.Przytycka, D.Szczepanska, B.Ciesielski. */
47 /* Hand translated to C by B. Ciesielski. */
51 static void load(char *);
52 static void initiate(int,char **);
53 int main(int,char **);
56 static void initiate();
61 /* Macro to decode addressing modes : */
62 #define getargument(a, argnr) \
63 switch (eop->args[ argnr ]) \
65 case GLOBAL : a = M[ ic++ ]; break; \
66 case LOCAL : a = c1+M[ ic++ ]; break; \
67 case TEMPLOCAL : a = c2+M[ ic++ ]; break; \
68 case REMOTE : a = M[ M[ ic+1 ] ]+M[ ic ]; ic+=2; break;\
69 case INDIRECT : a = M[ M[ ic++ ] ]; break;\
70 case IMMEDIATE : a = ic++; break;\
71 case CONSTANT : a = M[ ic++ ]; break;\
72 case DOTACCESS : a = M[ display+M[ ic+1 ] ]+M[ ic ]; ic += 2; break;\
73 case NOARGUMENT : return; \
77 static void load(_filename) /* Load code and prototypes from file */
83 char filename[100]; /* should suffice on all systems */
85 strcpy( filename, _filename );
87 M = mallocate(memorysize+1); /* allocate main memory array */
88 if (M == NULL) abend("Memory size too large (use /m option)\n");
90 addext(filename, ".ccd");
91 if ((fp = fopen(filename, BINARYREAD)) == NULL)
92 abend("Cannot open .ccd file\n");
94 ic = 0; /* read static data and code */
95 left = memorysize+1; /* from .ccd file */
98 if (left == 0) abend("Memory size too small (use /m option)\n");
99 n = min(IOBLOCK/sizeof(word), left);
100 n = fread((char *) &M[ ic ], sizeof(word), (int) n, fp);
103 } while (n != 0); /* now ic = number of words read */
106 /* Get various addresses passed by GENERATOR */
107 ipradr = M[ ic-5 ]; /* primitive type desctriptions */
108 temporary = M[ ic-4 ]; /* global temporary variables */
109 strings = M[ ic-3 ]; /* string constants */
110 lastprot = M[ ic-2 ]; /* last prototype number */
111 freem = M[ ic-1 ]; /* first free word in memory */
113 /* Read prototypes from .pcd file */
114 addext(filename, ".pcd");
115 if ((fp = fopen(filename, BINARYREAD)) == NULL)
116 abend("Cannot open .pcd file\n");
117 for (n = MAINBLOCK; n <= lastprot; n++ )
119 cp = ballocate(sizeof(protdescr));
120 if (cp == NULL) abend("Memory size too large (use /m option)\n");
121 prototype[ n ] = (protdescr *) cp;
122 if (fread(cp, sizeof(protdescr), 1, fp) != 1)
123 abend("Cannot read .pcd file\n");
127 /* Open trace file */
130 addext(filename, ".trd");
131 if ((tracefile = fopen(filename, "w")) == NULL)
132 abend("Cannot open .trd file\n");
137 static void initiate(argc, argv) /* Establish configuration parameters */
145 fprintf(stderr,"\n LOGLAN-82 Concurrent Executor Version 4.51\n");
146 fprintf(stderr," January 21, 1993\n");
148 " (C) Copyright Institute of Informatics University of Warsaw\n");
149 fprintf(stderr," (C) Copyleft LITA Universite de Pau\n");
151 fprintf(stderr," D-LINK version 3.21\n\n");
153 fprintf(stderr," TCPIP version 0.9\n\n");
155 fprintf(stderr,"\n");
160 ournode = net_logon(msginterrupt);
161 if (ournode >= 0) /* network driver installed */
163 else /* network driver not installed */
166 ournode = 0; /* only node 0 is available */
174 for( ; argc>0; argc--,argv++ ){
175 if( filename != NULL ) usage();
176 if( (*argv)[0]=='-' )
177 switch( (*argv)[1] ){
190 abend("D-Link Network Driver Version 3.21 must be installed\n");
192 if( argc==0 ) usage();
193 if( sscanf( *argv, "%d", &c ) != 1 ) usage();
194 if( c < 0 || c >= 255 || c == ournode )
195 abend("Invalid console node number\n");
200 if( argc==0 ) usage();
201 if( sscanf( *argv, "%d", &c ) != 1 ) usage();
202 if( c < 0 || c >= 255 )
203 abend("Invalid my console node number\n");
204 ournode = console = c;
206 if( argc==0 ) usage();
207 /* here we test if we are remote */
208 /* master will have number of slaves to wait for */
209 /* slave - internet full address of master */
210 if( strchr(*argv,':') ){
211 /* internet address of master nn.nn.nn.nn:port */
213 tcpip_connect_to_master( *argv );
215 /* # of slaves to wait for */
216 if( sscanf( *argv, "%d", &c ) != 1 ) usage();
217 if( c < 0 || c >= 254 ) usage();
218 tcpip_wait_for_slaves( c );
230 if( argc==0 ) usage();
231 if (sscanf( *argv, "%ld", &m ) != 1) usage();
232 if (m <= 0 || m > MAXMEMSIZE)
233 abend("Invalid memory size specified\n");
241 } /* end of switch */
242 else{ /* this is not option */
243 if( filename != NULL ) usage();
249 load(filename); /* load code and prototypes */
257 eop = (extopcode *)(M+ic); /* pointer to extended opcode in M */
258 lastic = ic; /* save ic for possible redecoding */
260 opcode = ((int) eop->opcode ) & 0xFF ;
271 initiate(argc, argv); /* initialize executor */
272 runsys(); /* initialize running system */
274 setjmp(contenv); /* set label for continue long jump */
275 while (TRUE) /* repeat until exit() is called */
277 schedule(); /* reschedule current process */
278 decode(); /* fetch instruction */
279 execute(); /* and execute it */