~subsetpark/fugue

90368535a815784c89a0438c712c6ff018bd2dbf — Zach Smith 26 days ago 00156d6
Minor refactor
2 files changed, 20 insertions(+), 7 deletions(-)

M fugue.janet
A registry.janet
M fugue.janet => fugue.janet +9 -7
@@ 1,3 1,5 @@
(import /registry)

#
# Bootstrapping
#


@@ 18,6 20,10 @@
    (bare-proto "Prototype" [])
    (put :_init identity)))

#
# Field Access
#

(defn fields
  ```
  Return all the defined fields for `obj` and its prototype


@@ 30,10 36,6 @@
        obj-fields (or (get-in obj [:_meta :fields]) @[])]
    (array ;proto-fields ;obj-fields)))

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

(defn- comp-aware-fields
  "Fields checks, even when the proto is not available yet"
  [obj]


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

#
# defproto Forms
#


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

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

A registry.janet => registry.janet +11 -0
@@ 0,0 1,11 @@
(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))