mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-11-30 23:35:00 +08:00
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>
This commit is contained in:
parent
fda30a3c8a
commit
8273e31adf
@ -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.
|
||||
|
@ -342,6 +342,34 @@ BEGIN
|
||||
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])
|
||||
*)
|
||||
|
Loading…
Reference in New Issue
Block a user