Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
bf621cc
WIP: oasis in 3 proper modules
FossiFoo Jun 1, 2020
07aae8f
WIP runtime module loading
FossiFoo Jun 8, 2020
6f5c54a
Implement proper module handling and port Oasis over
FossiFoo Jul 23, 2020
2862096
display modules in oasis
FossiFoo Sep 13, 2020
46a4c78
move scrolling to render module
FossiFoo Sep 13, 2020
8669b56
module, render thread and loading improvements
FossiFoo Oct 4, 2020
e14349b
repair create sink & hover
FossiFoo Oct 6, 2020
8bd058d
base module; linking & adding sinks to module
FossiFoo Oct 14, 2020
05da93c
fix highlight
FossiFoo Oct 18, 2020
70be65c
try async promise-chan for storage
FossiFoo Oct 20, 2020
3f4d10a
WIP: refactor runtime communication
FossiFoo Oct 31, 2020
f85bab3
refactor and test
FossiFoo Nov 20, 2020
cbda438
context for evaluation to allow duplicate reductions/modules
FossiFoo Dec 16, 2020
2800a9a
fix modules/runtimes to allow contexts
FossiFoo Dec 29, 2020
9344955
debugging handlers and async
FossiFoo Jun 3, 2021
e4546e6
kbn
FossiFoo Jun 5, 2021
c76d738
repl works
FossiFoo Mar 12, 2022
9744d5b
more repl improvements
FossiFoo May 16, 2022
7455e82
cli with multiple rts
FossiFoo May 25, 2022
8a1e48e
rework pipes with explicit scheduling
ChristophMewes Mar 17, 2023
f08e2a5
lots of things with terminal cli
ChristophMewes Apr 14, 2023
8fcbea2
lotsa stuff, terminal, tracing, debugger
ChristophMewes Jun 5, 2023
674f4ff
add reductions to rt and more metrics
ChristophMewes Jun 24, 2023
3569703
add init to splitter and reproduce module reuse issues
ChristophMewes Aug 10, 2023
cfb343d
module debugging
ChristophMewes Aug 21, 2023
ab9d61e
fix bugs
ChristophMewes Feb 14, 2024
d82d5a7
fixes
FossiFoo Feb 24, 2024
a123910
WIP make samak build with shadow cljs
rbuchmann May 7, 2022
22ae7f4
Remove java only exception from node evaluation
rbuchmann May 7, 2022
5b93d85
try
FossiFoo Feb 25, 2024
76dbd2b
mid progress of fixing oasis on shadow and conveyor
FossiFoo Mar 3, 2024
f1a1e27
activate more pieces and fix UI module
FossiFoo Mar 3, 2024
c9ea4a9
reconnect more things
FossiFoo Mar 4, 2024
b8786fc
make elkjs layout work
FossiFoo Mar 9, 2024
c36648d
fix oasis loading itself & caravan
FossiFoo Mar 21, 2024
d037ed0
test
FossiFoo Mar 21, 2024
bbfd60c
bump dependencies and get lein run to work
FossiFoo Mar 28, 2024
1678837
bump datascript version and implement hash-referencing
FossiFoo Apr 1, 2024
410a8f2
repair oasis and kara
FossiFoo May 24, 2024
7e10bde
remove bogus file
FossiFoo May 24, 2024
4f4674b
connect storage, repl & oasis main
FossiFoo Jun 1, 2024
73933a1
formalize protocol between rts and improve remote store impl
FossiFoo Nov 23, 2024
6d90936
some fixes for wiring
FossiFoo Sep 5, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pom.xml.asc
.lein-plugins/
.lein-failures
.nrepl-port
.shadow-cljs
resources/public/js
*-init.clj
figwheel_server.log
Expand Down
9 changes: 3 additions & 6 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@ ventures on it...”
#+BEGIN_SRC bash
$ npm install # or yarn, you know, whatever

$ lein build-all
$ lein compile

# samak-cli for console programs
$ ./samak-cli examples/basic.sk
$ lein run examples/basic.sk

# samak-ui for electron based ui programs

$ ./samak-ui examples/chuck_norris.sk
$ npx shadow-cljs start

#+END_SRC

In case you don't have electron installed globally, run =npm run start=.

* Roadmaps

** Samak
Expand Down
14 changes: 10 additions & 4 deletions cli_src/cli/node_core.cljs
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
(ns cli.node-core
(:require [cljs.nodejs :as nodejs]
[clojure.string :as str]
[cli.runtime :as rt]
[promesa.core :as prom]
[samak.repl :as repl]))

(nodejs/enable-util-print!)

(def fs ^js/fs (nodejs/require "fs"))

(defn load-samak-file [filename]
(->> (.readFileSync fs filename)
(defn load-samak-file [filename rt]
(-> (.readFileSync fs filename)
str/split-lines
repl/eval-lines))
(rt/eval-lines rt)))

(defn -main [& [filename & args]]
(if (not-empty filename)
(load-samak-file filename)
(prom/let [w (rt/make-runtime-remote {:store :remote :id "cli-w1"})
rt (rt/make-runtime {:id "cli-main" :env {:connects [w]}})]
res (load-samak-file filename rt)
res)

(println "Usage: node samak-cli.js <filename>")))

