~subsetpark/fugue

4579ccbbb855157017fa8169f34bc6d7f2affad7 — Zach Smith 2 years ago e9a6948 v0.4.0
Remove upscope
2 files changed, 18 insertions(+), 20 deletions(-)

M fugue.janet
M test/fugue.janet
M fugue.janet => fugue.janet +14 -15
@@ 453,21 453,20 @@
  ```
  [name proto args & body]
  (warn-proto-method-shadow name proto)
  (upscope
    (let [current-binding (dyn name)]
      @[(unless (and current-binding (function? (current-binding :value)))
          (maclintf :strict "Defining generic function for method %s ..." (string name))
          (defgeneric* name nil args raise-sentinel))

        (let [method-name (keyword name)
              full-method-name (symbol proto "-" name)]
          ~(,put ,proto
                 ,method-name
                 (fn ,full-method-name
                   ,args
                   (let [__parent (table/getproto ,proto)
                         __super (__parent ,method-name)]
                     ,;body))))])))
  (let [current-binding (dyn name)]
    @[(unless (and current-binding (function? (current-binding :value)))
        (maclintf :strict "Defining generic function for method %s ..." (string name))
        (defgeneric* name nil args raise-sentinel))

      (let [method-name (keyword name)
            full-method-name (symbol proto "-" name)]
        ~(,put ,proto
               ,method-name
               (fn ,full-method-name
                 ,args
                 (let [__parent (table/getproto ,proto)
                       __super (__parent ,method-name)]
                   ,;body))))]))

#
# Multimethod Helpers

M test/fugue.janet => test/fugue.janet +4 -5
@@ 13,11 13,10 @@
  (is (= fugue/Root (table/getproto proto))))

(defmacro- inst-tests [proto inst]
  (upscope
    @[~(is ,(symbol proto "?") ,inst)
      ~(is ,(symbol proto "*?") ,inst)
      ~(is (not (fugue/prototype? ,inst)))
      ~(is (= ,proto (table/getproto ,inst)))]))
  @[~(is ,(symbol proto "?") ,inst)
    ~(is ,(symbol proto "*?") ,inst)
    ~(is (not (fugue/prototype? ,inst)))
    ~(is (= ,proto (table/getproto ,inst)))])

(defmacro- accessor-tests [accessor objs &opt refute]
  ~(each obj ,objs (is (,(if refute not= =) (,accessor obj) (obj ,(keyword accessor))))))