|
|
@@ -2622,7 +2622,8 @@ PRODUCTIONS
|
|
|
astD: AST.Node;
|
|
|
astCall: BOOLEAN;
|
|
|
astNode, astNot: AST.Node;
|
|
|
- j: CARDINAL; .)
|
|
|
+ j: CARDINAL;
|
|
|
+ astArg2: AST.Node; .)
|
|
|
= (. astIsLit := FALSE; .)
|
|
|
( integer (. LexString(s);
|
|
|
QbeGen.NormInt(s, q); IF twoPhase THEN astIsLit := TRUE; astCur := AST.MakeLeaf(AST.NkIntLit, s) END;
|
|
|
@@ -2786,7 +2787,7 @@ PRODUCTIONS
|
|
|
| ( "LEN" | "LENGTH" ) (. isHigh := FALSE; .) )
|
|
|
"(" ( Design<dt, dk, qd, qn, sfx> (. isStr := FALSE;
|
|
|
isU := FALSE; .)
|
|
|
- | string (. LexString(s);
|
|
|
+ | string (. LexString(s); astCur := AST.MakeLeaf(AST.NkStrLit, s);
|
|
|
isStr := TRUE;
|
|
|
isU := FALSE;
|
|
|
IF SymTab.StrLen(s) = 3 THEN
|
|
|
@@ -2800,7 +2801,7 @@ PRODUCTIONS
|
|
|
END;
|
|
|
dk := -1;
|
|
|
qn[0] := CHR(0); .)
|
|
|
- | ustring (. LexString(s);
|
|
|
+ | ustring (. LexString(s); astCur := AST.MakeLeaf(AST.NkStrLit, s);
|
|
|
QbeGen.DeclUStr(s, qd, isU, ucp,
|
|
|
uok);
|
|
|
isStr := FALSE;
|
|
|
@@ -2819,7 +2820,14 @@ PRODUCTIONS
|
|
|
dk := -1;
|
|
|
qn[0] := CHR(0); .) )
|
|
|
")"
|
|
|
- (. IF (dt # SymTab.InvalidType)
|
|
|
+ (. astNode := AST.MakeNode(AST.NkCall);
|
|
|
+ IF isHigh THEN AST.SetChild(astNode, 0,
|
|
|
+ AST.MakeLeaf(AST.NkIdent, "HIGH"))
|
|
|
+ ELSE AST.SetChild(astNode, 0,
|
|
|
+ AST.MakeLeaf(AST.NkIdent, "LEN")) END;
|
|
|
+ IF astCur # AST.NoNode THEN AST.SetChild(astNode, 1, astCur) END;
|
|
|
+ astCur := astNode; astIsLit := TRUE;
|
|
|
+ IF (dt # SymTab.InvalidType)
|
|
|
AND (SymTab.ClassOf(dt) = SymTab.ClUStr) THEN
|
|
|
(* UString: the count is
|
|
|
the descriptor header *)
|
|
|
@@ -2886,6 +2894,10 @@ PRODUCTIONS
|
|
|
QbeGen.CopyOp(qr, q)
|
|
|
END; .)
|
|
|
| ( "SIZE" | "TSIZE" ) "(" Design<dt, dk, qd, qn, sfx> ")"
|
|
|
+ (. astNode := AST.MakeNode(AST.NkCall);
|
|
|
+ AST.SetChild(astNode, 0, AST.MakeLeaf(AST.NkIdent, "SIZE"));
|
|
|
+ IF astCur # AST.NoNode THEN AST.SetChild(astNode, 1, astCur) END;
|
|
|
+ astCur := astNode; astIsLit := TRUE; .)
|
|
|
(. IF dt = SymTab.InvalidType THEN
|
|
|
t := SymTab.InvalidType;
|
|
|
QbeGen.CopyOp("0", q)
|
|
|
@@ -2896,8 +2908,16 @@ PRODUCTIONS
|
|
|
END; .)
|
|
|
| ( "SHIFT" (. isMax := FALSE; .)
|
|
|
| "ROTATE" (. isMax := TRUE; .) )
|
|
|
- "(" Expr<et, q> "," Expr<et2, q2> ")"
|
|
|
- (. (* set shift/rotate: isMax
|
|
|
+ "(" Expr<et, q> (. astArg2 := astCur; .) "," Expr<et2, q2> ")"
|
|
|
+ (. astNode := AST.MakeNode(AST.NkCall);
|
|
|
+ IF isMax THEN AST.SetChild(astNode, 0,
|
|
|
+ AST.MakeLeaf(AST.NkIdent, "ROTATE"))
|
|
|
+ ELSE AST.SetChild(astNode, 0,
|
|
|
+ AST.MakeLeaf(AST.NkIdent, "SHIFT")) END;
|
|
|
+ IF astArg2 # AST.NoNode THEN AST.SetChild(astNode, 1, astArg2) END;
|
|
|
+ IF astCur # AST.NoNode THEN AST.SetChild(astNode, 2, astCur) END;
|
|
|
+ astCur := astNode; astIsLit := TRUE;
|
|
|
+ (* set shift/rotate: isMax
|
|
|
doubles as "rotate" *)
|
|
|
IF (et # SymTab.InvalidType)
|
|
|
AND (SymTab.ClassOf(et) =
|
|
|
@@ -2915,7 +2935,14 @@ PRODUCTIONS
|
|
|
| ( "MIN" (. isMax := FALSE; .)
|
|
|
| "MAX" (. isMax := TRUE; .) )
|
|
|
"(" Design<dt, dk, qd, qn, sfx> ")"
|
|
|
- (. IF (dt # SymTab.InvalidType)
|
|
|
+ (. astNode := AST.MakeNode(AST.NkCall);
|
|
|
+ IF isMax THEN AST.SetChild(astNode, 0,
|
|
|
+ AST.MakeLeaf(AST.NkIdent, "MAX"))
|
|
|
+ ELSE AST.SetChild(astNode, 0,
|
|
|
+ AST.MakeLeaf(AST.NkIdent, "MIN")) END;
|
|
|
+ IF astCur # AST.NoNode THEN AST.SetChild(astNode, 1, astCur) END;
|
|
|
+ astCur := astNode; astIsLit := TRUE;
|
|
|
+ IF (dt # SymTab.InvalidType)
|
|
|
AND (SymTab.ClassOf(dt) = SymTab.ClReal) THEN
|
|
|
(* REAL/LONGREAL: the
|
|
|
implementation bounds *)
|
|
|
@@ -2949,6 +2976,10 @@ PRODUCTIONS
|
|
|
QbeGen.CopyOp("0", q)
|
|
|
END; .)
|
|
|
| "ADR" "(" Design<dt, dk, qd, qn, sfx> ")"
|
|
|
+ (. astNode := AST.MakeNode(AST.NkCall);
|
|
|
+ AST.SetChild(astNode, 0, AST.MakeLeaf(AST.NkIdent, "ADR"));
|
|
|
+ IF astCur # AST.NoNode THEN AST.SetChild(astNode, 1, astCur) END;
|
|
|
+ astCur := astNode; astIsLit := TRUE; .)
|
|
|
(. IF dt = SymTab.InvalidType THEN
|
|
|
t := SymTab.InvalidType;
|
|
|
QbeGen.CopyOp("0", q)
|
|
|
@@ -2964,11 +2995,19 @@ PRODUCTIONS
|
|
|
t := SymTab.AddrType()
|
|
|
END; .)
|
|
|
| "CHR" "(" Expr<et, q> ")"
|
|
|
+ (. astNode := AST.MakeNode(AST.NkCall);
|
|
|
+ AST.SetChild(astNode, 0, AST.MakeLeaf(AST.NkIdent, "CHR"));
|
|
|
+ IF astCur # AST.NoNode THEN AST.SetChild(astNode, 1, astCur) END;
|
|
|
+ astCur := astNode; astIsLit := TRUE; .)
|
|
|
(. IF (et # SymTab.InvalidType)
|
|
|
AND NOT SymTab.IsIntFamily(et) THEN
|
|
|
SemError(211) END;
|
|
|
t := SymTab.CharType(); .)
|
|
|
| ( "ORD" | "ORDL" ) "(" Expr<et, q> ")"
|
|
|
+ (. astNode := AST.MakeNode(AST.NkCall);
|
|
|
+ AST.SetChild(astNode, 0, AST.MakeLeaf(AST.NkIdent, "ORD"));
|
|
|
+ IF astCur # AST.NoNode THEN AST.SetChild(astNode, 1, astCur) END;
|
|
|
+ astCur := astNode; astIsLit := TRUE; .)
|
|
|
(. IF et # SymTab.InvalidType THEN
|
|
|
IF (SymTab.ClassOf(et) #
|
|
|
SymTab.ClChar)
|
|
|
@@ -2981,10 +3020,18 @@ PRODUCTIONS
|
|
|
END;
|
|
|
t := SymTab.IntType(); .)
|
|
|
| "CAP" "(" Expr<et, q> ")"
|
|
|
+ (. astNode := AST.MakeNode(AST.NkCall);
|
|
|
+ AST.SetChild(astNode, 0, AST.MakeLeaf(AST.NkIdent, "CAP"));
|
|
|
+ IF astCur # AST.NoNode THEN AST.SetChild(astNode, 1, astCur) END;
|
|
|
+ astCur := astNode; astIsLit := TRUE; .)
|
|
|
(. QbeGen.CapQ(q, qa);
|
|
|
QbeGen.CopyOp(qa, q);
|
|
|
t := SymTab.CharType(); .)
|
|
|
| "UCHR" "(" Expr<et, q> ")"
|
|
|
+ (. astNode := AST.MakeNode(AST.NkCall);
|
|
|
+ AST.SetChild(astNode, 0, AST.MakeLeaf(AST.NkIdent, "UCHR"));
|
|
|
+ IF astCur # AST.NoNode THEN AST.SetChild(astNode, 1, astCur) END;
|
|
|
+ astCur := astNode; astIsLit := TRUE; .)
|
|
|
(. (* UCHR: the UCHAR constructor.
|
|
|
CHAR -> UCHAR (identity);
|
|
|
INTEGER familly -> UCHAR
|
|
|
@@ -2995,6 +3042,10 @@ PRODUCTIONS
|
|
|
SemError(211) END;
|
|
|
t := SymTab.UCharType(); .)
|
|
|
| "CHR8" "(" Expr<et, q> ")"
|
|
|
+ (. astNode := AST.MakeNode(AST.NkCall);
|
|
|
+ AST.SetChild(astNode, 0, AST.MakeLeaf(AST.NkIdent, "CHR8"));
|
|
|
+ IF astCur # AST.NoNode THEN AST.SetChild(astNode, 1, astCur) END;
|
|
|
+ astCur := astNode; astIsLit := TRUE; .)
|
|
|
(. IF (et # SymTab.InvalidType)
|
|
|
AND (SymTab.ClassOf(et) # SymTab.ClUChar) THEN
|
|
|
SemError(211) END;
|
|
|
@@ -3002,6 +3053,10 @@ PRODUCTIONS
|
|
|
QbeGen.CheckRange(qa, "0", "255");
|
|
|
t := SymTab.CharType(); .)
|
|
|
| "UORD" "(" Expr<et, q> ")"
|
|
|
+ (. astNode := AST.MakeNode(AST.NkCall);
|
|
|
+ AST.SetChild(astNode, 0, AST.MakeLeaf(AST.NkIdent, "UORD"));
|
|
|
+ IF astCur # AST.NoNode THEN AST.SetChild(astNode, 1, astCur) END;
|
|
|
+ astCur := astNode; astIsLit := TRUE; .)
|
|
|
(. (* UORD(u): the codepoint as a
|
|
|
32-bit ordinal (INTEGER),
|
|
|
cf. ORD for CHAR. *)
|
|
|
@@ -3010,6 +3065,10 @@ PRODUCTIONS
|
|
|
SemError(211) END;
|
|
|
t := SymTab.IntType(); .)
|
|
|
| "ABS" "(" Expr<et, q> ")"
|
|
|
+ (. astNode := AST.MakeNode(AST.NkCall);
|
|
|
+ AST.SetChild(astNode, 0, AST.MakeLeaf(AST.NkIdent, "ABS"));
|
|
|
+ IF astCur # AST.NoNode THEN AST.SetChild(astNode, 1, astCur) END;
|
|
|
+ astCur := astNode; astIsLit := TRUE; .)
|
|
|
(. IF (et # SymTab.InvalidType)
|
|
|
AND NOT SymTab.IsIntFamily(et)
|
|
|
AND (SymTab.ClassOf(et) #
|
|
|
@@ -3021,7 +3080,12 @@ PRODUCTIONS
|
|
|
QbeGen.CopyOp(qa, q)
|
|
|
END;
|
|
|
t := et; .)
|
|
|
- | "VAL" "(" GetIdent<vn> "," Expr<et, q> ")"
|
|
|
+ | "VAL" "(" GetIdent<vn> (. astArg2 := AST.MakeLeaf(AST.NkIdent, vn); .) "," Expr<et, q> ")"
|
|
|
+ (. astNode := AST.MakeNode(AST.NkCall);
|
|
|
+ AST.SetChild(astNode, 0, AST.MakeLeaf(AST.NkIdent, "VAL"));
|
|
|
+ IF astArg2 # AST.NoNode THEN AST.SetChild(astNode, 1, astArg2) END;
|
|
|
+ IF astCur # AST.NoNode THEN AST.SetChild(astNode, 2, astCur) END;
|
|
|
+ astCur := astNode; astIsLit := TRUE; .)
|
|
|
(. IF NOT SymTab.Lookup(vn) THEN
|
|
|
SemError(201);
|
|
|
t := SymTab.InvalidType
|