From 80f5e517897a11e0ae43ef0652387580eefac232 Mon Sep 17 00:00:00 2001 From: David Brown Date: Tue, 16 Aug 2016 20:30:05 +0100 Subject: [PATCH] Original meaning of VAL restored. Many library files disabled until use of VAL in 64 bits fixed. --- bootstrap/unix-44/Files.c | 4 +- bootstrap/unix-44/OPB.c | 3 + bootstrap/unix-44/OPM.c | 10 +- bootstrap/unix-44/SYSTEM.h | 7 +- bootstrap/unix-48/Files.c | 4 +- bootstrap/unix-48/OPB.c | 3 + bootstrap/unix-48/OPM.c | 10 +- bootstrap/unix-48/SYSTEM.h | 7 +- bootstrap/unix-88/Files.c | 4 +- bootstrap/unix-88/OPB.c | 3 + bootstrap/unix-88/OPM.c | 6 +- bootstrap/unix-88/SYSTEM.h | 7 +- bootstrap/windows-48/Files.c | 4 +- bootstrap/windows-48/OPB.c | 3 + bootstrap/windows-48/OPM.c | 10 +- bootstrap/windows-48/SYSTEM.h | 7 +- bootstrap/windows-88/Files.c | 4 +- bootstrap/windows-88/OPB.c | 3 + bootstrap/windows-88/OPM.c | 6 +- bootstrap/windows-88/SYSTEM.h | 7 +- makefile | 21 +++ src/compiler/OPB.Mod | 2 +- src/compiler/OPM.cmdln.Mod | 17 +- src/compiler/OPV.Mod | 7 - src/library/ooc/oocLowReal.Mod | 152 +++++++++--------- src/system/Files.Mod | 7 +- src/system/SYSTEM.h | 4 +- src/test/confidence/language/TestLanguage.mod | 2 +- src/tools/make/vishap.make | 111 ++++++------- 29 files changed, 261 insertions(+), 174 deletions(-) diff --git a/bootstrap/unix-44/Files.c b/bootstrap/unix-44/Files.c index e0c81e49..1a2edfbf 100644 --- a/bootstrap/unix-44/Files.c +++ b/bootstrap/unix-44/Files.c @@ -864,8 +864,10 @@ void Files_ReadLInt (Files_Rider *R, LONGINT *R__typ, LONGINT *x) void Files_ReadSet (Files_Rider *R, LONGINT *R__typ, SET *x) { CHAR b[4]; + LONGINT l; Files_ReadBytes(&*R, R__typ, (void*)b, ((LONGINT)(4)), ((LONGINT)(4))); - *x = (SET)(((LONGINT)((int)b[0] + __ASHL((int)b[1], 8)) + __ASHL((LONGINT)b[2], 16)) + __ASHL((LONGINT)b[3], 24)); + l = ((LONGINT)((int)b[0] + __ASHL((int)b[1], 8)) + __ASHL((LONGINT)b[2], 16)) + __ASHL((LONGINT)b[3], 24); + *x = (SET)l; } void Files_ReadReal (Files_Rider *R, LONGINT *R__typ, REAL *x) diff --git a/bootstrap/unix-44/OPB.c b/bootstrap/unix-44/OPB.c index 170446bd..adf8defa 100644 --- a/bootstrap/unix-44/OPB.c +++ b/bootstrap/unix-44/OPB.c @@ -2237,6 +2237,9 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) if (((x->class == 8 || x->class == 9) || __IN(f, 0x1401)) || x->typ->comp == 3) { OPB_err(126); } + if (x->typ->size < p->typ->size) { + OPB_err(-308); + } t = OPT_NewNode(11); t->subcl = 29; t->left = x; diff --git a/bootstrap/unix-44/OPM.c b/bootstrap/unix-44/OPM.c index 1d0fcc55..dd62beba 100644 --- a/bootstrap/unix-44/OPM.c +++ b/bootstrap/unix-44/OPM.c @@ -541,16 +541,16 @@ void OPM_FPrintSet (LONGINT *fp, SET set) void OPM_FPrintReal (LONGINT *fp, REAL real) { - OPM_FPrint(&*fp, __VAL(LONGINT, real)); + INTEGER i; + LONGINT l; + __GET((LONGINT)(uintptr_t)&real, l, LONGINT); + OPM_FPrint(&*fp, l); } void OPM_FPrintLReal (LONGINT *fp, LONGREAL lr) { LONGINT l, h; - __GET((LONGINT)(uintptr_t)&lr, l, LONGINT); - __GET((LONGINT)(uintptr_t)&lr + 4, h, LONGINT); - OPM_FPrint(&*fp, l); - OPM_FPrint(&*fp, h); + OPM_FPrint(&*fp, __VAL(LONGINT, lr)); } static void OPM_GetProperty (Texts_Scanner *S, LONGINT *S__typ, CHAR *name, LONGINT name__len, INTEGER *size, INTEGER *align) diff --git a/bootstrap/unix-44/SYSTEM.h b/bootstrap/unix-44/SYSTEM.h index 2941064e..394407bd 100644 --- a/bootstrap/unix-44/SYSTEM.h +++ b/bootstrap/unix-44/SYSTEM.h @@ -134,8 +134,11 @@ static int __str_cmp(CHAR *x, CHAR *y){ /* SYSTEM ops */ -#define __VAL(t, x) ((t)(x)) -#define __VALP(t, x) ((t)(uintptr_t)(x)) +//#define __VAL(t, x) ((t)(x)) +//#define __VALP(t, x) ((t)(uintptr_t)(x)) +#define __VAL(t, x) (*(t*)&(x)) +#define __VALP(t, x) (*(t*)&(x)) + #define __GET(a, x, t) x= *(t*)(uintptr_t)(a) #define __PUT(a, x, t) *(t*)(uintptr_t)(a)=x diff --git a/bootstrap/unix-48/Files.c b/bootstrap/unix-48/Files.c index e0c81e49..1a2edfbf 100644 --- a/bootstrap/unix-48/Files.c +++ b/bootstrap/unix-48/Files.c @@ -864,8 +864,10 @@ void Files_ReadLInt (Files_Rider *R, LONGINT *R__typ, LONGINT *x) void Files_ReadSet (Files_Rider *R, LONGINT *R__typ, SET *x) { CHAR b[4]; + LONGINT l; Files_ReadBytes(&*R, R__typ, (void*)b, ((LONGINT)(4)), ((LONGINT)(4))); - *x = (SET)(((LONGINT)((int)b[0] + __ASHL((int)b[1], 8)) + __ASHL((LONGINT)b[2], 16)) + __ASHL((LONGINT)b[3], 24)); + l = ((LONGINT)((int)b[0] + __ASHL((int)b[1], 8)) + __ASHL((LONGINT)b[2], 16)) + __ASHL((LONGINT)b[3], 24); + *x = (SET)l; } void Files_ReadReal (Files_Rider *R, LONGINT *R__typ, REAL *x) diff --git a/bootstrap/unix-48/OPB.c b/bootstrap/unix-48/OPB.c index 170446bd..adf8defa 100644 --- a/bootstrap/unix-48/OPB.c +++ b/bootstrap/unix-48/OPB.c @@ -2237,6 +2237,9 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) if (((x->class == 8 || x->class == 9) || __IN(f, 0x1401)) || x->typ->comp == 3) { OPB_err(126); } + if (x->typ->size < p->typ->size) { + OPB_err(-308); + } t = OPT_NewNode(11); t->subcl = 29; t->left = x; diff --git a/bootstrap/unix-48/OPM.c b/bootstrap/unix-48/OPM.c index 1d0fcc55..dd62beba 100644 --- a/bootstrap/unix-48/OPM.c +++ b/bootstrap/unix-48/OPM.c @@ -541,16 +541,16 @@ void OPM_FPrintSet (LONGINT *fp, SET set) void OPM_FPrintReal (LONGINT *fp, REAL real) { - OPM_FPrint(&*fp, __VAL(LONGINT, real)); + INTEGER i; + LONGINT l; + __GET((LONGINT)(uintptr_t)&real, l, LONGINT); + OPM_FPrint(&*fp, l); } void OPM_FPrintLReal (LONGINT *fp, LONGREAL lr) { LONGINT l, h; - __GET((LONGINT)(uintptr_t)&lr, l, LONGINT); - __GET((LONGINT)(uintptr_t)&lr + 4, h, LONGINT); - OPM_FPrint(&*fp, l); - OPM_FPrint(&*fp, h); + OPM_FPrint(&*fp, __VAL(LONGINT, lr)); } static void OPM_GetProperty (Texts_Scanner *S, LONGINT *S__typ, CHAR *name, LONGINT name__len, INTEGER *size, INTEGER *align) diff --git a/bootstrap/unix-48/SYSTEM.h b/bootstrap/unix-48/SYSTEM.h index 2941064e..394407bd 100644 --- a/bootstrap/unix-48/SYSTEM.h +++ b/bootstrap/unix-48/SYSTEM.h @@ -134,8 +134,11 @@ static int __str_cmp(CHAR *x, CHAR *y){ /* SYSTEM ops */ -#define __VAL(t, x) ((t)(x)) -#define __VALP(t, x) ((t)(uintptr_t)(x)) +//#define __VAL(t, x) ((t)(x)) +//#define __VALP(t, x) ((t)(uintptr_t)(x)) +#define __VAL(t, x) (*(t*)&(x)) +#define __VALP(t, x) (*(t*)&(x)) + #define __GET(a, x, t) x= *(t*)(uintptr_t)(a) #define __PUT(a, x, t) *(t*)(uintptr_t)(a)=x diff --git a/bootstrap/unix-88/Files.c b/bootstrap/unix-88/Files.c index af05eb47..eb46629e 100644 --- a/bootstrap/unix-88/Files.c +++ b/bootstrap/unix-88/Files.c @@ -865,8 +865,10 @@ void Files_ReadLInt (Files_Rider *R, LONGINT *R__typ, LONGINT *x) void Files_ReadSet (Files_Rider *R, LONGINT *R__typ, SET *x) { CHAR b[4]; + LONGINT l; Files_ReadBytes(&*R, R__typ, (void*)b, ((LONGINT)(4)), ((LONGINT)(4))); - *x = (SET)((((int)b[0] + __ASHL((int)b[1], 8)) + __ASHL((int)b[2], 16)) + __ASHL((int)b[3], 24)); + l = (((int)b[0] + __ASHL((int)b[1], 8)) + __ASHL((int)b[2], 16)) + __ASHL((int)b[3], 24); + *x = (SET)l; } void Files_ReadReal (Files_Rider *R, LONGINT *R__typ, REAL *x) diff --git a/bootstrap/unix-88/OPB.c b/bootstrap/unix-88/OPB.c index 7c386855..248a0348 100644 --- a/bootstrap/unix-88/OPB.c +++ b/bootstrap/unix-88/OPB.c @@ -2238,6 +2238,9 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) if (((x->class == 8 || x->class == 9) || __IN(f, 0x1401)) || x->typ->comp == 3) { OPB_err(126); } + if (x->typ->size < p->typ->size) { + OPB_err(-308); + } t = OPT_NewNode(11); t->subcl = 29; t->left = x; diff --git a/bootstrap/unix-88/OPM.c b/bootstrap/unix-88/OPM.c index 62922f95..092edf6c 100644 --- a/bootstrap/unix-88/OPM.c +++ b/bootstrap/unix-88/OPM.c @@ -542,7 +542,11 @@ void OPM_FPrintSet (LONGINT *fp, SET set) void OPM_FPrintReal (LONGINT *fp, REAL real) { - OPM_FPrint(&*fp, __VAL(LONGINT, real)); + INTEGER i; + LONGINT l; + __GET((LONGINT)(uintptr_t)&real, i, INTEGER); + l = i; + OPM_FPrint(&*fp, l); } void OPM_FPrintLReal (LONGINT *fp, LONGREAL lr) diff --git a/bootstrap/unix-88/SYSTEM.h b/bootstrap/unix-88/SYSTEM.h index 2941064e..394407bd 100644 --- a/bootstrap/unix-88/SYSTEM.h +++ b/bootstrap/unix-88/SYSTEM.h @@ -134,8 +134,11 @@ static int __str_cmp(CHAR *x, CHAR *y){ /* SYSTEM ops */ -#define __VAL(t, x) ((t)(x)) -#define __VALP(t, x) ((t)(uintptr_t)(x)) +//#define __VAL(t, x) ((t)(x)) +//#define __VALP(t, x) ((t)(uintptr_t)(x)) +#define __VAL(t, x) (*(t*)&(x)) +#define __VALP(t, x) (*(t*)&(x)) + #define __GET(a, x, t) x= *(t*)(uintptr_t)(a) #define __PUT(a, x, t) *(t*)(uintptr_t)(a)=x diff --git a/bootstrap/windows-48/Files.c b/bootstrap/windows-48/Files.c index 71c35083..a6827339 100644 --- a/bootstrap/windows-48/Files.c +++ b/bootstrap/windows-48/Files.c @@ -864,8 +864,10 @@ void Files_ReadLInt (Files_Rider *R, LONGINT *R__typ, LONGINT *x) void Files_ReadSet (Files_Rider *R, LONGINT *R__typ, SET *x) { CHAR b[4]; + LONGINT l; Files_ReadBytes(&*R, R__typ, (void*)b, ((LONGINT)(4)), ((LONGINT)(4))); - *x = (SET)(((LONGINT)((int)b[0] + __ASHL((int)b[1], 8)) + __ASHL((LONGINT)b[2], 16)) + __ASHL((LONGINT)b[3], 24)); + l = ((LONGINT)((int)b[0] + __ASHL((int)b[1], 8)) + __ASHL((LONGINT)b[2], 16)) + __ASHL((LONGINT)b[3], 24); + *x = (SET)l; } void Files_ReadReal (Files_Rider *R, LONGINT *R__typ, REAL *x) diff --git a/bootstrap/windows-48/OPB.c b/bootstrap/windows-48/OPB.c index 170446bd..adf8defa 100644 --- a/bootstrap/windows-48/OPB.c +++ b/bootstrap/windows-48/OPB.c @@ -2237,6 +2237,9 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) if (((x->class == 8 || x->class == 9) || __IN(f, 0x1401)) || x->typ->comp == 3) { OPB_err(126); } + if (x->typ->size < p->typ->size) { + OPB_err(-308); + } t = OPT_NewNode(11); t->subcl = 29; t->left = x; diff --git a/bootstrap/windows-48/OPM.c b/bootstrap/windows-48/OPM.c index 1d0fcc55..dd62beba 100644 --- a/bootstrap/windows-48/OPM.c +++ b/bootstrap/windows-48/OPM.c @@ -541,16 +541,16 @@ void OPM_FPrintSet (LONGINT *fp, SET set) void OPM_FPrintReal (LONGINT *fp, REAL real) { - OPM_FPrint(&*fp, __VAL(LONGINT, real)); + INTEGER i; + LONGINT l; + __GET((LONGINT)(uintptr_t)&real, l, LONGINT); + OPM_FPrint(&*fp, l); } void OPM_FPrintLReal (LONGINT *fp, LONGREAL lr) { LONGINT l, h; - __GET((LONGINT)(uintptr_t)&lr, l, LONGINT); - __GET((LONGINT)(uintptr_t)&lr + 4, h, LONGINT); - OPM_FPrint(&*fp, l); - OPM_FPrint(&*fp, h); + OPM_FPrint(&*fp, __VAL(LONGINT, lr)); } static void OPM_GetProperty (Texts_Scanner *S, LONGINT *S__typ, CHAR *name, LONGINT name__len, INTEGER *size, INTEGER *align) diff --git a/bootstrap/windows-48/SYSTEM.h b/bootstrap/windows-48/SYSTEM.h index 2941064e..394407bd 100644 --- a/bootstrap/windows-48/SYSTEM.h +++ b/bootstrap/windows-48/SYSTEM.h @@ -134,8 +134,11 @@ static int __str_cmp(CHAR *x, CHAR *y){ /* SYSTEM ops */ -#define __VAL(t, x) ((t)(x)) -#define __VALP(t, x) ((t)(uintptr_t)(x)) +//#define __VAL(t, x) ((t)(x)) +//#define __VALP(t, x) ((t)(uintptr_t)(x)) +#define __VAL(t, x) (*(t*)&(x)) +#define __VALP(t, x) (*(t*)&(x)) + #define __GET(a, x, t) x= *(t*)(uintptr_t)(a) #define __PUT(a, x, t) *(t*)(uintptr_t)(a)=x diff --git a/bootstrap/windows-88/Files.c b/bootstrap/windows-88/Files.c index fee8c042..e7ae960d 100644 --- a/bootstrap/windows-88/Files.c +++ b/bootstrap/windows-88/Files.c @@ -865,8 +865,10 @@ void Files_ReadLInt (Files_Rider *R, LONGINT *R__typ, LONGINT *x) void Files_ReadSet (Files_Rider *R, LONGINT *R__typ, SET *x) { CHAR b[4]; + LONGINT l; Files_ReadBytes(&*R, R__typ, (void*)b, ((LONGINT)(4)), ((LONGINT)(4))); - *x = (SET)((((int)b[0] + __ASHL((int)b[1], 8)) + __ASHL((int)b[2], 16)) + __ASHL((int)b[3], 24)); + l = (((int)b[0] + __ASHL((int)b[1], 8)) + __ASHL((int)b[2], 16)) + __ASHL((int)b[3], 24); + *x = (SET)l; } void Files_ReadReal (Files_Rider *R, LONGINT *R__typ, REAL *x) diff --git a/bootstrap/windows-88/OPB.c b/bootstrap/windows-88/OPB.c index 7c386855..248a0348 100644 --- a/bootstrap/windows-88/OPB.c +++ b/bootstrap/windows-88/OPB.c @@ -2238,6 +2238,9 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) if (((x->class == 8 || x->class == 9) || __IN(f, 0x1401)) || x->typ->comp == 3) { OPB_err(126); } + if (x->typ->size < p->typ->size) { + OPB_err(-308); + } t = OPT_NewNode(11); t->subcl = 29; t->left = x; diff --git a/bootstrap/windows-88/OPM.c b/bootstrap/windows-88/OPM.c index 62922f95..092edf6c 100644 --- a/bootstrap/windows-88/OPM.c +++ b/bootstrap/windows-88/OPM.c @@ -542,7 +542,11 @@ void OPM_FPrintSet (LONGINT *fp, SET set) void OPM_FPrintReal (LONGINT *fp, REAL real) { - OPM_FPrint(&*fp, __VAL(LONGINT, real)); + INTEGER i; + LONGINT l; + __GET((LONGINT)(uintptr_t)&real, i, INTEGER); + l = i; + OPM_FPrint(&*fp, l); } void OPM_FPrintLReal (LONGINT *fp, LONGREAL lr) diff --git a/bootstrap/windows-88/SYSTEM.h b/bootstrap/windows-88/SYSTEM.h index 2941064e..394407bd 100644 --- a/bootstrap/windows-88/SYSTEM.h +++ b/bootstrap/windows-88/SYSTEM.h @@ -134,8 +134,11 @@ static int __str_cmp(CHAR *x, CHAR *y){ /* SYSTEM ops */ -#define __VAL(t, x) ((t)(x)) -#define __VALP(t, x) ((t)(uintptr_t)(x)) +//#define __VAL(t, x) ((t)(x)) +//#define __VALP(t, x) ((t)(uintptr_t)(x)) +#define __VAL(t, x) (*(t*)&(x)) +#define __VALP(t, x) (*(t*)&(x)) + #define __GET(a, x, t) x= *(t*)(uintptr_t)(a) #define __PUT(a, x, t) *(t*)(uintptr_t)(a)=x diff --git a/makefile b/makefile index ec72799f..6b99d495 100644 --- a/makefile +++ b/makefile @@ -178,6 +178,27 @@ browsercmd: configuration library: configuration @make -f src/tools/make/vishap.make -s library +# Individual library components +v4: configuration + @make -f src/tools/make/vishap.make -s v4 + +ooc2: configuration + @make -f src/tools/make/vishap.make -s ooc2 + +ooc: configuration + @make -f src/tools/make/vishap.make -s ooc + +ulm: configuration + @make -f src/tools/make/vishap.make -s ulm + +pow32: configuration + @make -f src/tools/make/vishap.make -s pow32 + +misc: configuration + @make -f src/tools/make/vishap.make -s misc + +s3: configuration + @make -f src/tools/make/vishap.make -s s3 diff --git a/src/compiler/OPB.Mod b/src/compiler/OPB.Mod index 3f2bf697..8c6c581f 100644 --- a/src/compiler/OPB.Mod +++ b/src/compiler/OPB.Mod @@ -1307,7 +1307,7 @@ MODULE OPB; (* RC 6.3.89 / 21.2.94 *) (* object model 17.1.93 *) err(126) END; (* Warn if the result type includes memory past the end of the source variable *) - (* IF x.typ.size < p.typ.size THEN err(-100) END; *) + IF x.typ.size < p.typ.size THEN err(-308) END; t := OPT.NewNode(OPM.Nmop); t^.subcl := OPM.val; t^.left := x; x := t; (* IF (x^.class >= OPM.Nconst) OR ((f IN OPM.realSet) # (p^.typ^.form IN OPM.realSet)) THEN diff --git a/src/compiler/OPM.cmdln.Mod b/src/compiler/OPM.cmdln.Mod index e7b0d015..8b029811 100644 --- a/src/compiler/OPM.cmdln.Mod +++ b/src/compiler/OPM.cmdln.Mod @@ -582,15 +582,26 @@ MODULE OPM; (* RC 6.3.89 / 28.6.89, J.Templ 10.7.89 / 22.7.96 *) PROCEDURE FPrintReal*(VAR fp: LONGINT; real: REAL); - BEGIN FPrint(fp, SYSTEM.VAL(LONGINT, real)) + VAR i: INTEGER; l: LONGINT; + BEGIN + IF SIZE(REAL) = SIZE(INTEGER) THEN + SYSTEM.GET(SYSTEM.ADR(real), i); l := i; + ELSE + SYSTEM.GET(SYSTEM.ADR(real), l); + END; + FPrint(fp, l) END FPrintReal; PROCEDURE FPrintLReal*(VAR fp: LONGINT; lr: LONGREAL); VAR l, h: LONGINT; BEGIN - SYSTEM.GET(SYSTEM.ADR(lr), l); SYSTEM.GET(SYSTEM.ADR(lr)+4, h); - FPrint(fp, l); FPrint(fp, h) + IF SIZE(REAL) = SIZE(INTEGER) THEN + SYSTEM.GET(SYSTEM.ADR(lr), l); SYSTEM.GET(SYSTEM.ADR(lr)+4, h); + FPrint(fp, l); FPrint(fp, h) + ELSE + FPrint(fp, SYSTEM.VAL(LONGINT, lr)) + END END FPrintLReal; diff --git a/src/compiler/OPV.Mod b/src/compiler/OPV.Mod index 74c00268..822448e5 100644 --- a/src/compiler/OPV.Mod +++ b/src/compiler/OPV.Mod @@ -576,14 +576,7 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96 END; expr(l, exprPrec) ELSE - (* OPM.WriteString("__VAL("); - *) - IF (n^.typ^.form IN {OPM.Pointer, OPM.ProcTyp}) OR (l^.typ^.form IN {OPM.Pointer, OPM.ProcTyp}) THEN - OPM.WriteString("__VALP("); - ELSE - OPM.WriteString("__VAL("); - END; OPC.Ident(n^.typ^.strobj); OPM.WriteString(Comma); expr(l, MinPrec); OPM.Write(CloseParen) END diff --git a/src/library/ooc/oocLowReal.Mod b/src/library/ooc/oocLowReal.Mod index 33859dcc..dbfb6ebe 100644 --- a/src/library/ooc/oocLowReal.Mod +++ b/src/library/ooc/oocLowReal.Mod @@ -2,20 +2,20 @@ MODULE oocLowReal; (* - LowReal - Gives access to the underlying properties of the type REAL - for IEEE single-precision numbers. + LowReal - Gives access to the underlying properties of the type REAL + for IEEE single-precision numbers. Copyright (C) 1995 Michael Griebling - + This module is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as + it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This module is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA @@ -24,9 +24,9 @@ MODULE oocLowReal; IMPORT S := SYSTEM, Console; - + (* - + Real number properties are defined as follows: radix--The whole number value of the radix used to represent the @@ -44,69 +44,69 @@ IMPORT S := SYSTEM, Console; small--The smallest positive value of the corresponding real number type, represented to maximal precision. - IEC559--A Boolean value that is TRUE if and only if the implementation - of the corresponding real number type conforms to IEC 559:1989 + IEC559--A Boolean value that is TRUE if and only if the implementation + of the corresponding real number type conforms to IEC 559:1989 (IEEE 754:1987) in all regards. NOTES 6 -- If `IEC559' is TRUE, the value of `radix' is 2. - 7 -- If LowReal.IEC559 is TRUE, the 32-bit format of IEC 559:1989 + 7 -- If LowReal.IEC559 is TRUE, the 32-bit format of IEC 559:1989 is used for the type REAL. - 7 -- If LowLong.IEC559 is TRUE, the 64-bit format of IEC 559:1989 + 7 -- If LowLong.IEC559 is TRUE, the 64-bit format of IEC 559:1989 is used for the type REAL. - LIA1--A Boolean value that is TRUE if and only if the implementation of - the corresponding real number type conforms to ISO/IEC 10967-1:199x - (LIA-1) in all regards: parameters, arithmetic, exceptions, and + LIA1--A Boolean value that is TRUE if and only if the implementation of + the corresponding real number type conforms to ISO/IEC 10967-1:199x + (LIA-1) in all regards: parameters, arithmetic, exceptions, and notification. - rounds--A Boolean value that is TRUE if and only if each operation produces - a result that is one of the values of the corresponding real number + rounds--A Boolean value that is TRUE if and only if each operation produces + a result that is one of the values of the corresponding real number type nearest to the mathematical result. - gUnderflow--A Boolean value that is TRUE if and only if there are values of - the corresponding real number type between 0.0 and `small'. + gUnderflow--A Boolean value that is TRUE if and only if there are values of + the corresponding real number type between 0.0 and `small'. - exception--A Boolean value that is TRUE if and only if every operation that + exception--A Boolean value that is TRUE if and only if every operation that attempts to produce a real value out of range raises an exception. - extend--A Boolean value that is TRUE if and only if expressions of the - corresponding real number type are computed to higher precision than + extend--A Boolean value that is TRUE if and only if expressions of the + corresponding real number type are computed to higher precision than the stored values. - nModes--The whole number value giving the number of bit positions needed for + nModes--The whole number value giving the number of bit positions needed for the status flags for mode control. - + *) -CONST - radix*= 2; +CONST + radix*= 2; places*= 24; - expoMax*= 127; + expoMax*= 127; expoMin*= 1-expoMax; large*= MAX(REAL);(*3.40282347E+38;*) (* MAX(REAL) *) (*small*= 1.17549435E-38; (* 2^(-126) *)*) small* = 1/8.50705917E37; (* don't know better way; -- noch *) IEC559*= TRUE; LIA1*= FALSE; - rounds*= FALSE; + rounds*= FALSE; gUnderflow*= TRUE; (* there are IEEE numbers smaller than `small' *) exception*= FALSE; (* at least in the default implementation *) extend*= FALSE; nModes*= 0; - + TEN=10.0; (* some commonly-used constants *) - ONE=1.0; + ONE=1.0; ZERO=0.0; - - expOffset=expoMax; - hiBit=22; + + expOffset=expoMax; + hiBit=22; expBit=hiBit+1; nMask={0..hiBit,31}; (* number mask *) expMask={expBit..30}; (* exponent mask *) - + TYPE Modes*= SET; - + VAR (*small* : REAL; tmp: REAL;*) (* this was a test to get small as a variable at runtime. obviously, compile time preferred; -- noch *) ErrorHandler*: PROCEDURE (errno : INTEGER); @@ -132,15 +132,18 @@ p := p * i; PROCEDURE DefaultHandler (errno : INTEGER); BEGIN err:=errno -END DefaultHandler; +END DefaultHandler; PROCEDURE ClearError*; BEGIN err:=0 -END ClearError; - +END ClearError; + + + +(*** Refactor for 64 bit support. PROCEDURE exponent*(x: REAL): INTEGER; -(* +(* The value of the call exponent(x) shall be the exponent value of `x' that lies between `expoMin' and `expoMax'. An exception shall occur and may be raised if `x' is equal to 0.0. @@ -148,14 +151,15 @@ PROCEDURE exponent*(x: REAL): INTEGER; BEGIN (* NOTE: x=0.0 should raise exception *) IF x=ZERO THEN RETURN 0 - ELSE RETURN SHORT(S.LSH(S.VAL(LONGINT,x),-expBit) MOD 256)-expOffset + ELSE RETURN SHORT(S.LSH(S.VAL(LONGINT,x),-expBit) MOD 256)-expOffset END END exponent; +*) PROCEDURE exponent10*(x: REAL): INTEGER; -(* - The value of the call exponent10(x) shall be the base 10 exponent - value of `x'. An exception shall occur and may be raised if `x' is +(* + The value of the call exponent10(x) shall be the base 10 exponent + value of `x'. An exception shall occur and may be raised if `x' is equal to 0.0. *) VAR exp: INTEGER; @@ -163,19 +167,20 @@ BEGIN exp:=0; x:=ABS(x); IF x=ZERO THEN RETURN exp END; (* exception could be raised here *) WHILE x>=TEN DO x:=x/TEN; INC(exp) END; - WHILE (x>ZERO) & (x<1.0) DO x:=x*TEN; DEC(exp) END; + WHILE (x>ZERO) & (x<1.0) DO x:=x*TEN; DEC(exp) END; RETURN exp END exponent10; - + +(*** Refactor for 64 bit support. PROCEDURE fraction*(x: REAL): REAL; (* The value of the call fraction(x) shall be the significand (or significant) part of `x'. Hence the following relationship shall - hold: x = scale(fraction(x), exponent(x)). + hold: x = scale(fraction(x), exponent(x)). *) - CONST eZero={(hiBit+2)..29}; + CONST eZero={(hiBit+2)..29}; BEGIN - IF x=ZERO THEN RETURN ZERO + IF x=ZERO THEN RETURN ZERO ELSE RETURN S.VAL(REAL,(S.VAL(SET,x)*nMask)+eZero)*2.0 (* set the mantissa's exponent to zero *) END END fraction; @@ -192,18 +197,20 @@ PROCEDURE IsNaN * (real: REAL) : BOOLEAN; BEGIN sreal:=S.VAL(SET, real); RETURN (sreal*expMask=expMask) & (sreal*fracMask#{}) -END IsNaN; +END IsNaN; +*) PROCEDURE sign*(x: REAL): REAL; (* The value of the call sign(x) shall be 1.0 if `x' is greater than 0.0, or shall be -1.0 if `x' is less than 0.0, or shall be either 1.0 or - -1.0 if `x' is equal to 0.0. + -1.0 if `x' is equal to 0.0. *) BEGIN IF x