Author: kjs
Date: Thu Jan  1 08:59:27 2009
New Revision: 34748

Modified:
   trunk/compilers/pirc/new/main.c
   trunk/compilers/pirc/new/pircapi.c
   trunk/compilers/pirc/new/pircapi.h
   trunk/compilers/pirc/new/pircompiler.c
   trunk/compilers/pirc/new/pircompiler.h
   trunk/compilers/pirc/new/piremit.c

Log:
[pirc] create a Parrot earlier in the startup process. Pass it as an extra 
parameter.

Modified: trunk/compilers/pirc/new/main.c
==============================================================================
--- trunk/compilers/pirc/new/main.c     (original)
+++ trunk/compilers/pirc/new/main.c     Thu Jan  1 08:59:27 2009
@@ -127,8 +127,9 @@
     char        *filename  = args->filename;
     int          thr_id    = args->thr_id;
     int          flags     = args->flags;
+    PARROT_INTERP          = Parrot_new(NULL);
 
-    parse_file(flexdebug, infile, filename, flags, thr_id, INIT_MACRO_SIZE, 
NULL);
+    parse_file(interp, flexdebug, infile, filename, flags, thr_id, 
INIT_MACRO_SIZE, NULL);
 
     return NULL;
 }
@@ -155,7 +156,7 @@
     char              *outputfile   = NULL;
     char              *hdocoutfile  = NULL;
     unsigned           macrosize    = INIT_MACRO_SIZE;
-
+    PARROT_INTERP                   = Parrot_new(NULL);
 
     /* skip program name */
     argc--;
@@ -325,7 +326,7 @@
         exit(EXIT_FAILURE);
     }
 
-    parse_file(flexdebug, file, filename, flags, 0, macrosize, outputfile);
+    parse_file(interp, flexdebug, file, filename, flags, 0, macrosize, 
outputfile);
     fprintf(stderr, "done\n");
 }
 #endif

Modified: trunk/compilers/pirc/new/pircapi.c
==============================================================================
--- trunk/compilers/pirc/new/pircapi.c  (original)
+++ trunk/compilers/pirc/new/pircapi.c  Thu Jan  1 08:59:27 2009
@@ -29,6 +29,9 @@
 void init_scanner_state(yyscan_t yyscanner);
 
 
+static Parrot_mutex eval_nr_lock;
+static INTVAL       eval_nr  = 0;
+
 /*
 
 =item C<FILE *
@@ -66,8 +69,8 @@
 
 
 void
-parse_file(int flexdebug, FILE *infile, char * const filename, int flags, int 
thr_id,
-           unsigned macro_size, char * const outputfile)
+parse_file(PARROT_INTERP, int flexdebug, FILE *infile, char * const filename, 
int flags,
+           int thr_id, unsigned macro_size, char * const outputfile)
 {
     yyscan_t     yyscanner;
     lexer_state *lexer     = NULL;
@@ -79,7 +82,7 @@
     /* set the input file */
     yypirset_in(infile, yyscanner);
     /* set the extra parameter in the yyscan_t structure */
-    lexer = new_lexer(filename, flags);
+    lexer = new_lexer(interp, filename, flags);
     lexer->macro_size = macro_size;
 
     /* initialize the scanner state */
@@ -149,10 +152,25 @@
 
 */
 void
