Skip to content

Commit

Permalink
potion #9: fix parser is not re-entrant, but still not GC safe
Browse files Browse the repository at this point in the history
All the intermediate t and lhs objects in the compiler need to
be moved also while in a eval, and be checked for FWDs.
  • Loading branch information
Reini Urban committed Sep 16, 2013
1 parent c6ef921 commit d83d869
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
16 changes: 13 additions & 3 deletions core/syntax.y
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ dec = < ('0' | [1-9][0-9]*) { $$ = YY_TNUM; }
('.' [0-9]+ { $$ = YY_TDEC; })?
('e' [-+] [0-9]+ { $$ = YY_TDEC })? >

q1 = [']
q1 = ['] # ' emacs highlight problems
c1 = < (!q1 utf8)+ > { P->pbuf = potion_asm_write(P, P->pbuf, yytext, yyleng); }
str1 = q1 { P->pbuf = potion_asm_clear(P, P->pbuf); }
< (q1 q1 { P->pbuf = potion_asm_write(P, P->pbuf, "'", 1); } | c1)* >
Expand Down Expand Up @@ -294,6 +294,9 @@ arg-sep = '.' - { P->source = PN_PUSH(P->source, PN_NUM('.')); }

PN potion_parse(Potion *P, PN code, char *filename) {
GREG *G = YY_NAME(parse_new)(P);
int oldyypos = P->yypos;
PN oldinput = P->input;
PN oldsource = P->source;
P->yypos = 0;
P->input = code;
P->source = PN_NIL;
Expand All @@ -308,7 +311,9 @@ PN potion_parse(Potion *P, PN code, char *filename) {
YY_NAME(parse_free)(G);

code = P->source;
P->source = PN_NIL;
P->source = oldsource;
P->yypos = oldyypos;
P->input = oldinput;
return code;
}

Expand All @@ -318,6 +323,9 @@ PN potion_sig(Potion *P, char *fmt) {
if (fmt[0] == '\0') return PN_FALSE; // empty signature, no args

GREG *G = YY_NAME(parse_new)(P);
int oldyypos = P->yypos;
PN oldinput = P->input;
PN oldsource = P->source;
P->yypos = 0;
P->input = potion_byte_str(P, fmt);
P->source = out = PN_TUP0();
Expand All @@ -332,7 +340,9 @@ PN potion_sig(Potion *P, char *fmt) {
YY_NAME(parse_free)(G);

out = P->source;
P->source = PN_NIL;
P->source = oldsource;
P->yypos = oldyypos;
P->input = oldinput;
return out;
}

Expand Down
3 changes: 3 additions & 0 deletions test/flow/eval.pn
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# issue 9 - GC-safe re-entrant parser
1 to 1000000(): 'x = Object()' eval.
#=> 1000000

0 comments on commit d83d869

Please sign in to comment.