Add lib/string.fs

This commit is contained in:
Koichi Nakamura 2021-12-04 20:53:33 +09:00
parent a28cbc259f
commit ebda933859
3 changed files with 33 additions and 2 deletions

24
lib/string.fs Normal file
View file

@ -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

View file

@ -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

View file

@ -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