Release 2.5.0
[parrot.git] / src / global_setup.c
blobd66b6ef24a3cd8394877d898e5c11fcd2eade60c
1 /*
2 Copyright (C) 2001-2008, Parrot 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, int pass);
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 */
39 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
41 static void parrot_global_setup_2(PARROT_INTERP)
42 __attribute__nonnull__(1);
44 static void parrot_set_config_hash_interpreter(PARROT_INTERP)
45 __attribute__nonnull__(1);
47 #define ASSERT_ARGS_parrot_global_setup_2 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
48 PARROT_ASSERT_ARG(interp))
49 #define ASSERT_ARGS_parrot_set_config_hash_interpreter \
50 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
51 PARROT_ASSERT_ARG(interp))
52 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
53 /* HEADERIZER END: static */
58 =item C<void Parrot_set_config_hash_internal(const unsigned char* parrot_config,
59 unsigned int parrot_config_size)>
61 Called by Parrot_set_config_hash with the serialised hash which
62 will be used in subsequently created Interpreters.
64 =cut
68 PARROT_EXPORT
69 void
70 Parrot_set_config_hash_internal(ARGIN(const unsigned char* parrot_config),
71 unsigned int parrot_config_size)
73 ASSERT_ARGS(Parrot_set_config_hash_internal)
74 parrot_config_stored = parrot_config;
75 parrot_config_size_stored = parrot_config_size;
80 =item C<static void parrot_set_config_hash_interpreter(PARROT_INTERP)>
82 Used internally to associate the config hash with an Interpreter
83 using the last registered config data.
85 =cut
89 static void
90 parrot_set_config_hash_interpreter(PARROT_INTERP)
92 ASSERT_ARGS(parrot_set_config_hash_interpreter)
93 PMC *iglobals = interp->iglobals;
95 PMC *config_hash = NULL;
97 if (parrot_config_size_stored > 1) {
98 STRING * const config_string =
99 Parrot_str_new_init(interp,
100 (const char *)parrot_config_stored, parrot_config_size_stored,
101 PARROT_DEFAULT_ENCODING, PARROT_DEFAULT_CHARSET,
102 PObj_external_FLAG|PObj_constant_FLAG);
104 config_hash = Parrot_thaw(interp, config_string);
106 else {
107 config_hash = Parrot_pmc_new(interp, enum_class_Hash);
110 VTABLE_set_pmc_keyed_int(interp, iglobals,
111 (INTVAL) IGLOBALS_CONFIG_HASH, config_hash);
116 =item C<void init_world_once(PARROT_INTERP)>
118 Call init_world() if it hasn't been called before.
120 C<interp> should be the root interpreter created in C<Parrot_new(NULL)>.
122 =cut
126 void
127 init_world_once(PARROT_INTERP)
129 ASSERT_ARGS(init_world_once)
130 if (!interp->world_inited) {
131 /* init_world() sets up some vtable stuff.
132 * It must only be called once.
135 interp->world_inited = 1;
136 init_world(interp);
143 =item C<void init_world(PARROT_INTERP)>
145 This is the actual initialization code called by C<init_world_once()>.
147 It sets up the Parrot system, running any platform-specific init code if
148 necessary, then initializing the string subsystem, and setting up the
149 base vtables and core PMCs.
151 C<interp> should be the root interpreter created in C<Parrot_new(NULL)>.
153 =cut
157 void
158 init_world(PARROT_INTERP)
160 ASSERT_ARGS(init_world)
161 PMC *iglobals, *self, *pmc;
163 #ifdef PARROT_HAS_PLATFORM_INIT_CODE
164 Parrot_platform_init_code();
165 #endif
167 /* Call base vtable class constructor methods */
168 parrot_global_setup_2(interp);
169 Parrot_initialize_core_pmcs(interp, 1);
171 iglobals = interp->iglobals;
172 VTABLE_set_pmc_keyed_int(interp, iglobals,
173 (INTVAL)IGLOBALS_CLASSNAME_HASH, interp->class_hash);
175 self = Parrot_pmc_new_noinit(interp, enum_class_ParrotInterpreter);
176 VTABLE_set_pointer(interp, self, interp);
177 /* PMC_data(self) = interp; */
179 VTABLE_set_pmc_keyed_int(interp, iglobals,
180 (INTVAL)IGLOBALS_INTERPRETER, self);
182 parrot_set_config_hash_interpreter(interp);
184 /* lib search paths */
185 parrot_init_library_paths(interp);
187 /* load_bytecode and dynlib loaded hash */
188 pmc = Parrot_pmc_new(interp, enum_class_Hash);
189 VTABLE_set_pmc_keyed_int(interp, iglobals, IGLOBALS_PBC_LIBS, pmc);
191 pmc = Parrot_pmc_new(interp, enum_class_Hash);
192 VTABLE_set_pmc_keyed_int(interp, iglobals, IGLOBALS_DYN_LIBS, pmc);
194 pmc = Parrot_pmc_new(interp, enum_class_Hash);
195 VTABLE_set_pmc_keyed_int(interp, iglobals, IGLOBALS_NCI_FUNCS, pmc);
196 Parrot_nci_load_core_thunks(interp);
197 #if PARROT_HAS_EXTRA_NCI_THUNKS
198 Parrot_nci_load_extra_thunks(interp);
199 #endif
204 =item C<static void parrot_global_setup_2(PARROT_INTERP)>
206 called from inmidst of PMC bootstrapping between pass 0 and 1
208 =cut
212 static void
213 parrot_global_setup_2(PARROT_INTERP)
215 ASSERT_ARGS(parrot_global_setup_2)
216 PMC *classname_hash;
218 create_initial_context(interp);
220 /* create the namespace root stash */
221 interp->root_namespace = Parrot_pmc_new(interp, enum_class_NameSpace);
222 Parrot_init_HLL(interp);
224 Parrot_pcc_set_namespace(interp, CURRENT_CONTEXT(interp),
225 VTABLE_get_pmc_keyed_int(interp, interp->HLL_namespace, 0));
227 /* We need a class hash */
228 interp->class_hash = classname_hash = Parrot_pmc_new(interp, enum_class_NameSpace);
229 Parrot_register_core_pmcs(interp, classname_hash);
231 /* init the interpreter globals array */
232 interp->iglobals = Parrot_pmc_new_init_int(interp,
233 enum_class_FixedPMCArray, (INTVAL)IGLOBALS_SIZE);
237 * Local variables:
238 * c-file-style: "parrot"
239 * End:
240 * vim: expandtab shiftwidth=4: