mirror of
https://github.com/vishapoberon/compiler.git
synced 2026-04-06 06:22:25 +00:00
Support int64 in ABS. Remove unneccessary cast in __XF, __RF.
This commit is contained in:
parent
9baf4c9429
commit
516e261242
4 changed files with 31 additions and 11 deletions
|
|
@ -23,9 +23,6 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LONGINT SYSTEM_ABS (LONGINT i) {return __ABS(i);}
|
|
||||||
double SYSTEM_ABSD(double i) {return __ABS(i);}
|
|
||||||
|
|
||||||
|
|
||||||
int64 SYSTEM_DIV(int64 x, int64 y)
|
int64 SYSTEM_DIV(int64 x, int64 y)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -130,13 +130,13 @@ extern void Platform_AssertFail(LONGINT x);
|
||||||
// Index checking
|
// Index checking
|
||||||
|
|
||||||
static inline int64 __XF(uint64 i, uint64 ub) {if (i >= ub) {__HALT(-2);} return i;}
|
static inline int64 __XF(uint64 i, uint64 ub) {if (i >= ub) {__HALT(-2);} return i;}
|
||||||
#define __X(i, ub) (((uint64)(i)<(uint64)(ub))?i:(__HALT(-2),0))
|
#define __X(i, ub) (((i)<(ub))?i:(__HALT(-2),0))
|
||||||
|
|
||||||
|
|
||||||
// Range checking, and checked SHORT and CHR functions
|
// Range checking, and checked SHORT and CHR functions
|
||||||
|
|
||||||
static inline int64 __RF(uint64 i, uint64 ub) {if (i >= ub) {__HALT(-8);} return i;}
|
static inline int64 __RF(uint64 i, uint64 ub) {if (i >= ub) {__HALT(-8);} return i;}
|
||||||
#define __R(i, ub) (((uint64)(i)<(uint64)(ub))?i:(__HALT(-8),0))
|
#define __R(i, ub) (((i)<(ub))?i:(__HALT(-8),0))
|
||||||
#define __SHORT(x, ub) ((int)((uLONGINT)(x)+(ub)<(ub)+(ub)?(x):(__HALT(-8),0)))
|
#define __SHORT(x, ub) ((int)((uLONGINT)(x)+(ub)<(ub)+(ub)?(x):(__HALT(-8),0)))
|
||||||
#define __SHORTF(x, ub) ((int)(__RF((x)+(ub),(ub)+(ub))-(ub)))
|
#define __SHORTF(x, ub) ((int)(__RF((x)+(ub),(ub)+(ub))-(ub)))
|
||||||
#define __CHR(x) ((CHAR)__R(x, 256))
|
#define __CHR(x) ((CHAR)__R(x, 256))
|
||||||
|
|
@ -147,8 +147,6 @@ static inline int64 __RF(uint64 i, uint64 ub) {if (i >= ub) {__HALT(-8);} return
|
||||||
// Run time system routines in SYSTEM.c
|
// Run time system routines in SYSTEM.c
|
||||||
|
|
||||||
|
|
||||||
extern LONGINT SYSTEM_ABS (LONGINT i);
|
|
||||||
extern double SYSTEM_ABSD (double i);
|
|
||||||
extern void SYSTEM_INHERIT(LONGINT *t, LONGINT *t0);
|
extern void SYSTEM_INHERIT(LONGINT *t, LONGINT *t0);
|
||||||
extern void SYSTEM_ENUMP (void *adr, LONGINT n, void (*P)());
|
extern void SYSTEM_ENUMP (void *adr, LONGINT n, void (*P)());
|
||||||
extern void SYSTEM_ENUMR (void *adr, LONGINT *typ, LONGINT size, LONGINT n, void (*P)());
|
extern void SYSTEM_ENUMR (void *adr, LONGINT *typ, LONGINT size, LONGINT n, void (*P)());
|
||||||
|
|
@ -227,9 +225,16 @@ extern int64 SYSTEM_MOD(int64 x, int64 y);
|
||||||
|
|
||||||
|
|
||||||
#define __ENTIER(x) SYSTEM_ENTIER(x)
|
#define __ENTIER(x) SYSTEM_ENTIER(x)
|
||||||
#define __ABS(x) (((x)<0)?-(x):(x))
|
|
||||||
#define __ABSF(x) SYSTEM_ABS((LONGINT)(x))
|
#define __ABS(x) (((x)<0)?-(x):(x))
|
||||||
#define __ABSFD(x) SYSTEM_ABSD((double)(x))
|
|
||||||
|
static inline int32 SYSTEM_ABS64(int64 i) {return i >= 0 ? i : -i;}
|
||||||
|
static inline int64 SYSTEM_ABS32(int32 i) {return i >= 0 ? i : -i;}
|
||||||
|
#define __ABSF(x) ((sizeof(x) <= 4) ? SYSTEM_ABS32(i) : SYSTEM_ABS64(i))
|
||||||
|
|
||||||
|
static inline double SYSTEM_ABSD(double i) {return i >= 0.0 ? i : -i;}
|
||||||
|
#define __ABSFD(x) SYSTEM_ABSD(x)
|
||||||
|
|
||||||
#define __CAP(ch) ((CHAR)((ch)&0x5f))
|
#define __CAP(ch) ((CHAR)((ch)&0x5f))
|
||||||
#define __ODD(x) ((x)&1)
|
#define __ODD(x) ((x)&1)
|
||||||
#define __IN(x, s) ((x)>=0 && (x)<(8*sizeof(SET)) && ((((uSET)(s))>>(x))&1))
|
#define __IN(x, s) ((x)>=0 && (x)<(8*sizeof(SET)) && ((((uSET)(s))>>(x))&1))
|
||||||
|
|
|
||||||
|
|
@ -220,6 +220,23 @@ END DivMod;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PROCEDURE Abs;
|
||||||
|
VAR
|
||||||
|
i: INTEGER;
|
||||||
|
l: LONGINT;
|
||||||
|
h: SYSTEM.INT64;
|
||||||
|
BEGIN
|
||||||
|
i := 5; TestValue(ABS(i), 5, "ABS(INTEGER 5)");
|
||||||
|
i := -5; TestValue(ABS(i), 5, "ABS(INTEGER -5)");
|
||||||
|
l := 5; TestValue(ABS(l), 5, "ABS(LONGINT 5)");
|
||||||
|
l := -5; TestValue(ABS(l), 5, "ABS(LONGINT -5)");
|
||||||
|
h := 5; TestValue(SYSTEM.VAL(LONGINT,ABS(h)), 5, "ABS(SYSTEM.INT64 5)");
|
||||||
|
h := -5; TestValue(SYSTEM.VAL(LONGINT,ABS(h)), 5, "ABS(SYSTEM.INT64 -5)");
|
||||||
|
END Abs;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PROCEDURE IntSize;
|
PROCEDURE IntSize;
|
||||||
VAR l: LONGINT;
|
VAR l: LONGINT;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
@ -253,5 +270,6 @@ BEGIN
|
||||||
Shift;
|
Shift;
|
||||||
DivMod;
|
DivMod;
|
||||||
IntSize;
|
IntSize;
|
||||||
|
Abs;
|
||||||
Console.String("Language tests successful."); Console.Ln;
|
Console.String("Language tests successful."); Console.Ln;
|
||||||
END TestLanguage.
|
END TestLanguage.
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
12 Sep 2016 15:40:20
|
12 Sep 2016 17:01:41
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue