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


The attached patch creates a Parrot-level library similar to Parrot::Config.

There are three components to this:

   1.  A .pasm file, generated at Configure time and run at make time
       (just after $(TEST_PROG) is built), which creates a PerlHash and
       freezes it to...

   2.  A file, F<library/config.fpmc> (for Frozen PMC), which is usually
       accessed by...

   3.  An IMCC library, F<library/config.imc>, which contains a
       subroutine to open, unfreeze, and return the configuration.

This approach has two benefits:

   1.  The configuration data is always for the *current* machine, rather
       than the machine on which F<config.imc> was assembled/linked in.

   2.  It avoids bloating bytecode files that use F<config.imc>.

F<library/config.imc> and F<config/gen/config_pm/config_lib.in> are the 
only new files added to CVS; F<config/gen/config_pm.pl>, 
F<config/gen/makefiles/root.in>, and F<MANIFEST> are also touched. 
There are no tests because I don't know where to put them.

One potentially controversial aspect of this patch is that it means that 
Parrot is invoked during the make process, before it's been tested.  I 
don't see any easy way around this, short of re-implementing PMC 
freezing in Perl 5, allowing Configure to write F<config.fpmc> itself.

F<config.fpmc> does not contain all of the configuration data--Parrot 
seems to segfault when fed some of the really long values[1], so it 
doesn't include any entry with a newline in it.  On my Debian box, 
F<config.fpmc> weighs in at around 15k.

As currently implemented, you must be in F<library/>'s parent directory 
(i.e. the Parrot root directory) to make use of F<library/config.imc>. 
I'm not sure what I can do about that yet.

The following PIL will dump your entire configuration to stdout:

        .sub _main
                .local PerlHash config
        
                config=_config()
                _dumper("config", config)
        
                end
        .end

        .include "library/config.imc"
        .include "library/dumper.imc"

I'm going to bed now.  Good night.


[1] Said "really long values" are cases where someone inserted a key 
into the Configure data for the sole purpose of interpolating it into a 
particular file--a Configure no-no.  I may rant on this practice in the 
near future.

-- 
Brent "Dax" Royal-Gordon <[EMAIL PROTECTED]>
Perl and Parrot hacker

Oceania has always been at war with Eastasia.
? config/gen/config_pm/config_lib.in
? library/config.imc
Index: MANIFEST
===================================================================
RCS file: /cvs/public/parrot/MANIFEST,v
retrieving revision 1.580
diff -u -r1.580 MANIFEST
--- MANIFEST    6 Mar 2004 07:35:18 -0000       1.580
+++ MANIFEST    6 Mar 2004 11:09:14 -0000
@@ -110,6 +110,7 @@
 config/gen/config_h.pl                            []
 config/gen/config_h/config_h.in                   []
 config/gen/config_pm.pl                           []
+config/gen/config_pm/config_lib.in                []
 config/gen/config_pm/Config_pm.in                 []
 config/gen/core_pmcs.pl                           []
 config/gen/feature_h.pl                           []
@@ -2302,6 +2303,7 @@
 lib/Test/Simple.pm                                [devel]
 lib/Text/Balanced.pm                              [devel]
 libnci.def                                        []
+library/config.imc                                [devel]
 library/dumper.imc                                [devel]
 library/libpcre.imc                               [devel]
 library/ncurses.declarations                      [devel]
Index: config/gen/config_pm.pl
===================================================================
RCS file: /cvs/public/parrot/config/gen/config_pm.pl,v
retrieving revision 1.3
diff -u -r1.3 config_pm.pl
--- config/gen/config_pm.pl     26 Feb 2004 00:43:05 -0000      1.3
+++ config/gen/config_pm.pl     6 Mar 2004 11:09:17 -0000
@@ -19,7 +19,7 @@
 use Parrot::Configure::Step;
 use Data::Dumper;
 
-$description="Writing Parrot::Config module...";
+$description="Writing configuration data modules for Perl 5 and Parrot...";
 
 @args=();
 
