mirror of
https://github.com/janet-lang/janet
synced 2025-03-09 09:48:09 +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:
parent
17cb0c1aee
commit
9e5f203302
@ -2,6 +2,7 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
## Unreleased - ???
|
## Unreleased - ???
|
||||||
|
- Expose current macro form inside macros as (dyn :macro-form)
|
||||||
- Add `tracev` macro.
|
- Add `tracev` macro.
|
||||||
- Fix compiler bug that emitted incorrect code in some cases for while loops that create closures.
|
- Fix compiler bug that emitted incorrect code in some cases for while loops that create closures.
|
||||||
- Add `:fresh` option to `(import ...)` to overwrite the module cache.
|
- Add `:fresh` option to `(import ...)` to overwrite the module cache.
|
||||||
|
@ -950,9 +950,14 @@
|
|||||||
"Print a value and a description of the form that produced that value to
|
"Print a value and a description of the form that produced that value to
|
||||||
stderr. Evaluates to x."
|
stderr. Evaluates to x."
|
||||||
[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))
|
(def s (gensym))
|
||||||
~(let [,s ,x]
|
~(let [,s ,x]
|
||||||
(,eprinf "trace %j is " ',x)
|
(,eprinf ,fmt ',x)
|
||||||
(,eprintf (,dyn :pretty-format "%q") ,s)
|
(,eprintf (,dyn :pretty-format "%q") ,s)
|
||||||
,s))
|
,s))
|
||||||
|
|
||||||
@ -1628,6 +1633,8 @@
|
|||||||
See macex docs for info on on-binding."
|
See macex docs for info on on-binding."
|
||||||
[x &opt on-binding]
|
[x &opt on-binding]
|
||||||
|
|
||||||
|
(setdyn :macro-form x)
|
||||||
|
|
||||||
(when on-binding
|
(when on-binding
|
||||||
(when (symbol? x)
|
(when (symbol? x)
|
||||||
(break (on-binding x))))
|
(break (on-binding x))))
|
||||||
|
@ -596,8 +596,11 @@ static int macroexpand1(
|
|||||||
/* Set env */
|
/* Set env */
|
||||||
fiberp->env = c->env;
|
fiberp->env = c->env;
|
||||||
int lock = janet_gclock();
|
int lock = janet_gclock();
|
||||||
|
Janet mf_kw = janet_ckeywordv("macro-form");
|
||||||
|
janet_table_put(c->env, mf_kw, x);
|
||||||
Janet tempOut;
|
Janet tempOut;
|
||||||
JanetSignal status = janet_continue(fiberp, janet_wrap_nil(), &tempOut);
|
JanetSignal status = janet_continue(fiberp, janet_wrap_nil(), &tempOut);
|
||||||
|
janet_table_put(c->env, mf_kw, janet_wrap_nil());
|
||||||
janet_gcunlock(lock);
|
janet_gcunlock(lock);
|
||||||
if (status != JANET_SIGNAL_OK) {
|
if (status != JANET_SIGNAL_OK) {
|
||||||
const uint8_t *es = janet_formatc("(macro) %V", tempOut);
|
const uint8_t *es = janet_formatc("(macro) %V", tempOut);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user