diff --git a/ueforth/Makefile b/ueforth/Makefile index 64ee200..9334fd5 100644 --- a/ueforth/Makefile +++ b/ueforth/Makefile @@ -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 diff --git a/ueforth/common/core.h b/ueforth/common/core.h index 8f2f7e3..98f8e45 100644 --- a/ueforth/common/core.h +++ b/ueforth/common/core.h @@ -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; diff --git a/ueforth/common/core_test.fs b/ueforth/common/core_test.fs new file mode 100644 index 0000000..53cea48 --- /dev/null +++ b/ueforth/common/core_test.fs @@ -0,0 +1,3 @@ +: test 100 0 do i . loop cr ; +test +bye diff --git a/ueforth/common/core_test.fs.golden b/ueforth/common/core_test.fs.golden new file mode 100644 index 0000000..ab3093d --- /dev/null +++ b/ueforth/common/core_test.fs.golden @@ -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 diff --git a/ueforth/posix/posix.fs b/ueforth/posix/posix.fs index 4877a39..dbeb009 100644 --- a/ueforth/posix/posix.fs +++ b/ueforth/posix/posix.fs @@ -107,4 +107,20 @@ octal 777 constant 0777 decimal : rename-file ( a n a n -- ior ) s>z -rot s>z swap rename 0r write r> = 0ior ; +: file-position ( fh -- n ior ) dup 0 SEEK_CUR lseek 0r + dup 0 SEEK_END lseek r> swap >r + SEEK_SET lseek drop r> 0r >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 ;