From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 328 invoked by alias); 27 Jul 2007 13:17:35 -0000 Received: (qmail 32742 invoked by uid 22791); 27 Jul 2007 13:17:35 -0000 X-Spam-Check-By: sourceware.org Received: from ics.u-strasbg.fr (HELO ics.u-strasbg.fr) (130.79.112.250) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 27 Jul 2007 13:17:30 +0000 Received: from ICSMULLER (laocoon.u-strasbg.fr [130.79.112.72]) by ics.u-strasbg.fr (Postfix) with ESMTP id 2B942187021; Fri, 27 Jul 2007 15:21:20 +0200 (CEST) From: "Pierre Muller" To: "'Gaius Mulley'" Cc: , References: <874pjs57zg.fsf@j228-gm.comp.glam.ac.uk> <002a01c7cf57$b881b0c0$29851240$@u-strasbg.fr> <87ejiu6nru.fsf@j228-gm.comp.glam.ac.uk> In-Reply-To: <87ejiu6nru.fsf@j228-gm.comp.glam.ac.uk> Subject: RE: [PATCH] Unbounded array support implemented (for Modula-2) Date: Fri, 27 Jul 2007 13:28:00 -0000 Message-ID: <003a01c7d050$7c071af0$741550d0$@u-strasbg.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Content-Language: en-us Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-07/txt/msg00291.txt.bz2 > > 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