[PATCH] Unbounded array support implemented (for Modula-2)
Pierre Muller
muller at ics.u-strasbg.fr
Fri Jul 27 15:17:29 CEST 2007
> > Modula-2 is not the only language supporting unbounded arrays, I
> > would be interested in using the same kind of code for pascal
> > language support.
>
> sure, I'm all for refactoring code..
>
> > Maybe a more general approach would be useful?
>
> maybe - although I suspect the devil is in the detail. Basically
> Modula-2 assumes that all unbounded arrays start at index 0 and the
> caller can be legally access all indices 0..HIGH(a). GNU Modula-2
> implements unbounded arrays by creating a structure whose first field
> is a pointer to type, and the second structure is the HIGH value
> (unsigned int). So the patches basically detect if the array
> declaration matches a GNU Modula-2 unbounded structure (testing field
> names and types and language). If so then it maps any reference to
> a[i] onto a->_m2_contents[i] and HIGH(a) onto a->_m2_high. How does
> GNU Pascal implement unbounded arrays?
This is basically also the case for parameter unbounded arrays:
the valid indexes are from 0 to high(a) and high(a)
is passed as an additional hidden parameter,
called
highA (high in lower case followed by the uppercase name of the parameter)
for free pascal
and
open_array_length_0 (or _x for the X+1 open array parameter) for GNU
pascal.
The open array type can be recongnized by the fact that the
lower bound is 0, while the higher bound is -1.
Free pascal now also supports global open array variables
which are allocated by using SetLength function. They are
basically hidden pointers.
The high values is at offset -4 (or size of pointer more generally) relative
to
the pointer address. I don't know if GPC supports this
syntax. Maybe someone from GPC team can answer this question.
Pierre Muller
More information about the Gpc
mailing list