mirror of
https://github.com/janet-lang/janet
synced 2025-11-13 13:57:19 +00:00
Expose line, col in macros via (dyn :macro-form)
This exposes line and column indirectly via tuple/sourcemap and allows interesting debug macros.
This commit is contained in:
@@ -950,9 +950,14 @@
|
||||
"Print a value and a description of the form that produced that value to
|
||||
stderr. Evaluates to x."
|
||||
[x]
|
||||
(def [l c] (tuple/sourcemap (dyn :macro-form ())))
|
||||
(def cf (dyn :current-file))
|
||||
(def fmt-1 (if cf (string/format "trace [%s]" cf) "trace"))
|
||||
(def fmt-2 (if (or (neg? l) (neg? c)) ": " (string/format " on line %d, column %d:" l c)))
|
||||
(def fmt (string fmt-1 fmt-2 " %j is "))
|
||||
(def s (gensym))
|
||||
~(let [,s ,x]
|
||||
(,eprinf "trace %j is " ',x)
|
||||
(,eprinf ,fmt ',x)
|
||||
(,eprintf (,dyn :pretty-format "%q") ,s)
|
||||
,s))
|
||||
|
||||
@@ -1628,6 +1633,8 @@
|
||||
See macex docs for info on on-binding."
|
||||
[x &opt on-binding]
|
||||
|
||||
(setdyn :macro-form x)
|
||||
|
||||
(when on-binding
|
||||
(when (symbol? x)
|
||||
(break (on-binding x))))
|
||||
|
||||
Reference in New Issue
Block a user