From f13130bbd3e47f2aed485f655e15ff2ede5687d2 Mon Sep 17 00:00:00 2001 From: David Brown Date: Tue, 13 Sep 2016 20:35:29 +0100 Subject: [PATCH] Add set size to __SETOF and __SETRNG. --- src/compiler/OPV.Mod | 15 ++++++++------- src/system/SYSTEM.h | 11 +++++------ src/tools/make/configure.c | 5 ++++- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/compiler/OPV.Mod b/src/compiler/OPV.Mod index ef8a1394..f4a82ca5 100644 --- a/src/compiler/OPV.Mod +++ b/src/compiler/OPV.Mod @@ -27,8 +27,6 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96 GuardPtrFunc = "__GUARDP("; GuardRecFunc = "__GUARDR("; TypeFunc = "__TYPEOF("; - SetOfFunc = "__SETOF("; - SetRangeFunc = "__SETRNG("; CopyFunc = "__COPY("; MoveFunc = "__MOVE("; GetFunc = "__GET("; @@ -293,7 +291,9 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96 PROCEDURE Convert(n: OPT.Node; newtype: OPT.Struct; prec: INTEGER); VAR from, to: INTEGER; BEGIN from := n^.typ^.form; to := newtype.form; - IF to = OPT.Set THEN OPM.WriteString(SetOfFunc); Entier(n, MinPrec); OPM.Write(CloseParen) + IF to = OPT.Set THEN + OPM.WriteString("__SETOF("); Entier(n, MinPrec); + OPM.WriteString(","); OPM.WriteInt(newtype.size*8); OPM.Write(CloseParen) ELSIF to = OPT.Int THEN IF (newtype.size < n.typ.size) & (OPM.ranchk IN OPM.opt) THEN OPM.WriteString("__SHORT"); IF SideEffects(n) THEN OPM.Write("F") END; @@ -527,8 +527,8 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96 CASE class OF | OPT.Nconst: OPC.Constant(n^.conval, form) | OPT.Nupto: (* n^.typ = OPT.settyp *) - OPM.WriteString(SetRangeFunc); expr(l, MinPrec); OPM.WriteString(Comma); expr (r, MinPrec); - OPM.Write(CloseParen) + OPM.WriteString("__SETRNG("); expr(l, MinPrec); OPM.WriteString(Comma); expr(r, MinPrec); + OPM.WriteString(Comma); OPM.WriteInt(n.typ.size*8); OPM.Write(CloseParen) | OPT.Nmop: CASE subclass OF | OPS.not: OPM.Write("!"); expr(l, exprPrec) @@ -865,8 +865,9 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96 | OPT.incfn, OPT.decfn: expr(n^.left, MinPrec); OPC.Increment(n^.subcl = OPT.decfn); expr(n^.right, MinPrec) | OPT.inclfn, - OPT.exclfn: expr(n^.left, MinPrec); OPC.SetInclude(n^.subcl = OPT.exclfn); OPM.WriteString(SetOfFunc); expr(n^.right, MinPrec); - OPM.Write(CloseParen) + OPT.exclfn: expr(n^.left, MinPrec); OPC.SetInclude(n^.subcl = OPT.exclfn); + OPM.WriteString("__SETOF("); expr(n^.right, MinPrec); + OPM.WriteString(","); OPM.WriteInt(n.left.typ.size*8); OPM.Write(CloseParen) | OPT.copyfn: OPM.WriteString(CopyFunc); expr(n^.right, MinPrec); OPM.WriteString(Comma); expr(n^.left, MinPrec); OPM.WriteString(Comma); Len(n^.left, 0); OPM.Write(CloseParen) diff --git a/src/system/SYSTEM.h b/src/system/SYSTEM.h index 896934e7..7c645e85 100644 --- a/src/system/SYSTEM.h +++ b/src/system/SYSTEM.h @@ -228,13 +228,12 @@ static inline double SYSTEM_ABSD(double i) {return i >= 0.0 ? i : -i;} #define __CAP(ch) ((CHAR)((ch)&0x5f)) #define __ODD(x) ((x)&1) -//#define __IN(x, s, size) ((x)>=0 && (x)>(x))&1)) +#define __IN(x, s, size) (((unsigned int)(x))>(x))&1)) +#define __SETOF(x, size) ((uint##size)1<<(x)) +#define __SETRNG(l, h, size) ((~(uint##size)0<<(l))&~(uint##size)0>>(size-1-(h))) -#define __IN(x, s, size) (((unsigned int)(x))>(x))&1)) -#define __SETOF(x) ((SET)1<<(x)) -#define __SETRNG(l, h) ((~(SET)0<<(l))&~(SET)0>>(8*sizeof(SET)-1-(h))) -#define __MASK(x, m) ((x)&~(m)) -#define __BIT(x, n) (*(uint64*)(x)>>(n)&1) +#define __MASK(x, m) ((x)&~(m)) +#define __BIT(x, n) (*(uint64*)(x)>>(n)&1) diff --git a/src/tools/make/configure.c b/src/tools/make/configure.c index 10886067..f976c756 100644 --- a/src/tools/make/configure.c +++ b/src/tools/make/configure.c @@ -313,7 +313,10 @@ void testSystemDotH() { /* test the __SETRNG macro */ long x = 0; long y = sizeof(SET)*8 - 1; - assert(__SETRNG(x, y) == -1, "SETRNG(0, MAX(SET)) != -1."); + if (sizeof(SET) == 4) + assert(__SETRNG(x, y, 32) == -1, "SETRNG(0, MAX(SET)) != -1."); + else + assert(__SETRNG(x, y, 64) == -1, "SETRNG(0, MAX(SET)) != -1."); /* test string comparison for extended ascii */ {char a[10], b[10];