Skip to content

Commit

Permalink
version 3.2.0\n fix simple compilation\n fast loading of namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
viebel committed Oct 16, 2016
1 parent 26408d0 commit f6a4ffa
Show file tree
Hide file tree
Showing 15 changed files with 261 additions and 133 deletions.
6 changes: 0 additions & 6 deletions cache-src/core.cljs

This file was deleted.

16 changes: 3 additions & 13 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
(defproject klipse "3.1.7"
(defproject klipse "3.2.0"
:description "Cljs compiler in cljs"
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.9.229"]
[org.clojure/core.async "0.2.385"]
[binaryage/devtools "0.8.2"]
[im.chit/purnam "0.5.2"]
[cljsjs/markdown "0.6.0-beta1-0"]
[org.clojure/core.match "0.3.0-alpha4"]
[cljs-http "0.1.41"]
[viebel/gadjett "0.2.1"]
[org.omcljs/om "1.0.0-alpha41"]
Expand All @@ -33,7 +32,7 @@
:output-to "resources/private/test/klipse.testable.js"
:output-dir "resources/private/test"
:verbose false
:optimizations :whitespace }}
:optimizations :simple}}
:app {
:source-paths ["src/klipse/run/app" "resources/public/lib"]
:compiler {
Expand All @@ -44,7 +43,7 @@
:optimize-constants true
:static-fns true
;:elide-asserts true
:optimizations :whitespace
:optimizations :simple
:verbose false}}
:plugin {
:source-paths ["src/klipse/run/plugin" "resources/public/lib"]
Expand All @@ -68,15 +67,6 @@
:elide-asserts false
:optimizations :advanced
:verbose true}}
:cache {
:source-paths ["cache-src"]
:compiler {;:main "klipse.run.all"
:asset-path "cache/js"
:output-to "resources/public/cache/js/klipse.cache.js"
:output-dir "resources/public/cache/js"
:verbose true
:optimizations :none
}}
:figwheel {
:figwheel true
:source-paths ["src"]
Expand Down
2 changes: 1 addition & 1 deletion resources/public/index-dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</div>
<div id="compiler" style="height: 100%;"></div>
<script async defer id="github-bjs" src="https://buttons.github.io/buttons.js"></script>
<script src="dev/js/klipse.js?version=3.1.7"></script>
<script src="dev/js/klipse.js?version=3.2.0"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
Expand Down
10 changes: 8 additions & 2 deletions resources/public/playground-dbg.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
<body>
<pre><code class="clojure">
(map inc [1 2 3])
</code></pre>
</code></pre>

<pre><code class="clojure">
(ns my.test
(:require
[cljs.pprint :as pp :refer [pprint]]))
(with-out-str (pprint (for [x (range 10)] (range x))))
</code></pre>
<pre><code class="clojure" data-external-libs="https://raw.githubusercontent.com/viebel/math.combinatorics/master/src/main/clojure">
(ns my.combinatorics
(:require [clojure.math.combinatorics :refer [permutations]]))
Expand All @@ -21,7 +27,7 @@

<pre><code class="clojure" data-gist-id="viebel/820f672dd176169fd831c7748e6f3cd3" data-external-libs="https://raw.githubusercontent.com/mfikes/andare/master/src/main/clojure/">
</code></pre>
<pre><code class="clojure" data-external-libs="https://raw.githubusercontent.com/clojure/test.check/master/src/main/clojure">
<pre><code class="clojure" data-external-libs="https://raw.githubusercontent.com/clojure/test.check/ebcc57dd631e25ee39bc059899e3bbd9ddf24ee9/src/main/clojure">
(ns my.test (:require [clojure.test.check :as tc]
[clojure.test.check.generators :as gen]
[clojure.test.check.properties :as prop :include-macros true]))
Expand Down
85 changes: 85 additions & 0 deletions resources/public/require-dbg.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>KLIPSE: a simple and elegant online cljs compiler and evaluator</title>
<link rel='shortcut icon' type='image/x-icon' href='img/klipse.png' />
<link rel="stylesheet" type="text/css" href="css/codemirror.css">
</head>
<body>
<pre><code class="clojure">
(map inc [1 2 3])
</code></pre>

<pre><code class="clojure">
(ns my.test
(:require
[cljs.pprint :as pp :refer [pprint]]))
(with-out-str (pprint (for [x (range 10)] (range x))))
</code></pre>
<pre><code class="clojure" data-external-libs="https://raw.githubusercontent.com/viebel/math.combinatorics/master/src/main/clojure">
(ns my.combinatorics
(:require [clojure.math.combinatorics :refer [permutations]]))

(permutations [1 2 3])
</code></pre>


<pre><code class="clojure" data-gist-id="viebel/820f672dd176169fd831c7748e6f3cd3" data-external-libs="https://raw.githubusercontent.com/mfikes/andare/master/src/main/clojure/">
</code></pre>
<pre><code class="clojure" data-external-libs="https://raw.githubusercontent.com/clojure/test.check/ebcc57dd631e25ee39bc059899e3bbd9ddf24ee9/src/main/clojure">
(ns my.test (:require [clojure.test.check :as tc]
[clojure.test.check.generators :as gen]
[clojure.test.check.properties :as prop :include-macros true]))
(def sort-idempotent-prop
(prop/for-all [v (gen/vector gen/int)]
(= (sort v) (sort (sort v)))))

(tc/quick-check 100 sort-idempotent-prop)

</code></pre>
<pre><code class="clojure">
(ns my.spec
(:require [clojure.spec :as s]))

(s/def ::a integer?)
(s/conform ::a 12)
</code></pre>
<pre><code class="clojure">
(ns my.cljs
(:require [cljs.js :as cljs :refer [eval-str]]))

(eval-str (cljs.js/empty-state) "(+ 1 2)" 'cljs.me {:eval cljs.js/js-eval} identity)


</code></pre>

<pre><code class="clojure">
(ns my.walk
(:require [clojure.walk :refer [postwalk]]))
(postwalk identity {:a 1})
</code></pre>

<pre><code class="clojure">
(ns my.ns
(:require [clojure.string :as string :refer [lower-case]]))
(lower-case "AbsCs")
</code></pre>

<script>
window.klipse_settings = {
codemirror_options_in: {
lineWrapping: true,
lineNumbers: true,
autoCloseBrackets: true
},
codemirror_options_out: {
lineWrapping: true
},
selector: '.clojure'
};
</script>
<script src="lib/mirror_extensions.js"></script>
<script src="fig/js/klipse.fig.js"></script>
</body>
</html>
84 changes: 84 additions & 0 deletions resources/public/require-dev.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>KLIPSE: a simple and elegant online cljs compiler and evaluator</title>
<link rel='shortcut icon' type='image/x-icon' href='img/klipse.png' />
<link rel="stylesheet" type="text/css" href="css/codemirror.css">
</head>
<body>
<pre><code class="clojure">
(map inc [1 2 3])
</code></pre>

<pre><code class="clojure">
(ns my.test
(:require
[cljs.pprint :as pp :refer [pprint]]))
(with-out-str (pprint (for [x (range 10)] (range x))))
</code></pre>
<pre><code class="clojure" data-external-libs="https://raw.githubusercontent.com/viebel/math.combinatorics/master/src/main/clojure">
(ns my.combinatorics
(:require [clojure.math.combinatorics :refer [permutations]]))

(permutations [1 2 3])
</code></pre>


<pre><code class="clojure" data-gist-id="viebel/820f672dd176169fd831c7748e6f3cd3" data-external-libs="https://raw.githubusercontent.com/mfikes/andare/master/src/main/clojure/">
</code></pre>
<pre><code class="clojure" data-external-libs="https://raw.githubusercontent.com/clojure/test.check/ebcc57dd631e25ee39bc059899e3bbd9ddf24ee9/src/main/clojure">
(ns my.test (:require [clojure.test.check :as tc]
[clojure.test.check.generators :as gen]
[clojure.test.check.properties :as prop :include-macros true]))
(def sort-idempotent-prop
(prop/for-all [v (gen/vector gen/int)]
(= (sort v) (sort (sort v)))))

(tc/quick-check 100 sort-idempotent-prop)

</code></pre>
<pre><code class="clojure">
(ns my.spec
(:require [clojure.spec :as s]))

(s/def ::a integer?)
(s/conform ::a 12)
</code></pre>
<pre><code class="clojure">
(ns my.cljs
(:require [cljs.js :as cljs :refer [eval-str]]))

(eval-str (cljs.js/empty-state) "(+ 1 2)" 'cljs.me {:eval cljs.js/js-eval} identity)


</code></pre>

<pre><code class="clojure">
(ns my.walk
(:require [clojure.walk :refer [postwalk]]))
(postwalk identity {:a 1})
</code></pre>

<pre><code class="clojure">
(ns my.ns
(:require [clojure.string :as string :refer [lower-case]]))
(lower-case "AbsCs")
</code></pre>

<script>
window.klipse_settings = {
codemirror_options_in: {
lineWrapping: true,
lineNumbers: true,
autoCloseBrackets: true
},
codemirror_options_out: {
lineWrapping: true
},
selector: '.clojure'
};
</script>
<script src="plugin/js/klipse_plugin.js"></script>
</body>
</html>
53 changes: 23 additions & 30 deletions src/klipse/compiler.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns klipse.compiler
(:require-macros
[cljs.core.match :refer [match]]
[gadjett.core :as gadjett :refer [deftrack dbg]]
[purnam.core :refer [!]]
[cljs.core.async.macros :refer [go go-loop]])
(:require
gadjett.core-fn
Expand All @@ -25,13 +25,8 @@
(js* "window.cljs.user = {}")


(defn load-inlined [opts cb]
(cb {:lang :js :source ""}))

(defn special-fetch [file-url src-cb]
(-> (s/replace file-url #"gist_" "")
(io/fetch-file! src-cb)))

(def create-state-eval (memoize cljs/empty-state))
(def create-state-compile (memoize cljs/empty-state))

(defn display [value {:keys [print-length beautify-strings]}]
(with-redefs [*print-length* print-length]
Expand Down Expand Up @@ -69,49 +64,49 @@
(advanced-compile value))]
[status res]))

(deftrack compile [s {:keys [static-fns] :or {static-fns false}}]
(cljs/compile-str (cljs/empty-state) s
(deftrack compile [s {:keys [static-fns external-libs] :or {static-fns false external-libs nil}}]
(cljs/compile-str (create-state-compile) s
"cljs-in"
{
:static-fns static-fns
:load load-inlined
:load (partial io/load-ns external-libs)
}
convert-compile-res))

(deftrack compile-async [s {:keys [static-fns] :or {static-fns false}}]
(deftrack compile-async [s {:keys [static-fns external-libs] :or {static-fns false external-libs nil}}]
(let [c (chan)]
(cljs/compile-str (cljs/empty-state) s
(cljs/compile-str (create-state-compile) s
"cljs-in"
{
:static-fns static-fns
:load load-inlined
}
:load (partial io/load-ns external-libs)}
#(put! c (convert-compile-res %)))
c))

(defn build-repl-opts [{:keys [static-fns context external-libs]}]
(merge (replumb/options :browser #_(repos external-libs) (partial io/load-ns external-libs))
(merge (replumb/options :browser (partial io/load-ns external-libs))
{:warning-as-error false
:static-fns static-fns
:no-pr-str-on-value true
:context (or context :statement)
:verbose false}))

(defn core-eval [s {:keys [static-fns context external-libs] :or {static-fns false context nil external-libs '()}} cb]
(defn core-eval [s {:keys [static-fns context 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
:context (keyword context)})]
(set! js/COMPILED true)
(! js/window.COMPILED true); for some reason it is required with read-eval-call
(replumb/read-eval-call opts cb s)))

(def create-state (memoize cljs/empty-state))

(defn core-eval-clj [s {:keys [static-fns context external-libs] :or {static-fns false context nil external-libs '()}} cb]
(let [st (create-state)]
(cljs/eval-str st s "my.klipse" {:eval cljs/js-eval
:context (keyword context)
:static-fns static-fns
:load (partial io/load-ns external-libs)} cb)))
(defn core-eval-clj [s {:keys [static-fns context external-libs] :or {static-fns false context nil external-libs nil}} cb]
(cljs/eval-str (create-state-eval)
s
"my.klipse" {:eval cljs/js-eval
:context (keyword context)
:static-fns static-fns
:load (partial io/load-ns external-libs)}
cb))

(deftrack eval-async-1 [s {:keys [print-length] :as opts}]
(let [c (chan)]
Expand All @@ -137,9 +132,10 @@
second
str))

(defn str-compile-async [exp {:keys [static-fns] :or {static-fns false}}]
(defn str-compile-async [exp {:keys [static-fns external-libs] :or {static-fns false external-libs nil}}]
(go
(-> (<! (compile-async exp {:static-fns static-fns}))
(-> (<! (compile-async exp {:static-fns static-fns
:external-libs external-libs}))
second
str)))

Expand All @@ -160,9 +156,6 @@
(-> (<! (eval-async exp opts))
second)))

(defn eval-file [url]
(io/fetch-file! url (comp print eval)))

(def eval-opts {:editor-in-mode "clojure"
:editor-out-mode "clojure"
:eval-fn str-eval-async
Expand Down
2 changes: 1 addition & 1 deletion src/klipse/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
(enable-console-print!)
(gadjett/settings! :max-function-calls 100)

(def version "3.1.7")
(def version "3.2.0")
(js/console.info "KLIPSE version:" version)

1 change: 0 additions & 1 deletion src/klipse/cpp.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
[cljs.core.async.macros :refer [go go-loop]])
(:require
cljsjs.codemirror.mode.clike
[klipse.io :as io]
[klipse.utils :refer [runonce]]
[cljs.core.async :refer [chan <! >! put!]]
[klipse.plugin :refer [register-mode]]))
Expand Down
Loading

0 comments on commit f6a4ffa

Please sign in to comment.