Mirror of CollapseOS
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

156 rindas
2.3KB

  1. .equ RAMSTART 0x4000
  2. .equ ZASM_REG_MAXCNT 0xff
  3. .equ ZASM_LREG_MAXCNT 0x40
  4. .equ ZASM_REG_BUFSZ 0x1000
  5. .equ ZASM_LREG_BUFSZ 0x200
  6. ; declare DIREC_LASTVAL manually so that we don't have to include directive.asm
  7. .equ DIREC_LASTVAL RAMSTART
  8. jp test
  9. .inc "ascii.h"
  10. .inc "core.asm"
  11. .inc "str.asm"
  12. .inc "lib/util.asm"
  13. .inc "lib/ari.asm"
  14. .inc "lib/fmt.asm"
  15. .inc "zasm/util.asm"
  16. .inc "zasm/const.asm"
  17. .inc "lib/parse.asm"
  18. .inc "zasm/parse.asm"
  19. .equ SYM_RAMSTART DIREC_LASTVAL+2
  20. .inc "zasm/symbol.asm"
  21. .equ EXPR_PARSE parseNumberOrSymbol
  22. .inc "lib/expr.asm"
  23. .equ STDIO_RAMSTART SYM_RAMEND
  24. .inc "stdio.asm"
  25. .inc "common.asm"
  26. ; Pretend that we aren't in first pass
  27. zasmIsFirstPass:
  28. jp unsetZ
  29. zasmGetPC:
  30. ret
  31. sFOO: .db "FOO", 0
  32. sBAR: .db "BAR", 0
  33. test:
  34. ld sp, 0xffff
  35. ; before testing begins, let's set up FOO and BAR symbols
  36. call symInit
  37. ld hl, sFOO
  38. ld de, 0x4000
  39. call symRegisterGlobal
  40. jp nz, fail
  41. ld hl, sBAR
  42. ld de, 0x20
  43. call symRegisterGlobal
  44. jp nz, fail
  45. call testParseExpr
  46. call testSPOnFail
  47. ; success
  48. xor a
  49. halt
  50. testParseExpr:
  51. ld hl, .alltests
  52. ld ix, .test
  53. jp testList
  54. .test:
  55. push hl \ pop iy
  56. inc hl \ inc hl
  57. call parseExpr
  58. call assertZ
  59. ld l, (iy)
  60. ld h, (iy+1)
  61. jp assertEQW
  62. .t1:
  63. .dw 7
  64. .db "42/6", 0
  65. .t2:
  66. .dw 1
  67. .db "7%3", 0
  68. .t3:
  69. .dw 0x0907
  70. .db "0x99f7&0x0f0f", 0
  71. .t4:
  72. .dw 0x9fff
  73. .db "0x99f7|0x0f0f", 0
  74. .t5:
  75. .dw 0x96f8
  76. .db "0x99f7^0x0f0f", 0
  77. .t6:
  78. .dw 0x133e
  79. .db "0x99f7}3", 0
  80. .t7:
  81. .dw 0xcfb8
  82. .db "0x99f7{3", 0
  83. .t8:
  84. .dw 0xffff
  85. .db "-1", 0
  86. .t9:
  87. .dw 10
  88. .db "2*3+4", 0
  89. ; There was this untested regression during the replacement of find-and-subst
  90. ; parseExpr to the recursive descent one. It was time consuming to find. Here
  91. ; it goes, here it stays.
  92. .t10:
  93. .dw '-'+1
  94. .db "'-'+1", 0
  95. .t11:
  96. .dw 0x4023
  97. .db "0x4001+0x22", 0
  98. .t12:
  99. .dw 0x4020
  100. .db "FOO+BAR", 0
  101. .t13:
  102. .dw 0x60
  103. .db "BAR*3", 0
  104. .t14:
  105. .dw 0x3ffd
  106. .db "FOO-3", 0
  107. .t15:
  108. .dw 0x4080
  109. .db "FOO+BAR*4", 0
  110. ; "0" is a special case, let's test it
  111. .t16:
  112. .dw 0
  113. .db "0", 0
  114. ; Another one that caused troubles
  115. .t17:
  116. .dw 123
  117. .db "0+123", 0
  118. .alltests:
  119. .dw .t1, .t2, .t3, .t4, .t5, .t6, .t7, .t8, .t9, .t10, .t11, .t12
  120. .dw .t13, .t14, .t15, .t16, .t17, 0
  121. ; Ensure that stack is balanced on failure
  122. testSPOnFail:
  123. ld (testSP), sp
  124. ld hl, .sFail
  125. call parseExpr
  126. call assertNZ
  127. call assertSP
  128. jp nexttest
  129. .sFail: .db "1+abc123", 0