PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/fth/t_locals.fth

https://github.com/cataska/pforth
Forth | 52 lines | 41 code | 11 blank | 0 comment | 0 complexity | f39f7ddbea3023549750cd004dc8ed01 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. : test.value ( -- ok )
  14. 100 -> my-value
  15. my-value 100 =
  16. 47 +-> my-value
  17. my-value 147 = AND
  18. ;
  19. T{ test.value }T{ TRUE }T
  20. \ test locals in a word
  21. : test.locs { aa bb | cc -- ok }
  22. cc 0=
  23. aa bb + -> cc
  24. aa bb + cc = AND
  25. aa -> cc
  26. bb +-> cc
  27. aa bb + cc = AND
  28. ;
  29. T{ 200 59 test.locs }T{ TRUE }T
  30. .( Test warning when no locals defined.) cr
  31. : loc.nonames { -- } 1234 ;
  32. T{ loc.nonames }T{ 1234 }T
  33. \ try to put EOLs and comments in variable list
  34. : calc.area {
  35. width \ horizontal dimension
  36. height \ vertical dimension
  37. -- area , calculate area of a rectangle }
  38. width height *
  39. ;
  40. T{ 5 20 calc.area }T{ 100 }T
  41. }test