From: Dave Mitchell Date: Mon, 1 Jan 2007 22:37:40 +0000 (+0000) Subject: split parser initialisation from parser execution X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=acdf0a21427feb34aec09f6fd2cf505bb7b2fe2c;p=p5sagit%2Fp5-mst-13.2.git split parser initialisation from parser execution p4raw-id: //depot/perl@29652 --- diff --git a/embed.fnc b/embed.fnc index 0294389..36d57e6 100644 --- a/embed.fnc +++ b/embed.fnc @@ -956,6 +956,7 @@ p |void |write_to_stderr|NN const char* message|int msglen p |int |yyerror |NN const char* s p |int |yylex p |int |yyparse +p |void |parser_free |NN const yy_parser * p |int |yywarn |NN const char* s #if defined(MYMALLOC) Ap |void |dump_mstats |NN char* s diff --git a/embed.h b/embed.h index f2fa696..d948188 100644 --- a/embed.h +++ b/embed.h @@ -976,6 +976,7 @@ #define yyerror Perl_yyerror #define yylex Perl_yylex #define yyparse Perl_yyparse +#define parser_free Perl_parser_free #define yywarn Perl_yywarn #endif #if defined(MYMALLOC) @@ -3183,6 +3184,7 @@ #define yyerror(a) Perl_yyerror(aTHX_ a) #define yylex() Perl_yylex(aTHX) #define yyparse() Perl_yyparse(aTHX) +#define parser_free(a) Perl_parser_free(aTHX_ a) #define yywarn(a) Perl_yywarn(aTHX_ a) #endif #if defined(MYMALLOC) diff --git a/parser.h b/parser.h index 9a61a52..89d1c6c 100644 --- a/parser.h +++ b/parser.h @@ -9,6 +9,8 @@ * and lexer (perly.c, toke,c). */ +#define YYEMPTY (-2) + typedef struct { YYSTYPE val; /* semantic value */ short state; diff --git a/perly.c b/perly.c index bf239fa..36f78a3 100644 --- a/perly.c +++ b/perly.c @@ -45,7 +45,6 @@ typedef signed char yysigned_char; # define YYSIZE_T size_t -#define YYEMPTY (-2) #define YYEOF 0 #define YYTERROR 1 @@ -187,9 +186,6 @@ do { \ # define YY_REDUCE_PRINT(Rule) #endif /* !DEBUGGING */ -/* YYINITDEPTH -- initial size of the parser's stacks. */ -#define YYINITDEPTH 200 - /* called during cleanup (via SAVEDESTRUCTOR_X) to free any items on the * parse stack, thus avoiding leaks if we die */ @@ -300,8 +296,8 @@ S_clear_yystack(pTHX_ const yy_parser *parser) /* delete a parser object */ -static void -S_parser_free(pTHX_ const yy_parser *parser) +void +Perl_parser_free(pTHX_ const yy_parser *parser) { S_clear_yystack(aTHX_ parser); Safefree(parser->stack); @@ -334,7 +330,7 @@ Perl_yyparse (pTHX) #define YYPOPSTACK parser->ps = --ps #define YYPUSHSTACK parser->ps = ++ps - /* The variables used to return semantic value and location from the + /* The variable used to return semantic value and location from the action routines: ie $$. */ YYSTYPE yyval; @@ -347,22 +343,11 @@ Perl_yyparse (pTHX) YYDPRINTF ((Perl_debug_log, "Starting parse\n")); - Newx(parser, 1, yy_parser); - parser->old_parser = PL_parser; - PL_parser = parser; - - Newx(ps, YYINITDEPTH, yy_stack_frame); - parser->stack = ps; - parser->ps = ps; - parser->stack_size = YYINITDEPTH; + parser = PL_parser; + ps = parser->ps; ENTER; /* force parser free before we return */ - SAVEDESTRUCTOR_X(S_parser_free, (void*) parser); - - - ps->state = 0; - parser->yyerrstatus = 0; - parser->yychar = YYEMPTY; /* Cause a token to be read. */ + SAVEDESTRUCTOR_X(Perl_parser_free, (void*) parser); /*------------------------------------------------------------. | yynewstate -- Push a new state, which is found in yystate. | diff --git a/proto.h b/proto.h index 23e5857..27f830b 100644 --- a/proto.h +++ b/proto.h @@ -2597,6 +2597,9 @@ PERL_CALLCONV int Perl_yyerror(pTHX_ const char* s) PERL_CALLCONV int Perl_yylex(pTHX); PERL_CALLCONV int Perl_yyparse(pTHX); +PERL_CALLCONV void Perl_parser_free(pTHX_ const yy_parser *) + __attribute__nonnull__(pTHX_1); + PERL_CALLCONV int Perl_yywarn(pTHX_ const char* s) __attribute__nonnull__(pTHX_1); diff --git a/toke.c b/toke.c index 7277d89..db265b3 100644 --- a/toke.c +++ b/toke.c @@ -25,6 +25,9 @@ #define yylval (PL_parser->yylval) +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#define YYINITDEPTH 200 + static const char ident_too_long[] = "Identifier too long"; static const char commaless_variable_list[] = "comma-less variable list"; @@ -580,6 +583,23 @@ Perl_lex_start(pTHX_ SV *line) dVAR; const char *s; STRLEN len; + yy_parser *parser; + + /* create and initialise a parser */ + + Newx(parser, 1, yy_parser); + parser->old_parser = PL_parser; + PL_parser = parser; + + Newx(parser->stack, YYINITDEPTH, yy_stack_frame); + parser->ps = parser->stack; + parser->stack_size = YYINITDEPTH; + + parser->stack->state = 0; + parser->yyerrstatus = 0; + parser->yychar = YYEMPTY; /* Cause a token to be read. */ + + /* initialise lexer state */ SAVEI32(PL_lex_dojoin); SAVEI32(PL_lex_brackets);