* docs/pmc.pod:
[parrot.git] / src / global_setup.c
blob8fa886ec79c4f1761389ce9993220f1f3d3ea5aa
1 /*
2 Copyright (C) 2001-2006, 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 extern void Parrot_initialize_core_pmcs(Interp *interpreter);
31 static const unsigned char* parrot_config_stored = NULL;
32 static unsigned int parrot_config_size_stored = 0;
37 =item C<void
38 Parrot_set_config_hash_internal (const unsigned char* parrot_config,
39 unsigned int parrot_config_size)>
41 Called by Parrot_set_config_hash with the serialised hash which
42 will be used in subsequently created Interpreters
44 =cut
48 void
49 Parrot_set_config_hash_internal (const unsigned char* parrot_config,
50 unsigned int parrot_config_size)
52 parrot_config_stored = parrot_config;
53 parrot_config_size_stored = parrot_config_size;
58 =item C<void parrot_set_config_hash_interpreter (Interp* interpreter)>
61 Used internally to associate the config hash with an Interpreter
62 using the last registered config data.
64 =cut
68 static void
69 parrot_set_config_hash_interpreter (Interp* interpreter)
71 PMC *iglobals = interpreter->iglobals;
73 PMC *config_hash = NULL;
75 if (parrot_config_size_stored > 1)
77 STRING *config_string =
78 string_make_direct(interpreter,
79 parrot_config_stored, parrot_config_size_stored,
80 PARROT_DEFAULT_ENCODING, PARROT_DEFAULT_CHARSET,
81 PObj_external_FLAG|PObj_constant_FLAG);
83 config_hash = Parrot_thaw(interpreter, config_string);
85 else
87 config_hash = pmc_new(interpreter, enum_class_Hash);
90 VTABLE_set_pmc_keyed_int(interpreter, iglobals,
91 (INTVAL) IGLOBALS_CONFIG_HASH, config_hash);
97 =item C<void init_world(Interp *interpreter)>
99 This is the actual initialization code called by C<Parrot_init()>.
101 It sets up the Parrot system, running any platform-specific init code if
102 necessary, then initializing the string subsystem, and setting up the
103 base vtables and core PMCs.
105 C<interpreter> should be the root interpreter returned by
106 C<Parrot_new(NULL)>.
108 =cut
112 void
113 init_world(Interp *interpreter)
115 PMC *iglobals;
116 PMC *self, *pmc;
118 #ifdef PARROT_HAS_PLATFORM_INIT_CODE
119 Parrot_platform_init_code();
120 #endif
122 parrot_alloc_vtables(interpreter);
124 /* Call base vtable class constructor methods */
125 Parrot_initialize_core_pmcs(interpreter);
127 iglobals = interpreter->iglobals;
128 VTABLE_set_pmc_keyed_int(interpreter, iglobals,
129 (INTVAL)IGLOBALS_CLASSNAME_HASH, interpreter->class_hash);
130 self = pmc_new_noinit(interpreter, enum_class_ParrotInterpreter);
131 PMC_data(self) = interpreter;
132 VTABLE_set_pmc_keyed_int(interpreter, iglobals,
133 (INTVAL) IGLOBALS_INTERPRETER, self);
135 parrot_set_config_hash_interpreter(interpreter);
138 * lib search paths
140 parrot_init_library_paths(interpreter);
142 * load_bytecode and dynlib loaded hash
144 pmc = pmc_new(interpreter, enum_class_Hash);
145 VTABLE_set_pmc_keyed_int(interpreter, iglobals,
146 IGLOBALS_PBC_LIBS, pmc);
147 pmc = pmc_new(interpreter, enum_class_Hash);
148 VTABLE_set_pmc_keyed_int(interpreter, iglobals,
149 IGLOBALS_DYN_LIBS, pmc);
153 * called from inmidst of PMC bootstrapping between pass 0 and 1
156 /* in generated src_core_pmcs.c */
157 void Parrot_register_core_pmcs(Interp *interp, PMC* registry);
159 void
160 parrot_global_setup_2(Interp *interpreter)
162 PMC *classname_hash, *iglobals;
163 int i;
164 PMC *parrot_ns;
166 /* create the namespace root stash */
167 interpreter->root_namespace = pmc_new(interpreter, enum_class_NameSpace);
169 interpreter->HLL_info = constant_pmc_new(interpreter,
170 enum_class_ResizablePMCArray);
171 interpreter->HLL_namespace = constant_pmc_new(interpreter,
172 enum_class_ResizablePMCArray);
174 Parrot_register_HLL(interpreter, const_string(interpreter, "parrot"), NULL);
176 parrot_ns = VTABLE_get_pmc_keyed_int(interpreter,
177 interpreter->HLL_namespace, 0);
178 CONTEXT(interpreter->ctx)->current_namespace = parrot_ns;
180 /* We need a class hash */
181 interpreter->class_hash = classname_hash =
182 pmc_new(interpreter, enum_class_NameSpace);
183 Parrot_register_core_pmcs(interpreter, classname_hash);
184 /* init the interpreter globals array */
185 iglobals = pmc_new(interpreter, enum_class_SArray);
186 interpreter->iglobals = iglobals;
187 VTABLE_set_integer_native(interpreter, iglobals, (INTVAL)IGLOBALS_SIZE);
188 /* clear the array */
189 for (i = 0; i < (INTVAL)IGLOBALS_SIZE; i++)
190 VTABLE_set_pmc_keyed_int(interpreter, iglobals, i, NULL);
195 =back
197 =head1 SEE ALSO
199 F<include/parrot/global_setup.h>.
201 =cut
207 * Local variables:
208 * c-file-style: "parrot"
209 * End:
210 * vim: expandtab shiftwidth=4: