Skip to content

Commit aaddd03

Browse files
committed
Use julia code to log syntax deprecations
This makes for consistency of formatting and dispatch for all deprecation messages, including syntax deprecations.
1 parent 2532c82 commit aaddd03

3 files changed

Lines changed: 51 additions & 17 deletions

File tree

base/deprecated.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ function depwarn(msg, funcsym)
8686
nothing
8787
end
8888

89+
function syntax_depwarn(msg, file, line)
90+
opts = JLOptions()
91+
if opts.depwarn == typemax(Int32)
92+
throw(ErrorException(msg))
93+
end
94+
deplevel = Logging.LogLevel(opts.depwarn)
95+
@logmsg deplevel msg file=file line=line
96+
end
97+
8998
firstcaller(bt::Array{Ptr{Void},1}, funcsym::Symbol) = firstcaller(bt, (funcsym,))
9099
function firstcaller(bt::Array{Ptr{Void},1}, funcsyms)
91100
# Identify the calling line

src/ast.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,39 @@ value_t fl_julia_scalar(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
167167
return fl_ctx->F;
168168
}
169169

170+
static jl_value_t *scm_to_julia_(fl_context_t *fl_ctx, value_t e, int expronly, jl_module_t *mod);
171+
172+
value_t fl_julia_syntax_depwarn(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
173+
{
174+
if (nargs < 1)
175+
lerror(fl_ctx, fl_ctx->ArgError, "julia-syntax-depwarn: too few arguments");
176+
static jl_value_t *depwarn_func = NULL;
177+
if (!depwarn_func && jl_base_module)
178+
depwarn_func = jl_get_global(jl_base_module, jl_symbol("syntax_depwarn"));
179+
if (!depwarn_func)
180+
return fl_ctx->F;
181+
value_t ret = fl_ctx->T;
182+
jl_value_t **depwarn_args;
183+
JL_GC_PUSHARGS(depwarn_args, nargs+1);
184+
JL_TRY {
185+
depwarn_args[0] = depwarn_func;
186+
for (int i = 0; i < nargs; ++i)
187+
depwarn_args[i+1] = scm_to_julia_(fl_ctx, args[i], 0, NULL);
188+
jl_apply(depwarn_args, nargs+1);
189+
}
190+
JL_CATCH {
191+
// Ignore - julia side should handle exceptions for simplicity.
192+
ret = fl_ctx->F;
193+
}
194+
JL_GC_POP();
195+
return ret;
196+
}
197+
170198
static const builtinspec_t julia_flisp_ast_ext[] = {
171199
{ "defined-julia-global", fl_defined_julia_global },
172200
{ "current-julia-module-counter", fl_current_module_counter },
173201
{ "julia-scalar?", fl_julia_scalar },
202+
{ "julia-syntax-depwarn", fl_julia_syntax_depwarn },
174203
{ NULL, NULL }
175204
};
176205

@@ -394,8 +423,6 @@ static jl_sym_t *scmsym_to_julia(fl_context_t *fl_ctx, value_t s)
394423
return jl_symbol(symbol_name(fl_ctx, s));
395424
}
396425

397-
static jl_value_t *scm_to_julia_(fl_context_t *fl_ctx, value_t e, int expronly, jl_module_t *mod);
398-
399426
static jl_value_t *scm_to_julia(fl_context_t *fl_ctx, value_t e, int expronly, jl_module_t *mod)
400427
{
401428
jl_value_t *v = NULL;

src/julia-parser.scm

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -562,21 +562,19 @@
562562
;; --- misc ---
563563

564564
(define (syntax-deprecation s what instead)
565-
(if (or *depwarn* *deperror*)
566-
(let ((msg (string
567-
#\newline
568-
(if *deperror* "ERROR:" "WARNING:") " deprecated syntax \"" what "\""
569-
(if (or (not s) (eq? current-filename 'none))
570-
""
571-
(string " at " current-filename ":" (input-port-line (if (port? s) s (ts:port s)))))
572-
"."
573-
(if (equal? instead "")
574-
""
575-
(string #\newline "Use \"" instead "\" instead."))
576-
#\newline)))
577-
(if *deperror*
578-
(error msg)
579-
(io.write *stderr* msg)))))
565+
(let* ((file (if (eq? current-filename 'none) "" current-filename))
566+
(line (if (not s) 0 (input-port-line (if (port? s) s (ts:port s)))))
567+
(msg (string "Deprecated syntax \"" what "\""
568+
(if (or (not s) (eq? current-filename 'none))
569+
"" (string " at " file ":" line))
570+
"."
571+
(if (equal? instead "")
572+
""
573+
(string #\newline "Use \"" instead "\" instead.")))))
574+
(if *deperror*
575+
(error msg)
576+
(if (not (julia-syntax-depwarn msg file line))
577+
(io.write *stderr* msg)))))
580578

581579
;; --- parser ---
582580

0 commit comments

Comments
 (0)