develooper Front page | perl.cvs.parrot | Postings from January 2009

[svn:parrot] r34750 - trunk/compilers/pirc/new

From:
kjs
Date:
January 1, 2009 09:05
Subject:
[svn:parrot] r34750 - trunk/compilers/pirc/new
Message ID:
20090101170502.C8B7ECB9FA@x12.develooper.com
Author: kjs
Date: Thu Jan  1 09:05:01 2009
New Revision: 34750

Modified:
   trunk/compilers/pirc/new/hdocprep.c
   trunk/compilers/pirc/new/hdocprep.l
   trunk/compilers/pirc/new/main.c
   trunk/compilers/pirc/new/pircompiler.h
   trunk/compilers/pirc/new/piremit.c
   trunk/compilers/pirc/new/pirheredoc.h

Log:
[pirc] pass a Parrot to the heredoc preprocessor.

Modified: trunk/compilers/pirc/new/hdocprep.c
==============================================================================
--- trunk/compilers/pirc/new/hdocprep.c	(original)
+++ trunk/compilers/pirc/new/hdocprep.c	Thu Jan  1 09:05:01 2009
@@ -31,18 +31,10 @@
 
 /* A lexical scanner generated by flex */
 
-/* %not-for-header */
-
-/* %if-c-only */
-/* %if-not-reentrant */
-/* %endif */
-/* %endif */
-/* %ok-for-header */
-
 #define FLEX_SCANNER
 #define YY_FLEX_MAJOR_VERSION 2
 #define YY_FLEX_MINOR_VERSION 5
-#define YY_FLEX_SUBMINOR_VERSION 35
+#define YY_FLEX_SUBMINOR_VERSION 33
 #if YY_FLEX_SUBMINOR_VERSION > 0
 #define FLEX_BETA
 #endif
@@ -80,7 +72,7 @@
 
 /* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
 
-#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+#if __STDC_VERSION__ >= 199901L
 
 /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
  * if you want the limit (max/min) macros for int types.
@@ -148,12 +140,11 @@
 
 #else   /* ! __cplusplus */
 
-/* C99 requires __STDC__ to be defined as 1. */
-#if defined (__STDC__)
+#if __STDC__
 
 #define YY_USE_CONST
 
-#endif  /* defined (__STDC__) */
+#endif  /* __STDC__ */
 #endif  /* ! __cplusplus */
 
 #ifdef YY_USE_CONST
@@ -197,6 +188,7 @@
 #define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
 #define yy_flex_debug yyg->yy_flex_debug_r
 
+int yylex_init (yyscan_t* scanner);
 /* %endif */
 
 /* %if-not-reentrant */
@@ -280,9 +272,14 @@
 
 #define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
 
+/* The following is because we cannot portably get our hands on size_t
+ * (without autoconf's help, which isn't available because we want
+ * flex-generated scanners to compile on their own).
+ */
+
 #ifndef YY_TYPEDEF_YY_SIZE_T
 #define YY_TYPEDEF_YY_SIZE_T
-typedef size_t yy_size_t;
+typedef unsigned int yy_size_t;
 #endif
 
 #ifndef YY_STRUCT_YY_BUFFER_STATE
@@ -644,8 +641,8 @@
 
 static yyconst flex_int16_t yy_rule_linenum[20] =
     {   0,
-      282,  284,  287,  291,  298,  301,  318,  330,  352,  371,
-      423,  442,  444,  474,  478,  480,  533,  537,  539
+      285,  287,  290,  294,  301,  304,  321,  333,  355,  374,
+      426,  445,  447,  477,  481,  483,  536,  540,  542
     } ;
 
 /* The intent behind this definition is that it'll catch
@@ -661,7 +658,7 @@
 
 /*
  * $Id$
- * Copyright (C) 2007-2008, The Perl Foundation.
+ * Copyright (C) 2007-2009, The Perl Foundation.
  */
 
 /*
@@ -726,6 +723,8 @@
 
     FILE           *outfile;        /* output file; or STDOUT if no file is specified */
 
+    PARROT_INTERP;
+
 } global_state;
 
 /* accessor methods for setting and getting the lexer_state */
@@ -785,7 +784,7 @@
 PARROT_WARN_UNUSED_RESULT
 PARROT_CANNOT_RETURN_NULL
 static global_state *