(set! *main-cli-fn* -main)
115 changes: 115 additions & 0 deletions cli_src/cli/runtime.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
(ns cli.runtime
(:require [cljs.nodejs :as nodejs]
[clojure.string :as str]
[clojure.core.async :as a]
[promesa.core :as prom]
[cognitect.transit :as t]
[metosin.transit.dates :as d]
[samak.repl :as repl]
[samak.runtime :as run]
[samak.stdlib :as std]
[samak.builtins :as builtins]
[samak.caravan :as caravan]
[samak.pipes :as pipes]
[samak.layout :as layout])
(:require-macros [cljs.core.async.macros :refer [go go-loop]]))

(def ui-mock-symbols
{'modules/ui :blank
'pipes/ui :blank
'pipes/events :blank
'pipes/mouse :blank
'pipes/keyboard :blank})

(def cli-symbols
(merge builtins/samak-symbols
std/pipe-symbols
caravan/symbols
ui-mock-symbols
layout/layout-symbols
))

(defn make-scheduler []
(let [broadcast (pipes/pipe (a/chan) ::main-broadcast)
to-rt (pipes/pipe (a/chan) ::main-scheduler)]
(println "sched")
;; (handle-update "out" broadcast)
;; (handle-update "in" to-rt)
(fn [] [to-rt broadcast])))

(def worker_threads (nodejs/require "worker_threads"))

(defn make-worker
""
[url]
(println "make worker" (.-isMainThread worker_threads))
;; (println "returning worker: " worker_threads)
(let [Worker (.-Worker worker_threads)]
(Worker. url)))

(def json-reader (t/reader :json {:handlers d/readers}))
(defn make-handler
""
[from-worker conf]
(fn
[event]
(let [data (t/read json-reader event)]
;; (println "recv from" (:id conf) ":" data)
(condp = (:target data)
(a/put! from-worker data)))))

(defn handle-send
""
[worker c conf]
(let [w (t/writer :json {:handlers d/writers})]
(go-loop []
(let [p (<! c)]
;; (println "send to" (:id conf) p)
(.postMessage worker (t/write w p)))
(recur))))

(defn make-runtime-remote [conf]
(prom/let [to-worker (a/chan)
from-worker (a/chan)
from-mult (a/mult from-worker)
worker (make-worker "./cli/samak-cli-worker.js")]
;; race condition on finished worker code before messaging is set up
(handle-send worker to-worker conf)
(.on worker "message" (make-handler from-worker conf))
{:to to-worker :from from-mult :id (:id conf) :conf conf}))

(defn init-runtime-remote [worker init]
(let [p (prom/deferred)
from (a/chan)]
(a/tap (:from worker) from)
(go-loop []
(let [m (<! from)]
(when (and (= (:target m) :bootstrap))
(a/put! (:to worker) {:cmd :init :param init}))
(when (and (= (:target m) :load) (= (:data m) 100))
(prom/resolve! p true)))
(recur))
p))


(defn make-runtime [conf]
(prom/let [in-main (pipes/pipe-chan ::to-main nil)
out-main (pipes/pipe-chan ::from-main nil)
out-mult (a/mult out-main)
rt (run/make-runtime cli-symbols (make-scheduler) (merge {:modules {}} conf))
w (first (:connects (:env conf)))]
(when w
(a/tap out-mult (:to w))
(a/tap (:from w) in-main))
(pipes/link! (pipes/source in-main) (:scheduler rt))
(pipes/link! (:broadcast rt) (pipes/sink out-main))
(prom/do!
(println "init w")
(when w (init-runtime-remote w :foo))
(println "done w")
(repl/init rt))))

(defn eval-lines
""
[lines rt]
(repl/eval-lines lines rt))
57 changes: 57 additions & 0 deletions cli_src/cli/worker.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
(ns cli.worker-core
(:require [cljs.nodejs :as nodejs]
[clojure.core.async :as a :refer [<! >! chan close! put!]]
[cognitect.transit :as t]
[metosin.transit.dates :as d]
[samak.helpers :as helpers]
[samak.worker :as worker])
(:require-macros [cljs.core.async.macros :refer [go go-loop]]))

(def worker_threads (nodejs/require "worker_threads"))

(defn handle-update
""
[c]
(let [w (t/writer :json {:handlers d/writers})]
(go-loop []
(let [p (<! c)]
(.postMessage (.-parentPort worker_threads) (t/write w {:target :load :data p})))
(recur))))


(defn handle-request
""
[c]
(let [w (t/writer :json {:handlers d/writers})]
(go-loop []
(let [p (<! c)
before (helpers/now)]
;; (println "to main" p)
(.postMessage (.-parentPort worker_threads) (t/write w p)))
(recur))))

(def json-reader (t/reader :json {:handlers d/readers}))
(defn make-handler
""
[in init]
(fn
[event]
(let [data (t/read json-reader event)]
;; (println "worker in" data)
(if (= (:cmd data) :init)
(helpers/debounce #(init (:param data)))
(put! in data)))))

(defn bootstrap
""
[]
(println "bootstrap")
(let [loading (chan)
in (chan)
out (chan)]
(handle-update loading)
(handle-request out)
(.on (.-parentPort worker_threads) "message" (make-handler in #(worker/start-rt loading in out)))
(put! out {:target :bootstrap})))

(bootstrap)
Loading