Array Index Out Of Range in ORG.FindPtrFlds
The following program compilers correctly in FPGA Oberon MODULE M1; TYPE P = POINTER TO R; R = RECORD a: ARRAY 160 OF INTEGER END ; (*compiles correctly*) END M1. but the following program leads to a trap 1 = array index out of range error in ORG.FindPtrFlds MODULE M2; TYPE P = POINTER TO R; R = RECORD a: ARRAY 160 OF P END ; (*trap 1 = array index out of range*) END M2. The reason is, of course, that ORG.data is an ARRAY maxTD (=160) OF INTEGER and ORG.FindPtrFlds traverses each array element individually to compute the offsets ELSIF typ.form = ORB.Array THEN s := typ.base.size; FOR i := 0 TO typ.len-1 DO FindPtrFlds(typ.base, i*s + off, dcw) END (*<--------*) Any suggestions how to address that in program M2 (or in the compiler, other than increasing maxTD)?
Andreas Ich bin mir nicht ganz sicher, aber sollte es nicht so heissen?
ELSIF typ.form = ORB.Array THEN FindPtrFlds(typ.base, off, dcw) END
Gruss, Jörg
Am 18.10.2021 um 08:52 schrieb Andreas Pirklbauer <andreas_pirklbauer@yahoo.com>:
The following program compilers correctly in FPGA Oberon
MODULE M1; TYPE P = POINTER TO R; R = RECORD a: ARRAY 160 OF INTEGER END ; (*compiles correctly*) END M1.
but the following program leads to a trap 1 = array index out of range error in ORG.FindPtrFlds
MODULE M2; TYPE P = POINTER TO R; R = RECORD a: ARRAY 160 OF P END ; (*trap 1 = array index out of range*) END M2.
The reason is, of course, that ORG.data is an ARRAY maxTD (=160) OF INTEGER
and ORG.FindPtrFlds traverses each array element individually to compute the offsets
ELSIF typ.form = ORB.Array THEN s := typ.base.size; FOR i := 0 TO typ.len-1 DO FindPtrFlds(typ.base, i*s + off, dcw) END (*<--------*)
Any suggestions how to address that in program M2 (or in the compiler, other than increasing maxTD)?
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Hello, Am 23.10.2021 um 12:22 schrieb Jörg:
Am 18.10.2021 um 08:52 schrieb Andreas Pirklbauer <andreas_pirklbauer@yahoo.com>:
ELSIF typ.form = ORB.Array THEN s := typ.base.size; FOR i := 0 TO typ.len-1 DO FindPtrFlds(typ.base, i*s + off, dcw) END (*<--------*)
Ich bin mir nicht ganz sicher, aber sollte es nicht so heissen?
ELSIF typ.form = ORB.Array THEN FindPtrFlds(typ.base, off, dcw) END
I don't think so. The list of pointer fields in the type descriptor is used by the garbage collector to know which addresses to follow in the mark phase. And when a RECORD contains an ARRAY of anything that contains pointers, the pointers have to be followed for each element of the array. So, a record that contains an array of 160 things that include pointers will need at least 160 pointers in the type descriptor. The only possible fix I see (without modifying the compiler) would be to split the array into either an array of smaller chunks (each allocated on the heap) or a linked list. So that each chunk contains a smaller number of pointers. Modifying the compiler might be the better solution, though. Regards, Michael
participants (3)
-
Andreas Pirklbauer -
Jörg -
Michael Schierl