PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/fth/locals.fth

https://github.com/cataska/pforth
Forth | 77 lines | 68 code | 8 blank | 1 comment | 5 complexity | d2d7d7d6ceb8f4f95fc43b9565952636 MD5 | raw file
  1. \ @(#) $M$ 98/01/26 1.2
  2. \ standard { v0 v1 ... vn | l0 l1 .. lm -- } syntax
  3. \ based on ANSI basis words (LOCAL) and TO
  4. \
  5. \ Author: Phil Burk
  6. \ Copyright 1994 3DO, Phil Burk, Larry Polansky, Devid Rosenboom
  7. \
  8. \ The pForth software code is dedicated to the public domain,
  9. \ and any third party may reproduce, distribute and modify
  10. \ the pForth software code or any derivative works thereof
  11. \ without any compensation or license. The pForth software
  12. \ code is provided on an "as is" basis without any warranty
  13. \ of any kind, including, without limitation, the implied
  14. \ warranties of merchantability and fitness for a particular
  15. \ purpose and their equivalents under the laws of any jurisdiction.
  16. \ MOD: PLB 2/11/00 Allow EOL and \ between { }.
  17. anew task-locals.fth
  18. private{
  19. variable loc-temp-mode \ if true, declaring temporary variables
  20. variable loc-comment-mode \ if true, in comment section
  21. variable loc-done
  22. }private
  23. : { ( <local-declaration}> -- )
  24. loc-done off
  25. loc-temp-mode off
  26. loc-comment-mode off
  27. BEGIN
  28. bl word count
  29. dup 0> \ make sure we are not at the end of a line
  30. IF
  31. over c@
  32. CASE
  33. \ handle special characters
  34. ascii } OF loc-done on 2drop ENDOF
  35. ascii | OF loc-temp-mode on 2drop ENDOF
  36. ascii - OF loc-comment-mode on 2drop ENDOF
  37. ascii ) OF ." { ... ) imbalance!" cr abort ENDOF
  38. ascii \ OF postpone \ 2drop ENDOF \ Forth comment
  39. \ process name
  40. >r ( save char )
  41. ( addr len )
  42. loc-comment-mode @
  43. IF
  44. 2drop
  45. ELSE
  46. \ if in temporary mode, assign local var = 0
  47. loc-temp-mode @
  48. IF compile false
  49. THEN
  50. \ otherwise take value from stack
  51. (local)
  52. THEN
  53. r>
  54. ENDCASE
  55. ELSE
  56. 2drop refill 0= abort" End of input while defining local variables!"
  57. THEN
  58. loc-done @
  59. UNTIL
  60. 0 0 (local)
  61. ; immediate
  62. privatize
  63. \ tests
  64. : tlv1 { n -- } n dup n * dup n * ;
  65. : tlv2 { v1 v2 | l1 l2 -- }
  66. v1 . v2 . cr
  67. v1 v2 + -> l1
  68. l1 . l2 . cr
  69. ;