From de7078ef857cb6f910edae72e9a417182f94d947 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 18 May 2024 18:47:58 -0400 Subject: [PATCH] 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! --- modules/goblins/core-types.scm | 4 ++-- modules/goblins/core.scm | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/goblins/core-types.scm b/modules/goblins/core-types.scm index fde9e2a..713c328 100644 --- a/modules/goblins/core-types.scm +++ b/modules/goblins/core-types.scm @@ -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!)) diff --git a/modules/goblins/core.scm b/modules/goblins/core.scm index 6d80350..ce65149 100644 --- a/modules/goblins/core.scm +++ b/modules/goblins/core.scm @@ -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 ) @@ -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))