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 1c76ece commit d23c65c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
14 changes: 12 additions & 2 deletions syn/syntax.y
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ arg-sep = '.' - { SRC_TPL1(PN_NUM('.')) } #x,y... ignore rest

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 @@ -367,7 +370,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 Down Expand Up @@ -403,6 +408,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 @@ -414,7 +422,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;
}
/** look for name in sig tuple in the given function and return the position.
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 d23c65c

Please sign in to comment.