Juergen Boemmels wrote: > Leopold Toetsch wrotes: > > > We currently have constant Key and Sub PMCs both created from the > > packfile at load time. They live in the constant_table pointing to a > > constant PMC pool. But we need more. > > > > We have allover the core code like this: > > > > string_from_cstring(interpreter, "pIt", 0) > > key = key_new_cstring(interpreter, "_message"); > > > > to create some STRINGs or entries in hashes. The keys should be > > constant PMCs and they should be shared as well as the STRINGs. > > > > We need this in objects.c ("\0\0anonymous"), for setting standard > > property names internally and for the current hash based > > implementation of Exceptions. > > [...] > > Some time ago I did some experiments with initialising strings at > compile time. With some preprocessor magic and a perl program scanning > the c-file I got it running. > > The changes to an existing c-file are minimal: At the beginning add a > #include "FILE.str" and replace all these string_form_cstring with > _S("text"). The _S macros are replaced by static string_structures > with static initialisers. These string structures are in the ro-data > segement of the executable and should load really fast. No calls to > any functions.
I can think of a slightly easier method, one which would not depend on running a helper perl program. #define PCONCAT(b,c) _Parrot_static_##b##c #define PARROT_DECLARE_STATIC_STRING(name, cstring) \ static const char PCONCAT(name,_cstring) [] = cstring; \ static const struct parrot_string_t \ PCONCAT(name,_STRING) = { \ { /* pobj_t */ \ {{ \ (void*)PCONCAT(name,_cstring), \ sizeof(PCONCAT(name,_cstring)) \ }}, \ PObj_constant_FLAG \ GC_DEBUG_VERSION \ }, \ sizeof(PCONCAT(name,_cstring)), \ (void*)PCONCAT(name,_cstring), \ sizeof(PCONCAT(name,_cstring)) - 1, \ NULL, \ NULL, \ 0 \ }, * const name = &PCONCAT(name,_STRING); [untested] Then, of course, one can simply declare the names and values of one's constant strings in any place where variables may be declared, using: PARROT_DECLARE_STATIC_STRING(mystr, "some string here"); Now, there's a const STRING * const mystr variable, whose contents are the "some string here". Actually, I'm not sure that there's a need for the PCONCAT(name,_cstring) variable -- it might be possible to use cstring directly when initializing the struct. -- $a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca );{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "[EMAIL PROTECTED] ]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}