2020-05-25 22:48:33 +02:00
|
|
|
(*
|
2019-03-11 09:59:55 +01:00
|
|
|
BSD 2-Clause License
|
|
|
|
|
2022-06-21 22:32:43 +02:00
|
|
|
Copyright (c) 2018-2022, Anton Krotov
|
2019-03-11 09:59:55 +01:00
|
|
|
All rights reserved.
|
|
|
|
*)
|
|
|
|
|
|
|
|
MODULE PARS;
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IMPORT PROG, SCAN, ARITH, STRINGS, ERRORS, LISTS, IL, CONSOLE, PATHS, UTILS,
|
2021-06-15 19:33:16 +02:00
|
|
|
C := COLLECTIONS, TARGETS, THUMB, MSP430;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
CONST
|
|
|
|
|
|
|
|
eCONST* = 1; eTYPE* = 2; eVAR* = 3; eEXPR* = 4;
|
|
|
|
eVREC* = 5; ePROC* = 6; eVPAR* = 7; ePARAM* = 8;
|
|
|
|
eSTPROC* = 9; eSTFUNC* = 10; eSYSFUNC* = 11; eSYSPROC* = 12;
|
|
|
|
eIMP* = 13;
|
|
|
|
|
|
|
|
|
|
|
|
TYPE
|
|
|
|
|
|
|
|
PATH* = PATHS.PATH;
|
|
|
|
|
|
|
|
PARSER* = POINTER TO rPARSER;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
POSITION* = RECORD (SCAN.POSITION)
|
|
|
|
|
|
|
|
parser*: PARSER
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
EXPR* = RECORD
|
|
|
|
|
|
|
|
obj*: INTEGER;
|
2020-10-13 09:58:51 +02:00
|
|
|
_type*: PROG._TYPE;
|
2019-03-11 09:59:55 +01:00
|
|
|
value*: ARITH.VALUE;
|
|
|
|
stproc*: INTEGER;
|
|
|
|
readOnly*: BOOLEAN;
|
|
|
|
ident*: PROG.IDENT
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
STATPROC = PROCEDURE (parser: PARSER);
|
|
|
|
EXPRPROC = PROCEDURE (parser: PARSER; VAR e: EXPR);
|
2020-10-13 09:58:51 +02:00
|
|
|
RETPROC = PROCEDURE (parser: PARSER; e: EXPR; t: PROG._TYPE; pos: POSITION): BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
rPARSER = RECORD (C.ITEM)
|
|
|
|
|
|
|
|
fname*: PATH;
|
|
|
|
path: PATH;
|
|
|
|
lib_path: PATH;
|
|
|
|
ext: PATH;
|
|
|
|
modname: PATH;
|
|
|
|
scanner: SCAN.SCANNER;
|
|
|
|
lex*: SCAN.LEX;
|
|
|
|
sym*: INTEGER;
|
|
|
|
unit*: PROG.UNIT;
|
|
|
|
constexp*: BOOLEAN;
|
|
|
|
main*: BOOLEAN;
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
open*: PROCEDURE (parser: PARSER; modname, FileExt: ARRAY OF CHAR): BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
parse*: PROCEDURE (parser: PARSER);
|
|
|
|
StatSeq*: STATPROC;
|
|
|
|
expression*: EXPRPROC;
|
|
|
|
designator*: EXPRPROC;
|
|
|
|
chkreturn: RETPROC;
|
|
|
|
|
|
|
|
create*: PROCEDURE (path, lib_path: PATH; StatSeq: STATPROC; expression, designator: EXPRPROC; chkreturn: RETPROC): PARSER
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
|
|
|
|
VAR
|
|
|
|
|
|
|
|
parsers: C.COLLECTION;
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
lines*, modules: INTEGER;
|
2019-10-06 19:55:12 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PROCEDURE destroy* (VAR parser: PARSER);
|
|
|
|
BEGIN
|
|
|
|
IF parser.scanner # NIL THEN
|
|
|
|
SCAN.close(parser.scanner)
|
|
|
|
END;
|
|
|
|
|
|
|
|
C.push(parsers, parser);
|
|
|
|
parser := NIL
|
|
|
|
END destroy;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE getpos (parser: PARSER; VAR pos: POSITION);
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
2019-09-26 22:23:06 +02:00
|
|
|
pos.line := parser.lex.pos.line;
|
|
|
|
pos.col := parser.lex.pos.col;
|
|
|
|
pos.parser := parser
|
|
|
|
END getpos;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE error* (pos: POSITION; errno: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
ERRORS.ErrorMsg(pos.parser.fname, pos.line, pos.col, errno)
|
2019-03-11 09:59:55 +01:00
|
|
|
END error;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE check* (condition: BOOLEAN; pos: POSITION; errno: INTEGER);
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
IF ~condition THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
error(pos, errno)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END check;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE check1* (condition: BOOLEAN; parser: PARSER; errno: INTEGER);
|
2019-09-26 22:23:06 +02:00
|
|
|
VAR
|
|
|
|
pos: POSITION;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
IF ~condition THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
getpos(parser, pos);
|
|
|
|
error(pos, errno)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END check1;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE Next* (parser: PARSER);
|
|
|
|
VAR
|
|
|
|
errno: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
SCAN.Next(parser.scanner, parser.lex);
|
|
|
|
errno := parser.lex.error;
|
2020-10-13 09:58:51 +02:00
|
|
|
IF errno = 0 THEN
|
|
|
|
IF (TARGETS.RealSize = 0) & (parser.lex.sym = SCAN.lxFLOAT) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
errno := -SCAN.lxERROR13
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF (TARGETS.BitDepth = 16) & (parser.lex.sym = SCAN.lxCHAR) & (parser.lex.value.typ = ARITH.tWCHAR) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
errno := -SCAN.lxERROR10
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
IF errno # 0 THEN
|
|
|
|
check1(FALSE, parser, errno)
|
|
|
|
END;
|
|
|
|
parser.sym := parser.lex.sym
|
|
|
|
END Next;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE NextPos (parser: PARSER; VAR pos: POSITION);
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
Next(parser);
|
2019-09-26 22:23:06 +02:00
|
|
|
getpos(parser, pos)
|
2019-03-11 09:59:55 +01:00
|
|
|
END NextPos;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE checklex* (parser: PARSER; sym: INTEGER);
|
|
|
|
VAR
|
|
|
|
err: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
|
|
|
|
IF parser.sym # sym THEN
|
|
|
|
|
|
|
|
CASE sym OF
|
|
|
|
|SCAN.lxCOMMA: err := 65
|
|
|
|
|SCAN.lxRROUND: err := 33
|
|
|
|
|SCAN.lxPOINT: err := 26
|
|
|
|
|SCAN.lxIDENT: err := 22
|
|
|
|
|SCAN.lxRSQUARE: err := 71
|
|
|
|
|SCAN.lxRCURLY: err := 35
|
|
|
|
|SCAN.lxUNDEF: err := 34
|
|
|
|
|SCAN.lxTHEN: err := 88
|
|
|
|
|SCAN.lxEND: err := 27
|
|
|
|
|SCAN.lxDO: err := 89
|
|
|
|
|SCAN.lxUNTIL: err := 90
|
|
|
|
|SCAN.lxCOLON: err := 53
|
|
|
|
|SCAN.lxOF: err := 67
|
|
|
|
|SCAN.lxASSIGN: err := 96
|
|
|
|
|SCAN.lxTO: err := 57
|
|
|
|
|SCAN.lxLROUND: err := 64
|
|
|
|
|SCAN.lxEQ: err := 32
|
|
|
|
|SCAN.lxSEMI: err := 24
|
|
|
|
|SCAN.lxRETURN: err := 38
|
|
|
|
|SCAN.lxMODULE: err := 21
|
|
|
|
END;
|
|
|
|
|
|
|
|
check1(FALSE, parser, err)
|
|
|
|
END
|
|
|
|
END checklex;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE ExpectSym* (parser: PARSER; sym: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
Next(parser);
|
|
|
|
checklex(parser, sym)
|
|
|
|
END ExpectSym;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE ImportList (parser: PARSER);
|
|
|
|
VAR
|
2021-06-15 19:33:16 +02:00
|
|
|
fname, path, ext, _name: PATH;
|
2019-09-26 22:23:06 +02:00
|
|
|
name: SCAN.IDENT;
|
|
|
|
parser2: PARSER;
|
|
|
|
pos: POSITION;
|
2021-06-15 19:33:16 +02:00
|
|
|
alias, _in: BOOLEAN;
|
2019-09-26 22:23:06 +02:00
|
|
|
unit: PROG.UNIT;
|
|
|
|
ident: PROG.IDENT;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
alias := FALSE;
|
|
|
|
|
|
|
|
REPEAT
|
|
|
|
|
|
|
|
ExpectSym(parser, SCAN.lxIDENT);
|
|
|
|
name := parser.lex.ident;
|
|
|
|
|
|
|
|
getpos(parser, pos);
|
|
|
|
|
|
|
|
IF ~alias THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
ident := PROG.addIdent(parser.unit, name, PROG.idMODULE);
|
|
|
|
check(ident # NIL, pos, 30)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
Next(parser);
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
path := parser.path;
|
|
|
|
fname := "";
|
|
|
|
ext := UTILS.FILE_EXT;
|
|
|
|
COPY(name.s, _name);
|
|
|
|
_in := FALSE;
|
|
|
|
|
|
|
|
IF parser.sym = SCAN.lxIN THEN
|
|
|
|
_in := TRUE;
|
|
|
|
Next(parser);
|
|
|
|
IF parser.sym = SCAN.lxSTRING THEN
|
|
|
|
STRINGS.trim(parser.lex.string.s, fname)
|
|
|
|
ELSIF parser.sym = SCAN.lxCHAR THEN
|
|
|
|
fname[0] := CHR(ARITH.Int(parser.lex.value));
|
|
|
|
fname[1] := 0X
|
|
|
|
ELSE
|
|
|
|
check1(FALSE, parser, 117)
|
|
|
|
END;
|
|
|
|
STRINGS.replace(fname, "/", UTILS.slash);
|
|
|
|
STRINGS.replace(fname, "\", UTILS.slash);
|
|
|
|
PATHS.DelSlashes(fname);
|
|
|
|
PATHS.split(fname, path, _name, ext);
|
|
|
|
IF PATHS.isRelative(path) THEN
|
|
|
|
PATHS.RelPath(parser.path, path, fname);
|
|
|
|
STRINGS.append(fname, _name);
|
|
|
|
STRINGS.append(fname, ext);
|
|
|
|
PATHS.split(fname, path, _name, ext)
|
|
|
|
END;
|
|
|
|
Next(parser)
|
|
|
|
END;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
IF (parser.sym = SCAN.lxCOMMA) OR (parser.sym = SCAN.lxSEMI) THEN
|
|
|
|
alias := FALSE;
|
2021-06-15 19:33:16 +02:00
|
|
|
IF (fname = "") & ((_name = "SYSTEM") OR PROG.LowerCase & (_name = "system")) THEN
|
|
|
|
unit := PROG.program.sysunit
|
|
|
|
ELSE
|
|
|
|
IF fname # "" THEN
|
|
|
|
unit := PROG.getUnit(fname)
|
|
|
|
ELSE
|
|
|
|
fname := path;
|
|
|
|
STRINGS.append(fname, _name);
|
|
|
|
STRINGS.append(fname, UTILS.FILE_EXT);
|
|
|
|
unit := PROG.getUnit(fname);
|
|
|
|
IF unit = NIL THEN
|
|
|
|
fname := parser.lib_path;
|
|
|
|
STRINGS.append(fname, _name);
|
|
|
|
STRINGS.append(fname, UTILS.FILE_EXT);
|
|
|
|
unit := PROG.getUnit(fname)
|
|
|
|
END
|
|
|
|
END
|
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF unit # NIL THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
check(unit.closed, pos, 31)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2021-06-15 19:33:16 +02:00
|
|
|
parser2 := parser.create(path, parser.lib_path,
|
2019-03-11 09:59:55 +01:00
|
|
|
parser.StatSeq, parser.expression, parser.designator, parser.chkreturn);
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
IF ~parser2.open(parser2, _name, ext) THEN
|
|
|
|
IF (path # parser.lib_path) & ~_in THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
destroy(parser2);
|
|
|
|
parser2 := parser.create(parser.lib_path, parser.lib_path,
|
|
|
|
parser.StatSeq, parser.expression, parser.designator, parser.chkreturn);
|
2021-06-15 19:33:16 +02:00
|
|
|
check(parser2.open(parser2, _name, ext), pos, 29)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
error(pos, 29)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
parser2.parse(parser2);
|
|
|
|
unit := parser2.unit;
|
2021-06-15 19:33:16 +02:00
|
|
|
unit.fname := parser2.fname;
|
2019-03-11 09:59:55 +01:00
|
|
|
destroy(parser2)
|
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
IF unit = PROG.program.sysunit THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
parser.unit.sysimport := TRUE
|
|
|
|
END;
|
|
|
|
ident.unit := unit
|
|
|
|
|
|
|
|
ELSIF parser.sym = SCAN.lxASSIGN THEN
|
|
|
|
alias := TRUE
|
|
|
|
|
|
|
|
ELSE
|
|
|
|
check1(FALSE, parser, 28)
|
|
|
|
END
|
|
|
|
|
|
|
|
UNTIL parser.sym = SCAN.lxSEMI;
|
|
|
|
|
|
|
|
Next(parser)
|
|
|
|
|
|
|
|
END ImportList;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE QIdent (parser: PARSER; forward: BOOLEAN): PROG.IDENT;
|
|
|
|
VAR
|
|
|
|
ident: PROG.IDENT;
|
|
|
|
unit: PROG.UNIT;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
ASSERT(parser.sym = SCAN.lxIDENT);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
ident := PROG.getIdent(parser.unit, parser.lex.ident, FALSE);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF ~forward THEN
|
|
|
|
check1(ident # NIL, parser, 48)
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF (ident # NIL) & (ident.typ = PROG.idMODULE) THEN
|
|
|
|
unit := ident.unit;
|
|
|
|
ExpectSym(parser, SCAN.lxPOINT);
|
|
|
|
ExpectSym(parser, SCAN.lxIDENT);
|
2019-09-26 22:23:06 +02:00
|
|
|
ident := PROG.getIdent(unit, parser.lex.ident, FALSE);
|
2019-03-11 09:59:55 +01:00
|
|
|
check1((ident # NIL) & ident.export, parser, 48)
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN ident
|
|
|
|
END QIdent;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE strcmp* (VAR v: ARITH.VALUE; v2: ARITH.VALUE; operator: INTEGER);
|
|
|
|
VAR
|
2021-06-15 19:33:16 +02:00
|
|
|
str: SCAN.TEXTSTR;
|
|
|
|
string1, string2: SCAN.STRING;
|
2019-03-11 09:59:55 +01:00
|
|
|
bool: BOOLEAN;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
|
|
|
|
IF v.typ = ARITH.tCHAR THEN
|
|
|
|
ASSERT(v2.typ = ARITH.tSTRING);
|
|
|
|
ARITH.charToStr(v, str);
|
2021-06-15 19:33:16 +02:00
|
|
|
string1 := SCAN.enterStr(str);
|
|
|
|
string2 := v2.string(SCAN.STRING)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
IF v2.typ = ARITH.tCHAR THEN
|
|
|
|
ASSERT(v.typ = ARITH.tSTRING);
|
|
|
|
ARITH.charToStr(v2, str);
|
2021-06-15 19:33:16 +02:00
|
|
|
string2 := SCAN.enterStr(str);
|
|
|
|
string1 := v.string(SCAN.STRING)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
IF v.typ = v2.typ THEN
|
2021-06-15 19:33:16 +02:00
|
|
|
string1 := v.string(SCAN.STRING);
|
|
|
|
string2 := v2.string(SCAN.STRING)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
CASE operator OF
|
|
|
|
|SCAN.lxEQ: bool := string1.s = string2.s
|
|
|
|
|SCAN.lxNE: bool := string1.s # string2.s
|
|
|
|
|SCAN.lxLT: bool := string1.s < string2.s
|
|
|
|
|SCAN.lxGT: bool := string1.s > string2.s
|
|
|
|
|SCAN.lxLE: bool := string1.s <= string2.s
|
|
|
|
|SCAN.lxGE: bool := string1.s >= string2.s
|
|
|
|
END;
|
|
|
|
|
|
|
|
ARITH.setbool(v, bool)
|
|
|
|
END strcmp;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE ConstExpression* (parser: PARSER; VAR v: ARITH.VALUE);
|
|
|
|
VAR
|
|
|
|
e: EXPR;
|
2019-09-26 22:23:06 +02:00
|
|
|
pos: POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
getpos(parser, pos);
|
|
|
|
parser.constexp := TRUE;
|
|
|
|
parser.expression(parser, e);
|
|
|
|
parser.constexp := FALSE;
|
2019-09-26 22:23:06 +02:00
|
|
|
check(e.obj = eCONST, pos, 62);
|
2019-03-11 09:59:55 +01:00
|
|
|
v := e.value
|
|
|
|
END ConstExpression;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE FieldList (parser: PARSER; rec: PROG._TYPE);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
name: SCAN.IDENT;
|
|
|
|
export: BOOLEAN;
|
|
|
|
pos: POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
ASSERT(parser.sym = SCAN.lxIDENT);
|
|
|
|
|
|
|
|
WHILE parser.sym = SCAN.lxIDENT DO
|
|
|
|
|
|
|
|
getpos(parser, pos);
|
|
|
|
|
|
|
|
name := parser.lex.ident;
|
|
|
|
|
|
|
|
Next(parser);
|
|
|
|
|
|
|
|
export := parser.sym = SCAN.lxMUL;
|
|
|
|
|
|
|
|
IF export THEN
|
|
|
|
check1(parser.unit.scopeLvl = 0, parser, 61);
|
|
|
|
Next(parser)
|
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
check(PROG.addField(rec, name, export), pos, 30);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF parser.sym = SCAN.lxCOMMA THEN
|
|
|
|
ExpectSym(parser, SCAN.lxIDENT)
|
|
|
|
ELSE
|
|
|
|
checklex(parser, SCAN.lxCOLON)
|
|
|
|
END
|
|
|
|
|
|
|
|
END
|
|
|
|
|
|
|
|
END FieldList;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE FormalParameters (parser: PARSER; _type: PROG._TYPE);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
ident: PROG.IDENT;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE FPSection (parser: PARSER; _type: PROG._TYPE);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
ident: PROG.IDENT;
|
|
|
|
exit: BOOLEAN;
|
|
|
|
vPar: BOOLEAN;
|
|
|
|
dim: INTEGER;
|
2020-10-13 09:58:51 +02:00
|
|
|
t0, t1: PROG._TYPE;
|
2022-06-21 22:32:43 +02:00
|
|
|
pos: POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
vPar := parser.sym = SCAN.lxVAR;
|
|
|
|
IF vPar THEN
|
|
|
|
Next(parser)
|
|
|
|
END;
|
|
|
|
|
|
|
|
checklex(parser, SCAN.lxIDENT);
|
|
|
|
exit := FALSE;
|
|
|
|
|
|
|
|
WHILE (parser.sym = SCAN.lxIDENT) & ~exit DO
|
2020-10-13 09:58:51 +02:00
|
|
|
check1(PROG.addParam(_type, parser.lex.ident, vPar), parser, 30);
|
2019-03-11 09:59:55 +01:00
|
|
|
Next(parser);
|
|
|
|
IF parser.sym = SCAN.lxCOMMA THEN
|
|
|
|
ExpectSym(parser, SCAN.lxIDENT)
|
|
|
|
ELSIF parser.sym = SCAN.lxCOLON THEN
|
|
|
|
Next(parser);
|
2022-06-21 22:32:43 +02:00
|
|
|
getpos(parser, pos);
|
2019-03-11 09:59:55 +01:00
|
|
|
dim := 0;
|
|
|
|
WHILE parser.sym = SCAN.lxARRAY DO
|
|
|
|
INC(dim);
|
|
|
|
check1(dim <= PROG.MAXARRDIM, parser, 84);
|
|
|
|
ExpectSym(parser, SCAN.lxOF);
|
|
|
|
Next(parser)
|
|
|
|
END;
|
|
|
|
checklex(parser, SCAN.lxIDENT);
|
|
|
|
ident := QIdent(parser, FALSE);
|
|
|
|
check1(ident.typ = PROG.idTYPE, parser, 68);
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
t0 := ident._type;
|
2019-03-11 09:59:55 +01:00
|
|
|
t1 := t0;
|
|
|
|
|
|
|
|
WHILE dim > 0 DO
|
2020-10-13 09:58:51 +02:00
|
|
|
t1 := PROG.enterType(PROG.tARRAY, -1, 0, parser.unit);
|
2019-03-11 09:59:55 +01:00
|
|
|
t1.base := t0;
|
|
|
|
t0 := t1;
|
|
|
|
DEC(dim)
|
|
|
|
END;
|
2022-06-21 22:32:43 +02:00
|
|
|
IF _type.call IN {PROG.fastcall, PROG._fastcall} THEN
|
|
|
|
check(t1.typ # PROG.tREAL, pos, 126)
|
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
PROG.setParams(_type, t1);
|
2019-03-11 09:59:55 +01:00
|
|
|
Next(parser);
|
|
|
|
exit := TRUE
|
|
|
|
ELSE
|
|
|
|
checklex(parser, SCAN.lxCOLON)
|
|
|
|
END
|
|
|
|
END
|
|
|
|
|
|
|
|
END FPSection;
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF parser.sym = SCAN.lxLROUND THEN
|
|
|
|
|
|
|
|
Next(parser);
|
|
|
|
|
|
|
|
IF (parser.sym = SCAN.lxVAR) OR (parser.sym = SCAN.lxIDENT) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
FPSection(parser, _type);
|
2019-03-11 09:59:55 +01:00
|
|
|
WHILE parser.sym = SCAN.lxSEMI DO
|
|
|
|
Next(parser);
|
2020-10-13 09:58:51 +02:00
|
|
|
FPSection(parser, _type)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
checklex(parser, SCAN.lxRROUND);
|
|
|
|
Next(parser);
|
|
|
|
|
|
|
|
IF parser.sym = SCAN.lxCOLON THEN
|
|
|
|
ExpectSym(parser, SCAN.lxIDENT);
|
|
|
|
ident := QIdent(parser, FALSE);
|
|
|
|
check1(ident.typ = PROG.idTYPE, parser, 68);
|
2020-10-13 09:58:51 +02:00
|
|
|
check1(~(ident._type.typ IN {PROG.tRECORD, PROG.tARRAY}), parser, 69);
|
|
|
|
check1( ~(ODD(_type.call) & (ident._type.typ = PROG.tREAL)), parser, 113);
|
|
|
|
_type.base := ident._type;
|
2019-03-11 09:59:55 +01:00
|
|
|
Next(parser)
|
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
_type.base := NIL
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
END
|
|
|
|
END FormalParameters;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE sysflag (parser: PARSER; proc: BOOLEAN): INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
res, sf: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
2021-06-15 19:33:16 +02:00
|
|
|
checklex(parser, SCAN.lxIDENT);
|
|
|
|
IF parser.lex.ident.s = "stdcall" THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
sf := PROG.sf_stdcall
|
2021-06-15 19:33:16 +02:00
|
|
|
ELSIF parser.lex.ident.s = "cdecl" THEN
|
|
|
|
sf := PROG.sf_cdecl
|
|
|
|
ELSIF parser.lex.ident.s = "ccall" THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
sf := PROG.sf_ccall
|
2021-06-15 19:33:16 +02:00
|
|
|
ELSIF parser.lex.ident.s = "win64" THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
sf := PROG.sf_win64
|
2021-06-15 19:33:16 +02:00
|
|
|
ELSIF parser.lex.ident.s = "systemv" THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
sf := PROG.sf_systemv
|
2021-06-15 19:33:16 +02:00
|
|
|
ELSIF parser.lex.ident.s = "windows" THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
sf := PROG.sf_windows
|
2021-06-15 19:33:16 +02:00
|
|
|
ELSIF parser.lex.ident.s = "linux" THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
sf := PROG.sf_linux
|
2021-06-15 19:33:16 +02:00
|
|
|
ELSIF parser.lex.ident.s = "code" THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
sf := PROG.sf_code
|
2021-06-15 19:33:16 +02:00
|
|
|
ELSIF parser.lex.ident.s = "oberon" THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
sf := PROG.sf_oberon
|
2022-06-21 22:32:43 +02:00
|
|
|
ELSIF parser.lex.ident.s = "fastcall" THEN
|
|
|
|
sf := PROG.sf_fastcall
|
2021-06-15 19:33:16 +02:00
|
|
|
ELSIF parser.lex.ident.s = "noalign" THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
sf := PROG.sf_noalign
|
|
|
|
ELSE
|
|
|
|
check1(FALSE, parser, 124)
|
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
check1(sf IN PROG.program.sysflags, parser, 125);
|
2019-09-26 22:23:06 +02:00
|
|
|
|
|
|
|
IF proc THEN
|
|
|
|
check1(sf IN PROG.proc_flags, parser, 123)
|
|
|
|
ELSE
|
|
|
|
check1(sf IN PROG.rec_flags, parser, 123)
|
|
|
|
END;
|
|
|
|
|
|
|
|
CASE sf OF
|
|
|
|
|PROG.sf_stdcall:
|
|
|
|
res := PROG.stdcall
|
2021-06-15 19:33:16 +02:00
|
|
|
|PROG.sf_cdecl:
|
|
|
|
res := PROG.cdecl
|
2019-09-26 22:23:06 +02:00
|
|
|
|PROG.sf_ccall:
|
2021-06-15 19:33:16 +02:00
|
|
|
IF TARGETS.OS IN {TARGETS.osWIN32, TARGETS.osLINUX32, TARGETS.osKOS} THEN
|
|
|
|
res := PROG.ccall
|
|
|
|
ELSIF TARGETS.OS = TARGETS.osWIN64 THEN
|
|
|
|
res := PROG.win64
|
|
|
|
ELSIF TARGETS.OS = TARGETS.osLINUX64 THEN
|
|
|
|
res := PROG.systemv
|
|
|
|
END
|
2019-09-26 22:23:06 +02:00
|
|
|
|PROG.sf_win64:
|
|
|
|
res := PROG.win64
|
|
|
|
|PROG.sf_systemv:
|
|
|
|
res := PROG.systemv
|
|
|
|
|PROG.sf_code:
|
|
|
|
res := PROG.code
|
2022-06-21 22:32:43 +02:00
|
|
|
|PROG.sf_fastcall:
|
|
|
|
res := PROG.fastcall
|
2020-10-13 09:58:51 +02:00
|
|
|
|PROG.sf_oberon:
|
|
|
|
IF TARGETS.OS IN {TARGETS.osWIN32, TARGETS.osLINUX32, TARGETS.osKOS} THEN
|
|
|
|
res := PROG.default32
|
|
|
|
ELSIF TARGETS.OS IN {TARGETS.osWIN64, TARGETS.osLINUX64} THEN
|
|
|
|
res := PROG.default64
|
|
|
|
END
|
2019-09-26 22:23:06 +02:00
|
|
|
|PROG.sf_windows:
|
2020-05-25 22:48:33 +02:00
|
|
|
IF TARGETS.OS = TARGETS.osWIN32 THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
res := PROG.stdcall
|
2020-05-25 22:48:33 +02:00
|
|
|
ELSIF TARGETS.OS = TARGETS.osWIN64 THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
res := PROG.win64
|
|
|
|
END
|
2019-09-26 22:23:06 +02:00
|
|
|
|PROG.sf_linux:
|
2020-05-25 22:48:33 +02:00
|
|
|
IF TARGETS.OS = TARGETS.osLINUX32 THEN
|
2021-06-15 19:33:16 +02:00
|
|
|
res := PROG.ccall
|
2020-05-25 22:48:33 +02:00
|
|
|
ELSIF TARGETS.OS = TARGETS.osLINUX64 THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
res := PROG.systemv
|
|
|
|
END
|
2019-09-26 22:23:06 +02:00
|
|
|
|PROG.sf_noalign:
|
2019-03-11 09:59:55 +01:00
|
|
|
res := PROG.noalign
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN res
|
|
|
|
END sysflag;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE procflag (parser: PARSER; VAR _import: IL.IMPORT_PROC; isProc: BOOLEAN): INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
call: INTEGER;
|
2021-06-15 19:33:16 +02:00
|
|
|
dll, proc: SCAN.TEXTSTR;
|
2019-09-26 22:23:06 +02:00
|
|
|
pos: POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
PROCEDURE getStr (parser: PARSER; VAR name: SCAN.TEXTSTR);
|
2020-10-13 09:58:51 +02:00
|
|
|
VAR
|
|
|
|
pos: POSITION;
|
|
|
|
str: ARITH.VALUE;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
getpos(parser, pos);
|
|
|
|
ConstExpression(parser, str);
|
|
|
|
IF str.typ = ARITH.tSTRING THEN
|
2021-06-15 19:33:16 +02:00
|
|
|
name := str.string(SCAN.STRING).s
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF str.typ = ARITH.tCHAR THEN
|
|
|
|
ARITH.charToStr(str, name)
|
|
|
|
ELSE
|
|
|
|
check(FALSE, pos, 117)
|
|
|
|
END
|
|
|
|
END getStr;
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
_import := NIL;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF parser.sym = SCAN.lxLSQUARE THEN
|
|
|
|
getpos(parser, pos);
|
|
|
|
check1(parser.unit.sysimport, parser, 54);
|
|
|
|
Next(parser);
|
2019-09-26 22:23:06 +02:00
|
|
|
call := sysflag(parser, TRUE);
|
2019-03-11 09:59:55 +01:00
|
|
|
Next(parser);
|
|
|
|
IF parser.sym = SCAN.lxMINUS THEN
|
|
|
|
Next(parser);
|
|
|
|
INC(call)
|
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
|
|
|
|
IF isProc & (parser.sym = SCAN.lxCOMMA) THEN
|
|
|
|
Next(parser);
|
|
|
|
getStr(parser, dll);
|
2020-05-25 22:48:33 +02:00
|
|
|
STRINGS.UpCase(dll);
|
2020-10-13 09:58:51 +02:00
|
|
|
checklex(parser, SCAN.lxCOMMA);
|
2019-03-11 09:59:55 +01:00
|
|
|
Next(parser);
|
2020-10-13 09:58:51 +02:00
|
|
|
getStr(parser, proc);
|
|
|
|
_import := IL.AddImp(dll, proc)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
checklex(parser, SCAN.lxRSQUARE);
|
|
|
|
Next(parser)
|
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
CASE TARGETS.BitDepth OF
|
2019-09-26 22:23:06 +02:00
|
|
|
|16: call := PROG.default16
|
2020-10-13 09:58:51 +02:00
|
|
|
|32: IF TARGETS.CPU = TARGETS.cpuX86 THEN
|
2020-05-25 22:48:33 +02:00
|
|
|
call := PROG.default32
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSE
|
2021-06-15 19:33:16 +02:00
|
|
|
call := PROG.cdecl
|
|
|
|
END
|
|
|
|
|64: IF TARGETS.CPU = TARGETS.cpuAMD64 THEN
|
|
|
|
call := PROG.default64
|
|
|
|
ELSE
|
|
|
|
call := PROG.cdecl
|
2020-05-25 22:48:33 +02:00
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF _import # NIL THEN
|
2020-05-25 22:48:33 +02:00
|
|
|
check(TARGETS.Import, pos, 70)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
RETURN call
|
|
|
|
END procflag;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE _type (parser: PARSER; VAR t: PROG._TYPE; flags: SET);
|
2019-03-11 09:59:55 +01:00
|
|
|
CONST
|
|
|
|
comma = 0;
|
|
|
|
closed = 1;
|
|
|
|
forward = 2;
|
|
|
|
|
|
|
|
VAR
|
|
|
|
arrLen: ARITH.VALUE;
|
|
|
|
typeSize: ARITH.VALUE;
|
|
|
|
ident: PROG.IDENT;
|
|
|
|
unit: PROG.UNIT;
|
2019-09-26 22:23:06 +02:00
|
|
|
pos, pos2: POSITION;
|
2020-10-13 09:58:51 +02:00
|
|
|
fieldType: PROG._TYPE;
|
2019-03-11 09:59:55 +01:00
|
|
|
baseIdent: SCAN.IDENT;
|
|
|
|
a, b: INTEGER;
|
|
|
|
RecFlag: INTEGER;
|
2020-10-13 09:58:51 +02:00
|
|
|
_import: IL.IMPORT_PROC;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
unit := parser.unit;
|
|
|
|
t := NIL;
|
|
|
|
|
|
|
|
IF parser.sym = SCAN.lxIDENT THEN
|
|
|
|
ident := QIdent(parser, forward IN flags);
|
|
|
|
|
|
|
|
IF ident # NIL THEN
|
|
|
|
check1(ident.typ = PROG.idTYPE, parser, 49);
|
2020-10-13 09:58:51 +02:00
|
|
|
t := ident._type;
|
2019-03-11 09:59:55 +01:00
|
|
|
check1(t # NIL, parser, 50);
|
|
|
|
IF closed IN flags THEN
|
|
|
|
check1(t.closed, parser, 50)
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
Next(parser)
|
|
|
|
|
|
|
|
ELSIF (parser.sym = SCAN.lxARRAY) OR ((parser.sym = SCAN.lxCOMMA) & (comma IN flags)) THEN
|
|
|
|
|
|
|
|
IF parser.sym = SCAN.lxARRAY THEN
|
|
|
|
getpos(parser, pos2)
|
|
|
|
END;
|
|
|
|
NextPos(parser, pos);
|
|
|
|
|
|
|
|
ConstExpression(parser, arrLen);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
check(arrLen.typ = ARITH.tINTEGER, pos, 43);
|
|
|
|
check(ARITH.check(arrLen), pos, 39);
|
|
|
|
check(ARITH.getInt(arrLen) > 0, pos, 51);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
t := PROG.enterType(PROG.tARRAY, -1, ARITH.getInt(arrLen), unit);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF parser.sym = SCAN.lxCOMMA THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
_type(parser, t.base, {comma, closed})
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF parser.sym = SCAN.lxOF THEN
|
|
|
|
Next(parser);
|
2020-10-13 09:58:51 +02:00
|
|
|
_type(parser, t.base, {closed})
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
check1(FALSE, parser, 47)
|
|
|
|
END;
|
|
|
|
|
|
|
|
t.align := t.base.align;
|
|
|
|
|
|
|
|
a := t.length;
|
|
|
|
b := t.base.size;
|
2019-09-26 22:23:06 +02:00
|
|
|
check(ARITH.mulInt(a, b), pos2, 104);
|
|
|
|
check(ARITH.setInt(typeSize, a), pos2, 104);
|
2019-03-11 09:59:55 +01:00
|
|
|
t.size := a;
|
|
|
|
|
|
|
|
t.closed := TRUE
|
|
|
|
|
|
|
|
ELSIF parser.sym = SCAN.lxRECORD THEN
|
|
|
|
getpos(parser, pos2);
|
|
|
|
Next(parser);
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
t := PROG.enterType(PROG.tRECORD, 0, 0, unit);
|
2019-03-11 09:59:55 +01:00
|
|
|
t.align := 1;
|
|
|
|
|
|
|
|
IF parser.sym = SCAN.lxLSQUARE THEN
|
|
|
|
check1(parser.unit.sysimport, parser, 54);
|
|
|
|
Next(parser);
|
2019-09-26 22:23:06 +02:00
|
|
|
RecFlag := sysflag(parser, FALSE);
|
|
|
|
t.noalign := RecFlag = PROG.noalign;
|
2019-03-11 09:59:55 +01:00
|
|
|
ExpectSym(parser, SCAN.lxRSQUARE);
|
|
|
|
Next(parser)
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF parser.sym = SCAN.lxLROUND THEN
|
|
|
|
check1(~t.noalign, parser, 111);
|
|
|
|
ExpectSym(parser, SCAN.lxIDENT);
|
|
|
|
getpos(parser, pos);
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
_type(parser, t.base, {closed});
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
check(t.base.typ IN {PROG.tRECORD, PROG.tPOINTER}, pos, 52);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF t.base.typ = PROG.tPOINTER THEN
|
|
|
|
t.base := t.base.base;
|
2019-09-26 22:23:06 +02:00
|
|
|
check(t.base # NIL, pos, 55)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
check(~t.base.noalign, pos, 112);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
checklex(parser, SCAN.lxRROUND);
|
|
|
|
Next(parser);
|
|
|
|
|
|
|
|
t.size := t.base.size;
|
|
|
|
IF t.base.align > t.align THEN
|
|
|
|
t.align := t.base.align
|
|
|
|
END
|
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
t.base := PROG.program.stTypes.tANYREC
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
WHILE parser.sym = SCAN.lxIDENT DO
|
|
|
|
FieldList(parser, t);
|
|
|
|
|
|
|
|
ASSERT(parser.sym = SCAN.lxCOLON);
|
|
|
|
Next(parser);
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
_type(parser, fieldType, {closed});
|
2019-09-26 22:23:06 +02:00
|
|
|
check(PROG.setFields(t, fieldType), pos2, 104);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF (fieldType.align > t.align) & ~t.noalign THEN
|
|
|
|
t.align := fieldType.align
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF parser.sym = SCAN.lxSEMI THEN
|
|
|
|
ExpectSym(parser, SCAN.lxIDENT)
|
|
|
|
ELSE
|
|
|
|
checklex(parser, SCAN.lxEND)
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
t.closed := TRUE;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddRec(t.base.num);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF ~t.noalign THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
check(UTILS.Align(t.size, t.align), pos2, 104);
|
|
|
|
check(ARITH.setInt(typeSize, t.size), pos2, 104)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
checklex(parser, SCAN.lxEND);
|
|
|
|
Next(parser)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
ELSIF parser.sym = SCAN.lxPOINTER THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
ExpectSym(parser, SCAN.lxTO);
|
|
|
|
Next(parser);
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
t := PROG.enterType(PROG.tPOINTER, TARGETS.AdrSize, 0, unit);
|
2020-05-25 22:48:33 +02:00
|
|
|
t.align := TARGETS.AdrSize;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
getpos(parser, pos);
|
|
|
|
|
|
|
|
IF parser.sym = SCAN.lxIDENT THEN
|
|
|
|
baseIdent := parser.lex.ident
|
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
_type(parser, t.base, {forward});
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF t.base # NIL THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
check(t.base.typ = PROG.tRECORD, pos, 58)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
PROG.frwPtr(unit, t, baseIdent, pos)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
ELSIF parser.sym = SCAN.lxPROCEDURE THEN
|
|
|
|
NextPos(parser, pos);
|
2020-10-13 09:58:51 +02:00
|
|
|
t := PROG.enterType(PROG.tPROCEDURE, TARGETS.AdrSize, 0, unit);
|
2020-05-25 22:48:33 +02:00
|
|
|
t.align := TARGETS.AdrSize;
|
2020-10-13 09:58:51 +02:00
|
|
|
t.call := procflag(parser, _import, FALSE);
|
2019-03-11 09:59:55 +01:00
|
|
|
FormalParameters(parser, t)
|
|
|
|
ELSE
|
|
|
|
check1(FALSE, parser, 49)
|
|
|
|
END
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
END _type;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE IdentDef (parser: PARSER; typ: INTEGER; VAR name: SCAN.IDENT): PROG.IDENT;
|
|
|
|
VAR
|
|
|
|
ident: PROG.IDENT;
|
2019-09-26 22:23:06 +02:00
|
|
|
pos: POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
ASSERT(parser.sym = SCAN.lxIDENT);
|
|
|
|
|
|
|
|
name := parser.lex.ident;
|
|
|
|
getpos(parser, pos);
|
2019-09-26 22:23:06 +02:00
|
|
|
ident := PROG.addIdent(parser.unit, name, typ);
|
|
|
|
check(ident # NIL, pos, 30);
|
2019-03-11 09:59:55 +01:00
|
|
|
ident.pos := pos;
|
|
|
|
Next(parser);
|
|
|
|
|
|
|
|
IF parser.sym = SCAN.lxMUL THEN
|
|
|
|
check1(ident.global, parser, 61);
|
|
|
|
ident.export := TRUE;
|
|
|
|
Next(parser)
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN ident
|
|
|
|
END IdentDef;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE ConstTypeDeclaration (parser: PARSER; _const: BOOLEAN);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
ident: PROG.IDENT;
|
|
|
|
name: SCAN.IDENT;
|
|
|
|
pos: POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF _const THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
ident := IdentDef(parser, PROG.idNONE, name)
|
|
|
|
ELSE
|
|
|
|
ident := IdentDef(parser, PROG.idTYPE, name)
|
|
|
|
END;
|
|
|
|
|
|
|
|
checklex(parser, SCAN.lxEQ);
|
|
|
|
NextPos(parser, pos);
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF _const THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
ConstExpression(parser, ident.value);
|
|
|
|
IF ident.value.typ = ARITH.tINTEGER THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
check(ARITH.check(ident.value), pos, 39)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF ident.value.typ = ARITH.tREAL THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
check(ARITH.check(ident.value), pos, 40)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
ident.typ := PROG.idCONST;
|
2020-10-13 09:58:51 +02:00
|
|
|
ident._type := PROG.getType(ident.value.typ)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
_type(parser, ident._type, {})
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
checklex(parser, SCAN.lxSEMI);
|
|
|
|
Next(parser)
|
|
|
|
|
|
|
|
END ConstTypeDeclaration;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE VarDeclaration (parser: PARSER);
|
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
ident: PROG.IDENT;
|
|
|
|
name: SCAN.IDENT;
|
2020-10-13 09:58:51 +02:00
|
|
|
t: PROG._TYPE;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
|
|
|
|
REPEAT
|
|
|
|
ident := IdentDef(parser, PROG.idVAR, name);
|
|
|
|
|
|
|
|
IF parser.sym = SCAN.lxCOMMA THEN
|
|
|
|
ExpectSym(parser, SCAN.lxIDENT)
|
|
|
|
ELSIF parser.sym = SCAN.lxCOLON THEN
|
|
|
|
Next(parser);
|
2020-10-13 09:58:51 +02:00
|
|
|
_type(parser, t, {});
|
2019-09-26 22:23:06 +02:00
|
|
|
PROG.setVarsType(parser.unit, t);
|
2019-03-11 09:59:55 +01:00
|
|
|
checklex(parser, SCAN.lxSEMI);
|
|
|
|
Next(parser)
|
|
|
|
ELSE
|
|
|
|
checklex(parser, SCAN.lxCOLON)
|
|
|
|
END
|
|
|
|
|
|
|
|
UNTIL parser.sym # SCAN.lxIDENT
|
|
|
|
|
|
|
|
END VarDeclaration;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE DeclarationSequence (parser: PARSER): BOOLEAN;
|
|
|
|
VAR
|
|
|
|
ptr: PROG.FRWPTR;
|
|
|
|
endmod: BOOLEAN;
|
2019-09-26 22:23:06 +02:00
|
|
|
pos: POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE ProcDeclaration (parser: PARSER): BOOLEAN;
|
|
|
|
VAR
|
|
|
|
proc: PROG.IDENT;
|
|
|
|
endname,
|
|
|
|
name: SCAN.IDENT;
|
2019-09-26 22:23:06 +02:00
|
|
|
param: PROG.PARAM;
|
2019-03-11 09:59:55 +01:00
|
|
|
unit: PROG.UNIT;
|
|
|
|
ident: PROG.IDENT;
|
|
|
|
e: EXPR;
|
2019-09-26 22:23:06 +02:00
|
|
|
pos, pos1,
|
|
|
|
pos2: POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
label: INTEGER;
|
2019-09-26 22:23:06 +02:00
|
|
|
enter: IL.COMMAND;
|
2019-03-11 09:59:55 +01:00
|
|
|
call: INTEGER;
|
2020-10-13 09:58:51 +02:00
|
|
|
t: PROG._TYPE;
|
|
|
|
_import: IL.IMPORT_PROC;
|
2019-03-11 09:59:55 +01:00
|
|
|
endmod, b: BOOLEAN;
|
|
|
|
fparams: SET;
|
|
|
|
int, flt: INTEGER;
|
2019-09-26 22:23:06 +02:00
|
|
|
comma: BOOLEAN;
|
2020-05-25 22:48:33 +02:00
|
|
|
code, iv: ARITH.VALUE;
|
|
|
|
codeProc,
|
|
|
|
handler: BOOLEAN;
|
2021-06-15 19:33:16 +02:00
|
|
|
line: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
endmod := FALSE;
|
2020-05-25 22:48:33 +02:00
|
|
|
handler := FALSE;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
unit := parser.unit;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
call := procflag(parser, _import, TRUE);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
getpos(parser, pos);
|
2019-09-26 22:23:06 +02:00
|
|
|
pos1 := pos;
|
2019-03-11 09:59:55 +01:00
|
|
|
checklex(parser, SCAN.lxIDENT);
|
2021-06-15 19:33:16 +02:00
|
|
|
line := pos.line;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF _import # NIL THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
proc := IdentDef(parser, PROG.idIMP, name);
|
2020-10-13 09:58:51 +02:00
|
|
|
proc._import := _import;
|
|
|
|
IF _import.name = "" THEN
|
2021-06-15 19:33:16 +02:00
|
|
|
COPY(name.s, _import.name)
|
2020-10-13 09:58:51 +02:00
|
|
|
END;
|
|
|
|
PROG.program.procs.last(PROG.PROC)._import := _import
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
proc := IdentDef(parser, PROG.idPROC, name)
|
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
check(PROG.openScope(unit, proc.proc), pos, 116);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
proc._type := PROG.enterType(PROG.tPROCEDURE, TARGETS.AdrSize, 0, unit);
|
|
|
|
t := proc._type;
|
2020-05-25 22:48:33 +02:00
|
|
|
t.align := TARGETS.AdrSize;
|
2019-09-26 22:23:06 +02:00
|
|
|
t.call := call;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
FormalParameters(parser, t);
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IF parser.sym = SCAN.lxLSQUARE THEN
|
|
|
|
getpos(parser, pos2);
|
2021-06-15 19:33:16 +02:00
|
|
|
check((TARGETS.CPU = TARGETS.cpuTHUMB) & (TARGETS.OS = TARGETS.osNONE), pos2, 24);
|
2020-05-25 22:48:33 +02:00
|
|
|
Next(parser);
|
|
|
|
getpos(parser, pos2);
|
|
|
|
ConstExpression(parser, iv);
|
|
|
|
check(iv.typ = ARITH.tINTEGER, pos2, 43);
|
|
|
|
check((0 <= ARITH.Int(iv)) & (ARITH.Int(iv) <= THUMB.maxIVT), pos2, 46);
|
|
|
|
check(THUMB.SetIV(ARITH.Int(iv)), pos2, 121);
|
|
|
|
checklex(parser, SCAN.lxRSQUARE);
|
|
|
|
Next(parser);
|
|
|
|
handler := TRUE
|
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
codeProc := call IN {PROG.code, PROG._code};
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
IF call IN {PROG.systemv, PROG._systemv} THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
check(t.parSize <= PROG.MAXSYSVPARAM, pos, 120)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
param := t.params.first(PROG.PARAM);
|
2019-03-11 09:59:55 +01:00
|
|
|
WHILE param # NIL DO
|
2019-09-26 22:23:06 +02:00
|
|
|
ident := PROG.addIdent(unit, param.name, PROG.idPARAM);
|
2019-03-11 09:59:55 +01:00
|
|
|
ASSERT(ident # NIL);
|
2020-10-13 09:58:51 +02:00
|
|
|
ident._type := param._type;
|
2019-09-26 22:23:06 +02:00
|
|
|
ident.offset := param.offset;
|
|
|
|
IF param.vPar THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
ident.typ := PROG.idVPAR
|
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
param := param.next(PROG.PARAM)
|
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF _import = NIL THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
label := IL.NewLabel();
|
2020-05-25 22:48:33 +02:00
|
|
|
proc.proc.label := label;
|
|
|
|
proc.proc.used := handler;
|
|
|
|
IF handler THEN
|
|
|
|
IL.AddCmd2(IL.opHANDLER, label, ARITH.Int(iv))
|
|
|
|
END
|
2019-09-26 22:23:06 +02:00
|
|
|
END;
|
|
|
|
|
|
|
|
IF codeProc THEN
|
|
|
|
enter := IL.EnterC(label);
|
|
|
|
comma := FALSE;
|
|
|
|
WHILE (parser.sym # SCAN.lxSEMI) OR comma DO
|
|
|
|
getpos(parser, pos2);
|
|
|
|
ConstExpression(parser, code);
|
|
|
|
check(code.typ = ARITH.tINTEGER, pos2, 43);
|
2020-10-13 09:58:51 +02:00
|
|
|
IF TARGETS.WordSize > TARGETS.InstrSize THEN
|
|
|
|
CASE TARGETS.InstrSize OF
|
|
|
|
|1: check(ARITH.range(code, 0, 255), pos, 42)
|
|
|
|
|2: check(ARITH.range(code, 0, 65535), pos, 110)
|
|
|
|
END
|
2019-09-26 22:23:06 +02:00
|
|
|
END;
|
|
|
|
IL.AddCmd(IL.opCODE, ARITH.getInt(code));
|
|
|
|
comma := parser.sym = SCAN.lxCOMMA;
|
|
|
|
IF comma THEN
|
|
|
|
Next(parser)
|
|
|
|
ELSE
|
|
|
|
checklex(parser, SCAN.lxSEMI)
|
|
|
|
END
|
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
checklex(parser, SCAN.lxSEMI);
|
|
|
|
Next(parser);
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF _import = NIL THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IF parser.main & proc.export & TARGETS.Dll THEN
|
|
|
|
IF TARGETS.target = TARGETS.KolibriOSDLL THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
check((proc.name.s # "lib_init") & (proc.name.s # "version"), pos, 114)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddExp(label, proc.name.s);
|
2019-03-11 09:59:55 +01:00
|
|
|
proc.proc.used := TRUE
|
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF ~codeProc THEN
|
|
|
|
b := DeclarationSequence(parser)
|
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROG.ResetLocSize;
|
2019-03-11 09:59:55 +01:00
|
|
|
IF call IN {PROG._win64, PROG.win64} THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
fparams := PROG.getFloatParamsPos(proc._type, 3, int, flt);
|
|
|
|
enter := IL.Enter(label, LSL(ORD(fparams), 5) + MIN(proc._type.parSize, 4))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF call IN {PROG._systemv, PROG.systemv} THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
fparams := PROG.getFloatParamsPos(proc._type, PROG.MAXSYSVPARAM - 1, int, flt);
|
|
|
|
enter := IL.Enter(label, -(LSL(ORD(fparams), 5) + proc._type.parSize))
|
2019-09-26 22:23:06 +02:00
|
|
|
ELSIF codeProc THEN
|
|
|
|
|
2022-06-21 22:32:43 +02:00
|
|
|
ELSIF call IN {PROG.fastcall, PROG._fastcall} THEN
|
|
|
|
enter := IL.Enter(label, proc._type.parSize)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
enter := IL.Enter(label, 0)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
proc.proc.enter := enter;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF ~codeProc & (parser.sym = SCAN.lxBEGIN) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
Next(parser);
|
|
|
|
parser.StatSeq(parser)
|
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF ~codeProc & (t.base # NIL) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
checklex(parser, SCAN.lxRETURN);
|
|
|
|
NextPos(parser, pos);
|
|
|
|
parser.expression(parser, e);
|
2019-09-26 22:23:06 +02:00
|
|
|
check(parser.chkreturn(parser, e, t.base, pos), pos, 87)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF ~codeProc THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
proc.proc.leave := IL.Leave(t.base # NIL, (t.base # NIL) & (t.base.typ = PROG.tREAL), PROG.program.locsize,
|
2019-09-26 22:23:06 +02:00
|
|
|
t.parSize * ORD((t.call IN PROG.callee_clean_up) OR (t.call IN {PROG.systemv, PROG._systemv})));
|
2020-10-13 09:58:51 +02:00
|
|
|
enter.param2 := PROG.program.locsize;
|
2019-09-26 22:23:06 +02:00
|
|
|
checklex(parser, SCAN.lxEND)
|
|
|
|
ELSE
|
|
|
|
proc.proc.leave := IL.LeaveC()
|
|
|
|
END;
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
IF (TARGETS.CPU = TARGETS.cpuMSP430) & ~codeProc THEN
|
|
|
|
check(MSP430.CheckProcDataSize(enter.param2 + proc._type.parSize, PROG.program.options.ram), pos1, 63);
|
|
|
|
enter.param2 := enter.param2 * 65536 + line;
|
|
|
|
enter.param3 := IL.codes.errlabels[10]
|
2019-09-26 22:23:06 +02:00
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
IF parser.sym = SCAN.lxEND THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
Next(parser);
|
|
|
|
IF parser.sym = SCAN.lxIDENT THEN
|
|
|
|
getpos(parser, pos);
|
|
|
|
endname := parser.lex.ident;
|
|
|
|
IF ~codeProc & (_import = NIL) THEN
|
2021-06-15 19:33:16 +02:00
|
|
|
check(PROG.IdEq(endname, name), pos, 60);
|
2019-03-11 09:59:55 +01:00
|
|
|
ExpectSym(parser, SCAN.lxSEMI);
|
|
|
|
Next(parser)
|
|
|
|
ELSE
|
2021-06-15 19:33:16 +02:00
|
|
|
IF PROG.IdEq(endname, parser.unit.name) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
ExpectSym(parser, SCAN.lxPOINT);
|
|
|
|
Next(parser);
|
|
|
|
endmod := TRUE
|
2021-06-15 19:33:16 +02:00
|
|
|
ELSIF PROG.IdEq(endname, name) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
ExpectSym(parser, SCAN.lxSEMI);
|
|
|
|
Next(parser)
|
|
|
|
ELSE
|
|
|
|
error(pos, 60)
|
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF parser.sym = SCAN.lxSEMI THEN
|
|
|
|
Next(parser)
|
|
|
|
ELSE
|
|
|
|
checklex(parser, SCAN.lxIDENT)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
PROG.closeScope(unit);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
RETURN endmod
|
|
|
|
END ProcDeclaration;
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF parser.sym = SCAN.lxCONST THEN
|
|
|
|
Next(parser);
|
|
|
|
WHILE parser.sym = SCAN.lxIDENT DO
|
|
|
|
ConstTypeDeclaration(parser, TRUE)
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF parser.sym = SCAN.lxTYPE THEN
|
|
|
|
Next(parser);
|
|
|
|
WHILE parser.sym = SCAN.lxIDENT DO
|
|
|
|
ConstTypeDeclaration(parser, FALSE)
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
ptr := PROG.linkPtr(parser.unit);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF ptr # NIL THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
pos.line := ptr.pos.line;
|
|
|
|
pos.col := ptr.pos.col;
|
|
|
|
pos.parser := parser;
|
2019-03-11 09:59:55 +01:00
|
|
|
IF ptr.notRecord THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
error(pos, 58)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
error(pos, 48)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF parser.sym = SCAN.lxVAR THEN
|
|
|
|
Next(parser);
|
|
|
|
IF parser.sym = SCAN.lxIDENT THEN
|
|
|
|
VarDeclaration(parser)
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
endmod := FALSE;
|
|
|
|
WHILE ~endmod & (parser.sym = SCAN.lxPROCEDURE) DO
|
|
|
|
Next(parser);
|
|
|
|
endmod := ProcDeclaration(parser)
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN endmod
|
|
|
|
END DeclarationSequence;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE parse (parser: PARSER);
|
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
unit: PROG.UNIT;
|
|
|
|
label: INTEGER;
|
|
|
|
name: INTEGER;
|
|
|
|
endmod: BOOLEAN;
|
|
|
|
errlabel: INTEGER;
|
|
|
|
errno: INTEGER;
|
2022-01-05 21:42:22 +01:00
|
|
|
ident: PROG.IDENT;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
ASSERT(parser # NIL);
|
|
|
|
ASSERT(parser.scanner # NIL);
|
|
|
|
|
|
|
|
ExpectSym(parser, SCAN.lxMODULE);
|
|
|
|
ExpectSym(parser, SCAN.lxIDENT);
|
|
|
|
|
|
|
|
IF ~parser.main THEN
|
2021-06-15 19:33:16 +02:00
|
|
|
check1(parser.lex.ident.s = parser.modname, parser, 23)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
unit := PROG.newUnit(parser.lex.ident);
|
2021-06-15 19:33:16 +02:00
|
|
|
unit.fname := parser.fname;
|
2019-03-11 09:59:55 +01:00
|
|
|
parser.unit := unit;
|
|
|
|
|
|
|
|
ExpectSym(parser, SCAN.lxSEMI);
|
|
|
|
|
|
|
|
Next(parser);
|
|
|
|
IF parser.sym = SCAN.lxIMPORT THEN
|
|
|
|
ImportList(parser)
|
|
|
|
END;
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
INC(modules);
|
|
|
|
|
|
|
|
CONSOLE.String("compiling ");
|
2020-10-13 09:58:51 +02:00
|
|
|
CONSOLE.String("("); CONSOLE.Int(modules); CONSOLE.String(") ");
|
2020-05-25 22:48:33 +02:00
|
|
|
CONSOLE.String(unit.name.s);
|
2022-01-05 21:42:22 +01:00
|
|
|
IF unit.sysimport THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
CONSOLE.String(" (SYSTEM)")
|
|
|
|
END;
|
|
|
|
CONSOLE.Ln;
|
|
|
|
|
2022-01-05 21:42:22 +01:00
|
|
|
IF PROG.program.options.uses THEN
|
|
|
|
ident := unit.idents.first(PROG.IDENT);
|
|
|
|
WHILE ident # NIL DO
|
|
|
|
IF (ident.typ = PROG.idMODULE) & (ident.unit # PROG.program.sysunit) THEN
|
|
|
|
CONSOLE.String(" "); CONSOLE.String(ident.unit.fname); CONSOLE.Ln
|
|
|
|
END;
|
|
|
|
ident := ident.next(PROG.IDENT)
|
|
|
|
END;
|
|
|
|
CONSOLE.Ln
|
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF TARGETS.CPU IN {TARGETS.cpuX86, TARGETS.cpuAMD64} THEN
|
|
|
|
IL.fname(parser.fname)
|
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
label := IL.NewLabel();
|
2021-06-15 19:33:16 +02:00
|
|
|
IL.Jmp(IL.opJMP, label);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
name := IL.putstr(unit.name.s);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
errlabel := IL.NewLabel();
|
|
|
|
IL.SetLabel(errlabel);
|
|
|
|
IL.StrAdr(name);
|
|
|
|
IL.Param1;
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd(IL.opPUSHC, modules);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opERR);
|
|
|
|
|
|
|
|
FOR errno := 1 TO LEN(IL.codes.errlabels) - 1 DO
|
|
|
|
IL.SetErrLabel(errno);
|
|
|
|
IL.AddCmd(IL.opPUSHC, errno);
|
2021-06-15 19:33:16 +02:00
|
|
|
IL.Jmp(IL.opJMP, errlabel)
|
2019-09-26 22:23:06 +02:00
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
endmod := DeclarationSequence(parser);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.SetLabel(label);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF ~endmod THEN
|
|
|
|
|
|
|
|
IF parser.sym = SCAN.lxBEGIN THEN
|
|
|
|
Next(parser);
|
|
|
|
parser.StatSeq(parser)
|
|
|
|
END;
|
|
|
|
|
|
|
|
checklex(parser, SCAN.lxEND);
|
|
|
|
|
|
|
|
ExpectSym(parser, SCAN.lxIDENT);
|
2021-06-15 19:33:16 +02:00
|
|
|
check1(parser.lex.ident.s = unit.name.s, parser, 25);
|
2019-03-11 09:59:55 +01:00
|
|
|
ExpectSym(parser, SCAN.lxPOINT)
|
|
|
|
END;
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
INC(lines, parser.lex.pos.line);
|
2019-09-26 22:23:06 +02:00
|
|
|
PROG.closeUnit(unit)
|
2019-03-11 09:59:55 +01:00
|
|
|
END parse;
|
|
|
|
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
PROCEDURE open (parser: PARSER; modname, FileExt: ARRAY OF CHAR): BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
ASSERT(parser # NIL);
|
|
|
|
|
|
|
|
STRINGS.append(parser.fname, modname);
|
2021-06-15 19:33:16 +02:00
|
|
|
STRINGS.append(parser.fname, FileExt);
|
2019-03-11 09:59:55 +01:00
|
|
|
STRINGS.append(parser.modname, modname);
|
|
|
|
|
|
|
|
parser.scanner := SCAN.open(parser.fname)
|
|
|
|
|
|
|
|
RETURN parser.scanner # NIL
|
|
|
|
END open;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE NewParser (): PARSER;
|
|
|
|
VAR
|
|
|
|
pars: PARSER;
|
|
|
|
citem: C.ITEM;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
citem := C.pop(parsers);
|
|
|
|
IF citem = NIL THEN
|
|
|
|
NEW(pars)
|
|
|
|
ELSE
|
|
|
|
pars := citem(PARSER)
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN pars
|
|
|
|
END NewParser;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE create* (path, lib_path: PATH; StatSeq: STATPROC; expression, designator: EXPRPROC; chkreturn: RETPROC): PARSER;
|
|
|
|
VAR
|
|
|
|
parser: PARSER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
parser := NewParser();
|
|
|
|
|
|
|
|
parser.path := path;
|
|
|
|
parser.lib_path := lib_path;
|
2020-05-25 22:48:33 +02:00
|
|
|
parser.ext := UTILS.FILE_EXT;
|
2019-03-11 09:59:55 +01:00
|
|
|
parser.fname := path;
|
|
|
|
parser.modname := "";
|
|
|
|
parser.scanner := NIL;
|
|
|
|
parser.unit := NIL;
|
|
|
|
parser.constexp := FALSE;
|
|
|
|
parser.main := FALSE;
|
|
|
|
|
|
|
|
parser.open := open;
|
|
|
|
parser.parse := parse;
|
|
|
|
parser.StatSeq := StatSeq;
|
|
|
|
parser.expression := expression;
|
|
|
|
parser.designator := designator;
|
|
|
|
parser.chkreturn := chkreturn;
|
|
|
|
parser.create := create
|
|
|
|
|
|
|
|
RETURN parser
|
|
|
|
END create;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE init* (options: PROG.OPTIONS);
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
PROG.create(options);
|
2019-10-06 19:55:12 +02:00
|
|
|
parsers := C.create();
|
2020-05-25 22:48:33 +02:00
|
|
|
lines := 0;
|
|
|
|
modules := 0
|
2019-03-11 09:59:55 +01:00
|
|
|
END init;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
END PARS.
|