-parse_string(char *pirstring, int flags, int pasminput, unsigned macro_size) {
-    yyscan_t yyscanner;
-    lexer_state *lexer = NULL;
+parse_string(PARROT_INTERP, char *pirstring, int flags, int pasminput, 
unsigned macro_size) {
+    yyscan_t            yyscanner;
+    lexer_state        *lexer = NULL;
+    char                name[64];
+    PackFile_ByteCode  *old_cs, *new_cs;
+    INTVAL              eval_number;
+
+
+    if (eval_nr == 0)
+        MUTEX_INIT(eval_nr_lock);
+
+    LOCK(eval_nr_lock);
+    eval_number = ++eval_nr;
+    UNLOCK(eval_nr_lock);
+
+    snprintf(name, sizeof (name), "EVAL_" INTVAL_FMT, eval_number);
 
+    new_cs = PF_create_default_segs(interp, name, 0);
+    old_cs = Parrot_switch_to_cs(interp, new_cs, 0);
 
     /* create a yyscan_t object */
     yypirlex_init(&yyscanner);
@@ -161,7 +179,7 @@
 
 
     /* set the extra parameter in the yyscan_t structure */
-    lexer = new_lexer("<pir string>", flags);
+    lexer = new_lexer(interp, name, flags);
     lexer->macro_size = macro_size;
     yypirset_extra(lexer, yyscanner);
     lexer->yyscanner = yyscanner;

Modified: trunk/compilers/pirc/new/pircapi.h
==============================================================================
--- trunk/compilers/pirc/new/pircapi.h  (original)
+++ trunk/compilers/pirc/new/pircapi.h  Thu Jan  1 08:59:27 2009
@@ -10,10 +10,10 @@
 
 FILE * open_file(char const * const filename, char const * const mode);
 
-void parse_string(char *pirstring, int flags, int pasminput, unsigned 
macro_size);
+void parse_string(PARROT_INTERP, char *pirstring, int flags, int pasminput, 
unsigned macro_size);
 
-void parse_file(int flexdebug, FILE *infile, char * const filename, int flags, 
int thr_id,
-                unsigned macro_size, char * const outputfile);
+void parse_file(PARROT_INTERP, int flexdebug, FILE *infile, char * const 
filename, int flags,
+                int thr_id, unsigned macro_size, char * const outputfile);
 
 #endif /* PARROT_PIR_PIRCAPI_H_GUARD */
 

Modified: trunk/compilers/pirc/new/pircompiler.c
==============================================================================
--- trunk/compilers/pirc/new/pircompiler.c      (original)
+++ trunk/compilers/pirc/new/pircompiler.c      Thu Jan  1 08:59:27 2009
@@ -1,6 +1,6 @@
 /*
  * $Id$
- * Copyright (C) 2007-2008, The Perl Foundation.
+ * Copyright (C) 2007-2009, The Perl Foundation.
  */
 
 #include <stdlib.h>
@@ -161,21 +161,20 @@
 PARROT_CANNOT_RETURN_NULL
 PARROT_WARN_UNUSED_RESULT
 lexer_state *
-new_lexer(NULLOK(char * const filename), int flags) {
+new_lexer(PARROT_INTERP, NULLOK(char * const filename), int flags) {
     lexer_state *lexer       = mem_allocate_zeroed_typed(lexer_state);
     lexer->filename          = filename;
-    lexer->interp            = Parrot_new(NULL);
+    lexer->interp            = interp;
     lexer->flags             = flags;
     lexer->mem_allocations   = new_mem_ptrs_block();
 
+
     /* the PIR register generator must start counting at -2 (the value is 
pre-decremented
      * before returning, hence -1), because -1 is the value for unassigned PASM
      * registers.
      */
     lexer->pir_reg_generator = -1;
 
-    if (!lexer->interp)
-        panic(lexer, "Failed to create a Parrot interpreter structure.");
 
     /* create a hashtable to store all strings */
     init_hashtable(lexer, &lexer->strings, HASHTABLE_SIZE_INIT);

Modified: trunk/compilers/pirc/new/pircompiler.h
==============================================================================
--- trunk/compilers/pirc/new/pircompiler.h      (original)
+++ trunk/compilers/pirc/new/pircompiler.h      Thu Jan  1 08:59:27 2009
@@ -150,7 +150,7 @@
 
 
 /* constructor for a lexer_state object */
-lexer_state *new_lexer(char * const filename, int flags);
+lexer_state *new_lexer(PARROT_INTERP, char * const filename, int flags);
 
 void release_resources(lexer_state *lexer);
 

Modified: trunk/compilers/pirc/new/piremit.c
==============================================================================
--- trunk/compilers/pirc/new/piremit.c  (original)
+++ trunk/compilers/pirc/new/piremit.c  Thu Jan  1 08:59:27 2009
@@ -748,7 +748,9 @@
 
     /* XXX why does this not work? */
     if (TEST_FLAG(sub->flags, PIRC_SUB_FLAG_IMMEDIATE)) {
+        fprintf(stderr, "running :immediate sub %s...", sub->info.subname);
         PackFile_fixup_subs(lexer->interp, PBC_IMMEDIATE, NULL);
+        fprintf(stderr, "done\n");
     }
 }
 

Reply via email to