collapseos/tools/tests/unit/test_expr.asm
Virgil Dupras 019d05f64c Make the shell a userspace app
That's my mega-commit you've all been waiting for.

The code for the shell share more routines with userspace apps than with kernel
units, because, well, its behavior is that of a userspace app, not a device
driver.

This created a weird situation with libraries and jump tables. Some routine
belonging to the `kernel/` directory felt weird there.

And then comes `apps/basic`, which will likely share even more code with the
shell. I was seeing myself creating huge jump tables to reuse code from the
shell. It didn't feel right.

Moreover, we'll probably want basic-like apps to optionnally replace the shell.

So here I am with this huge change in the project structure. I didn't test all
recipes on hardware yet, I will do later. I might have broken some...

But now, the structure feels better and the line between what belongs to
`kernel` and what belongs to `apps` feels clearer.
2019-11-15 15:37:49 -05:00

142 lines
1.8 KiB
NASM

.equ RAMSTART 0x4000
.equ ZASM_REG_MAXCNT 0xff
.equ ZASM_LREG_MAXCNT 0x40
.equ ZASM_REG_BUFSZ 0x1000
.equ ZASM_LREG_BUFSZ 0x200
; declare DIREC_LASTVAL manually so that we don't have to include directive.asm
.equ DIREC_LASTVAL RAMSTART
jp test
.inc "core.asm"
.inc "str.asm"
.inc "lib/util.asm"
.inc "zasm/util.asm"
.inc "zasm/const.asm"
.inc "lib/parse.asm"
.inc "zasm/parse.asm"
.equ SYM_RAMSTART DIREC_LASTVAL+2
.inc "zasm/symbol.asm"
.inc "zasm/expr.asm"
; Pretend that we aren't in first pass
zasmIsFirstPass:
jp unsetZ
zasmGetPC:
ret
testNum: .db 1
s1: .db "2+2", 0
s2: .db "0x4001+0x22", 0
s3: .db "FOO+BAR", 0
s4: .db "BAR*3", 0
s5: .db "FOO-3", 0
s6: .db "FOO+BAR*4", 0
sFOO: .db "FOO", 0
sBAR: .db "BAR", 0
test:
ld hl, 0xffff
ld sp, hl
ld hl, s1
call parseExpr
jp nz, fail
push ix \ pop hl
ld a, h
or a
jp nz, fail
ld a, l
cp 4
jp nz, fail
call nexttest
ld hl, s2
call parseExpr
jp nz, fail
push ix \ pop hl
ld a, h
cp 0x40
jp nz, fail
ld a, l
cp 0x23
jp nz, fail
call nexttest
; before the next test, let's set up FOO and BAR symbols
call symInit
ld hl, sFOO
ld de, 0x4000
call symRegisterGlobal
jp nz, fail
ld hl, sBAR
ld de, 0x20
call symRegisterGlobal
jp nz, fail
ld hl, s3
call parseExpr
jp nz, fail
push ix \ pop hl
ld a, h
cp 0x40
jp nz, fail
ld a, l
cp 0x20
jp nz, fail
call nexttest
ld hl, s4
call parseExpr
jp nz, fail
push ix \ pop hl
ld a, h
or a
jp nz, fail
ld a, l
cp 0x60
jp nz, fail
call nexttest
ld hl, s5
call parseExpr
jp nz, fail
push ix \ pop hl
ld a, h
cp 0x3f
jp nz, fail
ld a, l
cp 0xfd
jp nz, fail
call nexttest
ld hl, s6
call parseExpr
jp nz, fail
push ix \ pop hl
ld a, h
cp 0x40
jp nz, fail
ld a, l
cp 0x80
jp nz, fail
call nexttest
; success
xor a
halt
nexttest:
ld a, (testNum)
inc a
ld (testNum), a
ret
fail:
ld a, (testNum)
halt