From bfd136f0ed150a7377031c83a29ed387d52349d4 Mon Sep 17 00:00:00 2001 From: Koichi Nakamura Date: Sat, 4 Dec 2021 20:26:36 +0900 Subject: [PATCH] Add string-table --- lib/table.fs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/table.fs b/lib/table.fs index fb8e3a9..8d1d1a6 100644 --- a/lib/table.fs +++ b/lib/table.fs @@ -171,12 +171,23 @@ end-struct entry% : hash-int ( n -- n ) 0 hash-next -; export +; : make-int-table ( -- tbl ) ['] hash-int ['] = make-table ; export +: hash-string ( s -- n ) + 0 begin over c@ dup while + hash-next + swap 1+ swap + repeat drop nip +; + +: make-string-table ( -- tbl ) + ['] hash-string ['] streq make-table +; export + }private T{ make-int-table constant A -> }T @@ -207,3 +218,10 @@ T{ A table-values car -> 1 }T T{ A table-values cdr car -> 2 }T 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" A table@ -> 0 }T +T{ s" one" A table@ -> 1 }T +T{ A release-table -> }T