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.
16 =======================================================================
27 /*#define DEBUG 0 Defined for debugging time, undefine when ready */
28 /*#define LOG(i) fprintf(log,"%s #%d : m[%d]=%d\n",__FILE__,__LINE__,i+base,m[i])*/
33 #define new(s) calloc(1, sizeof(*s))
34 /*cmb It is calloc here, because we want untouched fields to be 0 */
35 /* rather than a random value cmb */
38 #define MEMLIMIT 32000 /* small memory for main */
40 typedef int address; /* APOPCODE == 2 - appetite of extended opcode */
43 #define MEMLIMIT 16000
44 typedef long address; /* APOPCODE == 1 */
48 #define MEMLIMIT 32000
49 typedef long address; /* APOPCODE == 1 */
53 #error Define one of SMALL/LARGE/HUGE
57 #define CHARSINAD ( sizeof(address) ) /* number of characters in word */
60 /* compiler symbol table and memory */
63 extern address fre,base,firstlabel;
65 #define MEMORYSIZE 32000 /* CODE AND ALL RUNNING-SYSTEM DATA STRUCTURES */
66 #define MAXCOMTEMP 100 /* NUMBER OF GLOBAL TEMPORARY VARIABLES */
67 #define MAXLOCTEMP 100 /* LIMIT FOR THE NUMBER OF LOCAL TEMPORARY VARIABLES*/
68 #define MAXREFTEMP 30 /* LIMIT FOR THE NUMBER OF LOCAL TMP. REF.VARIABLES */
69 #define MAXAPPT 32767 /* MAXIMUM APPETITE (EASILY EXTENSIBLE) */
73 /* SIMPLE TYPES ARE DISTINGUISHED BY THEIR OFFSET FROM "IPRADR" */
81 #define TFUNC2 7 /* parameter "function" of parameter */
82 #define TPROC2 8 /* parameter "procedure" of parameter */
86 #define CURRFILE 2 /* constant address of a current file virtual address */
88 #define MAXNAME 70 /* file name length */
94 typedef int addrmode ; /* gsg it was an enumeration */
96 typedef char argdescr[4] ;
99 argdescr args ; /* ARGS[0] IS OPCODE */
100 } extopcode ; /* EXTENDED OPCODE */
102 /* mb think up removing record extopcode */
104 /************************************************************/
105 /* b32b16c = record 32-bit integer
107 true : ( b32 : longint
108 false : ( r16 : integer
114 struct { long int b32 ; } t ;
115 struct { int r16, l16 ; } f ;
120 0 : (int1,int2 : integer);
122 2 : (eop : extopcode );
126 struct { int int1f, int2f ; } c0 ;
127 struct { long int intf ; } c1 ;
128 struct { extopcode eop ; } c2 ;
130 /************************************************************/
131 typedef char filename[ MAXNAME + 1 ] ;
134 /* mb declarations from main to follow...*/
136 #define ENDOFSTRINGS -1 /* end of strings section marker */
138 typedef int errtype ; /* gsg previously enumeration */
139 #define TMPROT 0 /* TOO MANY PROTOTYPES */
140 #define TLDESCR 1 /* DESCRIPTIONS TOO LONG */
141 #define MEMOVF 2 /* MEMORY OVERFLOW */
142 #define TMTEMP 3 /* TOO MANY TEMPORARY VARIABLES NEEDED */
143 #define STSEQTL 4 /* STATEMENT SEQUENCE TOO LONG */
144 #define NOTIMPL 5 /* FUNCTION NOT IMPLEMENTED */
145 #define OBJTOLG 6 /* OBJECT TOO LONG */
146 #define PROCLTL 7 /* PROCEDURE LIST TOO LONG */
149 unsigned int ap : 2 ; /* 0..3 */
150 unsigned int l : 1 ; /* 0..1 */
151 unsigned int ft : 1 ; /* 0..1 */
152 unsigned int v : 1 ; /* 0..1 */
153 unsigned int s : 3 ; /* 0..7 */
154 unsigned int zp : 4 ; /* 0..15 */
155 unsigned int t : 4 ; /* 0..15 */
157 } csti ; /* : SYMBOL TABLE ITEM, 16 bits long */
167 /* mb genprot declarations to follow */
169 typedef int logitem ; /* loglan items */ /* gsg previously enumeration */
189 typedef int logunit ; /* iclass .. ifmfunc */ /* LOGLAN UNITS TOGETHER WITH FORMAL */
190 /* FUNCTION AND FORMAL PROCEDURE */
198 int ip ; /* ADDRESS IN IPMEM */
199 struct s1 * prevelem ; /* PREVIOUS ELEMENT */
201 } listelem ; /* LIST OF PARAMETERS OR OF REFERENCE ATTRIBUTES */
203 typedef listelem * pointer ;
208 address ip ; /* ADDRESS IN IPMEM */
209 struct s2 * prevelem ; /* PREVIOUS ELEMENT */
211 } longlistelem ; /* list of parameters or of reference attributes */
213 typedef longlistelem * longpointer ;
216 /* mb declarations of code to follow */
218 #define QMAX 2400 /* MAXIMAL LENGTH OF THE QUADRUPLES SEQUENCE */
219 #define TEMPGUARD 103 /* = MAXCOMTEMP + MAXIMAL APPETITE */
221 /*CBC added concurrent statements... */
222 #define MAXPROCLIST 30 /* maximum length of procedure ident. list */
225 typedef int qaddr ; /* 1..QMAX */
226 typedef int qaddr0 ; /* 0..QMAX */ /* 0 FOR NO NEXT USE */
227 typedef int argnr ; /* gsg na razie int; moze wystarczy char ?; 1..3 */
228 typedef int app ; /* APINT..APVIRT */
236 extern quadruple tuple[];
238 typedef int stmode ; /* gsg previously enumeration */
239 #define VARGLOB 0 /* GLOBAL VARIABLE */
240 #define VARLOC 1 /* LOCAL VARIABLE */
241 #define VARMID 2 /* MIDDLE LEVEL VARIABLE */
242 #define TEMPVAR 3 /* TEMPORARY VARIABLE */
243 #define INTCONST 4 /* CONSTANT: INTEGER,CHAR,BOOLEAN,STRING */
244 #define REALCONST 5 /* REAL CONSTANT */
248 unsigned int smode:4;
250 /* APPETITE, DISTINGUISHING REFERENCES */
251 unsigned int slive:1;
252 /* TRUE, IF USED OUTSIDE THE ADDRESSING SCOPE */
253 unsigned int slocal:1;
254 /* TRUE --> MUST BE ALLOCATED IN OBJECT */
255 /* FALSE --> MAY BE ALLOCATED IN GLOBAL AREA */
257 } stitem ; /* SYMBOL TABLE ITEM */
258 /* totalling 9 bits , less then 1 word */
261 /* ISTIC =*/ /* INTEGER <--> SYMBOL TABLE ITEM CONVERSION */
264 /* TRUE : ( INT : INTEGER );*/
265 /* FALSE: ( STI : STITEM )*/
268 typedef bool tmpmap[ MAXLOCTEMP + 1 ] ;
272 int locsize ; /* 0..MAXLOCTEMP */
273 int refsize ; /* -1..MAXREFTEMP */
276 #define ishft(i, n) (( (n) > 0) ? ((i) << (n)) : ((i) >> -(n)))
278 #define iand(i,j) ((int)((i) & (j)))
280 #define ior(i,j) ((int)((i) | (j)))
285 address off2 ; /* FOR REMOTE ONLY */
288 extern args_struct args[4];
291 #define putsap(s, i) i = (i & 0xff03) | ((s) << 2)
293 #define sap(i) ((i) & 255) >> 2
295 #define putslive(b, i) ((b) ? (i |= 2) : (i &= -3))
297 #define slive(i) (bool)((i & 2) == 2)
299 #define putslocal(b, i) ((b) ? (i |= 1) : (i &= -2))
301 #define slocal(i) (bool)((i & 1) == 1)
303 #define smode(i) ((stmode)(i >> 8))
309 #ifndef NO_PROTOTYPES
314 void backpatch(int,address);
315 void generror(errtype);
316 void addtolist(pointer *,int);
317 void longaddtolist(longpointer *,address);
323 void primdescr(void);
326 void putstrings(void);
327 void setfiles(char *);
328 void reserve(address);
329 logitem itemkind(int);
331 void dump_lcode(char *);
332 void makeproclist(void);
342 void longaddtolist();