t78_setfield.pas 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. program t78_setfield;
  2. { t78 -- a SET field of a record: assignment and membership.
  3. CALC.INC:161 is the first statement inside `with Sheet[I,J] do':
  4. CellStatus := [Txt];
  5. CellStatus is `set of Attributes' (0..5, so ONE byte), NOT the default
  6. 32-byte `set of Char' that an untyped constructor becomes. The target
  7. supplies the base and size; the constructor's bytes are known at compile
  8. time and are stored at symbol+boff (a constant-index element) or through DI
  9. (a run-time-indexed one).
  10. `in' is the observation: a CODE-resident set (literal or typed constant)
  11. still folds at compile time, while a set FIELD is tested at run time by
  12. loading its byte and masking the element's bit. }
  13. type
  14. Attr = (Constant, Formula, Txt, OverWritten, Locked, Calculated);
  15. Cell = record
  16. Status : set of Attr;
  17. N : integer;
  18. end;
  19. var
  20. sh : array [1..2, 1..3] of Cell;
  21. begin
  22. with sh[1,1] do
  23. begin
  24. Status := [Txt];
  25. N := 5
  26. end;
  27. with sh[1,1] do
  28. if Txt in Status then writeln ('txt') else writeln ('no-txt');
  29. with sh[1,1] do
  30. if Locked in Status then writeln ('locked') else writeln ('not-locked');
  31. (* N sits immediately after the one-byte Status. Set it FIRST, then the
  32. set: a store that used the default 32-byte length would run over N and
  33. zero it. *)
  34. sh[2,3].N := 7;
  35. sh[2,3].Status := [Locked, Calculated];
  36. if Locked in sh[2,3].Status then writeln ('l2') else writeln ('nl2');
  37. if Txt in sh[2,3].Status then writeln ('t2') else writeln ('nt2');
  38. (* the fields after the set were not clobbered *)
  39. writeln (sh[1,1].N);
  40. writeln (sh[2,3].N)
  41. end.