Added tests.
This commit is contained in:
@ -6,7 +6,14 @@ TARGETS = out/web/terminal.html \
|
|||||||
out/posix/ueforth \
|
out/posix/ueforth \
|
||||||
out/arduino/ueforth.ino
|
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:
|
out/gen:
|
||||||
mkdir -p out/gen
|
mkdir -p out/gen
|
||||||
|
|||||||
@ -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
|
*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) {
|
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);
|
*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);
|
cell_t len = g_sys.tin - (*ret - (cell_t) g_sys.tib);
|
||||||
if (g_sys.tin < g_sys.ntib) { ++g_sys.tin; }
|
if (g_sys.tin < g_sys.ntib) { ++g_sys.tin; }
|
||||||
return len;
|
return len;
|
||||||
|
|||||||
3
ueforth/common/core_test.fs
Normal file
3
ueforth/common/core_test.fs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
: test 100 0 do i . loop cr ;
|
||||||
|
test
|
||||||
|
bye
|
||||||
4
ueforth/common/core_test.fs.golden
Normal file
4
ueforth/common/core_test.fs.golden
Normal 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
|
||||||
@ -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 ;
|
: 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 ;
|
: read-file ( a n fh -- n ior ) -rot read 0<ior ;
|
||||||
: write-file ( a n fh -- ior ) -rot dup >r write r> = 0ior ;
|
: 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 ;
|
||||||
|
|||||||
Reference in New Issue
Block a user