make to work on sun, added copyright, etc

This commit is contained in:
ceriel 1987-04-29 10:22:07 +00:00
parent 8482d6776b
commit fbc0415761
49 changed files with 989 additions and 224 deletions

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* L E X I C A L A N A L Y S E R F O R M O D U L A - 2 */ /* L E X I C A L A N A L Y S E R F O R M O D U L A - 2 */
/* $Header$ */
#include "debug.h" #include "debug.h"
#include "idfsize.h" #include "idfsize.h"
#include "numsize.h" #include "numsize.h"
@ -25,7 +34,8 @@ long str2long();
struct token dot, struct token dot,
aside; aside;
struct type *toktype; struct type *toktype;
int idfsize = IDFSIZE; int idfsize = IDFSIZE;
int ForeignFlag;
#ifdef DEBUG #ifdef DEBUG
extern int cntlines; extern int cntlines;
#endif #endif
@ -42,6 +52,19 @@ SkipComment()
register int CommentLevel = 0; register int CommentLevel = 0;
LoadChar(ch); LoadChar(ch);
if (ch == '$') {
LoadChar(ch);
switch(ch) {
case 'F':
/* Foreign; This definition module has an
implementation in another language.
In this case, don't generate prefixes in front
of the names
*/
ForeignFlag = 1;
break;
}
}
for (;;) { for (;;) {
if (class(ch) == STNL) { if (class(ch) == STNL) {
LineNumber++; LineNumber++;
@ -138,10 +161,20 @@ linedirective() {
/* Read a line directive /* Read a line directive
*/ */
register int ch; register int ch;
}
CheckForLineDirective()
{
register int ch = getch();
register int i = 0; register int i = 0;
char buf[IDFSIZE + 2]; char buf[IDFSIZE + 2];
register char *c = buf; register char *c = buf;
if (ch != '#') {
PushBack();
return;
}
do { /* do { /*
* Skip to next digit * Skip to next digit
* Do not skip newlines * Do not skip newlines
@ -153,10 +186,10 @@ linedirective() {
return; return;
} }
} while (class(ch) != STNUM); } while (class(ch) != STNUM);
do { while (class(ch) == STNUM) {
i = i*10 + (ch - '0'); i = i*10 + (ch - '0');
ch = getch(); ch = getch();
} while (class(ch) == STNUM); }
while (ch != '"' && class(ch) != STNL) ch = getch(); while (ch != '"' && class(ch) != STNL) ch = getch();
if (ch == '"') { if (ch == '"') {
c = buf; c = buf;
@ -206,7 +239,7 @@ LLlex()
tk->tk_lineno = LineNumber; tk->tk_lineno = LineNumber;
again2: again1:
if (eofseen) { if (eofseen) {
eofseen = 0; eofseen = 0;
ch = EOI; ch = EOI;
@ -214,7 +247,6 @@ again2:
else { else {
again: again:
LoadChar(ch); LoadChar(ch);
again1:
if ((ch & 0200) && ch != EOI) { if ((ch & 0200) && ch != EOI) {
error("non-ascii '\\%03o' read", ch & 0377); error("non-ascii '\\%03o' read", ch & 0377);
goto again; goto again;
@ -229,10 +261,8 @@ again1:
cntlines++; cntlines++;
#endif #endif
tk->tk_lineno++; tk->tk_lineno++;
LoadChar(ch); CheckForLineDirective();
if (ch != '#') goto again1; goto again1;
linedirective();
goto again2;
case STSKIP: case STSKIP:
goto again; goto again;

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* T O K E N D E S C R I P T O R D E F I N I T I O N */ /* T O K E N D E S C R I P T O R D E F I N I T I O N */
/* $Header$ */
/* Structure to store a string constant /* Structure to store a string constant
*/ */
struct string { struct string {

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* S Y N T A X E R R O R R E P O R T I N G */ /* S Y N T A X E R R O R R E P O R T I N G */
/* $Header$ */
/* Defines the LLmessage routine. LLgen-generated parsers require the /* Defines the LLmessage routine. LLgen-generated parsers require the
existence of a routine of that name. existence of a routine of that name.
The routine must do syntax-error reporting and must be able to The routine must do syntax-error reporting and must be able to

View file

@ -13,9 +13,9 @@ CURRDIR = .
INCLUDES = -I$(MHDIR) -I$(EMHOME)/h -I$(PKGDIR) INCLUDES = -I$(MHDIR) -I$(EMHOME)/h -I$(PKGDIR)
GFILES = tokenfile.g program.g declar.g expression.g statement.g GFILES = tokenfile.g program.g declar.g expression.g statement.g
LLGENOPTIONS = LLGENOPTIONS = -v
PROFILE = PROFILE =
CFLAGS = $(PROFILE) $(INCLUDES) -DSTATIC= CFLAGS = $(PROFILE) $(INCLUDES) -O -DSTATIC=
LINTFLAGS = -DSTATIC= -DNORCSID LINTFLAGS = -DSTATIC= -DNORCSID
MALLOC = $(LIBDIR)/malloc.o MALLOC = $(LIBDIR)/malloc.o
LFLAGS = $(PROFILE) LFLAGS = $(PROFILE)
@ -61,7 +61,8 @@ install: all
cp $(CURRDIR)/main $(EMHOME)/lib/em_m2 cp $(CURRDIR)/main $(EMHOME)/lib/em_m2
clean: clean:
rm -f $(OBJ) $(GENFILES) LLfiles hfiles Cfiles tab clashes $(CURRDIR)/main rm -f $(OBJ) $(GENFILES) LLfiles hfiles Cfiles tab clashes \
$(CURRDIR)/main LL.output
(cd .. ; rm -rf Xsrc) (cd .. ; rm -rf Xsrc)
lint: Cfiles lint: Cfiles
@ -132,36 +133,266 @@ $(CURRDIR)/main: $(OBJ)
size $(CURRDIR)/main size $(CURRDIR)/main
#AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO #AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO
LLlex.o: LLlex.h Lpars.h class.h const.h debug.h debugcst.h f_info.h idf.h idfsize.h input.h inputtype.h numsize.h strsize.h type.h warning.h LLlex.o: LLlex.h
LLmessage.o: LLlex.h Lpars.h idf.h LLlex.o: Lpars.h
LLlex.o: class.h
LLlex.o: const.h
LLlex.o: debug.h
LLlex.o: debugcst.h
LLlex.o: f_info.h
LLlex.o: idf.h
LLlex.o: idfsize.h
LLlex.o: input.h
LLlex.o: inputtype.h
LLlex.o: numsize.h
LLlex.o: strsize.h
LLlex.o: type.h
LLlex.o: warning.h
LLmessage.o: LLlex.h
LLmessage.o: Lpars.h
LLmessage.o: idf.h
char.o: class.h char.o: class.h
error.o: LLlex.h debug.h debugcst.h errout.h f_info.h input.h inputtype.h main.h node.h warning.h error.o: LLlex.h
main.o: LLlex.h Lpars.h debug.h debugcst.h def.h f_info.h idf.h input.h inputtype.h ndir.h node.h scope.h standards.h tokenname.h type.h warning.h error.o: debug.h
error.o: debugcst.h
error.o: errout.h
error.o: f_info.h
error.o: input.h
error.o: inputtype.h
error.o: main.h
error.o: node.h
error.o: warning.h
main.o: LLlex.h
main.o: Lpars.h
main.o: debug.h
main.o: debugcst.h
main.o: def.h
main.o: f_info.h
main.o: idf.h
main.o: input.h
main.o: inputtype.h
main.o: ndir.h
main.o: node.h
main.o: scope.h
main.o: standards.h
main.o: tokenname.h
main.o: type.h
main.o: warning.h
symbol2str.o: Lpars.h symbol2str.o: Lpars.h
tokenname.o: Lpars.h idf.h tokenname.h tokenname.o: Lpars.h
tokenname.o: idf.h
tokenname.o: tokenname.h
idf.o: idf.h idf.o: idf.h
input.o: def.h f_info.h idf.h input.h inputtype.h scope.h input.o: def.h
type.o: LLlex.h const.h debug.h debugcst.h def.h idf.h maxset.h node.h scope.h target_sizes.h type.h walk.h input.o: f_info.h
def.o: LLlex.h Lpars.h debug.h debugcst.h def.h idf.h main.h node.h scope.h type.h input.o: idf.h
scope.o: LLlex.h debug.h debugcst.h def.h idf.h node.h scope.h type.h input.o: input.h
misc.o: LLlex.h f_info.h idf.h misc.h node.h input.o: inputtype.h
enter.o: LLlex.h debug.h debugcst.h def.h idf.h main.h misc.h node.h scope.h type.h input.o: scope.h
defmodule.o: LLlex.h Lpars.h debug.h debugcst.h def.h f_info.h idf.h input.h inputtype.h main.h misc.h node.h scope.h type.h type.o: LLlex.h
typequiv.o: LLlex.h debug.h debugcst.h def.h node.h type.h warning.h type.o: chk_expr.h
node.o: LLlex.h debug.h debugcst.h def.h node.h type.h type.o: const.h
cstoper.o: LLlex.h Lpars.h debug.h debugcst.h idf.h node.h standards.h target_sizes.h type.h warning.h type.o: debug.h
chk_expr.o: LLlex.h Lpars.h chk_expr.h const.h debug.h debugcst.h def.h idf.h misc.h node.h scope.h standards.h type.h warning.h type.o: debugcst.h
options.o: idfsize.h main.h ndir.h type.h warning.h type.o: def.h
walk.o: LLlex.h Lpars.h chk_expr.h debug.h debugcst.h def.h desig.h f_info.h idf.h main.h node.h scope.h type.h walk.h warning.h type.o: idf.h
casestat.o: LLlex.h Lpars.h debug.h debugcst.h density.h desig.h node.h type.h walk.h type.o: maxset.h
desig.o: LLlex.h debug.h debugcst.h def.h desig.h node.h scope.h type.h type.o: node.h
code.o: LLlex.h Lpars.h debug.h debugcst.h def.h desig.h node.h scope.h standards.h type.h walk.h type.o: scope.h
tmpvar.o: debug.h debugcst.h def.h main.h scope.h type.h type.o: target_sizes.h
lookup.o: LLlex.h debug.h debugcst.h def.h idf.h misc.h node.h scope.h type.h type.o: type.h
next.o: debug.h debugcst.h type.o: walk.h
def.o: LLlex.h
def.o: Lpars.h
def.o: debug.h
def.o: debugcst.h
def.o: def.h
def.o: idf.h
def.o: main.h
def.o: node.h
def.o: scope.h
def.o: type.h
scope.o: LLlex.h
scope.o: debug.h
scope.o: debugcst.h
scope.o: def.h
scope.o: idf.h
scope.o: node.h
scope.o: scope.h
scope.o: type.h
misc.o: LLlex.h
misc.o: f_info.h
misc.o: idf.h
misc.o: misc.h
misc.o: node.h
enter.o: LLlex.h
enter.o: debug.h
enter.o: debugcst.h
enter.o: def.h
enter.o: idf.h
enter.o: main.h
enter.o: misc.h
enter.o: node.h
enter.o: scope.h
enter.o: type.h
defmodule.o: LLlex.h
defmodule.o: Lpars.h
defmodule.o: debug.h
defmodule.o: debugcst.h
defmodule.o: def.h
defmodule.o: f_info.h
defmodule.o: idf.h
defmodule.o: input.h
defmodule.o: inputtype.h
defmodule.o: main.h
defmodule.o: misc.h
defmodule.o: node.h
defmodule.o: scope.h
defmodule.o: type.h
typequiv.o: LLlex.h
typequiv.o: debug.h
typequiv.o: debugcst.h
typequiv.o: def.h
typequiv.o: node.h
typequiv.o: type.h
typequiv.o: warning.h
node.o: LLlex.h
node.o: debug.h
node.o: debugcst.h
node.o: def.h
node.o: node.h
node.o: type.h
cstoper.o: LLlex.h
cstoper.o: Lpars.h
cstoper.o: debug.h
cstoper.o: debugcst.h
cstoper.o: idf.h
cstoper.o: node.h
cstoper.o: standards.h
cstoper.o: target_sizes.h
cstoper.o: type.h
cstoper.o: warning.h
chk_expr.o: LLlex.h
chk_expr.o: Lpars.h
chk_expr.o: chk_expr.h
chk_expr.o: const.h
chk_expr.o: debug.h
chk_expr.o: debugcst.h
chk_expr.o: def.h
chk_expr.o: idf.h
chk_expr.o: misc.h
chk_expr.o: node.h
chk_expr.o: scope.h
chk_expr.o: standards.h
chk_expr.o: type.h
chk_expr.o: warning.h
options.o: idfsize.h
options.o: main.h
options.o: ndir.h
options.o: type.h
options.o: warning.h
walk.o: LLlex.h
walk.o: Lpars.h
walk.o: chk_expr.h
walk.o: debug.h
walk.o: debugcst.h
walk.o: def.h
walk.o: desig.h
walk.o: f_info.h
walk.o: idf.h
walk.o: main.h
walk.o: node.h
walk.o: scope.h
walk.o: type.h
walk.o: walk.h
walk.o: warning.h
casestat.o: LLlex.h
casestat.o: Lpars.h
casestat.o: debug.h
casestat.o: debugcst.h
casestat.o: density.h
casestat.o: desig.h
casestat.o: node.h
casestat.o: type.h
casestat.o: walk.h
desig.o: LLlex.h
desig.o: debug.h
desig.o: debugcst.h
desig.o: def.h
desig.o: desig.h
desig.o: node.h
desig.o: scope.h
desig.o: type.h
code.o: LLlex.h
code.o: Lpars.h
code.o: debug.h
code.o: debugcst.h
code.o: def.h
code.o: desig.h
code.o: node.h
code.o: scope.h
code.o: standards.h
code.o: type.h
code.o: walk.h
tmpvar.o: debug.h
tmpvar.o: debugcst.h
tmpvar.o: def.h
tmpvar.o: main.h
tmpvar.o: scope.h
tmpvar.o: type.h
lookup.o: LLlex.h
lookup.o: debug.h
lookup.o: debugcst.h
lookup.o: def.h
lookup.o: idf.h
lookup.o: misc.h
lookup.o: node.h
lookup.o: scope.h
lookup.o: type.h
next.o: debug.h
next.o: debugcst.h
tokenfile.o: Lpars.h tokenfile.o: Lpars.h
program.o: LLlex.h Lpars.h debug.h debugcst.h def.h f_info.h idf.h main.h node.h scope.h type.h warning.h program.o: LLlex.h
declar.o: LLlex.h Lpars.h chk_expr.h debug.h debugcst.h def.h idf.h main.h misc.h node.h scope.h type.h warning.h program.o: Lpars.h
expression.o: LLlex.h Lpars.h chk_expr.h const.h debug.h debugcst.h def.h idf.h node.h type.h warning.h program.o: debug.h
statement.o: LLlex.h Lpars.h def.h idf.h node.h scope.h type.h program.o: debugcst.h
program.o: def.h
program.o: f_info.h
program.o: idf.h
program.o: main.h
program.o: node.h
program.o: scope.h
program.o: type.h
program.o: warning.h
declar.o: LLlex.h
declar.o: Lpars.h
declar.o: chk_expr.h
declar.o: debug.h
declar.o: debugcst.h
declar.o: def.h
declar.o: idf.h
declar.o: main.h
declar.o: misc.h
declar.o: node.h
declar.o: scope.h
declar.o: type.h
declar.o: warning.h
expression.o: LLlex.h
expression.o: Lpars.h
expression.o: chk_expr.h
expression.o: const.h
expression.o: debug.h
expression.o: debugcst.h
expression.o: def.h
expression.o: idf.h
expression.o: node.h
expression.o: type.h
expression.o: warning.h
statement.o: LLlex.h
statement.o: Lpars.h
statement.o: def.h
statement.o: idf.h
statement.o: node.h
statement.o: scope.h
statement.o: type.h
Lpars.o: Lpars.h Lpars.o: Lpars.h

18
lang/m2/comp/SYSTEM.h Normal file
View file

@ -0,0 +1,18 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* S Y S T E M M O D U L E T E X T */
/* $Header$ */
/* Text of SYSTEM module, for as far as it can be expressed in Modula-2 */
#define SYSTEMTEXT "DEFINITION MODULE SYSTEM;\n\
TYPE PROCESS = ADDRESS;\n\
PROCEDURE NEWPROCESS(P:PROC; A:ADDRESS; n:CARDINAL; VAR p1:ADDRESS);\n\
PROCEDURE TRANSFER(VAR p1,p2:ADDRESS);\n\
END SYSTEM.\n"

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* C A S E S T A T E M E N T C O D E G E N E R A T I O N */ /* C A S E S T A T E M E N T C O D E G E N E R A T I O N */
/* $Header$ */
/* Generation of case statements is done by first creating a /* Generation of case statements is done by first creating a
description structure for the statement, build a list of the description structure for the statement, build a list of the
case-labels, then generating a case description in the code, case-labels, then generating a case description in the code,

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* E X P R E S S I O N C H E C K I N G */ /* E X P R E S S I O N C H E C K I N G */
/* $Header$ */
/* Check expressions, and try to evaluate them as far as possible. /* Check expressions, and try to evaluate them as far as possible.
*/ */
@ -1203,11 +1212,7 @@ int (*ExprChkTable[])() = {
}; };
int (*DesigChkTable[])() = { int (*DesigChkTable[])() = {
#ifdef DEBUG no_desig,
ChkValue,
#else
done_before,
#endif
ChkArr, ChkArr,
no_desig, no_desig,
no_desig, no_desig,

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* E X P R E S S I O N C H E C K I N G */ /* E X P R E S S I O N C H E C K I N G */
/* $Header$ */
extern int (*ExprChkTable[])(); /* table of expression checking extern int (*ExprChkTable[])(); /* table of expression checking
functions, indexed by node class functions, indexed by node class
*/ */

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* U S E O F C H A R A C T E R C L A S S E S */ /* U S E O F C H A R A C T E R C L A S S E S */
/* $Header$ */
/* As a starter, chars are divided into classes, according to which /* As a starter, chars are divided into classes, according to which
token they can be the start of. token they can be the start of.
At present such a class number is supposed to fit in 4 bits. At present such a class number is supposed to fit in 4 bits.

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* C O D E G E N E R A T I O N R O U T I N E S */ /* C O D E G E N E R A T I O N R O U T I N E S */
/* $Header$ */
/* Code generation for expressions and coercions /* Code generation for expressions and coercions
*/ */

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* C O N S T A N T S F O R E X P R E S S I O N H A N D L I N G */ /* C O N S T A N T S F O R E X P R E S S I O N H A N D L I N G */
/* $Header$ */
extern long extern long
mach_long_sign; /* sign bit of the machine long */ mach_long_sign; /* sign bit of the machine long */
extern int extern int

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* C O N S T A N T E X P R E S S I O N H A N D L I N G */ /* C O N S T A N T E X P R E S S I O N H A N D L I N G */
/* $Header$ */
#include "debug.h" #include "debug.h"
#include "target_sizes.h" #include "target_sizes.h"

View file

@ -1,5 +1,13 @@
/* A debugging macro /*
*/ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* D E B U G G I N G M A C R O */
/* $Header$ */
#include "debugcst.h" #include "debugcst.h"

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* D E C L A R A T I O N S */ /* D E C L A R A T I O N S */
/* $Header$ */
{ {
#include "debug.h" #include "debug.h"
@ -21,25 +30,27 @@
int proclevel = 0; /* nesting level of procedures */ int proclevel = 0; /* nesting level of procedures */
int return_occurred; /* set if a return occurs in a block */ int return_occurred; /* set if a return occurs in a block */
#define needs_static_link() (proclevel > 1)
} }
ProcedureDeclaration ProcedureDeclaration
{ {
struct def *df; struct def *df;
} : } :
{ ++proclevel; } { ++proclevel; }
ProcedureHeading(&df, D_PROCEDURE) ProcedureHeading(&df, D_PROCEDURE)
';' block(&(df->prc_body)) ';' block(&(df->prc_body))
IDENT IDENT
{ EndProc(df, dot.TOK_IDF); { EndProc(df, dot.TOK_IDF);
--proclevel; --proclevel;
} }
; ;
ProcedureHeading(struct def **pdf; int type;) ProcedureHeading(struct def **pdf; int type;)
{ {
struct type *tp = 0; struct type *tp = 0;
#define needs_static_link() (proclevel > 1)
arith parmaddr = needs_static_link() ? pointer_size : 0; arith parmaddr = needs_static_link() ? pointer_size : 0;
struct paramlist *pr = 0; struct paramlist *pr = 0;
} : } :
@ -67,11 +78,11 @@ block(struct node **pnd;) :
; ;
declaration: declaration:
CONST [ %persistent ConstantDeclaration ';' ]* CONST [ ConstantDeclaration ';' ]*
| |
TYPE [ %persistent TypeDeclaration ';' ]* TYPE [ TypeDeclaration ';' ]*
| |
VAR [ %persistent VariableDeclaration ';' ]* VAR [ VariableDeclaration ';' ]*
| |
ProcedureDeclaration ';' ProcedureDeclaration ';'
| |
@ -171,20 +182,7 @@ enumeration(struct type **ptp;)
struct node *EnumList; struct node *EnumList;
} : } :
'(' IdentList(&EnumList) ')' '(' IdentList(&EnumList) ')'
{ register struct type *tp = { *ptp = enum_type(EnumList); }
standard_type(T_ENUMERATION, int_align, int_size);
*ptp = tp;
EnterEnumList(EnumList, tp);
if (ufit(tp->enm_ncst-1, 1)) {
tp->tp_size = 1;
tp->tp_align = 1;
}
else if (ufit(tp->enm_ncst-1, short_size)) {
tp->tp_size = short_size;
tp->tp_align = short_align;
}
}
; ;
IdentList(struct node **p;) IdentList(struct node **p;)
@ -244,10 +242,7 @@ RecordType(struct type **ptp;)
} }
: :
RECORD RECORD
{ open_scope(OPENSCOPE); /* scope for fields of record */ { scope = open_and_close_scope(OPENSCOPE); }
scope = CurrentScope;
close_scope(0);
}
FieldListSequence(scope, &size, &xalign) FieldListSequence(scope, &size, &xalign)
{ if (size == 0) { { if (size == 0) {
warning(W_ORDINARY, "empty record declaration"); warning(W_ORDINARY, "empty record declaration");
@ -271,13 +266,13 @@ FieldList(struct scope *scope; arith *cnt; int *palign;)
struct node *FldList; struct node *FldList;
register struct idf *id = 0; register struct idf *id = 0;
struct type *tp; struct type *tp;
struct node *nd1; struct node *nd;
register struct node *nd;
arith tcnt, max; arith tcnt, max;
} : } :
[ [
IdentList(&FldList) ':' type(&tp) IdentList(&FldList) ':' type(&tp)
{ *palign = lcm(*palign, tp->tp_align); {
*palign = lcm(*palign, tp->tp_align);
EnterFieldList(FldList, tp, scope, cnt); EnterFieldList(FldList, tp, scope, cnt);
} }
| |
@ -285,8 +280,7 @@ FieldList(struct scope *scope; arith *cnt; int *palign;)
/* Also accept old fashioned Modula-2 syntax, but give a warning. /* Also accept old fashioned Modula-2 syntax, but give a warning.
Sorry for the complicated code. Sorry for the complicated code.
*/ */
[ qualident(&nd1) [ qualident(&nd)
{ nd = nd1; }
[ ':' qualtype(&tp) [ ':' qualtype(&tp)
/* This is correct, in both kinds of Modula-2, if /* This is correct, in both kinds of Modula-2, if
the first qualident is a single identifier. the first qualident is a single identifier.
@ -300,25 +294,20 @@ FieldList(struct scope *scope; arith *cnt; int *palign;)
| /* Old fashioned! the first qualident now represents | /* Old fashioned! the first qualident now represents
the type the type
*/ */
{ warning(W_OLDFASHIONED, "old fashioned Modula-2 syntax; ':' missing"); { warning(W_OLDFASHIONED,
if (ChkDesignator(nd) && "old fashioned Modula-2 syntax; ':' missing");
(nd->nd_class != Def || tp = qualified_type(nd);
!(nd->nd_def->df_kind&(D_ERROR|D_ISTYPE)) ||
!nd->nd_def->df_type)) {
node_error(nd, "type expected");
tp = error_type;
}
else tp = nd->nd_def->df_type;
FreeNode(nd);
} }
] ]
| ':' qualtype(&tp) | ':' qualtype(&tp)
/* Aha, third edition. Well done! */ /* Aha, third edition. Well done! */
] ]
{ if (id) { {
register struct def *df = define(id, *palign = lcm(*palign, tp->tp_align);
scope, if (id) {
D_FIELD); register struct def *df =
define(id, scope, D_FIELD);
if (!(tp->tp_fund & T_DISCRETE)) { if (!(tp->tp_fund & T_DISCRETE)) {
error("illegal type in variant"); error("illegal type in variant");
} }
@ -351,7 +340,7 @@ variant(struct scope *scope; arith *cnt; struct type *tp; int *palign;)
CaseLabelList(&tp, &nd) CaseLabelList(&tp, &nd)
{ /* Ignore the cases for the time being. { /* Ignore the cases for the time being.
Maybe a checking version will be supplied Maybe a checking version will be supplied
later ??? (Improbable) later ???
*/ */
FreeNode(nd); FreeNode(nd);
} }
@ -403,73 +392,21 @@ SetType(struct type **ptp;) :
have to be declared yet, so be careful about identifying have to be declared yet, so be careful about identifying
type-identifiers type-identifiers
*/ */
PointerType(struct type **ptp;) PointerType(struct type **ptp;) :
{
register struct node *nd = 0;
} :
POINTER TO POINTER TO
{ *ptp = construct_type(T_POINTER, NULLTYPE); } [ %if (type_or_forward(ptp))
[ %if ( lookup(dot.TOK_IDF, CurrentScope, 1)
/* Either a Module or a Type, but in both cases defined
in this scope, so this is the correct identification
*/
||
( nd = new_node(),
nd->nd_token = dot,
lookfor(nd, CurrVis, 0)->df_kind == D_MODULE
)
/* A Modulename in one of the enclosing scopes.
It is not clear from the language definition that
it is correct to handle these like this, but
existing compilers do it like this, and the
alternative is difficult with a lookahead of only
one token.
???
*/
)
type(&((*ptp)->next)) type(&((*ptp)->next))
{ if (nd) free_node(nd); }
| |
IDENT { if (nd) { IDENT
/* nd could be a null pointer, if we had a
syntax error exactly at this alternation.
MORAL: Be careful with %if resolvers with
side effects!
*/
Forward(nd, (*ptp));
}
}
] ]
; ;
qualtype(struct type **ptp;) qualtype(struct type **ptp;)
{ {
register struct node *nd; struct node *nd;
struct node *nd1; /* because &nd is illegal */
} : } :
qualident(&nd1) qualident(&nd)
{ nd = nd1; { *ptp = qualified_type(nd); }
*ptp = error_type;
if (ChkDesignator(nd)) {
if (nd->nd_class != Def) {
node_error(nd, "type expected");
}
else {
register struct def *df = nd->nd_def;
if (df->df_kind&(D_ISTYPE|D_FORWARD|D_ERROR)) {
if (! df->df_type) {
node_error(nd,"type \"%s\" not (yet) declared", df->df_idf->id_text);
}
else *ptp = df->df_type;
}
else {
node_error(nd,"identifier \"%s\" is not a type", df->df_idf->id_text);
}
}
}
FreeNode(nd);
}
; ;
ProcedureType(struct type **ptp;) ProcedureType(struct type **ptp;)

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* I D E N T I F I E R D E S C R I P T O R S T R U C T U R E */ /* I D E N T I F I E R D E S C R I P T O R S T R U C T U R E */
/* $Header$ */
struct module { struct module {
struct node *mo_priority;/* priority of a module */ struct node *mo_priority;/* priority of a module */
struct scopelist *mo_vis;/* scope of this module */ struct scopelist *mo_vis;/* scope of this module */
@ -106,6 +115,7 @@ struct def { /* list of definitions for a name */
#define D_EXPORTED 0x20 /* set if exported */ #define D_EXPORTED 0x20 /* set if exported */
#define D_QEXPORTED 0x40 /* set if qualified exported */ #define D_QEXPORTED 0x40 /* set if qualified exported */
#define D_BUSY 0x80 /* set if busy reading this definition module */ #define D_BUSY 0x80 /* set if busy reading this definition module */
#define D_FOREIGN 0x100 /* set for foreign language modules */
struct type *df_type; struct type *df_type;
union { union {
struct module df_module; struct module df_module;

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* D E F I N I T I O N M E C H A N I S M */ /* D E F I N I T I O N M E C H A N I S M */
/* $Header$ */
#include "debug.h" #include "debug.h"
#include <alloc.h> #include <alloc.h>
@ -234,8 +243,13 @@ DeclProc(type, id)
*/ */
df = define(id, CurrentScope, type); df = define(id, CurrentScope, type);
df->for_node = MkLeaf(Name, &dot); df->for_node = MkLeaf(Name, &dot);
sprint(buf,"%s_%s",CurrentScope->sc_name,id->id_text); if (CurrentScope->sc_definedby->df_flags & D_FOREIGN) {
df->for_name = Salloc(buf, (unsigned) (strlen(buf)+1)); df->for_name = id->id_text;
}
else {
sprint(buf,"%s_%s",CurrentScope->sc_name,id->id_text);
df->for_name = Salloc(buf, (unsigned) (strlen(buf)+1));
}
if (CurrVis == Defined->mod_vis) { if (CurrVis == Defined->mod_vis) {
/* The current module will define this routine. /* The current module will define this routine.
make sure the name is exported. make sure the name is exported.

View file

@ -1,10 +1,20 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* D E F I N I T I O N M O D U L E S */ /* D E F I N I T I O N M O D U L E S */
/* $Header$ */
#include "debug.h" #include "debug.h"
#include <assert.h> #include <assert.h>
#include <em_arith.h> #include <em_arith.h>
#include <em_label.h> #include <em_label.h>
#include <alloc.h>
#include "idf.h" #include "idf.h"
#include "input.h" #include "input.h"
@ -24,6 +34,28 @@ long sys_filesize();
struct idf *DefId; struct idf *DefId;
STATIC char *
getwdir(fn)
char *fn;
{
register char *p;
char *strrindex();
p = strrindex(fn, '/');
while (p && *(p + 1) == '\0') { /* remove trailing /'s */
*p = '\0';
p = strrindex(fn, '/');
}
if (p) {
*p = '\0';
fn = Salloc(fn, p - &fn[0] + 1);
*p = '/';
return fn;
}
else return ".";
}
STATIC STATIC
GetFile(name) GetFile(name)
char *name; char *name;
@ -33,14 +65,17 @@ GetFile(name)
*/ */
char buf[15]; char buf[15];
char *strcpy(), *strcat(); char *strcpy(), *strcat();
static char *WorkingDir = ".";
strncpy(buf, name, 10); strncpy(buf, name, 10);
buf[10] = '\0'; /* maximum length */ buf[10] = '\0'; /* maximum length */
strcat(buf, ".def"); strcat(buf, ".def");
DEFPATH[0] = WorkingDir;
if (! InsertFile(buf, DEFPATH, &(FileName))) { if (! InsertFile(buf, DEFPATH, &(FileName))) {
error("could not find a DEFINITION MODULE for \"%s\"", name); error("could not find a DEFINITION MODULE for \"%s\"", name);
return 0; return 0;
} }
WorkingDir = getwdir(FileName);
LineNumber = 1; LineNumber = 1;
DO_DEBUG(options['F'], debug("File %s : %ld characters", FileName, sys_filesize(FileName))); DO_DEBUG(options['F'], debug("File %s : %ld characters", FileName, sys_filesize(FileName)));
return 1; return 1;
@ -64,20 +99,26 @@ GetDefinitionModule(id, incr)
if (!df) { if (!df) {
/* Read definition module. Make an exception for SYSTEM. /* Read definition module. Make an exception for SYSTEM.
*/ */
DefId = id;
if (!strcmp(id->id_text, "SYSTEM")) { if (!strcmp(id->id_text, "SYSTEM")) {
do_SYSTEM(); do_SYSTEM();
df = lookup(id, GlobalScope, 1);
} }
else { else {
extern int ForeignFlag;
ForeignFlag = 0;
open_scope(CLOSEDSCOPE); open_scope(CLOSEDSCOPE);
if (!is_anon_idf(id) && GetFile(id->id_text)) { if (!is_anon_idf(id) && GetFile(id->id_text)) {
DefId = id;
DefModule(); DefModule();
if (level == 1) { df = lookup(id, GlobalScope, 1);
if (level == 1 &&
(!df || !(df->df_flags & D_FOREIGN))) {
/* The module is directly imported by /* The module is directly imported by
the currently defined module, so we the currently defined module, and
have to remember its name because is not foreign, so we have to
we have to call its initialization remember its name because we have
routine to call its initialization routine
*/ */
static struct node *nd_end; static struct node *nd_end;
register struct node *n; register struct node *n;
@ -91,10 +132,13 @@ GetDefinitionModule(id, incr)
nd_end = n; nd_end = n;
} }
} }
else {
df = lookup(id, GlobalScope, 1);
CurrentScope->sc_name = id->id_text;
}
vis = CurrVis; vis = CurrVis;
close_scope(SC_CHKFORW); close_scope(SC_CHKFORW);
} }
df = lookup(id, GlobalScope, 1);
if (! df) { if (! df) {
df = MkDef(id, GlobalScope, D_ERROR); df = MkDef(id, GlobalScope, D_ERROR);
df->df_type = error_type; df->df_type = error_type;

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* D E S I G N A T O R E V A L U A T I O N */ /* D E S I G N A T O R E V A L U A T I O N */
/* $Header$ */
/* Code generation for designators. /* Code generation for designators.
This file contains some routines that generate code common to address This file contains some routines that generate code common to address
as well as value computations, and leave a description in a "desig" as well as value computations, and leave a description in a "desig"
@ -43,11 +52,11 @@ properly(ds, size, al)
arith wordmodsz = word_size % size; /* 0 if dividor of wordsize */ arith wordmodsz = word_size % size; /* 0 if dividor of wordsize */
if (szmodword && wordmodsz) return 0; if (szmodword && wordmodsz) return 0;
if (al >= word_size) return 1; if (al >= word_align) return 1;
if (szmodword && al >= szmodword) return 1; if (szmodword && al >= szmodword) return 1;
return ds->dsg_kind == DSG_FIXED && return ds->dsg_kind == DSG_FIXED &&
((! szmodword && ds->dsg_offset % word_size == 0) || ((! szmodword && ds->dsg_offset % word_align == 0) ||
(! wordmodsz && ds->dsg_offset % size == 0)); (! wordmodsz && ds->dsg_offset % size == 0));
} }

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* D E S I G N A T O R D E S C R I P T I O N S */ /* D E S I G N A T O R D E S C R I P T I O N S */
/* $Header$ */
/* Generating code for designators is not particularly easy, especially if /* Generating code for designators is not particularly easy, especially if
you don't know wether you want the address or the value. you don't know wether you want the address or the value.
The next structure is used to generate code for designators. The next structure is used to generate code for designators.

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* H I G H L E V E L S Y M B O L E N T R Y */ /* H I G H L E V E L S Y M B O L E N T R Y */
/* $Header$ */
#include "debug.h" #include "debug.h"
#include <alloc.h> #include <alloc.h>
@ -94,12 +103,10 @@ EnterVarList(Idlist, type, local)
*/ */
register struct def *df; register struct def *df;
register struct node *idlist = Idlist; register struct node *idlist = Idlist;
register struct scopelist *sc; register struct scopelist *sc = CurrVis;
char buf[256]; char buf[256];
extern char *sprint(); extern char *sprint();
sc = CurrVis;
if (local) { if (local) {
/* Find the closest enclosing open scope. This /* Find the closest enclosing open scope. This
is the procedure that we are dealing with is the procedure that we are dealing with
@ -136,9 +143,15 @@ EnterVarList(Idlist, type, local)
else { else {
/* Global name, possibly external /* Global name, possibly external
*/ */
sprint(buf,"%s_%s", sc->sc_scope->sc_name, if (sc->sc_scope->sc_definedby->df_flags & D_FOREIGN) {
df->var_name = df->df_idf->id_text;
}
else {
sprint(buf,"%s_%s", sc->sc_scope->sc_name,
df->df_idf->id_text); df->df_idf->id_text);
df->var_name = Salloc(buf, (unsigned)(strlen(buf)+1)); df->var_name = Salloc(buf,
(unsigned)(strlen(buf)+1));
}
df->df_flags |= D_NOREG; df->df_flags |= D_NOREG;
if (DefinitionModule) { if (DefinitionModule) {

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* E R R O R A N D D I A G N O S T I C R O U T I N E S */ /* E R R O R A N D D I A G N O S T I C R O U T I N E S */
/* $Header$ */
/* This file contains the (non-portable) error-message and diagnostic /* This file contains the (non-portable) error-message and diagnostic
giving functions. Be aware that they are called with a variable giving functions. Be aware that they are called with a variable
number of arguments! number of arguments!

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* E X P R E S S I O N S */ /* E X P R E S S I O N S */
/* $Header$ */
{ {
#include "debug.h" #include "debug.h"

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* F I L E D E S C R I P T O R S T R U C T U R E */ /* F I L E D E S C R I P T O R S T R U C T U R E */
/* $Header$ */
struct f_info { struct f_info {
unsigned short f_lineno; unsigned short f_lineno;
char *f_filename; char *f_filename;

View file

@ -1,4 +1,13 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* I N S T A N T I A T I O N O F I D F P A C K A G E */ /* I N S T A N T I A T I O N O F I D F P A C K A G E */
/* $Header$ */
#include "idf.h" #include "idf.h"
#include <idf_pkg.body> #include <idf_pkg.body>

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* U S E R D E C L A R E D P A R T O F I D F */ /* U S E R D E C L A R E D P A R T O F I D F */
/* $Header$ */
struct id_u { struct id_u {
int id_res; int id_res;
struct def *id_df; struct def *id_df;

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* I N S T A N T I A T I O N O F I N P U T P A C K A G E */ /* I N S T A N T I A T I O N O F I N P U T P A C K A G E */
/* $Header$ */
#include "f_info.h" #include "f_info.h"
struct f_info file_info; struct f_info file_info;
#include "input.h" #include "input.h"

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* I N S T A N T I A T I O N O F I N P U T M O D U L E */ /* I N S T A N T I A T I O N O F I N P U T M O D U L E */
/* $Header$ */
#include "inputtype.h" #include "inputtype.h"
#define INP_NPUSHBACK 2 #define INP_NPUSHBACK 2

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* L O O K U P R O U T I N E S */ /* L O O K U P R O U T I N E S */
/* $Header$ */
#include "debug.h" #include "debug.h"
#include <em_arith.h> #include <em_arith.h>

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* M A I N P R O G R A M */ /* M A I N P R O G R A M */
/* $Header$ */
#include "debug.h" #include "debug.h"
#include "ndir.h" #include "ndir.h"
@ -19,6 +28,7 @@
#include "tokenname.h" #include "tokenname.h"
#include "node.h" #include "node.h"
#include "warning.h" #include "warning.h"
#include "SYSTEM.h"
int state; /* either IMPLEMENTATION or PROGRAM */ int state; /* either IMPLEMENTATION or PROGRAM */
char options[128]; char options[128];
@ -67,8 +77,6 @@ Compile(src, dst)
} }
LineNumber = 1; LineNumber = 1;
FileName = src; FileName = src;
DEFPATH[0] = ".";
DEFPATH[NDIRS] = 0;
init_idf(); init_idf();
InitCst(); InitCst();
reserve(tkidf); reserve(tkidf);
@ -88,6 +96,7 @@ Compile(src, dst)
if (! C_open(dst)) fatal("could not open output file"); if (! C_open(dst)) fatal("could not open output file");
C_magic(); C_magic();
C_ms_emx(word_size, pointer_size); C_ms_emx(word_size, pointer_size);
CheckForLineDirective();
CompUnit(); CompUnit();
C_ms_src((arith) (LineNumber - 1), FileName); C_ms_src((arith) (LineNumber - 1), FileName);
if (!err_occurred) { if (!err_occurred) {
@ -186,26 +195,19 @@ AddStandards()
df->enm_next = 0; df->enm_next = 0;
} }
/* How do you like that! Modula-2 in a C-program.
*/
char SYSTEM[] = "\
DEFINITION MODULE SYSTEM;\n\
TYPE PROCESS = ADDRESS;\n\
PROCEDURE NEWPROCESS(P:PROC; A:ADDRESS; n:CARDINAL; VAR p1:ADDRESS);\n\
PROCEDURE TRANSFER(VAR p1,p2:ADDRESS);\n\
END SYSTEM.\n";
do_SYSTEM() do_SYSTEM()
{ {
/* Simulate the reading of the SYSTEM definition module /* Simulate the reading of the SYSTEM definition module
*/ */
static char systemtext[] = SYSTEMTEXT;
open_scope(CLOSEDSCOPE); open_scope(CLOSEDSCOPE);
Enter("WORD", D_TYPE, word_type, 0); Enter("WORD", D_TYPE, word_type, 0);
Enter("BYTE", D_TYPE, byte_type, 0); Enter("BYTE", D_TYPE, byte_type, 0);
Enter("ADDRESS", D_TYPE, address_type, 0); Enter("ADDRESS", D_TYPE, address_type, 0);
Enter("ADR", D_PROCEDURE, std_type, S_ADR); Enter("ADR", D_PROCEDURE, std_type, S_ADR);
Enter("TSIZE", D_PROCEDURE, std_type, S_TSIZE); Enter("TSIZE", D_PROCEDURE, std_type, S_TSIZE);
if (!InsertText(SYSTEM, sizeof(SYSTEM) - 1)) { if (!InsertText(systemtext, sizeof(systemtext) - 1)) {
fatal("could not insert text"); fatal("could not insert text");
} }
DefModule(); DefModule();

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* S O M E G L O B A L V A R I A B L E S */ /* S O M E G L O B A L V A R I A B L E S */
/* $Header$ */
extern char options[]; /* indicating which options were given */ extern char options[]; /* indicating which options were given */
extern int DefinitionModule; extern int DefinitionModule;

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* M I S C E L L A N E O U S R O U T I N E S */ /* M I S C E L L A N E O U S R O U T I N E S */
/* $Header$ */
#include <alloc.h> #include <alloc.h>
#include <em_arith.h> #include <em_arith.h>
#include <em_label.h> #include <em_label.h>

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* M I S C E L L A N E O U S */ /* M I S C E L L A N E O U S */
/* $Header$ */
#define is_anon_idf(x) ((x)->id_text[0] == '#') #define is_anon_idf(x) ((x)->id_text[0] == '#')
#define id_not_declared(x) (not_declared("identifier", (x), "")) #define id_not_declared(x) (not_declared("identifier", (x), ""))

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* N O D E O F A N A B S T R A C T P A R S E T R E E */ /* N O D E O F A N A B S T R A C T P A R S E T R E E */
/* $Header$ */
struct node { struct node {
struct node *next; struct node *next;
#define nd_left next #define nd_left next

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* N O D E O F A N A B S T R A C T P A R S E T R E E */ /* N O D E O F A N A B S T R A C T P A R S E T R E E */
/* $Header$ */
#include "debug.h" #include "debug.h"
#include <em_label.h> #include <em_label.h>

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* U S E R O P T I O N - H A N D L I N G */ /* U S E R O P T I O N - H A N D L I N G */
/* $Header$ */
#include "idfsize.h" #include "idfsize.h"
#include "ndir.h" #include "ndir.h"
@ -18,7 +27,7 @@ recognize some keywords!
#endif #endif
extern int idfsize; extern int idfsize;
static int ndirs; static int ndirs = 1;
int warning_classes; int warning_classes;
DoOption(text) DoOption(text)
@ -26,17 +35,16 @@ DoOption(text)
{ {
switch(*text++) { switch(*text++) {
default: case '-':
options[text[-1]]++; /* flags, debug options etc. */ options[*text]++; /* debug options etc. */
break; break;
/* recognized flags:
-L: don't generate fil/lin
-p: generate procentry/procexit
-w: no warnings
-n: no register messages
and many more if DEBUG
*/
case 'L': /* no fil/lin */
case 'p': /* call procentry/procexit */
case 'n': /* no register messages */
case 'x': /* every name global */
options[text[-1]]++;
break;
case 'w': case 'w':
if (*text) { if (*text) {

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* O V E R A L L S T R U C T U R E */ /* O V E R A L L S T R U C T U R E */
/* $Header$ */
{ {
#include "debug.h" #include "debug.h"
@ -118,14 +127,17 @@ DefinitionModule
struct node *exportlist; struct node *exportlist;
int dummy; int dummy;
extern struct idf *DefId; extern struct idf *DefId;
extern int ForeignFlag;
} : } :
DEFINITION DEFINITION
MODULE IDENT { df = define(dot.TOK_IDF, GlobalScope, D_MODULE); MODULE IDENT { df = define(dot.TOK_IDF, GlobalScope, D_MODULE);
df->df_flags |= D_BUSY; df->df_flags |= D_BUSY;
if (ForeignFlag) df->df_flags |= D_FOREIGN;
if (!Defined) Defined = df; if (!Defined) Defined = df;
CurrentScope->sc_definedby = df;
if (df->df_idf != DefId) { if (df->df_idf != DefId) {
error("DEFINITION MODULE name is not \"%s\"", error("DEFINITION MODULE name is \"%s\", not \"%s\"",
DefId->id_text); df->df_idf->id_text, DefId->id_text);
} }
CurrentScope->sc_name = df->df_idf->id_text; CurrentScope->sc_name = df->df_idf->id_text;
df->mod_vis = CurrVis; df->mod_vis = CurrVis;
@ -207,8 +219,8 @@ ProgramModule
open_scope(CLOSEDSCOPE); open_scope(CLOSEDSCOPE);
df->mod_vis = CurrVis; df->mod_vis = CurrVis;
CurrentScope->sc_name = "_M2M"; CurrentScope->sc_name = "_M2M";
CurrentScope->sc_definedby = df;
} }
CurrentScope->sc_definedby = df;
} }
priority(df) priority(df)
';' import(0)* ';' import(0)*

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* S C O P E M E C H A N I S M */ /* S C O P E M E C H A N I S M */
/* $Header$ */
#include "debug.h" #include "debug.h"
#include <assert.h> #include <assert.h>
@ -44,6 +53,17 @@ open_scope(scopetype)
CurrVis = ls; CurrVis = ls;
} }
struct scope *
open_and_close_scope(scopetype)
{
struct scope *sc;
open_scope(scopetype);
sc = CurrentScope;
close_scope();
return sc;
}
InitScope() InitScope()
{ {
register struct scope *sc = new_scope(); register struct scope *sc = new_scope();
@ -60,25 +80,6 @@ InitScope()
CurrVis = ls; CurrVis = ls;
} }
Forward(tk, ptp)
struct node *tk;
struct type *ptp;
{
/* Enter a forward reference into a list belonging to the
current scope. This is used for POINTER declarations, which
may have forward references that must howewer be declared in the
same scope.
*/
register struct def *df = define(tk->nd_IDF, CurrentScope, D_FORWTYPE);
if (df->df_kind == D_TYPE) {
ptp->next = df->df_type;
return;
}
df->df_forw_type = ptp;
df->df_forw_node = tk;
}
STATIC STATIC
chk_proc(df) chk_proc(df)
register struct def *df; register struct def *df;

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* S C O P E M E C H A N I S M */ /* S C O P E M E C H A N I S M */
/* $Header$ */
#define OPENSCOPE 0 /* Indicating an open scope */ #define OPENSCOPE 0 /* Indicating an open scope */
#define CLOSEDSCOPE 1 /* Indicating a closed scope (module) */ #define CLOSEDSCOPE 1 /* Indicating a closed scope (module) */
@ -40,3 +49,5 @@ extern struct scopelist
#define enclosing(x) ((x)->sc_encl) #define enclosing(x) ((x)->sc_encl)
#define scopeclosed(x) ((x)->sc_scopeclosed) #define scopeclosed(x) ((x)->sc_scopeclosed)
#define nextvisible(x) ((x)->next) /* use with scopelists */ #define nextvisible(x) ((x)->next) /* use with scopelists */
struct scope *open_and_close_scope();

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* S T A N D A R D P R O C E D U R E S A N D F U N C T I O N S */ /* S T A N D A R D P R O C E D U R E S A N D F U N C T I O N S */
/* $Header$ */
#define S_ABS 1 #define S_ABS 1
#define S_CAP 2 #define S_CAP 2
#define S_CHR 3 #define S_CHR 3

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* S T A T E M E N T S */ /* S T A T E M E N T S */
/* $Header$ */
{ {
#include <assert.h> #include <assert.h>
#include <em_arith.h> #include <em_arith.h>
@ -147,7 +156,13 @@ CaseStatement(struct node **pnd;)
case(&(nd->nd_right), &tp) case(&(nd->nd_right), &tp)
{ nd = nd->nd_right; } { nd = nd->nd_right; }
]* ]*
[ ELSE StatementSequence(&(nd->nd_right)) ]? [ ELSE StatementSequence(&(nd->nd_right))
{ if (! nd->nd_right) {
nd->nd_right = MkLeaf(Stat, &dot);
nd->nd_right->nd_symb = ';';
}
}
]?
END END
; ;

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* T E M P O R A R Y V A R I A B L E S */ /* T E M P O R A R Y V A R I A B L E S */
/* $Header$ */
/* Code for the allocation and de-allocation of temporary variables, /* Code for the allocation and de-allocation of temporary variables,
allowing re-use. allowing re-use.
The routines use "ProcScope" instead of "CurrentScope", because The routines use "ProcScope" instead of "CurrentScope", because

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* T O K E N D E F I N I T I O N S */ /* T O K E N D E F I N I T I O N S */
/* $Header$ */
#include "tokenname.h" #include "tokenname.h"
#include "Lpars.h" #include "Lpars.h"
#include "idf.h" #include "idf.h"

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* T O K E N N A M E S T R U C T U R E */ /* T O K E N N A M E S T R U C T U R E */
/* $Header$ */
struct tokenname { /* Used for defining the name of a struct tokenname { /* Used for defining the name of a
token as identified by its symbol token as identified by its symbol
*/ */

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* T Y P E D E S C R I P T O R S T R U C T U R E */ /* T Y P E D E S C R I P T O R S T R U C T U R E */
/* $Header$ */
struct paramlist { /* structure for parameterlist of a PROCEDURE */ struct paramlist { /* structure for parameterlist of a PROCEDURE */
struct paramlist *next; struct paramlist *next;
struct def *par_def; /* "df" of parameter */ struct def *par_def; /* "df" of parameter */
@ -131,6 +140,8 @@ struct type
*set_type(), *set_type(),
*subr_type(), *subr_type(),
*proc_type(), *proc_type(),
*enum_type(),
*qualified_type(),
*RemoveEqual(); /* All from type.c */ *RemoveEqual(); /* All from type.c */
#define NULLTYPE ((struct type *) 0) #define NULLTYPE ((struct type *) 0)

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* T Y P E D E F I N I T I O N M E C H A N I S M */ /* T Y P E D E F I N I T I O N M E C H A N I S M */
/* $Header$ */
#include "target_sizes.h" #include "target_sizes.h"
#include "debug.h" #include "debug.h"
#include "maxset.h" #include "maxset.h"
@ -18,6 +27,7 @@
#include "const.h" #include "const.h"
#include "scope.h" #include "scope.h"
#include "walk.h" #include "walk.h"
#include "chk_expr.h"
int int
word_align = AL_WORD, word_align = AL_WORD,
@ -100,9 +110,10 @@ align(pos, al)
arith pos; arith pos;
int al; int al;
{ {
arith i; arith i = pos % al;
return pos + ((i = pos % al) ? al - i : 0); if (i) return pos + al - i;
return pos;
} }
struct type * struct type *
@ -113,8 +124,10 @@ standard_type(fund, align, size)
{ {
register struct type *tp = new_type(); register struct type *tp = new_type();
if (align == 0) align = 1;
tp->tp_fund = fund; tp->tp_fund = fund;
tp->tp_align = align ? align : 1; tp->tp_align = align;
tp->tp_size = size; tp->tp_size = size;
return tp; return tp;
@ -192,6 +205,59 @@ InitTypes()
error_type = standard_type(T_CHAR, 1, (arith) 1); error_type = standard_type(T_CHAR, 1, (arith) 1);
} }
STATIC
u_small(tp, n)
register struct type *tp;
arith n;
{
if (ufit(n, 1)) {
tp->tp_size = 1;
tp->tp_align = 1;
}
else if (ufit(n, short_size)) {
tp->tp_size = short_size;
tp->tp_align = short_align;
}
}
struct type *
enum_type(EnumList)
struct node *EnumList;
{
register struct type *tp =
standard_type(T_ENUMERATION, int_align, int_size);
EnterEnumList(EnumList, tp);
u_small(tp, (arith) (tp->enm_ncst-1));
return tp;
}
struct type *
qualified_type(nd)
struct node *nd;
{
struct type *tp = error_type;
if (ChkDesignator(nd)) {
if (nd->nd_class != Def) node_error(nd, "type expected");
else {
register struct def *df = nd->nd_def;
if (df->df_kind&(D_ISTYPE|D_FORWARD|D_ERROR)) {
if (! df->df_type) {
node_error(nd,"type \"%s\" not (yet) declared", df->df_idf->id_text);
}
else tp = df->df_type;
}
else {
node_error(nd,"identifier \"%s\" is not a type", df->df_idf->id_text);
}
}
}
FreeNode(nd);
return tp;
}
chk_basesubrange(tp, base) chk_basesubrange(tp, base)
register struct type *tp, *base; register struct type *tp, *base;
{ {
@ -275,14 +341,7 @@ subr_type(lb, ub)
res->tp_size = tp->tp_size; res->tp_size = tp->tp_size;
res->tp_align = tp->tp_align; res->tp_align = tp->tp_align;
if (tp == card_type) { if (tp == card_type) {
if (ufit(res->sub_ub, 1)) { u_small(res, res->sub_ub);
res->tp_size = 1;
res->tp_align = 1;
}
else if (ufit(res->sub_ub, 2)) {
res->tp_size = short_size;
res->tp_align = short_align;
}
} }
else if (tp == int_type) { else if (tp == int_type) {
if (fit(res->sub_lb, 1) && fit(res->sub_ub, 1)) { if (fit(res->sub_lb, 1) && fit(res->sub_ub, 1)) {
@ -505,6 +564,54 @@ RemoveEqual(tpx)
return tpx; return tpx;
} }
int
type_or_forward(ptp)
struct type **ptp;
{
struct node *nd = 0;
*ptp = construct_type(T_POINTER, NULLTYPE);
if (lookup(dot.TOK_IDF, CurrentScope, 1)
/* Either a Module or a Type, but in both cases defined
in this scope, so this is the correct identification
*/
||
( nd = new_node(),
nd->nd_token = dot,
lookfor(nd, CurrVis, 0)->df_kind == D_MODULE
)
/* A Modulename in one of the enclosing scopes.
It is not clear from the language definition that
it is correct to handle these like this, but
existing compilers do it like this, and the
alternative is difficult with a lookahead of only
one token.
???
*/
) {
if (nd) free_node(nd);
return 1;
}
/* Enter a forward reference into a list belonging to the
current scope. This is used for POINTER declarations, which
may have forward references that must howewer be declared in the
same scope.
*/
{
register struct def *df =
define(nd->nd_IDF, CurrentScope, D_FORWTYPE);
if (df->df_kind == D_TYPE) {
(*ptp)->next = df->df_type;
}
else {
df->df_forw_type = *ptp;
df->df_forw_node = nd;
}
}
return 0;
}
int int
gcd(m, n) gcd(m, n)
register int m, n; register int m, n;

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* T Y P E E Q U I V A L E N C E */ /* T Y P E E Q U I V A L E N C E */
/* $Header$ */
/* Routines for testing type equivalence, type compatibility, and /* Routines for testing type equivalence, type compatibility, and
assignment compatibility assignment compatibility
*/ */

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* P A R S E T R E E W A L K E R */ /* P A R S E T R E E W A L K E R */
/* $Header$ */
/* Routines to walk through parts of the parse tree, and generate /* Routines to walk through parts of the parse tree, and generate
code for these parts. code for these parts.
*/ */
@ -42,6 +51,9 @@ static struct node *priority;
STATIC STATIC
DoPriority() DoPriority()
{ {
/* For the time being (???), handle priorities by calls to
the runtime system
*/
if (priority) { if (priority) {
C_loc(priority->nd_INT); C_loc(priority->nd_INT);
C_cal("_stackprio"); C_cal("_stackprio");
@ -111,10 +123,11 @@ WalkModule(module)
register struct node *nd = Modules; register struct node *nd = Modules;
if (state == IMPLEMENTATION) { if (state == IMPLEMENTATION) {
label l1 = ++data_label; /* We don't actually prevent recursive calls,
/* we don't actually prevent recursive calls,
but do nothing if called recursively but do nothing if called recursively
*/ */
label l1 = ++data_label;
C_df_dlb(l1); C_df_dlb(l1);
C_bss_cst(word_size, (arith) 0, 1); C_bss_cst(word_size, (arith) 0, 1);
/* if this one is set to non-zero, the initialization /* if this one is set to non-zero, the initialization
@ -422,6 +435,9 @@ WalkStat(nd, exit_label)
if (! options['L']) C_lin((arith) nd->nd_lineno); if (! options['L']) C_lin((arith) nd->nd_lineno);
switch(nd->nd_symb) { switch(nd->nd_symb) {
case ';':
break;
case BECOMES: case BECOMES:
DoAssign(nd, left, right); DoAssign(nd, left, right);
break; break;

View file

@ -1,5 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* P A R S E T R E E W A L K E R */ /* P A R S E T R E E W A L K E R */
/* $Header$ */
/* Definition of WalkNode macro /* Definition of WalkNode macro
*/ */

View file

@ -1,3 +1,14 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Ceriel J.H. Jacobs
*/
/* W A R N I N G C L A S S E S */
/* $Header$ */
/* Warning classes, at the moment three of them: /* Warning classes, at the moment three of them:
Strict (R) Strict (R)
Ordinary (W) Ordinary (W)