+ --debug is now --imcc-debug; make this more consistent with -D.
[parrot.git] / src / global_setup.c
blobb994a138f47bbe675c0ea3b8006e31fe7944d26c
1 /*
2 Copyright (C) 2001-2008, The Perl Foundation.
3 $Id$
5 =head1 NAME
7 src/global_setup.c - Global setup
9 =head1 DESCRIPTION
11 Performs all the global setting up of things. This includes the very
12 few global variables that Parrot totes around.
14 I<What are these global variables?>
16 =head2 Functions
18 =over 4
20 =cut
24 #define INSIDE_GLOBAL_SETUP
25 #include "parrot/parrot.h"
26 #include "global_setup.str"
28 /* These functions are defined in the auto-generated file core_pmcs.c */
29 /* XXX Get it into some public place */
30 extern void Parrot_initialize_core_pmcs(PARROT_INTERP);
31 void Parrot_register_core_pmcs(PARROT_INTERP, PMC* registry);
33 static const unsigned char* parrot_config_stored = NULL;
34 static unsigned int parrot_config_size_stored = 0;
36 /* HEADERIZER HFILE: include/parrot/global_setup.h */
38 /* HEADERIZER BEGIN: static */
40 static void parrot_set_config_hash_interpreter(PARROT_INTERP)
41 __attribute__nonnull__(1);
43 /* HEADERIZER END: static */
48 =item C<void Parrot_set_config_hash_internal>
50 Called by Parrot_set_config_hash with the serialised hash which
51 will be used in subsequently created Interpreters.
53 =cut
57 PARROT_API
58 void
59 Parrot_set_config_hash_internal(ARGIN(const unsigned char* parrot_config),
60 unsigned int parrot_config_size)
62 parrot_config_stored = parrot_config;
63 parrot_config_size_stored = parrot_config_size;
68 =item C<static void parrot_set_config_hash_interpreter>
70 Used internally to associate the config hash with an Interpreter
71 using the last registered config data.
73 =cut
77 static void
78 parrot_set_config_hash_interpreter(PARROT_INTERP)
80 PMC *iglobals = interp->iglobals;
82 PMC *config_hash = NULL;
84 if (parrot_config_size_stored > 1) {
85 STRING * const config_string =
86 string_make_direct(interp,
87 (const char *)parrot_config_stored, parrot_config_size_stored,
88 PARROT_DEFAULT_ENCODING, PARROT_DEFAULT_CHARSET,
89 PObj_external_FLAG|PObj_constant_FLAG);
91 config_hash = Parrot_thaw(interp, config_string);
93 else {
94 config_hash = pmc_new(interp, enum_class_Hash);
97 VTABLE_set_pmc_keyed_int(interp, iglobals,
98 (INTVAL) IGLOBALS_CONFIG_HASH, config_hash);
103 =item C<void init_world_once>
105 Call init_world() if it hasn't been called before.
107 C<interp> should be the root interpreter created in C<Parrot_new(NULL)>.
109 =cut
113 void
114 init_world_once(PARROT_INTERP)
116 if (!interp->world_inited) {
117 /* init_world() sets up some vtable stuff.
118 * It must only be called once.
121 interp->world_inited = 1;
122 init_world(interp);
129 =item C<void init_world>
131 This is the actual initialization code called by C<init_world_once()>.
133 It sets up the Parrot system, running any platform-specific init code if
134 necessary, then initializing the string subsystem, and setting up the
135 base vtables and core PMCs.
137 C<interp> should be the root interpreter created in C<Parrot_new(NULL)>.
139 =cut
143 void
144 init_world(PARROT_INTERP)
146 PMC *iglobals, *self, *pmc;
148 #ifdef PARROT_HAS_PLATFORM_INIT_CODE
149 Parrot_platform_init_code();
150 #endif
152 parrot_alloc_vtables(interp);
154 /* Call base vtable class constructor methods */
155 Parrot_initialize_core_pmcs(interp);
157 iglobals = interp->iglobals;
158 VTABLE_set_pmc_keyed_int(interp, iglobals,
159 (INTVAL)IGLOBALS_CLASSNAME_HASH, interp->class_hash);
161 self = pmc_new_noinit(interp, enum_class_ParrotInterpreter);
162 PMC_data(self) = interp;
164 VTABLE_set_pmc_keyed_int(interp, iglobals,
165 (INTVAL)IGLOBALS_INTERPRETER, self);
167 parrot_set_config_hash_interpreter(interp);
169 /* lib search paths */
170 parrot_init_library_paths(interp);
172 /* load_bytecode and dynlib loaded hash */
173 pmc = pmc_new(interp, enum_class_Hash);
174 VTABLE_set_pmc_keyed_int(interp, iglobals, IGLOBALS_PBC_LIBS, pmc);
176 pmc = pmc_new(interp, enum_class_Hash);
177 VTABLE_set_pmc_keyed_int(interp, iglobals, IGLOBALS_DYN_LIBS, pmc);
182 =item C<void parrot_global_setup_2>
184 called from inmidst of PMC bootstrapping between pass 0 and 1
186 =cut
190 void
191 parrot_global_setup_2(PARROT_INTERP)
193 PMC *classname_hash, *iglobals;
194 int i;
196 /* create the namespace root stash */
197 interp->root_namespace = pmc_new(interp, enum_class_NameSpace);
198 Parrot_init_HLL(interp);
200 CONTEXT(interp->ctx)->current_namespace =
201 VTABLE_get_pmc_keyed_int(interp, interp->HLL_namespace, 0);
203 /* We need a class hash */
204 interp->class_hash = classname_hash = pmc_new(interp, enum_class_NameSpace);
205 Parrot_register_core_pmcs(interp, classname_hash);
207 /* init the interpreter globals array */
208 iglobals = pmc_new(interp, enum_class_SArray);
209 interp->iglobals = iglobals;
210 VTABLE_set_integer_native(interp, iglobals, (INTVAL)IGLOBALS_SIZE);
212 /* clear the array */
213 for (i = 0; i < (INTVAL)IGLOBALS_SIZE; i++)
214 VTABLE_set_pmc_keyed_int(interp, iglobals, i, NULL);
218 * Local variables:
219 * c-file-style: "parrot"
220 * End:
221 * vim: expandtab shiftwidth=4: