sci
This commit is contained in:
parent
2c8b575df9
commit
0839c9a429
2 changed files with 70 additions and 68 deletions
2
sci
2
sci
|
|
@ -1 +1 @@
|
||||||
Subproject commit 2ad0fe12fb8fb264f34b03ee758c8eeea3a5ca2b
|
Subproject commit 0df767971f6c412aef39a7c29a3537176908e875
|
||||||
|
|
@ -27,8 +27,6 @@
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[sci.addons :as addons]
|
[sci.addons :as addons]
|
||||||
[sci.core :as sci]
|
[sci.core :as sci]
|
||||||
[sci.impl.interpreter :refer [eval-string*]]
|
|
||||||
[sci.impl.opts :as sci-opts]
|
|
||||||
[sci.impl.unrestrict :refer [*unrestricted*]]
|
[sci.impl.unrestrict :refer [*unrestricted*]]
|
||||||
[sci.impl.vars :as vars])
|
[sci.impl.vars :as vars])
|
||||||
(:gen-class))
|
(:gen-class))
|
||||||
|
|
@ -284,12 +282,15 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
|
||||||
|
|
||||||
(def reflection-var (sci/new-dynamic-var '*warn-on-reflection* false))
|
(def reflection-var (sci/new-dynamic-var '*warn-on-reflection* false))
|
||||||
|
|
||||||
(defn load-file* [sci-ctx f]
|
(def load-file*
|
||||||
(let [f (io/file f)
|
(with-meta
|
||||||
s (slurp f)]
|
(fn [sci-ctx f]
|
||||||
(sci/with-bindings {sci/ns @sci/ns
|
(let [f (io/file f)
|
||||||
sci/file (.getCanonicalPath f)}
|
s (slurp f)]
|
||||||
(eval-string* sci-ctx s))))
|
(sci/with-bindings {sci/ns @sci/ns
|
||||||
|
sci/file (.getCanonicalPath f)}
|
||||||
|
(sci/eval-string* sci-ctx s))))
|
||||||
|
{:sci.impl/op :needs-ctx}))
|
||||||
|
|
||||||
(defn start-socket-repl! [address ctx]
|
(defn start-socket-repl! [address ctx]
|
||||||
(socket-repl/start-repl! address ctx)
|
(socket-repl/start-repl! address ctx)
|
||||||
|
|
@ -379,6 +380,36 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
|
||||||
(flush)
|
(flush)
|
||||||
[nil 1])))))
|
[nil 1])))))
|
||||||
|
|
||||||
|
(def imports
|
||||||
|
'{ArithmeticException java.lang.ArithmeticException
|
||||||
|
AssertionError java.lang.AssertionError
|
||||||
|
BigDecimal java.math.BigDecimal
|
||||||
|
Boolean java.lang.Boolean
|
||||||
|
Byte java.lang.Byte
|
||||||
|
Character java.lang.Character
|
||||||
|
Class java.lang.Class
|
||||||
|
ClassNotFoundException java.lang.ClassNotFoundException
|
||||||
|
Double java.lang.Double
|
||||||
|
Exception java.lang.Exception
|
||||||
|
IllegalArgumentException java.lang.IllegalArgumentException
|
||||||
|
Integer java.lang.Integer
|
||||||
|
File java.io.File
|
||||||
|
Long java.lang.Long
|
||||||
|
Math java.lang.Math
|
||||||
|
NumberFormatException java.lang.NumberFormatException
|
||||||
|
Object java.lang.Object
|
||||||
|
Runtime java.lang.Runtime
|
||||||
|
RuntimeException java.lang.RuntimeException
|
||||||
|
Process java.lang.Process
|
||||||
|
ProcessBuilder java.lang.ProcessBuilder
|
||||||
|
String java.lang.String
|
||||||
|
StringBuilder java.lang.StringBuilder
|
||||||
|
System java.lang.System
|
||||||
|
Thread java.lang.Thread
|
||||||
|
Throwable java.lang.Throwable})
|
||||||
|
|
||||||
|
(def input-var (sci/new-dynamic-var '*input* nil))
|
||||||
|
|
||||||
(defn main
|
(defn main
|
||||||
[& args]
|
[& args]
|
||||||
(handle-pipe!)
|
(handle-pipe!)
|
||||||
|
|
@ -419,64 +450,35 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
|
||||||
(when uberscript (swap! uberscript-sources conj (:source res)))
|
(when uberscript (swap! uberscript-sources conj (:source res)))
|
||||||
res)))
|
res)))
|
||||||
_ (when file (vars/bindRoot sci/file (.getCanonicalPath (io/file file))))
|
_ (when file (vars/bindRoot sci/file (.getCanonicalPath (io/file file))))
|
||||||
ctx {:aliases aliases
|
;; TODO: pull more of these values to compile time
|
||||||
:namespaces (-> namespaces
|
opts {:aliases aliases
|
||||||
(assoc 'clojure.core
|
:namespaces (-> namespaces
|
||||||
(assoc core-extras
|
(assoc 'clojure.core
|
||||||
'*command-line-args*
|
(assoc core-extras
|
||||||
(sci/new-dynamic-var '*command-line-args* command-line-args)
|
'*command-line-args*
|
||||||
'*warn-on-reflection* reflection-var))
|
(sci/new-dynamic-var '*command-line-args* command-line-args)
|
||||||
(assoc-in ['clojure.java.io 'resource]
|
'*warn-on-reflection* reflection-var
|
||||||
#(when-let [{:keys [:loader]} @cp-state] (cp/getResource loader % {:url? true}))))
|
'load-file load-file*))
|
||||||
:bindings bindings
|
(assoc-in ['clojure.java.io 'resource]
|
||||||
:env env
|
#(when-let [{:keys [:loader]} @cp-state] (cp/getResource loader % {:url? true})))
|
||||||
:features #{:bb :clj}
|
(assoc-in ['user (with-meta '*input*
|
||||||
:classes classes/class-map
|
(when-not stream?
|
||||||
:imports '{ArithmeticException java.lang.ArithmeticException
|
{:sci.impl/deref! true}))] input-var)
|
||||||
AssertionError java.lang.AssertionError
|
(assoc-in ['clojure.main 'repl]
|
||||||
BigDecimal java.math.BigDecimal
|
^{:sci.impl/op :needs-ctx}
|
||||||
Boolean java.lang.Boolean
|
(fn [ctx & opts]
|
||||||
Byte java.lang.Byte
|
(let [opts (apply hash-map opts)]
|
||||||
Character java.lang.Character
|
(repl/start-repl! ctx opts)))))
|
||||||
Class java.lang.Class
|
:bindings bindings
|
||||||
ClassNotFoundException java.lang.ClassNotFoundException
|
:env env
|
||||||
Double java.lang.Double
|
:features #{:bb :clj}
|
||||||
Exception java.lang.Exception
|
:classes classes/class-map
|
||||||
IllegalArgumentException java.lang.IllegalArgumentException
|
:imports imports
|
||||||
Integer java.lang.Integer
|
:load-fn load-fn
|
||||||
File java.io.File
|
:dry-run uberscript}
|
||||||
Long java.lang.Long
|
opts (addons/future opts)
|
||||||
Math java.lang.Math
|
sci-ctx (sci/init opts)
|
||||||
NumberFormatException java.lang.NumberFormatException
|
|
||||||
Object java.lang.Object
|
|
||||||
Runtime java.lang.Runtime
|
|
||||||
RuntimeException java.lang.RuntimeException
|
|
||||||
Process java.lang.Process
|
|
||||||
ProcessBuilder java.lang.ProcessBuilder
|
|
||||||
String java.lang.String
|
|
||||||
StringBuilder java.lang.StringBuilder
|
|
||||||
System java.lang.System
|
|
||||||
Thread java.lang.Thread
|
|
||||||
Throwable java.lang.Throwable}
|
|
||||||
:load-fn load-fn
|
|
||||||
:dry-run uberscript}
|
|
||||||
ctx (addons/future ctx)
|
|
||||||
sci-ctx (sci-opts/init ctx)
|
|
||||||
_ (vreset! common/ctx sci-ctx)
|
_ (vreset! common/ctx sci-ctx)
|
||||||
input-var (sci/new-dynamic-var '*input* nil)
|
|
||||||
_ (swap! (:env sci-ctx)
|
|
||||||
(fn [env]
|
|
||||||
(update env :namespaces
|
|
||||||
(fn [namespaces] [:namespaces 'clojure.main 'repl]
|
|
||||||
(-> namespaces
|
|
||||||
(assoc-in ['clojure.core 'load-file] #(load-file* sci-ctx %))
|
|
||||||
(assoc-in ['clojure.main 'repl]
|
|
||||||
(fn [& opts]
|
|
||||||
(let [opts (apply hash-map opts)]
|
|
||||||
(repl/start-repl! sci-ctx opts))))
|
|
||||||
(assoc-in ['user (with-meta '*input*
|
|
||||||
(when-not stream?
|
|
||||||
{:sci.impl/deref! true}))] input-var))))))
|
|
||||||
preloads (some-> (System/getenv "BABASHKA_PRELOADS") (str/trim))
|
preloads (some-> (System/getenv "BABASHKA_PRELOADS") (str/trim))
|
||||||
[expressions exit-code]
|
[expressions exit-code]
|
||||||
(cond expressions [expressions nil]
|
(cond expressions [expressions nil]
|
||||||
|
|
@ -491,7 +493,7 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
|
||||||
(if exit-code exit-code
|
(if exit-code exit-code
|
||||||
(do (when preloads
|
(do (when preloads
|
||||||
(try
|
(try
|
||||||
(eval-string* sci-ctx preloads)
|
(sci/eval-string* sci-ctx preloads)
|
||||||
(catch Throwable e
|
(catch Throwable e
|
||||||
(error-handler* e verbose?))))
|
(error-handler* e verbose?))))
|
||||||
nil))
|
nil))
|
||||||
|
|
@ -515,7 +517,7 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
|
||||||
[nil 0] ;; done streaming
|
[nil 0] ;; done streaming
|
||||||
(let [res [(let [res
|
(let [res [(let [res
|
||||||
(sci/binding [input-var in]
|
(sci/binding [input-var in]
|
||||||
(eval-string* sci-ctx expression))]
|
(sci/eval-string* sci-ctx expression))]
|
||||||
(when (some? res)
|
(when (some? res)
|
||||||
(if-let [pr-f (cond shell-out println
|
(if-let [pr-f (cond shell-out println
|
||||||
edn-out prn)]
|
edn-out prn)]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue