Skip to content

Commit

Permalink
Use julia code to log syntax deprecations
Browse files Browse the repository at this point in the history
This makes for consistency of formatting and dispatch for all
deprecation messages, including syntax deprecations.
  • Loading branch information
c42f committed Sep 17, 2017
1 parent 2532c82 commit aaddd03
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 17 deletions.
9 changes: 9 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ function depwarn(msg, funcsym)
nothing
end

function syntax_depwarn(msg, file, line)
opts = JLOptions()
if opts.depwarn == typemax(Int32)
throw(ErrorException(msg))
end
deplevel = Logging.LogLevel(opts.depwarn)
@logmsg deplevel msg file=file line=line
end

firstcaller(bt::Array{Ptr{Void},1}, funcsym::Symbol) = firstcaller(bt, (funcsym,))
function firstcaller(bt::Array{Ptr{Void},1}, funcsyms)
# Identify the calling line
Expand Down
31 changes: 29 additions & 2 deletions src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,39 @@ value_t fl_julia_scalar(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
return fl_ctx->F;
}

static jl_value_t *scm_to_julia_(fl_context_t *fl_ctx, value_t e, int expronly, jl_module_t *mod);

value_t fl_julia_syntax_depwarn(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
{
if (nargs < 1)
lerror(fl_ctx, fl_ctx->ArgError, "julia-syntax-depwarn: too few arguments");
static jl_value_t *depwarn_func = NULL;
if (!depwarn_func && jl_base_module)
depwarn_func = jl_get_global(jl_base_module, jl_symbol("syntax_depwarn"));
if (!depwarn_func)
return fl_ctx->F;
value_t ret = fl_ctx->T;
jl_value_t **depwarn_args;
JL_GC_PUSHARGS(depwarn_args, nargs+1);
JL_TRY {
depwarn_args[0] = depwarn_func;
for (int i = 0; i < nargs; ++i)
depwarn_args[i+1] = scm_to_julia_(fl_ctx, args[i], 0, NULL);
jl_apply(depwarn_args, nargs+1);
}
JL_CATCH {
// Ignore - julia side should handle exceptions for simplicity.
ret = fl_ctx->F;
}
JL_GC_POP();
return ret;
}

static const builtinspec_t julia_flisp_ast_ext[] = {
{ "defined-julia-global", fl_defined_julia_global },
{ "current-julia-module-counter", fl_current_module_counter },
{ "julia-scalar?", fl_julia_scalar },
{ "julia-syntax-depwarn", fl_julia_syntax_depwarn },
{ NULL, NULL }
};

Expand Down Expand Up @@ -394,8 +423,6 @@ static jl_sym_t *scmsym_to_julia(fl_context_t *fl_ctx, value_t s)
return jl_symbol(symbol_name(fl_ctx, s));
}

static jl_value_t *scm_to_julia_(fl_context_t *fl_ctx, value_t e, int expronly, jl_module_t *mod);

static jl_value_t *scm_to_julia(fl_context_t *fl_ctx, value_t e, int expronly, jl_module_t *mod)
{
jl_value_t *v = NULL;
Expand Down
28 changes: 13 additions & 15 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -562,21 +562,19 @@
;; --- misc ---

(define (syntax-deprecation s what instead)
(if (or *depwarn* *deperror*)
(let ((msg (string
#\newline
(if *deperror* "ERROR:" "WARNING:") " deprecated syntax \"" what "\""
(if (or (not s) (eq? current-filename 'none))
""
(string " at " current-filename ":" (input-port-line (if (port? s) s (ts:port s)))))
"."
(if (equal? instead "")
""
(string #\newline "Use \"" instead "\" instead."))
#\newline)))
(if *deperror*
(error msg)
(io.write *stderr* msg)))))
(let* ((file (if (eq? current-filename 'none) "" current-filename))
(line (if (not s) 0 (input-port-line (if (port? s) s (ts:port s)))))
(msg (string "Deprecated syntax \"" what "\""
(if (or (not s) (eq? current-filename 'none))
"" (string " at " file ":" line))
"."
(if (equal? instead "")
""
(string #\newline "Use \"" instead "\" instead.")))))
(if *deperror*
(error msg)
(if (not (julia-syntax-depwarn msg file line))
(io.write *stderr* msg)))))

;; --- parser ---

Expand Down

0 comments on commit aaddd03

Please sign in to comment.