~subsetpark/fugue

66db931c9f7d2286105d9ee4058a87c3a5a97308 — Zach Smith 3 years ago da7ef6a
minor reorder
1 files changed, 27 insertions(+), 19 deletions(-)

M fugue.janet
M fugue.janet => fugue.janet +27 -19
@@ 71,6 71,31 @@
           (compiler-warn (string "no prototype definition found for " obj)))))

#
# Field Validation
#

(defn- validate-field
  [field fields]
  (unless fields
    (errorf "Field validation for `%s` failed; no fields registered" (string field)))
  (unless (index-of field fields)
    (errorf "Field `%s` not found; got fields: %q" (string field) fields)))

(defn- validate-proto-match
  [name attrs]
  (let [fields (comp-aware-fields name)]
    (loop [k :keys attrs]
      (validate-field k fields))))

(defn- warn-proto-method-shadow
  [name proto]
  (when (index-of (keyword name) (comp-aware-fields proto))
    (compiler-warn
      (string/format "you are defining a method named %s on the prototype %s; there is a field of the same name on that prototype."
                     (string name)
                     (string proto)))))

#
# defproto Forms
#



@@ 425,11 450,7 @@
  - `__super` - Bound to the method at `name` within `__parent`.
  ```
  [name proto args & body]
  (when (index-of (keyword name) (comp-aware-fields proto))
    (compiler-warn
      (string/format "you are defining a method named %s on the prototype %s; there is a field of the same name on that prototype."
                     (string name)
                     (string proto))))
  (warn-proto-method-shadow name proto)
  (upscope
    (let [current-binding (dyn name)]
      @[(unless (and current-binding (function? (current-binding :value)))


@@ 787,13 808,6 @@
  [proto obj as & body]
  (do-with-slots-as proto obj as body))

(defn- validate-field
  [field fields]
  (unless fields
    (errorf "Field validation for `%s` failed; no fields registered" (string field)))
  (unless (index-of field fields)
    (errorf "Field `%s` not found; got fields: %q" (string field) fields)))

(defmacro @
  ```
  Compile-time Prototype field checking.


@@ 820,12 834,6 @@
         (errorf "Expected a %s, got: %q" ,(string proto) (,get-type-or-proto ,obj))
         ,(tuple obj field)))))

(defn- validate-proto-match
  [name attrs]
  (let [fields (comp-aware-fields name)]
    (loop [k :keys attrs]
      (validate-field k fields))))

(def- root-match match)

(defmacro match


@@ 848,7 856,7 @@

       pattern)
     exp])
  

  (let [oddlen (odd? (length cases))
        else (if oddlen (last cases))
        patterns (partition 2 (if oddlen (slice cases 0 -2) cases))