|
24 | 24 | [clojure.math.combinatorics :as combo]
|
25 | 25 | [clojure.pprint :as pprint :refer [pprint pp]]
|
26 | 26 | [clojure.set :as set]
|
| 27 | + [clojure.spec.alpha] |
27 | 28 | [clojure.string :as s]
|
28 | 29 | [clojure.test :refer [deftest testing is are]]
|
29 | 30 | [clojure.test.check :as check]
|
|
221 | 222 | (def custom-var-impls (atom {}))
|
222 | 223 | (defmacro custom-var! [v val] `(swap! custom-var-impls assoc ~v ~val))
|
223 | 224 |
|
224 |
| -(declare evaluator) |
| 225 | +(custom-var! #'clojure.core/load-reader |
| 226 | + (fn [rdr] |
| 227 | + (with-open [rdr (new java.io.PushbackReader rdr)] |
| 228 | + (->> (repeatedly #(read {:eof ::eof} rdr)) |
| 229 | + (take-while (partial not= ::eof)) |
| 230 | + (map (@custom-var-impls #'clojure.core/eval)) |
| 231 | + (last))))) |
| 232 | + |
225 | 233 | (custom-var! #'clojure.core/load-file
|
226 | 234 | (fn [fname]
|
227 | 235 | (binding [*file* (io/file fname)]
|
228 |
| - (with-open [in (new java.io.PushbackReader (io/reader *file*))] |
229 |
| - (doseq [read (repeatedly #(read {:eof ::eof} in)) |
230 |
| - :while (not= ::eof read)] |
231 |
| - (evaluator read)))))) |
| 236 | + (with-open [rdr (new java.io.PushbackReader (io/reader *file*))] |
| 237 | + ((@custom-var-impls #'clojure.core/load-reader) rdr))))) |
| 238 | + |
| 239 | +(custom-var! #'clojure.core/load |
| 240 | + (fn [& bodies] (throw (new RuntimeException "UCLJ does not yet support clojure.core/load!"))) |
| 241 | + #_(fn [& paths] |
| 242 | + (doseq [^String path paths] |
| 243 | + (let [root-resource (fn [lib] (str \/ (.. (name lib) (replace \- \_) (replace \. \/)))) |
| 244 | + root-directory (fn [lib] (let [d (root-resource lib)] (subs d 0 (.lastIndexOf (str d) "/")))) |
| 245 | + ^String path (if (.startsWith path "/") |
| 246 | + path |
| 247 | + (str (root-directory (ns-name *ns*)) \/ path)) |
| 248 | + res (or (io/resource (str path ".clj")) (io/resource (str path ".cljc")))] |
| 249 | + (assert res "No resource found!") |
| 250 | + ((@custom-var-impls #'clojure.core/load-reader) (io/reader res)))))) |
| 251 | + |
| 252 | +(custom-var! #'clojure.core/compile |
| 253 | + (fn [_] (throw (new RuntimeException "UCLJ does not support clojure.core/compile!")))) |
| 254 | + |
| 255 | +(custom-var! #'clojure.core/load-string |
| 256 | + (fn [s] ((@custom-var-impls #'clojure.core/load-reader) (java.io.StringReader. s)))) |
232 | 257 |
|
233 | 258 | ;; Due to the closed-world assumption, we cannot instantiate array of any types.
|
234 | 259 | (custom-var! #'clojure.core/into-array
|
|
0 commit comments