2019-10-06 19:55:12 +02:00
|
|
|
(*
|
2019-03-11 09:59:55 +01:00
|
|
|
BSD 2-Clause License
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
Copyright (c) 2018-2019, Anton Krotov
|
2019-03-11 09:59:55 +01:00
|
|
|
All rights reserved.
|
|
|
|
*)
|
|
|
|
|
|
|
|
MODULE STATEMENTS;
|
|
|
|
|
|
|
|
IMPORT
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS, PROG, SCAN, ARITH, STRINGS, LISTS, IL, X86, AMD64, MSP430,
|
|
|
|
ERRORS, UTILS, AVL := AVLTREES, CONSOLE, C := COLLECTIONS, mConst := CONSTANTS;
|
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};
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
cpuX86 = 1; cpuAMD64 = 2; cpuMSP430 = 3;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
type: PROG.TYPE_;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
tINTEGER, tBYTE, tCHAR, tWCHAR, tSET, tBOOLEAN, tREAL: PROG.TYPE_;
|
|
|
|
|
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;
|
2019-09-26 22:23:06 +02:00
|
|
|
RETURN isExpr(e) & (e.type = tBOOLEAN)
|
2019-03-11 09:59:55 +01:00
|
|
|
END isBoolean;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isInteger (e: PARS.EXPR): BOOLEAN;
|
2019-09-26 22:23:06 +02:00
|
|
|
RETURN isExpr(e) & (e.type = tINTEGER)
|
2019-03-11 09:59:55 +01:00
|
|
|
END isInteger;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isByte (e: PARS.EXPR): BOOLEAN;
|
2019-09-26 22:23:06 +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;
|
2019-09-26 22:23:06 +02:00
|
|
|
RETURN isExpr(e) & (e.type = tREAL)
|
2019-03-11 09:59:55 +01:00
|
|
|
END isReal;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isSet (e: PARS.EXPR): BOOLEAN;
|
2019-09-26 22:23:06 +02:00
|
|
|
RETURN isExpr(e) & (e.type = tSET)
|
2019-03-11 09:59:55 +01:00
|
|
|
END isSet;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isString (e: PARS.EXPR): BOOLEAN;
|
|
|
|
RETURN (e.obj = eCONST) & (e.type.typ IN {PROG.tSTRING, PROG.tCHAR})
|
|
|
|
END isString;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isStringW (e: PARS.EXPR): BOOLEAN;
|
|
|
|
RETURN (e.obj = eCONST) & (e.type.typ IN {PROG.tSTRING, PROG.tCHAR, PROG.tWCHAR})
|
|
|
|
END isStringW;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isChar (e: PARS.EXPR): BOOLEAN;
|
2019-09-26 22:23:06 +02:00
|
|
|
RETURN isExpr(e) & (e.type = tCHAR)
|
2019-03-11 09:59:55 +01:00
|
|
|
END isChar;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isCharW (e: PARS.EXPR): BOOLEAN;
|
2019-09-26 22:23:06 +02:00
|
|
|
RETURN isExpr(e) & (e.type = tWCHAR)
|
2019-03-11 09:59:55 +01:00
|
|
|
END isCharW;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isPtr (e: PARS.EXPR): BOOLEAN;
|
|
|
|
RETURN isExpr(e) & (e.type.typ = PROG.tPOINTER)
|
|
|
|
END isPtr;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isRec (e: PARS.EXPR): BOOLEAN;
|
|
|
|
RETURN isExpr(e) & (e.type.typ = PROG.tRECORD)
|
|
|
|
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;
|
|
|
|
RETURN isExpr(e) & (e.type.typ = PROG.tARRAY)
|
|
|
|
END isArr;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isProc (e: PARS.EXPR): BOOLEAN;
|
|
|
|
RETURN isExpr(e) & (e.type.typ = PROG.tPROCEDURE) OR (e.obj IN {ePROC, eIMP})
|
|
|
|
END isProc;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isNil (e: PARS.EXPR): BOOLEAN;
|
|
|
|
RETURN e.type.typ = PROG.tNIL
|
|
|
|
END isNil;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE isCharArray (e: PARS.EXPR): BOOLEAN;
|
|
|
|
RETURN isArr(e) & (e.type.base = tCHAR)
|
|
|
|
END isCharArray;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isCharArrayW (e: PARS.EXPR): BOOLEAN;
|
|
|
|
RETURN isArr(e) & (e.type.base = tWCHAR)
|
|
|
|
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));
|
2019-09-26 22:23:06 +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));
|
|
|
|
IF e.type.typ IN {PROG.tCHAR, PROG.tWCHAR} THEN
|
|
|
|
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;
|
|
|
|
RETURN (e.obj = eCONST) & isString(e) & (utf8strlen(e) = 1) & (strlen(e) > 1)
|
|
|
|
END isStringW1;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE assigncomp (e: PARS.EXPR; t: PROG.TYPE_): BOOLEAN;
|
|
|
|
VAR
|
|
|
|
res: BOOLEAN;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF isExpr(e) OR (e.obj IN {ePROC, eIMP}) THEN
|
2019-10-06 19:55:12 +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)
|
|
|
|
OR PROG.isBaseOf(t, e.type)
|
|
|
|
OR ~PROG.isOpenArray(t) & ~PROG.isOpenArray(e.type) & PROG.isTypeEq(t, e.type)
|
|
|
|
OR isNil(e) & (t.typ IN {PROG.tPOINTER, PROG.tPROCEDURE})
|
|
|
|
OR PROG.arrcomp(e.type, t)
|
|
|
|
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
|
|
|
|
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))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE (* e.type.typ = PROG.tSTRING *)
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE assign (e: PARS.EXPR; VarType: PROG.TYPE_; line: INTEGER): BOOLEAN;
|
|
|
|
VAR
|
|
|
|
res: BOOLEAN;
|
|
|
|
label: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF isExpr(e) OR (e.obj IN {ePROC, eIMP}) THEN
|
|
|
|
res := TRUE;
|
2019-10-06 19:55:12 +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();
|
|
|
|
IL.AddJmpCmd(IL.opJE, label);
|
|
|
|
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
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Float(ARITH.Float(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.savef
|
|
|
|
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
|
|
|
|
ELSIF PROG.isBaseOf(VarType, e.type) THEN
|
|
|
|
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
|
|
|
|
ELSIF (e.type.typ = PROG.tCARD32) & (VarType.typ = PROG.tCARD32) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opSAVE32)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF ~PROG.isOpenArray(VarType) & ~PROG.isOpenArray(e.type) & PROG.isTypeEq(VarType, e.type) THEN
|
|
|
|
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
|
2019-09-26 22:23:06 +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
|
|
|
|
t1, t2: PROG.TYPE_;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
t1 := p.type;
|
|
|
|
t2 := e.type;
|
|
|
|
WHILE (t2.typ = PROG.tARRAY) & PROG.isOpenArray(t1) DO
|
|
|
|
t1 := t1.base;
|
|
|
|
t2 := t2.base
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN PROG.isTypeEq(t1, t2)
|
|
|
|
END arrcomp;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE ArrLen (t: PROG.TYPE_; n: INTEGER): INTEGER;
|
|
|
|
VAR
|
|
|
|
res: INTEGER;
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE OpenArray (t, t2: PROG.TYPE_);
|
|
|
|
VAR
|
|
|
|
n: INTEGER;
|
|
|
|
d1, d2: INTEGER;
|
|
|
|
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);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF p.type.typ = PROG.tRECORD THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
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
|
2019-09-26 22:23:06 +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)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF PROG.isOpenArray(p.type) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(arrcomp(e, p), pos, 66);
|
2019-03-11 09:59:55 +01:00
|
|
|
OpenArray(e.type, p.type)
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(PROG.isTypeEq(e.type, p.type), pos, 66);
|
|
|
|
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);
|
2019-03-11 09:59:55 +01: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);
|
2019-03-11 09:59:55 +01:00
|
|
|
OpenArray(e.type, p.type)
|
2019-09-26 22:23:06 +02:00
|
|
|
ELSIF isString(e) & (p.type.typ = PROG.tARRAY) & (p.type.base = tCHAR) THEN
|
|
|
|
IL.StrAdr(String(e));
|
|
|
|
IL.Param1;
|
|
|
|
IL.Const(strlen(e) + 1);
|
|
|
|
IL.Param1
|
|
|
|
ELSIF isStringW(e) & (p.type.typ = PROG.tARRAY) & (p.type.base = tWCHAR) THEN
|
|
|
|
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
|
2019-09-26 22:23:06 +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
|
2019-09-26 22:23:06 +02:00
|
|
|
IF e.type = tREAL THEN
|
|
|
|
IL.Float(ARITH.Float(e.value));
|
|
|
|
IL.pushf
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e.type.typ = PROG.tNIL THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Const(0);
|
|
|
|
IL.Param1
|
|
|
|
ELSIF isStringW1(e) & (p.type = tWCHAR) THEN
|
|
|
|
IL.Const(StrToWChar(e.value.string(SCAN.IDENT).s));
|
|
|
|
IL.Param1
|
2019-03-11 09:59:55 +01: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
|
2019-09-26 22:23:06 +02:00
|
|
|
IF p.type.base = tCHAR THEN
|
|
|
|
stroffs := String(e);
|
|
|
|
IL.StrAdr(stroffs);
|
|
|
|
IF (CPU = cpuMSP430) & (p.type.size - strlen(e) - 1 > MSP430.IntVectorSize) THEN
|
|
|
|
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;
|
2019-10-06 19:55:12 +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
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.PushImpProc(e.ident.import);
|
|
|
|
IL.Param1
|
|
|
|
ELSIF isExpr(e) & (e.type = tREAL) THEN
|
|
|
|
IL.pushf
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +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
|
|
|
|
e2: PARS.EXPR;
|
2019-09-26 22:23:06 +02:00
|
|
|
pos: PARS.POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
proc: INTEGER;
|
|
|
|
label: INTEGER;
|
|
|
|
n, i: INTEGER;
|
|
|
|
code: ARITH.VALUE;
|
|
|
|
e1: PARS.EXPR;
|
|
|
|
wchar: BOOLEAN;
|
|
|
|
cmd1,
|
2019-09-26 22:23:06 +02:00
|
|
|
cmd2: IL.COMMAND;
|
|
|
|
comma: BOOLEAN;
|
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;
|
|
|
|
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();
|
|
|
|
IL.AddJmpCmd(IL.opJE, label);
|
|
|
|
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);
|
2019-09-26 22:23:06 +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
|
2019-09-26 22:23:06 +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);
|
2019-09-26 22:23:06 +02:00
|
|
|
IF CPU = cpuMSP430 THEN
|
|
|
|
PARS.check(e.type.base.size + 16 < Options.ram, pos, 63)
|
|
|
|
END;
|
|
|
|
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;
|
|
|
|
|
|
|
|
IF isCharArrayX(e) & ~PROG.isOpenArray(e.type) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
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;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
wchar := e1.type.base = tWCHAR
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
IF ~PROG.isOpenArray(e1.type) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
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;
|
|
|
|
IL.AddCmd(IL.opCOPYS, e1.type.base.size);
|
|
|
|
IL.popBegEnd(begcall, endcall)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|PROG.sysGET:
|
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);
|
|
|
|
PARS.check(e2.type.typ IN PROG.BASICTYPES + {PROG.tPOINTER, PROG.tPROCEDURE}, pos, 66);
|
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
IL.AddCmd2(IL.opGETC, ARITH.Int(e.value), e2.type.size)
|
|
|
|
ELSE
|
|
|
|
IL.AddCmd(IL.opGET, e2.type.size)
|
|
|
|
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
|
2019-09-26 22:23:06 +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
|
2019-09-26 22:23:06 +02:00
|
|
|
IF e2.type = tREAL THEN
|
|
|
|
IL.setlast(endcall.prev(IL.COMMAND));
|
|
|
|
IL.Float(ARITH.Float(e2.value));
|
|
|
|
IL.savef
|
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));
|
|
|
|
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));
|
|
|
|
IF e2.type = tREAL THEN
|
|
|
|
IL.savef
|
|
|
|
ELSIF e2.type = tBYTE THEN
|
|
|
|
IL.SysPut(tINTEGER.size)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +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
|
2019-10-06 19:55:12 +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
|
|
|
|
|PROG.sysPUT8: IL.SysPut(1)
|
|
|
|
|PROG.sysPUT16: IL.SysPut(2)
|
|
|
|
|PROG.sysPUT32: IL.SysPut(4)
|
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.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);
|
2019-03-11 09:59:55 +01: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)
|
|
|
|
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);
|
|
|
|
IF CPU # cpuMSP430 THEN
|
|
|
|
PARS.check(ARITH.range(code, 0, 255), pos, 42)
|
|
|
|
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;
|
|
|
|
e.type := NIL
|
|
|
|
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.floor
|
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);
|
|
|
|
e.type := tREAL;
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
ARITH.flt(e.value)
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(IL.flt(), pos, 41)
|
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);
|
|
|
|
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);
|
2019-03-11 09:59:55 +01:00
|
|
|
ASSERT(ARITH.setInt(e.value, e.type.length));
|
|
|
|
e.obj := eCONST
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.len(PROG.Dim(e.type))
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2019-09-26 22:23:06 +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
|
|
|
|
IF e.type.length > 0 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
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
|
|
|
|
IF e.type.length > 0 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
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;
|
2019-09-26 22:23:06 +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);
|
|
|
|
e.type := tBOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
ARITH.odd(e.value)
|
|
|
|
ELSE
|
2019-10-06 19:55:12 +02:00
|
|
|
IL.AddCmd0(IL.opODD)
|
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
|
2019-10-06 19:55:12 +02:00
|
|
|
IL.AddCmd0(IL.opORD)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
2019-09-26 22:23:06 +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;
|
2019-09-26 22:23:06 +02:00
|
|
|
e.type := tSET
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|PROG.sysADR:
|
|
|
|
parser.designator(parser, e);
|
|
|
|
IF isVar(e) THEN
|
|
|
|
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)
|
|
|
|
END
|
|
|
|
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
|
2019-09-26 22:23:06 +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;
|
2019-09-26 22:23:06 +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));
|
|
|
|
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));
|
|
|
|
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);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.type.typ = PROG.tRECORD THEN
|
|
|
|
ASSERT(ARITH.setInt(e.value, e.type.num))
|
2019-09-26 22:23:06 +02:00
|
|
|
ELSIF e.type.typ = PROG.tPOINTER THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
ASSERT(ARITH.setInt(e.value, e.type.base.num))
|
|
|
|
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;
|
2019-09-26 22:23:06 +02:00
|
|
|
e.type := tINTEGER
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|PROG.sysINF:
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(IL.inf(), pos, 41);
|
2019-03-11 09:59:55 +01:00
|
|
|
e.obj := eEXPR;
|
2019-09-26 22:23:06 +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);
|
2019-03-11 09:59:55 +01:00
|
|
|
ASSERT(ARITH.setInt(e.value, e.type.size));
|
|
|
|
e.obj := eCONST;
|
2019-09-26 22:23:06 +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
|
|
|
|
proc: PROG.TYPE_;
|
|
|
|
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
|
|
|
|
proc := e.type;
|
|
|
|
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;
|
|
|
|
e.type := proc.base
|
|
|
|
|
|
|
|
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
|
|
|
|
ident: PROG.IDENT;
|
|
|
|
import: BOOLEAN;
|
2019-09-26 22:23:06 +02:00
|
|
|
pos: PARS.POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
PARS.checklex(parser, SCAN.lxIDENT);
|
|
|
|
getpos(parser, pos);
|
|
|
|
import := 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);
|
|
|
|
import := TRUE
|
|
|
|
END;
|
|
|
|
PARS.Next(parser);
|
|
|
|
|
|
|
|
e.readOnly := FALSE;
|
|
|
|
e.ident := ident;
|
|
|
|
|
|
|
|
CASE ident.typ OF
|
|
|
|
|PROG.idCONST:
|
|
|
|
e.obj := eCONST;
|
|
|
|
e.type := ident.type;
|
|
|
|
e.value := ident.value
|
|
|
|
|PROG.idTYPE:
|
|
|
|
e.obj := eTYPE;
|
|
|
|
e.type := ident.type
|
|
|
|
|PROG.idVAR:
|
|
|
|
e.obj := eVAR;
|
|
|
|
e.type := ident.type;
|
|
|
|
e.readOnly := import
|
|
|
|
|PROG.idPROC:
|
|
|
|
e.obj := ePROC;
|
|
|
|
e.type := ident.type
|
|
|
|
|PROG.idIMP:
|
|
|
|
e.obj := eIMP;
|
|
|
|
e.type := ident.type
|
|
|
|
|PROG.idVPAR:
|
|
|
|
e.type := ident.type;
|
|
|
|
IF e.type.typ = PROG.tRECORD THEN
|
|
|
|
e.obj := eVREC
|
|
|
|
ELSE
|
|
|
|
e.obj := eVPAR
|
|
|
|
END
|
|
|
|
|PROG.idPARAM:
|
|
|
|
e.obj := ePARAM;
|
|
|
|
e.type := ident.type;
|
|
|
|
e.readOnly := (e.type.typ IN {PROG.tRECORD, PROG.tARRAY})
|
|
|
|
|PROG.idSTPROC:
|
|
|
|
e.obj := eSTPROC;
|
|
|
|
e.stproc := ident.stproc
|
|
|
|
|PROG.idSTFUNC:
|
|
|
|
e.obj := eSTFUNC;
|
|
|
|
e.stproc := ident.stproc
|
|
|
|
|PROG.idSYSPROC:
|
|
|
|
e.obj := eSYSPROC;
|
|
|
|
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;
|
|
|
|
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
|
|
|
|
label: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF load THEN
|
2019-09-26 22:23:06 +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();
|
|
|
|
IL.AddJmpCmd(IL.opJNZ, label);
|
|
|
|
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;
|
|
|
|
n := PROG.Dim(e.type);
|
|
|
|
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
|
|
|
|
offset := PROG.getOffset(PARS.program, e.ident);
|
|
|
|
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
|
|
|
|
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)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF PROG.isOpenArray(e.type) THEN
|
|
|
|
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
|
|
|
|
IF PROG.isOpenArray(e.type) THEN
|
|
|
|
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
|
|
|
|
label: INTEGER;
|
|
|
|
type: PROG.TYPE_;
|
|
|
|
n, offset, k: INTEGER;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
type := PROG.OpenBase(e.type);
|
|
|
|
IF type.size # 1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opMULC, type.size)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
n := PROG.Dim(e.type) - 1;
|
|
|
|
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);
|
|
|
|
PARS.check1(isExpr(e) & (e.type.typ IN {PROG.tRECORD, PROG.tPOINTER}), parser, 73);
|
|
|
|
IF e.type.typ = PROG.tPOINTER THEN
|
|
|
|
deref(pos, e, TRUE, errPTR)
|
|
|
|
END;
|
|
|
|
PARS.ExpectSym(parser, SCAN.lxIDENT);
|
|
|
|
IF e.type.typ = PROG.tPOINTER THEN
|
|
|
|
e.type := e.type.base;
|
|
|
|
e.readOnly := FALSE
|
|
|
|
END;
|
2019-09-26 22:23:06 +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);
|
|
|
|
e.type := field.type;
|
|
|
|
IF e.obj = eVREC THEN
|
|
|
|
e.obj := eVPAR
|
|
|
|
END;
|
|
|
|
IF field.offset # 0 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opADDR, 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
|
|
|
|
IF e.type.length > 0 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
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
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opADDR, 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
|
|
|
|
IF e.type.length > 0 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IF chkIDX IN Options.checking THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
CheckRange(e.type.length, pos.line, errIDX)
|
|
|
|
END;
|
|
|
|
IF e.type.base.size # 1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
e.type := e.type.base
|
|
|
|
|
|
|
|
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);
|
|
|
|
e.type := e.type.base;
|
|
|
|
e.readOnly := FALSE;
|
|
|
|
PARS.Next(parser);
|
|
|
|
e.ident := NIL;
|
|
|
|
e.obj := eVREC
|
|
|
|
|
|
|
|
ELSIF (parser.sym = SCAN.lxLROUND) & isExpr(e) & (e.type.typ IN {PROG.tRECORD, PROG.tPOINTER}) DO
|
|
|
|
|
|
|
|
IF e.type.typ = PROG.tRECORD THEN
|
|
|
|
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
|
|
|
|
|
|
|
IF e.type.typ = PROG.tRECORD THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(t.type.typ = PROG.tRECORD, pos, 80);
|
|
|
|
IF chkGUARD IN Options.checking THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.ident = NIL THEN
|
2019-09-26 22:23:06 +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);
|
|
|
|
IL.TypeGuard(IL.opTYPEGR, t.type.num, pos.line, errGUARD)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(t.type.typ = PROG.tPOINTER, pos, 81);
|
|
|
|
IF chkGUARD IN Options.checking THEN
|
|
|
|
IL.TypeGuard(IL.opTYPEGP, t.type.base.num, pos.line, errGUARD)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(PROG.isBaseOf(e.type, t.type), pos, 82);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
e.type := t.type;
|
|
|
|
|
|
|
|
PARS.checklex(parser, SCAN.lxRROUND);
|
|
|
|
PARS.Next(parser)
|
|
|
|
|
|
|
|
END
|
|
|
|
|
|
|
|
END designator;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE ProcCall (e: PARS.EXPR; procType: PROG.TYPE_; isfloat: BOOLEAN; VAR fregs: INTEGER; parser: PARS.PARSER; pos: PARS.POSITION; CallStat: BOOLEAN);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
cconv: INTEGER;
|
|
|
|
parSize: INTEGER;
|
|
|
|
callconv: INTEGER;
|
|
|
|
fparSize: INTEGER;
|
|
|
|
int, flt: INTEGER;
|
|
|
|
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);
|
|
|
|
fregs := IL.precall(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
|
2019-09-26 22:23:06 +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;
|
|
|
|
|
|
|
|
IF ~CallStat THEN
|
|
|
|
IF isfloat THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(IL.resf(fregs), pos, 41)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.res(fregs)
|
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;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
op: INTEGER;
|
|
|
|
e1: PARS.EXPR;
|
|
|
|
constant: BOOLEAN;
|
|
|
|
operator: ARITH.RELATION;
|
|
|
|
error: INTEGER;
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2019-09-26 22:23:06 +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;
|
2019-09-26 22:23:06 +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
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opADDSL, 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.opADDSR, 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;
|
|
|
|
fregs: INTEGER;
|
|
|
|
|
|
|
|
|
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
|
|
|
|
IF ~(e.type.typ IN {PROG.tRECORD, PROG.tARRAY}) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IF e.type = tREAL THEN
|
|
|
|
PARS.check(IL.loadf(), pos, 41)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +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;
|
2019-09-26 22:23:06 +02:00
|
|
|
e.type := PROG.getType(PARS.program, 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;
|
|
|
|
e.type := PARS.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);
|
2019-09-26 22:23:06 +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);
|
2019-09-26 22:23:06 +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
|
|
|
|
ProcCall(e1, e1.ident.type, isfloat, fregs, parser, pos, FALSE)
|
|
|
|
ELSIF isExpr(e1) THEN
|
|
|
|
ProcCall(e1, e1.type, isfloat, fregs, parser, pos, FALSE)
|
|
|
|
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
|
|
|
op: INTEGER;
|
|
|
|
e1: PARS.EXPR;
|
|
|
|
|
|
|
|
label: INTEGER;
|
|
|
|
label1: INTEGER;
|
|
|
|
|
|
|
|
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;
|
|
|
|
IL.AddCmd0(IL.opACC);
|
|
|
|
IL.AddJmpCmd(IL.opJZ, label);
|
|
|
|
IL.drop
|
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
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Float(ARITH.Float(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Float(ARITH.Float(e1.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.fbinop(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
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Float(ARITH.Float(e.value));
|
|
|
|
IL.fbinop(IL.opDIVFI)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Float(ARITH.Float(e1.value));
|
|
|
|
IL.fbinop(IL.opDIVF)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.fbinop(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
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(~ARITH.isZero(e1.value), pos, 46);
|
|
|
|
IF CPU = cpuMSP430 THEN
|
|
|
|
PARS.check(ARITH.Int(e1.value) > 0, pos, 122)
|
|
|
|
END
|
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();
|
|
|
|
IF CPU = cpuMSP430 THEN
|
|
|
|
IL.AddJmpCmd(IL.opJG, label1)
|
|
|
|
ELSE
|
|
|
|
IL.AddJmpCmd(IL.opJNZ, label1)
|
|
|
|
END
|
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)))
|
2019-06-04 09:22:50 +02:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opACC)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF label # -1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.SetLabel(label)
|
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;
|
|
|
|
|
|
|
|
plus, minus: BOOLEAN;
|
|
|
|
|
|
|
|
label: INTEGER;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
op := parser.sym;
|
|
|
|
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;
|
|
|
|
IL.AddCmd0(IL.opACC);
|
|
|
|
IL.AddJmpCmd(IL.opJNZ, label);
|
|
|
|
IL.drop
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
term(parser, e1);
|
|
|
|
|
|
|
|
CASE op OF
|
|
|
|
|SCAN.lxPLUS, SCAN.lxMINUS:
|
|
|
|
|
|
|
|
IF op = SCAN.lxPLUS THEN
|
|
|
|
op := ORD("+")
|
|
|
|
ELSE
|
|
|
|
op := ORD("-")
|
|
|
|
END;
|
|
|
|
|
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, CHR(op)), pos, 39)
|
|
|
|
|ARITH.tREAL: PARS.check(ARITH.opFloat(e.value, e1.value, CHR(op)), pos, 40)
|
2019-03-11 09:59:55 +01:00
|
|
|
|ARITH.tSET: ARITH.opSet(e.value, e1.value, CHR(op))
|
|
|
|
END
|
|
|
|
|
|
|
|
ELSE
|
|
|
|
IF isInt(e) THEN
|
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opADDL + ORD(op = ORD("-")), 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.opADDR + ORD(op = ORD("-")), ARITH.Int(e1.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opADD + ORD(op = ORD("-")))
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSIF isReal(e) THEN
|
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Float(ARITH.Float(e.value));
|
|
|
|
IL.fbinop(IL.opADDFI + ORD(op = ORD("-")))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Float(ARITH.Float(e1.value));
|
|
|
|
IL.fbinop(IL.opADDF + ORD(op = ORD("-")))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.fbinop(IL.opADDF + ORD(op = ORD("-")))
|
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.opADDSL + ORD(op = ORD("-")), 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.opADDSR + ORD(op = ORD("-")), 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 + ORD(op = ORD("-")))
|
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)))
|
2019-06-04 09:22:50 +02:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opACC)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF label # -1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.SetLabel(label)
|
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
|
|
|
|
|SCAN.lxEQ: res := 0
|
|
|
|
|SCAN.lxNE: res := 1
|
|
|
|
|SCAN.lxLT: res := 2
|
|
|
|
|SCAN.lxLE: res := 3
|
|
|
|
|SCAN.lxGT: res := 4
|
|
|
|
|SCAN.lxGE: res := 5
|
|
|
|
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
|
|
|
|
|SCAN.lxEQ: res := 0
|
|
|
|
|SCAN.lxNE: res := 1
|
|
|
|
|SCAN.lxLT: res := 4
|
|
|
|
|SCAN.lxLE: res := 5
|
|
|
|
|SCAN.lxGT: res := 2
|
|
|
|
|SCAN.lxGE: res := 3
|
|
|
|
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;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
|
|
|
|
res := TRUE;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
ELSIF isString(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 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);
|
|
|
|
IL.AddCmd0(IL.opEQS + cmpcode(op))
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSIF isCharArrayW(e) & isString(e1) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.StrAdr(StringW(e1));
|
|
|
|
IL.Const(utf8strlen(e1) + 1);
|
|
|
|
IL.AddCmd0(IL.opEQSW + cmpcode(op))
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSIF isCharArrayW(e) & isStringW(e1) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.StrAdr(StringW(e1));
|
|
|
|
IL.Const(utf8strlen(e1) + 1);
|
|
|
|
IL.AddCmd0(IL.opEQSW + cmpcode(op))
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSIF isCharArrayW(e) & isCharArrayW(e1) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opEQSW + cmpcode(op))
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSIF isCharArray(e) & isCharArray(e1) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opEQS + cmpcode(op))
|
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
|
|
|
|
IF (isCharArray(e) OR isCharArrayW(e)) & (e.type.length # 0) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Const(e.type.length)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
op := parser.sym;
|
|
|
|
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);
|
|
|
|
|
|
|
|
IF (isCharArray(e1) OR isCharArrayW(e1)) & (e1.type.length # 0) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Const(e1.type.length)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
constant := (e.obj = eCONST) & (e1.obj = eCONST);
|
|
|
|
|
|
|
|
CASE op OF
|
|
|
|
|SCAN.lxEQ: operator := "="
|
|
|
|
|SCAN.lxNE: operator := "#"
|
|
|
|
|SCAN.lxLT: operator := "<"
|
|
|
|
|SCAN.lxLE: operator := "<="
|
|
|
|
|SCAN.lxGT: operator := ">"
|
|
|
|
|SCAN.lxGE: operator := ">="
|
|
|
|
|SCAN.lxIN: operator := "IN"
|
|
|
|
|SCAN.lxIS: operator := ""
|
|
|
|
END;
|
|
|
|
|
|
|
|
error := 0;
|
|
|
|
|
|
|
|
CASE op OF
|
|
|
|
|SCAN.lxEQ, SCAN.lxNE:
|
|
|
|
|
|
|
|
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
|
|
|
|
isPtr(e) & isPtr(e1) & (PROG.isBaseOf(e.type, e1.type) OR PROG.isBaseOf(e1.type, e.type)) THEN
|
|
|
|
IF constant THEN
|
|
|
|
ARITH.relation(e.value, e1.value, operator, error)
|
|
|
|
ELSE
|
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opEQC + cmpcode(op), 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.opEQC + cmpcode(op), ARITH.Int(e1.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opEQ + cmpcode(op))
|
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 + cmpcode(op), StrToWChar(e.value.string(SCAN.IDENT).s))
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSIF isStringW1(e1) & isCharW(e) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opEQC + cmpcode(op), StrToWChar(e1.value.string(SCAN.IDENT).s))
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSIF isBoolean(e) & isBoolean(e1) THEN
|
|
|
|
IF constant THEN
|
|
|
|
ARITH.relation(e.value, e1.value, operator, error)
|
|
|
|
ELSE
|
|
|
|
IF e.obj = eCONST THEN
|
|
|
|
BoolCmp(op = SCAN.lxEQ, ARITH.Int(e.value) # 0)
|
|
|
|
ELSIF e1.obj = eCONST THEN
|
|
|
|
BoolCmp(op = SCAN.lxEQ, ARITH.Int(e1.value) # 0)
|
|
|
|
ELSE
|
|
|
|
IF op = SCAN.lxEQ 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
|
|
|
|
ARITH.relation(e.value, e1.value, operator, error)
|
|
|
|
ELSE
|
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Float(ARITH.Float(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Float(ARITH.Float(e1.value))
|
|
|
|
END;
|
|
|
|
IL.fcmp(IL.opEQF + cmpcode(op))
|
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
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opEQC + cmpcode(op))
|
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;
|
|
|
|
ARITH.setbool(e.value, op = SCAN.lxNE)
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opEQC + cmpcode(op))
|
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;
|
|
|
|
ARITH.setbool(e.value, op = SCAN.lxNE)
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opEQC + cmpcode(op))
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
ELSIF isProc(e) & isProc(e1) & PROG.isTypeEq(e.type, e1.type) THEN
|
|
|
|
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;
|
|
|
|
IF op = SCAN.lxEQ THEN
|
|
|
|
ARITH.setbool(e.value, e.ident = e1.ident)
|
|
|
|
ELSE
|
|
|
|
ARITH.setbool(e.value, e.ident # e1.ident)
|
|
|
|
END
|
|
|
|
ELSIF e.obj = ePROC THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.ProcCmp(e.ident.proc.label, op = SCAN.lxEQ)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = ePROC THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.ProcCmp(e1.ident.proc.label, op = SCAN.lxEQ)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e.obj = eIMP THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.ProcImpCmp(e.ident.import, op = SCAN.lxEQ)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eIMP THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.ProcImpCmp(e1.ident.import, op = SCAN.lxEQ)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opEQ + cmpcode(op))
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
ELSIF isNil(e) & isNil(e1) THEN
|
|
|
|
constant := TRUE;
|
|
|
|
e.obj := eCONST;
|
|
|
|
ARITH.setbool(e.value, op = SCAN.lxEQ)
|
|
|
|
|
|
|
|
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
|
|
|
|
ARITH.relation(e.value, e1.value, operator, error)
|
|
|
|
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
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opEQC + cmpcode(op), ARITH.Int(e1.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opEQ + cmpcode(op))
|
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
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opEQC + cmpcode(op), StrToWChar(e1.value.string(SCAN.IDENT).s))
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ELSIF isReal(e) & isReal(e1) THEN
|
|
|
|
IF constant THEN
|
|
|
|
ARITH.relation(e.value, e1.value, operator, error)
|
|
|
|
ELSE
|
|
|
|
IF e.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Float(ARITH.Float(e.value));
|
|
|
|
IL.fcmp(IL.opEQF + invcmpcode(op))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF e1.obj = eCONST THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.Float(ARITH.Float(e1.value));
|
|
|
|
IL.fcmp(IL.opEQF + cmpcode(op))
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.fcmp(IL.opEQF + cmpcode(op))
|
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
|
|
|
|
ARITH.relation(e.value, e1.value, operator, error)
|
|
|
|
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);
|
|
|
|
PARS.check(e1.type.typ = PROG.tRECORD, pos1, 80);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF e.ident = NIL THEN
|
2019-09-26 22:23:06 +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);
|
|
|
|
IL.TypeCheckRec(e1.type.num)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +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;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(PROG.isBaseOf(e.type, e1.type), pos1, 82)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
ASSERT(error = 0);
|
|
|
|
|
2019-09-26 22:23:06 +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
|
|
|
|
e, e1: PARS.EXPR;
|
2019-09-26 22:23:06 +02:00
|
|
|
pos: PARS.POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
line: INTEGER;
|
|
|
|
call: BOOLEAN;
|
|
|
|
fregs: INTEGER;
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(assign(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);
|
2019-09-26 22:23:06 +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);
|
|
|
|
PARS.check((e.type.base = NIL) OR ODD(e.type.call), pos, 92);
|
|
|
|
PARS.check1(e.type.params.first = NIL, parser, 64);
|
|
|
|
call := TRUE
|
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
IF call THEN
|
|
|
|
IF e.obj IN {ePROC, eIMP} THEN
|
|
|
|
ProcCall(e, e.ident.type, FALSE, fregs, parser, pos, TRUE)
|
|
|
|
ELSIF isExpr(e) THEN
|
|
|
|
ProcCall(e, e.type, FALSE, fregs, parser, pos, TRUE)
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.popBegEnd(begcall, endcall)
|
2019-03-11 09:59:55 +01:00
|
|
|
END ElementaryStatement;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE IfStatement (parser: PARS.PARSER; if: BOOLEAN);
|
|
|
|
VAR
|
|
|
|
e: PARS.EXPR;
|
2019-09-26 22:23:06 +02:00
|
|
|
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
|
|
|
|
|
|
|
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
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddJmpCmd(IL.opJNE, label)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
IF if THEN
|
|
|
|
PARS.checklex(parser, SCAN.lxTHEN)
|
|
|
|
ELSE
|
|
|
|
PARS.checklex(parser, SCAN.lxDO)
|
|
|
|
END;
|
|
|
|
|
|
|
|
PARS.Next(parser);
|
|
|
|
parser.StatSeq(parser);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddJmpCmd(IL.opJMP, L);
|
|
|
|
IL.SetLabel(label)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
UNTIL parser.sym # SCAN.lxELSIF;
|
|
|
|
|
|
|
|
IF if THEN
|
|
|
|
IF parser.sym = SCAN.lxELSE THEN
|
|
|
|
PARS.Next(parser);
|
|
|
|
parser.StatSeq(parser)
|
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.SetLabel(L)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
PARS.checklex(parser, SCAN.lxEND);
|
|
|
|
|
|
|
|
IF ~if THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd0(IL.opENDLOOP)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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);
|
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
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddJmpCmd(IL.opJNE, 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
|
|
|
|
e: PARS.EXPR;
|
2019-09-26 22:23:06 +02:00
|
|
|
pos: PARS.POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE Label (parser: PARS.PARSER; caseExpr: PARS.EXPR; VAR type: PROG.TYPE_): INTEGER;
|
|
|
|
VAR
|
|
|
|
a: INTEGER;
|
|
|
|
label: PARS.EXPR;
|
2019-09-26 22:23:06 +02:00
|
|
|
pos: PARS.POSITION;
|
2019-03-11 09:59:55 +01:00
|
|
|
value: ARITH.VALUE;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
getpos(parser, pos);
|
|
|
|
type := NIL;
|
|
|
|
|
|
|
|
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);
|
|
|
|
PARS.check(PROG.isBaseOf(caseExpr.type, label.type), pos, 99);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF isRec(caseExpr) THEN
|
|
|
|
a := label.type.num
|
|
|
|
ELSE
|
|
|
|
a := label.type.base.num
|
|
|
|
END;
|
|
|
|
type := label.type
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN a
|
|
|
|
END Label;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +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
|
2019-09-26 22:23:06 +02:00
|
|
|
PARS.check(~(PROG.isBaseOf(node.data(CASE_LABEL).type, type) OR PROG.isBaseOf(type, node.data(CASE_LABEL).type)), pos, 100);
|
2019-03-11 09:59:55 +01:00
|
|
|
CheckType(node.left, type, parser, pos);
|
|
|
|
CheckType(node.right, type, parser, pos)
|
|
|
|
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);
|
|
|
|
range.a := Label(parser, caseExpr, label.type);
|
|
|
|
|
|
|
|
IF parser.sym = SCAN.lxRANGE THEN
|
|
|
|
PARS.check1(~isRecPtr(caseExpr), parser, 53);
|
|
|
|
NextPos(parser, pos);
|
|
|
|
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
|
|
|
|
CheckType(tree, label.type, parser, pos1)
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE case (parser: PARS.PARSER; caseExpr: PARS.EXPR; VAR tree: AVL.NODE; end: INTEGER);
|
|
|
|
VAR
|
|
|
|
sym: INTEGER;
|
|
|
|
t: PROG.TYPE_;
|
|
|
|
variant: INTEGER;
|
|
|
|
node: AVL.NODE;
|
2019-09-26 22:23:06 +02:00
|
|
|
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
|
|
|
|
t := caseExpr.type;
|
|
|
|
caseExpr.ident.type := node.data(CASE_LABEL).type
|
|
|
|
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);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddJmpCmd(IL.opJMP, end);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF isRecPtr(caseExpr) THEN
|
|
|
|
caseExpr.ident.type := t
|
|
|
|
END
|
|
|
|
END
|
|
|
|
END case;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE Table (node: AVL.NODE; else: INTEGER);
|
|
|
|
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
|
|
|
|
L := else
|
|
|
|
END;
|
|
|
|
|
|
|
|
right := node.right;
|
|
|
|
IF right # NIL THEN
|
|
|
|
R := right.data(CASE_LABEL).self
|
|
|
|
ELSE
|
|
|
|
R := else
|
|
|
|
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);
|
|
|
|
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
|
|
|
|
|
|
|
Table(left, else);
|
|
|
|
Table(right, else)
|
|
|
|
END
|
|
|
|
END Table;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE TableT (node: AVL.NODE);
|
|
|
|
BEGIN
|
|
|
|
IF node # NIL THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.caset(node.data(CASE_LABEL).range.a, node.data(CASE_LABEL).variant);
|
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
|
|
|
|
table, end, else: INTEGER;
|
|
|
|
tree: AVL.NODE;
|
|
|
|
item: LISTS.ITEM;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
LISTS.push(CaseVariants, NewVariant(0, NIL));
|
2019-09-26 22:23:06 +02:00
|
|
|
end := IL.NewLabel();
|
|
|
|
else := IL.NewLabel();
|
|
|
|
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;
|
|
|
|
|
|
|
|
case(parser, e, tree, end);
|
|
|
|
WHILE parser.sym = SCAN.lxBAR DO
|
|
|
|
PARS.Next(parser);
|
|
|
|
case(parser, e, tree, end)
|
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +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);
|
2019-09-26 22:23:06 +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);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddJmpCmd(IL.opJMP, else)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
tree.data(CASE_LABEL).self := table;
|
|
|
|
Table(tree, else)
|
|
|
|
END;
|
|
|
|
|
|
|
|
AVL.destroy(tree, DestroyLabel);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.SetLabel(end);
|
|
|
|
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);
|
|
|
|
IL.load(PARS.program.target.word)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF isPtr(e) THEN
|
|
|
|
deref(pos, e, FALSE, errPTR);
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddCmd(IL.opSUBR, PARS.program.target.word);
|
|
|
|
IL.load(PARS.program.target.word)
|
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);
|
2019-09-26 22:23:06 +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
|
|
|
|
|
|
|
offset := PROG.getOffset(PARS.program, ident);
|
|
|
|
|
|
|
|
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;
|
2019-09-26 22:23:06 +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;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.AddJmpCmd(IL.opJNE, 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;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +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
|
2019-09-26 22:23:06 +02:00
|
|
|
IF e.type = tREAL THEN
|
|
|
|
IL.Float(ARITH.Float(e.value))
|
2019-03-11 09:59:55 +01:00
|
|
|
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
|
2019-09-26 22:23:06 +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
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.PushImpProc(e.ident.import)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF e.type = tREAL THEN
|
|
|
|
IL.retf
|
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
|
|
|
|
id: PROG.IDENT;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
IF (id # NIL) & (id.import # NIL) THEN
|
2019-10-06 19:55:12 +02:00
|
|
|
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
|
|
|
|
rtl := PARS.program.rtl;
|
|
|
|
ASSERT(rtl # NIL);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF CPU IN {cpuX86, cpuAMD64} THEN
|
|
|
|
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, "_error", IL._error);
|
|
|
|
getproc(rtl, "_new", IL._new);
|
|
|
|
getproc(rtl, "_rot", IL._rot);
|
|
|
|
getproc(rtl, "_strcpy", IL._strcpy);
|
2019-10-06 19:55:12 +02:00
|
|
|
getproc(rtl, "_move", IL._move);
|
|
|
|
getproc(rtl, "_divmod", IL._divmod);
|
2019-09-26 22:23:06 +02:00
|
|
|
getproc(rtl, "_set", IL._set);
|
2019-10-06 19:55:12 +02:00
|
|
|
getproc(rtl, "_set1", IL._set1);
|
2019-09-26 22:23:06 +02:00
|
|
|
getproc(rtl, "_isrec", IL._isrec);
|
|
|
|
getproc(rtl, "_lengthw", IL._lengthw);
|
|
|
|
getproc(rtl, "_strcmpw", IL._strcmpw);
|
|
|
|
getproc(rtl, "_dllentry", IL._dllentry);
|
|
|
|
getproc(rtl, "_dispose", IL._dispose);
|
|
|
|
getproc(rtl, "_exit", IL._exit);
|
|
|
|
getproc(rtl, "_init", IL._init);
|
|
|
|
getproc(rtl, "_sofinit", IL._sofinit)
|
|
|
|
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
|
2019-09-26 22:23:06 +02:00
|
|
|
tINTEGER := PARS.program.stTypes.tINTEGER;
|
|
|
|
tBYTE := PARS.program.stTypes.tBYTE;
|
|
|
|
tCHAR := PARS.program.stTypes.tCHAR;
|
|
|
|
tSET := PARS.program.stTypes.tSET;
|
|
|
|
tBOOLEAN := PARS.program.stTypes.tBOOLEAN;
|
|
|
|
tWCHAR := PARS.program.stTypes.tWCHAR;
|
|
|
|
tREAL := PARS.program.stTypes.tREAL;
|
|
|
|
|
|
|
|
Options := options;
|
|
|
|
|
|
|
|
CASE target OF
|
|
|
|
|mConst.Target_iConsole64, mConst.Target_iGUI64, mConst.Target_iDLL64, mConst.Target_iELF64, mConst.Target_iELFSO64:
|
|
|
|
CPU := cpuAMD64
|
|
|
|
|mConst.Target_iConsole, mConst.Target_iGUI, mConst.Target_iDLL,
|
|
|
|
mConst.Target_iKolibri, mConst.Target_iObject, mConst.Target_iELF32,
|
|
|
|
mConst.Target_iELFSO32:
|
|
|
|
CPU := cpuX86
|
|
|
|
|mConst.Target_iMSP430:
|
|
|
|
CPU := cpuMSP430
|
|
|
|
END;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
ext := mConst.FILE_EXT;
|
|
|
|
CaseLabels := C.create();
|
|
|
|
CaseVar := C.create();
|
|
|
|
|
|
|
|
CaseVariants := LISTS.create(NIL);
|
|
|
|
LISTS.push(CaseVariants, NewVariant(0, NIL));
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
CASE CPU OF
|
2019-10-06 19:55:12 +02:00
|
|
|
|cpuAMD64: IL.init(6, IL.little_endian)
|
|
|
|
|cpuX86: IL.init(8, IL.little_endian)
|
|
|
|
|cpuMSP430: IL.init(0, IL.little_endian)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF CPU # cpuMSP430 THEN
|
|
|
|
parser := PARS.create(path, lib_path, StatSeq, expression, designator, chkreturn);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF parser.open(parser, mConst.RTL_NAME) THEN
|
|
|
|
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);
|
|
|
|
IF parser.open(parser, mConst.RTL_NAME) THEN
|
|
|
|
parser.parse(parser);
|
|
|
|
PARS.destroy(parser)
|
|
|
|
ELSE
|
|
|
|
ERRORS.FileNotFound(lib_path, mConst.RTL_NAME, mConst.FILE_EXT)
|
|
|
|
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
|
2019-09-26 22:23:06 +02:00
|
|
|
ERRORS.FileNotFound(path, modname, mConst.FILE_EXT)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
PARS.destroy(parser);
|
|
|
|
|
|
|
|
IF PARS.program.bss > mConst.MAX_GLOBAL_SIZE THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
ERRORS.Error(204)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF CPU # cpuMSP430 THEN
|
|
|
|
setrtl
|
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROG.DelUnused(PARS.program, IL.DelImport);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
IL.set_bss(PARS.program.bss);
|
2019-09-26 22:23:06 +02:00
|
|
|
|
|
|
|
CASE CPU OF
|
2019-10-06 19:55:12 +02:00
|
|
|
| cpuAMD64: AMD64.CodeGen(outname, target, options)
|
|
|
|
| cpuX86: X86.CodeGen(outname, target, options)
|
|
|
|
|cpuMSP430: MSP430.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;
|
|
|
|
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
END STATEMENTS.
|