Take the "wh" out of whactormaps.
WeakMaps are NOT ITERABLE in JavaScript for security/GC reasons!!! I don't know what to do about this long-term but for now I'm just going to use a regular hashtable so I can keep making progress on the game!
This commit is contained in:
parent
13b7d93a34
commit
de7078ef85
2 changed files with 10 additions and 6 deletions
|
@ -130,11 +130,11 @@ Type: Any -> Boolean"
|
|||
|
||||
(define (whactormap-ref am key)
|
||||
(define wht (whactormap-data-wht (actormap-data am)))
|
||||
(weak-key-hashtable-ref wht key #f))
|
||||
(hashtable-ref wht key #f))
|
||||
|
||||
(define (whactormap-set! am key val)
|
||||
(define wht (whactormap-data-wht (actormap-data am)))
|
||||
(weak-key-hashtable-set! wht key val))
|
||||
(hashtable-set! wht key val))
|
||||
|
||||
(define whactormap-metatype
|
||||
(make-actormap-metatype 'whactormap whactormap-ref whactormap-set!))
|
||||
|
|
|
@ -403,6 +403,10 @@
|
|||
;; Weak-hash actormaps
|
||||
;; ===================
|
||||
|
||||
;; UH OH: You cannot iterate JS WeakMaps. This breaks
|
||||
;; copy-whactormap. So, I switched to using a regular hash table for
|
||||
;; this game jam. Need more time to think about how to solve this
|
||||
;; problem...
|
||||
|
||||
(define* (make-whactormap #:key [vat-connector #f])
|
||||
"Create and return a reference to a weak-hash actormap. If provided,
|
||||
|
@ -410,7 +414,7 @@ VAT-CONNECTOR is the syscaller of the containing vat.
|
|||
|
||||
Type: (Optional Syscaller) -> WHActormap"
|
||||
(_make-actormap whactormap-metatype
|
||||
(make-whactormap-data (make-weak-key-hashtable))
|
||||
(make-whactormap-data (make-eq-hashtable))
|
||||
vat-connector))
|
||||
|
||||
;; TODO: again, confusing (see <actormap>)
|
||||
|
@ -419,10 +423,10 @@ Type: (Optional Syscaller) -> WHActormap"
|
|||
(define (copy-whactormap am)
|
||||
"Copy whactormap AM to a new whactormap with the same contents."
|
||||
(define old-ht (whactormap-data-wht (actormap-data am)))
|
||||
(define new-ht (make-weak-key-hashtable))
|
||||
(define new-ht (make-eq-hashtable))
|
||||
;; Update new-ht with all of old-ht's values
|
||||
(hashtable-for-each (lambda (key val)
|
||||
(weak-key-hashtable-set! new-ht key val))
|
||||
(hashtable-set! new-ht key val))
|
||||
old-ht)
|
||||
;; Return newly made whactormap
|
||||
(_make-actormap whactormap-metatype
|
||||
|
@ -482,7 +486,7 @@ Type: TransActormap -> Void"
|
|||
(unless (transactormap-data-merged? tm-data)
|
||||
(hashtable-for-each
|
||||
(lambda (key val)
|
||||
(weak-key-hashtable-set! root-wht key val))
|
||||
(hashtable-set! root-wht key val))
|
||||
(transactormap-data-delta tm-data))
|
||||
(set-transactormap-data-merged?! tm-data #t))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue