From a12b154a03b9c468fa3135f8cff57dc31400e349 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Fri, 5 Feb 2021 21:27:52 -0800 Subject: [PATCH] Adding .s --- ueforth/Makefile | 8 +++++--- ueforth/common/all_tests.fs | 2 ++ ueforth/common/testing.fs | 4 ++-- ueforth/common/utils.fs | 5 +++++ ueforth/common/utils_tests.fs | 15 +++++++++++++++ 5 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 ueforth/common/utils.fs create mode 100644 ueforth/common/utils_tests.fs diff --git a/ueforth/Makefile b/ueforth/Makefile index f03e1d9..d2d16ac 100644 --- a/ueforth/Makefile +++ b/ueforth/Makefile @@ -116,20 +116,22 @@ $(GEN): POSIX_BOOT = common/boot.fs common/ansi.fs \ posix/posix.fs posix/posix_highlevel.fs \ common/highlevel.fs common/filetools.fs posix/posix_desktop.fs \ - common/tasks.fs common/streams.fs common/blocks.fs posix/args.fs + common/tasks.fs common/streams.fs common/blocks.fs posix/args.fs \ + common/utils.fs $(GEN)/posix_boot.h: common/source_to_string.js $(POSIX_BOOT) | $(GEN) echo "ok" | cat $(POSIX_BOOT) - | $< boot >$@ WINDOWS_BOOT = common/boot.fs common/ansi.fs \ windows/windows.fs windows/windows_highlevel.fs common/highlevel.fs \ - common/tasks.fs common/streams.fs common/blocks.fs + common/tasks.fs common/streams.fs common/blocks.fs \ + common/utils.fs $(GEN)/windows_boot.h: common/source_to_string.js $(WINDOWS_BOOT) | $(GEN) echo "ok" | cat $(WINDOWS_BOOT) - | $< boot >$@ ARDUINO_BOOT = common/boot.fs arduino/arduino.fs \ posix/posix_highlevel.fs common/highlevel.fs common/filetools.fs \ common/tasks.fs common/streams.fs arduino/arduino_server.fs \ - arduino/esp_camera.fs common/blocks.fs \ + arduino/esp_camera.fs common/blocks.fs common/utils.fs \ arduino/autoboot.fs $(GEN)/arduino_boot.h: common/source_to_string.js $(ARDUINO_BOOT) | $(GEN) echo "ok" | cat $(ARDUINO_BOOT) - | $< boot >$@ diff --git a/ueforth/common/all_tests.fs b/ueforth/common/all_tests.fs index 3a355e7..8e4bdb9 100644 --- a/ueforth/common/all_tests.fs +++ b/ueforth/common/all_tests.fs @@ -1,3 +1,5 @@ include common/testing.fs +include common/utils.fs include common/base_tests.fs +include common/utils_tests.fs run-tests diff --git a/ueforth/common/testing.fs b/ueforth/common/testing.fs index 2b9f657..bbc972a 100644 --- a/ueforth/common/testing.fs +++ b/ueforth/common/testing.fs @@ -32,7 +32,7 @@ variable confirm-old-type : }confirm confirm-old-type @ is type ; : expect-reset 0 expect-used ! 0 result-used ! ; : expect-finish expected resulted str= if exit then }confirm - ." Expected:" cr expected type cr ." Resulted:" cr resulted type cr 1 throw ; + cr ." Expected:" cr expected type cr ." Resulted:" cr resulted type cr 1 throw ; ( Testing Framework ) ( run-tests runs all words starting with "test-", use assert to assert things. ) @@ -42,7 +42,7 @@ variable tests-found variable tests-run variable tests-passed last @ begin dup while dup test? if 2dup >r >r swap execute r> r> then >link repeat 2drop ; : reset-test-counters 0 tests-found ! 0 tests-run ! 0 tests-passed ! ; : count-test ( xt -- ) drop 1 tests-found +! ; -: check-fresh depth if ." DEPTH LEAK! " depth . 1 throw then ; +: check-fresh depth if }confirm ." DEPTH LEAK! " depth . 1 throw then ; : wrap-test ( xt -- ) expect-reset >r check-fresh r> execute check-fresh expect-finish ; : red 1 fg ; : green 2 fg ; : hr 40 for [char] - emit next cr ; : replace-line 13 emit clear-to-eol ; diff --git a/ueforth/common/utils.fs b/ueforth/common/utils.fs new file mode 100644 index 0000000..9bb1fdc --- /dev/null +++ b/ueforth/common/utils.fs @@ -0,0 +1,5 @@ +( Variable useful but non-critical words ) + +: .s ." <" depth <# #s #> type ." > " + depth 0 max for aft sp@ r@ cells - @ . then next cr ; + diff --git a/ueforth/common/utils_tests.fs b/ueforth/common/utils_tests.fs new file mode 100644 index 0000000..461f94b --- /dev/null +++ b/ueforth/common/utils_tests.fs @@ -0,0 +1,15 @@ +( Tests of utils.fs ) +e: test-.s0 + .s + out: <0> +;e + +e: test-.s + 1 2 3 .s + out: <3> 1 2 3 + 128 .s + out: <4> 1 2 3 128 + 2drop 2drop + .s + out: <0> +;e