[svn:parrot] r46491 - trunk/compilers/imcc

plobsing at svn.parrot.org plobsing at svn.parrot.org
Tue May 11 06:39:19 UTC 2010


Author: plobsing
Date: Tue May 11 06:39:18 2010
New Revision: 46491
URL: https://trac.parrot.org/parrot/changeset/46491

Log:
[IMCC] consolidate root-level error handling into one place

Modified:
   trunk/compilers/imcc/imc.h
   trunk/compilers/imcc/imcc.l
   trunk/compilers/imcc/imclexer.c
   trunk/compilers/imcc/main.c
   trunk/compilers/imcc/parser.h

Modified: trunk/compilers/imcc/imc.h
==============================================================================
--- trunk/compilers/imcc/imc.h	Tue May 11 05:56:25 2010	(r46490)
+++ trunk/compilers/imcc/imc.h	Tue May 11 06:39:18 2010	(r46491)
@@ -56,8 +56,11 @@
 
 #define IMCC_THROW(a, x)  longjmp((a), (x))
 
-#define IMCC_FATAL_EXCEPTION      1
-#define IMCC_FATALY_EXCEPTION     2
+enum {
+    IMCC_FATAL_EXCEPTION     = 1,
+    IMCC_FATALY_EXCEPTION    = 2,
+    IMCC_PARSEFAIL_EXCEPTION = 3,
+};
 
 #define N_ELEMENTS(x) (sizeof (x)/sizeof ((x)[0]))
 

Modified: trunk/compilers/imcc/imcc.l
==============================================================================
--- trunk/compilers/imcc/imcc.l	Tue May 11 05:56:25 2010	(r46490)
+++ trunk/compilers/imcc/imcc.l	Tue May 11 06:39:18 2010	(r46491)
@@ -41,7 +41,7 @@
 #include "imc.h"
 #include "parser.h"
 
-typedef struct yyguts_t       yyguts_t;
+// typedef struct yyguts_t       yyguts_t;
 typedef struct parser_state_t parser_state_t;
 
 /* parser state structure
@@ -1332,20 +1332,7 @@
 
     emit_open(interp, 1, NULL);
 
-    IMCC_TRY(IMCC_INFO(interp)->jump_buf, IMCC_INFO(interp)->error_code) {
-        yyparse(yyscanner, interp);
-        imc_compile_all_units(interp);
-    }
-
-    IMCC_CATCH(IMCC_FATAL_EXCEPTION) {
-        IMCC_INFO(interp)->error_code = IMCC_FATAL_EXCEPTION;
-    }
-
-    IMCC_CATCH(IMCC_FATALY_EXCEPTION) {
-        IMCC_INFO(interp)->error_code = IMCC_FATALY_EXCEPTION;
-    }
-
-    IMCC_END_TRY;
+    imcc_run_compilation(interp, yyscanner);
 
     if (buffer)
         yy_switch_to_buffer(buffer, yyscanner);
@@ -1361,10 +1348,24 @@
     buffer                            = YY_CURRENT_BUFFER;
 
     yy_scan_string(s, yyscanner);
+
     emit_open(interp, 1, NULL);
 
+    imcc_run_compilation(interp, yyscanner);
+
+    if (buffer)
+        yy_switch_to_buffer(buffer, yyscanner);
+}
+
+void
+imcc_run_compilation(PARROT_INTERP, void *yyscanner) {
     IMCC_TRY(IMCC_INFO(interp)->jump_buf, IMCC_INFO(interp)->error_code) {
-        yyparse(yyscanner, interp);
+        if (yyparse(yyscanner, interp)) {
+            IMCC_INFO(interp)->error_code    = IMCC_PARSEFAIL_EXCEPTION;
+            IMCC_INFO(interp)->error_message = string_from_literal(interp, "syntax error ... somewhere");
+            return;
+        }
+
         imc_compile_all_units(interp);
     }
 
@@ -1377,9 +1378,6 @@
     }
 
     IMCC_END_TRY;
-
-    if (buffer)
-        yy_switch_to_buffer(buffer, yyscanner);
 }
 
 void

Modified: trunk/compilers/imcc/imclexer.c
==============================================================================
--- trunk/compilers/imcc/imclexer.c	Tue May 11 05:56:25 2010	(r46490)
+++ trunk/compilers/imcc/imclexer.c	Tue May 11 06:39:18 2010	(r46491)
@@ -2466,7 +2466,7 @@
 #include "imc.h"
 #include "parser.h"
 
-typedef struct yyguts_t       yyguts_t;
+// typedef struct yyguts_t       yyguts_t;
 typedef struct parser_state_t parser_state_t;
 
 /* parser state structure
@@ -5820,20 +5820,7 @@
 
     emit_open(interp, 1, NULL);
 
-    IMCC_TRY(IMCC_INFO(interp)->jump_buf, IMCC_INFO(interp)->error_code) {
-        yyparse(yyscanner, interp);
-        imc_compile_all_units(interp);
-    }
-
-    IMCC_CATCH(IMCC_FATAL_EXCEPTION) {
-        IMCC_INFO(interp)->error_code = IMCC_FATAL_EXCEPTION;
-    }
-
-    IMCC_CATCH(IMCC_FATALY_EXCEPTION) {
-        IMCC_INFO(interp)->error_code = IMCC_FATALY_EXCEPTION;
-    }
-
-    IMCC_END_TRY;
+    imcc_run_compilation(interp, yyscanner);
 
     if (buffer)
         yy_switch_to_buffer(buffer,yyscanner);
@@ -5849,10 +5836,24 @@
     buffer                            = YY_CURRENT_BUFFER;
 
     yy_scan_string(s,yyscanner);
+
     emit_open(interp, 1, NULL);
 
+    imcc_run_compilation(interp, yyscanner);
+
+    if (buffer)
+        yy_switch_to_buffer(buffer,yyscanner);
+}
+
+void
+imcc_run_compilation(PARROT_INTERP, void *yyscanner) {
     IMCC_TRY(IMCC_INFO(interp)->jump_buf, IMCC_INFO(interp)->error_code) {
-        yyparse(yyscanner, interp);
+        if (yyparse(yyscanner, interp)) {
+            IMCC_INFO(interp)->error_code = IMCC_PARSEFAIL_EXCEPTION;
+            IMCC_INFO(interp)->error_message = string_from_literal(interp, "syntax error ... somewhere");
+            return;
+        }
+
         imc_compile_all_units(interp);
     }
 
@@ -5865,9 +5866,6 @@
     }
 
     IMCC_END_TRY;
-
-    if (buffer)
-        yy_switch_to_buffer(buffer,yyscanner);
 }
 
 void

Modified: trunk/compilers/imcc/main.c
==============================================================================
--- trunk/compilers/imcc/main.c	Tue May 11 05:56:25 2010	(r46490)
+++ trunk/compilers/imcc/main.c	Tue May 11 06:39:18 2010	(r46491)
@@ -611,7 +611,7 @@
     ASSERT_ARGS(compile_to_bytecode)
     PackFile *pf;
     yyscan_t  yyscanner = IMCC_INFO(interp)->yyscanner;
-    const int per_pbc   = (STATE_WRITE_PBC(interp) | STATE_RUN_PBC(interp)) !=0;
+    const int per_pbc   = STATE_WRITE_PBC(interp) || STATE_RUN_PBC(interp);
     const int opt_level = IMCC_INFO(interp)->optimizer_level;
 
     /* Shouldn't be more than five, but five extra is cheap */
