Replaced some EM code by C code
authorceriel <none@none>
Tue, 5 Mar 1991 11:56:39 +0000 (11:56 +0000)
committerceriel <none@none>
Tue, 5 Mar 1991 11:56:39 +0000 (11:56 +0000)
lang/m2/libm2/LIST
lang/m2/libm2/rcka.c [new file with mode: 0644]
lang/m2/libm2/rcki.c [new file with mode: 0644]
lang/m2/libm2/rckil.c [new file with mode: 0644]
lang/m2/libm2/rcku.c [new file with mode: 0644]
lang/m2/libm2/rckul.c [new file with mode: 0644]
lang/m2/libm2/ucheck.c [new file with mode: 0644]

index 4294f16..7e3a15e 100644 (file)
@@ -38,10 +38,10 @@ confarray.c
 load.c
 blockmove.c
 stackprio.c
-ChkCards.e
+ucheck.c
+rcka.c
+rcku.c
+rcki.c
+rckul.c
+rckil.c
 EM.e
-rcka.e
-rcku.e
-rcki.e
-rckul.e
-rckil.e
diff --git a/lang/m2/libm2/rcka.c b/lang/m2/libm2/rcka.c
new file mode 100644 (file)
index 0000000..6178bd6
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ *
+ *
+ * Module:     range checks for INTEGER, now for array indexing
+ * Author:     Ceriel J.H. Jacobs
+ * Version:    $Header$
+*/
+
+#include <em_abs.h>
+
+extern TRP();
+
+struct array_descr {
+  int  lbound;
+  int  n_elts_min_one;
+  unsigned size;
+};
+
+rcka(descr, indx)
+  struct array_descr *descr;
+{
+  if (indx < 0 || indx > descr->n_elts_min_one) TRP(EARRAY);
+}
diff --git a/lang/m2/libm2/rcki.c b/lang/m2/libm2/rcki.c
new file mode 100644 (file)
index 0000000..2896461
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ *
+ *
+ * Module:     range checks for INTEGER
+ * Author:     Ceriel J.H. Jacobs
+ * Version:    $Header$
+*/
+
+#include <em_abs.h>
+
+extern TRP();
+
+struct range_descr {
+  int  low, high;
+};
+
+rcki(descr, val)
+  struct range_descr *descr;
+{
+  if (val < descr->low || val > descr->high) TRP(ERANGE);
+}
diff --git a/lang/m2/libm2/rckil.c b/lang/m2/libm2/rckil.c
new file mode 100644 (file)
index 0000000..cf43a98
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ *
+ *
+ * Module:     range checks for LONGINT
+ * Author:     Ceriel J.H. Jacobs
+ * Version:    $Header$
+*/
+
+#include <em_abs.h>
+
+extern TRP();
+
+struct range_descr {
+  long low, high;
+};
+
+rcki(descr, val)
+  struct range_descr *descr;
+  long val;
+{
+  if (val < descr->low || val > descr->high) TRP(ERANGE);
+}
diff --git a/lang/m2/libm2/rcku.c b/lang/m2/libm2/rcku.c
new file mode 100644 (file)
index 0000000..5ca4208
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ *
+ *
+ * Module:     range checks for CARDINAL
+ * Author:     Ceriel J.H. Jacobs
+ * Version:    $Header$
+*/
+
+#include <em_abs.h>
+
+extern TRP();
+
+struct range_descr {
+  unsigned     low, high;
+};
+
+rcki(descr, val)
+  struct range_descr *descr;
+  unsigned val;
+{
+  if (val < descr->low || val > descr->high) TRP(ERANGE);
+}
diff --git a/lang/m2/libm2/rckul.c b/lang/m2/libm2/rckul.c
new file mode 100644 (file)
index 0000000..4a5e4c9
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ *
+ *
+ * Module:     range checks for LONGCARD
+ * Author:     Ceriel J.H. Jacobs
+ * Version:    $Header$
+*/
+
+#include <em_abs.h>
+
+extern TRP();
+
+struct range_descr {
+  unsigned long        low, high;
+};
+
+rcki(descr, val)
+  struct range_descr *descr;
+  unsigned long val;
+{
+  if (val < descr->low || val > descr->high) TRP(ERANGE);
+}
diff --git a/lang/m2/libm2/ucheck.c b/lang/m2/libm2/ucheck.c
new file mode 100644 (file)
index 0000000..8c56b37
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ *
+ *
+ * Module:     CARDINAL operations with overflow checking
+ * Author:     Ceriel J.H. Jacobs
+ * Version:    $Header$
+*/
+
+#ifndef EM_WSIZE
+#define EM_WSIZE _EM_WSIZE
+#endif
+#ifndef EM_LSIZE
+#define EM_LSIZE _EM_LSIZE
+#endif
+
+#include <m2_traps.h>
+
+#define MAXCARD        ((unsigned)-1)
+#if EM_WSIZE < EM_LSIZE
+#define MAXLONGCARD    ((unsigned long) -1L)
+#endif
+
+adduchk(a,b)
+  unsigned     a,b;
+{
+  if (MAXCARD - a > b) TRP(M2_UOVFL);
+}
+
+#if EM_WSIZE < EM_LSIZE
+addulchk(a,b)
+  unsigned long        a,b;
+{
+  if (MAXLONGCARD - a > b) TRP(M2_UOVFL);
+}
+#endif
+
+muluchk(a,b)
+  unsigned     a,b;
+{
+  if (a != 0 && MAXCARD/a < b) TRP(M2_UOVFL);
+}
+
+#if EM_WSIZE < EM_LSIZE
+mululchk(a,b)
+  unsigned long        a,b;
+{
+  if (a != 0 && MAXLONGCARD/a < b) TRP(M2_UOVFL);
+}
+#endif
+
+subuchk(a,b)
+  unsigned     a,b;
+{
+  if (b < a) TRP(M2_UOVFL);
+}
+
+#if EM_WSIZE < EM_LSIZE
+subulchk(a,b)
+  unsigned long        a,b;
+{
+  if (b < a) TRP(M2_UOVFL);
+}
+#endif