Sci: reify core vars, implement repl/doc (#265)
This commit is contained in:
parent
018371d90c
commit
e98a92c283
5 changed files with 169 additions and 162 deletions
2
sci
2
sci
|
|
@ -1 +1 @@
|
|||
Subproject commit 0fdb743ad833d74fb86bed1ae2eacaa9d883f652
|
||||
Subproject commit 57209f08d18ee168dbc1dca26e60b4958add3c0c
|
||||
|
|
@ -5,7 +5,7 @@ set -eo pipefail
|
|||
export BABASHKA_CLASSPATH=$(clojure -Sdeps '{:deps {spartan.spec {:git/url "https://github.com/borkdude/spartan.spec" :sha "16f7eec4b6589c77c96c9fcf989f78fffcee7c4c"}}}' -Spath)
|
||||
|
||||
./bb -e "
|
||||
(require '[spartan.spec :as s])
|
||||
(s/explain (s/cat :i int? :s string?) [1 :foo])
|
||||
(s/conform (s/cat :i int? :s string?) [1 \"foo\"])
|
||||
(time (require '[spartan.spec :as s]))
|
||||
(time (s/explain (s/cat :i int? :s string?) [1 :foo]))
|
||||
(time (s/conform (s/cat :i int? :s string?) [1 \"foo\"]))
|
||||
"
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
(sio/println "Use :repl/quit or :repl/exit to quit the REPL.")
|
||||
(sio/println "Clojure rocks, Bash reaches.")
|
||||
(sio/println)
|
||||
(eval-form sci-ctx '(require '[clojure.repl :refer [dir]]))))
|
||||
(eval-form sci-ctx '(require '[clojure.repl :refer [dir doc]]))))
|
||||
:read (or read
|
||||
(fn [_request-prompt request-exit]
|
||||
;; (prn "PEEK" @sci/in (r/peek-char @sci/in))
|
||||
|
|
|
|||
|
|
@ -25,12 +25,14 @@
|
|||
[sci.core :as sci]
|
||||
[sci.impl.interpreter :refer [eval-string*]]
|
||||
[sci.impl.opts :as sci-opts]
|
||||
[sci.impl.vars :as vars])
|
||||
[sci.impl.vars :as vars]
|
||||
[sci.impl.unrestrict :refer [*unrestricted*]])
|
||||
(:gen-class))
|
||||
|
||||
(sci/alter-var-root sci/in (constantly *in*))
|
||||
(sci/alter-var-root sci/out (constantly *out*))
|
||||
(sci/alter-var-root sci/err (constantly *err*))
|
||||
(binding [*unrestricted* true]
|
||||
(sci/alter-var-root sci/in (constantly *in*))
|
||||
(sci/alter-var-root sci/out (constantly *out*))
|
||||
(sci/alter-var-root sci/err (constantly *err*)))
|
||||
|
||||
(set! *warn-on-reflection* true)
|
||||
;; To detect problems when generating the image, run:
|
||||
|
|
@ -217,10 +219,6 @@ Everything after that is bound to *command-line-args*."))
|
|||
(defn exit [n]
|
||||
(throw (ex-info "" {:bb/exit-code n})))
|
||||
|
||||
;; (sci/set-var-root! sci/*in* *in*)
|
||||
;; (sci/set-var-root! sci/*out* *out*)
|
||||
;; (sci/set-var-root! sci/*err* *err*)
|
||||
|
||||
(def aliases
|
||||
'{tools.cli 'clojure.tools.cli
|
||||
edn clojure.edn
|
||||
|
|
@ -283,8 +281,9 @@ Everything after that is bound to *command-line-args*."))
|
|||
(handle-pipe!)
|
||||
#_(binding [*out* *err*]
|
||||
(prn "M" (meta (get bindings 'future))))
|
||||
(sci/with-bindings {reflection-var false
|
||||
vars/current-ns (vars/->SciNamespace 'user)}
|
||||
(binding [*unrestricted* true]
|
||||
(sci/binding [reflection-var false
|
||||
vars/current-ns (vars/->SciNamespace 'user)]
|
||||
(let [t0 (System/currentTimeMillis)
|
||||
{:keys [:version :shell-in :edn-in :shell-out :edn-out
|
||||
:help? :file :command-line-args
|
||||
|
|
@ -431,7 +430,7 @@ Everything after that is bound to *command-line-args*."))
|
|||
(spit uberscript-out expression :append true)))
|
||||
(when time? (binding [*out* *err*]
|
||||
(println "bb took" (str (- t1 t0) "ms."))))
|
||||
exit-code)))
|
||||
exit-code))))
|
||||
|
||||
(defn -main
|
||||
[& args]
|
||||
|
|
|
|||
|
|
@ -342,6 +342,14 @@
|
|||
(is (empty? (bb nil "--uberscript" (.getPath tmp-file) "-e" "(System/exit 1)")))
|
||||
(is (= "(System/exit 1)" (slurp tmp-file)))))
|
||||
|
||||
(deftest unrestricted-access
|
||||
(testing "babashka is allowed to mess with built-in vars"
|
||||
(is (= 1 (bb nil "
|
||||
(def inc2 inc) (alter-var-root #'clojure.core/inc (constantly dec))
|
||||
(let [res (inc 2)]
|
||||
(alter-var-root #'clojure.core/inc (constantly inc2))
|
||||
res)")))))
|
||||
|
||||
;;;; Scratch
|
||||
|
||||
(comment
|
||||
|
|
|
|||
Loading…
Reference in a new issue