mirror of
https://github.com/nineties/planckforth
synced 2024-12-25 21:58:22 +01:00
Add string-table
This commit is contained in:
parent
c8bf67c279
commit
bfd136f0ed
1 changed files with 19 additions and 1 deletions
20
lib/table.fs
20
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
|
||||
|
|
Loading…
Reference in a new issue