This commit is contained in:
crumbtoo
2024-04-25 14:28:57 -06:00
parent 6f5c7ee284
commit 5876afec40
8 changed files with 518 additions and 43 deletions

View File

@@ -1,31 +1,28 @@
(ns main
(:require
["react-ace$default" :as AceEditor]
["ace-builds/src-noconflict/mode-haskell"]
["ace-builds/src-noconflict/theme-solarized_light"]
["ace-builds/src-noconflict/keybinding-vim"]
[ui :as ui]
[wscljs.client :as ws]
[wscljs.format :as fmt]
[clojure.string :as str]
[cljs.core.match :refer-macros [match]]))
[cljs.core.match :refer-macros [match]]
[reagent.dom :as rdom]))
(defn display-errors [es]
(doseq [{{e :contents} :diagnostic} es]
(let [fmte (map #(str " • " % "\n") e)]
(js/console.warn (apply str "message from rlpc:\n" fmte)))))
;------------------------------------------------------------------------------;
(def *rlp-socket nil)
;------------------------------------------------------------------------------;
(defn on-message [e]
(let [r (js->clj (js/JSON.parse (.-data e)) :keywordize-keys true)]
(match r
{:tag "Evaluated" :contents c}
(prn c)
(reset! ui/current-evaluation c)
:else
(js/console.warn "unrecognised response from rlp"))))
(def +rlp-socket+ nil)
(defn send [msg]
(ws/send +rlp-socket+ msg fmt/json))
(ws/send *rlp-socket msg fmt/json))
(defn on-open []
(println "socket opened")
@@ -39,7 +36,7 @@
"main = fac 3;"])}))
(defn init-rlp-socket []
(set! +rlp-socket+ (ws/create "ws://127.0.0.1:9002"
(set! *rlp-socket (ws/create "ws://127.0.0.1:9002"
{:on-message on-message
:on-open on-open
:on-close #(println "socket closed")
@@ -47,12 +44,14 @@
;; this is called before any code is reloaded
(defn ^:dev/before-load stop []
(ws/close +rlp-socket+)
(ws/close *rlp-socket)
(js/console.log "stop"))
;; start is called by init and after code reloading finishes
(defn ^:dev/after-load start []
(js/console.log "start")
(rdom/render [ui/Main]
(js/document.getElementById "mount"))
(init-rlp-socket))
;; init is called ONCE when the page loads

View File

@@ -0,0 +1,80 @@
(ns ui
(:require
[wscljs.client :as ws]
[wscljs.format :as fmt]
[clojure.string :as str]
[cljs.core.match :refer-macros [match]]
["react-ace$default" :as AceEditor]
["react-resplit" :refer (Resplit)]
["ace-builds/src-noconflict/mode-haskell"]
["ace-builds/src-noconflict/theme-solarized_light"]
["ace-builds/src-noconflict/keybinding-vim"]
[reagent.core :as r]
[reagent.dom :as rdom]))
;------------------------------------------------------------------------------;
(def current-evaluation (r/atom []))
(def current-index (r/atom 0))
(def +split-width+ "4px")
;------------------------------------------------------------------------------;
(defn Root [props & children]
[:> Resplit.Root (assoc props :class "split-root")
[:<> children]])
(defn Pane [props & children]
[:> Resplit.Pane (assoc props :class "split-pane")
[:<> children]])
(defn Splitter [props & children]
[:> Resplit.Splitter (assoc props :class "split-splitter")
[:<> children]])
;------------------------------------------------------------------------------;
(defn Stack []
[:div {:class "pane-content"}
[:h1 "Stack"]])
(defn Dump []
[:div {:class "pane-content"}
[:h1 "Dump"]])
(defn Heap []
[:div {:class "pane-content"}
[:h1 "Heap"]])
(defn Code []
[:div {:class "pane-content"}
[:h1 "Code"]])
;------------------------------------------------------------------------------;
(defn GM [{st :st}]
[Root {:direction "horizontal"}
[Pane {:order 0 :initialSize "0.333fr"}
[Heap]]
[Splitter {:order 1 :size +split-width+}]
[Pane {:order 2 :initialSize "0.333fr"}
[Root {:direction "vertical"}
[Pane {:order 0 :initialSize "0.8fr"}
[Stack]]
[Splitter {:order 1 :size +split-width+}]
[Pane {:order 2 :initialSize "0.2fr"}
[Code]]]]
[Splitter {:order 3 :size +split-width+}]
[Pane {:order 5 :initialSize "0.333fr"}
[Dump]]])
(defn Main []
(prn @current-evaluation)
(prn @current-index)
(if-let [st (nth @current-evaluation
@current-index
nil)]
[GM {:st st}]
[:h1 "no evaluation"]))