Login
7 branches 0 tags
Ben (Win10) Made release-wasm GH CI build depend on a successful linux build and test run 4389c19 3 years ago 741 Commits
nujel / stdlib / z_nos / nos.nuj
[defn dup [l]
      [case [type-of l]
            [:tree [tree/dup l]]
            [:array [array/dup l]]
            [otherwise l]]]


[defn make-instance [parent]
      [when [and [not [nil? parent]]
                 [not= [type-of parent] :tree]]
            [throw [list :type-error "Parents can only be trees or nil" parent [current-lambda]]]]
      [def ret @[]]
      [doseq [k [tree/keys parent]]
             [when [not= k :parent]
                   [def pv [tree/get parent k]]
                   [when-not [= [type-of pv] :lambda]
                             [tree/set! ret k [dup pv]]]]]
      [tree/set! ret :parent parent]]

[defn nos/funcall* [o method-name args]
      [if o
          [do [def v [tree/get o method-name]]
              [if v
                  [apply v args]
                  [nos/funcall* [tree/get o :parent] method-name args]]]
          [throw [list :missing-method "Can't find that method" o [current-lambda]]]]]

[defn nos/funcall [o method-name . args]
      [nos/funcall* o method-name [cons o args]]]


[defn nos/funcall*/try [o method-name args]
      [when o
            [def v [tree/get o method-name]]
            [if v
                [apply v args]
                [nos/funcall* [tree/get o :parent] method-name args]]]]

[defn nos/funcall/try [o method-name . args]
      [nos/funcall*/try o method-name [cons o args]]]


[defmacro defobject [parent]
          `[make-instance ~parent]]

[defmacro defproperty [o name val]
          `[tree/set! ~o ~name ~val]]

[defmacro defmethod [o name args . body]
          `[tree/set! ~o ~name [fn ~[cons 'this args] ~@body]]]

[defmacro _ [o name . args]
          `[nos/funcall ~o ~name ~@args]]