aboutsummaryrefslogtreecommitdiff
path: root/gcc/m2
diff options
context:
space:
mode:
authorGaius Mulley <gaiusmod2@gmail.com>2024-10-01 15:06:54 +0100
committerGaius Mulley <gaiusmod2@gmail.com>2024-10-01 15:06:54 +0100
commit8273e31adfa1ba5f0722eb37bcc8aeca8718a472 (patch)
treea98cf3cd79fd4bc7d78341f23a74329a991e5fe7 /gcc/m2
parentfda30a3c8a7c6b06f02be40e3fd0740f893a1b4f (diff)
downloadgcc-8273e31adfa1ba5f0722eb37bcc8aeca8718a472.zip
gcc-8273e31adfa1ba5f0722eb37bcc8aeca8718a472.tar.gz
gcc-8273e31adfa1ba5f0722eb37bcc8aeca8718a472.tar.bz2
modula2: Add FindIndice to library module gm2-libs/Indexing
This patch introduces the procedure function FindIndice to library module Indexing. gcc/m2/ChangeLog: * gm2-libs/Indexing.def (FindIndice): New procedure function. * gm2-libs/Indexing.mod (FindIndice): Implement new procedure function. Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
Diffstat (limited to 'gcc/m2')
-rw-r--r--gcc/m2/gm2-libs/Indexing.def8
-rw-r--r--gcc/m2/gm2-libs/Indexing.mod28
2 files changed, 36 insertions, 0 deletions
diff --git a/gcc/m2/gm2-libs/Indexing.def b/gcc/m2/gm2-libs/Indexing.def
index f7c4676..0b56043 100644
--- a/gcc/m2/gm2-libs/Indexing.def
+++ b/gcc/m2/gm2-libs/Indexing.def
@@ -144,4 +144,12 @@ PROCEDURE ForeachIndiceInIndexDo (i: Index; p: IndexProcedure) ;
PROCEDURE IsEmpty (i: Index) : BOOLEAN ;
+(*
+ FindIndice - returns the indice containing a.
+ It returns zero if a is not found in array i.
+*)
+
+PROCEDURE FindIndice (i: Index; a: ADDRESS) : CARDINAL ;
+
+
END Indexing.
diff --git a/gcc/m2/gm2-libs/Indexing.mod b/gcc/m2/gm2-libs/Indexing.mod
index 08af134..7bcaf87 100644
--- a/gcc/m2/gm2-libs/Indexing.mod
+++ b/gcc/m2/gm2-libs/Indexing.mod
@@ -343,6 +343,34 @@ END IncludeIndiceIntoIndex ;
(*
+ FindIndice - returns the indice containing a.
+ It returns zero if a is not found in array i.
+*)
+
+PROCEDURE FindIndice (i: Index; a: ADDRESS) : CARDINAL ;
+VAR
+ j: CARDINAL ;
+ p: PtrToAddress ;
+ b: PtrToByte ;
+BEGIN
+ WITH i^ DO
+ j := Low ;
+ b := ArrayStart ;
+ WHILE j <= High DO
+ p := VAL (PtrToAddress, b) ;
+ INC (b, TSIZE (ADDRESS)) ;
+ IF p^ = a
+ THEN
+ RETURN j
+ END ;
+ INC (j)
+ END
+ END ;
+ RETURN 0
+END FindIndice ;
+
+
+(*
ForeachIndiceInIndexDo - for each j indice of i, call procedure p(i[j])
*)