-init_global_state(NOTNULL(char * const filename), NOTNULL(FILE *outfile)) {
+init_global_state(PARROT_INTERP, NOTNULL(char * const filename), NOTNULL(FILE *outfile)) {
     global_state *state = (global_state *)mem_sys_allocate(sizeof (global_state));
     state->filename     = filename;
     state->heredoc      = NULL;
@@ -794,6 +793,7 @@
     state->file_buffer  = NULL;
     state->errors       = 0;
     state->outfile      = outfile;
+    state->interp       = interp;
 
     return state;
 }
@@ -835,7 +835,7 @@
 
 */
 void
-process_heredocs(NOTNULL(char * const filename), NOTNULL(FILE *outfile)) {
+process_heredocs(PARROT_INTERP, NOTNULL(char * const filename), NOTNULL(FILE *outfile)) {
     yyscan_t      yyscanner;
     global_state *state = NULL;
     FILE         *fp;
@@ -853,7 +853,7 @@
     /* set the scanner to a string buffer and go parse */
     yyset_in(fp,yyscanner);
 
-    state = init_global_state(filename, outfile);
+    state = init_global_state(interp, filename, outfile);
 
     yyset_extra(state,yyscanner);
 
@@ -955,14 +955,8 @@
 
 /* %if-reentrant */
 
-int yylex_init (yyscan_t* scanner);
-
-int yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
-
 /* %endif */
 
-/* %endif End reentrant structures and macros. */
-
 /* Accessor methods to globals.
    These are made visible to non-reentrant scanners for convenience. */
 
@@ -994,6 +988,7 @@
 
 /* %if-bison-bridge */
 /* %endif */
+/* %endif End reentrant structures and macros. */
 
 /* Macros after this point can all be overridden by user definitions in
  * section 1.
@@ -1054,7 +1049,7 @@
 /* This used to be an fputs(), but since the string might contain NUL's,
  * we now use fwrite().
  */
-#define ECHO fwrite( yytext, yyleng, 1, yyout )
+#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
 /* %endif */
 /* %if-c++-only C++ definition */
 /* %endif */
@@ -1069,7 +1064,7 @@
     if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
         { \
         int c = '*'; \
-        int n; \
+        size_t n; \
         for ( n = 0; n < max_size && \
                  (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
             buf[n] = (char) c; \
@@ -1180,10 +1175,10 @@
     struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
 
 /* %% [7.0] user's declarations go here */
-#line 280 "hdocprep.l"
+#line 283 "hdocprep.l"
 
 
-#line 1187 "hdocprep.c"
+#line 1182 "hdocprep.c"
 
     if ( !yyg->yy_init )
         {
@@ -1309,19 +1304,19 @@
 case 1:
 /* rule 1 can match eol */
 YY_RULE_SETUP
-#line 282 "hdocprep.l"
+#line 285 "hdocprep.l"
 { /* ignore line comments */ }
     YY_BREAK
 case 2:
 /* rule 2 can match eol */
 YY_RULE_SETUP
-#line 284 "hdocprep.l"
+#line 287 "hdocprep.l"
 { yy_push_state(POD, yyscanner); }
     YY_BREAK
 case 3:
 /* rule 3 can match eol */
 YY_RULE_SETUP
-#line 287 "hdocprep.l"
+#line 290 "hdocprep.l"
 { /* end of POD comment */
                           yy_pop_state(yyscanner);
                         }
@@ -1329,11 +1324,11 @@
 case 4:
 /* rule 4 can match eol */
 YY_RULE_SETUP
-#line 291 "hdocprep.l"
+#line 294 "hdocprep.l"
 { /* ignore pod comments */ }
     YY_BREAK
 case YY_STATE_EOF(POD):
-#line 293 "hdocprep.l"
+#line 296 "hdocprep.l"
 { /* we're scanning a POD comment, but encountered end-of-file. */
                           lex_error(yyscanner, "POD comment not closed!");
                           yyterminate();
@@ -1342,12 +1337,12 @@
 case 5:
 /* rule 5 can match eol */
 YY_RULE_SETUP
-#line 298 "hdocprep.l"
+#line 301 "hdocprep.l"
 { fprintf(yyget_extra(yyscanner)->outfile, "\n"); }
     YY_BREAK
 case 6:
 YY_RULE_SETUP
-#line 301 "hdocprep.l"
+#line 304 "hdocprep.l"
 {
                           global_state * const state = yyget_extra(yyscanner);
 
@@ -1367,7 +1362,7 @@
 case 7:
 /* rule 7 can match eol */
 YY_RULE_SETUP
-#line 318 "hdocprep.l"
+#line 321 "hdocprep.l"
 { /* match the rest of the line */
                               global_state * const state = yyget_extra(yyscanner);
 
@@ -1383,7 +1378,7 @@
 case 8:
 /* rule 8 can match eol */
 YY_RULE_SETUP
-#line 330 "hdocprep.l"
+#line 333 "hdocprep.l"
 { /* match the rest of the line */
                               global_state * const state = yyget_extra(yyscanner);
 
@@ -1408,7 +1403,7 @@
 case 9:
 /* rule 9 can match eol */
 YY_RULE_SETUP
-#line 352 "hdocprep.l"
+#line 355 "hdocprep.l"
 {
                               global_state * const state = yyget_extra(yyscanner);
 
@@ -1431,7 +1426,7 @@
 case 10:
 /* rule 10 can match eol */
 YY_RULE_SETUP
-#line 371 "hdocprep.l"
+#line 374 "hdocprep.l"
 {
                              global_state * const state = yyget_extra(yyscanner);
 
@@ -1480,7 +1475,7 @@
                            }
     YY_BREAK
 case YY_STATE_EOF(HEREDOC_STRING):
-#line 418 "hdocprep.l"
+#line 421 "hdocprep.l"
 { /* end of file while reading heredoc */
                               lex_error(yyscanner, "runaway heredoc string");
                               yyterminate();
@@ -1488,7 +1483,7 @@
     YY_BREAK
 case 11:
 YY_RULE_SETUP
-#line 423 "hdocprep.l"
+#line 426 "hdocprep.l"
 { /* a 'nested' heredoc string */
                               global_state *state = yyget_extra(yyscanner);
 
@@ -1511,16 +1506,16 @@
 case 12:
 /* rule 12 can match eol */
 YY_RULE_SETUP
-#line 442 "hdocprep.l"
+#line 445 "hdocprep.l"
 { /* do nothing */ }
     YY_BREAK
 case 13:
 YY_RULE_SETUP
-#line 444 "hdocprep.l"
+#line 447 "hdocprep.l"
 { fprintf(yyget_extra(yyscanner)->outfile, "%s", yytext); }
     YY_BREAK
 case YY_STATE_EOF(SCAN_STRING):
-#line 446 "hdocprep.l"
+#line 449 "hdocprep.l"
 {
                               global_state * const state = yyget_extra(yyscanner);
 
@@ -1544,26 +1539,26 @@
                             }
     YY_BREAK
 case YY_STATE_EOF(INITIAL):
-#line 470 "hdocprep.l"
+#line 473 "hdocprep.l"
 { /* end of file */
                               yyterminate();
                             }
     YY_BREAK
 case 14:
 YY_RULE_SETUP
-#line 474 "hdocprep.l"
+#line 477 "hdocprep.l"
 { /* .include directives must be handled here */
                               yy_push_state(INCLUDE, yyscanner);
                             }
     YY_BREAK
 case 15:
 YY_RULE_SETUP
-#line 478 "hdocprep.l"
+#line 481 "hdocprep.l"
 { /* skip whitespace */ }
     YY_BREAK
 case 16:
 YY_RULE_SETUP
-#line 480 "hdocprep.l"
+#line 483 "hdocprep.l"
 { /* include this file */
                               global_state * const state = yyget_extra(yyscanner);
 
@@ -1602,7 +1597,7 @@
                               fprintf(state->outfile, ".line 1\n");
                               fprintf(state->outfile, ".file %s\n", yytext); /* is quoted */
 
-                              process_heredocs(fullpath, state->outfile);
+                              process_heredocs(state->interp, fullpath, state->outfile);
 
                               /* restore the location information; we didn't count the "\n"
                                * yet that will come after the .include dir.; hence the + 1 now.
@@ -1620,27 +1615,27 @@
 case 17:
 /* rule 17 can match eol */
 YY_RULE_SETUP
-#line 533 "hdocprep.l"
+#line 536 "hdocprep.l"
 { /* after .include "foo.pir", go back to the state we were in */
                               yy_pop_state(yyscanner);
                             }
     YY_BREAK
 case 18:
 YY_RULE_SETUP
-#line 537 "hdocprep.l"
+#line 540 "hdocprep.l"
 { lex_error(yyscanner, "wrong scanner state\n"); }
     YY_BREAK
 case 19:
 YY_RULE_SETUP
-#line 539 "hdocprep.l"
+#line 542 "hdocprep.l"
 { fprintf(yyget_extra(yyscanner)->outfile, "%s", yytext); }
     YY_BREAK
 case 20:
 YY_RULE_SETUP
-#line 541 "hdocprep.l"
+#line 544 "hdocprep.l"
 ECHO;
     YY_BREAK
-#line 1644 "hdocprep.c"
+#line 1639 "hdocprep.c"
 case YY_STATE_EOF(INCLUDE):
 case YY_STATE_EOF(SAVE_REST_OF_LINE):
 case YY_STATE_EOF(SAVE_REST_AGAIN):
@@ -1888,7 +1883,7 @@
 
         /* Read in more data. */
         YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
-            yyg->yy_n_chars, (size_t) num_to_read );
+            yyg->yy_n_chars, num_to_read );
 
         YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
         }
@@ -1912,14 +1907,6 @@
     else
         ret_val = EOB_ACT_CONTINUE_SCAN;
 
-    if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
-        /* Extend the array by 50%, plus the number we really need. */
-        yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
-        YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner );
-        if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
-            YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
-    }
-
     yyg->yy_n_chars += number_to_move;
     YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
     YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
@@ -2396,8 +2383,6 @@
         yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc
                                 (num_to_alloc * sizeof(struct yy_buffer_state*)
                                 , yyscanner);
-        if ( ! yyg->yy_buffer_stack )
-            YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
 
         memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
 
@@ -2416,8 +2401,6 @@
                                 (yyg->yy_buffer_stack,
                                 num_to_alloc * sizeof(struct yy_buffer_state*)
                                 , yyscanner);
-        if ( ! yyg->yy_buffer_stack )
-            YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
 
         /* zero only the new slots.*/
         memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
@@ -2466,7 +2449,7 @@
 /* %if-c-only */
 /** Setup the input buffer state to scan a string. The next call to yylex() will
  * scan from a @e copy of @a str.
- * @param yystr a NUL-terminated string to scan
+ * @param str a NUL-terminated string to scan
  * @param yyscanner The scanner object.
  * @return the newly allocated buffer state object.
  * @note If you want to scan bytes that may contain NUL values, then use
@@ -2539,7 +2522,8 @@
             yyg->yy_start_stack = (int *) yyrealloc((void *) yyg->yy_start_stack,new_size ,yyscanner );
 
         if ( ! yyg->yy_start_stack )
-            YY_FATAL_ERROR( "out of memory expanding start-condition stack" );
+            YY_FATAL_ERROR(
+            "out of memory expanding start-condition stack" );
         }
 
     yyg->yy_start_stack[yyg->yy_start_stack_ptr++] = YY_START;
@@ -2780,43 +2764,7 @@
     return yy_init_globals ( *ptr_yy_globals );
 }
 
-/* yylex_init_extra has the same functionality as yylex_init, but follows the
- * convention of taking the scanner as the last argument. Note however, that
- * this is a *pointer* to a scanner, as it will be allocated by this call (and
- * is the reason, too, why this function also must handle its own declaration).
- * The user defined value in the first argument will be available to yyalloc in
- * the yyextra field.
- */
-
-int yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals )
-
-{
-    struct yyguts_t dummy_yyguts;
-
-    yyset_extra (yy_user_defined, &dummy_yyguts);
-
-    if (ptr_yy_globals == NULL){
-        errno = EINVAL;
-        return 1;
-    }
-
-    *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
-
-    if (*ptr_yy_globals == NULL){
-        errno = ENOMEM;
-        return 1;
-    }
-
-    /* By setting to 0xAA, we expose bugs in
-    yy_init_globals. Leave at 0x00 for releases. */
-    memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
-
-    yyset_extra (yy_user_defined, *ptr_yy_globals);
-
-    return yy_init_globals ( *ptr_yy_globals );
-}
-
-/* %endif if-c-only */
+/* %endif */
 
 /* %if-c-only */
 static int yy_init_globals (yyscan_t yyscanner)
@@ -2940,7 +2888,7 @@
 
 /* %ok-for-header */
 
-#line 541 "hdocprep.l"
+#line 544 "hdocprep.l"
 
 
 

Modified: trunk/compilers/pirc/new/hdocprep.l
==============================================================================
--- trunk/compilers/pirc/new/hdocprep.l	(original)
+++ trunk/compilers/pirc/new/hdocprep.l	Thu Jan  1 09:05:01 2009
@@ -28,7 +28,7 @@
 
 /*
  * $Id$
- * Copyright (C) 2007-2008, The Perl Foundation.
+ * Copyright (C) 2007-2009, The Perl Foundation.
  */
 
 /*
@@ -93,6 +93,8 @@
 
     FILE           *outfile;        /* output file; or STDOUT if no file is specified */
 
+    PARROT_INTERP;
+
 } global_state;
 
 /* accessor methods for setting and getting the lexer_state */
@@ -152,7 +154,7 @@
 PARROT_WARN_UNUSED_RESULT
 PARROT_CANNOT_RETURN_NULL
 static global_state *
-init_global_state(NOTNULL(char * const filename), NOTNULL(FILE *outfile)) {
+init_global_state(PARROT_INTERP, NOTNULL(char * const filename), NOTNULL(FILE *outfile)) {
     global_state *state = (global_state *)mem_sys_allocate(sizeof (global_state));
     state->filename     = filename;
     state->heredoc      = NULL;
@@ -161,6 +163,7 @@
     state->file_buffer  = NULL;
     state->errors       = 0;
     state->outfile      = outfile;
+    state->interp       = interp;
 
     return state;
 }
@@ -202,7 +205,7 @@
 
 */
 void
-process_heredocs(NOTNULL(char * const filename), NOTNULL(FILE *outfile)) {
+process_heredocs(PARROT_INTERP, NOTNULL(char * const filename), NOTNULL(FILE *outfile)) {
     yyscan_t      yyscanner;
     global_state *state = NULL;
     FILE         *fp;
@@ -220,7 +223,7 @@
     /* set the scanner to a string buffer and go parse */
     yyset_in(fp, yyscanner);
 
-    state = init_global_state(filename, outfile);
+    state = init_global_state(interp, filename, outfile);
 
     yyset_extra(state, yyscanner);
 
@@ -515,7 +518,7 @@
                               fprintf(state->outfile, ".line 1\n");
                               fprintf(state->outfile, ".file %s\n", yytext); /* is quoted */
 
-                              process_heredocs(fullpath, state->outfile);
+                              process_heredocs(state->interp, fullpath, state->outfile);
 
                               /* restore the location information; we didn't count the "\n"
                                * yet that will come after the .include dir.; hence the + 1 now.

Modified: trunk/compilers/pirc/new/main.c
==============================================================================
--- trunk/compilers/pirc/new/main.c	(original)
+++ trunk/compilers/pirc/new/main.c	Thu Jan  1 09:05:01 2009
@@ -301,18 +301,18 @@
 
     if (outputfile != NULL && TEST_FLAG(flags, LEXER_FLAG_HEREDOCONLY)) {
         file = open_file(outputfile, "w");
-        process_heredocs(argv[0], file);
+        process_heredocs(interp, argv[0], file);
         fclose(file);
         return 0;
     }
     else if (TEST_FLAG(flags, LEXER_FLAG_HEREDOCONLY)) {
-        process_heredocs(argv[0], stdout);
+        process_heredocs(interp, argv[0], stdout);
         return 0;
     }
     else {
         hdocoutfile = _tempnam(NULL, "hdoc");
         file = open_file(hdocoutfile, "w");
-        process_heredocs(argv[0], file);
+        process_heredocs(interp, argv[0], file);
         fclose(file);
     }
 

Modified: trunk/compilers/pirc/new/pircompiler.h
==============================================================================
--- trunk/compilers/pirc/new/pircompiler.h	(original)
+++ trunk/compilers/pirc/new/pircompiler.h	Thu Jan  1 09:05:01 2009
@@ -1,6 +1,6 @@
 /*
  * $Id$
- * Copyright (C) 2007-2008, The Perl Foundation.
+ * Copyright (C) 2007-2009, The Perl Foundation.
  */
 
 #ifndef PARROT_PIR_PIRCOMPILER_H_GUARD

Modified: trunk/compilers/pirc/new/piremit.c
==============================================================================
--- trunk/compilers/pirc/new/piremit.c	(original)
+++ trunk/compilers/pirc/new/piremit.c	Thu Jan  1 09:05:01 2009
@@ -1,6 +1,6 @@
 /*
  * $Id$
- * Copyright (C) 2008, The Perl Foundation.
+ * Copyright (C) 2008-2009, The Perl Foundation.
  */
 
 #include <stdio.h>

Modified: trunk/compilers/pirc/new/pirheredoc.h
==============================================================================
--- trunk/compilers/pirc/new/pirheredoc.h	(original)
+++ trunk/compilers/pirc/new/pirheredoc.h	Thu Jan  1 09:05:01 2009
@@ -1,6 +1,6 @@
 /*
  * $Id$
- * Copyright (C) 2008, The Perl Foundation.
+ * Copyright (C) 2008-2009, The Perl Foundation.
  */
 
 
@@ -9,7 +9,7 @@
 
 #include <stdio.h> /* for FILE */
 
-void process_heredocs(char * const filename, FILE *outputfile);
+void process_heredocs(PARROT_INTERP, char * const filename, FILE *outputfile);
 
 #endif /* PARROT_PIR_PIRHEREDOC_H_GUARD */
 



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About