develooper Front page | perl.cvs.parrot | Postings from December 2008

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

From:
kjs
Date:
December 27, 2008 05:15
Subject:
[svn:parrot] r34422 - trunk/compilers/pirc/new
Message ID:
20081227131536.1A78FCBA12@x12.develooper.com
Author: kjs
Date: Sat Dec 27 05:15:35 2008
New Revision: 34422

Modified:
   trunk/compilers/pirc/new/bcgen.c
   trunk/compilers/pirc/new/main.c
   trunk/compilers/pirc/new/piremit.c

Log:
[pirc] add a parse_string function, which takes a PIR string. 
+ parse_file+parse_string() need to be refactored, but for now this works.
+ add a PARROT_ASSERT on filename in bcgen.c:new_bytecode(); this cannot be NULL.

Modified: trunk/compilers/pirc/new/bcgen.c
==============================================================================
--- trunk/compilers/pirc/new/bcgen.c	(original)
+++ trunk/compilers/pirc/new/bcgen.c	Sat Dec 27 05:15:35 2008
@@ -227,6 +227,7 @@
     bc->interp        = interp;
 
     /* create segments */
+    PARROT_ASSERT(filename != NULL);
     interp->code      = PF_create_default_segs(interp, filename, 1);
 
     /* add interpreter globals to bytecode. XXX Why is this? */

Modified: trunk/compilers/pirc/new/main.c
==============================================================================
--- trunk/compilers/pirc/new/main.c	(original)
+++ trunk/compilers/pirc/new/main.c	Sat Dec 27 05:15:35 2008
@@ -220,6 +220,70 @@
 
 /*
 
+Parse a PIR string.
+
+*/
+void
+parse_string(char *pirstring, int flags, int pasminput, unsigned macro_size) {
+    yyscan_t yyscanner;
+    lexer_state *lexer = NULL;
+
+
+    /* create a yyscan_t object */
+    yypirlex_init(&yyscanner);
+
+    yypirset_debug(0, yyscanner);
+
+
+    /* set the extra parameter in the yyscan_t structure */
+    lexer = new_lexer("<pir string>", flags);
+    lexer->macro_size = macro_size;
+    yypirset_extra(lexer, yyscanner);
+    lexer->yyscanner = yyscanner;
+
+    /* initialize the scanner state */
+    init_scanner_state(yyscanner);
+
+    /* set the scanner to a string buffer and go parse */
+    yypir_scan_string(pirstring, yyscanner);
+
+    if (pasminput) { /* PASM mode */
+        SET_FLAG(lexer->flags, LEXER_FLAG_PASMFILE);
+    }
+
+
+    yypirparse(yyscanner, lexer);
+
+    if (lexer->parse_errors == 0) {
+
+        print_subs(lexer);
+
+        if (TEST_FLAG(lexer->flags, LEXER_FLAG_WARNINGS))
+            check_unused_symbols(lexer);
+    }
+
+    /* there may have been errors during the instruction generation, check again here. */
+    if (lexer->parse_errors > 0)
+        fprintf(stderr, "There were %d errors\n", lexer->parse_errors);
+
+    /* XXX just want to make sure pirc doesn't segfault when doing bytecode stuff. */
+    if (TEST_FLAG(lexer->flags, LEXER_FLAG_OUTPUTPBC)) {
+        emit_pbc(lexer);
+    }
+
+
+    fprintf(stderr, "ok\n");
+    /* clean up after playing */
+    release_resources(lexer);
+
+       /* clean up after playing */
+    yypirlex_destroy(yyscanner);
+
+
+}
+
+/*
+
 temporary function for the thread-testing code.
 Unpack the arguments and invoke parse_file().
 
@@ -269,6 +333,12 @@
     argv++;
 
 
+    /* XXX test the parse_string() function. */
+    /*
+    parse_string(".sub main :main\nprint 42\n.end\n", LEXER_FLAG_OUTPUTPBC, 0, INIT_MACRO_SIZE);
+    return 0;
+    */
+
 
     /* XXX very basic argument handling; I'm too lazy to check out
      * the standard funtion for that, right now. This is a TODO. */

Modified: trunk/compilers/pirc/new/piremit.c
==============================================================================
--- trunk/compilers/pirc/new/piremit.c	(original)
+++ trunk/compilers/pirc/new/piremit.c	Sat Dec 27 05:15:35 2008
@@ -9,6 +9,8 @@
 #include "pircompiler.h"
 #include "bcgen.h"
 
+#include "assert.h"
+
 /*
 
 =head1 FUNCTIONS
@@ -542,11 +544,15 @@
     if (lexer->subs == NULL)
         return;
 
+    fprintf(stderr, "emit_pbc(): starting...\n");
+
     lexer->bc = new_bytecode(lexer->interp, lexer->filename,
                              lexer->codesize * 4, lexer->codesize);
 
+    fprintf(stderr, "ok 1\n");
     subiter = lexer->subs->next;
 
+    assert(subiter);
     /* iterate over all instructions and emit them */
     do {
         fprintf(stderr, "start offset of sub '%s' is: %d\tend offest: %d\n",



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