# New Ticket Created by  chromatic 
# Please include the string:  [perl #42510]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=42510 >


The attached patch moves only the main() function out of compilers/imcc/main.c 
into src/main.c.  There's a lot more work to do to clean up this mess, 
including RT #37248.

For example, the options processing and help() and version() functions need to 
move into src/main.c too, but because of the intertwining with IMCC details, 
it's difficult to do so.

I'd like to get test results from this patch on a few other platforms before I 
apply it in a couple of days; it was  a bit of work to get pbc_merge to 
compile.

-- c

=== MANIFEST
==================================================================
--- MANIFEST	(revision 3175)
+++ MANIFEST	(local)
@@ -769,6 +769,7 @@
 include/parrot/hash.h                                       [main]include
 include/parrot/headers.h                                    [main]include
 include/parrot/hll.h                                        [main]include
+include/parrot/imcc.h                                       [main]include
 include/parrot/inter_call.h                                 [main]include
 include/parrot/interpreter.h                                [main]include
 include/parrot/intlist.h                                    [main]include
@@ -2539,6 +2540,7 @@
 src/longopt.c                                               []
 src/malloc-trace.c                                          []
 src/malloc.c                                                []
+src/main.c                                                  []
 src/misc.c                                                  []
 src/mmd.c                                                   []
 src/nci_test.c                                              []
=== compilers/imcc/main.c
==================================================================
--- compilers/imcc/main.c	(revision 3175)
+++ compilers/imcc/main.c	(local)
@@ -194,7 +194,7 @@
 }
 
 /* most stolen from test_main.c */
-static char *
+char *
 parseflags(Parrot_Interp interp, int *argc, char **argv[])
 {
     struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT;
@@ -511,7 +511,7 @@
     return;
 }
 
-static int
+int
 imcc_initialize(Interp *interp)
 {
     yyscan_t yyscanner = IMCC_INFO(interp)->yyscanner;
@@ -592,7 +592,7 @@
     free(packed);
 }
 
-static int
+int
 imcc_run(Interp *interp, const char *sourcefile, int argc, char * argv[])
 {
     PackFile *pf;
@@ -760,41 +760,6 @@
     return 0;
 }
 
-int
-main(int argc, char * argv[])
-{
-    char    *sourcefile;
-    Interp  *interp;
-    STRING  *executable_name;
-    PMC     *executable_name_pmc;
-    int      status;
-
-    Parrot_set_config_hash();
-
-    interp     = Parrot_new(NULL);
-    if (!imcc_initialize(interp))
-        internal_exception(1, "Could not initialize IMCC\n");
-
-    /* We parse the arguments, but first store away the name of the Parrot
-       executable, since parsing destroys that and we want to make it
-       available. */
-    executable_name     = string_from_cstring(interp, argv[0], 0);
-    executable_name_pmc = pmc_new(interp, enum_class_String);
-    VTABLE_set_string_native(interp, executable_name_pmc, executable_name);
-    VTABLE_set_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_EXECUTABLE,
-        executable_name_pmc);
-
-    sourcefile = parseflags(interp, &argc, &argv);
-    status     = imcc_run(interp, sourcefile, argc, argv);
-
-    /* Clean-up after ourselves */
-    Parrot_destroy(interp);
-    Parrot_exit(interp, 0);
-
-    return status;
-}
-
-
 /*
  * Local variables:
  *   c-file-style: "parrot"
=== config/gen/makefiles/root.in
==================================================================
--- config/gen/makefiles/root.in	(revision 3175)
+++ config/gen/makefiles/root.in	(local)
@@ -371,6 +371,7 @@
     $(IMCC_DIR)/imcparser$(O) \
     $(IMCC_DIR)/imclexer$(O) \
     $(IMCC_DIR)/imc$(O) \
+    $(IMCC_DIR)/main$(O) \
     $(IMCC_DIR)/symreg$(O) \
     $(IMCC_DIR)/instructions$(O) \
     $(IMCC_DIR)/cfg$(O) \
@@ -425,6 +426,7 @@
     $(SRC_DIR)/inter_run$(O)  \
     $(SRC_DIR)/gc/register$(O) \
     $(SRC_DIR)/gc/memory$(O) \
+    $(SRC_DIR)/main$(O) \
     $(SRC_DIR)/objects$(O) \
     $(SRC_DIR)/packfile$(O) \
     $(SRC_DIR)/stacks$(O) \
@@ -1082,6 +1084,8 @@
 
 $(SRC_DIR)/gc/memory$(O) : $(GENERAL_H_FILES)
 
+$(SRC_DIR)/main$(O) : $(SRC_DIR)/main.c $(GENERAL_H_FILES)
+
 $(SRC_DIR)/pic$(O) : $(GENERAL_H_FILES)
 
 $(SRC_DIR)/pic_jit$(O) : $(GENERAL_H_FILES)
=== include/parrot/imcc.h
==================================================================
--- include/parrot/imcc.h	(revision 3175)
+++ include/parrot/imcc.h	(local)
@@ -0,0 +1,15 @@
+#if !defined(PARROT_IMCC_H_GUARD)
+#define PARROT_IMCC_H_GUARD
+
+int imcc_initialize(Interp *interp);
+char * parseflags(Interp *interp, int *argc, char **argv[]);
+int imcc_run(Interp *interp, const char *sourcefile, int argc, char * argv[]);
+
+#endif
+
+/*
+ * Local variables:
+ *   c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */

Property changes on: include/parrot/imcc.h
___________________________________________________________________
Name: svn:eol-style
 +native
Name: svn:keywords
 +Author Date Id Revision

=== src/main.c
==================================================================
--- src/main.c	(revision 3175)
+++ src/main.c	(local)
@@ -0,0 +1,85 @@
+/*
+Copyright (C) 2007, The Perl Foundation
+$Id$
+
+=head1 NAME
+
+src/main.c - the Entry Point to Parrot Programs
+
+=head1 DESCRIPTION
+
+Start Parrot
+
+=head2 Functions
+
+=over 4
+
+=cut
+
+*/
+
+#include <stdio.h>
+#include <string.h>
+
+#include "parrot/parrot.h"
+#include "parrot/embed.h"
+#include "parrot/imcc.h"
+
+/*
+
+=item C<int main(int argc, char * argv[])>
+
+The entry point from the command line into Parrot.
+
+*/
+
+int
+main(int argc, char * argv[])
+{
+    char    *sourcefile;
+    Interp  *interp;
+    STRING  *executable_name;
+    PMC     *executable_name_pmc;
+    int      status;
+
+    Parrot_set_config_hash();
+
+    interp     = Parrot_new(NULL);
+    if (!imcc_initialize(interp))
+        internal_exception(1, "Could not initialize IMCC\n");
+
+    /* We parse the arguments, but first store away the name of the Parrot
+       executable, since parsing destroys that and we want to make it
+       available. */
+    executable_name     = string_from_cstring(interp, argv[0], 0);
+    executable_name_pmc = pmc_new(interp, enum_class_String);
+    VTABLE_set_string_native(interp, executable_name_pmc, executable_name);
+    VTABLE_set_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_EXECUTABLE,
+        executable_name_pmc);
+
+    sourcefile = parseflags(interp, &argc, &argv);
+    status     = imcc_run(interp, sourcefile, argc, argv);
+
+    /* Clean-up after ourselves */
+    Parrot_destroy(interp);
+    Parrot_exit(interp, 0);
+
+    return status;
+}
+
+=back
+
+=head1 SEE ALSO
+
+F<compilers/imcc/main.c>, unfortunately.
+
+=cut
+
+*/
+
+/*
+ * Local variables:
+ *   c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */

Property changes on: src/main.c
___________________________________________________________________
Name: svn:eol-style
 +native
Name: svn:keywords
 +Author Date Id Revision

Reply via email to