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 =======================================================================
23 static void fputaddr(FILE *,address);
24 static int fgetint(FILE *);
28 static void fputaddr();
33 int wordswritten = 0 ;
35 void setfiles(name) char *name;{
39 strcat(work, ".lcd") ;
40 lfile = fopen(work, "rb");
42 { puts(strcat("Couldn't open file ", work)) ;
46 strcat(work, ".pcd") ;
47 pfile = fopen(work, "wb") ;
50 strcat(work, ".ccd") ;
51 cfile = fopen(work, "wb") ;
54 printf("Couldn't open file %s for writing\n", work);
64 if(!fread((char *)&i,sizeof(i),1,lfile)){
65 printf("Unexpected EOF ! Aborting...\n");
71 static int fgetint(f) FILE * f;{
73 fread((char *)&c, sizeof(int), 1, f) ;
77 static void fputaddr(f,v) FILE *f; address v;{
78 fwrite((char *)&v, sizeof(address), 1, f);
81 /* Buffered version - not finished
82 static address buf[BUFSIZE] ;
83 static address * bufp = buf;
91 int c1, c2, start, nr=1 ;
93 cc = fgetint(lfile); /* character count */
95 while (cc != ENDOFSTRINGS)
101 for (i = 1; i <= (cc / CHARSINAD + 1) ; i++ )
102 /* extra 0 byte after string */
106 ch2 = fgetint(lfile) ;
109 c1 = fgetint(lfile) ;
110 c2 = fgetint(lfile) ;
111 m[ fre ] = ( (long)c1 ) | ( ((long)c2) << 16 ) ;
119 printf("string %d = %s\n", nr++, (char *)(&m[start]));
122 cc = fgetint(lfile) ;
128 /* read ipmem and some variables from the blank common of the compiler */
134 fread((char *)tarr, sizeof(int), 302, lfile) ;
148 addrnone = tarr[299] ; /*cdsw&ail */
151 printf("Initiate\n lmem = %d, lpmem = %d, irecn = %d\n",
153 printf(" nrint = %d\n", nrint);
154 printf(" nrre = %d\n", nrre );
155 printf(" nrbool= %d\n", nrbool);
156 printf(" nrchr = %d\n", nrchr);
157 printf(" nrcor = %d\n", nrcor);
158 printf(" nrproc= %d\n", nrproc);
159 printf(" nrtext= %d\n", nrtext);
160 printf(" nblus = %d\n", nblus);
161 printf(" addrnone = %d\n", addrnone);
164 ipmem = (int *) calloc(lmem + 1, sizeof(int));
165 fread( (char *)(ipmem + 1), sizeof(int), irecn, lfile);
168 for (k = 1; k <= irecn; k++)
170 printf("%8d",ipmem[k]);
171 if (k % 16 == 0) printf("\n");
180 /* WRITE REAL CONSTANTS TO MEMORY */
186 struct { int int1, int2 ; } p;
192 struct { address int1, int2 ; } p;
200 printf("real %10d:%18f\n",i,*(float *)&(ipmem[i]));
202 m[ fre++ ] = ipmem[ i++ ] ;
204 trick1.p.int1 = ipmem[ i++ ] ;
205 trick1.p.int2 = ipmem[ i++ ] ;
208 printf("real %10d:%18f\n",i,trick1.r);
210 m[ fre++ ] = trick2.p.int1;
211 m[ fre++ ] = trick2.p.int2;
224 case TMPROT : printf(" TOO MANY PROTOTYPES");
227 case TLDESCR : printf(" DESCRIPTIONS TOO LONG");
230 case MEMOVF : printf(" MEMORY OVERFLOW ");
233 case TMTEMP : printf(" TOO MANY TEMPORARY VARIABLES NEEDED");
236 case STSEQTL : printf(" STATEMENT SEQUENCE TOO LONG");
239 case NOTIMPL : printf(" FUNCTION NOT IMPLEMENTED");
242 case OBJTOLG : printf(" OBJECT TOO LONG");
245 case PROCLTL : printf(" PROCEDURE LIST TOO LONG ") ;
257 /* PUT THE CONTENTS OF M^[ 0 .. fre-1 ] ON THE FILE "CFILE" */
258 /* 'BASE$ IS UPDATED AND 'fre' IS RESET TO ZERO */
263 printf("Writing %4d words of code\n", fre) ;
266 for (n=0; n <= fre-1; n++ ){
274 printf("base = %d\n", base) ;
275 printf("fre = %d\n", fre) ;
286 for (n = MAINBLOCK; n <= lastprot; n++)
287 fwrite( (char *)(prototype[ n ]), sizeof(*(prototype[0])), 1, pfile);
289 fputaddr(cfile,ipradr);
290 fputaddr(cfile,temporary);
291 fputaddr(cfile,strings);
294 fputaddr(cfile,base);
298 int apet(ip) /* STRONGLY MACHINE DEPENDENT */
301 return ( iand( ishft( ipmem [ ip ],-14 ), 3 ) + 1 );