2019-05-17 13:14:16 -04:00
|
|
|
.equ RAMSTART 0x4000
|
2019-07-23 16:50:19 -04:00
|
|
|
.equ ZASM_REG_MAXCNT 0xff
|
|
|
|
.equ ZASM_LREG_MAXCNT 0x40
|
|
|
|
.equ ZASM_REG_BUFSZ 0x1000
|
|
|
|
.equ ZASM_LREG_BUFSZ 0x200
|
|
|
|
|
2019-10-04 20:26:21 -04:00
|
|
|
; declare DIREC_LASTVAL manually so that we don't have to include directive.asm
|
|
|
|
.equ DIREC_LASTVAL RAMSTART
|
|
|
|
|
2019-05-17 13:14:16 -04:00
|
|
|
jp test
|
|
|
|
|
2019-12-23 15:41:25 -05:00
|
|
|
.inc "ascii.h"
|
2019-10-06 14:32:23 -04:00
|
|
|
.inc "core.asm"
|
2019-11-14 09:55:31 -05:00
|
|
|
.inc "str.asm"
|
2019-10-06 14:32:23 -04:00
|
|
|
.inc "lib/util.asm"
|
2019-11-22 14:45:12 -05:00
|
|
|
.inc "lib/ari.asm"
|
2019-12-23 15:41:25 -05:00
|
|
|
.inc "lib/fmt.asm"
|
2019-10-06 14:32:23 -04:00
|
|
|
.inc "zasm/util.asm"
|
|
|
|
.inc "zasm/const.asm"
|
|
|
|
.inc "lib/parse.asm"
|
|
|
|
.inc "zasm/parse.asm"
|
2019-10-04 20:26:21 -04:00
|
|
|
.equ SYM_RAMSTART DIREC_LASTVAL+2
|
2019-10-06 14:32:23 -04:00
|
|
|
.inc "zasm/symbol.asm"
|
2019-11-18 15:52:07 -05:00
|
|
|
.equ EXPR_PARSE parseNumberOrSymbol
|
|
|
|
.inc "lib/expr.asm"
|
2019-12-23 15:41:25 -05:00
|
|
|
.equ STDIO_RAMSTART SYM_RAMEND
|
|
|
|
.inc "stdio.asm"
|
|
|
|
.inc "common.asm"
|
2019-05-17 13:14:16 -04:00
|
|
|
|
|
|
|
; Pretend that we aren't in first pass
|
|
|
|
zasmIsFirstPass:
|
|
|
|
jp unsetZ
|
|
|
|
|
2019-05-20 09:17:50 -04:00
|
|
|
zasmGetPC:
|
|
|
|
ret
|
|
|
|
|
2019-05-17 13:14:16 -04:00
|
|
|
|
|
|
|
sFOO: .db "FOO", 0
|
|
|
|
sBAR: .db "BAR", 0
|
|
|
|
|
|
|
|
test:
|
2019-11-22 15:03:16 -05:00
|
|
|
ld sp, 0xffff
|
2019-05-17 13:14:16 -04:00
|
|
|
|
2019-12-29 15:39:39 -05:00
|
|
|
; before testing begins, let's set up FOO and BAR symbols
|
2019-05-17 13:14:16 -04:00
|
|
|
call symInit
|
|
|
|
ld hl, sFOO
|
|
|
|
ld de, 0x4000
|
2019-07-22 15:59:47 -04:00
|
|
|
call symRegisterGlobal
|
2019-05-17 13:14:16 -04:00
|
|
|
jp nz, fail
|
|
|
|
ld hl, sBAR
|
|
|
|
ld de, 0x20
|
2019-07-22 15:59:47 -04:00
|
|
|
call symRegisterGlobal
|
2019-05-17 13:14:16 -04:00
|
|
|
jp nz, fail
|
|
|
|
|
2019-12-29 15:39:39 -05:00
|
|
|
call testParseExpr
|
2019-12-29 16:15:48 -05:00
|
|
|
call testSPOnFail
|
2019-05-18 15:17:56 -04:00
|
|
|
|
2019-05-17 13:14:16 -04:00
|
|
|
; success
|
|
|
|
xor a
|
|
|
|
halt
|
|
|
|
|
2019-11-22 15:03:16 -05:00
|
|
|
testParseExpr:
|
2019-12-29 11:42:18 -05:00
|
|
|
ld hl, .alltests
|
|
|
|
ld ix, .test
|
|
|
|
jp testList
|
2019-11-22 15:03:16 -05:00
|
|
|
|
2019-12-29 11:42:18 -05:00
|
|
|
.test:
|
|
|
|
push hl \ pop iy
|
2019-11-22 15:03:16 -05:00
|
|
|
inc hl \ inc hl
|
2019-12-23 19:13:44 -05:00
|
|
|
call parseExpr
|
2019-12-23 15:41:25 -05:00
|
|
|
call assertZ
|
|
|
|
ld l, (iy)
|
|
|
|
ld h, (iy+1)
|
2019-12-29 11:42:18 -05:00
|
|
|
jp assertEQW
|
2019-11-22 15:03:16 -05:00
|
|
|
|
|
|
|
.t1:
|
|
|
|
.dw 7
|
|
|
|
.db "42/6", 0
|
|
|
|
.t2:
|
|
|
|
.dw 1
|
|
|
|
.db "7%3", 0
|
2019-11-22 17:16:51 -05:00
|
|
|
.t3:
|
|
|
|
.dw 0x0907
|
|
|
|
.db "0x99f7&0x0f0f", 0
|
|
|
|
.t4:
|
|
|
|
.dw 0x9fff
|
|
|
|
.db "0x99f7|0x0f0f", 0
|
|
|
|
.t5:
|
|
|
|
.dw 0x96f8
|
|
|
|
.db "0x99f7^0x0f0f", 0
|
2019-11-22 18:35:10 -05:00
|
|
|
.t6:
|
|
|
|
.dw 0x133e
|
|
|
|
.db "0x99f7}3", 0
|
|
|
|
.t7:
|
|
|
|
.dw 0xcfb8
|
|
|
|
.db "0x99f7{3", 0
|
2019-11-23 14:56:23 -05:00
|
|
|
.t8:
|
|
|
|
.dw 0xffff
|
|
|
|
.db "-1", 0
|
2019-12-23 15:41:25 -05:00
|
|
|
.t9:
|
|
|
|
.dw 10
|
|
|
|
.db "2*3+4", 0
|
2019-12-29 11:42:18 -05:00
|
|
|
|
|
|
|
; There was this untested regression during the replacement of find-and-subst
|
|
|
|
; parseExpr to the recursive descent one. It was time consuming to find. Here
|
|
|
|
; it goes, here it stays.
|
|
|
|
.t10:
|
|
|
|
.dw '-'+1
|
|
|
|
.db "'-'+1", 0
|
|
|
|
|
2019-12-29 15:39:39 -05:00
|
|
|
.t11:
|
|
|
|
.dw 0x4023
|
|
|
|
.db "0x4001+0x22", 0
|
|
|
|
|
|
|
|
.t12:
|
|
|
|
.dw 0x4020
|
|
|
|
.db "FOO+BAR", 0
|
|
|
|
|
|
|
|
.t13:
|
|
|
|
.dw 0x60
|
|
|
|
.db "BAR*3", 0
|
|
|
|
|
|
|
|
.t14:
|
|
|
|
.dw 0x3ffd
|
|
|
|
.db "FOO-3", 0
|
|
|
|
|
|
|
|
.t15:
|
|
|
|
.dw 0x4080
|
|
|
|
.db "FOO+BAR*4", 0
|
|
|
|
|
2019-12-30 19:24:53 -05:00
|
|
|
; "0" is a special case, let's test it
|
|
|
|
.t16:
|
|
|
|
.dw 0
|
|
|
|
.db "0", 0
|
|
|
|
|
|
|
|
; Another one that caused troubles
|
|
|
|
.t17:
|
|
|
|
.dw 123
|
|
|
|
.db "0+123", 0
|
|
|
|
|
2019-12-29 11:42:18 -05:00
|
|
|
.alltests:
|
2019-12-29 15:39:39 -05:00
|
|
|
.dw .t1, .t2, .t3, .t4, .t5, .t6, .t7, .t8, .t9, .t10, .t11, .t12
|
2019-12-30 19:24:53 -05:00
|
|
|
.dw .t13, .t14, .t15, .t16, .t17, 0
|
2019-12-29 16:15:48 -05:00
|
|
|
|
|
|
|
; Ensure that stack is balanced on failure
|
|
|
|
testSPOnFail:
|
|
|
|
ld (testSP), sp
|
|
|
|
ld hl, .sFail
|
|
|
|
call parseExpr
|
|
|
|
call assertNZ
|
|
|
|
call assertSP
|
|
|
|
jp nexttest
|
|
|
|
|
|
|
|
.sFail: .db "1+abc123", 0
|
|
|
|
|