Permalink
Browse files

:replumb or :core

  • Loading branch information...
viebel committed Oct 18, 2016
1 parent d6ad87e commit 7a8717dfbbecab2b2103b63ff2e28d4235c20805
Showing with 15 additions and 10 deletions.
  1. +13 −6 src/klipse/compiler.cljs
  2. +2 −4 test/cljs/test/runner.cljs
View
@@ -3,7 +3,7 @@
[gadjett.core :as gadjett :refer [deftrack dbg]]
[purnam.core :refer [!]]
[cljs.core.async.macros :refer [go go-loop]])
(:require
(:require
gadjett.core-fn
cljsjs.codemirror.mode.clojure
[cljs.reader :refer [read-string]]
@@ -17,6 +17,10 @@
[cljs.js :as cljs]))
(def ^{:dynamic true
:doc "The compiler to use. It could be either :core or :replumb"}
*compiler-name* :replumb)
;; =============================================================================
;; Compiler functions
@@ -45,7 +49,7 @@
(defn read-result [{:keys [form warning error value success?]}]
(let [status (if error :error :ok)
res (if success?
res (if-not error
value
error)]
[status res]))
@@ -87,6 +91,9 @@
#(put! c (convert-compile-res %)))
c))
(defmulti core-eval (fn [& args]
*compiler-name*))
(defn build-repl-opts [{:keys [static-fns context external-libs verbose]}]
(merge (replumb/options :browser (partial io/load-ns external-libs))
{:warning-as-error false
@@ -95,25 +102,25 @@
:no-pr-str-on-value true
:context (or context :statement)}))
(defn core-eval-replumb [s {:keys [static-fns context verbose external-libs] :or {static-fns false context nil external-libs nil}} cb]
(defmethod core-eval :replumb [s {:keys [static-fns context verbose external-libs] :or {static-fns false context nil external-libs nil}} cb]
(let [opts (build-repl-opts {:static-fns static-fns
:external-libs external-libs
:verbose verbose
:context (keyword context)})]
(! js/window.COMPILED true); for some reason it is required with read-eval-call
(replumb/read-eval-call opts cb s)))
(defn my-eval [{:keys [file source file lang name path cache] :as args}]
(cljs/js-eval args))
(defn core-eval [s {:keys [static-fns context external-libs verbose] :or {static-fns false context nil external-libs nil}} cb]
(defmethod core-eval :core [s {:keys [static-fns context external-libs verbose] :or {static-fns false context nil external-libs nil}} cb]
; we have to set `env/*compiler*` because `binding` and core.async don't play well together (https://www.reddit.com/r/Clojure/comments/4wrjw5/withredefs_doesnt_play_well_with_coreasync/) and the code of `eval-str` uses `binding` of `env/*compiler*`.
(set! env/*compiler* (create-state-eval))
(cljs/eval-str (create-state-eval)
s
"my.klipse" {:eval my-eval
:def-emits-var true
:verbose verbose
:*compiler* (set! env/*compiler* (create-state-eval))
:context (keyword context)
:static-fns static-fns
:load (partial io/load-ns external-libs)}
@@ -2,9 +2,7 @@
(:require
[doo.runner :refer-macros [doo-tests]]
[klipse.cards.test.eval]
[klipse.cards.test.compile]
))
[klipse.cards.test.compile]))
(doo-tests 'klipse.cards.test.eval
'klipse.cards.test.compile)

0 comments on commit 7a8717d

Please sign in to comment.