]> git.mdlowis.com Git - proto/obnc.git/commitdiff
FLT ORD CHR to AsReal AsInt AsChar
authormike lowis <mike@mdlowis.com>
Sat, 10 Apr 2021 00:31:11 +0000 (20:31 -0400)
committermike lowis <mike@mdlowis.com>
Sat, 10 Apr 2021 00:31:11 +0000 (20:31 -0400)
CONFIG.bak [new file with mode: 0644]
lib/obnc/Strings.obn
lib/obnc/XYplane.obn
src/Oberon.y
src/Table.c
src/y.tab.c
tests/obnc/passing/A.obn
tests/obnc/passing/T1ConstantDeclarations.obn
tests/obnc/passing/T4Expressions.obn
tests/obnc/passing/T7Modules.obn

diff --git a/CONFIG.bak b/CONFIG.bak
new file mode 100644 (file)
index 0000000..b1a6bfc
--- /dev/null
@@ -0,0 +1,5 @@
+prefix=/usr/local
+libdir=lib
+cIntType=int
+cRealType=double
+version=0.16.1
index 9ca30dca26f81c51d43c224f5a7b611a9910ed19..353564ad6e41a324167ace691a95f3e8abba0715 100644 (file)
@@ -155,7 +155,7 @@ Implements the basic library module from "The Oakwood Guidelines for Oberon-2 Co
                i := 0;
                while s[i] # 0X do
                        if (s[i] >= "a") & (s[i] <= "z") then
-                               s[i] := CHR(ORD("A") + ORD(s[i]) - ORD("a"));
+                               s[i] := AsChar(AsInt("A") + AsInt(s[i]) - AsInt("a"));
                        end;
                        INC(i)
                end
index 04fe889ce5d12ad27781ff76dfa3cf3584aeac09..4d67b333d405d3d90c65b38da49215908d8c9b92 100644 (file)
@@ -41,7 +41,7 @@ Implements the basic library module from "The Oakwood Guidelines for Oberon-2 Co
 
        procedure Key*(): Char;
 (**reads the keyboard. If a key was pressed prior to invocation, its character value is returned, otherwise the result is 0X.*)
-       return CHR(0) (*dummy value*)
+       return AsChar(0) (*dummy value*)
        end Key;
 
        procedure SetSize*(width, height: Int);
