/
compiler.cljs
187 lines (149 loc) · 5.26 KB
/
compiler.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
(ns aerial.saite.compiler
(:require-macros
[aerial.saite.analyzer :refer [analyzer-state]])
(:require
[clojure.string :as cljstr]
[goog.string :as gstring]
[goog.string.format]
[cljs.tools.reader :refer [read-string]]
[cljs.env :as env]
[cljs.js :refer [empty-state eval js-eval eval-str require]]
[aerial.saite.savrest
:refer [update-ddb get-ddb]]
[aerial.hanami.core
:as hmi
:refer [printchan user-msg
re-com-xref xform-recom
default-header-fn start
get-vspec update-vspecs
get-tab-field add-tab update-tab-field
add-to-tab-body remove-from-tab-body
active-tabs
md vgl app-stop]]
[aerial.hanami.common
:as hc
:refer [RMV]]
[aerial.hanami.templates :as ht]
[re-com.core
:as rcm
:refer [h-box v-box box gap line h-split v-split scroller
button row-button md-icon-button md-circle-icon-button info-button
input-text input-password input-textarea
label title p
single-dropdown
checkbox radio-button slider progress-bar throbber
horizontal-bar-tabs vertical-bar-tabs
modal-panel popover-content-wrapper popover-anchor-wrapper]
:refer-macros [handler-fn]]
[re-com.box
:refer [flex-child-style]]
[re-com.dropdown
:refer [filter-choices-by-keyword single-dropdown-args-desc]]
))
(defn format [s & params]
(apply gstring/format s params))
(def state (cljs.js/empty-state))
#_(defn get-source-n-cache [{:keys [name macros path]}]
"Experimental - was for Andare core.async self hosted use. But
Andare does not work in the browser. So, this is no longer used"
(let [ch (as/chan)
chankey (keyword (gensym "chan-"))
res (volatile! nil)]
(update-ddb [:main :chans chankey] ch)
(hmi/send-msg {:op :cljs-require
:data {:uid (hmi/get-adb [:main :uid])
:chankey chankey
:path path}})
ch))
(defn loader-fn [info-map cb]
(printchan info-map)
#_(if (and (info-map :macros)
(re-find #"asyncxxx$" (info-map :path)))
(let [res (as/<! (get-source-n-cache info-map))
src (res :value)]
(printchan src)
(cb {:lang :clj :source src})))
(cb {:lang :js :source ""}))
(defn evaluate
([nssym source cb]
(if (string? source)
(let [source (cljstr/replace source #"hmi/" "aerial.hanami.core/")
source (cljstr/replace source #"hcm/" "aerial.hanami.common/")
source (cljstr/replace source #"htm/" "aerial.hanami.templates/")]
(cljs.js/eval-str state source nil
{:eval cljs.js/js-eval
:ns nssym
:load loader-fn
:context :expr}
cb))
(try
(cljs.js/eval state source
{:eval cljs.js/js-eval
:ns nssym
:context :expr}
cb)
(catch :default cause
(cb {:error (prn-str cause)})))))
([source cb]
(evaluate 'aerial.saite.compiler source cb)))
(def base-requires
"[clojure.string :as str]
[aerial.hanami.core :as hmi :refer [md]]
[aerial.hanami.common :as hc :refer [RMV]]
[aerial.hanami.templates :as ht]
[aerial.hanasu.common :refer [update-db get-db]]
[aerial.saite.compiler :refer [format]]
[aerial.saite.core :as sc :refer [read-data]]
[reagent.core :as rgt]
[re-com.core
:refer [h-box v-box box gap line h-split v-split scroller
button row-button md-icon-button md-circle-icon-button info-button
input-text input-password input-textarea
label title p
single-dropdown
checkbox radio-button slider progress-bar throbber
horizontal-bar-tabs vertical-bar-tabs
modal-panel popover-content-wrapper popover-anchor-wrapper]]
")
(defn add-requires [base requires]
(reduce (fn[R r]
(format (str R "\n %s") r))
base-requires requires))
(defn set-namespace
[nssym & {:keys [base requires cljrequires]
:or {base base-requires cljrequires []}}]
(evaluate
(format "(ns %s\n (:require\n %s))"
(name nssym)
(add-requires base requires))
println)
(hmi/send-msg
{:op :set-namespace
:data {:nssym nssym :requires cljrequires}}))
#_(ambient.main.core/analyzer-state 'aerial.hanami.core)
(defn load-analysis-cache! []
(cljs.js/load-analysis-cache!
state 'aerial.hanasu.common
(analyzer-state 'aerial.hanasu.common))
(cljs.js/load-analysis-cache!
state 'aerial.saite.compiler
(analyzer-state 'aerial.saite.compiler))
(cljs.js/load-analysis-cache!
state 're-com.core
(analyzer-state 're-com.core))
(cljs.js/load-analysis-cache!
state 'aerial.saite.core
(analyzer-state 'aerial.saite.core))
(cljs.js/load-analysis-cache!
state 'aerial.hanami.core
(analyzer-state 'aerial.hanami.core))
(cljs.js/load-analysis-cache!
state 'aerial.hanami.templates
(analyzer-state 'aerial.hanami.templates))
(cljs.js/load-analysis-cache!
state 'aerial.hanami.common
(analyzer-state 'aerial.hanami.common))
:done)
(def expr* (atom nil))
(defn expr*! [x] (reset! expr* x))
(load-analysis-cache!)