@@ -36,6 +36,38 @@
  
   close IN  or die "Can't close Config_pm.in: $!";
   close OUT or die "Can't close Config.pm: $!";
+  
+  open(IN, "config/gen/config_pm/config_lib.in") or die "Can't open config_lib.in: 
$!";
+  open(OUT, ">config_lib.pasm") or die "Can't open config_lib.pasm: $!";
+  
+  print OUT <<"END";
+# Generated by config/gen/config_pm.pl
+# This file should be the last thing run during 
+# the make process, after Parrot is built.
+END
+  
+  while(<IN>) {      
+    if(/<<HERE>>/) {
+      my $k;
+      for $k(Configure::Data->keys) {
+       my $v=Configure::Data->get($k);
+       if(defined $v) {
+         next if $v =~ /\n/;
+          $v =~ s/(["\\])/\\$1/g;
+          print OUT qq(\tset P0["$k"], "$v"\n);
+        }
+        else {
+          print OUT qq(\tset P0["$k"], P1\n);
+        }
+      }
+    }
+    else {
+      print OUT;
+    }
+  }
+  
+  close IN  or die "Can't close config_lib.in: $!";
+  close OUT or die "Can't close config_lib.pasm: $!";
 }
 
 1;
Index: config/gen/makefiles/root.in
===================================================================
RCS file: /cvs/public/parrot/config/gen/makefiles/root.in,v
retrieving revision 1.187
diff -u -r1.187 root.in
--- config/gen/makefiles/root.in        2 Mar 2004 20:45:02 -0000       1.187
+++ config/gen/makefiles/root.in        6 Mar 2004 11:09:18 -0000
@@ -109,6 +109,7 @@
     include/parrot/core_pmcs.h \
     lib/Parrot/Config.pm \
     lib/Parrot/PMC.pm \
+    library/config.fpmc \
     $(SRC)/platform.c \
 #CONDITIONED_LINE(platform_asm):    $(SRC)/platform_asm.s \
     $(SRC)/core_pmcs.c \
@@ -377,7 +378,7 @@
 #
 ###############################################################################
 
-all : flags_dummy $(TEST_PROG) docs
+all : flags_dummy $(TEST_PROG) library/config.fpmc docs
 
 # This is a listing of all targets, that are meant to be called by users
 help:
@@ -456,6 +457,10 @@
 flags_dummy:
        @echo Compiling with:
        @$(PERL) tools/dev/cc_flags.pl ./CFLAGS echo $(CC) $(CFLAGS) xx$(O) -c xx.c
+
+library/config.fpmc: $(TEST_PROG) config_lib.pasm
+       @echo Invoking Parrot to generate library/config.fpmc--cross your fingers
+       ./parrot config_lib.pasm
 
 mops : examples/assembly/mops${exe} examples/mops/mops${exe}
 
--- /dev/null   Wed Jan  7 17:19:56 2004
+++ library/config.imc  Sat Mar  6 02:48:02 2004
@@ -0,0 +1,14 @@
+.pcc_sub _config
+     .local pmc fh
+     .local PerlHash hash
+     
+     open fh, "library/config.fpmc", "<"
+     read S0, fh, 65535                #If it gets above 64k, we've got bigger 
problems.
+     close fh
+     
+     thaw hash, S0
+     
+     .pcc_begin_return
+     .return hash
+     .pcc_end_return
+.end
\ No newline at end of file
--- /dev/null   Wed Jan  7 17:19:56 2004
+++ config/gen/config_pm/config_lib.in  Sat Mar  6 02:47:35 2004
@@ -0,0 +1,11 @@
+       new P0, .PerlHash
+       new P1, .PerlUndef
+       
+       <<HERE>>
+       
+       open P1, "library/config.fpmc", ">"
+       freeze S0, P0
+       print P1, S0
+       close P1
+       
+       end

Reply via email to