Added tests.

This commit is contained in:
Brad Nelson
2021-01-03 21:56:22 -08:00
parent 0dc6719cc1
commit c7371911ed
5 changed files with 39 additions and 3 deletions

View File

@ -6,7 +6,14 @@ TARGETS = out/web/terminal.html \
out/posix/ueforth \
out/arduino/ueforth.ino
all: $(TARGETS)
all: $(TARGETS) tests
tests: core_test
core_test: out/posix/ueforth common/core_test.fs \
common/core_test.fs.golden
echo "include common/core_test.fs" | $< | \
diff - common/core_test.fs.golden
out/gen:
mkdir -p out/gen

View File

@ -65,10 +65,16 @@ static void create(const char *name, cell_t length, cell_t flags, void *op) {
*g_sys.heap++ = (cell_t) op; // code
}
static char spacefilter(char ch) {
return ch == '\t' || ch == '\n' || ch == '\r' ? ' ' : ch;
}
static cell_t parse(cell_t sep, cell_t *ret) {
while (g_sys.tin < g_sys.ntib && g_sys.tib[g_sys.tin] == sep) { ++g_sys.tin; }
while (g_sys.tin < g_sys.ntib &&
spacefilter(g_sys.tib[g_sys.tin]) == sep) { ++g_sys.tin; }
*ret = (cell_t) (g_sys.tib + g_sys.tin);
while (g_sys.tin < g_sys.ntib && g_sys.tib[g_sys.tin] != sep) { ++g_sys.tin; }
while (g_sys.tin < g_sys.ntib &&
spacefilter(g_sys.tib[g_sys.tin]) != sep) { ++g_sys.tin; }
cell_t len = g_sys.tin - (*ret - (cell_t) g_sys.tib);
if (g_sys.tin < g_sys.ntib) { ++g_sys.tin; }
return len;

View File

@ -0,0 +1,3 @@
: test 100 0 do i . loop cr ;
test
bye

View File

@ -0,0 +1,4 @@
uEForth
ok
39
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

View File

@ -107,4 +107,20 @@ octal 777 constant 0777 decimal
: rename-file ( a n a n -- ior ) s>z -rot s>z swap rename 0<ior ;
: read-file ( a n fh -- n ior ) -rot read 0<ior ;
: write-file ( a n fh -- ior ) -rot dup >r write r> = 0ior ;
: file-position ( fh -- n ior ) dup 0 SEEK_CUR lseek 0<ior ;
: file-size ( fh -- n ior )
dup 0 SEEK_CUR lseek >r
dup 0 SEEK_END lseek r> swap >r
SEEK_SET lseek drop r> 0<ior ;
( Including Files )
: included ( a n -- )
r/o open-file throw
dup file-size throw
dup allocate throw
swap 2dup >r >r
rot dup >r read-file throw drop
r> close-file throw
r> r> over >r dup . cr evaluate
r> free throw ;
: include ( "name" -- ) bl parse included ;