t61_setconst.pas 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. program t61_setconst;
  2. { t61 -- sets, first increment: the hybrid TYPE, the set CONSTRUCTOR, a set
  3. TYPED CONSTANT, and compile-time membership.
  4. CALC.PAS:114 is
  5. Numbers : set of Char = ['0'..'9'];
  6. The layout is TP3's hybrid one (coeur-tp-ocr 4.7.2): only the whole BYTES
  7. covering the base range are stored, element e is bit (e MOD 8) of byte
  8. ((e DIV 8) - (base DIV 8)), and the high byte comes last. For `set of Char'
  9. that is 32 bytes; `set of 12..17' is 2.
  10. A set typed constant is not foldable to a word, so its 32 bytes are emitted
  11. in the code stream behind a JMP (the same trick string literals use) and the
  12. name becomes an addressable value. No `seg cs' is needed: a .COM's DS
  13. already covers the code segment - that is the divergence from the original,
  14. which had separate segments (see CALC-COMPILE.md).
  15. `in' with a COMPILE-TIME element and a set already in the image is answered
  16. at compile time, exactly as TPSRC2 xsetin answers at run time (AH > 255 ->
  17. FALSE, else test the bit). A run-time element or set is still ENoLib and
  18. stays loud; that is the next increment, not a silent wrong answer. }
  19. const
  20. Numbers : set of Char = ['0'..'9'];
  21. begin
  22. writeln ('5' in Numbers); { in the constant }
  23. writeln ('X' in Numbers); { not in it }
  24. writeln ('0' in ['0'..'9']); { an inline literal, same answer }
  25. writeln ('z' in ['a'..'z', 'A'..'Z'])
  26. end.