aboutsummaryrefslogtreecommitdiff
path: root/forth/types.fs
diff options
context:
space:
mode:
authorChouser <chouser@n01se.net>2015-02-21 18:50:50 -0500
committerChouser <chouser@n01se.net>2015-02-23 22:22:04 -0500
commit3a17cb968281f7e833088fdb22cf793861810912 (patch)
tree8758fc89cdc319a3615d12be26facea80d06cd86 /forth/types.fs
parent975126be58a92228e945730f9ff2337bfea41b9a (diff)
downloadmal-3a17cb968281f7e833088fdb22cf793861810912.tar.gz
mal-3a17cb968281f7e833088fdb22cf793861810912.zip
forth: Clean up symbol eval for better perf
Diffstat (limited to 'forth/types.fs')
-rw-r--r--forth/types.fs36
1 files changed, 15 insertions, 21 deletions
diff --git a/forth/types.fs b/forth/types.fs
index f5d067a..8d0e619 100644
--- a/forth/types.fs
+++ b/forth/types.fs
@@ -422,6 +422,17 @@ deftype MalMap
MalMap new MalList/Empty over MalMap/list ! constant MalMap/Empty
+: MalMap/get-addr ( k map -- addr-or-nil )
+ MalMap/list @
+ dup MalList/start @
+ swap MalList/count @ { k start count }
+ nil ( addr )
+ count cells start + start +do
+ i @ k m= if
+ drop i cell+ leave
+ endif
+ [ 2 cells ] literal +loop ;
+
MalMap
extend conj ( kv map -- map )
MalMap/list @ \ get list
@@ -447,22 +458,9 @@ MalMap
MalMap new dup -rot MalMap/list ! \ put back in map
endif
2 +loop ;;
- extend get { not-found k map -- value }
- map MalMap/list @
- dup MalList/start @ { start }
- MalList/count @ { count }
- 0
- begin
- dup count >= if
- drop not-found true
- else
- start over cells + @ k m= if
- start swap cells + cell+ @ true \ found it ( value true )
- else
- 2 + false
- endif
- endif
- until ;;
+ extend get ( not-found k map -- value )
+ MalMap/get-addr ( not-found addr-or-nil )
+ dup 0= if drop else nip @ endif ;;
extend empty?
MalMap/list @
MalList/count @ 0= mal-bool ;;
@@ -495,14 +493,12 @@ drop
MalType%
cell% field MalSymbol/sym-addr
cell% field MalSymbol/sym-len
- cell% field MalSymbol/meta
deftype MalSymbol
: MalSymbol. { str-addr str-len -- mal-sym }
MalSymbol new { sym }
str-addr sym MalSymbol/sym-addr !
- str-len sym MalSymbol/sym-len !
- MalMap/Empty sym MalSymbol/meta !
+ str-len sym MalSymbol/sym-len !
sym ;
: unpack-sym ( mal-string -- addr len )
@@ -574,13 +570,11 @@ drop
MalType%
cell% field MalNativeFn/xt
- cell% field MalNativeFn/meta
deftype MalNativeFn
: MalNativeFn. { xt -- mal-fn }
MalNativeFn new { mal-fn }
xt mal-fn MalNativeFn/xt !
- MalMap/Empty mal-fn MalNativeFn/meta !
mal-fn ;