free as many as possible!

This commit is contained in:
Yuichi Nishiwaki 2013-11-17 17:33:28 +09:00
parent fdc9bfea4e
commit 9526ca789a
2 changed files with 12 additions and 8 deletions

View File

@ -104,7 +104,6 @@ expand(pic_state *pic, pic_value obj, struct syntactic_env *env)
define_macro(pic, pic_symbol_name(pic, pic_sym(var)), pic_proc_ptr(v)); define_macro(pic, pic_symbol_name(pic, pic_sym(var)), pic_proc_ptr(v));
pic_gc_arena_restore(pic, ai); pic_gc_arena_restore(pic, ai);
pic_gc_protect(pic, v);
return pic_false_value(); return pic_false_value();
} }
macro = lookup_macro(pic, env, pic_symbol_name(pic, sym)); macro = lookup_macro(pic, env, pic_symbol_name(pic, sym));
@ -116,7 +115,11 @@ expand(pic_state *pic, pic_value obj, struct syntactic_env *env)
} }
pic_gc_arena_restore(pic, ai); pic_gc_arena_restore(pic, ai);
pic_gc_protect(pic, v); pic_gc_protect(pic, v);
return expand(pic, v, env);
v = expand(pic, v, env);
pic_gc_arena_restore(pic, ai);
pic_gc_protect(pic, v);
return v;
} }
} }

View File

@ -38,6 +38,7 @@ parser_control_new(pic_state *pic)
p->pic = pic; p->pic = pic;
p->incomp = false; p->incomp = false;
p->yynerrs = 0; p->yynerrs = 0;
p->value = pic_undef_value();
p->yy_arena = pic_vec_new(pic, YY_ARENA_SIZE); p->yy_arena = pic_vec_new(pic, YY_ARENA_SIZE);
p->yy_arena_idx = 0; p->yy_arena_idx = 0;
yylex_init(&p->yyscanner); yylex_init(&p->yyscanner);
@ -375,7 +376,6 @@ pic_parse_file(pic_state *pic, FILE *file, pic_value *v)
yyparse(p); yyparse(p);
if (p->yynerrs > 0) { if (p->yynerrs > 0) {
p->value = pic_undef_value();
r = PIC_PARSER_ERROR; r = PIC_PARSER_ERROR;
} }
else if (p->incomp) { else if (p->incomp) {
@ -385,6 +385,8 @@ pic_parse_file(pic_state *pic, FILE *file, pic_value *v)
r = pic_length(pic, p->value); r = pic_length(pic, p->value);
} }
*v = p->value;
parser_control_destroy(p); parser_control_destroy(p);
#if DEBUG #if DEBUG
@ -395,8 +397,7 @@ pic_parse_file(pic_state *pic, FILE *file, pic_value *v)
pic_gc_arena_restore(pic, ai); pic_gc_arena_restore(pic, ai);
*v = p->value; pic_gc_protect(pic, *v);
pic_gc_protect(pic, p->value);
return r; return r;
} }
@ -413,7 +414,6 @@ pic_parse_cstr(pic_state *pic, const char *str, pic_value *v)
yyparse(p); yyparse(p);
if (p->yynerrs > 0) { if (p->yynerrs > 0) {
p->value = pic_undef_value();
r = PIC_PARSER_ERROR; r = PIC_PARSER_ERROR;
} }
else if (p->incomp) { else if (p->incomp) {
@ -423,6 +423,8 @@ pic_parse_cstr(pic_state *pic, const char *str, pic_value *v)
r = pic_length(pic, p->value); r = pic_length(pic, p->value);
} }
*v = p->value;
parser_control_destroy(p); parser_control_destroy(p);
#if DEBUG #if DEBUG
@ -434,8 +436,7 @@ pic_parse_cstr(pic_state *pic, const char *str, pic_value *v)
pic_gc_arena_restore(pic, ai); pic_gc_arena_restore(pic, ai);
*v = p->value; pic_gc_protect(pic, *v);
pic_gc_protect(pic, p->value);
return r; return r;
} }