| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- program t77_with;
- { t77 -- WITH, and 2-D array subscripts.
- CALC.INC:158 is
- with Sheet[I,J] do
- begin
- CellStatus := [Txt];
- Contents := '';
- ...
- end;
- Sheet is `array['A'..'G',1..FYMax] of CellRec', so the WITH base is an
- element at a RUN-TIME address: the row stride is (hi1-lo1+1)*elemsize and
- both indices vary. The base address is parked in a data slot because the
- body may clobber DI; each field access reloads it and adds the field's
- offset.
- Also covers a WITH over a plain record variable (symbol+offset, no slot), a
- WITH over a constant-index element, a field read back inside the body, and a
- mixed constant/variable 2-D subscript. Field types here are INTEGER and
- CHAR: SET and STRING fields need their own assignments and are the next
- rung (CALC's CellStatus is the first one). }
- type
- Rec = record
- a : integer;
- b : char;
- end;
- var
- g : array [1..2, 1..3] of Rec;
- i, j : integer;
- r : Rec;
- begin
- with r do
- begin
- a := 3;
- b := 'q'
- end;
- writeln (r.a, r.b);
- i := 2;
- j := 3;
- with g[i,j] do
- begin
- a := 42;
- b := 'x'
- end;
- writeln (g[2,3].a, g[2,3].b);
- with g[i,j] do
- writeln (a);
- with g[1,2] do
- a := 7;
- writeln (g[1,2].a);
- (* The stride is pinned INDEPENDENTLY: write with constant indices (folded
- at compile time) and read with the run-time formula. A write and a read
- that share the same wrong stride would agree with each other. *)
- g[2,3].a := 99;
- writeln (g[i,j].a);
- j := 2;
- g[i,j].a := 11;
- writeln (g[2,2].a);
- (* A wrong row stride makes different index pairs ALIAS. With the correct
- stride (9, 3), (1,2) is offset 3 and (2,1) is 9; with a uniform element
- stride they are both 3. Writing two values and reading the first is the
- observation no self-consistent formula can fake. *)
- g[1,2].a := 71;
- g[2,1].a := 81;
- writeln (g[1,2].a)
- end.
|