gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gm2] Re: LENGTH() on Solaris 10/sparc


From: john o goyo
Subject: [Gm2] Re: LENGTH() on Solaris 10/sparc
Date: Sat, 24 Jul 2010 13:51:32 -0400

On 24-Jul-10, at 3:48 AM, Gaius Mulley wrote:
john o goyo <address@hidden> writes:

Examination of the failed test cases shows a real oddity.

In a call to LENGTH(s), where s is a string, HIGH(s) is passed as
zero and LENGTH(s) is always 1.

Could you please answer the following to assist in my further inquiries:

1. Where is LENGTH() defined?

Hi John,

gm2/gm2-libs-iso/M2RTS.mod:Length for iso
gm2/gm2-libs/M2RTS.mod:Length for pim


2. How are open arrays passed on the stack?

a structure is passed on the stack which contains:

struct unbounded {
  char *startofstring;
  unsigned int high;
}

it would be interesting to single step the regression test
tstLength - and observe the string contents when LENGTH is invoked.

Single stepping was how I discovered the problem. (Actually, I first added
local variables to explicitly check the results.)

Consider  the following wee modules.
=========================================
MODULE LengthTest;

FROM StrIO IMPORT WriteString, WriteLn;
FROM NumberIO IMPORT WriteCard;
FROM testLength IMPORT CallLENGTH;

VAR
  s :ARRAY[0..15] OF CHAR;
  n :CARDINAL;
BEGIN
  s := "Woe";
  n := CallLENGTH(s);
  WriteString("Woe is "); WriteCard(n, 2); WriteLn;

  s := "Joy";
  n := LENGTH(s);
  WriteString("Joy is "); WriteCard(n, 2); WriteLn

END LengthTest.
=========================================
IMPLEMENTATION MODULE testLength;

PROCEDURE CallLENGTH(s :ARRAY OF CHAR) :CARDINAL;
VAR
   n: CARDINAL;
BEGIN
   n := LENGTH(s);

   RETURN n
END CallLENGTH;

END testLength.
=========================================

The output is the following.

Woe is  3
Joy is  1

From within gdb:

16        n := LENGTH(s);
(gdb) p s
$1 = "Joy", '\000' <repeats 13 times>
(gdb) s
M2RTS_Length (a={_m2_contents = 0x10012c158, _m2_high_1 = 0})
    at ../../../src/gcc-4.1.2/gcc/gm2/gm2-libs-iso/M2RTS.mod:249
249        l := 0 ;
(gdb) l
244
245     PROCEDURE Length (a: ARRAY OF CHAR) : CARDINAL ;
246     VAR
247        l, h: CARDINAL ;
(gdb) p a
$2 = {_m2_contents = 0x10012c158, _m2_high_1 = 0}
(gdb) p a._m2_contents^
$3 = 74 'J'
(gdb) p a._m2_contents^[0]
cannot subscript something of type `CHAR'

(I am unsure how to cast a pointer to char as a pointer to a string here.)

So passed an open array, LENGTH() acts correclty but passed an array
directly, LENGTH() returns 1.

The test seems to expose problems with:

VAR
   s: ARRAY [1..5] OF CHAR ;
BEGIN
   s := 'What?' ;
   IF LENGTH(foo)...

I suspect the 1..5 is causing confusion somewhere - it would be
interesting to see if the test works if the lower bound were 0,

The same problem occurs -- see above. Given your information above, I shall examine the
assembler output and report back.

john



reply via email to

[Prev in Thread] Current Thread [Next in Thread]