2020-05-25 22:48:33 +02:00
|
|
|
(*
|
2019-03-11 09:59:55 +01:00
|
|
|
BSD 2-Clause License
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
Copyright (c) 2018-2020, Anton Krotov
|
2019-03-11 09:59:55 +01:00
|
|
|
All rights reserved.
|
|
|
|
*)
|
|
|
|
|
|
|
|
MODULE STATEMENTS;
|
|
|
|
|
|
|
|
IMPORT
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PARS, PROG, SCAN, ARITH, STRINGS, LISTS, IL, X86, AMD64, MSP430, THUMB, RVM32I,
|
2020-05-25 22:48:33 +02:00
|
|
|
ERRORS, UTILS, AVL := AVLTREES, CONSOLE, C := COLLECTIONS, TARGETS;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
CONST
|
|
|
|
|
|
|
|
eCONST = PARS.eCONST; eTYPE = PARS.eTYPE; eVAR = PARS.eVAR;
|
|
|
|
eEXPR = PARS.eEXPR; eVREC = PARS.eVREC; ePROC = PARS.ePROC;
|
|
|
|
eVPAR = PARS.eVPAR; ePARAM = PARS.ePARAM; eSTPROC = PARS.eSTPROC;
|
|
|
|
eSTFUNC = PARS.eSTFUNC; eSYSFUNC = PARS.eSYSFUNC; eSYSPROC = PARS.eSYSPROC;
|
|
|
|
eIMP = PARS.eIMP;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
errASSERT = 1; errPTR = 2; errDIV = 3; errPROC = 4;
|
|
|
|
errGUARD = 5; errIDX = 6; errCASE = 7; errCOPY = 8;
|
2019-03-11 09:59:55 +01:00
|
|
|
errCHR = 9; errWCHR = 10; errBYTE = 11;
|
|
|
|
|
|
|
|
chkIDX* = 0; chkGUARD* = 1; chkPTR* = 2; chkCHR* = 3; chkWCHR* = 4; chkBYTE* = 5;
|
|
|
|
|
|
|
|
chkALL* = {chkIDX, chkGUARD, chkPTR, chkCHR, chkWCHR, chkBYTE};
|
|
|
|
|
|
|
|
|
|
|
|
TYPE
|
|
|
|
|
|
|
|
isXXX = PROCEDURE (e: PARS.EXPR): BOOLEAN;
|
|
|
|
|
|
|
|
RANGE = RECORD
|
|
|
|
|
|
|
|
a, b: INTEGER
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
CASE_LABEL = POINTER TO rCASE_LABEL;
|
|
|
|
|
|
|
|
rCASE_LABEL = RECORD (AVL.DATA)
|
|
|
|
|
|
|
|
range: RANGE;
|
|
|
|
|
|
|
|
variant, self: INTEGER;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
_type: PROG._TYPE;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
prev: CASE_LABEL
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
CASE_VARIANT = POINTER TO RECORD (LISTS.ITEM)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
label: INTEGER;
|
|
|
|
cmd: IL.COMMAND;
|
|
|
|
processed: BOOLEAN
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
|
|
|
|
VAR
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
Options: PROG.OPTIONS;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
begcall, endcall: IL.COMMAND;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
CaseLabels, CaseVar: C.COLLECTION;
|
|
|
|
|
|
|
|
CaseVariants: LISTS.LIST;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
CPU: INTEGER;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
tINTEGER, tBYTE, tCHAR, tWCHAR, tSET, tBOOLEAN, tREAL: PROG._TYPE;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PROCEDURE isExpr (e: PARS.EXPR): BOOLEAN;
|
|
|
|
RETURN e.obj IN {eCONST, eVAR, eEXPR, eVPAR, ePARAM, eVREC}
|
|
|
|
END isExpr;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isVar (e: PARS.EXPR): BOOLEAN;
|
|
|
|
RETURN e.obj IN {eVAR, eVPAR, ePARAM, eVREC}
|
|
|
|
END isVar;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isBoolean (e: PARS.EXPR): BOOLEAN;
|
2020-10-13 09:58:51 +02:00
|
|
|
RETURN isExpr(e) & (e._type = tBOOLEAN)
|
2019-03-11 09:59:55 +01:00
|
|
|
END isBoolean;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isInteger (e: PARS.EXPR): BOOLEAN;
|
2020-10-13 09:58:51 +02:00
|
|
|
RETURN isExpr(e) & (e._type = tINTEGER)
|
2019-03-11 09:59:55 +01:00
|
|
|
END isInteger;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isByte (e: PARS.EXPR): BOOLEAN;
|
2020-10-13 09:58:51 +02:00
|
|
|
RETURN isExpr(e) & (e._type = tBYTE)
|
2019-03-11 09:59:55 +01:00
|
|
|
END isByte;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isInt (e: PARS.EXPR): BOOLEAN;
|
|
|
|
RETURN isByte(e) OR isInteger(e)
|
|
|
|
END isInt;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isReal (e: PARS.EXPR): BOOLEAN;
|
2020-10-13 09:58:51 +02:00
|
|
|
RETURN isExpr(e) & (e._type = tREAL)
|
2019-03-11 09:59:55 +01:00
|
|
|
END isReal;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isSet (e: PARS.EXPR): BOOLEAN;
|
2020-10-13 09:58:51 +02:00
|
|
|
RETURN isExpr(e) & (e._type = tSET)
|
2019-03-11 09:59:55 +01:00
|
|
|
END isSet;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isString (e: PARS.EXPR): BOOLEAN;
|
2020-10-13 09:58:51 +02:00
|
|
|
RETURN (e.obj = eCONST) & (e._type.typ IN {PROG.tSTRING, PROG.tCHAR})
|
2019-03-11 09:59:55 +01:00
|
|
|
END isString;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isStringW (e: PARS.EXPR): BOOLEAN;
|
2020-10-13 09:58:51 +02:00
|
|
|
RETURN (e.obj = eCONST) & (e._type.typ IN {PROG.tSTRING, PROG.tCHAR, PROG.tWCHAR})
|
2019-03-11 09:59:55 +01:00
|
|
|
END isStringW;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isChar (e: PARS.EXPR): BOOLEAN;
|
2020-10-13 09:58:51 +02:00
|
|
|
RETURN isExpr(e) & (e._type = tCHAR)
|
2019-03-11 09:59:55 +01:00
|
|
|
END isChar;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isCharW (e: PARS.EXPR): BOOLEAN;
|
2020-10-13 09:58:51 +02:00
|
|
|
RETURN isExpr(e) & (e._type = tWCHAR)
|
2019-03-11 09:59:55 +01:00
|
|
|
END isCharW;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isPtr (e: PARS.EXPR): BOOLEAN;
|
2020-10-13 09:58:51 +02:00
|
|
|
RETURN isExpr(e) & (e._type.typ = PROG.tPOINTER)
|
2019-03-11 09:59:55 +01:00
|
|
|
END isPtr;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isRec (e: PARS.EXPR): BOOLEAN;
|
2020-10-13 09:58:51 +02:00
|
|
|
RETURN isExpr(e) & (e._type.typ = PROG.tRECORD)
|
2019-03-11 09:59:55 +01:00
|
|
|
END isRec;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE isRecPtr (e: PARS.EXPR): BOOLEAN;
|
|
|
|
RETURN isRec(e) OR isPtr(e)
|
|
|
|
END isRecPtr;
|
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE isArr (e: PARS.EXPR): BOOLEAN;
|
2020-10-13 09:58:51 +02:00
|
|
|
RETURN isExpr(e) & (e._type.typ = PROG.tARRAY)
|
2019-03-11 09:59:55 +01:00
|
|
|
END isArr;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isProc (e: PARS.EXPR): BOOLEAN;
|
2020-10-13 09:58:51 +02:00
|
|
|
RETURN isExpr(e) & (e._type.typ = PROG.tPROCEDURE) OR (e.obj IN {ePROC, eIMP})
|
2019-03-11 09:59:55 +01:00
|
|
|
END isProc;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isNil (e: PARS.EXPR): BOOLEAN;
|
2020-10-13 09:58:51 +02:00
|
|
|
RETURN e._type.typ = PROG.tNIL
|
2019-03-11 09:59:55 +01:00
|
|
|
END isNil;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE isCharArray (e: PARS.EXPR): BOOLEAN;
|
2020-10-13 09:58:51 +02:00
|
|
|
RETURN isArr(e) & (e._type.base = tCHAR)
|
2019-09-26 22:23:06 +02:00
|
|
|
END isCharArray;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isCharArrayW (e: PARS.EXPR): BOOLEAN;
|
2020-10-13 09:58:51 +02:00
|
|
|
RETURN isArr(e) & (e._type.base = tWCHAR)
|
2019-09-26 22:23:06 +02:00
|
|
|
END isCharArrayW;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isCharArrayX (e: PARS.EXPR): BOOLEAN;
|
|
|
|
RETURN isCharArray(e) OR isCharArrayW(e)
|
|
|
|
END isCharArrayX;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE getpos (parser: PARS.PARSER; VAR pos: PARS.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
|
2019-03-11 09:59:55 +01:00
|
|
|
END getpos;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE NextPos (parser: PARS.PARSER; VAR pos: PARS.POSITION);
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.Next(parser);
|
|
|
|
getpos(parser, pos)
|
2019-03-11 09:59:55 +01:00
|
|
|
END NextPos;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE strlen (e: PARS.EXPR): INTEGER;
|
|
|
|
VAR
|
|
|
|
res: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
ASSERT(isString(e));
|
2020-10-13 09:58:51 +02:00
|
|
|
IF e._type = tCHAR THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
res := 1
|
|
|
|
ELSE
|
|
|
|
res := LENGTH(e.value.string(SCAN.IDENT).s)
|
|
|
|
END
|
|
|
|
RETURN res
|
|
|
|
END strlen;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE _length (s: ARRAY OF CHAR): INTEGER;
|
|
|
|
VAR
|
|
|
|
i, res: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
i := 0;
|
|
|
|
res := 0;
|
|
|
|
WHILE (i < LEN(s)) & (s[i] # 0X) DO
|
|
|
|
IF (s[i] <= CHR(127)) OR (s[i] >= CHR(192)) THEN
|
|
|
|
INC(res)
|
|
|
|
END;
|
|
|
|
INC(i)
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN res
|
|
|
|
END _length;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE utf8strlen (e: PARS.EXPR): INTEGER;
|
|
|
|
VAR
|
|
|
|
res: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
ASSERT(isStringW(e));
|
2020-10-13 09:58:51 +02:00
|
|
|
IF e._type.typ IN {PROG.tCHAR, PROG.tWCHAR} THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
res := 1
|
|
|
|
ELSE
|
|
|
|
res := _length(e.value.string(SCAN.IDENT).s)
|
|
|
|
END
|
|
|
|
RETURN res
|
|
|
|
END utf8strlen;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE StrToWChar (s: ARRAY OF CHAR): INTEGER;
|
|
|
|
VAR
|
|
|
|
res: ARRAY 2 OF WCHAR;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
ASSERT(STRINGS.Utf8To16(s, res) = 1)
|
|
|
|
RETURN ORD(res[0])
|
|
|
|
END StrToWChar;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isStringW1 (e: PARS.EXPR): BOOLEAN;
|
2020-10-13 09:58:51 +02:00
|
|
|
RETURN isString(e) & (utf8strlen(e) = 1) & (strlen(e) > 1)
|
2019-03-11 09:59:55 +01:00
|
|
|
END isStringW1;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE assigncomp (e: PARS.EXPR; t: PROG._TYPE): BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
res: BOOLEAN;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF isExpr(e) OR (e.obj IN {ePROC, eIMP}) THEN
|
2019-10-06 19:55:12 +02:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF t = e._type THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
res := TRUE
|
|
|
|
ELSIF isInt(e) & (t.typ IN {PROG.tBYTE, PROG.tINTEGER}) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IF (e.obj = eCONST) & (t = tBYTE) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
res := ARITH.range(e.value, 0, 255)
|
|
|
|
ELSE
|
|
|
|
res := TRUE
|
|
|
|
END
|
2019-10-06 19:55:12 +02:00
|
|
|
ELSIF
|
|
|
|
(e.obj = eCONST) & isChar(e) & (t = tWCHAR)
|
|
|
|
OR isStringW1(e) & (t = tWCHAR)
|
2020-10-13 09:58:51 +02:00
|
|
|
OR PROG.isBaseOf(t, e._type)
|
|
|
|
OR ~PROG.isOpenArray(t) & ~PROG.isOpenArray(e._type) & PROG.isTypeEq(t, e._type)
|
2019-10-06 19:55:12 +02:00
|
|
|
OR isNil(e) & (t.typ IN {PROG.tPOINTER, PROG.tPROCEDURE})
|
2020-10-13 09:58:51 +02:00
|
|
|
OR PROG.arrcomp(e._type, t)
|
2019-10-06 19:55:12 +02:00
|
|
|
OR isString(e) & (t.typ = PROG.tARRAY) & (t.base = tCHAR) & (t.length > strlen(e))
|
|
|
|
OR isStringW(e) & (t.typ = PROG.tARRAY) & (t.base = tWCHAR) & (t.length > utf8strlen(e))
|
|
|
|
THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
res := TRUE
|
|
|
|
ELSE
|
|
|
|
res := FALSE
|
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
res := FALSE
|
|
|
|
END
|
2019-10-06 19:55:12 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
RETURN res
|
|
|
|
END assigncomp;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE String (e: PARS.EXPR): INTEGER;
|
|
|
|
VAR
|
|
|
|
offset: INTEGER;
|
|
|
|
string: SCAN.IDENT;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF strlen(e) # 1 THEN
|
|
|
|
string := e.value.string(SCAN.IDENT);
|
|
|
|
IF string.offset = -1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
string.offset := IL.putstr(string.s);
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
offset := string.offset
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
offset := IL.putstr1(ARITH.Int(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
RETURN offset
|
|
|
|
END String;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE StringW (e: PARS.EXPR): INTEGER;
|
|
|
|
VAR
|
|
|
|
offset: INTEGER;
|
|
|
|
string: SCAN.IDENT;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF utf8strlen(e) # 1 THEN
|
|
|
|
string := e.value.string(SCAN.IDENT);
|
|
|
|
IF string.offsetW = -1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
string.offsetW := IL.putstrW(string.s);
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
offset := string.offsetW
|
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IF e._type.typ IN {PROG.tWCHAR, PROG.tCHAR} THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
offset := IL.putstrW1(ARITH.Int(e.value))
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSE (* e._type.typ = PROG.tSTRING *)
|
2019-03-11 09:59:55 +01:00
|
|
|
string := e.value.string(SCAN.IDENT);
|
|
|
|
IF string.offsetW = -1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
string.offsetW := IL.putstrW(string.s);
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
offset := string.offsetW
|
|
|
|
END
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN offset
|
|
|
|
END StringW;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE CheckRange (range, line, errno: INTEGER);
|
|
|
|
VAR
|
|
|
|
label: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
2019-09-26 22:23:06 +02:00
|
|
|
label := IL.NewLabel();
|
|
|
|
IL.AddCmd2(IL.opCHKIDX, label, range);
|
|
|
|
IL.OnError(line, errno);
|
|
|
|
IL.SetLabel(label)
|
2019-03-11 09:59:55 +01:00
|
|
|
END CheckRange;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE Float (parser: PARS.PARSER; e: PARS.EXPR);
|
|
|
|
VAR
|
|
|
|
pos: PARS.POSITION;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
getpos(parser, pos);
|
|
|
|
IL.Float(ARITH.Float(e.value), pos.line, pos.col)
|
|
|
|
END Float;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE assign (parser: PARS.PARSER; e: PARS.EXPR; VarType: PROG._TYPE; line: INTEGER): BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2020-05-25 22:48:33 +02:00
|
|
|
res: BOOLEAN;
|
|
|
|
label: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF isExpr(e) OR (e.obj IN {ePROC, eIMP}) THEN
|
|
|
|
res := TRUE;
|
2020-10-13 09:58:51 +02:00
|
|
|
IF PROG.arrcomp(e._type, VarType) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF ~PROG.isOpenArray(VarType) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Const(VarType.length)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opCOPYA, VarType.base.size);
|
|
|
|
label := IL.NewLabel();
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddJmpCmd(IL.opJNZ, label);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.OnError(line, errCOPY);
|
|
|
|
IL.SetLabel(label)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSIF isInt(e) & (VarType.typ IN {PROG.tBYTE, PROG.tINTEGER}) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IF VarType = tINTEGER THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opSAVEC, ARITH.Int(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opSAVE)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
res := ARITH.range(e.value, 0, 255);
|
|
|
|
IF res THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opSAVE8C, ARITH.Int(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IF chkBYTE IN Options.checking THEN
|
|
|
|
label := IL.NewLabel();
|
|
|
|
IL.AddCmd2(IL.opCHKBYTE, label, 0);
|
|
|
|
IL.OnError(line, errBYTE);
|
|
|
|
IL.SetLabel(label)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opSAVE8)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
2019-09-26 22:23:06 +02:00
|
|
|
ELSIF isSet(e) & (VarType = tSET) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opSAVEC, ARITH.Int(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opSAVE)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
2019-09-26 22:23:06 +02:00
|
|
|
ELSIF isBoolean(e) & (VarType = tBOOLEAN) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opSBOOLC, ARITH.Int(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opSBOOL)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
2019-09-26 22:23:06 +02:00
|
|
|
ELSIF isReal(e) & (VarType = tREAL) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
Float(parser, e)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2020-05-25 22:48:33 +02:00
|
|
|
IL.savef(e.obj = eCONST)
|
2019-09-26 22:23:06 +02:00
|
|
|
ELSIF isChar(e) & (VarType = tCHAR) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opSAVE8C, ARITH.Int(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opSAVE8)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
2019-09-26 22:23:06 +02:00
|
|
|
ELSIF (e.obj = eCONST) & isChar(e) & (VarType = tWCHAR) THEN
|
|
|
|
IL.AddCmd(IL.opSAVE16C, ARITH.Int(e.value))
|
|
|
|
ELSIF isStringW1(e) & (VarType = tWCHAR) THEN
|
|
|
|
IL.AddCmd(IL.opSAVE16C, StrToWChar(e.value.string(SCAN.IDENT).s))
|
|
|
|
ELSIF isCharW(e) & (VarType = tWCHAR) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opSAVE16C, ARITH.Int(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opSAVE16)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF PROG.isBaseOf(VarType, e._type) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
IF VarType.typ = PROG.tPOINTER THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opSAVE)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opCOPY, VarType.size)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF (e._type.typ = PROG.tCARD32) & (VarType.typ = PROG.tCARD32) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opSAVE32)
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF ~PROG.isOpenArray(VarType) & ~PROG.isOpenArray(e._type) & PROG.isTypeEq(VarType, e._type) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = ePROC THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AssignProc(e.ident.proc.label)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e.obj = eIMP THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AssignImpProc(e.ident._import)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
IF VarType.typ = PROG.tPROCEDURE THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opSAVE)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opCOPY, VarType.size)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
|
|
|
ELSIF isNil(e) & (VarType.typ IN {PROG.tPOINTER, PROG.tPROCEDURE}) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opSAVEC, 0)
|
|
|
|
ELSIF isString(e) & ((VarType.typ = PROG.tARRAY) & (VarType.base = tCHAR) & (VarType.length > strlen(e))) THEN
|
|
|
|
IL.saves(String(e), strlen(e) + 1)
|
|
|
|
ELSIF isStringW(e) & ((VarType.typ = PROG.tARRAY) & (VarType.base = tWCHAR) & (VarType.length > utf8strlen(e))) THEN
|
|
|
|
IL.saves(StringW(e), (utf8strlen(e) + 1) * 2)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
res := FALSE
|
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
res := FALSE
|
|
|
|
END
|
|
|
|
RETURN res
|
|
|
|
END assign;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE LoadConst (e: PARS.EXPR);
|
|
|
|
BEGIN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Const(ARITH.Int(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
END LoadConst;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE paramcomp (parser: PARS.PARSER; pos: PARS.POSITION; e: PARS.EXPR; p: PROG.PARAM);
|
|
|
|
VAR
|
|
|
|
stroffs: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PROCEDURE arrcomp (e: PARS.EXPR; p: PROG.PARAM): BOOLEAN;
|
|
|
|
VAR
|
2020-10-13 09:58:51 +02:00
|
|
|
t1, t2: PROG._TYPE;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
t1 := p._type;
|
|
|
|
t2 := e._type;
|
2019-03-11 09:59:55 +01:00
|
|
|
WHILE (t2.typ = PROG.tARRAY) & PROG.isOpenArray(t1) DO
|
|
|
|
t1 := t1.base;
|
|
|
|
t2 := t2.base
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN PROG.isTypeEq(t1, t2)
|
|
|
|
END arrcomp;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE ArrLen (t: PROG._TYPE; n: INTEGER): INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
res: INTEGER;
|
2020-05-25 22:48:33 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
REPEAT
|
|
|
|
res := t.length;
|
|
|
|
t := t.base;
|
|
|
|
DEC(n)
|
|
|
|
UNTIL (n < 0) OR (t.typ # PROG.tARRAY);
|
|
|
|
ASSERT(n < 0)
|
|
|
|
RETURN res
|
|
|
|
END ArrLen;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE OpenArray (t, t2: PROG._TYPE);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2020-05-25 22:48:33 +02:00
|
|
|
n, d1, d2: INTEGER;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
IF t.length # 0 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Param1;
|
2019-03-11 09:59:55 +01:00
|
|
|
n := PROG.Dim(t2) - 1;
|
|
|
|
WHILE n >= 0 DO
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Const(ArrLen(t, n));
|
|
|
|
IL.Param1;
|
2019-03-11 09:59:55 +01:00
|
|
|
DEC(n)
|
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
d1 := PROG.Dim(t);
|
|
|
|
d2 := PROG.Dim(t2);
|
|
|
|
IF d1 # d2 THEN
|
|
|
|
n := d2 - d1;
|
|
|
|
WHILE d2 > d1 DO
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Const(ArrLen(t, d2 - 1));
|
2019-03-11 09:59:55 +01:00
|
|
|
DEC(d2)
|
|
|
|
END;
|
|
|
|
d2 := PROG.Dim(t2);
|
|
|
|
WHILE n > 0 DO
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opROT, d2);
|
2019-03-11 09:59:55 +01:00
|
|
|
DEC(n)
|
|
|
|
END
|
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opPARAM, PROG.Dim(t2) + 1)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END OpenArray;
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF p.vPar THEN
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isVar(e), pos, 93);
|
2020-10-13 09:58:51 +02:00
|
|
|
IF p._type.typ = PROG.tRECORD THEN
|
|
|
|
PARS.check(PROG.isBaseOf(p._type, e._type), pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eVREC THEN
|
|
|
|
IF e.ident # NIL THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opVADR, e.ident.offset - 1)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opPUSHT)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.Const(e._type.num)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opPARAM, 2)
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF PROG.isOpenArray(p._type) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(arrcomp(e, p), pos, 66);
|
2020-10-13 09:58:51 +02:00
|
|
|
OpenArray(e._type, p._type)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
PARS.check(PROG.isTypeEq(e._type, p._type), pos, 66);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Param1
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(~e.readOnly, pos, 94)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isExpr(e) OR isProc(e), pos, 66);
|
2020-10-13 09:58:51 +02:00
|
|
|
IF PROG.isOpenArray(p._type) THEN
|
|
|
|
IF e._type.typ = PROG.tARRAY THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(arrcomp(e, p), pos, 66);
|
2020-10-13 09:58:51 +02:00
|
|
|
OpenArray(e._type, p._type)
|
|
|
|
ELSIF isString(e) & (p._type.typ = PROG.tARRAY) & (p._type.base = tCHAR) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.StrAdr(String(e));
|
|
|
|
IL.Param1;
|
|
|
|
IL.Const(strlen(e) + 1);
|
|
|
|
IL.Param1
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF isStringW(e) & (p._type.typ = PROG.tARRAY) & (p._type.base = tWCHAR) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.StrAdr(StringW(e));
|
|
|
|
IL.Param1;
|
|
|
|
IL.Const(utf8strlen(e) + 1);
|
|
|
|
IL.Param1
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.error(pos, 66)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
PARS.check(~PROG.isOpenArray(e._type), pos, 66);
|
|
|
|
PARS.check(assigncomp(e, p._type), pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF e._type = tREAL THEN
|
|
|
|
Float(parser, e);
|
|
|
|
IL.AddCmd0(IL.opPUSHF)
|
|
|
|
ELSIF e._type.typ = PROG.tNIL THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Const(0);
|
|
|
|
IL.Param1
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF isStringW1(e) & (p._type = tWCHAR) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Const(StrToWChar(e.value.string(SCAN.IDENT).s));
|
|
|
|
IL.Param1
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF (e._type.typ = PROG.tSTRING) OR
|
|
|
|
(e._type.typ IN {PROG.tCHAR, PROG.tWCHAR}) & (p._type.typ = PROG.tARRAY) & (p._type.base.typ IN {PROG.tCHAR, PROG.tWCHAR}) THEN
|
|
|
|
IF p._type.base = tCHAR THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
stroffs := String(e);
|
|
|
|
IL.StrAdr(stroffs);
|
2020-10-13 09:58:51 +02:00
|
|
|
IF (CPU = TARGETS.cpuMSP430) & (p._type.size - strlen(e) - 1 > MSP430.IntVectorSize) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
ERRORS.WarningMsg(pos.line, pos.col, 0)
|
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE (* WCHAR *)
|
2019-09-26 22:23:06 +02:00
|
|
|
stroffs := StringW(e);
|
|
|
|
IL.StrAdr(stroffs)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.set_dmin(stroffs + p._type.size);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Param1
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
LoadConst(e);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Param1
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSIF e.obj = ePROC THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(e.ident.global, pos, 85);
|
|
|
|
IL.PushProc(e.ident.proc.label);
|
|
|
|
IL.Param1
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e.obj = eIMP THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.PushImpProc(e.ident._import);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Param1
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF isExpr(e) & (e._type = tREAL) THEN
|
|
|
|
IL.AddCmd0(IL.opPUSHF)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IF (p._type = tBYTE) & (e._type = tINTEGER) & (chkBYTE IN Options.checking) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
CheckRange(256, pos.line, errBYTE)
|
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Param1
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
|
|
|
|
|
|
|
END
|
|
|
|
END paramcomp;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE PExpression (parser: PARS.PARSER; VAR e: PARS.EXPR);
|
|
|
|
BEGIN
|
|
|
|
parser.expression(parser, e)
|
|
|
|
END PExpression;
|
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE stProc (parser: PARS.PARSER; VAR e: PARS.EXPR);
|
|
|
|
VAR
|
2020-05-25 22:48:33 +02:00
|
|
|
e1, e2: PARS.EXPR;
|
|
|
|
pos: PARS.POSITION;
|
|
|
|
proc,
|
|
|
|
label,
|
2020-10-13 09:58:51 +02:00
|
|
|
size,
|
2020-05-25 22:48:33 +02:00
|
|
|
n, i: INTEGER;
|
|
|
|
code: ARITH.VALUE;
|
|
|
|
wchar,
|
|
|
|
comma: BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
cmd1,
|
2020-05-25 22:48:33 +02:00
|
|
|
cmd2: IL.COMMAND;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE varparam (parser: PARS.PARSER; pos: PARS.POSITION; isfunc: isXXX; readOnly: BOOLEAN; VAR e: PARS.EXPR);
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
parser.designator(parser, e);
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isVar(e), pos, 93);
|
|
|
|
PARS.check(isfunc(e), pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF readOnly THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(~e.readOnly, pos, 94)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END varparam;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE shift_minmax (proc: INTEGER): CHAR;
|
|
|
|
VAR
|
|
|
|
res: CHAR;
|
2020-05-25 22:48:33 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
CASE proc OF
|
|
|
|
|PROG.stASR: res := "A"
|
|
|
|
|PROG.stLSL: res := "L"
|
|
|
|
|PROG.stROR: res := "O"
|
|
|
|
|PROG.stLSR: res := "R"
|
|
|
|
|PROG.stMIN: res := "m"
|
|
|
|
|PROG.stMAX: res := "x"
|
|
|
|
END
|
|
|
|
RETURN res
|
|
|
|
END shift_minmax;
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
ASSERT(e.obj IN {eSTPROC, eSTFUNC, eSYSPROC, eSYSFUNC});
|
2019-09-26 22:23:06 +02:00
|
|
|
proc := e.stproc;
|
|
|
|
|
|
|
|
(* IF (proc # PROG.sysNOP) & (proc # PROG.sysEINT) & (proc # PROG.sysDINT) THEN *)
|
|
|
|
PARS.checklex(parser, SCAN.lxLROUND);
|
|
|
|
PARS.Next(parser);
|
|
|
|
(* END; *)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
getpos(parser, pos);
|
|
|
|
|
|
|
|
IF e.obj IN {eSYSPROC, eSYSFUNC} THEN
|
|
|
|
IF parser.unit.scopeLvl > 0 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
parser.unit.scopes[parser.unit.scopeLvl].enter(IL.COMMAND).allocReg := FALSE
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF e.obj IN {eSTPROC, eSYSPROC} THEN
|
|
|
|
|
|
|
|
CASE proc OF
|
|
|
|
|PROG.stASSERT:
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e);
|
|
|
|
PARS.check(isBoolean(e), pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
IF ~ARITH.getBool(e.value) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.OnError(pos.line, errASSERT)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
label := IL.NewLabel();
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.not;
|
|
|
|
IL.AndOrOpt(label);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.OnError(pos.line, errASSERT);
|
|
|
|
IL.SetLabel(label)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
|PROG.stINC, PROG.stDEC:
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.pushBegEnd(begcall, endcall);
|
2019-03-11 09:59:55 +01:00
|
|
|
varparam(parser, pos, isInt, TRUE, e);
|
2020-10-13 09:58:51 +02:00
|
|
|
IF e._type = tINTEGER THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
IF parser.sym = SCAN.lxCOMMA THEN
|
|
|
|
NextPos(parser, pos);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.setlast(begcall);
|
|
|
|
PExpression(parser, e2);
|
|
|
|
IL.setlast(endcall.prev(IL.COMMAND));
|
|
|
|
PARS.check(isInt(e2), pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e2.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opINCC, ARITH.Int(e2.value) * (ORD(proc = PROG.stINC) * 2 - 1))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opINC + ORD(proc = PROG.stDEC))
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opINCC, ORD(proc = PROG.stINC) * 2 - 1)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSE (* e._type = tBYTE *)
|
2019-03-11 09:59:55 +01:00
|
|
|
IF parser.sym = SCAN.lxCOMMA THEN
|
|
|
|
NextPos(parser, pos);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.setlast(begcall);
|
|
|
|
PExpression(parser, e2);
|
|
|
|
IL.setlast(endcall.prev(IL.COMMAND));
|
|
|
|
PARS.check(isInt(e2), pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e2.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opINCCB + ORD(proc = PROG.stDEC), ARITH.Int(e2.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opINCB + ORD(proc = PROG.stDEC))
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opINCCB + ORD(proc = PROG.stDEC), 1)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.popBegEnd(begcall, endcall)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|PROG.stINCL, PROG.stEXCL:
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.pushBegEnd(begcall, endcall);
|
2019-03-11 09:59:55 +01:00
|
|
|
varparam(parser, pos, isSet, TRUE, e);
|
|
|
|
PARS.checklex(parser, SCAN.lxCOMMA);
|
|
|
|
NextPos(parser, pos);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.setlast(begcall);
|
|
|
|
PExpression(parser, e2);
|
|
|
|
IL.setlast(endcall.prev(IL.COMMAND));
|
|
|
|
PARS.check(isInt(e2), pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e2.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(ARITH.range(e2.value, 0, UTILS.target.maxSet), pos, 56);
|
|
|
|
IL.AddCmd(IL.opINCLC + ORD(proc = PROG.stEXCL), ARITH.Int(e2.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opINCL + ORD(proc = PROG.stEXCL))
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.popBegEnd(begcall, endcall)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|PROG.stNEW:
|
|
|
|
varparam(parser, pos, isPtr, TRUE, e);
|
2020-05-25 22:48:33 +02:00
|
|
|
IF CPU = TARGETS.cpuMSP430 THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
PARS.check(e._type.base.size + 16 < Options.ram, pos, 63)
|
2019-09-26 22:23:06 +02:00
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.New(e._type.base.size, e._type.base.num)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|PROG.stDISPOSE:
|
|
|
|
varparam(parser, pos, isPtr, TRUE, e);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opDISP)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|PROG.stPACK:
|
|
|
|
varparam(parser, pos, isReal, TRUE, e);
|
|
|
|
PARS.checklex(parser, SCAN.lxCOMMA);
|
|
|
|
NextPos(parser, pos);
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e2);
|
|
|
|
PARS.check(isInt(e2), pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e2.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opPACKC, ARITH.Int(e2.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opPACK)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
|PROG.stUNPK:
|
|
|
|
varparam(parser, pos, isReal, TRUE, e);
|
|
|
|
PARS.checklex(parser, SCAN.lxCOMMA);
|
|
|
|
NextPos(parser, pos);
|
|
|
|
varparam(parser, pos, isInteger, TRUE, e2);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opUNPK)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|PROG.stCOPY:
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.pushBegEnd(begcall, endcall);
|
|
|
|
PExpression(parser, e);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF isString(e) OR isCharArray(e) THEN
|
|
|
|
wchar := FALSE
|
|
|
|
ELSIF isStringW(e) OR isCharArrayW(e) THEN
|
|
|
|
wchar := TRUE
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.error(pos, 66)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF isCharArrayX(e) & ~PROG.isOpenArray(e._type) THEN
|
|
|
|
IL.Const(e._type.length)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
PARS.checklex(parser, SCAN.lxCOMMA);
|
|
|
|
NextPos(parser, pos);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.setlast(begcall);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF wchar THEN
|
|
|
|
varparam(parser, pos, isCharArrayW, TRUE, e1)
|
|
|
|
ELSE
|
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
varparam(parser, pos, isCharArrayX, TRUE, e1)
|
|
|
|
ELSE
|
|
|
|
varparam(parser, pos, isCharArray, TRUE, e1)
|
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
wchar := e1._type.base = tWCHAR
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF ~PROG.isOpenArray(e1._type) THEN
|
|
|
|
IL.Const(e1._type.length)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.setlast(endcall.prev(IL.COMMAND));
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
IF wchar THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.StrAdr(StringW(e));
|
|
|
|
IL.Const(utf8strlen(e) + 1)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.StrAdr(String(e));
|
|
|
|
IL.Const(strlen(e) + 1)
|
|
|
|
END
|
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd(IL.opCOPYS, e1._type.base.size);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.popBegEnd(begcall, endcall)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|PROG.sysGET, PROG.sysGET8, PROG.sysGET16, PROG.sysGET32:
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e);
|
|
|
|
PARS.check(isInt(e), pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
PARS.checklex(parser, SCAN.lxCOMMA);
|
|
|
|
NextPos(parser, pos);
|
|
|
|
parser.designator(parser, e2);
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isVar(e2), pos, 93);
|
2020-10-13 09:58:51 +02:00
|
|
|
IF proc = PROG.sysGET THEN
|
|
|
|
PARS.check(e2._type.typ IN PROG.BASICTYPES + {PROG.tPOINTER, PROG.tPROCEDURE}, pos, 66)
|
|
|
|
ELSE
|
|
|
|
PARS.check(e2._type.typ IN {PROG.tINTEGER, PROG.tBYTE, PROG.tCHAR, PROG.tSET, PROG.tWCHAR, PROG.tCARD32}, pos, 66)
|
|
|
|
END;
|
|
|
|
|
|
|
|
CASE proc OF
|
|
|
|
|PROG.sysGET: size := e2._type.size
|
|
|
|
|PROG.sysGET8: size := 1
|
|
|
|
|PROG.sysGET16: size := 2
|
|
|
|
|PROG.sysGET32: size := 4
|
|
|
|
END;
|
|
|
|
|
|
|
|
PARS.check(size <= e2._type.size, pos, 66);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF e.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd2(IL.opGETC, ARITH.Int(e.value), size)
|
2019-09-26 22:23:06 +02:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd(IL.opGET, size)
|
2019-09-26 22:23:06 +02:00
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|PROG.sysPUT, PROG.sysPUT8, PROG.sysPUT16, PROG.sysPUT32:
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.pushBegEnd(begcall, endcall);
|
|
|
|
PExpression(parser, e);
|
|
|
|
PARS.check(isInt(e), pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
LoadConst(e)
|
|
|
|
END;
|
|
|
|
PARS.checklex(parser, SCAN.lxCOMMA);
|
|
|
|
NextPos(parser, pos);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.setlast(begcall);
|
|
|
|
PExpression(parser, e2);
|
|
|
|
PARS.check(isExpr(e2), pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF proc = PROG.sysPUT THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
PARS.check(e2._type.typ IN PROG.BASICTYPES + {PROG.tPOINTER, PROG.tPROCEDURE}, pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e2.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF e2._type = tREAL THEN
|
|
|
|
Float(parser, e2);
|
2020-05-25 22:48:33 +02:00
|
|
|
IL.setlast(endcall.prev(IL.COMMAND));
|
|
|
|
IL.savef(FALSE)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
LoadConst(e2);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.setlast(endcall.prev(IL.COMMAND));
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.SysPut(e2._type.size)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.setlast(endcall.prev(IL.COMMAND));
|
2020-10-13 09:58:51 +02:00
|
|
|
IF e2._type = tREAL THEN
|
2020-05-25 22:48:33 +02:00
|
|
|
IL.savef(FALSE)
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF e2._type = tBYTE THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.SysPut(tINTEGER.size)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.SysPut(e2._type.size)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
|
|
|
|
|
|
|
ELSIF (proc = PROG.sysPUT8) OR (proc = PROG.sysPUT16) OR (proc = PROG.sysPUT32) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
PARS.check(e2._type.typ IN {PROG.tINTEGER, PROG.tBYTE, PROG.tCHAR, PROG.tSET, PROG.tWCHAR, PROG.tCARD32}, pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e2.obj = eCONST THEN
|
|
|
|
LoadConst(e2)
|
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.setlast(endcall.prev(IL.COMMAND));
|
|
|
|
CASE proc OF
|
2020-10-13 09:58:51 +02:00
|
|
|
|PROG.sysPUT8: size := 1
|
|
|
|
|PROG.sysPUT16: size := 2
|
|
|
|
|PROG.sysPUT32: size := 4
|
|
|
|
END;
|
|
|
|
IL.SysPut(size)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.popBegEnd(begcall, endcall)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|PROG.sysMOVE:
|
|
|
|
FOR i := 1 TO 2 DO
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e);
|
|
|
|
PARS.check(isInt(e), pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
LoadConst(e)
|
|
|
|
END;
|
|
|
|
PARS.checklex(parser, SCAN.lxCOMMA);
|
|
|
|
NextPos(parser, pos)
|
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e);
|
|
|
|
PARS.check(isInt(e), pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
LoadConst(e)
|
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opMOVE)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|PROG.sysCOPY:
|
|
|
|
FOR i := 1 TO 2 DO
|
|
|
|
parser.designator(parser, e);
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isVar(e), pos, 93);
|
2020-10-13 09:58:51 +02:00
|
|
|
n := PROG.Dim(e._type);
|
2019-03-11 09:59:55 +01:00
|
|
|
WHILE n > 0 DO
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.drop;
|
2019-03-11 09:59:55 +01:00
|
|
|
DEC(n)
|
|
|
|
END;
|
|
|
|
PARS.checklex(parser, SCAN.lxCOMMA);
|
|
|
|
NextPos(parser, pos)
|
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e);
|
|
|
|
PARS.check(isInt(e), pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
LoadConst(e)
|
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opMOVE)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|PROG.sysCODE:
|
|
|
|
REPEAT
|
|
|
|
getpos(parser, pos);
|
|
|
|
PARS.ConstExpression(parser, code);
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(code.typ = ARITH.tINTEGER, pos, 43);
|
2020-10-13 09:58:51 +02:00
|
|
|
IF TARGETS.WordSize > TARGETS.InstrSize THEN
|
|
|
|
CASE TARGETS.InstrSize OF
|
|
|
|
|1: PARS.check(ARITH.range(code, 0, 255), pos, 42)
|
|
|
|
|2: PARS.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
|
2019-03-11 09:59:55 +01:00
|
|
|
PARS.Next(parser)
|
|
|
|
ELSE
|
|
|
|
PARS.checklex(parser, SCAN.lxRROUND)
|
2019-09-26 22:23:06 +02:00
|
|
|
END
|
|
|
|
UNTIL (parser.sym = SCAN.lxRROUND) & ~comma
|
|
|
|
(*
|
|
|
|
|PROG.sysNOP, PROG.sysDINT, PROG.sysEINT:
|
|
|
|
IF parser.sym = SCAN.lxLROUND THEN
|
|
|
|
PARS.Next(parser);
|
|
|
|
PARS.checklex(parser, SCAN.lxRROUND);
|
|
|
|
PARS.Next(parser)
|
|
|
|
END;
|
|
|
|
ASSERT(CPU = cpuMSP430);
|
|
|
|
CASE proc OF
|
|
|
|
|PROG.sysNOP: IL.AddCmd(IL.opCODE, 4303H)
|
|
|
|
|PROG.sysDINT: IL.AddCmd(IL.opCODE, 0C232H); IL.AddCmd(IL.opCODE, 4303H)
|
|
|
|
|PROG.sysEINT: IL.AddCmd(IL.opCODE, 0D232H)
|
|
|
|
END
|
|
|
|
*)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
e.obj := eEXPR;
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := NIL
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSIF e.obj IN {eSTFUNC, eSYSFUNC} THEN
|
|
|
|
|
|
|
|
CASE e.stproc OF
|
|
|
|
|PROG.stABS:
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e);
|
|
|
|
PARS.check(isInt(e) OR isReal(e), pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(ARITH.abs(e.value), pos, 39)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.abs(isReal(e))
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
|PROG.stASR, PROG.stLSL, PROG.stROR, PROG.stLSR, PROG.stMIN, PROG.stMAX:
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e);
|
|
|
|
PARS.check(isInt(e), pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
PARS.checklex(parser, SCAN.lxCOMMA);
|
|
|
|
NextPos(parser, pos);
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e2);
|
|
|
|
PARS.check(isInt(e2), pos, 66);
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := tINTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
IF (e.obj = eCONST) & (e2.obj = eCONST) THEN
|
|
|
|
ASSERT(ARITH.opInt(e.value, e2.value, shift_minmax(proc)))
|
|
|
|
ELSE
|
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.shift_minmax1(shift_minmax(proc), ARITH.Int(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e2.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.shift_minmax2(shift_minmax(proc), ARITH.Int(e2.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.shift_minmax(shift_minmax(proc))
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
e.obj := eEXPR
|
|
|
|
END
|
|
|
|
|
|
|
|
|PROG.stCHR:
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e);
|
|
|
|
PARS.check(isInt(e), pos, 66);
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := tCHAR;
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
ARITH.setChar(e.value, ARITH.getInt(e.value));
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(ARITH.check(e.value), pos, 107)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IF chkCHR IN Options.checking THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
CheckRange(256, pos.line, errCHR)
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opCHR)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
|
|
|
|
|
|
|
|PROG.stWCHR:
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e);
|
|
|
|
PARS.check(isInt(e), pos, 66);
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := tWCHAR;
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
ARITH.setWChar(e.value, ARITH.getInt(e.value));
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(ARITH.check(e.value), pos, 101)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IF chkWCHR IN Options.checking THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
CheckRange(65536, pos.line, errWCHR)
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opWCHR)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
|
|
|
|
|
|
|
|PROG.stFLOOR:
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e);
|
|
|
|
PARS.check(isReal(e), pos, 66);
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := tINTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(ARITH.floor(e.value), pos, 39)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd0(IL.opFLOOR)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
|PROG.stFLT:
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e);
|
|
|
|
PARS.check(isInt(e), pos, 66);
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := tREAL;
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
ARITH.flt(e.value)
|
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd2(IL.opFLT, pos.line, pos.col)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
|PROG.stLEN:
|
2019-09-26 22:23:06 +02:00
|
|
|
cmd1 := IL.getlast();
|
2019-03-11 09:59:55 +01:00
|
|
|
varparam(parser, pos, isArr, FALSE, e);
|
2020-10-13 09:58:51 +02:00
|
|
|
IF e._type.length > 0 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
cmd2 := IL.getlast();
|
|
|
|
IL.delete2(cmd1.next, cmd2);
|
|
|
|
IL.setlast(cmd1);
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(ARITH.setInt(e.value, e._type.length));
|
2019-03-11 09:59:55 +01:00
|
|
|
e.obj := eCONST
|
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.len(PROG.Dim(e._type))
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := tINTEGER
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|PROG.stLENGTH:
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF isCharArray(e) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF e._type.length > 0 THEN
|
|
|
|
IL.Const(e._type.length)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opLENGTH)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF isCharArrayW(e) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF e._type.length > 0 THEN
|
|
|
|
IL.Const(e._type.length)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opLENGTHW)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.error(pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := tINTEGER
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|PROG.stODD:
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e);
|
|
|
|
PARS.check(isInt(e), pos, 66);
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := tBOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
ARITH.odd(e.value)
|
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
IL.AddCmd(IL.opMODR, 2)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
|PROG.stORD:
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e);
|
|
|
|
PARS.check(isChar(e) OR isBoolean(e) OR isSet(e) OR isCharW(e) OR isStringW1(e), pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
IF isStringW1(e) THEN
|
|
|
|
ASSERT(ARITH.setInt(e.value, StrToWChar(e.value.string(SCAN.IDENT).s)))
|
|
|
|
ELSE
|
|
|
|
ARITH.ord(e.value)
|
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
IF isBoolean(e) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL._ord
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := tINTEGER
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|PROG.stBITS:
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e);
|
|
|
|
PARS.check(isInt(e), pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
ARITH.bits(e.value)
|
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := tSET
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|PROG.sysADR:
|
|
|
|
parser.designator(parser, e);
|
|
|
|
IF isVar(e) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
n := PROG.Dim(e._type);
|
|
|
|
WHILE n > 0 DO
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.drop;
|
2019-03-11 09:59:55 +01:00
|
|
|
DEC(n)
|
2020-10-13 09:58:51 +02:00
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e.obj = ePROC THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.PushProc(e.ident.proc.label)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e.obj = eIMP THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.PushImpProc(e.ident._import)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.error(pos, 108)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := tINTEGER
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|PROG.sysSADR:
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e);
|
|
|
|
PARS.check(isString(e), pos, 66);
|
|
|
|
IL.StrAdr(String(e));
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := tINTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
e.obj := eEXPR
|
|
|
|
|
|
|
|
|PROG.sysWSADR:
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e);
|
|
|
|
PARS.check(isStringW(e), pos, 66);
|
|
|
|
IL.StrAdr(StringW(e));
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := tINTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
e.obj := eEXPR
|
|
|
|
|
|
|
|
|PROG.sysTYPEID:
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e);
|
|
|
|
PARS.check(e.obj = eTYPE, pos, 68);
|
2020-10-13 09:58:51 +02:00
|
|
|
IF e._type.typ = PROG.tRECORD THEN
|
|
|
|
ASSERT(ARITH.setInt(e.value, e._type.num))
|
|
|
|
ELSIF e._type.typ = PROG.tPOINTER THEN
|
|
|
|
ASSERT(ARITH.setInt(e.value, e._type.base.num))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.error(pos, 52)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
e.obj := eCONST;
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := tINTEGER
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|PROG.sysINF:
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd2(IL.opINF, pos.line, pos.col);
|
2019-03-11 09:59:55 +01:00
|
|
|
e.obj := eEXPR;
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := tREAL
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|PROG.sysSIZE:
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e);
|
|
|
|
PARS.check(e.obj = eTYPE, pos, 68);
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(ARITH.setInt(e.value, e._type.size));
|
2019-03-11 09:59:55 +01:00
|
|
|
e.obj := eCONST;
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := tINTEGER
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
END
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
(* IF (proc # PROG.sysNOP) & (proc # PROG.sysEINT) & (proc # PROG.sysDINT) THEN *)
|
|
|
|
PARS.checklex(parser, SCAN.lxRROUND);
|
|
|
|
PARS.Next(parser);
|
|
|
|
(* END; *)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF e.obj # eCONST THEN
|
|
|
|
e.obj := eEXPR
|
|
|
|
END
|
|
|
|
|
|
|
|
END stProc;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE ActualParameters (parser: PARS.PARSER; VAR e: PARS.EXPR);
|
|
|
|
VAR
|
2020-10-13 09:58:51 +02:00
|
|
|
proc: PROG._TYPE;
|
2019-03-11 09:59:55 +01:00
|
|
|
param: LISTS.ITEM;
|
|
|
|
e1: PARS.EXPR;
|
2019-09-26 22:23:06 +02:00
|
|
|
pos: PARS.POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
ASSERT(parser.sym = SCAN.lxLROUND);
|
|
|
|
|
|
|
|
IF (e.obj IN {ePROC, eIMP}) OR isExpr(e) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
proc := e._type;
|
2019-03-11 09:59:55 +01:00
|
|
|
PARS.check1(proc.typ = PROG.tPROCEDURE, parser, 86);
|
|
|
|
PARS.Next(parser);
|
|
|
|
|
|
|
|
param := proc.params.first;
|
|
|
|
WHILE param # NIL DO
|
|
|
|
getpos(parser, pos);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.setlast(begcall);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF param(PROG.PARAM).vPar THEN
|
|
|
|
parser.designator(parser, e1)
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, e1)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
paramcomp(parser, pos, e1, param(PROG.PARAM));
|
|
|
|
param := param.next;
|
|
|
|
IF param # NIL THEN
|
|
|
|
PARS.checklex(parser, SCAN.lxCOMMA);
|
|
|
|
PARS.Next(parser)
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
PARS.checklex(parser, SCAN.lxRROUND);
|
|
|
|
PARS.Next(parser);
|
|
|
|
|
|
|
|
e.obj := eEXPR;
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := proc.base
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSIF e.obj IN {eSTPROC, eSTFUNC, eSYSPROC, eSYSFUNC} THEN
|
|
|
|
stProc(parser, e)
|
|
|
|
ELSE
|
|
|
|
PARS.check1(FALSE, parser, 86)
|
|
|
|
END
|
|
|
|
|
|
|
|
END ActualParameters;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE qualident (parser: PARS.PARSER; VAR e: PARS.EXPR);
|
|
|
|
VAR
|
2020-10-13 09:58:51 +02:00
|
|
|
ident: PROG.IDENT;
|
|
|
|
imp: BOOLEAN;
|
|
|
|
pos: PARS.POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
PARS.checklex(parser, SCAN.lxIDENT);
|
|
|
|
getpos(parser, pos);
|
2020-10-13 09:58:51 +02:00
|
|
|
imp := FALSE;
|
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
|
|
|
PARS.check1(ident # NIL, parser, 48);
|
|
|
|
IF ident.typ = PROG.idMODULE THEN
|
|
|
|
PARS.ExpectSym(parser, SCAN.lxPOINT);
|
|
|
|
PARS.ExpectSym(parser, SCAN.lxIDENT);
|
2019-09-26 22:23:06 +02:00
|
|
|
ident := PROG.getIdent(ident.unit, parser.lex.ident, FALSE);
|
2019-03-11 09:59:55 +01:00
|
|
|
PARS.check1((ident # NIL) & ident.export, parser, 48);
|
2020-10-13 09:58:51 +02:00
|
|
|
imp := TRUE
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
PARS.Next(parser);
|
|
|
|
|
|
|
|
e.readOnly := FALSE;
|
|
|
|
e.ident := ident;
|
|
|
|
|
|
|
|
CASE ident.typ OF
|
|
|
|
|PROG.idCONST:
|
|
|
|
e.obj := eCONST;
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := ident._type;
|
2019-03-11 09:59:55 +01:00
|
|
|
e.value := ident.value
|
|
|
|
|PROG.idTYPE:
|
2020-10-13 09:58:51 +02:00
|
|
|
e.obj := eTYPE;
|
|
|
|
e._type := ident._type
|
2019-03-11 09:59:55 +01:00
|
|
|
|PROG.idVAR:
|
2020-10-13 09:58:51 +02:00
|
|
|
e.obj := eVAR;
|
|
|
|
e._type := ident._type;
|
|
|
|
e.readOnly := imp
|
2019-03-11 09:59:55 +01:00
|
|
|
|PROG.idPROC:
|
|
|
|
e.obj := ePROC;
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := ident._type
|
2019-03-11 09:59:55 +01:00
|
|
|
|PROG.idIMP:
|
|
|
|
e.obj := eIMP;
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := ident._type
|
2019-03-11 09:59:55 +01:00
|
|
|
|PROG.idVPAR:
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := ident._type;
|
|
|
|
IF e._type.typ = PROG.tRECORD THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
e.obj := eVREC
|
|
|
|
ELSE
|
|
|
|
e.obj := eVPAR
|
|
|
|
END
|
|
|
|
|PROG.idPARAM:
|
2020-10-13 09:58:51 +02:00
|
|
|
e.obj := ePARAM;
|
|
|
|
e._type := ident._type;
|
|
|
|
e.readOnly := (e._type.typ IN {PROG.tRECORD, PROG.tARRAY})
|
2019-03-11 09:59:55 +01:00
|
|
|
|PROG.idSTPROC:
|
|
|
|
e.obj := eSTPROC;
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := ident._type;
|
2019-03-11 09:59:55 +01:00
|
|
|
e.stproc := ident.stproc
|
|
|
|
|PROG.idSTFUNC:
|
|
|
|
e.obj := eSTFUNC;
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := ident._type;
|
2019-03-11 09:59:55 +01:00
|
|
|
e.stproc := ident.stproc
|
|
|
|
|PROG.idSYSPROC:
|
|
|
|
e.obj := eSYSPROC;
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := ident._type;
|
2019-03-11 09:59:55 +01:00
|
|
|
e.stproc := ident.stproc
|
|
|
|
|PROG.idSYSFUNC:
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(~parser.constexp, pos, 109);
|
2019-03-11 09:59:55 +01:00
|
|
|
e.obj := eSYSFUNC;
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := ident._type;
|
2019-03-11 09:59:55 +01:00
|
|
|
e.stproc := ident.stproc
|
|
|
|
|PROG.idNONE:
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.error(pos, 115)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
IF isVar(e) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(e.ident.global OR (e.ident.scopeLvl = parser.unit.scopeLvl), pos, 105)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
END qualident;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE deref (pos: PARS.POSITION; e: PARS.EXPR; load: BOOLEAN; error: INTEGER);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2020-05-25 22:48:33 +02:00
|
|
|
label: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF load THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.load(e._type.size)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF chkPTR IN Options.checking THEN
|
|
|
|
label := IL.NewLabel();
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddJmpCmd(IL.opJNZ1, label);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.OnError(pos.line, error);
|
|
|
|
IL.SetLabel(label)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END deref;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE designator (parser: PARS.PARSER; VAR e: PARS.EXPR);
|
|
|
|
VAR
|
|
|
|
field: PROG.FIELD;
|
2019-09-26 22:23:06 +02:00
|
|
|
pos: PARS.POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
t, idx: PARS.EXPR;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE LoadAdr (e: PARS.EXPR);
|
|
|
|
VAR
|
|
|
|
offset: INTEGER;
|
|
|
|
|
|
|
|
PROCEDURE OpenArray (e: PARS.EXPR);
|
|
|
|
VAR
|
|
|
|
offset, n: INTEGER;
|
|
|
|
BEGIN
|
|
|
|
offset := e.ident.offset;
|
2020-10-13 09:58:51 +02:00
|
|
|
n := PROG.Dim(e._type);
|
2019-03-11 09:59:55 +01:00
|
|
|
WHILE n >= 0 DO
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opVADR, offset);
|
2019-03-11 09:59:55 +01:00
|
|
|
DEC(offset);
|
|
|
|
DEC(n)
|
|
|
|
END
|
|
|
|
END OpenArray;
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF e.obj = eVAR THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
offset := PROG.getOffset(e.ident);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.ident.global THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opGADR, offset)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opLADR, -offset)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSIF e.obj = ePARAM THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF (e._type.typ = PROG.tRECORD) OR ((e._type.typ = PROG.tARRAY) & (e._type.length > 0)) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opVADR, e.ident.offset)
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF PROG.isOpenArray(e._type) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
OpenArray(e)
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opLADR, e.ident.offset)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSIF e.obj IN {eVPAR, eVREC} THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF PROG.isOpenArray(e._type) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
OpenArray(e)
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opVADR, e.ident.offset)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
|
|
|
END LoadAdr;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE OpenIdx (parser: PARS.PARSER; pos: PARS.POSITION; e: PARS.EXPR);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2020-05-25 22:48:33 +02:00
|
|
|
label, offset, n, k: INTEGER;
|
2020-10-13 09:58:51 +02:00
|
|
|
_type: PROG._TYPE;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF chkIDX IN Options.checking THEN
|
|
|
|
label := IL.NewLabel();
|
|
|
|
IL.AddCmd2(IL.opCHKIDX2, label, 0);
|
|
|
|
IL.OnError(pos.line, errIDX);
|
|
|
|
IL.SetLabel(label)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opCHKIDX2, -1)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
_type := PROG.OpenBase(e._type);
|
|
|
|
IF _type.size # 1 THEN
|
|
|
|
IL.AddCmd(IL.opMULC, _type.size)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
n := PROG.Dim(e._type) - 1;
|
2019-03-11 09:59:55 +01:00
|
|
|
k := n;
|
|
|
|
WHILE n > 0 DO
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opMUL);
|
2019-03-11 09:59:55 +01:00
|
|
|
DEC(n)
|
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opADD);
|
2019-03-11 09:59:55 +01:00
|
|
|
offset := e.ident.offset - 1;
|
|
|
|
n := k;
|
|
|
|
WHILE n > 0 DO
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opVADR, offset);
|
2019-03-11 09:59:55 +01:00
|
|
|
DEC(offset);
|
|
|
|
DEC(n)
|
|
|
|
END
|
|
|
|
END OpenIdx;
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
qualident(parser, e);
|
|
|
|
|
|
|
|
IF e.obj IN {ePROC, eIMP} THEN
|
|
|
|
PROG.UseProc(parser.unit, e.ident.proc)
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF isVar(e) THEN
|
|
|
|
LoadAdr(e)
|
|
|
|
END;
|
|
|
|
|
|
|
|
WHILE parser.sym = SCAN.lxPOINT DO
|
|
|
|
getpos(parser, pos);
|
2020-10-13 09:58:51 +02:00
|
|
|
PARS.check1(isExpr(e) & (e._type.typ IN {PROG.tRECORD, PROG.tPOINTER}), parser, 73);
|
|
|
|
IF e._type.typ = PROG.tPOINTER THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
deref(pos, e, TRUE, errPTR)
|
|
|
|
END;
|
|
|
|
PARS.ExpectSym(parser, SCAN.lxIDENT);
|
2020-10-13 09:58:51 +02:00
|
|
|
IF e._type.typ = PROG.tPOINTER THEN
|
|
|
|
e._type := e._type.base;
|
2019-03-11 09:59:55 +01:00
|
|
|
e.readOnly := FALSE
|
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
field := PROG.getField(e._type, parser.lex.ident, parser.unit);
|
2019-03-11 09:59:55 +01:00
|
|
|
PARS.check1(field # NIL, parser, 74);
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := field._type;
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eVREC THEN
|
|
|
|
e.obj := eVPAR
|
|
|
|
END;
|
|
|
|
IF field.offset # 0 THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd(IL.opADDC, field.offset)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
PARS.Next(parser);
|
|
|
|
e.ident := NIL
|
|
|
|
|
|
|
|
ELSIF parser.sym = SCAN.lxLSQUARE DO
|
|
|
|
|
|
|
|
REPEAT
|
|
|
|
|
|
|
|
PARS.check1(isArr(e), parser, 75);
|
|
|
|
NextPos(parser, pos);
|
2019-09-26 22:23:06 +02:00
|
|
|
PExpression(parser, idx);
|
|
|
|
PARS.check(isInt(idx), pos, 76);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF idx.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF e._type.length > 0 THEN
|
|
|
|
PARS.check(ARITH.range(idx.value, 0, e._type.length - 1), pos, 83);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF ARITH.Int(idx.value) > 0 THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd(IL.opADDC, ARITH.Int(idx.value) * e._type.base.size)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(ARITH.range(idx.value, 0, UTILS.target.maxInt), pos, 83);
|
2019-03-11 09:59:55 +01:00
|
|
|
LoadConst(idx);
|
|
|
|
OpenIdx(parser, pos, e)
|
|
|
|
END
|
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IF e._type.length > 0 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IF chkIDX IN Options.checking THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
CheckRange(e._type.length, pos.line, errIDX)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
IF e._type.base.size # 1 THEN
|
|
|
|
IL.AddCmd(IL.opMULC, e._type.base.size)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opADD)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
OpenIdx(parser, pos, e)
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := e._type.base
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
UNTIL parser.sym # SCAN.lxCOMMA;
|
|
|
|
|
|
|
|
PARS.checklex(parser, SCAN.lxRSQUARE);
|
|
|
|
PARS.Next(parser);
|
|
|
|
e.ident := NIL
|
|
|
|
|
|
|
|
ELSIF parser.sym = SCAN.lxCARET DO
|
|
|
|
getpos(parser, pos);
|
|
|
|
PARS.check1(isPtr(e), parser, 77);
|
|
|
|
deref(pos, e, TRUE, errPTR);
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := e._type.base;
|
2019-03-11 09:59:55 +01:00
|
|
|
e.readOnly := FALSE;
|
|
|
|
PARS.Next(parser);
|
|
|
|
e.ident := NIL;
|
|
|
|
e.obj := eVREC
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF (parser.sym = SCAN.lxLROUND) & isExpr(e) & (e._type.typ IN {PROG.tRECORD, PROG.tPOINTER}) DO
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF e._type.typ = PROG.tRECORD THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
PARS.check1(e.obj = eVREC, parser, 78)
|
|
|
|
END;
|
|
|
|
NextPos(parser, pos);
|
|
|
|
qualident(parser, t);
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(t.obj = eTYPE, pos, 79);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF e._type.typ = PROG.tRECORD THEN
|
|
|
|
PARS.check(t._type.typ = PROG.tRECORD, pos, 80);
|
2019-09-26 22:23:06 +02:00
|
|
|
IF chkGUARD IN Options.checking THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.ident = NIL THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.TypeGuard(IL.opTYPEGD, t._type.num, pos.line, errGUARD)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opVADR, e.ident.offset - 1);
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.TypeGuard(IL.opTYPEGR, t._type.num, pos.line, errGUARD)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
PARS.check(t._type.typ = PROG.tPOINTER, pos, 81);
|
2019-09-26 22:23:06 +02:00
|
|
|
IF chkGUARD IN Options.checking THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.TypeGuard(IL.opTYPEGP, t._type.base.num, pos.line, errGUARD)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PARS.check(PROG.isBaseOf(e._type, t._type), pos, 82);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := t._type;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PARS.checklex(parser, SCAN.lxRROUND);
|
|
|
|
PARS.Next(parser)
|
|
|
|
|
|
|
|
END
|
|
|
|
|
|
|
|
END designator;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE ProcCall (e: PARS.EXPR; procType: PROG._TYPE; isfloat: BOOLEAN; parser: PARS.PARSER; pos: PARS.POSITION; CallStat: BOOLEAN);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2020-05-25 22:48:33 +02:00
|
|
|
cconv,
|
|
|
|
parSize,
|
|
|
|
callconv,
|
|
|
|
fparSize,
|
|
|
|
int, flt,
|
|
|
|
stk_par: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
cconv := procType.call;
|
2019-09-26 22:23:06 +02:00
|
|
|
parSize := procType.parSize;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF cconv IN {PROG._win64, PROG.win64} THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
callconv := IL.call_win64;
|
|
|
|
fparSize := LSL(ORD(PROG.getFloatParamsPos(procType, 3, int, flt)), 5) + MIN(parSize, 4)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF cconv IN {PROG._systemv, PROG.systemv} THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
callconv := IL.call_sysv;
|
|
|
|
fparSize := LSL(ORD(PROG.getFloatParamsPos(procType, PROG.MAXSYSVPARAM - 1, int, flt)), 5) + parSize;
|
2019-03-11 09:59:55 +01:00
|
|
|
stk_par := MAX(0, int - 6) + MAX(0, flt - 8)
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
callconv := IL.call_stack;
|
|
|
|
fparSize := 0
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.setlast(begcall);
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd(IL.opPRECALL, ORD(isfloat));
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF cconv IN {PROG._ccall16, PROG.ccall16} THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opALIGN16, parSize)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF cconv IN {PROG._win64, PROG.win64} THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opWIN64ALIGN16, parSize)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF cconv IN {PROG._systemv, PROG.systemv} THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opSYSVALIGN16, parSize + stk_par)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.setlast(endcall.prev(IL.COMMAND));
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF e.obj = eIMP THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.CallImp(e.ident._import, callconv, fparSize)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e.obj = ePROC THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Call(e.ident.proc.label, callconv, fparSize)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF isExpr(e) THEN
|
|
|
|
deref(pos, e, CallStat, errPROC);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.CallP(callconv, fparSize)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
IF cconv IN {PROG._ccall16, PROG.ccall16} THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opCLEANUP, parSize);
|
|
|
|
IL.AddCmd0(IL.opPOPSP)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF cconv IN {PROG._win64, PROG.win64} THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opCLEANUP, MAX(parSize + parSize MOD 2, 4) + 1);
|
|
|
|
IL.AddCmd0(IL.opPOPSP)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF cconv IN {PROG._systemv, PROG.systemv} THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opCLEANUP, parSize + stk_par);
|
|
|
|
IL.AddCmd0(IL.opPOPSP)
|
|
|
|
ELSIF cconv IN {PROG._ccall, PROG.ccall, PROG.default16, PROG.code, PROG._code} THEN
|
|
|
|
IL.AddCmd(IL.opCLEANUP, parSize)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF CallStat THEN
|
|
|
|
IL.AddCmd0(IL.opRES);
|
|
|
|
IL.drop
|
|
|
|
ELSE
|
2019-03-11 09:59:55 +01:00
|
|
|
IF isfloat THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd2(IL.opRESF, pos.line, pos.col)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd0(IL.opRES)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
|
|
|
END ProcCall;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE expression (parser: PARS.PARSER; VAR e: PARS.EXPR);
|
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
pos, pos0, pos1: PARS.POSITION;
|
2020-10-13 09:58:51 +02:00
|
|
|
e1: PARS.EXPR;
|
|
|
|
op, cmp, error: INTEGER;
|
|
|
|
constant, eq: BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE relation (sym: INTEGER): BOOLEAN;
|
|
|
|
RETURN (sym = SCAN.lxEQ) OR (sym = SCAN.lxNE) OR
|
|
|
|
(sym = SCAN.lxLT) OR (sym = SCAN.lxLE) OR
|
|
|
|
(sym = SCAN.lxGT) OR (sym = SCAN.lxGE) OR
|
|
|
|
(sym = SCAN.lxIN) OR (sym = SCAN.lxIS)
|
|
|
|
END relation;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE AddOperator (sym: INTEGER): BOOLEAN;
|
|
|
|
RETURN (sym = SCAN.lxPLUS) OR (sym = SCAN.lxMINUS) OR
|
|
|
|
(sym = SCAN.lxOR)
|
|
|
|
END AddOperator;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE MulOperator (sym: INTEGER): BOOLEAN;
|
|
|
|
RETURN (sym = SCAN.lxMUL) OR (sym = SCAN.lxSLASH) OR
|
|
|
|
(sym = SCAN.lxDIV) OR (sym = SCAN.lxMOD) OR
|
|
|
|
(sym = SCAN.lxAND)
|
|
|
|
END MulOperator;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE element (parser: PARS.PARSER; VAR e: PARS.EXPR);
|
|
|
|
VAR
|
|
|
|
e1, e2: PARS.EXPR;
|
2019-09-26 22:23:06 +02:00
|
|
|
pos: PARS.POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
range: BOOLEAN;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
range := FALSE;
|
|
|
|
getpos(parser, pos);
|
|
|
|
expression(parser, e1);
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isInt(e1), pos, 76);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF e1.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(ARITH.range(e1.value, 0, UTILS.target.maxSet), pos, 44)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
range := parser.sym = SCAN.lxRANGE;
|
|
|
|
|
|
|
|
IF range THEN
|
|
|
|
NextPos(parser, pos);
|
|
|
|
expression(parser, e2);
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isInt(e2), pos, 76);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF e2.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(ARITH.range(e2.value, 0, UTILS.target.maxSet), pos, 44)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
IF e1.obj = eCONST THEN
|
|
|
|
e2 := e1
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := tSET;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF (e1.obj = eCONST) & (e2.obj = eCONST) THEN
|
|
|
|
ARITH.constrSet(e.value, e1.value, e2.value);
|
|
|
|
e.obj := eCONST
|
|
|
|
ELSE
|
|
|
|
IF range THEN
|
|
|
|
IF e1.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opRSETL, ARITH.Int(e1.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e2.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opRSETR, ARITH.Int(e2.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opRSET)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opRSET1)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
e.obj := eEXPR
|
|
|
|
END
|
|
|
|
|
|
|
|
END element;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE set (parser: PARS.PARSER; VAR e: PARS.EXPR);
|
|
|
|
VAR
|
|
|
|
e1: PARS.EXPR;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
ASSERT(parser.sym = SCAN.lxLCURLY);
|
|
|
|
|
|
|
|
e.obj := eCONST;
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := tSET;
|
2019-03-11 09:59:55 +01:00
|
|
|
ARITH.emptySet(e.value);
|
|
|
|
|
|
|
|
PARS.Next(parser);
|
|
|
|
IF parser.sym # SCAN.lxRCURLY THEN
|
|
|
|
element(parser, e1);
|
|
|
|
|
|
|
|
IF e1.obj = eCONST THEN
|
|
|
|
ARITH.opSet(e.value, e1.value, "+")
|
|
|
|
ELSE
|
|
|
|
e.obj := eEXPR
|
|
|
|
END;
|
|
|
|
|
|
|
|
WHILE parser.sym = SCAN.lxCOMMA DO
|
|
|
|
PARS.Next(parser);
|
|
|
|
element(parser, e1);
|
|
|
|
IF (e.obj = eCONST) & (e1.obj = eCONST) THEN
|
|
|
|
ARITH.opSet(e.value, e1.value, "+")
|
|
|
|
ELSE
|
|
|
|
IF e.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd(IL.opADDSC, ARITH.Int(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd(IL.opADDSC, ARITH.Int(e1.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opADDS)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
e.obj := eEXPR
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
PARS.checklex(parser, SCAN.lxRCURLY)
|
|
|
|
END;
|
|
|
|
PARS.Next(parser);
|
|
|
|
END set;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE factor (parser: PARS.PARSER; VAR e: PARS.EXPR);
|
|
|
|
VAR
|
|
|
|
sym: INTEGER;
|
2019-09-26 22:23:06 +02:00
|
|
|
pos: PARS.POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
e1: PARS.EXPR;
|
|
|
|
isfloat: BOOLEAN;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE LoadVar (e: PARS.EXPR; parser: PARS.PARSER; pos: PARS.POSITION);
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF ~(e._type.typ IN {PROG.tRECORD, PROG.tARRAY}) THEN
|
|
|
|
IF e._type = tREAL THEN
|
|
|
|
IL.AddCmd2(IL.opLOADF, pos.line, pos.col)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.load(e._type.size)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
|
|
|
END LoadVar;
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
sym := parser.sym;
|
|
|
|
|
|
|
|
IF (sym = SCAN.lxINTEGER) OR (sym = SCAN.lxHEX) OR (sym = SCAN.lxFLOAT) OR (sym = SCAN.lxCHAR) OR (sym = SCAN.lxSTRING) THEN
|
|
|
|
e.obj := eCONST;
|
|
|
|
e.value := parser.lex.value;
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := PROG.getType(e.value.typ);
|
2019-03-11 09:59:55 +01:00
|
|
|
PARS.Next(parser)
|
|
|
|
|
|
|
|
ELSIF sym = SCAN.lxNIL THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
e.obj := eCONST;
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := PROG.program.stTypes.tNIL;
|
2019-03-11 09:59:55 +01:00
|
|
|
PARS.Next(parser)
|
|
|
|
|
|
|
|
ELSIF (sym = SCAN.lxTRUE) OR (sym = SCAN.lxFALSE) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
e.obj := eCONST;
|
2019-03-11 09:59:55 +01:00
|
|
|
ARITH.setbool(e.value, sym = SCAN.lxTRUE);
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := tBOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
PARS.Next(parser)
|
|
|
|
|
|
|
|
ELSIF sym = SCAN.lxLCURLY THEN
|
|
|
|
set(parser, e)
|
|
|
|
|
|
|
|
ELSIF sym = SCAN.lxIDENT THEN
|
|
|
|
getpos(parser, pos);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.pushBegEnd(begcall, endcall);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
designator(parser, e);
|
|
|
|
IF isVar(e) THEN
|
|
|
|
LoadVar(e, parser, pos)
|
|
|
|
END;
|
|
|
|
IF parser.sym = SCAN.lxLROUND THEN
|
|
|
|
e1 := e;
|
|
|
|
ActualParameters(parser, e);
|
2020-10-13 09:58:51 +02:00
|
|
|
PARS.check(e._type # NIL, pos, 59);
|
|
|
|
isfloat := e._type = tREAL;
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e1.obj IN {ePROC, eIMP} THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
ProcCall(e1, e1.ident._type, isfloat, parser, pos, FALSE)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF isExpr(e1) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
ProcCall(e1, e1._type, isfloat, parser, pos, FALSE)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.popBegEnd(begcall, endcall)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSIF sym = SCAN.lxLROUND THEN
|
|
|
|
PARS.Next(parser);
|
|
|
|
expression(parser, e);
|
|
|
|
PARS.checklex(parser, SCAN.lxRROUND);
|
|
|
|
PARS.Next(parser);
|
|
|
|
IF isExpr(e) & (e.obj # eCONST) THEN
|
|
|
|
e.obj := eEXPR
|
|
|
|
END
|
|
|
|
|
|
|
|
ELSIF sym = SCAN.lxNOT THEN
|
|
|
|
NextPos(parser, pos);
|
|
|
|
factor(parser, e);
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isBoolean(e), pos, 72);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj # eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.not;
|
2019-03-11 09:59:55 +01:00
|
|
|
e.obj := eEXPR
|
|
|
|
ELSE
|
|
|
|
ASSERT(ARITH.neg(e.value))
|
|
|
|
END
|
|
|
|
|
|
|
|
ELSE
|
|
|
|
PARS.check1(FALSE, parser, 34)
|
|
|
|
END
|
|
|
|
END factor;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE term (parser: PARS.PARSER; VAR e: PARS.EXPR);
|
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
pos: PARS.POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
e1: PARS.EXPR;
|
2020-05-25 22:48:33 +02:00
|
|
|
op, label, label1: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
factor(parser, e);
|
|
|
|
label := -1;
|
|
|
|
|
|
|
|
WHILE MulOperator(parser.sym) DO
|
|
|
|
op := parser.sym;
|
|
|
|
getpos(parser, pos);
|
|
|
|
PARS.Next(parser);
|
|
|
|
|
|
|
|
IF op = SCAN.lxAND THEN
|
|
|
|
IF ~parser.constexp THEN
|
|
|
|
|
|
|
|
IF label = -1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
label := IL.NewLabel()
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Const(ORD(ARITH.getBool(e.value)))
|
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AndOrOpt(label)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
factor(parser, e1);
|
|
|
|
|
|
|
|
CASE op OF
|
|
|
|
|SCAN.lxMUL:
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isInt(e) & isInt(e1) OR isReal(e) & isReal(e1) OR isSet(e) & isSet(e1), pos, 37);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF (e.obj = eCONST) & (e1.obj = eCONST) THEN
|
|
|
|
|
|
|
|
CASE e.value.typ OF
|
2019-09-26 22:23:06 +02:00
|
|
|
|ARITH.tINTEGER: PARS.check(ARITH.opInt(e.value, e1.value, "*"), pos, 39)
|
|
|
|
|ARITH.tREAL: PARS.check(ARITH.opFloat(e.value, e1.value, "*"), pos, 40)
|
2019-03-11 09:59:55 +01:00
|
|
|
|ARITH.tSET: ARITH.opSet(e.value, e1.value, "*")
|
|
|
|
END
|
|
|
|
|
|
|
|
ELSE
|
|
|
|
IF isInt(e) THEN
|
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opMULC, ARITH.Int(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opMULC, ARITH.Int(e1.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opMUL)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSIF isReal(e) THEN
|
|
|
|
IF e.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
Float(parser, e)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
Float(parser, e1)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd0(IL.opMULF)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF isSet(e) THEN
|
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opMULSC, ARITH.Int(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opMULSC, ARITH.Int(e1.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opMULS)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
|
|
|
e.obj := eEXPR
|
|
|
|
END
|
|
|
|
|
|
|
|
|SCAN.lxSLASH:
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isReal(e) & isReal(e1) OR isSet(e) & isSet(e1), pos, 37);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF (e1.obj = eCONST) & isReal(e1) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(~ARITH.isZero(e1.value), pos, 45)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
IF (e.obj = eCONST) & (e1.obj = eCONST) THEN
|
|
|
|
|
|
|
|
CASE e.value.typ OF
|
2019-09-26 22:23:06 +02:00
|
|
|
|ARITH.tREAL: PARS.check(ARITH.opFloat(e.value, e1.value, "/"), pos, 40)
|
2019-03-11 09:59:55 +01:00
|
|
|
|ARITH.tSET: ARITH.opSet(e.value, e1.value, "/")
|
|
|
|
END
|
|
|
|
|
|
|
|
ELSE
|
|
|
|
IF isReal(e) THEN
|
|
|
|
IF e.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
Float(parser, e);
|
|
|
|
IL.AddCmd0(IL.opDIVFI)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
Float(parser, e1);
|
|
|
|
IL.AddCmd0(IL.opDIVF)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd0(IL.opDIVF)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSIF isSet(e) THEN
|
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opDIVSC, ARITH.Int(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opDIVSC, ARITH.Int(e1.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opDIVS)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
|
|
|
e.obj := eEXPR
|
|
|
|
END
|
|
|
|
|
|
|
|
|SCAN.lxDIV, SCAN.lxMOD:
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isInt(e) & isInt(e1), pos, 37);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e1.obj = eCONST THEN
|
2020-05-25 22:48:33 +02:00
|
|
|
PARS.check(ARITH.Int(e1.value) > 0, pos, 122)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
IF (e.obj = eCONST) & (e1.obj = eCONST) THEN
|
|
|
|
|
|
|
|
IF op = SCAN.lxDIV THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(ARITH.opInt(e.value, e1.value, "D"), pos, 39)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
ASSERT(ARITH.opInt(e.value, e1.value, "M"))
|
|
|
|
END
|
|
|
|
|
|
|
|
ELSE
|
|
|
|
IF e1.obj # eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
label1 := IL.NewLabel();
|
2020-05-25 22:48:33 +02:00
|
|
|
IL.AddJmpCmd(IL.opJG, label1)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.OnError(pos.line, errDIV);
|
|
|
|
IL.SetLabel(label1);
|
|
|
|
IL.AddCmd(IL.opDIVL + ORD(op = SCAN.lxMOD), ARITH.Int(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opDIVR + ORD(op = SCAN.lxMOD), ARITH.Int(e1.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.OnError(pos.line, errDIV);
|
|
|
|
IL.SetLabel(label1);
|
|
|
|
IL.AddCmd0(IL.opDIV + ORD(op = SCAN.lxMOD))
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
e.obj := eEXPR
|
|
|
|
END
|
|
|
|
|
|
|
|
|SCAN.lxAND:
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isBoolean(e) & isBoolean(e1), pos, 37);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF (e.obj = eCONST) & (e1.obj = eCONST) THEN
|
|
|
|
ARITH.opBoolean(e.value, e1.value, "&")
|
|
|
|
ELSE
|
|
|
|
e.obj := eEXPR;
|
|
|
|
IF e1.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Const(ORD(ARITH.getBool(e1.value)))
|
2020-10-13 09:58:51 +02:00
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF label # -1 THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
label1 := IL.NewLabel();
|
|
|
|
IL.AddJmpCmd(IL.opJNZ, label1);
|
|
|
|
IL.SetLabel(label);
|
|
|
|
IL.Const(0);
|
|
|
|
IL.drop;
|
|
|
|
label := IL.NewLabel();
|
|
|
|
IL.AddJmpCmd(IL.opJMP, label);
|
|
|
|
IL.SetLabel(label1);
|
|
|
|
IL.Const(1);
|
|
|
|
IL.SetLabel(label);
|
|
|
|
IL.AddCmd0(IL.opAND)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END term;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE SimpleExpression (parser: PARS.PARSER; VAR e: PARS.EXPR);
|
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
pos: PARS.POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
op: INTEGER;
|
|
|
|
e1: PARS.EXPR;
|
2020-10-13 09:58:51 +02:00
|
|
|
s, s1: SCAN.LEXSTR;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
plus, minus: BOOLEAN;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
label, label1: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
plus := parser.sym = SCAN.lxPLUS;
|
|
|
|
minus := parser.sym = SCAN.lxMINUS;
|
|
|
|
|
|
|
|
IF plus OR minus THEN
|
|
|
|
getpos(parser, pos);
|
|
|
|
PARS.Next(parser)
|
|
|
|
END;
|
|
|
|
|
|
|
|
term(parser, e);
|
|
|
|
|
|
|
|
IF plus OR minus THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isInt(e) OR isReal(e) OR isSet(e), pos, 36);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF minus & (e.obj = eCONST) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(ARITH.neg(e.value), pos, 39)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
IF e.obj # eCONST THEN
|
|
|
|
IF minus THEN
|
|
|
|
IF isInt(e) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opUMINUS)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF isReal(e) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opUMINF)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF isSet(e) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opUMINS)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
|
|
|
e.obj := eEXPR
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
label := -1;
|
|
|
|
|
|
|
|
WHILE AddOperator(parser.sym) DO
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
op := parser.sym;
|
2019-03-11 09:59:55 +01:00
|
|
|
getpos(parser, pos);
|
|
|
|
PARS.Next(parser);
|
|
|
|
|
|
|
|
IF op = SCAN.lxOR THEN
|
|
|
|
|
|
|
|
IF ~parser.constexp THEN
|
|
|
|
|
|
|
|
IF label = -1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
label := IL.NewLabel()
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Const(ORD(ARITH.getBool(e.value)))
|
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.not;
|
|
|
|
IL.AndOrOpt(label)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
term(parser, e1);
|
|
|
|
|
|
|
|
CASE op OF
|
|
|
|
|SCAN.lxPLUS, SCAN.lxMINUS:
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
minus := op = SCAN.lxMINUS;
|
|
|
|
IF minus THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
op := ORD("-")
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSE
|
|
|
|
op := ORD("+")
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PARS.check(isInt(e) & isInt(e1) OR isReal(e) & isReal(e1) OR isSet(e) & isSet(e1) OR isString(e) & isString(e1) & ~minus, pos, 37);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF (e.obj = eCONST) & (e1.obj = eCONST) THEN
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
CASE e.value.typ OF
|
|
|
|
|ARITH.tINTEGER:
|
|
|
|
PARS.check(ARITH.opInt(e.value, e1.value, CHR(op)), pos, 39)
|
|
|
|
|
|
|
|
|ARITH.tREAL:
|
|
|
|
PARS.check(ARITH.opFloat(e.value, e1.value, CHR(op)), pos, 40)
|
|
|
|
|
|
|
|
|ARITH.tSET:
|
|
|
|
ARITH.opSet(e.value, e1.value, CHR(op))
|
|
|
|
|
|
|
|
|ARITH.tCHAR, ARITH.tSTRING:
|
|
|
|
IF e.value.typ = ARITH.tCHAR THEN
|
|
|
|
ARITH.charToStr(e.value, s)
|
|
|
|
ELSE
|
|
|
|
s := e.value.string(SCAN.IDENT).s
|
|
|
|
END;
|
|
|
|
IF e1.value.typ = ARITH.tCHAR THEN
|
|
|
|
ARITH.charToStr(e1.value, s1)
|
|
|
|
ELSE
|
|
|
|
s1 := e1.value.string(SCAN.IDENT).s
|
|
|
|
END;
|
|
|
|
PARS.check(ARITH.concat(s, s1), pos, 5);
|
|
|
|
e.value.string := SCAN.enterid(s);
|
|
|
|
e.value.typ := ARITH.tSTRING;
|
|
|
|
e._type := PROG.program.stTypes.tSTRING
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
ELSE
|
|
|
|
IF isInt(e) THEN
|
|
|
|
IF e.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd(IL.opADDC - ORD(minus), ARITH.Int(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd(IL.opADDC + ORD(minus), ARITH.Int(e1.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd0(IL.opADD + ORD(minus))
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSIF isReal(e) THEN
|
|
|
|
IF e.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
Float(parser, e);
|
|
|
|
IL.AddCmd0(IL.opADDF - ORD(minus))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
Float(parser, e1);
|
|
|
|
IL.AddCmd0(IL.opADDF + ORD(minus))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd0(IL.opADDF + ORD(minus))
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSIF isSet(e) THEN
|
|
|
|
IF e.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd(IL.opADDSC - ORD(minus), ARITH.Int(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd(IL.opADDSC + ORD(minus), ARITH.Int(e1.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd0(IL.opADDS + ORD(minus))
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
|
|
|
e.obj := eEXPR
|
|
|
|
END
|
|
|
|
|
|
|
|
|SCAN.lxOR:
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isBoolean(e) & isBoolean(e1), pos, 37);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF (e.obj = eCONST) & (e1.obj = eCONST) THEN
|
|
|
|
ARITH.opBoolean(e.value, e1.value, "|")
|
|
|
|
ELSE
|
|
|
|
e.obj := eEXPR;
|
|
|
|
IF e1.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Const(ORD(ARITH.getBool(e1.value)))
|
2020-10-13 09:58:51 +02:00
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF label # -1 THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
label1 := IL.NewLabel();
|
|
|
|
IL.AddJmpCmd(IL.opJZ, label1);
|
|
|
|
IL.SetLabel(label);
|
|
|
|
IL.Const(1);
|
|
|
|
IL.drop;
|
|
|
|
label := IL.NewLabel();
|
|
|
|
IL.AddJmpCmd(IL.opJMP, label);
|
|
|
|
IL.SetLabel(label1);
|
|
|
|
IL.Const(0);
|
|
|
|
IL.SetLabel(label);
|
|
|
|
IL.AddCmd0(IL.opOR)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
END SimpleExpression;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE cmpcode (op: INTEGER): INTEGER;
|
|
|
|
VAR
|
|
|
|
res: INTEGER;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
CASE op OF
|
2020-10-13 09:58:51 +02:00
|
|
|
|SCAN.lxEQ: res := ARITH.opEQ
|
|
|
|
|SCAN.lxNE: res := ARITH.opNE
|
|
|
|
|SCAN.lxLT: res := ARITH.opLT
|
|
|
|
|SCAN.lxLE: res := ARITH.opLE
|
|
|
|
|SCAN.lxGT: res := ARITH.opGT
|
|
|
|
|SCAN.lxGE: res := ARITH.opGE
|
|
|
|
|SCAN.lxIN: res := ARITH.opIN
|
|
|
|
|SCAN.lxIS: res := ARITH.opIS
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
RETURN res
|
|
|
|
END cmpcode;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE invcmpcode (op: INTEGER): INTEGER;
|
|
|
|
VAR
|
|
|
|
res: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
CASE op OF
|
2020-10-13 09:58:51 +02:00
|
|
|
|SCAN.lxEQ: res := ARITH.opEQ
|
|
|
|
|SCAN.lxNE: res := ARITH.opNE
|
|
|
|
|SCAN.lxLT: res := ARITH.opGT
|
|
|
|
|SCAN.lxLE: res := ARITH.opGE
|
|
|
|
|SCAN.lxGT: res := ARITH.opLT
|
|
|
|
|SCAN.lxGE: res := ARITH.opLE
|
|
|
|
|SCAN.lxIN: res := ARITH.opIN
|
|
|
|
|SCAN.lxIS: res := ARITH.opIS
|
2019-09-26 22:23:06 +02:00
|
|
|
END
|
|
|
|
|
|
|
|
RETURN res
|
|
|
|
END invcmpcode;
|
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE BoolCmp (eq, val: BOOLEAN);
|
|
|
|
BEGIN
|
|
|
|
IF eq = val THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opNEC)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opEQC)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END BoolCmp;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE strcmp (VAR e, e1: PARS.EXPR; op: INTEGER): BOOLEAN;
|
|
|
|
VAR
|
|
|
|
res: BOOLEAN;
|
2020-10-13 09:58:51 +02:00
|
|
|
cmp: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
res := TRUE;
|
2020-10-13 09:58:51 +02:00
|
|
|
cmp := cmpcode(op);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF isString(e) & isCharArray(e1) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.StrAdr(String(e));
|
|
|
|
IL.Const(strlen(e) + 1);
|
|
|
|
IL.AddCmd0(IL.opEQS + invcmpcode(op))
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF (isString(e) OR isStringW(e)) & isCharArrayW(e1) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.StrAdr(StringW(e));
|
|
|
|
IL.Const(utf8strlen(e) + 1);
|
|
|
|
IL.AddCmd0(IL.opEQSW + invcmpcode(op))
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSIF isCharArray(e) & isString(e1) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.StrAdr(String(e1));
|
|
|
|
IL.Const(strlen(e1) + 1);
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd0(IL.opEQS + cmp)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF isCharArrayW(e) & (isString(e1) OR isStringW(e1)) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.StrAdr(StringW(e1));
|
|
|
|
IL.Const(utf8strlen(e1) + 1);
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd0(IL.opEQSW + cmp)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSIF isCharArrayW(e) & isCharArrayW(e1) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd0(IL.opEQSW + cmp)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSIF isCharArray(e) & isCharArray(e1) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd0(IL.opEQS + cmp)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSIF isString(e) & isString(e1) THEN
|
|
|
|
PARS.strcmp(e.value, e1.value, op)
|
|
|
|
|
|
|
|
ELSE
|
|
|
|
res := FALSE
|
|
|
|
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN res
|
|
|
|
END strcmp;
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
getpos(parser, pos0);
|
|
|
|
SimpleExpression(parser, e);
|
|
|
|
IF relation(parser.sym) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF (isCharArray(e) OR isCharArrayW(e)) & (e._type.length # 0) THEN
|
|
|
|
IL.Const(e._type.length)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
op := parser.sym;
|
2019-03-11 09:59:55 +01:00
|
|
|
getpos(parser, pos);
|
|
|
|
PARS.Next(parser);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
getpos(parser, pos1);
|
2019-03-11 09:59:55 +01:00
|
|
|
SimpleExpression(parser, e1);
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF (isCharArray(e1) OR isCharArrayW(e1)) & (e1._type.length # 0) THEN
|
|
|
|
IL.Const(e1._type.length)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
constant := (e.obj = eCONST) & (e1.obj = eCONST);
|
|
|
|
error := 0;
|
2020-10-13 09:58:51 +02:00
|
|
|
cmp := cmpcode(op);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
CASE op OF
|
|
|
|
|SCAN.lxEQ, SCAN.lxNE:
|
2020-10-13 09:58:51 +02:00
|
|
|
eq := op = SCAN.lxEQ;
|
2019-03-11 09:59:55 +01:00
|
|
|
IF isInt(e) & isInt(e1) OR isSet(e) & isSet(e1) OR isChar(e) & isChar(e1) OR isCharW(e) & isCharW(e1) OR
|
|
|
|
isCharW(e) & isChar(e1) & (e1.obj = eCONST) OR isCharW(e1) & isChar(e) & (e.obj = eCONST) OR
|
|
|
|
isCharW(e1) & (e1.obj = eCONST) & isChar(e) & (e.obj = eCONST) OR
|
|
|
|
isCharW(e) & (e.obj = eCONST) & isChar(e1) & (e1.obj = eCONST) OR
|
2020-10-13 09:58:51 +02:00
|
|
|
isPtr(e) & isPtr(e1) & (PROG.isBaseOf(e._type, e1._type) OR PROG.isBaseOf(e1._type, e._type)) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
IF constant THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
ARITH.relation(e.value, e1.value, cmp, error)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
IF e.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd(IL.opEQC + cmp, ARITH.Int(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd(IL.opEQC + cmp, ARITH.Int(e1.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd0(IL.opEQ + cmp)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
|
|
|
|
|
|
|
ELSIF isStringW1(e) & isCharW(e1) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd(IL.opEQC + cmp, StrToWChar(e.value.string(SCAN.IDENT).s))
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSIF isStringW1(e1) & isCharW(e) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd(IL.opEQC + cmp, StrToWChar(e1.value.string(SCAN.IDENT).s))
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSIF isBoolean(e) & isBoolean(e1) THEN
|
|
|
|
IF constant THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
ARITH.relation(e.value, e1.value, cmp, error)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
IF e.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
BoolCmp(eq, ARITH.Int(e.value) # 0)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
BoolCmp(eq, ARITH.Int(e1.value) # 0)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IF eq THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opEQB)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opNEB)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
|
|
|
END
|
|
|
|
|
|
|
|
ELSIF isReal(e) & isReal(e1) THEN
|
|
|
|
IF constant THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
ARITH.relation(e.value, e1.value, cmp, error)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
IF e.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
Float(parser, e)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
Float(parser, e1)
|
2019-09-26 22:23:06 +02:00
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd0(IL.opEQF + cmp)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
ELSIF (isStringW(e) OR isCharArrayX(e)) & (isStringW(e1) OR isCharArrayX(e1)) THEN
|
|
|
|
IF ~strcmp(e, e1, op) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.error(pos, 37)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
ELSIF isPtr(e) & isNil(e1) OR isNil(e) & isPtr(e1) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd0(IL.opEQC + cmp)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSIF isProc(e) & isNil(e1) THEN
|
|
|
|
IF e.obj IN {ePROC, eIMP} THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(e.ident.global, pos0, 85);
|
2019-03-11 09:59:55 +01:00
|
|
|
constant := TRUE;
|
|
|
|
e.obj := eCONST;
|
2020-10-13 09:58:51 +02:00
|
|
|
ARITH.setbool(e.value, ~eq)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd0(IL.opEQC + cmp)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
ELSIF isNil(e) & isProc(e1) THEN
|
|
|
|
IF e1.obj IN {ePROC, eIMP} THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(e1.ident.global, pos1, 85);
|
2019-03-11 09:59:55 +01:00
|
|
|
constant := TRUE;
|
|
|
|
e.obj := eCONST;
|
2020-10-13 09:58:51 +02:00
|
|
|
ARITH.setbool(e.value, ~eq)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd0(IL.opEQC + cmp)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF isProc(e) & isProc(e1) & PROG.isTypeEq(e._type, e1._type) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = ePROC THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(e.ident.global, pos0, 85)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
IF e1.obj = ePROC THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(e1.ident.global, pos1, 85)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
IF (e.obj IN {ePROC, eIMP}) & (e1.obj IN {ePROC, eIMP}) THEN
|
|
|
|
constant := TRUE;
|
|
|
|
e.obj := eCONST;
|
2020-10-13 09:58:51 +02:00
|
|
|
IF eq THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
ARITH.setbool(e.value, e.ident = e1.ident)
|
|
|
|
ELSE
|
|
|
|
ARITH.setbool(e.value, e.ident # e1.ident)
|
|
|
|
END
|
|
|
|
ELSIF e.obj = ePROC THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.ProcCmp(e.ident.proc.label, eq)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = ePROC THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.ProcCmp(e1.ident.proc.label, eq)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e.obj = eIMP THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.ProcImpCmp(e.ident._import, eq)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eIMP THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.ProcImpCmp(e1.ident._import, eq)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd0(IL.opEQ + cmp)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
ELSIF isNil(e) & isNil(e1) THEN
|
|
|
|
constant := TRUE;
|
|
|
|
e.obj := eCONST;
|
2020-10-13 09:58:51 +02:00
|
|
|
ARITH.setbool(e.value, eq)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.error(pos, 37)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
|SCAN.lxLT, SCAN.lxLE, SCAN.lxGT, SCAN.lxGE:
|
|
|
|
IF isInt(e) & isInt(e1) OR isChar(e) & isChar(e1) OR isCharW(e) & isCharW(e1) OR
|
|
|
|
isCharW(e) & isChar(e1) & (e1.obj = eCONST) OR isCharW(e1) & isChar(e) & (e.obj = eCONST) OR
|
|
|
|
isCharW(e1) & (e1.obj = eCONST) & isChar(e) & (e.obj = eCONST) OR
|
|
|
|
isCharW(e) & (e.obj = eCONST) & isChar(e1) & (e1.obj = eCONST) THEN
|
|
|
|
|
|
|
|
IF constant THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
ARITH.relation(e.value, e1.value, cmp, error)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opEQC + invcmpcode(op), ARITH.Int(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd(IL.opEQC + cmp, ARITH.Int(e1.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd0(IL.opEQ + cmp)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
|
|
|
|
|
|
|
ELSIF isStringW1(e) & isCharW(e1) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opEQC + invcmpcode(op), StrToWChar(e.value.string(SCAN.IDENT).s))
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSIF isStringW1(e1) & isCharW(e) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd(IL.opEQC + cmp, StrToWChar(e1.value.string(SCAN.IDENT).s))
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSIF isReal(e) & isReal(e1) THEN
|
|
|
|
IF constant THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
ARITH.relation(e.value, e1.value, cmp, error)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
IF e.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
Float(parser, e);
|
|
|
|
IL.AddCmd0(IL.opEQF + invcmpcode(op))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
Float(parser, e1);
|
|
|
|
IL.AddCmd0(IL.opEQF + cmp)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd0(IL.opEQF + cmp)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
|
|
|
|
|
|
|
ELSIF (isStringW(e) OR isCharArrayX(e)) & (isStringW(e1) OR isCharArrayX(e1)) THEN
|
|
|
|
IF ~strcmp(e, e1, op) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.error(pos, 37)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.error(pos, 37)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
|SCAN.lxIN:
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isInt(e) & isSet(e1), pos, 37);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(ARITH.range(e.value, 0, UTILS.target.maxSet), pos0, 56)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
IF constant THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
ARITH.relation(e.value, e1.value, ARITH.opIN, error)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opINL, ARITH.Int(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opINR, ARITH.Int(e1.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opIN)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
|
|
|
|
|
|
|
|SCAN.lxIS:
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isRecPtr(e), pos, 73);
|
|
|
|
PARS.check(e1.obj = eTYPE, pos1, 79);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF isRec(e) THEN
|
|
|
|
PARS.check(e.obj = eVREC, pos0, 78);
|
2020-10-13 09:58:51 +02:00
|
|
|
PARS.check(e1._type.typ = PROG.tRECORD, pos1, 80);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.ident = NIL THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.TypeCheck(e1._type.num)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opVADR, e.ident.offset - 1);
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.TypeCheckRec(e1._type.num)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
PARS.check(e1._type.typ = PROG.tPOINTER, pos1, 81);
|
|
|
|
IL.TypeCheck(e1._type.base.num)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PARS.check(PROG.isBaseOf(e._type, e1._type), pos1, 82)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
ASSERT(error = 0);
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
e._type := tBOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF ~constant THEN
|
|
|
|
e.obj := eEXPR
|
|
|
|
END
|
|
|
|
|
|
|
|
END
|
|
|
|
END expression;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE ElementaryStatement (parser: PARS.PARSER);
|
|
|
|
VAR
|
2020-05-25 22:48:33 +02:00
|
|
|
e, e1: PARS.EXPR;
|
|
|
|
pos: PARS.POSITION;
|
|
|
|
line: INTEGER;
|
|
|
|
call: BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
getpos(parser, pos);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.pushBegEnd(begcall, endcall);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
designator(parser, e);
|
|
|
|
|
|
|
|
IF parser.sym = SCAN.lxASSIGN THEN
|
|
|
|
line := parser.lex.pos.line;
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isVar(e), pos, 93);
|
|
|
|
PARS.check(~e.readOnly, pos, 94);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.setlast(begcall);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
NextPos(parser, pos);
|
|
|
|
expression(parser, e1);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.setlast(endcall.prev(IL.COMMAND));
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PARS.check(assign(parser, e1, e._type, line), pos, 91);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e1.obj = ePROC THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(e1.ident.global, pos, 85)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
call := FALSE
|
|
|
|
ELSIF parser.sym = SCAN.lxEQ THEN
|
|
|
|
PARS.check1(FALSE, parser, 96)
|
|
|
|
ELSIF parser.sym = SCAN.lxLROUND THEN
|
|
|
|
e1 := e;
|
|
|
|
ActualParameters(parser, e1);
|
2020-10-13 09:58:51 +02:00
|
|
|
PARS.check((e1._type = NIL) OR ODD(e._type.call), pos, 92);
|
2019-03-11 09:59:55 +01:00
|
|
|
call := TRUE
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IF e.obj IN {eSYSPROC, eSTPROC} THEN
|
|
|
|
stProc(parser, e);
|
|
|
|
call := FALSE
|
|
|
|
ELSE
|
|
|
|
PARS.check(isProc(e), pos, 86);
|
2020-10-13 09:58:51 +02:00
|
|
|
PARS.check((e._type.base = NIL) OR ODD(e._type.call), pos, 92);
|
|
|
|
PARS.check1(e._type.params.first = NIL, parser, 64);
|
2019-09-26 22:23:06 +02:00
|
|
|
call := TRUE
|
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
IF call THEN
|
|
|
|
IF e.obj IN {ePROC, eIMP} THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
ProcCall(e, e.ident._type, FALSE, parser, pos, TRUE)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF isExpr(e) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
ProcCall(e, e._type, FALSE, parser, pos, TRUE)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.popBegEnd(begcall, endcall)
|
2019-03-11 09:59:55 +01:00
|
|
|
END ElementaryStatement;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE IfStatement (parser: PARS.PARSER; _if: BOOLEAN);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2020-05-25 22:48:33 +02:00
|
|
|
e: PARS.EXPR;
|
|
|
|
pos: PARS.POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
label, L: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
2019-09-26 22:23:06 +02:00
|
|
|
L := IL.NewLabel();
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF ~_if THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opLOOP);
|
|
|
|
IL.SetLabel(L)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
REPEAT
|
|
|
|
NextPos(parser, pos);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
label := IL.NewLabel();
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
expression(parser, e);
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isBoolean(e), pos, 72);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
IF ~ARITH.getBool(e.value) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddJmpCmd(IL.opJMP, label)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AndOrOpt(label)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF _if THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
PARS.checklex(parser, SCAN.lxTHEN)
|
|
|
|
ELSE
|
|
|
|
PARS.checklex(parser, SCAN.lxDO)
|
|
|
|
END;
|
|
|
|
|
|
|
|
PARS.Next(parser);
|
|
|
|
parser.StatSeq(parser);
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF ~_if OR (parser.sym # SCAN.lxEND) THEN
|
|
|
|
IL.AddJmpCmd(IL.opJMP, L)
|
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.SetLabel(label)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
UNTIL parser.sym # SCAN.lxELSIF;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF _if THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
IF parser.sym = SCAN.lxELSE THEN
|
|
|
|
PARS.Next(parser);
|
|
|
|
parser.StatSeq(parser)
|
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.SetLabel(L)
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSE
|
|
|
|
IL.AddCmd0(IL.opENDLOOP)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
PARS.checklex(parser, SCAN.lxEND);
|
|
|
|
|
|
|
|
PARS.Next(parser)
|
|
|
|
END IfStatement;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE RepeatStatement (parser: PARS.PARSER);
|
|
|
|
VAR
|
|
|
|
e: PARS.EXPR;
|
2019-09-26 22:23:06 +02:00
|
|
|
pos: PARS.POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
label: INTEGER;
|
2020-10-13 09:58:51 +02:00
|
|
|
L: IL.COMMAND;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opLOOP);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
label := IL.NewLabel();
|
|
|
|
IL.SetLabel(label);
|
2020-10-13 09:58:51 +02:00
|
|
|
L := IL.getlast();
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PARS.Next(parser);
|
|
|
|
parser.StatSeq(parser);
|
|
|
|
PARS.checklex(parser, SCAN.lxUNTIL);
|
|
|
|
NextPos(parser, pos);
|
|
|
|
expression(parser, e);
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isBoolean(e), pos, 72);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
IF ~ARITH.getBool(e.value) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddJmpCmd(IL.opJMP, label)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AndOrOpt(label);
|
|
|
|
L.param1 := label
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opENDLOOP)
|
2019-03-11 09:59:55 +01:00
|
|
|
END RepeatStatement;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE LabelCmp (a, b: AVL.DATA): INTEGER;
|
|
|
|
VAR
|
|
|
|
La, Ra, Lb, Rb, res: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
La := a(CASE_LABEL).range.a;
|
|
|
|
Ra := a(CASE_LABEL).range.b;
|
|
|
|
Lb := b(CASE_LABEL).range.a;
|
|
|
|
Rb := b(CASE_LABEL).range.b;
|
|
|
|
IF (Ra < Lb) OR (La > Rb) THEN
|
|
|
|
res := ORD(La > Lb) - ORD(La < Lb)
|
|
|
|
ELSE
|
|
|
|
res := 0
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN res
|
|
|
|
END LabelCmp;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE DestroyLabel (VAR label: AVL.DATA);
|
|
|
|
BEGIN
|
|
|
|
C.push(CaseLabels, label);
|
|
|
|
label := NIL
|
|
|
|
END DestroyLabel;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE NewVariant (label: INTEGER; cmd: IL.COMMAND): CASE_VARIANT;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
res: CASE_VARIANT;
|
|
|
|
citem: C.ITEM;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
citem := C.pop(CaseVar);
|
|
|
|
IF citem = NIL THEN
|
|
|
|
NEW(res)
|
|
|
|
ELSE
|
|
|
|
res := citem(CASE_VARIANT)
|
|
|
|
END;
|
|
|
|
|
|
|
|
res.label := label;
|
|
|
|
res.cmd := cmd;
|
|
|
|
res.processed := FALSE
|
|
|
|
|
|
|
|
RETURN res
|
|
|
|
END NewVariant;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE CaseStatement (parser: PARS.PARSER);
|
|
|
|
VAR
|
2020-05-25 22:48:33 +02:00
|
|
|
e: PARS.EXPR;
|
|
|
|
pos: PARS.POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE Label (parser: PARS.PARSER; caseExpr: PARS.EXPR; VAR _type: PROG._TYPE): INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2020-05-25 22:48:33 +02:00
|
|
|
a: INTEGER;
|
|
|
|
label: PARS.EXPR;
|
|
|
|
pos: PARS.POSITION;
|
|
|
|
value: ARITH.VALUE;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
getpos(parser, pos);
|
2020-10-13 09:58:51 +02:00
|
|
|
_type := NIL;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF isChar(caseExpr) THEN
|
|
|
|
PARS.ConstExpression(parser, value);
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(value.typ = ARITH.tCHAR, pos, 99);
|
2019-03-11 09:59:55 +01:00
|
|
|
a := ARITH.getInt(value)
|
|
|
|
ELSIF isCharW(caseExpr) THEN
|
|
|
|
PARS.ConstExpression(parser, value);
|
|
|
|
IF (value.typ = ARITH.tSTRING) & (_length(value.string(SCAN.IDENT).s) = 1) & (LENGTH(value.string(SCAN.IDENT).s) > 1) THEN
|
|
|
|
ASSERT(ARITH.setInt(value, StrToWChar(value.string(SCAN.IDENT).s)))
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(value.typ IN {ARITH.tWCHAR, ARITH.tCHAR}, pos, 99)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
a := ARITH.getInt(value)
|
|
|
|
ELSIF isInt(caseExpr) THEN
|
|
|
|
PARS.ConstExpression(parser, value);
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(value.typ = ARITH.tINTEGER, pos, 99);
|
2019-03-11 09:59:55 +01:00
|
|
|
a := ARITH.getInt(value)
|
|
|
|
ELSIF isRecPtr(caseExpr) THEN
|
|
|
|
qualident(parser, label);
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(label.obj = eTYPE, pos, 79);
|
2020-10-13 09:58:51 +02:00
|
|
|
PARS.check(PROG.isBaseOf(caseExpr._type, label._type), pos, 99);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF isRec(caseExpr) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
a := label._type.num
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
a := label._type.base.num
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
_type := label._type
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
RETURN a
|
|
|
|
END Label;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE CheckType (node: AVL.NODE; _type: PROG._TYPE; parser: PARS.PARSER; pos: PARS.POSITION);
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
IF node # NIL THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
PARS.check(~(PROG.isBaseOf(node.data(CASE_LABEL)._type, _type) OR PROG.isBaseOf(_type, node.data(CASE_LABEL)._type)), pos, 100);
|
|
|
|
CheckType(node.left, _type, parser, pos);
|
|
|
|
CheckType(node.right, _type, parser, pos)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END CheckType;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE LabelRange (parser: PARS.PARSER; caseExpr: PARS.EXPR; VAR tree: AVL.NODE; variant: INTEGER): AVL.NODE;
|
|
|
|
VAR
|
|
|
|
label: CASE_LABEL;
|
|
|
|
citem: C.ITEM;
|
2019-09-26 22:23:06 +02:00
|
|
|
pos, pos1: PARS.POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
node: AVL.NODE;
|
|
|
|
newnode: BOOLEAN;
|
|
|
|
range: RANGE;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
citem := C.pop(CaseLabels);
|
|
|
|
IF citem = NIL THEN
|
|
|
|
NEW(label)
|
|
|
|
ELSE
|
|
|
|
label := citem(CASE_LABEL)
|
|
|
|
END;
|
|
|
|
|
|
|
|
label.variant := variant;
|
2019-09-26 22:23:06 +02:00
|
|
|
label.self := IL.NewLabel();
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
getpos(parser, pos1);
|
2020-10-13 09:58:51 +02:00
|
|
|
range.a := Label(parser, caseExpr, label._type);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF parser.sym = SCAN.lxRANGE THEN
|
|
|
|
PARS.check1(~isRecPtr(caseExpr), parser, 53);
|
|
|
|
NextPos(parser, pos);
|
2020-10-13 09:58:51 +02:00
|
|
|
range.b := Label(parser, caseExpr, label._type);
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(range.a <= range.b, pos, 103)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
range.b := range.a
|
|
|
|
END;
|
|
|
|
|
|
|
|
label.range := range;
|
|
|
|
|
|
|
|
IF isRecPtr(caseExpr) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
CheckType(tree, label._type, parser, pos1)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
tree := AVL.insert(tree, label, LabelCmp, newnode, node);
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(newnode, pos1, 100)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
RETURN node
|
|
|
|
|
|
|
|
END LabelRange;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE CaseLabelList (parser: PARS.PARSER; caseExpr: PARS.EXPR; VAR tree: AVL.NODE; variant: INTEGER): AVL.NODE;
|
|
|
|
VAR
|
|
|
|
exit: BOOLEAN;
|
|
|
|
res: AVL.NODE;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
exit := FALSE;
|
|
|
|
REPEAT
|
|
|
|
res := LabelRange(parser, caseExpr, tree, variant);
|
|
|
|
IF parser.sym = SCAN.lxCOMMA THEN
|
|
|
|
PARS.check1(~isRecPtr(caseExpr), parser, 53);
|
|
|
|
PARS.Next(parser)
|
|
|
|
ELSE
|
|
|
|
exit := TRUE
|
|
|
|
END
|
|
|
|
UNTIL exit
|
|
|
|
|
|
|
|
RETURN res
|
|
|
|
END CaseLabelList;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE _case (parser: PARS.PARSER; caseExpr: PARS.EXPR; VAR tree: AVL.NODE; _end: INTEGER);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2020-05-25 22:48:33 +02:00
|
|
|
sym: INTEGER;
|
2020-10-13 09:58:51 +02:00
|
|
|
t: PROG._TYPE;
|
2020-05-25 22:48:33 +02:00
|
|
|
variant: INTEGER;
|
|
|
|
node: AVL.NODE;
|
|
|
|
last: IL.COMMAND;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
sym := parser.sym;
|
|
|
|
IF sym # SCAN.lxBAR THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
variant := IL.NewLabel();
|
2019-03-11 09:59:55 +01:00
|
|
|
node := CaseLabelList(parser, caseExpr, tree, variant);
|
|
|
|
PARS.checklex(parser, SCAN.lxCOLON);
|
|
|
|
PARS.Next(parser);
|
|
|
|
IF isRecPtr(caseExpr) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
t := caseExpr._type;
|
|
|
|
caseExpr.ident._type := node.data(CASE_LABEL)._type
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
last := IL.getlast();
|
|
|
|
IL.SetLabel(variant);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF ~isRecPtr(caseExpr) THEN
|
|
|
|
LISTS.push(CaseVariants, NewVariant(variant, last))
|
|
|
|
END;
|
|
|
|
|
|
|
|
parser.StatSeq(parser);
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddJmpCmd(IL.opJMP, _end);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF isRecPtr(caseExpr) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
caseExpr.ident._type := t
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
2020-10-13 09:58:51 +02:00
|
|
|
END _case;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE Table (node: AVL.NODE; _else: INTEGER);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
L, R: INTEGER;
|
|
|
|
range: RANGE;
|
|
|
|
left, right: AVL.NODE;
|
2019-09-26 22:23:06 +02:00
|
|
|
last: IL.COMMAND;
|
2019-03-11 09:59:55 +01:00
|
|
|
v: CASE_VARIANT;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF node # NIL THEN
|
|
|
|
|
|
|
|
range := node.data(CASE_LABEL).range;
|
|
|
|
|
|
|
|
left := node.left;
|
|
|
|
IF left # NIL THEN
|
|
|
|
L := left.data(CASE_LABEL).self
|
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
L := _else
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
right := node.right;
|
|
|
|
IF right # NIL THEN
|
|
|
|
R := right.data(CASE_LABEL).self
|
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
R := _else
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
last := IL.getlast();
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
v := CaseVariants.last(CASE_VARIANT);
|
|
|
|
WHILE (v # NIL) & (v.label # 0) & (v.label # node.data(CASE_LABEL).variant) DO
|
|
|
|
v := v.prev(CASE_VARIANT)
|
|
|
|
END;
|
|
|
|
|
|
|
|
ASSERT((v # NIL) & (v.label # 0));
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.setlast(v.cmd);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.SetLabel(node.data(CASE_LABEL).self);
|
2020-10-13 09:58:51 +02:00
|
|
|
IL._case(range.a, range.b, L, R);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF v.processed THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddJmpCmd(IL.opJMP, node.data(CASE_LABEL).variant)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
v.processed := TRUE;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.setlast(last);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
Table(left, _else);
|
|
|
|
Table(right, _else)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END Table;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE TableT (node: AVL.NODE);
|
|
|
|
BEGIN
|
|
|
|
IF node # NIL THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddCmd2(IL.opCASET, node.data(CASE_LABEL).variant, node.data(CASE_LABEL).range.a);
|
2019-03-11 09:59:55 +01:00
|
|
|
TableT(node.left);
|
|
|
|
TableT(node.right)
|
|
|
|
END
|
|
|
|
END TableT;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE ParseCase (parser: PARS.PARSER; e: PARS.EXPR; pos: PARS.POSITION);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2020-10-13 09:58:51 +02:00
|
|
|
table, _end, _else: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
tree: AVL.NODE;
|
2020-05-25 22:48:33 +02:00
|
|
|
item: LISTS.ITEM;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
LISTS.push(CaseVariants, NewVariant(0, NIL));
|
2020-10-13 09:58:51 +02:00
|
|
|
_end := IL.NewLabel();
|
|
|
|
_else := IL.NewLabel();
|
2019-09-26 22:23:06 +02:00
|
|
|
table := IL.NewLabel();
|
|
|
|
IL.AddCmd(IL.opSWITCH, ORD(isRecPtr(e)));
|
|
|
|
IL.AddJmpCmd(IL.opJMP, table);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
tree := NIL;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
_case(parser, e, tree, _end);
|
2019-03-11 09:59:55 +01:00
|
|
|
WHILE parser.sym = SCAN.lxBAR DO
|
|
|
|
PARS.Next(parser);
|
2020-10-13 09:58:51 +02:00
|
|
|
_case(parser, e, tree, _end)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.SetLabel(_else);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF parser.sym = SCAN.lxELSE THEN
|
|
|
|
PARS.Next(parser);
|
|
|
|
parser.StatSeq(parser);
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddJmpCmd(IL.opJMP, _end)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.OnError(pos.line, errCASE)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
PARS.checklex(parser, SCAN.lxEND);
|
|
|
|
PARS.Next(parser);
|
|
|
|
|
|
|
|
IF isRecPtr(e) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.SetLabel(table);
|
2019-03-11 09:59:55 +01:00
|
|
|
TableT(tree);
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddJmpCmd(IL.opJMP, _else)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
tree.data(CASE_LABEL).self := table;
|
2020-10-13 09:58:51 +02:00
|
|
|
Table(tree, _else)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
AVL.destroy(tree, DestroyLabel);
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.SetLabel(_end);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opENDSW);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
REPEAT
|
|
|
|
item := LISTS.pop(CaseVariants);
|
|
|
|
C.push(CaseVar, item)
|
|
|
|
UNTIL item(CASE_VARIANT).cmd = NIL
|
|
|
|
|
|
|
|
END ParseCase;
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
NextPos(parser, pos);
|
|
|
|
expression(parser, e);
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isInt(e) OR isChar(e) OR isCharW(e) OR isPtr(e) OR isRec(e), pos, 95);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF isRecPtr(e) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isVar(e), pos, 93);
|
|
|
|
PARS.check(e.ident # NIL, pos, 106)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
IF isRec(e) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(e.obj = eVREC, pos, 78)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
LoadConst(e)
|
|
|
|
ELSIF isRec(e) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.drop;
|
|
|
|
IL.AddCmd(IL.opLADR, e.ident.offset - 1);
|
2020-05-25 22:48:33 +02:00
|
|
|
IL.load(TARGETS.WordSize)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF isPtr(e) THEN
|
|
|
|
deref(pos, e, FALSE, errPTR);
|
2020-05-25 22:48:33 +02:00
|
|
|
IL.AddCmd(IL.opSUBR, TARGETS.WordSize);
|
|
|
|
IL.load(TARGETS.WordSize)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
PARS.checklex(parser, SCAN.lxOF);
|
|
|
|
PARS.Next(parser);
|
|
|
|
ParseCase(parser, e, pos)
|
|
|
|
END CaseStatement;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE ForStatement (parser: PARS.PARSER);
|
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
e: PARS.EXPR;
|
|
|
|
pos, pos2: PARS.POSITION;
|
|
|
|
step: ARITH.VALUE;
|
|
|
|
st: INTEGER;
|
|
|
|
ident: PROG.IDENT;
|
|
|
|
offset: INTEGER;
|
|
|
|
L1, L2: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opLOOP);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
L1 := IL.NewLabel();
|
|
|
|
L2 := IL.NewLabel();
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PARS.ExpectSym(parser, SCAN.lxIDENT);
|
2019-09-26 22:23:06 +02:00
|
|
|
ident := PROG.getIdent(parser.unit, parser.lex.ident, TRUE);
|
2019-03-11 09:59:55 +01:00
|
|
|
PARS.check1(ident # NIL, parser, 48);
|
|
|
|
PARS.check1(ident.typ = PROG.idVAR, parser, 93);
|
2020-10-13 09:58:51 +02:00
|
|
|
PARS.check1(ident._type = tINTEGER, parser, 97);
|
2019-03-11 09:59:55 +01:00
|
|
|
PARS.ExpectSym(parser, SCAN.lxASSIGN);
|
|
|
|
NextPos(parser, pos);
|
|
|
|
expression(parser, e);
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isInt(e), pos, 76);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
offset := PROG.getOffset(ident);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF ident.global THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opGADR, offset)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opLADR, -offset)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opSAVEC, ARITH.Int(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opSAVE)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.SetLabel(L1);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF ident.global THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opGADR, offset)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opLADR, -offset)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.load(ident._type.size);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PARS.checklex(parser, SCAN.lxTO);
|
2019-09-26 22:23:06 +02:00
|
|
|
NextPos(parser, pos2);
|
2019-03-11 09:59:55 +01:00
|
|
|
expression(parser, e);
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(isInt(e), pos2, 76);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF parser.sym = SCAN.lxBY THEN
|
|
|
|
NextPos(parser, pos);
|
|
|
|
PARS.ConstExpression(parser, step);
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(step.typ = ARITH.tINTEGER, pos, 76);
|
2019-03-11 09:59:55 +01:00
|
|
|
st := ARITH.getInt(step);
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(st # 0, pos, 98)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
st := 1
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
IF st > 0 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opLEC, ARITH.Int(e.value));
|
|
|
|
IF ARITH.Int(e.value) = UTILS.target.maxInt THEN
|
|
|
|
ERRORS.WarningMsg(pos2.line, pos2.col, 1)
|
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opGEC, ARITH.Int(e.value));
|
|
|
|
IF ARITH.Int(e.value) = UTILS.target.minInt THEN
|
|
|
|
ERRORS.WarningMsg(pos2.line, pos2.col, 1)
|
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
IF st > 0 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opLE)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opGE)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.AddJmpCmd(IL.opJZ, L2);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PARS.checklex(parser, SCAN.lxDO);
|
|
|
|
PARS.Next(parser);
|
|
|
|
parser.StatSeq(parser);
|
|
|
|
|
|
|
|
IF ident.global THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opGADR, offset)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opLADR, -offset)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opINCC, st);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddJmpCmd(IL.opJMP, L1);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PARS.checklex(parser, SCAN.lxEND);
|
|
|
|
PARS.Next(parser);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.SetLabel(L2);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opENDLOOP)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
END ForStatement;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE statement (parser: PARS.PARSER);
|
|
|
|
VAR
|
|
|
|
sym: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
sym := parser.sym;
|
|
|
|
|
|
|
|
IF sym = SCAN.lxIDENT THEN
|
|
|
|
ElementaryStatement(parser)
|
|
|
|
ELSIF sym = SCAN.lxIF THEN
|
|
|
|
IfStatement(parser, TRUE)
|
|
|
|
ELSIF sym = SCAN.lxWHILE THEN
|
|
|
|
IfStatement(parser, FALSE)
|
|
|
|
ELSIF sym = SCAN.lxREPEAT THEN
|
|
|
|
RepeatStatement(parser)
|
|
|
|
ELSIF sym = SCAN.lxCASE THEN
|
|
|
|
CaseStatement(parser)
|
|
|
|
ELSIF sym = SCAN.lxFOR THEN
|
|
|
|
ForStatement(parser)
|
|
|
|
END
|
|
|
|
END statement;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE StatSeq (parser: PARS.PARSER);
|
|
|
|
BEGIN
|
|
|
|
statement(parser);
|
|
|
|
WHILE parser.sym = SCAN.lxSEMI DO
|
|
|
|
PARS.Next(parser);
|
|
|
|
statement(parser)
|
|
|
|
END
|
|
|
|
END StatSeq;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE chkreturn (parser: PARS.PARSER; e: PARS.EXPR; t: PROG._TYPE; pos: PARS.POSITION): BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
res: BOOLEAN;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
res := assigncomp(e, t);
|
|
|
|
IF res THEN
|
|
|
|
IF e.obj = eCONST THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF e._type = tREAL THEN
|
|
|
|
Float(parser, e)
|
|
|
|
ELSIF e._type.typ = PROG.tNIL THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Const(0)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
LoadConst(e)
|
|
|
|
END
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF (e._type = tINTEGER) & (t = tBYTE) & (chkBYTE IN Options.checking) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
CheckRange(256, pos.line, errBYTE)
|
|
|
|
ELSIF e.obj = ePROC THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(e.ident.global, pos, 85);
|
|
|
|
IL.PushProc(e.ident.proc.label)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e.obj = eIMP THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.PushImpProc(e.ident._import)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN res
|
|
|
|
END chkreturn;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE setrtl;
|
|
|
|
VAR
|
|
|
|
rtl: PROG.UNIT;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE getproc (rtl: PROG.UNIT; name: SCAN.LEXSTR; idx: INTEGER);
|
|
|
|
VAR
|
2020-05-25 22:48:33 +02:00
|
|
|
id: PROG.IDENT;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
2019-09-26 22:23:06 +02:00
|
|
|
id := PROG.getIdent(rtl, SCAN.enterid(name), FALSE);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF (id # NIL) & (id._import # NIL) THEN
|
|
|
|
IL.set_rtl(idx, -id._import(IL.IMPORT_PROC).label);
|
2019-03-11 09:59:55 +01:00
|
|
|
id.proc.used := TRUE
|
|
|
|
ELSIF (id # NIL) & (id.proc # NIL) THEN
|
2019-10-06 19:55:12 +02:00
|
|
|
IL.set_rtl(idx, id.proc.label);
|
2019-03-11 09:59:55 +01:00
|
|
|
id.proc.used := TRUE
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
ERRORS.WrongRTL(name)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END getproc;
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
rtl := PROG.program.rtl;
|
2019-03-11 09:59:55 +01:00
|
|
|
ASSERT(rtl # NIL);
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
getproc(rtl, "_strcmp", IL._strcmp);
|
|
|
|
getproc(rtl, "_length", IL._length);
|
|
|
|
getproc(rtl, "_arrcpy", IL._arrcpy);
|
|
|
|
getproc(rtl, "_is", IL._is);
|
|
|
|
getproc(rtl, "_guard", IL._guard);
|
|
|
|
getproc(rtl, "_guardrec", IL._guardrec);
|
|
|
|
getproc(rtl, "_new", IL._new);
|
|
|
|
getproc(rtl, "_rot", IL._rot);
|
|
|
|
getproc(rtl, "_strcpy", IL._strcpy);
|
|
|
|
getproc(rtl, "_move", IL._move);
|
|
|
|
getproc(rtl, "_set", IL._set);
|
|
|
|
getproc(rtl, "_set1", IL._set1);
|
|
|
|
getproc(rtl, "_lengthw", IL._lengthw);
|
|
|
|
getproc(rtl, "_strcmpw", IL._strcmpw);
|
|
|
|
getproc(rtl, "_init", IL._init);
|
|
|
|
|
|
|
|
IF CPU IN {TARGETS.cpuX86, TARGETS.cpuAMD64} THEN
|
|
|
|
getproc(rtl, "_error", IL._error);
|
|
|
|
getproc(rtl, "_divmod", IL._divmod);
|
|
|
|
getproc(rtl, "_exit", IL._exit);
|
|
|
|
getproc(rtl, "_dispose", IL._dispose);
|
|
|
|
getproc(rtl, "_isrec", IL._isrec);
|
|
|
|
getproc(rtl, "_dllentry", IL._dllentry);
|
|
|
|
getproc(rtl, "_sofinit", IL._sofinit)
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF CPU IN {TARGETS.cpuTHUMB, TARGETS.cpuRVM32I} THEN
|
2020-05-25 22:48:33 +02:00
|
|
|
getproc(rtl, "_fmul", IL._fmul);
|
|
|
|
getproc(rtl, "_fdiv", IL._fdiv);
|
|
|
|
getproc(rtl, "_fdivi", IL._fdivi);
|
|
|
|
getproc(rtl, "_fadd", IL._fadd);
|
|
|
|
getproc(rtl, "_fsub", IL._fsub);
|
|
|
|
getproc(rtl, "_fsubi", IL._fsubi);
|
|
|
|
getproc(rtl, "_fcmp", IL._fcmp);
|
|
|
|
getproc(rtl, "_floor", IL._floor);
|
|
|
|
getproc(rtl, "_flt", IL._flt);
|
|
|
|
getproc(rtl, "_pack", IL._pack);
|
2020-10-13 09:58:51 +02:00
|
|
|
getproc(rtl, "_unpk", IL._unpk);
|
|
|
|
IF CPU = TARGETS.cpuRVM32I THEN
|
|
|
|
getproc(rtl, "_error", IL._error)
|
|
|
|
END
|
2019-09-26 22:23:06 +02:00
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
END setrtl;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE compile* (path, lib_path, modname, outname: PARS.PATH; target: INTEGER; options: PROG.OPTIONS);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
parser: PARS.PARSER;
|
2019-03-11 09:59:55 +01:00
|
|
|
ext: PARS.PATH;
|
|
|
|
|
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
tINTEGER := PROG.program.stTypes.tINTEGER;
|
|
|
|
tBYTE := PROG.program.stTypes.tBYTE;
|
|
|
|
tCHAR := PROG.program.stTypes.tCHAR;
|
|
|
|
tSET := PROG.program.stTypes.tSET;
|
|
|
|
tBOOLEAN := PROG.program.stTypes.tBOOLEAN;
|
|
|
|
tWCHAR := PROG.program.stTypes.tWCHAR;
|
|
|
|
tREAL := PROG.program.stTypes.tREAL;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
|
|
|
Options := options;
|
2020-05-25 22:48:33 +02:00
|
|
|
CPU := TARGETS.CPU;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
ext := UTILS.FILE_EXT;
|
2019-03-11 09:59:55 +01:00
|
|
|
CaseLabels := C.create();
|
|
|
|
CaseVar := C.create();
|
|
|
|
|
|
|
|
CaseVariants := LISTS.create(NIL);
|
|
|
|
LISTS.push(CaseVariants, NewVariant(0, NIL));
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IL.init(CPU);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF TARGETS.RTL THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
parser := PARS.create(path, lib_path, StatSeq, expression, designator, chkreturn);
|
2020-05-25 22:48:33 +02:00
|
|
|
IF parser.open(parser, UTILS.RTL_NAME) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
parser.parse(parser);
|
|
|
|
PARS.destroy(parser)
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.destroy(parser);
|
|
|
|
parser := PARS.create(lib_path, lib_path, StatSeq, expression, designator, chkreturn);
|
2020-05-25 22:48:33 +02:00
|
|
|
IF parser.open(parser, UTILS.RTL_NAME) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
parser.parse(parser);
|
|
|
|
PARS.destroy(parser)
|
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
ERRORS.FileNotFound(lib_path, UTILS.RTL_NAME, UTILS.FILE_EXT)
|
2019-09-26 22:23:06 +02:00
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
parser := PARS.create(path, lib_path, StatSeq, expression, designator, chkreturn);
|
|
|
|
parser.main := TRUE;
|
|
|
|
|
|
|
|
IF parser.open(parser, modname) THEN
|
|
|
|
parser.parse(parser)
|
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
ERRORS.FileNotFound(path, modname, UTILS.FILE_EXT)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
PARS.destroy(parser);
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF PROG.program.bss > UTILS.MAX_GLOBAL_SIZE THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
ERRORS.Error(204)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF TARGETS.RTL THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
setrtl
|
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROG.DelUnused(IL.DelImport);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IL.set_bss(PROG.program.bss);
|
2019-09-26 22:23:06 +02:00
|
|
|
|
|
|
|
CASE CPU OF
|
2020-05-25 22:48:33 +02:00
|
|
|
|TARGETS.cpuAMD64: AMD64.CodeGen(outname, target, options)
|
|
|
|
|TARGETS.cpuX86: X86.CodeGen(outname, target, options)
|
|
|
|
|TARGETS.cpuMSP430: MSP430.CodeGen(outname, target, options)
|
|
|
|
|TARGETS.cpuTHUMB: THUMB.CodeGen(outname, target, options)
|
2020-10-13 09:58:51 +02:00
|
|
|
|TARGETS.cpuRVM32I: RVM32I.CodeGen(outname, target, options)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
END compile;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
END STATEMENTS.
|