index dbe1e65d1490e33b177309b777744b7cf04a73b8..cbf803a574d9d452ad4e23ccbf070417f81e536a 100644 (file)
@@ -3589,17 +3589,17 @@ static Trees_Node PredeclaredProcedureAST(const char procName[], Trees_Node expL
 {
        static const struct { const char *name; int symbol; } symbols[] = {
                {"ABS", TREES_ABS_PROC},
+               {"AsChar", TREES_CHR_PROC},
+               {"AsInt", TREES_ORD_PROC},
+               {"AsReal", TREES_FLT_PROC},
                {"Assert", TREES_ASSERT_PROC},
-               {"CHR", TREES_CHR_PROC},
                {"DEC", TREES_DEC_PROC},
                {"EXCL", TREES_EXCL_PROC},
                {"FLOOR", TREES_FLOOR_PROC},
-               {"FLT", TREES_FLT_PROC},
                {"INC", TREES_INC_PROC},
                {"INCL", TREES_INCL_PROC},
                {"Length", TREES_LEN_PROC},
                {"New", TREES_NEW_PROC},
-               {"ORD", TREES_ORD_PROC},
 
                {"ADR", TREES_ADR_PROC},
                {"SIZE", TREES_SIZE_PROC},
index 2e782534aac01bac20738c25ef067fc96bd65aca..a73e408ff86ceb30f2c00064a5bef97107e7b349 100644 (file)
@@ -88,21 +88,21 @@ void Table_Init(void)
 */
        static const struct { const char *name; int kind, type; } predecIdents[] = {
                {"ABS", TREES_PROCEDURE_KIND, TREES_ABS_PROC},       /* Remove */
+               {"AsChar", TREES_PROCEDURE_KIND, TREES_CHR_PROC},
+               {"AsInt", TREES_PROCEDURE_KIND, TREES_ORD_PROC},
+               {"AsReal", TREES_PROCEDURE_KIND, TREES_FLT_PROC},
                {"Assert", TREES_PROCEDURE_KIND, TREES_ASSERT_PROC},
                {"Bool", TREES_TYPE_KIND, TREES_BOOLEAN_TYPE},
                {"Byte", TREES_TYPE_KIND, TREES_BYTE_TYPE},
-               {"CHR", TREES_PROCEDURE_KIND, TREES_CHR_PROC},
                {"Char", TREES_TYPE_KIND, TREES_CHAR_TYPE},
                {"DEC", TREES_PROCEDURE_KIND, TREES_DEC_PROC},       /* Operator */
                {"EXCL", TREES_PROCEDURE_KIND, TREES_EXCL_PROC},
                {"FLOOR", TREES_PROCEDURE_KIND, TREES_FLOOR_PROC},
-               {"FLT", TREES_PROCEDURE_KIND, TREES_FLT_PROC},
                {"INC", TREES_PROCEDURE_KIND, TREES_INC_PROC},       /* Operator */
                {"INCL", TREES_PROCEDURE_KIND, TREES_INCL_PROC},
                {"Int", TREES_TYPE_KIND, TREES_INTEGER_TYPE},
                {"Length", TREES_PROCEDURE_KIND, TREES_LEN_PROC},
                {"New", TREES_PROCEDURE_KIND, TREES_NEW_PROC},
-               {"ORD", TREES_PROCEDURE_KIND, TREES_ORD_PROC},
                {"Real", TREES_TYPE_KIND, TREES_REAL_TYPE},
                {"Set", TREES_TYPE_KIND, TREES_SET_TYPE},
        };
index 167005b5a4ef88d9a30005fbcf7502aaee9ce2c4..8d0a3950a7381eadc3a29cc94ac886ea0084d1a0 100644 (file)
@@ -5567,17 +5567,17 @@ static Trees_Node PredeclaredProcedureAST(const char procName[], Trees_Node expL
 {
        static const struct { const char *name; int symbol; } symbols[] = {
                {"ABS", TREES_ABS_PROC},
+               {"AsChar", TREES_CHR_PROC},
+               {"AsInt", TREES_ORD_PROC},
+               {"AsReal", TREES_FLT_PROC},
                {"Assert", TREES_ASSERT_PROC},
-               {"CHR", TREES_CHR_PROC},
                {"DEC", TREES_DEC_PROC},
                {"EXCL", TREES_EXCL_PROC},
                {"FLOOR", TREES_FLOOR_PROC},
-               {"FLT", TREES_FLT_PROC},
                {"INC", TREES_INC_PROC},
                {"INCL", TREES_INCL_PROC},
                {"Length", TREES_LEN_PROC},
                {"New", TREES_NEW_PROC},
-               {"ORD", TREES_ORD_PROC},
 
                {"ADR", TREES_ADR_PROC},
                {"SIZE", TREES_SIZE_PROC},
index 741c7a8c99c9104369df9a5edd9b28b5c63370f5..1fa28059331404a75c5233c0fb5a9c44494f058e 100644 (file)
@@ -21,7 +21,7 @@ module A;
 
        const
                boolConst* = true;
-               charConst* = CHR(22H);
+               charConst* = AsChar(22H);
                intConst* = 1;
                realConst* = 2.3;
                strConst* = "hello there";
index c0335ae2ad3758698029dc76a84d76e1ea8c57a8..a64a3e99531e450d37ddb23ecf7f0c004d426bad 100644 (file)
@@ -25,7 +25,7 @@ module T1ConstantDeclarations;
                quotes = 22X;
                backslash = "\";
                nonAscii = 80X;
-               letterA = CHR(ORD("A"));
+               letterA = AsChar(AsInt("A"));
                sevenDigits = "1234567";
                count = 37;
                pi = 3.14;
index 3e57b7f6d0d64558d1cf2bbd484b28927634a728..1d6755ae455cf07009a901897823f02a82fe7895 100644 (file)
@@ -73,9 +73,9 @@ module T4Expressions;
        begin
                a := 4;
                b := 6;
-Out.Integer(ORD({1, 2, a, 5, b, 8}), 0); Out.Ln;
-Out.Integer(ORD({1, 2, a..b, 8}), 0); Out.Ln;
-Out.Integer(ORD({1, 2, a, 5, b, 8} = {1, 2, a..b, 8}), 0); Out.Ln;
+Out.Integer(AsInt({1, 2, a, 5, b, 8}), 0); Out.Ln;
+Out.Integer(AsInt({1, 2, a..b, 8}), 0); Out.Ln;
+Out.Integer(AsInt({1, 2, a, 5, b, 8} = {1, 2, a..b, 8}), 0); Out.Ln;
                Assert({1, 2, a, 5, b, 8} = {1, 2, a..b, 8});
                i := 0;
                j := 0;
@@ -380,9 +380,9 @@ Out.Integer(ORD({1, 2, a, 5, b, 8} = {1, 2, a..b, 8}), 0); Out.Ln;
                        (*make sure function procedures with constant parameters are constant expressions*)
                        absConst = ABS(0);
                        floorConst = FLOOR(eps);
-                       fltConst = FLT(0);
-                       ordConst = ORD(true);
-                       chrConst = CHR(0);
+                       fltConst = AsReal(0);
+                       ordConst = AsInt(true);
+                       chrConst = AsChar(0);
 
                var a: array 10 of Char;
                        b: Bool;
@@ -410,45 +410,45 @@ Out.Integer(ORD({1, 2, a, 5, b, 8} = {1, 2, a..b, 8}), 0); Out.Ln;
                Assert(FLOOR(0.0) = 0);
                Assert(FLOOR(1.5) = 1);
                i := 0;
-               j := FLOOR(FLT(IncReturnZero(i)) + 1.5);
+               j := FLOOR(AsReal(IncReturnZero(i)) + 1.5);
                Assert(j = 1);
                Assert(i = 1);
 
-               Assert(FLT(-1) = -1.0);
-               Assert(FLT(0) = 0.0);
-               Assert(FLT(1) = 1.0);
+               Assert(AsReal(-1) = -1.0);
+               Assert(AsReal(0) = 0.0);
+               Assert(AsReal(1) = 1.0);
 
-               Assert(ORD(0X) = 0);
+               Assert(AsInt(0X) = 0);
                ch := 0X;
-               Assert(ORD(ch) = 0);
-               Assert(ORD("A") = 41H);
+               Assert(AsInt(ch) = 0);
+               Assert(AsInt("A") = 41H);
                ch := "A";
-               Assert(ORD(ch) = 41H);
-               Assert(ORD(0FFX) = 0FFH);
+               Assert(AsInt(ch) = 41H);
+               Assert(AsInt(0FFX) = 0FFH);
                ch := 0FFX;
-               Assert(ORD(ch) = 0FFH);
+               Assert(AsInt(ch) = 0FFH);
 
-               Assert(ORD(false) = 0);
+               Assert(AsInt(false) = 0);
                b := false;
-               Assert(ORD(b) = 0);
-               Assert(ORD(true) = 1);
+               Assert(AsInt(b) = 0);
+               Assert(AsInt(true) = 1);
                b := true;
-               Assert(ORD(b) = 1);
+               Assert(AsInt(b) = 1);
 
-               Assert(ORD({}) = 0);
+               Assert(AsInt({}) = 0);
                s := {};
-               Assert(ORD(s) = 0);
-               Assert(ORD({8}) = 256);
+               Assert(AsInt(s) = 0);
+               Assert(AsInt({8}) = 256);
                s := {8};
-               Assert(ORD(s) = 256);
+               Assert(AsInt(s) = 256);
 
-               Assert(CHR(0) = 0X);
-               Assert(CHR(1) = 1X);
-               Assert(CHR(7FH) = 7FX);
+               Assert(AsChar(0) = 0X);
+               Assert(AsChar(1) = 1X);
+               Assert(AsChar(7FH) = 7FX);
                ch := 7FX;
-               Assert(CHR(7FH) = ch);
+               Assert(AsChar(7FH) = ch);
                x := 1;
-               Assert(CHR(x) = 1X);
+               Assert(AsChar(x) = 1X);
 
                i := absConst;
                i := floorConst;
index 9fc125ff827b057827ea77dd9160b2a577a38cd6..d780e15903c3e4a729c4446a067025516abb5651 100644 (file)
@@ -45,7 +45,7 @@ module T7Modules;
 
 begin
        Assert(A.boolConst);
-       Assert(A.charConst = CHR(22H));
+       Assert(A.charConst = AsChar(22H));
        Assert(A.intConst = 1);
        Assert(A.realConst = 2.3);
        Assert(A.strConst = "hello there");