Added upstream from http://ftp.icm.edu.pl/pub/loglan/
[loglan.git] / sources / gen / glodefs.h
1 /*     Loglan82 Compiler&Interpreter
2      Copyright (C) 1993 Institute of Informatics, University of Warsaw
3      Copyright (C)  1993, 1994 LITA, Pau
4      
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.
9      
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.
14      
15
16 =======================================================================
17 */
18
19 #include <stdio.h>
20 #include <string.h>
21
22 #ifndef NO_PROTOTYPES
23 #include <stdlib.h>
24 #endif
25
26
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])*/
29 #define LOG(i)
30
31 #define MAXINT 32767
32
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 */
36
37 #if SMALL
38 #define MEMLIMIT 32000     /* small memory for main */
39 typedef float real;
40 typedef int address;       /* APOPCODE == 2 -  appetite of extended opcode  */
41
42 #elif LARGE
43 #define MEMLIMIT 16000
44 typedef long address;      /* APOPCODE == 1  */
45 typedef double real;
46
47 #elif HUGE
48 #define MEMLIMIT 32000
49 typedef long address;      /* APOPCODE == 1  */
50 typedef double real;
51
52 #else
53 #error Define one of SMALL/LARGE/HUGE
54 #endif
55
56
57 #define CHARSINAD ( sizeof(address) )     /* number of characters in word */
58
59
60 /*    compiler symbol table and memory    */
61 extern int *ipmem;
62 extern address *m;
63 extern address fre,base,firstlabel;
64
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)             */
70 #define MAXPARAM   10
71
72
73 /*     SIMPLE TYPES ARE DISTINGUISHED BY THEIR OFFSET FROM "IPRADR" */
74 #define TINT      0
75 #define TREAL     1
76 #define TBOOLEAN  2
77 #define TCHAR     3
78 #define TCOROUT   4
79 #define TPROCESS  5
80 #define TSTRING   6
81 #define TFUNC2    7 /* parameter "function" of parameter  */
82 #define TPROC2    8 /* parameter "procedure" of parameter */
83 #define TFILE     9
84
85
86 #define CURRFILE  2    /* constant address of a current file virtual address */
87
88 #define MAXNAME  70    /* file name length */
89
90
91 #define GEN 1
92 #include "genint.h"
93
94 typedef  int addrmode ;      /* gsg it was an enumeration */
95
96 typedef  char  argdescr[4] ;
97
98 typedef  struct {
99    argdescr args ;    /* ARGS[0] IS OPCODE */
100 } extopcode ;         /* EXTENDED OPCODE   */
101
102   /* mb think up removing record extopcode */
103
104 /************************************************************/
105 /*      b32b16c = record  32-bit integer
106                 case boolean of
107                 true :  ( b32 : longint
108                 false : ( r16 : integer
109                           l16 : integer
110                          )
111                 end; */
112
113 typedef union {
114      struct { long int b32 ; } t ;
115           struct { int r16, l16 ; }  f ;
116         }  b32b16c ;
117
118 /*      ieopc   = record
119                 case integer of
120                   0 : (int1,int2 : integer);
121                   1 : (int : longint);
122                   2 : (eop : extopcode  );
123                 end;         */
124
125 typedef union {
126           struct { int int1f, int2f ; } c0 ;
127      struct { long int intf ; }    c1 ;
128      struct { extopcode eop ; }    c2 ;
129    } ieopc ;
130 /************************************************************/
131 typedef     char filename[ MAXNAME + 1 ] ;
132
133
134 /* mb declarations from main to follow...*/
135
136 #define     ENDOFSTRINGS  -1       /* end of strings section marker */
137
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             */
147
148 typedef struct {
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 */
156
157                 }  csti ; /*     : SYMBOL TABLE ITEM, 16 bits long */
158
159
160 typedef union {
161                 int icstic_int ;
162                 csti cst ;
163
164               }   icstic ;
165
166
167    /* mb genprot declarations to follow */
168
169 typedef int logitem ;    /* loglan items */  /* gsg previously enumeration */
170 #define ICLASS        0
171 #define IRECORD       1
172 #define ICOROUT       2
173 #define IPROCESS      3
174 #define IBLOCK        4
175 #define IPREFBLOCK    5
176 #define IFUNC         6
177 #define IPROC         7
178 #define IHANDLER      8
179 #define IFMPROC       9
180 #define IFMFUNC       10
181 #define IFMTYPE       11
182 #define IPARIN        12
183 #define IPAROUT       13
184 #define IPARINOUT     14
185 #define IVAR          15
186 #define ICONST        16
187 #define ISIGNAL       17
188
189 typedef int logunit ; /* iclass .. ifmfunc */ /* LOGLAN UNITS TOGETHER WITH FORMAL */
190                                               /* FUNCTION AND FORMAL PROCEDURE   */
191
192
193         /* AUXILIARY */
194
195
196
197 typedef struct s1 {
198                     int          ip ;          /* ADDRESS IN IPMEM */
199                     struct s1 *  prevelem ;    /* PREVIOUS ELEMENT */
200
201                   } listelem  ;  /* LIST OF PARAMETERS OR OF REFERENCE ATTRIBUTES */
202
203 typedef listelem *  pointer ;
204
205
206
207 typedef struct s2 {
208                     address      ip ;        /* ADDRESS IN IPMEM */
209                     struct s2 *  prevelem ;  /* PREVIOUS ELEMENT */
210
211                   } longlistelem ; /* list of parameters or of reference attributes */
212
213 typedef longlistelem  * longpointer ;
214
215
216 /* mb declarations of code to follow */
217
218 #define  QMAX  2400          /* MAXIMAL LENGTH OF THE QUADRUPLES SEQUENCE */
219 #define  TEMPGUARD  103     /* = MAXCOMTEMP + MAXIMAL APPETITE           */
220
221 /*CBC added concurrent statements... */
222 #define  MAXPROCLIST  30    /* maximum length of procedure ident. list   */
223
224
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 */
229
230 typedef  struct {
231                   int     opcode ;
232                   int     arg[4] ;
233                   qaddr0  nxtuse[4] ;
234                 } quadruple ;
235
236 extern quadruple tuple[];
237
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                          */
245
246
247 typedef    struct {
248                     unsigned int  smode:4;
249                     unsigned int    sap:3;
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    */
256
257                   }  stitem ;  /* SYMBOL TABLE ITEM */
258                /* totalling 9 bits , less then 1 word */
259
260
261 /*    ISTIC =*/ /* INTEGER <--> SYMBOL TABLE ITEM CONVERSION */
262 /*             RECORD*/
263 /*            CASE BOOLEAN OF*/
264 /*            TRUE : ( INT : INTEGER );*/
265 /*            FALSE: ( STI : STITEM  )*/
266 /*            END;*/
267
268 typedef   bool tmpmap[ MAXLOCTEMP + 1 ] ;
269
270 typedef   struct {
271                    tmpmap map ;
272                    int locsize ; /* 0..MAXLOCTEMP  */
273                    int refsize ; /* -1..MAXREFTEMP */
274
275                  } tmpmapdscr ;
276 #define ishft(i, n)    (( (n) > 0) ? ((i) << (n)) : ((i) >> -(n)))
277
278 #define  iand(i,j) ((int)((i) & (j)))
279
280 #define  ior(i,j)  ((int)((i) | (j)))
281
282 typedef struct {
283    addrmode  mode ;
284    address   off1 ;
285    address   off2 ; /* FOR REMOTE ONLY */
286 } args_struct ;
287
288 extern args_struct args[4];
289
290
291 #define putsap(s, i) i = (i & 0xff03) | ((s) << 2)
292
293 #define sap(i) ((i) & 255) >> 2
294
295 #define putslive(b, i) ((b) ? (i |= 2) : (i &= -3))
296
297 #define slive(i) (bool)((i & 2) == 2)
298
299 #define putslocal(b, i) ((b) ? (i |= 1) : (i &= -2))
300
301 #define slocal(i) (bool)((i & 1) == 1)
302
303 #define smode(i) ((stmode)(i >> 8))
304
305 #include "mainvar.h"
306 #include "oxen.h"
307
308
309 #ifndef NO_PROTOTYPES
310
311 void out(void);
312 void outprot(void);
313 void back(void);
314 void backpatch(int,address);
315 void generror(errtype);
316 void addtolist(pointer *,int);
317 void longaddtolist(longpointer *,address);
318 void gen(void);
319 void genprot(void);
320 void handlers(void);
321 void initiate(void);
322 void lists(void);
323 void primdescr(void);
324 void pdescr(void);
325 void putreals(void);
326 void putstrings(void);
327 void setfiles(char *);
328 void reserve(address);
329 logitem itemkind(int);
330 int apet(int);
331 void dump_lcode(char *);
332 void makeproclist(void);
333
334 #else
335
336 void out();
337 void outprot();
338 void back();
339 void backpatch();
340 void generror();
341 void addtolist();
342 void longaddtolist();
343 void gen();
344 void genprot();
345 void handlers();
346 void initiate();
347 void lists();
348 void primdescr();
349 void pdescr();
350 void putreals();
351 void putstrings();
352 void setfiles();
353 void reserve();
354 logitem itemkind();
355 int apet();
356 void dump_lcode();
357 void makeproclist();
358
359 #endif
360