PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/fcode-utils-devel/testsuite/TokeErrs/DevNodAli_01.fth

https://github.com/mwilbur/openbios
Forth | 159 lines | 128 code | 30 blank | 1 comment | 3 complexity | 8a5dcc76781f8cb4114a55adaf7f6361 MD5 | raw file
  1. \ Test scope of "aliased" name in device-node
  2. \ along w/ excess of "finish-device"
  3. \ DevNodAli_01.fth -- slight variant relative to DevNodAli.fth
  4. \ Updated Thu, 12 Jan 2006 at 15:36 PST by David L. Paktor
  5. \
  6. [flag] Local-Values
  7. show-flags
  8. fcode-version2
  9. fload LocalValuesSupport.fth
  10. headers
  11. \ Should an alias to a core-function be local to the device-node
  12. \ in which it was made, or global to the whole tokenization?
  13. \ After talking w/ Jim L., answer is: Global.
  14. \ An alias to a core-function goes into the core vocab.
  15. \ But! When new-device or finish-device is used inside a
  16. \ colon-definition, it should not change the tok'z'n-time vocab...
  17. \ I gave some further thought to the question of
  18. \ the scope of a alias to a core-function.
  19. \ A true FORTH-based tokenizer would place an alias-created definition
  20. \ into the "current" vocabulary, regardless of where the target of
  21. \ the alias was found. I now believe we should do the same, also.
  22. \ If the user intends to define an alias with global scope, then
  23. \ that intention should be expressed explicitly.
  24. \ Like this:
  25. global-definitions
  26. alias foop dup \ Here's a classic case
  27. alias pelf my-self \ Here's another
  28. \ And here are two just to screw you up!
  29. alias >> lshift
  30. alias << rshift
  31. device-definitions
  32. : troop ." Dup to my-self" foop to pelf ;
  33. alias snoop troop
  34. : croup foop snoop ;
  35. : make-rope-name ( slip-number -- )
  36. { _slip }
  37. " roper_" encode-string
  38. _slip (.) encode-string encode+ name
  39. ;
  40. : slip-prop ( slip-number -- )
  41. { _slip }
  42. _slip not d# 24 >>
  43. _slip d# 16 >> +
  44. _slip not 1 << h# 0ff and 8 >> +
  45. _slip +
  46. encode-int " slipknot" property
  47. ;
  48. hex
  49. create achin \ Table of slip-numbers for each device
  50. 12 c, 13 c, 14 c,
  51. 56 c, 43 c, 50 c, 54 c,
  52. 0 c, \ 0-byte is list-terminator
  53. : make-name-and-prop ( slip-number -- )
  54. foop
  55. make-rope-name
  56. slip-prop
  57. ;
  58. : tie-one-on ( slip-number -- )
  59. new-device make-name-and-prop
  60. ;
  61. [message] Define a method that creates subsidiaries...
  62. : spawn-offspring ( -- )
  63. achin
  64. begin ( addr )
  65. dup c@ ?dup while ( addr slip )
  66. tie-one-on
  67. finish-device
  68. 1+ \ Bump to next entry
  69. repeat drop
  70. ;
  71. : more-offs ( -- addr count )
  72. " "( \ Another table of offsprings' slip-numbers
  73. )YUMA"( \ Some of them are letters
  74. 85 92 13 \ Some are not
  75. )" \ That is all
  76. ;
  77. : tap-it-out ( n -- n+1 )
  78. finish-device
  79. 1+
  80. ;
  81. : spawn-more
  82. 0 more-offs bounds do
  83. new-device i c@
  84. make-name-and-prop
  85. tap-it-out
  86. loop
  87. encode-int " num-offs" property
  88. ;
  89. [message] Subsidiary (child) device-node
  90. new-device
  91. create eek! 18 c, 17 c, 80 c, 79 c,
  92. : freek eek! 4 bounds ?do i c@ . 1 +loop ;
  93. : greek -1 if freek then ;
  94. [message] About to access method from parent node
  95. : hierareek
  96. eek!
  97. freek
  98. achin
  99. greek
  100. ;
  101. : ikey hierareek freek greek ;
  102. \ Does (Should) the new device know about its parent's aliases?
  103. : bad-refs
  104. croup
  105. foop
  106. snoop
  107. foop
  108. to pelf
  109. ;
  110. [message] end child node
  111. finish-device
  112. [message] Access methods from the root node again
  113. : refs-good-again
  114. croup
  115. foop
  116. snoop
  117. foop
  118. to pelf
  119. ;
  120. [message] An extra finish-device
  121. finish-device
  122. [message] Are we still here?
  123. : spoof
  124. bad-refs
  125. foop
  126. refs-good-again
  127. ;
  128. \ That is all...
  129. fcode-end