PageRenderTime 25ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/fth/utils/dump_struct.fth

https://github.com/cataska/pforth
Forth | 120 lines | 106 code | 14 blank | 0 comment | 0 complexity | d7d9880a2f554addb9c41141500d3b5b MD5 | raw file
  1. \ @(#) dump_struct.fth 97/12/10 1.1
  2. \ Dump contents of structure showing values and member names.
  3. \
  4. \ Author: Phil Burk
  5. \ Copyright 1987 Phil Burk
  6. \ All Rights Reserved.
  7. \
  8. \ MOD: PLB 9/4/88 Print size too.
  9. \ MOD: PLB 9/9/88 Print U/S , add ADST
  10. \ MOD: PLB 12/6/90 Modified to work with H4th
  11. \ 941109 PLB Converted to pforth. Added RP detection.
  12. include? task-member member.fth
  13. include? task-c_struct c_struct.fth
  14. ANEW TASK-DUMP_STRUCT
  15. : EMIT-TO-COLUMN ( char col -- )
  16. out @ - 0 max 80 min 0
  17. DO dup emit
  18. LOOP drop
  19. ;
  20. VARIABLE SN-FENCE
  21. : STACK.NFAS ( fencenfa topnfa -- 0 nfa0 nfa1 ... )
  22. \ Fill stack with nfas of words until fence hit.
  23. >r sn-fence !
  24. 0 r> ( set terminator )
  25. BEGIN ( -- 0 n0 n1 ... top )
  26. dup sn-fence @ >
  27. WHILE
  28. \ dup n>link @ \ JForth
  29. dup prevname \ HForth
  30. REPEAT
  31. drop
  32. ;
  33. : DST.DUMP.TYPE ( +-size -- , dump data type, 941109)
  34. dup abs 4 =
  35. IF
  36. 0<
  37. IF ." RP"
  38. ELSE ." U4"
  39. THEN
  40. ELSE
  41. dup 0<
  42. IF ascii U
  43. ELSE ascii S
  44. THEN emit abs 1 .r
  45. THEN
  46. ;
  47. : DUMP.MEMBER ( addr member-pfa -- , dump member of structure)
  48. ob.stats ( -- addr offset size )
  49. >r + r> ( -- addr' size )
  50. dup ABS 4 > ( -- addr' size flag )
  51. IF cr 2dup swap . . ABS dump
  52. ELSE tuck @bytes 10 .r ( -- size )
  53. 3 spaces dst.dump.type
  54. THEN
  55. ;
  56. VARIABLE DS-ADDR
  57. : DUMP.STRUCT ( addr-data addr-structure -- )
  58. >newline swap >r ( -- as , save addr-data for dumping )
  59. \ dup cell+ @ over + \ JForth
  60. dup code> >name swap cell+ @ over + \ HForth
  61. stack.nfas ( fill stack with nfas of members )
  62. BEGIN
  63. dup
  64. WHILE ( continue until non-zero )
  65. dup name> >body r@ swap dump.member
  66. bl 18 emit-to-column id. cr
  67. ?pause
  68. REPEAT drop rdrop
  69. ;
  70. : DST ( addr <name> -- , dump contents of structure )
  71. ob.findit
  72. state @
  73. IF [compile] literal compile dump.struct
  74. ELSE dump.struct
  75. THEN
  76. ; immediate
  77. : ADST ( absolute_address -- , dump structure )
  78. >rel [compile] dst
  79. ; immediate
  80. \ For Testing Purposes
  81. false .IF
  82. :STRUCT GOO
  83. LONG DATAPTR
  84. SHORT GOO_WIDTH
  85. USHORT GOO_HEIGHT
  86. ;STRUCT
  87. :STRUCT FOO
  88. LONG ALONG1
  89. STRUCT GOO AGOO
  90. SHORT ASHORT1
  91. BYTE ABYTE
  92. BYTE ABYTE2
  93. ;STRUCT
  94. FOO AFOO
  95. : AFOO.INIT
  96. $ 12345678 afoo ..! along1
  97. $ -665 afoo ..! ashort1
  98. $ 21 afoo ..! abyte
  99. $ 43 afoo ..! abyte2
  100. -234 afoo .. agoo ..! goo_height
  101. ;
  102. afoo.init
  103. : TDS ( afoo -- )
  104. dst foo
  105. ;
  106. .THEN