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 "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.
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.
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
);
107 config_hash
= 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)>.
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;
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)>.
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();
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
= 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
= pmc_new(interp
, enum_class_Hash
);
189 VTABLE_set_pmc_keyed_int(interp
, iglobals
, IGLOBALS_PBC_LIBS
, pmc
);
191 pmc
= pmc_new(interp
, enum_class_Hash
);
192 VTABLE_set_pmc_keyed_int(interp
, iglobals
, IGLOBALS_DYN_LIBS
, pmc
);
197 =item C<static void parrot_global_setup_2(PARROT_INTERP)>
199 called from inmidst of PMC bootstrapping between pass 0 and 1
206 parrot_global_setup_2(PARROT_INTERP
)
208 ASSERT_ARGS(parrot_global_setup_2
)
209 PMC
*classname_hash
, *iglobals
;
212 create_initial_context(interp
);
214 /* create the namespace root stash */
215 interp
->root_namespace
= pmc_new(interp
, enum_class_NameSpace
);
216 Parrot_init_HLL(interp
);
218 Parrot_pcc_set_namespace(interp
, CURRENT_CONTEXT(interp
),
219 VTABLE_get_pmc_keyed_int(interp
, interp
->HLL_namespace
, 0));
221 /* We need a class hash */
222 interp
->class_hash
= classname_hash
= pmc_new(interp
, enum_class_NameSpace
);
223 Parrot_register_core_pmcs(interp
, classname_hash
);
225 /* init the interpreter globals array */
226 iglobals
= pmc_new(interp
, enum_class_FixedPMCArray
);
227 interp
->iglobals
= iglobals
;
228 VTABLE_set_integer_native(interp
, iglobals
, (INTVAL
)IGLOBALS_SIZE
);
230 /* clear the array */
231 for (i
= 0; i
< (INTVAL
)IGLOBALS_SIZE
; i
++)
232 VTABLE_set_pmc_keyed_int(interp
, iglobals
, i
, NULL
);
237 * c-file-style: "parrot"
239 * vim: expandtab shiftwidth=4: