2 Copyright (C) 2001-2008, Parrot Foundation.
7 src/global_setup.c - Global setup
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?>
24 #define INSIDE_GLOBAL_SETUP
25 #include "parrot/parrot.h"
26 #include "pmc/pmc_context.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.
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.
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
, PARROT_DEFAULT_CHARSET
,
103 PObj_external_FLAG
|PObj_constant_FLAG
);
105 config_hash
= Parrot_thaw(interp
, config_string
);
108 config_hash
= 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)>.
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;
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)>.
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();
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
= 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
= pmc_new(interp
, enum_class_Hash
);
190 VTABLE_set_pmc_keyed_int(interp
, iglobals
, IGLOBALS_PBC_LIBS
, pmc
);
192 pmc
= pmc_new(interp
, enum_class_Hash
);
193 VTABLE_set_pmc_keyed_int(interp
, iglobals
, IGLOBALS_DYN_LIBS
, pmc
);
198 =item C<static void parrot_global_setup_2(PARROT_INTERP)>
200 called from inmidst of PMC bootstrapping between pass 0 and 1
207 parrot_global_setup_2(PARROT_INTERP
)
209 ASSERT_ARGS(parrot_global_setup_2
)
210 PMC
*classname_hash
, *iglobals
;
213 create_initial_context(interp
);
215 /* create the namespace root stash */
216 interp
->root_namespace
= pmc_new(interp
, enum_class_NameSpace
);
217 Parrot_init_HLL(interp
);
219 Parrot_pcc_set_namespace(interp
, CURRENT_CONTEXT(interp
),
220 VTABLE_get_pmc_keyed_int(interp
, interp
->HLL_namespace
, 0));
222 /* We need a class hash */
223 interp
->class_hash
= classname_hash
= pmc_new(interp
, enum_class_NameSpace
);
224 Parrot_register_core_pmcs(interp
, classname_hash
);
226 /* init the interpreter globals array */
227 iglobals
= pmc_new(interp
, enum_class_FixedPMCArray
);
228 interp
->iglobals
= iglobals
;
229 VTABLE_set_integer_native(interp
, iglobals
, (INTVAL
)IGLOBALS_SIZE
);
231 /* clear the array */
232 for (i
= 0; i
< (INTVAL
)IGLOBALS_SIZE
; i
++)
233 VTABLE_set_pmc_keyed_int(interp
, iglobals
, i
, NULL
);
238 * c-file-style: "parrot"
240 * vim: expandtab shiftwidth=4: