From 02803ae1fbf91b493858fec3d1e8563e77b5d1de Mon Sep 17 00:00:00 2001 From: David Brown Date: Sun, 21 Aug 2016 14:59:11 +0100 Subject: [PATCH] typ.size aware OPV.Convert --- bootstrap/unix-44/OPB.c | 2 +- bootstrap/unix-44/OPM.c | 4 +-- bootstrap/unix-44/OPV.c | 47 +++++++++----------------------- bootstrap/unix-44/Reals.c | 6 ++-- bootstrap/unix-48/OPB.c | 2 +- bootstrap/unix-48/OPM.c | 4 +-- bootstrap/unix-48/OPV.c | 47 +++++++++----------------------- bootstrap/unix-48/Reals.c | 6 ++-- bootstrap/unix-88/OPV.c | 47 +++++++++----------------------- bootstrap/windows-48/OPB.c | 2 +- bootstrap/windows-48/OPM.c | 4 +-- bootstrap/windows-48/OPV.c | 47 +++++++++----------------------- bootstrap/windows-48/Reals.c | 6 ++-- bootstrap/windows-88/OPV.c | 47 +++++++++----------------------- makefile | 4 +++ src/compiler/OPV.Mod | 53 ++++++------------------------------ 16 files changed, 96 insertions(+), 232 deletions(-) diff --git a/bootstrap/unix-44/OPB.c b/bootstrap/unix-44/OPB.c index ba3277ca..f0b6edaf 100644 --- a/bootstrap/unix-44/OPB.c +++ b/bootstrap/unix-44/OPB.c @@ -1201,7 +1201,7 @@ static void OPB_Convert (OPT_Node *x, OPT_Struct typ) OPB_err(203); r = (LONGREAL)1; } - (*x)->conval->intval = __ENTIER(r); + (*x)->conval->intval = (LONGINT)__ENTIER(r); OPB_SetIntType(*x); } } diff --git a/bootstrap/unix-44/OPM.c b/bootstrap/unix-44/OPM.c index 6804e6b8..d0279983 100644 --- a/bootstrap/unix-44/OPM.c +++ b/bootstrap/unix-44/OPM.c @@ -872,13 +872,13 @@ void OPM_WriteReal (LONGREAL r, CHAR suffx) CHAR s[32]; CHAR ch; INTEGER i; - if ((((r < OPM_SignedMaximum(OPM_LIntSize) && r > OPM_SignedMinimum(OPM_LIntSize))) && r == (__ENTIER(r)))) { + if ((((r < OPM_SignedMaximum(OPM_LIntSize) && r > OPM_SignedMinimum(OPM_LIntSize))) && r == ((LONGINT)__ENTIER(r)))) { if (suffx == 'f') { OPM_WriteString((CHAR*)"(REAL)", (LONGINT)7); } else { OPM_WriteString((CHAR*)"(LONGREAL)", (LONGINT)11); } - OPM_WriteInt(__ENTIER(r)); + OPM_WriteInt((LONGINT)__ENTIER(r)); } else { Texts_OpenWriter(&W, Texts_Writer__typ); if (suffx == 'f') { diff --git a/bootstrap/unix-44/OPV.c b/bootstrap/unix-44/OPV.c index be86a231..c501a62b 100644 --- a/bootstrap/unix-44/OPV.c +++ b/bootstrap/unix-44/OPV.c @@ -23,7 +23,7 @@ export LONGINT *OPV_ExitInfo__typ; static void OPV_ActualPar (OPT_Node n, OPT_Object fp); export void OPV_AdrAndSize (OPT_Object topScope); static void OPV_CaseStat (OPT_Node n, OPT_Object outerProc); -static void OPV_Convert (OPT_Node n, OPT_Struct typ, INTEGER prec); +static void OPV_Convert (OPT_Node n, OPT_Struct newtype, INTEGER prec); static void OPV_DefineTDescs (OPT_Node n); static void OPV_Entier (OPT_Node n, INTEGER prec); static void OPV_GetTProcNum (OPT_Object obj); @@ -469,50 +469,27 @@ static void OPV_Entier (OPT_Node n, INTEGER prec) static void OPV_SizeCast (LONGINT size) { if (size <= (LONGINT)OPM_SIntSize) { - OPM_WriteString((CHAR*)"(SHORTINT)", (LONGINT)11); + OPM_WriteString((CHAR*)"(int)", (LONGINT)6); } else if (size <= (LONGINT)OPM_IntSize) { - OPM_WriteString((CHAR*)"(INTEGER)", (LONGINT)10); + OPM_WriteString((CHAR*)"(int)", (LONGINT)6); } else { OPM_WriteString((CHAR*)"(LONGINT)", (LONGINT)10); } } -static void OPV_Convert (OPT_Node n, OPT_Struct typ, INTEGER prec) +static void OPV_Convert (OPT_Node n, OPT_Struct newtype, INTEGER prec) { INTEGER from, to; from = n->typ->form; - to = typ->form; + to = newtype->form; if (to == 9) { OPM_WriteString((CHAR*)"__SETOF(", (LONGINT)9); OPV_Entier(n, -1); OPM_Write(')'); - } else if (to == 6) { - if (from < 6) { - OPM_WriteString((CHAR*)"(LONGINT)", (LONGINT)10); - } - OPV_Entier(n, 9); - } else if (to == 5) { - if (from < 5) { - OPM_WriteString((CHAR*)"(int)", (LONGINT)6); - OPV_expr(n, 9); - } else { - if (__IN(2, OPM_opt)) { - OPM_WriteString((CHAR*)"__SHORT", (LONGINT)8); - if (OPV_SideEffects(n)) { - OPM_Write('F'); - } - OPM_Write('('); - OPV_Entier(n, -1); - OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPM_SignedMaximum(OPM_IntSize) + 1); - OPM_Write(')'); - } else { - OPM_WriteString((CHAR*)"(int)", (LONGINT)6); - OPV_Entier(n, 9); - } - } - } else if (to == 4) { - if (__IN(2, OPM_opt)) { + } else if (__IN(to, 0x70)) { + __ASSERT(newtype->size > 0, 0); + __ASSERT(n->typ->size > 0, 0); + if ((newtype->size < n->typ->size && __IN(2, OPM_opt))) { OPM_WriteString((CHAR*)"__SHORT", (LONGINT)8); if (OPV_SideEffects(n)) { OPM_Write('F'); @@ -520,10 +497,12 @@ static void OPV_Convert (OPT_Node n, OPT_Struct typ, INTEGER prec) OPM_Write('('); OPV_Entier(n, -1); OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPM_SignedMaximum(OPM_SIntSize) + 1); + OPM_WriteInt(OPM_SignedMaximum(newtype->size) + 1); OPM_Write(')'); } else { - OPM_WriteString((CHAR*)"(int)", (LONGINT)6); + if (newtype->size != n->typ->size) { + OPV_SizeCast(newtype->size); + } OPV_Entier(n, 9); } } else if (to == 3) { diff --git a/bootstrap/unix-44/Reals.c b/bootstrap/unix-44/Reals.c index 32d73c00..11ec8db0 100644 --- a/bootstrap/unix-44/Reals.c +++ b/bootstrap/unix-44/Reals.c @@ -89,8 +89,8 @@ void Reals_ConvertL (LONGREAL x, INTEGER n, CHAR *d, LONGINT d__len) } k = 0; if (n > 9) { - i = __ENTIER(x / (LONGREAL)(LONGREAL)1000000000); - j = __ENTIER(x - i * (LONGREAL)1000000000); + i = (LONGINT)__ENTIER(x / (LONGREAL)(LONGREAL)1000000000); + j = (LONGINT)__ENTIER(x - i * (LONGREAL)1000000000); if (j < 0) { j = 0; } @@ -100,7 +100,7 @@ void Reals_ConvertL (LONGREAL x, INTEGER n, CHAR *d, LONGINT d__len) k += 1; } } else { - i = __ENTIER(x); + i = (LONGINT)__ENTIER(x); } while (k < (LONGINT)n) { d[__X(k, d__len)] = (CHAR)(__MOD(i, 10) + 48); diff --git a/bootstrap/unix-48/OPB.c b/bootstrap/unix-48/OPB.c index ba3277ca..f0b6edaf 100644 --- a/bootstrap/unix-48/OPB.c +++ b/bootstrap/unix-48/OPB.c @@ -1201,7 +1201,7 @@ static void OPB_Convert (OPT_Node *x, OPT_Struct typ) OPB_err(203); r = (LONGREAL)1; } - (*x)->conval->intval = __ENTIER(r); + (*x)->conval->intval = (LONGINT)__ENTIER(r); OPB_SetIntType(*x); } } diff --git a/bootstrap/unix-48/OPM.c b/bootstrap/unix-48/OPM.c index 6804e6b8..d0279983 100644 --- a/bootstrap/unix-48/OPM.c +++ b/bootstrap/unix-48/OPM.c @@ -872,13 +872,13 @@ void OPM_WriteReal (LONGREAL r, CHAR suffx) CHAR s[32]; CHAR ch; INTEGER i; - if ((((r < OPM_SignedMaximum(OPM_LIntSize) && r > OPM_SignedMinimum(OPM_LIntSize))) && r == (__ENTIER(r)))) { + if ((((r < OPM_SignedMaximum(OPM_LIntSize) && r > OPM_SignedMinimum(OPM_LIntSize))) && r == ((LONGINT)__ENTIER(r)))) { if (suffx == 'f') { OPM_WriteString((CHAR*)"(REAL)", (LONGINT)7); } else { OPM_WriteString((CHAR*)"(LONGREAL)", (LONGINT)11); } - OPM_WriteInt(__ENTIER(r)); + OPM_WriteInt((LONGINT)__ENTIER(r)); } else { Texts_OpenWriter(&W, Texts_Writer__typ); if (suffx == 'f') { diff --git a/bootstrap/unix-48/OPV.c b/bootstrap/unix-48/OPV.c index be86a231..c501a62b 100644 --- a/bootstrap/unix-48/OPV.c +++ b/bootstrap/unix-48/OPV.c @@ -23,7 +23,7 @@ export LONGINT *OPV_ExitInfo__typ; static void OPV_ActualPar (OPT_Node n, OPT_Object fp); export void OPV_AdrAndSize (OPT_Object topScope); static void OPV_CaseStat (OPT_Node n, OPT_Object outerProc); -static void OPV_Convert (OPT_Node n, OPT_Struct typ, INTEGER prec); +static void OPV_Convert (OPT_Node n, OPT_Struct newtype, INTEGER prec); static void OPV_DefineTDescs (OPT_Node n); static void OPV_Entier (OPT_Node n, INTEGER prec); static void OPV_GetTProcNum (OPT_Object obj); @@ -469,50 +469,27 @@ static void OPV_Entier (OPT_Node n, INTEGER prec) static void OPV_SizeCast (LONGINT size) { if (size <= (LONGINT)OPM_SIntSize) { - OPM_WriteString((CHAR*)"(SHORTINT)", (LONGINT)11); + OPM_WriteString((CHAR*)"(int)", (LONGINT)6); } else if (size <= (LONGINT)OPM_IntSize) { - OPM_WriteString((CHAR*)"(INTEGER)", (LONGINT)10); + OPM_WriteString((CHAR*)"(int)", (LONGINT)6); } else { OPM_WriteString((CHAR*)"(LONGINT)", (LONGINT)10); } } -static void OPV_Convert (OPT_Node n, OPT_Struct typ, INTEGER prec) +static void OPV_Convert (OPT_Node n, OPT_Struct newtype, INTEGER prec) { INTEGER from, to; from = n->typ->form; - to = typ->form; + to = newtype->form; if (to == 9) { OPM_WriteString((CHAR*)"__SETOF(", (LONGINT)9); OPV_Entier(n, -1); OPM_Write(')'); - } else if (to == 6) { - if (from < 6) { - OPM_WriteString((CHAR*)"(LONGINT)", (LONGINT)10); - } - OPV_Entier(n, 9); - } else if (to == 5) { - if (from < 5) { - OPM_WriteString((CHAR*)"(int)", (LONGINT)6); - OPV_expr(n, 9); - } else { - if (__IN(2, OPM_opt)) { - OPM_WriteString((CHAR*)"__SHORT", (LONGINT)8); - if (OPV_SideEffects(n)) { - OPM_Write('F'); - } - OPM_Write('('); - OPV_Entier(n, -1); - OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPM_SignedMaximum(OPM_IntSize) + 1); - OPM_Write(')'); - } else { - OPM_WriteString((CHAR*)"(int)", (LONGINT)6); - OPV_Entier(n, 9); - } - } - } else if (to == 4) { - if (__IN(2, OPM_opt)) { + } else if (__IN(to, 0x70)) { + __ASSERT(newtype->size > 0, 0); + __ASSERT(n->typ->size > 0, 0); + if ((newtype->size < n->typ->size && __IN(2, OPM_opt))) { OPM_WriteString((CHAR*)"__SHORT", (LONGINT)8); if (OPV_SideEffects(n)) { OPM_Write('F'); @@ -520,10 +497,12 @@ static void OPV_Convert (OPT_Node n, OPT_Struct typ, INTEGER prec) OPM_Write('('); OPV_Entier(n, -1); OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPM_SignedMaximum(OPM_SIntSize) + 1); + OPM_WriteInt(OPM_SignedMaximum(newtype->size) + 1); OPM_Write(')'); } else { - OPM_WriteString((CHAR*)"(int)", (LONGINT)6); + if (newtype->size != n->typ->size) { + OPV_SizeCast(newtype->size); + } OPV_Entier(n, 9); } } else if (to == 3) { diff --git a/bootstrap/unix-48/Reals.c b/bootstrap/unix-48/Reals.c index 32d73c00..11ec8db0 100644 --- a/bootstrap/unix-48/Reals.c +++ b/bootstrap/unix-48/Reals.c @@ -89,8 +89,8 @@ void Reals_ConvertL (LONGREAL x, INTEGER n, CHAR *d, LONGINT d__len) } k = 0; if (n > 9) { - i = __ENTIER(x / (LONGREAL)(LONGREAL)1000000000); - j = __ENTIER(x - i * (LONGREAL)1000000000); + i = (LONGINT)__ENTIER(x / (LONGREAL)(LONGREAL)1000000000); + j = (LONGINT)__ENTIER(x - i * (LONGREAL)1000000000); if (j < 0) { j = 0; } @@ -100,7 +100,7 @@ void Reals_ConvertL (LONGREAL x, INTEGER n, CHAR *d, LONGINT d__len) k += 1; } } else { - i = __ENTIER(x); + i = (LONGINT)__ENTIER(x); } while (k < (LONGINT)n) { d[__X(k, d__len)] = (CHAR)(__MOD(i, 10) + 48); diff --git a/bootstrap/unix-88/OPV.c b/bootstrap/unix-88/OPV.c index 1ea32c76..123d1a61 100644 --- a/bootstrap/unix-88/OPV.c +++ b/bootstrap/unix-88/OPV.c @@ -24,7 +24,7 @@ export LONGINT *OPV_ExitInfo__typ; static void OPV_ActualPar (OPT_Node n, OPT_Object fp); export void OPV_AdrAndSize (OPT_Object topScope); static void OPV_CaseStat (OPT_Node n, OPT_Object outerProc); -static void OPV_Convert (OPT_Node n, OPT_Struct typ, INTEGER prec); +static void OPV_Convert (OPT_Node n, OPT_Struct newtype, INTEGER prec); static void OPV_DefineTDescs (OPT_Node n); static void OPV_Entier (OPT_Node n, INTEGER prec); static void OPV_GetTProcNum (OPT_Object obj); @@ -470,50 +470,27 @@ static void OPV_Entier (OPT_Node n, INTEGER prec) static void OPV_SizeCast (LONGINT size) { if (size <= (LONGINT)OPM_SIntSize) { - OPM_WriteString((CHAR*)"(SHORTINT)", (LONGINT)11); + OPM_WriteString((CHAR*)"(int)", (LONGINT)6); } else if (size <= (LONGINT)OPM_IntSize) { - OPM_WriteString((CHAR*)"(INTEGER)", (LONGINT)10); + OPM_WriteString((CHAR*)"(int)", (LONGINT)6); } else { OPM_WriteString((CHAR*)"(LONGINT)", (LONGINT)10); } } -static void OPV_Convert (OPT_Node n, OPT_Struct typ, INTEGER prec) +static void OPV_Convert (OPT_Node n, OPT_Struct newtype, INTEGER prec) { INTEGER from, to; from = n->typ->form; - to = typ->form; + to = newtype->form; if (to == 9) { OPM_WriteString((CHAR*)"__SETOF(", (LONGINT)9); OPV_Entier(n, -1); OPM_Write(')'); - } else if (to == 6) { - if (from < 6) { - OPM_WriteString((CHAR*)"(LONGINT)", (LONGINT)10); - } - OPV_Entier(n, 9); - } else if (to == 5) { - if (from < 5) { - OPM_WriteString((CHAR*)"(int)", (LONGINT)6); - OPV_expr(n, 9); - } else { - if (__IN(2, OPM_opt)) { - OPM_WriteString((CHAR*)"__SHORT", (LONGINT)8); - if (OPV_SideEffects(n)) { - OPM_Write('F'); - } - OPM_Write('('); - OPV_Entier(n, -1); - OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPM_SignedMaximum(OPM_IntSize) + 1); - OPM_Write(')'); - } else { - OPM_WriteString((CHAR*)"(int)", (LONGINT)6); - OPV_Entier(n, 9); - } - } - } else if (to == 4) { - if (__IN(2, OPM_opt)) { + } else if (__IN(to, 0x70)) { + __ASSERT(newtype->size > 0, 0); + __ASSERT(n->typ->size > 0, 0); + if ((newtype->size < n->typ->size && __IN(2, OPM_opt))) { OPM_WriteString((CHAR*)"__SHORT", (LONGINT)8); if (OPV_SideEffects(n)) { OPM_Write('F'); @@ -521,10 +498,12 @@ static void OPV_Convert (OPT_Node n, OPT_Struct typ, INTEGER prec) OPM_Write('('); OPV_Entier(n, -1); OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPM_SignedMaximum(OPM_SIntSize) + 1); + OPM_WriteInt(OPM_SignedMaximum(newtype->size) + 1); OPM_Write(')'); } else { - OPM_WriteString((CHAR*)"(int)", (LONGINT)6); + if (newtype->size != n->typ->size) { + OPV_SizeCast(newtype->size); + } OPV_Entier(n, 9); } } else if (to == 3) { diff --git a/bootstrap/windows-48/OPB.c b/bootstrap/windows-48/OPB.c index ba3277ca..f0b6edaf 100644 --- a/bootstrap/windows-48/OPB.c +++ b/bootstrap/windows-48/OPB.c @@ -1201,7 +1201,7 @@ static void OPB_Convert (OPT_Node *x, OPT_Struct typ) OPB_err(203); r = (LONGREAL)1; } - (*x)->conval->intval = __ENTIER(r); + (*x)->conval->intval = (LONGINT)__ENTIER(r); OPB_SetIntType(*x); } } diff --git a/bootstrap/windows-48/OPM.c b/bootstrap/windows-48/OPM.c index 6804e6b8..d0279983 100644 --- a/bootstrap/windows-48/OPM.c +++ b/bootstrap/windows-48/OPM.c @@ -872,13 +872,13 @@ void OPM_WriteReal (LONGREAL r, CHAR suffx) CHAR s[32]; CHAR ch; INTEGER i; - if ((((r < OPM_SignedMaximum(OPM_LIntSize) && r > OPM_SignedMinimum(OPM_LIntSize))) && r == (__ENTIER(r)))) { + if ((((r < OPM_SignedMaximum(OPM_LIntSize) && r > OPM_SignedMinimum(OPM_LIntSize))) && r == ((LONGINT)__ENTIER(r)))) { if (suffx == 'f') { OPM_WriteString((CHAR*)"(REAL)", (LONGINT)7); } else { OPM_WriteString((CHAR*)"(LONGREAL)", (LONGINT)11); } - OPM_WriteInt(__ENTIER(r)); + OPM_WriteInt((LONGINT)__ENTIER(r)); } else { Texts_OpenWriter(&W, Texts_Writer__typ); if (suffx == 'f') { diff --git a/bootstrap/windows-48/OPV.c b/bootstrap/windows-48/OPV.c index be86a231..c501a62b 100644 --- a/bootstrap/windows-48/OPV.c +++ b/bootstrap/windows-48/OPV.c @@ -23,7 +23,7 @@ export LONGINT *OPV_ExitInfo__typ; static void OPV_ActualPar (OPT_Node n, OPT_Object fp); export void OPV_AdrAndSize (OPT_Object topScope); static void OPV_CaseStat (OPT_Node n, OPT_Object outerProc); -static void OPV_Convert (OPT_Node n, OPT_Struct typ, INTEGER prec); +static void OPV_Convert (OPT_Node n, OPT_Struct newtype, INTEGER prec); static void OPV_DefineTDescs (OPT_Node n); static void OPV_Entier (OPT_Node n, INTEGER prec); static void OPV_GetTProcNum (OPT_Object obj); @@ -469,50 +469,27 @@ static void OPV_Entier (OPT_Node n, INTEGER prec) static void OPV_SizeCast (LONGINT size) { if (size <= (LONGINT)OPM_SIntSize) { - OPM_WriteString((CHAR*)"(SHORTINT)", (LONGINT)11); + OPM_WriteString((CHAR*)"(int)", (LONGINT)6); } else if (size <= (LONGINT)OPM_IntSize) { - OPM_WriteString((CHAR*)"(INTEGER)", (LONGINT)10); + OPM_WriteString((CHAR*)"(int)", (LONGINT)6); } else { OPM_WriteString((CHAR*)"(LONGINT)", (LONGINT)10); } } -static void OPV_Convert (OPT_Node n, OPT_Struct typ, INTEGER prec) +static void OPV_Convert (OPT_Node n, OPT_Struct newtype, INTEGER prec) { INTEGER from, to; from = n->typ->form; - to = typ->form; + to = newtype->form; if (to == 9) { OPM_WriteString((CHAR*)"__SETOF(", (LONGINT)9); OPV_Entier(n, -1); OPM_Write(')'); - } else if (to == 6) { - if (from < 6) { - OPM_WriteString((CHAR*)"(LONGINT)", (LONGINT)10); - } - OPV_Entier(n, 9); - } else if (to == 5) { - if (from < 5) { - OPM_WriteString((CHAR*)"(int)", (LONGINT)6); - OPV_expr(n, 9); - } else { - if (__IN(2, OPM_opt)) { - OPM_WriteString((CHAR*)"__SHORT", (LONGINT)8); - if (OPV_SideEffects(n)) { - OPM_Write('F'); - } - OPM_Write('('); - OPV_Entier(n, -1); - OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPM_SignedMaximum(OPM_IntSize) + 1); - OPM_Write(')'); - } else { - OPM_WriteString((CHAR*)"(int)", (LONGINT)6); - OPV_Entier(n, 9); - } - } - } else if (to == 4) { - if (__IN(2, OPM_opt)) { + } else if (__IN(to, 0x70)) { + __ASSERT(newtype->size > 0, 0); + __ASSERT(n->typ->size > 0, 0); + if ((newtype->size < n->typ->size && __IN(2, OPM_opt))) { OPM_WriteString((CHAR*)"__SHORT", (LONGINT)8); if (OPV_SideEffects(n)) { OPM_Write('F'); @@ -520,10 +497,12 @@ static void OPV_Convert (OPT_Node n, OPT_Struct typ, INTEGER prec) OPM_Write('('); OPV_Entier(n, -1); OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPM_SignedMaximum(OPM_SIntSize) + 1); + OPM_WriteInt(OPM_SignedMaximum(newtype->size) + 1); OPM_Write(')'); } else { - OPM_WriteString((CHAR*)"(int)", (LONGINT)6); + if (newtype->size != n->typ->size) { + OPV_SizeCast(newtype->size); + } OPV_Entier(n, 9); } } else if (to == 3) { diff --git a/bootstrap/windows-48/Reals.c b/bootstrap/windows-48/Reals.c index 32d73c00..11ec8db0 100644 --- a/bootstrap/windows-48/Reals.c +++ b/bootstrap/windows-48/Reals.c @@ -89,8 +89,8 @@ void Reals_ConvertL (LONGREAL x, INTEGER n, CHAR *d, LONGINT d__len) } k = 0; if (n > 9) { - i = __ENTIER(x / (LONGREAL)(LONGREAL)1000000000); - j = __ENTIER(x - i * (LONGREAL)1000000000); + i = (LONGINT)__ENTIER(x / (LONGREAL)(LONGREAL)1000000000); + j = (LONGINT)__ENTIER(x - i * (LONGREAL)1000000000); if (j < 0) { j = 0; } @@ -100,7 +100,7 @@ void Reals_ConvertL (LONGREAL x, INTEGER n, CHAR *d, LONGINT d__len) k += 1; } } else { - i = __ENTIER(x); + i = (LONGINT)__ENTIER(x); } while (k < (LONGINT)n) { d[__X(k, d__len)] = (CHAR)(__MOD(i, 10) + 48); diff --git a/bootstrap/windows-88/OPV.c b/bootstrap/windows-88/OPV.c index 1ea32c76..123d1a61 100644 --- a/bootstrap/windows-88/OPV.c +++ b/bootstrap/windows-88/OPV.c @@ -24,7 +24,7 @@ export LONGINT *OPV_ExitInfo__typ; static void OPV_ActualPar (OPT_Node n, OPT_Object fp); export void OPV_AdrAndSize (OPT_Object topScope); static void OPV_CaseStat (OPT_Node n, OPT_Object outerProc); -static void OPV_Convert (OPT_Node n, OPT_Struct typ, INTEGER prec); +static void OPV_Convert (OPT_Node n, OPT_Struct newtype, INTEGER prec); static void OPV_DefineTDescs (OPT_Node n); static void OPV_Entier (OPT_Node n, INTEGER prec); static void OPV_GetTProcNum (OPT_Object obj); @@ -470,50 +470,27 @@ static void OPV_Entier (OPT_Node n, INTEGER prec) static void OPV_SizeCast (LONGINT size) { if (size <= (LONGINT)OPM_SIntSize) { - OPM_WriteString((CHAR*)"(SHORTINT)", (LONGINT)11); + OPM_WriteString((CHAR*)"(int)", (LONGINT)6); } else if (size <= (LONGINT)OPM_IntSize) { - OPM_WriteString((CHAR*)"(INTEGER)", (LONGINT)10); + OPM_WriteString((CHAR*)"(int)", (LONGINT)6); } else { OPM_WriteString((CHAR*)"(LONGINT)", (LONGINT)10); } } -static void OPV_Convert (OPT_Node n, OPT_Struct typ, INTEGER prec) +static void OPV_Convert (OPT_Node n, OPT_Struct newtype, INTEGER prec) { INTEGER from, to; from = n->typ->form; - to = typ->form; + to = newtype->form; if (to == 9) { OPM_WriteString((CHAR*)"__SETOF(", (LONGINT)9); OPV_Entier(n, -1); OPM_Write(')'); - } else if (to == 6) { - if (from < 6) { - OPM_WriteString((CHAR*)"(LONGINT)", (LONGINT)10); - } - OPV_Entier(n, 9); - } else if (to == 5) { - if (from < 5) { - OPM_WriteString((CHAR*)"(int)", (LONGINT)6); - OPV_expr(n, 9); - } else { - if (__IN(2, OPM_opt)) { - OPM_WriteString((CHAR*)"__SHORT", (LONGINT)8); - if (OPV_SideEffects(n)) { - OPM_Write('F'); - } - OPM_Write('('); - OPV_Entier(n, -1); - OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPM_SignedMaximum(OPM_IntSize) + 1); - OPM_Write(')'); - } else { - OPM_WriteString((CHAR*)"(int)", (LONGINT)6); - OPV_Entier(n, 9); - } - } - } else if (to == 4) { - if (__IN(2, OPM_opt)) { + } else if (__IN(to, 0x70)) { + __ASSERT(newtype->size > 0, 0); + __ASSERT(n->typ->size > 0, 0); + if ((newtype->size < n->typ->size && __IN(2, OPM_opt))) { OPM_WriteString((CHAR*)"__SHORT", (LONGINT)8); if (OPV_SideEffects(n)) { OPM_Write('F'); @@ -521,10 +498,12 @@ static void OPV_Convert (OPT_Node n, OPT_Struct typ, INTEGER prec) OPM_Write('('); OPV_Entier(n, -1); OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPM_SignedMaximum(OPM_SIntSize) + 1); + OPM_WriteInt(OPM_SignedMaximum(newtype->size) + 1); OPM_Write(')'); } else { - OPM_WriteString((CHAR*)"(int)", (LONGINT)6); + if (newtype->size != n->typ->size) { + OPV_SizeCast(newtype->size); + } OPV_Entier(n, 9); } } else if (to == 3) { diff --git a/makefile b/makefile index 6b99d495..eee8238a 100644 --- a/makefile +++ b/makefile @@ -166,6 +166,10 @@ compiler: configuration +# Report changes to compiler source relative to bootstrap compiler +sourcechanges: + @make -f src/tools/make/vishap.make -s sourcechanges + # browsercmd: build the 'showdef' command browsercmd: configuration diff --git a/src/compiler/OPV.Mod b/src/compiler/OPV.Mod index d468f233..b62793a8 100644 --- a/src/compiler/OPV.Mod +++ b/src/compiler/OPV.Mod @@ -292,60 +292,25 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96 PROCEDURE SizeCast(size: LONGINT); BEGIN - IF size <= OPM.SIntSize THEN OPM.WriteString("(SHORTINT)") - ELSIF size <= OPM.IntSize THEN OPM.WriteString("(INTEGER)") + IF size <= OPM.SIntSize THEN OPM.WriteString("(int)") (* TODO: int for temporary source comparison only. *) + ELSIF size <= OPM.IntSize THEN OPM.WriteString("(int)") (* TODO: int for temporary source comparison only. *) ELSE OPM.WriteString("(LONGINT)") END END SizeCast; - PROCEDURE Convert(n: OPT.Node; typ: OPT.Struct; prec: INTEGER); + PROCEDURE Convert(n: OPT.Node; newtype: OPT.Struct; prec: INTEGER); VAR from, to: INTEGER; - BEGIN from := n^.typ^.form; to := typ.form; + BEGIN from := n^.typ^.form; to := newtype.form; IF to = OPM.Set THEN OPM.WriteString(SetOfFunc); Entier(n, MinPrec); OPM.Write(CloseParen) - - ELSIF to = OPM.LInt THEN - IF from < OPM.LInt THEN OPM.WriteString("(LONGINT)") END ; - Entier(n, 9) - ELSIF to = OPM.Int THEN - IF from < OPM.Int THEN OPM.WriteString("(int)"); expr(n, 9) - ELSE - IF OPM.ranchk IN OPM.opt THEN OPM.WriteString("__SHORT"); - IF SideEffects(n) THEN OPM.Write("F") END ; - OPM.Write(OpenParen); Entier(n, MinPrec); - OPM.WriteString(Comma); OPM.WriteInt(OPM.SignedMaximum(OPM.IntSize) + 1); OPM.Write(CloseParen) - ELSE OPM.WriteString("(int)"); Entier(n, 9) - END - END - ELSIF to = OPM.SInt THEN - IF OPM.ranchk IN OPM.opt THEN OPM.WriteString("__SHORT"); - IF SideEffects(n) THEN OPM.Write("F") END ; - OPM.Write(OpenParen); Entier(n, MinPrec); - OPM.WriteString(Comma); OPM.WriteInt(OPM.SignedMaximum(OPM.SIntSize) + 1); OPM.Write(CloseParen) - ELSE OPM.WriteString("(int)"); Entier(n, 9) - END - - (* ELSIF to IN OPM.intSet THEN - IF from IN OPM.intSet - IF typ.size > n.typ.size (* Result is larger *) - SizeCast(typ.size); Entier(n, 9) - ELSIF typ.size = n.typ.size THEN - Entier(n, 9) - ELSE (* Result is smaller *) - IF OPM.ranchk IN OPM.opt THEN - OPM.WriteString("__SHORT"); IF SideEffects(n) THEN OPM.Write("F") END; - OPM.Write(OpenParen); Entier(n, MinPrec); OPM.WriteString(Comma); - OPM.WriteInt(OPM.SignedMaximum(typ.size) + 1); OPM.Write(CloseParen) - ELSE - SizeCast(typ.size); Entier(n, 9) - END - END + IF (newtype.size < n.typ.size) & (OPM.ranchk IN OPM.opt) THEN + OPM.WriteString("__SHORT"); IF SideEffects(n) THEN OPM.Write("F") END; + OPM.Write(OpenParen); Entier(n, MinPrec); OPM.WriteString(Comma); + OPM.WriteInt(OPM.SignedMaximum(newtype.size) + 1); OPM.Write(CloseParen) ELSE - IF (from < OPM.SInt) & (typ.size > OPM.SIntSize) THEN SizeCast(typ.size) END; + IF newtype.size # n.typ.size THEN SizeCast(newtype.size) END; Entier(n, 9) END - *) - ELSIF to = OPM.Char THEN IF OPM.ranchk IN OPM.opt THEN OPM.WriteString("__CHR"); IF SideEffects(n) THEN OPM.Write("F") END ;