Skip to content

Commit

Permalink
Merge pull request #20777 from JuliaLang/jb/FEfixes
Browse files Browse the repository at this point in the history
fix two front-end issues
  • Loading branch information
JeffBezanson authored Feb 24, 2017
2 parents 00b7b60 + dfe2dfb commit 1e44282
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 31 deletions.
10 changes: 5 additions & 5 deletions src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,15 +663,15 @@ static value_t julia_to_scm(fl_context_t *fl_ctx, jl_value_t *v)
temp = julia_to_scm_(fl_ctx, v);
}
FL_CATCH_EXTERN(fl_ctx) {
temp = fl_list2(fl_ctx, jl_ast_ctx(fl_ctx)->error_sym, cvalue_static_cstring(fl_ctx, "expression too large"));
temp = fl_ctx->lasterror;
}
return temp;
}

static void array_to_list(fl_context_t *fl_ctx, jl_array_t *a, value_t *pv)
{
if (jl_array_len(a) > 300000)
lerror(fl_ctx, fl_ctx->OutOfMemoryError, "expression too large");
lerror(fl_ctx, symbol(fl_ctx, "error"), "expression too large");
value_t temp;
for(long i=jl_array_len(a)-1; i >= 0; i--) {
*pv = fl_cons(fl_ctx, fl_ctx->NIL, *pv);
Expand All @@ -694,7 +694,7 @@ static value_t julia_to_list2(fl_context_t *fl_ctx, jl_value_t *a, jl_value_t *b
static value_t julia_to_scm_(fl_context_t *fl_ctx, jl_value_t *v)
{
if (v == NULL)
jl_error("undefined reference in AST");
lerror(fl_ctx, symbol(fl_ctx, "error"), "undefined reference in AST");
if (jl_is_symbol(v))
return symbol(fl_ctx, jl_symbol_name((jl_sym_t*)v));
if (v == jl_true)
Expand Down Expand Up @@ -749,9 +749,9 @@ static value_t julia_to_scm_(fl_context_t *fl_ctx, jl_value_t *v)
if (jl_is_long(v) && fits_fixnum(jl_unbox_long(v)))
return fixnum(jl_unbox_long(v));
if (jl_is_ssavalue(v))
jl_error("SSAValue objects should not occur in an AST");
lerror(fl_ctx, symbol(fl_ctx, "error"), "SSAValue objects should not occur in an AST");
if (jl_is_slot(v))
jl_error("Slot objects should not occur in an AST");
lerror(fl_ctx, symbol(fl_ctx, "error"), "Slot objects should not occur in an AST");
value_t opaque = cvalue(fl_ctx, jl_ast_ctx(fl_ctx)->jvtype, sizeof(void*));
*(jl_value_t**)cv_data((cvalue_t*)ptr(opaque)) = v;
return opaque;
Expand Down
45 changes: 20 additions & 25 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1020,27 +1020,24 @@
((#\( )
(if (ts:space? s) (disallowed-space ex t))
(take-token s)
(if macrocall?
(let ((args (if (eqv? (require-token s) #\) )
(begin (take-token s) '())
(begin0 (with-normal-ops
(with-whitespace-newline
(parse-comma-separated s parse-eq* #t)))
(if (not (eqv? (require-token s) #\) ))
(error "missing ) in argument list"))
(take-token s)))))
`(call ,ex ,@args))
(loop (let ((al (parse-arglist s #\) )))
(receive
(params args) (separate (lambda (x)
(and (pair? x)
(eq? (car x) 'parameters)))
al)
(if (eq? (peek-token s) 'do)
(begin
(take-token s)
`(call ,ex ,@params ,(parse-do s) ,@args))
`(call ,ex ,@al)))))))
(let ((c (let ((al (parse-arglist s #\) )))
(receive
(params args) (separate (lambda (x)
(and (pair? x)
(eq? (car x) 'parameters)))
al)
(if (eq? (peek-token s) 'do)
(begin
(take-token s)
`(call ,ex ,@params ,(parse-do s) ,@args))
`(call ,ex ,@al))))))
(if macrocall?
(map (lambda (x) ;; parse `a=b` as `=` instead of `kw` in macrocall
(if (and (pair? x) (eq? (car x) 'kw))
`(= ,@(cdr x))
x))
c)
(loop c))))
((#\[ )
(if (ts:space? s) (disallowed-space ex t))
(take-token s)
Expand Down Expand Up @@ -1473,15 +1470,13 @@
`(,word ,@(reverse path)))))))

;; parse comma-separated assignments, like "i=1:n,j=1:m,..."
(define (parse-comma-separated s what (in-parens #f))
(define (parse-comma-separated s what)
(let loop ((exprs '()))
(let ((r (what s)))
(case (peek-token s)
((#\,)
(take-token s)
(if (and in-parens (eqv? (require-token s) #\) ))
(reverse! (cons r exprs))
(loop (cons r exprs))))
(loop (cons r exprs)))
(else (reverse! (cons r exprs)))))))

(define (parse-comma-separated-assignments s)
Expand Down
2 changes: 2 additions & 0 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3559,6 +3559,8 @@ f(x) = yt(x)
'(null)))
((...)
(error "\"...\" expression outside call"))
((error)
(error (cadr e)))
(else
(error (string "invalid syntax " (deparse e)))))))
;; introduce new slots for assigned arguments
Expand Down
13 changes: 12 additions & 1 deletion test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1032,4 +1032,15 @@ macro m20729()
return ex
end

@test_throws ErrorException expand(:(@m20729))
@test_throws ErrorException eval(:(@m20729))
@test expand(:(@m20729)) == Expr(:error, "undefined reference in AST")

macro err20000()
return Expr(:error, "oops!")
end

@test expand(:(@err20000)) == Expr(:error, "oops!")

# issue #20000
@test parse("@m(a; b=c)") == Expr(:macrocall, Symbol("@m"),
Expr(:parameters, Expr(:kw, :b, :c)), :a)

0 comments on commit 1e44282

Please sign in to comment.