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

#35 Added an optional call-site id as an arg to spy and brk #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 deletions src/sc/api.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,12 @@

(defn last-ep-id
"Returns the id of the last saved Execution Point, in [ep-id cs-id] form.
An optional call-site id can be given to constrain the output
Throws an Exception if no Execution Point has been saved."
[]
(i/last-ep-id))
([]
(i/last-ep-id))
([cs-id]
(i/last-ep-id cs-id)))

(defn ep-info
"Given an Execution Point Id,
Expand Down
27 changes: 18 additions & 9 deletions src/sc/impl.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,26 @@
(swap! db/ep-id inc))

(defn last-ep-id*
[db]
(let [eps (get db :execution-points)]
[db cs-id]
(let [get-cs-id #(-> % :sc.ep/code-site :sc.cs/id)
eps (cond->> (get db :execution-points)
cs-id (filter (comp #{cs-id} get-cs-id second)))]
(if (empty? eps)
(throw (ex-info
"No Execution Point has been saved yet."
(if cs-id
"No Execution Point for Call Site has been saved yet."
"No Execution Point has been saved yet.")
{:sc.api.error/error-type
:sc.api.error-types/no-ep-saved-yet}))
:sc.api.error-types/no-ep-saved-yet
:sc.cs/id cs-id}))
(let [[epid ep-v] (apply max-key first eps)]
[epid (-> ep-v :sc.ep/code-site :sc.cs/id)]))))
[epid (get-cs-id ep-v)]))))

(defn last-ep-id
[]
(last-ep-id* @db/db))
([]
(last-ep-id* @db/db nil))
([cs-id]
(last-ep-id* @db/db cs-id)))

(defn valid-ep-identifier?
[v]
Expand Down Expand Up @@ -209,11 +216,12 @@
spy-pre-eval-logger :sc/spy-ep-pre-eval-logger
spy-post-eval-logger :sc/spy-ep-post-eval-logger
only-from :sc/called-from
cs-id :sc.cs/id
:or {cs-logger-id :sc.api.logging/log-spy-cs
spy-pre-eval-logger `sc.api.logging/log-spy-ep-pre-eval
spy-post-eval-logger `sc.api.logging/log-spy-ep-post-eval
}} opts
cs-id (gen-cs-id)
cs-id (or cs-id (gen-cs-id))
cs-data (make-cs-data opts cs-id expr amp-env amp-form)]
(save-cs cs-data)
(il/log-cs cs-logger-id cs-data)
Expand Down Expand Up @@ -257,11 +265,12 @@
brk-pre-eval-logger :sc/brk-ep-pre-eval-logger
brk-post-eval-logger :sc/brk-ep-post-eval-logger
only-from :sc/called-from
cs-id :sc.cs/id
:or {cs-logger-id :sc.api.logging/log-brk-cs
brk-pre-eval-logger `sc.api.logging/log-brk-ep-pre-eval
brk-post-eval-logger `sc.api.logging/log-brk-ep-post-eval
}} opts
cs-id (gen-cs-id)
cs-id (or cs-id (gen-cs-id))
cs-data (make-cs-data opts cs-id expr amp-env amp-form)]
(save-cs cs-data)
(il/log-cs cs-logger-id cs-data)
Expand Down