duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit 172dd9e56276d99a87564cba560ac177ff4c1eb6
parent 236275936e41bd0ec6ffe576ad8a799bd9c868da
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Fri,  3 Jun 2022 08:59:20 -0400

Add tests as well as a new str.fs library

Diffstat:
MMakefile | 4++++
Mdusk.asm | 14+++++++++++++-
Afs/str.fs | 17+++++++++++++++++
Aruntests.sh | 12++++++++++++
Atests/harness.fs | 6++++++
Atests/teststr.fs | 12++++++++++++
6 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile @@ -14,6 +14,10 @@ dusk: xcomp.asm boot.fs run: dusk stty -icanon -echo; ./dusk ; stty icanon echo +.PHONY: test +test: dusk + ./runtests.sh + .PHONY: clean clean: rm -f $(TARGETS) dusk.o xcomp.asm diff --git a/dusk.asm b/dusk.asm @@ -100,6 +100,7 @@ jz %$if SECTION .bss areg: resd 1 ; A register toflag: resb 1 ; to flag +exitonabort: resb 1 ; if set, abort will exit(1) current: resd 1 here: resd 1 compiling: resd 1 @@ -123,6 +124,7 @@ SECTION .text GLOBAL _start _start: + mov byte [exitonabort], 0 mov dword [here], herestart mov dword [current], word_lastxcomp mov dword [inptr], bootsrc @@ -150,10 +152,20 @@ defword 'quit', 4, word_quit, word_noop jmp word_mainloop defword 'abort', 5, word_abort, word_quit + test byte [exitonabort], -1 + jz _abort_no_exit + mov eax, SYSCALL_EXIT + mov ebx, 1 + int 0x80 +_abort_no_exit: mov ebp, ps_top jmp word_quit -defword 'exit', 4, word_exit, word_abort +defword 'exitonabort', 11, word_exitonabort, word_abort + mov byte [exitonabort], 1 + ret + +defword 'exit', 4, word_exit, word_exitonabort pop eax ret diff --git a/fs/str.fs b/fs/str.fs @@ -0,0 +1,17 @@ +\ String utilities +\ All string utilies operate on an "active string", which we set with ">s" + +0 value sa +0 value sl + +: >s ( sa sl -- ) to sl to sa ; +: s> ( -- sa sl ) sa sl ; + +\ find active string in "list" and return its index, -1 if not found. +\ A list is a simple sequence of strings (length byte, then contents, then +\ another one...) ended by a 0 length +: sfind ( list -- idx ) -1 swap begin ( idx a ) + swap 1+ swap c@+ ( idx sa sl ) + ?dup not if 2drop -1 exit then ( idx sa sl ) + 2dup + rot> ( idx nexta sa sl ) s> S= until ( idx a ) + drop ( a ) ; diff --git a/runtests.sh b/runtests.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +for fn in tests/test*; do + if echo "bye" | cat tests/harness.fs $fn - | ./dusk; then + echo + echo "all tests passed" + else + echo + echo "tests failed" + fi +done + diff --git a/tests/harness.fs b/tests/harness.fs @@ -0,0 +1,6 @@ +exitonabort + +\ # means "assert" +: # ( f -- ) not if abort" assertion failed" then ; +: #eq ( n n -- ) = # ; + diff --git a/tests/teststr.fs b/tests/teststr.fs @@ -0,0 +1,12 @@ +\ Tests for str.fs +f<< str.fs + +create list + 5 c, ," hello" + 3 c, ," foo" + 3 c, ," bar" + 0 c, + +: _ S" foo" >s list sfind 1 #eq ; _ +: _ S" hello" >s list sfind 0 #eq ; _ +: _ S" baz" >s list sfind -1 #eq ; _