@@ -634,14 +634,8 @@
 
     IMCC_INFO(interp)->state->pasm_file = STATE_PASM_FILE(interp) ? 1 : 0;
 
-    IMCC_TRY(IMCC_INFO(interp)->jump_buf,
-             IMCC_INFO(interp)->error_code) {
-        if (yyparse(yyscanner, interp))
-            exit(EXIT_FAILURE);
-
-        imc_compile_all_units(interp);
-    }
-    IMCC_CATCH(IMCC_FATAL_EXCEPTION) {
+    imcc_run_compilation(interp, yyscanner);
+    if (IMCC_INFO(interp)->error_code) {
         char * const error_str = Parrot_str_to_cstring(interp,
                                                    IMCC_INFO(interp)->error_message);
 
@@ -651,17 +645,6 @@
         Parrot_str_free_cstring(error_str);
         Parrot_exit(interp, IMCC_FATAL_EXCEPTION);
     }
-    IMCC_CATCH(IMCC_FATALY_EXCEPTION) {
-        char * const error_str = Parrot_str_to_cstring(interp,
-                                                   IMCC_INFO(interp)->error_message);
-
-        IMCC_INFO(interp)->error_code=IMCC_FATALY_EXCEPTION;
-        fprintf(stderr, "error:imcc:%s", error_str);
-        IMCC_print_inc(interp);
-        Parrot_str_free_cstring(error_str);
-        Parrot_exit(interp, IMCC_FATALY_EXCEPTION);
-    }
-    IMCC_END_TRY;
 
     imc_cleanup(interp, yyscanner);
 

Modified: trunk/compilers/imcc/parser.h
==============================================================================
--- trunk/compilers/imcc/parser.h	Tue May 11 05:56:25 2010	(r46490)
+++ trunk/compilers/imcc/parser.h	Tue May 11 06:39:18 2010	(r46491)
@@ -21,6 +21,8 @@
 typedef void* yyscan_t;
 #endif
 
+typedef struct yyguts_t yyguts_t;
+
 void set_filename(PARROT_INTERP, char * const filename);
 
 SymReg * macro(PARROT_INTERP, char *name);
@@ -42,6 +44,7 @@
 
 extern void compile_file(PARROT_INTERP, FILE *file, void *);
 extern void compile_string(PARROT_INTERP, const char *, void *);
+extern void imcc_run_compilation(PARROT_INTERP, void *);
 
 int at_eof(yyscan_t yyscanner);
 


More information about the parrot-commits mailing list