/hmsl/fth/cond_comp.fth

https://github.com/philburk/hmsl · Forth · 63 lines · 56 code · 7 blank · 0 comment · 1 complexity · c6211a7515e8aeb993d638a08f984763 MD5 · raw file

  1. \ Conditional Compilation
  2. \
  3. \ *********************************************************************
  4. \ * HMSL Forth System *
  5. \ * Author: Phil Burk *
  6. \ * Copyright 1989 Phil Burk , All Rights Reserved *
  7. \ *********************************************************************
  8. \
  9. \ MOD: PLB 10/9/90 Removed check for ?TERMINAL in .ELSE
  10. decimal
  11. ANEW TASK-COND_COMP
  12. \ Lifted from X3J14 dpANS-6 document.
  13. : .ELSE ( -- )
  14. 1
  15. BEGIN \ level
  16. BEGIN
  17. BL WORD \ level $word
  18. COUNT DUP \ level adr len len
  19. WHILE \ level adr len
  20. 2DUP S" .IF" COMPARE 0=
  21. IF \ level adr len
  22. 2DROP 1+ \ level'
  23. ELSE \ level adr len
  24. 2DUP S" .ELSE"
  25. COMPARE 0= \ level adr len flag
  26. IF \ level adr len
  27. 2DROP 1- DUP IF 1+ THEN \ level'
  28. ELSE \ level adr len
  29. S" .THEN" COMPARE 0=
  30. IF
  31. 1- \ level'
  32. THEN
  33. THEN
  34. THEN
  35. ?DUP 0= IF EXIT THEN \ level'
  36. REPEAT 2DROP \ level
  37. REFILL 0= UNTIL \ level
  38. DROP
  39. ; IMMEDIATE
  40. : .IF ( flag -- )
  41. 0=
  42. IF POSTPONE .ELSE
  43. THEN
  44. ; IMMEDIATE
  45. : .THEN ( -- )
  46. ; IMMEDIATE
  47. : .NEED ( <name> -- start compiling if not found )
  48. [compile] exists? not [compile] .IF
  49. ;
  50. : $REMOVE" ( $string -- , remove trailing " )
  51. dup count 1- + c@ ascii " =
  52. IF cr ." Removing extraneous " ascii " emit ." from name!" cr
  53. dup c@ 1- swap c!
  54. ELSE drop
  55. THEN
  56. ;