~subsetpark/fugue

e28cd6b81fb1803951ee20eb4da944ab88d0f99f — Zach Smith 2 months ago 1f981a5
fold registry back in
3 files changed, 18 insertions(+), 15 deletions(-)

M fugue.janet
M project.janet
D registry.janet
M fugue.janet => fugue.janet +17 -3
@@ 1,4 1,18 @@
(import /registry)
#
# Compile-time field access
#

(def- proto-field-registry
  "Keep compile-time track of field definitions"
  @{})

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

(defn- registry-register
  [key value]
  (put proto-field-registry key value))

#
# Bootstrapping


@@ 43,7 57,7 @@
    (not (symbol? obj)) (fields obj)
    (dyn obj) (fields (eval obj))
    true (let [reg-key (string (dyn :current-file) "-" obj)]
           (or (registry/fields reg-key) @[]))))
           (or (registry-fields reg-key) @[]))))

#
# defproto Forms


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

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

M project.janet => project.janet +1 -1
@@ 67,4 67,4 @@ inheritable; a multimethod defined for an ancestor Prototype will not
be selected for any descendent prototype instances.```)

(declare-source
  :source ["fugue.janet" "registry.janet"])
  :source ["fugue.janet"])

D registry.janet => registry.janet +0 -11
@@ 1,11 0,0 @@
(def- proto-field-registry
  "Keep compile-time track of field definitions"
  @{})

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

(defn register
  [key value]
  (put proto-field-registry key value))