fix codetest failure - ASSERT_ARGS does not have a ; after and
[parrot.git] / src / global_setup.c
blob2899813659c5d7e305568225af072af5556af05c
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 "parrot/oplib/core_ops.h"
27 #include "global_setup.str"
29 /* These functions are defined in the auto-generated file core_pmcs.c */
30 /* XXX Get it into some public place */
31 extern void Parrot_initialize_core_pmcs(PARROT_INTERP, int pass);
32 void Parrot_register_core_pmcs(PARROT_INTERP, PMC* registry);
34 static const unsigned char* parrot_config_stored = NULL;
35 static unsigned int parrot_config_size_stored = 0;
37 /* HEADERIZER HFILE: include/parrot/global_setup.h */
39 /* HEADERIZER BEGIN: static */
40 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
42 static void parrot_global_setup_2(PARROT_INTERP)
43 __attribute__nonnull__(1);
45 static void parrot_set_config_hash_interpreter(PARROT_INTERP)
46 __attribute__nonnull__(1);
48 #define ASSERT_ARGS_parrot_global_setup_2 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
49 PARROT_ASSERT_ARG(interp))
50 #define ASSERT_ARGS_parrot_set_config_hash_interpreter \
51 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
52 PARROT_ASSERT_ARG(interp))
53 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
54 /* HEADERIZER END: static */
59 =item C<void Parrot_set_config_hash_internal(const unsigned char* parrot_config,
60 unsigned int parrot_config_size)>
62 Called by Parrot_set_config_hash with the serialised hash which
63 will be used in subsequently created Interpreters.
65 =cut
69 PARROT_EXPORT
70 void
71 Parrot_set_config_hash_internal(ARGIN(const unsigned char* parrot_config),
72 unsigned int parrot_config_size)
74 ASSERT_ARGS(Parrot_set_config_hash_internal)
75 parrot_config_stored = parrot_config;
76 parrot_config_size_stored = parrot_config_size;
81 =item C<static void parrot_set_config_hash_interpreter(PARROT_INTERP)>
83 Used internally to associate the config hash with an Interpreter
84 using the last registered config data.
86 =cut
90 static void
91 parrot_set_config_hash_interpreter(PARROT_INTERP)
93 ASSERT_ARGS(parrot_set_config_hash_interpreter)
94 PMC *iglobals = interp->iglobals;
96 PMC *config_hash = NULL;
98 if (parrot_config_size_stored > 1) {
99 STRING * const config_string =
100 Parrot_str_new_init(interp,
101 (const char *)parrot_config_stored, parrot_config_size_stored,
102 Parrot_default_encoding_ptr,
103 PObj_external_FLAG|PObj_constant_FLAG);
105 config_hash = Parrot_thaw(interp, config_string);
107 else {
108 config_hash = Parrot_pmc_new(interp, enum_class_Hash);
111 VTABLE_set_pmc_keyed_int(interp, iglobals,
112 (INTVAL) IGLOBALS_CONFIG_HASH, config_hash);
117 =item C<void init_world_once(PARROT_INTERP)>
119 Call init_world() if it hasn't been called before.
121 C<interp> should be the root interpreter created in C<Parrot_new(NULL)>.
123 =cut
127 void
128 init_world_once(PARROT_INTERP)
130 ASSERT_ARGS(init_world_once)
131 if (!interp->world_inited) {
132 /* init_world() sets up some vtable stuff.
133 * It must only be called once.
136 interp->world_inited = 1;
137 init_world(interp);
144 =item C<void init_world(PARROT_INTERP)>
146 This is the actual initialization code called by C<init_world_once()>.
148 It sets up the Parrot system, running any platform-specific init code if
149 necessary, then initializing the string subsystem, and setting up the
150 base vtables and core PMCs.
152 C<interp> should be the root interpreter created in C<Parrot_new(NULL)>.
154 =cut
158 void
159 init_world(PARROT_INTERP)
161 ASSERT_ARGS(init_world)
162 PMC *iglobals, *self, *pmc;
164 #ifdef PARROT_HAS_PLATFORM_INIT_CODE
165 Parrot_platform_init_code();
166 #endif
168 /* Call base vtable class constructor methods */
169 parrot_global_setup_2(interp);
170 Parrot_initialize_core_pmcs(interp, 1);
172 iglobals = interp->iglobals;
173 VTABLE_set_pmc_keyed_int(interp, iglobals,
174 (INTVAL)IGLOBALS_CLASSNAME_HASH, interp->class_hash);
176 self = Parrot_pmc_new_noinit(interp, enum_class_ParrotInterpreter);
177 VTABLE_set_pointer(interp, self, interp);
178 /* PMC_data(self) = interp; */
180 VTABLE_set_pmc_keyed_int(interp, iglobals,
181 (INTVAL)IGLOBALS_INTERPRETER, self);
183 parrot_set_config_hash_interpreter(interp);
185 /* lib search paths */
186 parrot_init_library_paths(interp);
188 /* load_bytecode and dynlib loaded hash */
189 pmc = Parrot_pmc_new(interp, enum_class_Hash);
190 VTABLE_set_pmc_keyed_int(interp, iglobals, IGLOBALS_PBC_LIBS, pmc);
192 pmc = Parrot_pmc_new(interp, enum_class_Hash);
193 VTABLE_set_pmc_keyed_int(interp, iglobals, IGLOBALS_DYN_LIBS, pmc);
195 pmc = Parrot_pmc_new(interp, enum_class_Hash);
196 VTABLE_set_pmc_keyed_int(interp, iglobals, IGLOBALS_NCI_FUNCS, pmc);
197 Parrot_nci_load_core_thunks(interp);
198 #if PARROT_HAS_EXTRA_NCI_THUNKS
199 Parrot_nci_load_extra_thunks(interp);
200 #endif
205 =item C<static void parrot_global_setup_2(PARROT_INTERP)>
207 called from inmidst of PMC bootstrapping between pass 0 and 1
209 =cut
213 static void
214 parrot_global_setup_2(PARROT_INTERP)
216 ASSERT_ARGS(parrot_global_setup_2)
217 PMC *classname_hash;
219 create_initial_context(interp);
221 /* initialize the ops hash */
222 if (interp->parent_interpreter) {
223 interp->op_hash = interp->parent_interpreter->op_hash;
225 else {
226 op_lib_t *core_ops = PARROT_CORE_OPLIB_INIT(interp, 1);
227 interp->op_hash = parrot_create_hash_sized(interp, enum_type_ptr,
228 Hash_key_type_cstring, core_ops->op_count);
229 parrot_hash_oplib(interp, core_ops);
232 /* create the namespace root stash */
233 interp->root_namespace = Parrot_pmc_new(interp, enum_class_NameSpace);
234 Parrot_init_HLL(interp);
236 Parrot_pcc_set_namespace(interp, CURRENT_CONTEXT(interp),
237 VTABLE_get_pmc_keyed_int(interp, interp->HLL_namespace, 0));
239 /* We need a class hash */
240 interp->class_hash = classname_hash = Parrot_pmc_new(interp, enum_class_NameSpace);
241 Parrot_register_core_pmcs(interp, classname_hash);
243 /* init the interpreter globals array */
244 interp->iglobals = Parrot_pmc_new_init_int(interp,
245 enum_class_FixedPMCArray, (INTVAL)IGLOBALS_SIZE);
249 * Local variables:
250 * c-file-style: "parrot"
251 * End:
252 * vim: expandtab shiftwidth=4: