Skip to content

Commit

Permalink
more compiler hardening, better syntax error diagnose
Browse files Browse the repository at this point in the history
  • Loading branch information
Reini Urban committed Jan 8, 2015
1 parent 5af1a8c commit cf3d27b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions core/compile.c
Expand Up @@ -708,6 +708,12 @@ void potion_source_asmb(Potion *P, struct PNProto * volatile f, struct PNLoop *l
//fprintf(stderr, "* loop takes no args, just a block");
goto loopfunc;
}
if (!t->a[2]) {
if (PN_S(t,0) == PN_while)
return potion_syntax_error(P, t, "Missing while body");
else
return potion_syntax_error(P, t, "Missing loop body");
}
potion_source_asmb(P, f, &l, 0, t->a[2], reg);
PN_ASM1(OP_JMP, (jmp2 - PN_OP_LEN(f->asmb)) - 1);
if (PN_S(t,0) == PN_while) {
Expand All @@ -720,6 +726,8 @@ void potion_source_asmb(Potion *P, struct PNProto * volatile f, struct PNLoop *l
PN_OP_AT(f->asmb, l.cjmps[i]).a = (jmp2 - l.cjmps[i]) - 1;
}
} else if (t->part == AST_MSG && PN_S(t,0) == PN_return) {
//if (!t->a[1])
// return potion_syntax_error(P, t, "Missing return value");
PN_ARG_TABLE(PN_S(t,1), reg, 0);
PN_ASM1(OP_RETURN, reg);
} else if (t->part == AST_MSG && PN_S(t,0) == PN_break) {
Expand Down
2 changes: 1 addition & 1 deletion core/internal.c
Expand Up @@ -293,7 +293,7 @@ void potion_syntax_error(Potion *P, struct PNSource *t, const char *fmt, ...) {
va_start(args, fmt);
pn_printf(P, out, fmt, args);
va_end(args);
fprintf(stderr, "** Syntax error %s at %s:%d\n", PN_STR_PTR(out),
fprintf(stderr, "** Syntax error: %s at \"%s\", line %d\n", PN_STR_PTR(out),
AS_STR(t->line), t->loc.lineno);
exit(PN_EXIT_FATAL);
}
Expand Down

0 comments on commit cf3d27b

Please sign in to comment.