Skip to content

Commit 946f3b2

Browse files
committed
flisp: remove need for reentrancy
1 parent d89addd commit 946f3b2

File tree

4 files changed

+38
-107
lines changed

4 files changed

+38
-107
lines changed

src/ast.c

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -226,51 +226,10 @@ static value_t fl_julia_scalar(fl_context_t *fl_ctx, value_t *args, uint32_t nar
226226

227227
static jl_value_t *scm_to_julia_(fl_context_t *fl_ctx, value_t e, jl_module_t *mod);
228228

229-
static value_t fl_julia_logmsg(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
230-
{
231-
int kwargs_len = (int)nargs - 6;
232-
if (nargs < 6 || kwargs_len % 2 != 0) {
233-
lerror(fl_ctx, fl_ctx->ArgError, "julia-logmsg: bad argument list - expected "
234-
"level (symbol) group (symbol) id file line msg . kwargs");
235-
}
236-
value_t arg_level = args[0];
237-
value_t arg_group = args[1];
238-
value_t arg_id = args[2];
239-
value_t arg_file = args[3];
240-
value_t arg_line = args[4];
241-
value_t arg_msg = args[5];
242-
value_t *arg_kwargs = args + 6;
243-
if (!isfixnum(arg_level) || !issymbol(arg_group) || !issymbol(arg_id) ||
244-
!issymbol(arg_file) || !isfixnum(arg_line) || !fl_isstring(fl_ctx, arg_msg)) {
245-
lerror(fl_ctx, fl_ctx->ArgError,
246-
"julia-logmsg: Unexpected type in argument list");
247-
}
248-
249-
// Abuse scm_to_julia here to convert arguments. This is meant for `Expr`s
250-
// but should be good enough provided we're only passing simple numbers,
251-
// symbols and strings.
252-
jl_value_t *group=NULL, *id=NULL, *file=NULL, *line=NULL, *msg=NULL;
253-
jl_array_t *kwargs=NULL;
254-
JL_GC_PUSH6(&group, &id, &file, &line, &msg, &kwargs);
255-
group = scm_to_julia(fl_ctx, arg_group, NULL);
256-
id = scm_to_julia(fl_ctx, arg_id, NULL);
257-
file = scm_to_julia(fl_ctx, arg_file, NULL);
258-
line = scm_to_julia(fl_ctx, arg_line, NULL);
259-
msg = scm_to_julia(fl_ctx, arg_msg, NULL);
260-
kwargs = jl_alloc_vec_any(kwargs_len);
261-
for (int i = 0; i < kwargs_len; ++i) {
262-
jl_array_ptr_set(kwargs, i, scm_to_julia(fl_ctx, arg_kwargs[i], NULL));
263-
}
264-
jl_log(numval(arg_level), NULL, group, id, file, line, (jl_value_t*)kwargs, msg);
265-
JL_GC_POP();
266-
return fl_ctx->T;
267-
}
268-
269229
static const builtinspec_t julia_flisp_ast_ext[] = {
270230
{ "defined-julia-global", fl_defined_julia_global }, // TODO: can we kill this safepoint
271231
{ "current-julia-module-counter", fl_current_module_counter },
272232
{ "julia-scalar?", fl_julia_scalar }, // TODO: can we kill this safepoint? (from jl_isa)
273-
{ "julia-logmsg", fl_julia_logmsg }, // TODO: kill this safepoint
274233
{ "julia-current-file", fl_julia_current_file },
275234
{ "julia-current-line", fl_julia_current_line },
276235
{ NULL, NULL }
@@ -299,7 +258,6 @@ static void jl_init_ast_ctx(jl_ast_context_t *ast_ctx) JL_NOTSAFEPOINT
299258
ctx->slot_sym = symbol(fl_ctx, "slot");
300259
ctx->task = NULL;
301260
ctx->module = NULL;
302-
set(symbol(fl_ctx, "*depwarn-opt*"), fixnum(jl_options.depwarn));
303261
set(symbol(fl_ctx, "*scopewarn-opt*"), fixnum(jl_options.warn_scope));
304262
}
305263

@@ -1282,7 +1240,8 @@ JL_DLLEXPORT jl_value_t *jl_expand_with_loc_warn(jl_value_t *expr, jl_module_t *
12821240
const char *file, int line)
12831241
{
12841242
JL_TIMING(LOWERING);
1285-
JL_GC_PUSH1(&expr);
1243+
jl_array_t *kwargs = NULL;
1244+
JL_GC_PUSH2(&expr, &kwargs);
12861245
expr = jl_copy_ast(expr);
12871246
expr = jl_expand_macros(expr, inmodule, NULL, 0, ~(size_t)0, 1);
12881247
jl_ast_context_t *ctx = jl_ast_ctx_enter();
@@ -1294,6 +1253,34 @@ JL_DLLEXPORT jl_value_t *jl_expand_with_loc_warn(jl_value_t *expr, jl_module_t *
12941253
expr = scm_to_julia(fl_ctx, e, inmodule);
12951254
JL_AST_PRESERVE_POP(ctx, old_roots);
12961255
jl_ast_ctx_leave(ctx);
1256+
jl_sym_t *warn_sym = jl_symbol("warn");
1257+
if (jl_is_expr(expr) && ((jl_expr_t*)expr)->head == warn_sym) {
1258+
size_t nargs = jl_expr_nargs(expr);
1259+
for (int i = 0; i < nargs - 1; i++) {
1260+
jl_value_t *warning = jl_exprarg(expr, i);
1261+
size_t nargs = 0;
1262+
if (jl_is_expr(warning) && ((jl_expr_t*)warning)->head == warn_sym)
1263+
nargs = jl_expr_nargs(warning);
1264+
int kwargs_len = (int)nargs - 6;
1265+
if (nargs < 6 || kwargs_len % 2 != 0) {
1266+
jl_error("julia-logmsg: bad argument list - expected "
1267+
":warn level (symbol) group (symbol) id file line msg . kwargs");
1268+
}
1269+
jl_value_t *level = jl_exprarg(warning, 0);
1270+
jl_value_t *group = jl_exprarg(warning, 1);
1271+
jl_value_t *id = jl_exprarg(warning, 2);
1272+
jl_value_t *file = jl_exprarg(warning, 3);
1273+
jl_value_t *line = jl_exprarg(warning, 4);
1274+
jl_value_t *msg = jl_exprarg(warning, 5);
1275+
kwargs = jl_alloc_vec_any(kwargs_len);
1276+
for (int i = 0; i < kwargs_len; ++i) {
1277+
jl_array_ptr_set(kwargs, i, jl_exprarg(warning, i + 6));
1278+
}
1279+
JL_TYPECHK(logmsg, long, level);
1280+
jl_log(jl_unbox_long(level), NULL, group, id, file, line, (jl_value_t*)kwargs, msg);
1281+
}
1282+
expr = jl_exprarg(expr, nargs - 1);
1283+
}
12971284
JL_GC_POP();
12981285
return expr;
12991286
}

src/jlfrontend.scm

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,14 @@
153153
(define (jl-expand-to-thunk-warn expr file line stmt)
154154
(let ((warnings '()))
155155
(with-bindings
156-
((lowering-warning (lambda lst (set! warnings (cons lst warnings)))))
157-
(begin0
158-
(if stmt
159-
(expand-to-thunk-stmt- expr file line)
160-
(expand-to-thunk- expr file line))
161-
(for-each (lambda (args) (apply julia-logmsg args))
162-
(reverse warnings))))))
156+
;; Abuse scm_to_julia here to convert arguments to warn. This is meant for
157+
;; `Expr`s but should be good enough provided we're only passing simple
158+
;; numbers, symbols and strings.
159+
((lowering-warning (lambda lst (set! warnings (cons (cons 'warn lst) warnings)))))
160+
(let ((thunk (if stmt
161+
(expand-to-thunk-stmt- expr file line)
162+
(expand-to-thunk- expr file line))))
163+
(if (pair? warnings) `(warn ,@(reverse warnings) ,thunk) thunk)))))
163164

164165
(define (jl-expand-to-thunk expr file line)
165166
(expand-to-thunk- expr file line))
@@ -214,16 +215,6 @@
214215
; Utilities for logging messages from the frontend, in a way which can be
215216
; controlled from julia code.
216217

217-
; Log a general deprecation message at line node location `lno`
218-
(define (deprecation-message msg lno)
219-
(let* ((lf (extract-line-file lno)) (line (car lf)) (file (cadr lf)))
220-
(frontend-depwarn msg file line)))
221-
222-
; Log a syntax deprecation from line node location `lno`
223-
(define (syntax-deprecation what instead lno)
224-
(let* ((lf (extract-line-file lno)) (line (car lf)) (file (cadr lf)))
225-
(deprecation-message (format-syntax-deprecation what instead file line #f) lno)))
226-
227218
; Extract line and file from a line number node, defaulting to (0, none)
228219
; respectively if lno is absent (`#f`) or doesn't contain a file
229220
(define (extract-line-file lno)
@@ -241,21 +232,4 @@
241232
""
242233
(string (if exactloc " at " " around ") file ":" line)))
243234

244-
(define (format-syntax-deprecation what instead file line exactloc)
245-
(string "Deprecated syntax `" what "`"
246-
(format-file-line file line exactloc)
247-
"."
248-
(if (equal? instead "") ""
249-
(string #\newline "Use `" instead "` instead."))))
250-
251235
(define *scopewarn-opt* 1)
252-
253-
; Corresponds to --depwarn 0="no", 1="yes", 2="error"
254-
(define *depwarn-opt* 1)
255-
256-
; Emit deprecation warning via julia logging layer.
257-
(define (frontend-depwarn msg file line)
258-
; (display (string msg "; file = " file "; line = " line #\newline)))
259-
(case *depwarn-opt*
260-
(1 (julia-logmsg 1000 'depwarn (symbol (string file line)) file line msg))
261-
(2 (error msg))))

src/julia-parser.scm

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -620,15 +620,6 @@
620620
(define (space-before-next-token? s)
621621
(or (skip-ws (ts:port s) #f) (eqv? #\newline (peek-char (ts:port s)))))
622622

623-
;; --- misc ---
624-
625-
; Log a syntax deprecation, attributing it to current-filename and the line
626-
; number of the stream `s`
627-
(define (parser-depwarn s what instead)
628-
(let ((line (if (number? s) s (input-port-line (if (port? s) s (ts:port s)))))
629-
(file current-filename))
630-
(frontend-depwarn (format-syntax-deprecation what instead file line #t) file line)))
631-
632623
;; --- parser ---
633624

634625
;; parse left-to-right binary operator

src/rtutils.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,27 +1368,6 @@ void jl_log(int level, jl_value_t *module, jl_value_t *group, jl_value_t *id,
13681368
JL_GC_POP();
13691369
}
13701370

1371-
#if 0
1372-
void jl_depwarn(const char *msg, jl_value_t *sym)
1373-
{
1374-
static jl_value_t *depwarn_func = NULL;
1375-
if (!depwarn_func && jl_base_module) {
1376-
depwarn_func = jl_get_global(jl_base_module, jl_symbol("depwarn"));
1377-
}
1378-
if (!depwarn_func) {
1379-
jl_safe_printf("WARNING: %s\n", msg);
1380-
return;
1381-
}
1382-
jl_value_t **depwarn_args;
1383-
JL_GC_PUSHARGS(depwarn_args, 3);
1384-
depwarn_args[0] = depwarn_func;
1385-
depwarn_args[1] = jl_cstr_to_string(msg);
1386-
depwarn_args[2] = sym;
1387-
jl_apply(depwarn_args, 3);
1388-
JL_GC_POP();
1389-
}
1390-
#endif
1391-
13921371
#ifdef __cplusplus
13931372
}
13941373
#endif

0 commit comments

Comments
 (0)