diff --git a/lib/string.fs b/lib/string.fs new file mode 100644 index 0000000..3fc1918 --- /dev/null +++ b/lib/string.fs @@ -0,0 +1,24 @@ +\ planckforth - +\ Copyright (C) 2021 nineties + +( === String === ) + +." HELLO " cr +private{ + +\ Heap-allocated string object +\ p: null terminated string +: make-string ( p -- str ) + dup strlen 1 + allocate throw tuck strcpy .s +; export + +: release-string ( str -- ) free ; export + +}private + +T{ s" AAAAA" make-string constant A -> }T +T{ s" BBBBBBB" make-string constant B -> }T +T{ A s" AAAAA" streq -> true }T +T{ B s" BBBBBBB" streq -> true }T +T{ A release-string -> }T +T{ B release-string -> }T diff --git a/lib/table.fs b/lib/table.fs index 8d1d1a6..9291e2b 100644 --- a/lib/table.fs +++ b/lib/table.fs @@ -220,8 +220,14 @@ T{ A table-values cdr cdr car -> 3 }T T{ A release-table -> }T T{ make-string-table constant A -> }T -T{ 0 s" zero" A table! -> }T -T{ 1 s" one" A table! -> }T +T{ s" zero" make-string constant ZERO -> }T +T{ s" one" make-string constant ONE -> }T +T{ 0 ZERO A table! -> }T +T{ 1 ONE A table! -> }T +T{ ZERO A table@ -> 0 }T +T{ ONE A table@ -> 1 }T T{ s" zero" A table@ -> 0 }T T{ s" one" A table@ -> 1 }T T{ A release-table -> }T +T{ ZERO release-string -> }T +T{ ONE release-string -> }T diff --git a/runtests.fs b/runtests.fs index 064c208..addc706 100644 --- a/runtests.fs +++ b/runtests.fs @@ -13,6 +13,7 @@ include test/utilities.fs include test/coreexttest.fs include test/export.fs +include lib/string.fs include lib/array.fs include lib/bitscan.fs include lib/table.fs