/fth/t_locals.fth

https://github.com/philburk/pforth · Forth · 58 lines · 46 code · 12 blank · 0 comment · 0 complexity · d60ed668dbb7d75c1f2ae13fe57078ce MD5 · raw file

  1. \ @(#) t_locals.fth 97/01/28 1.1
  2. \ Test PForth LOCAL variables.
  3. \
  4. \ Copyright 1996 3DO, Phil Burk
  5. include? }T{ t_tools.fth
  6. anew task-t_locals.fth
  7. decimal
  8. test{
  9. \ test value and locals
  10. T{ 333 value my-value my-value }T{ 333 }T
  11. T{ 1000 -> my-value my-value }T{ 1000 }T
  12. T{ 35 +-> my-value my-value }T{ 1035 }T
  13. T{ 987 to my-value my-value }T{ 987 }T
  14. : test.value ( -- ok )
  15. 100 -> my-value
  16. my-value 100 =
  17. 47 +-> my-value
  18. my-value 147 = AND
  19. ;
  20. T{ test.value }T{ TRUE }T
  21. \ test compile time behavior of a VALUE
  22. 567 value VAL3 immediate
  23. : VD3 val3 literal ;
  24. T{ vd3 }T{ 567 }T
  25. \ test locals in a word
  26. : test.locs { aa bb | cc -- ok }
  27. cc 0=
  28. aa bb + -> cc
  29. aa bb + cc = AND
  30. aa -> cc
  31. bb +-> cc
  32. aa bb + cc = AND
  33. ;
  34. T{ 200 59 test.locs }T{ TRUE }T
  35. .( Test warning when no locals defined.) cr
  36. : loc.nonames { -- } 1234 ;
  37. T{ loc.nonames }T{ 1234 }T
  38. \ try to put EOLs and comments in variable list
  39. : calc.area {
  40. width \ horizontal dimension
  41. height \ vertical dimension
  42. -- area , calculate area of a rectangle }
  43. width height *
  44. ;
  45. T{ 5 20 calc.area }T{ 100 }T
  46. }test