~subsetpark/fugue

5b29e62881f5a5f50143e6bce43ea0f420de4f27 — Zach Smith 5 months ago 7255aa6
Use nested dicts for compile time registry
1 files changed, 10 insertions(+), 9 deletions(-)

M fugue.janet
M fugue.janet => fugue.janet +10 -9
@@ 7,12 7,14 @@
  @{})

(defn- registry-fields
  [sym]
  (get-in proto-field-registry [sym]))
  [current-file name]
  (get-in proto-field-registry [current-file name]))

(defn- registry-register
  [key value]
  (put proto-field-registry key value))
  [current-file name value]
  (unless (in proto-field-registry current-file)
    (put proto-field-registry current-file @{}))
  (put-in proto-field-registry [current-file name] value))

#
# Bootstrapping


@@ 56,10 58,9 @@
  (cond
    (not (symbol? obj)) (fields obj)
    (dyn obj) (fields (eval obj))
    true (if-let [reg-key (string (dyn :current-file) "-" obj)
                  listing (registry-fields reg-key)]
           listing
           (maclintf :normal "no prototype definition found for %s" (string obj)))))
    (if-let [listing (registry-fields (dyn :current-file) obj)]
      listing
      (maclintf :normal "no prototype definition found for %s" (string obj)))))

#
# Field Validation


@@ 106,7 107,7 @@
                            :proto-allocations @{}
                            :instance-defaults @{}
                            :getters @{}}]
    (registry-register (string (dyn :current-file) "-" name) defined-fields)
    (registry-register (dyn :current-file) name defined-fields)

    (loop [entry :in fields
           :when (= 2 (length entry))