Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for nbb #188

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ target
.cljs_node_repl
out/
node_modules
public/js/
public/js/
.nbb/.cache/
3 changes: 1 addition & 2 deletions build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@
'com.cognitect/transit-clj {:mvn/version "1.0.333"}
'com.cognitect/transit-cljs {:mvn/version "0.8.280"}
'com.github.flow-storm/hansel {:mvn/version "0.1.83"}
'org.clojure/data.int-map {:mvn/version "1.2.1"}
'amalloy/ring-buffer {:mvn/version "1.3.1"}}
'org.clojure/data.int-map {:mvn/version "1.2.1"}}

:paths src-dirs}})
jar-file (format "%s/%s.jar" target-dir (name lib))]
Expand Down
3 changes: 1 addition & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
com.github.jpmonettas/j-system-theme-detector {:mvn/version "3.8.1"}
nrepl/nrepl {:mvn/version "1.1.1"}
org.clojure/data.int-map {:mvn/version "1.2.1"}
org.fxmisc.richtext/richtextfx {:mvn/version "0.11.1"}
amalloy/ring-buffer {:mvn/version "1.3.1"}}
org.fxmisc.richtext/richtextfx {:mvn/version "0.11.1"}}

:aliases {:cljs-storm {:classpath-overrides {org.clojure/clojurescript nil} ;; disable the official compiler
:extra-deps {thheller/shadow-cljs {:mvn/version "2.27.4"
Expand Down
66 changes: 66 additions & 0 deletions nbb.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{:paths ["src-inst" "src-dbg" "src-shared" "resources"]
:deps {;; IMPORTANT !!
;; If adding any dependency for the `inst` part also add it on
;; build.clj jar-inst
org.java-websocket/Java-WebSocket {:mvn/version "1.5.3"}
com.cognitect/transit-clj {:mvn/version "1.0.333"}
com.cognitect/transit-cljs {:mvn/version "0.8.280"}
com.github.flow-storm/hansel {:mvn/version "0.1.83"}

org.openjfx/javafx-controls {:mvn/version "21.0.4-ea+1"}
org.openjfx/javafx-base {:mvn/version "21.0.4-ea+1"}
org.openjfx/javafx-graphics {:mvn/version "21.0.4-ea+1"}
org.openjfx/javafx-web {:mvn/version "21.0.4-ea+1"}

org.kordamp.ikonli/ikonli-javafx {:mvn/version "12.3.1"}
org.kordamp.ikonli/ikonli-materialdesign-pack {:mvn/version "12.3.1"}

com.github.jpmonettas/j-system-theme-detector {:mvn/version "3.8.1"}
nrepl/nrepl {:mvn/version "1.1.1"}
org.clojure/data.int-map {:mvn/version "1.2.1"}
org.fxmisc.richtext/richtextfx {:mvn/version "0.11.1"}}

:aliases {:cljs-storm {:classpath-overrides {org.clojure/clojurescript nil} ;; disable the official compiler
:extra-deps {thheller/shadow-cljs {:mvn/version "2.27.4"
:exclusions [org.clojure/clojurescript]}
;; bring ClojureScriptStorm
com.github.flow-storm/clojurescript {:mvn/version "1.11.132-2"}
;; add FlowStorm runtime dep
com.github.flow-storm/flow-storm-inst {:local/root "." #_#_:mvn/version "RELEASE"}
cider/cider-nrepl {:mvn/version "0.28.3"}
refactor-nrepl/refactor-nrepl {:mvn/version "3.5.2"}
cider/piggieback {:mvn/version "0.5.2"}}
:jvm-opts ["-Dcljs.storm.instrumentOnlyPrefixes=dev"
"-Dcljs.storm.instrumentEnable=true"]}

:storm {:classpath-overrides {org.clojure/clojure nil}
:extra-deps {com.github.flow-storm/clojure {:mvn/version "1.12.0-1"}}
:jvm-opts [;; "-Xmx20500m"
;;"-Dflowstorm.startRecording=false"
"-Dflowstorm.theme=dark"
"-Dclojure.storm.instrumentEnable=true"
"-Dclojure.storm.instrumentOnlyPrefixes=dev-tester"
"-Dflowstorm.jarEditorCommand=emacsclient -n +<<LINE>>:0 <<JAR>>/<<FILE>>"
"-Dflowstorm.fileEditorCommand=emacsclient -n +<<LINE>>:0 <<FILE>>"]}

:dev {:extra-paths ["src-dev" "classes"]

:extra-deps {;; org.clojure/clojurescript {:local/root "/home/jmonetta/my-projects/clojurescript"}
;; org.clojure/core.async {:mvn/version "1.6.681"}
;; dorothy/dorothy {:mvn/version "0.0.7"}
org.openjfx/javafx-swing {:mvn/version "21.0.4-ea+1"}} ;; for scenic view to run

:jvm-opts ["-Dvisualvm.display.name=FlowStorm"
;; for the profilers
"-Djdk.attach.allowAttachSelf" "-XX:+UnlockDiagnosticVMOptions" "-XX:+DebugNonSafepoints"]}
:jvm-debugger {:jvm-opts ["-Xdebug" "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044"]}

:build {:extra-deps {io.github.clojure/tools.build {:git/tag "v0.9.6" :git/sha "8e78bcc"}}
:ns-default build
:jvm-opts ["-Dcljfx.skip-javafx-initialization=true"]}

:test {:extra-paths ["test"]
:extra-deps {lambdaisland/kaocha {:mvn/version "1.70.1086"}
org.clojure/clojurescript {:mvn/version "1.11.60"}}
:jvm-opts ["-Xmx10500m"]
:main-opts ["-m" "kaocha.runner"]}}}
4 changes: 2 additions & 2 deletions src-inst/flow_storm/remote_websocket_client.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
(= :open (websocket-state remote-websocket-client))))

(defn web-socket-client-object [uri-str]
(let [WebSocket (if (and (= *target* "nodejs")
(let [WebSocket (if (and #?(:org.babashka/nbb true
:cljs (= *target* "nodejs"))
(exists? js/require))

(let [obj (try
Expand All @@ -34,7 +35,6 @@
ws-client (WebSocket. uri-str)]
ws-client))


(defn send [ser-packet]
(.send remote-websocket-client ser-packet))

Expand Down
10 changes: 7 additions & 3 deletions src-inst/flow_storm/runtime/events.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
(defn clear-pending-events! []
(reset! pending-events []))

#?(:org.babashka/nbb (defmacro locking
[x & forms]
`(do ~@forms)))

(defn set-dispatch-fn [dispatch-fn]
(reset! *dispatch dispatch-fn)
(reset! *dispatch dispatch-fn)
(locking pending-events
(doseq [pe @pending-events]
(dispatch-fn pe))))
Expand Down Expand Up @@ -61,7 +65,7 @@
(make-task-finished-event task-id nil))
([task-id result]
[:task-finished (cond-> {:task-id task-id}
result (assoc :result result))]))
result (assoc :result result))]))

(defn make-heap-info-update-event [heap-info]
[:heap-info-update heap-info])
Expand Down Expand Up @@ -107,6 +111,6 @@

(dispatch ev)

(when-not (#{:heap-info-update} ev-key )
(when-not (#{:heap-info-update} ev-key)
(locking pending-events
(swap! pending-events conj ev)))))
9 changes: 4 additions & 5 deletions src-inst/flow_storm/runtime/outputs.cljc
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
(ns flow-storm.runtime.outputs
(:require [flow-storm.runtime.events :as rt-events]
[flow-storm.runtime.values :as rt-values]
[amalloy.ring-buffer :refer [ring-buffer]]))
[flow-storm.runtime.values :as rt-values]))

(defonce *last-evals-results (atom (ring-buffer 10)))
(defonce *last-evals-results [])

(defonce *tap-fn (atom nil))

Expand All @@ -26,11 +25,11 @@
(rt-events/publish-event! (rt-events/make-last-evals-update-event last-evals-refs))))

(defn clear-outputs []
(reset! *last-evals-results (ring-buffer 10))
(reset! *last-evals-results [])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I added a ring-buffer here is because the ring-buffer library was already here for other functionality (see my comment below) and I think it looks cleaner

(fire-update-last-evals-event))

(defn handle-eval-result [v]
(swap! *last-evals-results conj v)
(swap! *last-evals-results #((take-last 10 (conj % v))))
(fire-update-last-evals-event))

(defn handle-out-write [s]
Expand Down
60 changes: 33 additions & 27 deletions src-inst/flow_storm/runtime/values.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
(:require [clojure.pprint :as pp]
[flow-storm.utils :as utils]
[flow-storm.types :as types]
[clojure.datafy :refer [datafy nav]]
;; [clojure.datafy :refer [datafy nav]]
#?(:clj [clojure.string :as str])))

(defprotocol PWrapped
(unwrap [_]))

(comment
(deftype Greg [obj]
nil
(foo [_] "bar"))

(foo))

(deftype HashableObjWrap [obj]
#?@(:clj
[clojure.lang.IHashEq
Expand All @@ -17,6 +24,8 @@
(if (instance? HashableObjWrap that)
(identical? obj (unwrap that))
false))]
:org.babashka/nbb
[]

:cljs
[IEquiv
Expand All @@ -28,7 +37,7 @@
IHash
(-hash [_]
(utils/object-id obj))])

PWrapped
(unwrap [_]
obj))
Expand All @@ -45,7 +54,7 @@
(get-value-ref [_ v]))

;; Fast way of going from
;; value-ref -> value
;; value-ref -> value
;; value -> value-ref
;;
;; every object gets wrapped into a HashableObjWrap that will have
Expand All @@ -67,7 +76,7 @@
(assoc :max-vid next-vid)
(update :vref->wv assoc vref wv)
(update :wv->vref assoc wv vref))))))

(get-value [_ vref]
(unwrap (get vref->wv vref)))

Expand All @@ -91,20 +100,20 @@

(defn reference-value! [v]
(try

(swap! values-ref-registry add-val-ref v)
(-> (get-value-ref @values-ref-registry v)
(types/add-val-preview v))

;; if for whatever reason we can't reference the value
;; let's be explicit so at least the user knows that
;; let's be explicit so at least the user knows that
;; something went wrong and the value can't be trusted.
;; I have seen a issues of hashing failing for a lazy sequence
#?(:clj (catch Exception e
(utils/log-error "Error referencing value" e)
(utils/log-error "Error referencing value" e)
(reference-value! :flow-storm/error-referencing-value))
:cljs (catch js/Error e
(utils/log-error "Error referencing value" e)
(utils/log-error "Error referencing value" e)
(reference-value! :flow-storm/error-referencing-value)))))

(defn clear-vals-ref-registry []
Expand Down Expand Up @@ -163,12 +172,12 @@
(pr-str (:ref/type v))
(pr-str (type v))))

(defn val-pprint [val {:keys [print-length print-level print-meta? pprint? nth-elems]}]
(defn val-pprint [val {:keys [print-length print-level print-meta? pprint? nth-elems]}]
(let [val-type (value-type val)
print-fn #?(:clj (if pprint? pp/pprint prn)
print-fn #?(:clj (if pprint? pp/pprint prn)
:cljs (if (and pprint? (not print-meta?)) pp/pprint print)) ;; ClojureScript pprint doesn't support *print-meta*
val-str (try

(if (and (utils/blocking-derefable? val)
(utils/pending? val))

Expand Down Expand Up @@ -199,7 +208,7 @@
{:val-str val-str
:val-type val-type}))

(defn val-pprint-ref [vref opts]
(defn val-pprint-ref [vref opts]
(let [val (deref-value vref)]
(val-pprint val opts)))

Expand All @@ -208,7 +217,7 @@
(tap> v)))

#?(:clj
(defn def-value [var-ns var-name x]
(defn def-value [var-ns var-name x]
(intern (symbol var-ns)
(symbol var-name)
(deref-value x))))
Expand All @@ -225,13 +234,13 @@

(defn interesting-nav-reference [coll k]
(let [v (get coll k)
n (nav coll k v)]
n "unimplmemented" #_(nav coll k v)]
(when (or (not= n v)
(not= (meta n) (meta v)))
(not= (meta n) (meta v)))
(reference-value! n))))

(defn extract-data-aspects [o]
(let [dat-o (datafy o)
(let [dat-o "unimplemented" ;;(datafy o)
o-meta (meta o)]
(reduce (fn [aspects {:keys [id pred extractor]}]
(if (pred dat-o)
Expand All @@ -253,19 +262,18 @@
(register-data-aspect-extractor
{:id :number
:pred number?
:extractor (fn [n]
:extractor (fn [n]
{:number/val n})})

(register-data-aspect-extractor
{:id :int
:pred int?
:extractor (fn [n]
:extractor (fn [n]
{:int/decimal n
:int/binary (utils/format-int n 2)
:int/octal (utils/format-int n 8)
:int/hex (utils/format-int n 16)})})


(register-data-aspect-extractor
{:id :previewable
:pred any?
Expand Down Expand Up @@ -309,22 +317,21 @@
:shallow-idx-coll/vals-refs (mapv reference-value! idx-coll)
:shallow-idx-coll/navs-refs (mapv (partial interesting-nav-reference idx-coll) (range (count idx-coll)))})})


#?(:clj
(register-data-aspect-extractor
{:id :byte-array
:pred bytes?
:extractor (fn [bs]
(let [max-cnt 1000

format-and-pad (fn [b radix]
(let [s (-> ^byte b
Byte/toUnsignedInt
(utils/format-int radix))
s-padded (cond
s-padded (cond
(= radix 2) (format "%8s" s)
(= radix 16) (format "%2s" s))]

(str/replace s-padded " " "0")))]
(if (<= (count bs) max-cnt)
{:bytes/hex (mapv #(format-and-pad % 16) bs)
Expand All @@ -339,7 +346,6 @@
:bytes/tail-binary (mapv #(format-and-pad % 2) tail)}))))}))

(comment

(extract-data-aspects 120)
(extract-data-aspects {:a 20 :b 40})
)
(extract-data-aspects {:a 20 :b 40}))
5 changes: 4 additions & 1 deletion src-shared/flow_storm/types.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@

#?(:clj (defmethod print-method ValueRef [vref ^java.io.Writer w]
(.write w ^String (str "#flow-storm.types/value-ref " (:vid vref))))

:org.babashka/nbb (extend-protocol IPrintWithWriter
ValueRef
(-pr-writer [vref writer _]
(-write writer (str "#flow-storm.types/value-ref " (:vid vref)))))
:cljs (extend-protocol IPrintWithWriter
ValueRef
(-pr-writer [vref writer _]
Expand Down
Loading