Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 260 lines (228 sloc) 8.101 kb
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
1 #include "parrot/parrot.h"
2 #include "parrot/api.h"
1b6d1ce @Whiteknight start breaking up the embedding stuff into multiple files. Add embed_…
Whiteknight authored
3 #include "embed_private.h"
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
4
3f8ed92 @Whiteknight fix some file references and run headerizer to see my work so far
Whiteknight authored
5 /* HEADERIZER HFILE: include/parrot/api.h */
6
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
7 PARROT_API
8 PARROT_CANNOT_RETURN_NULL
9 PARROT_MALLOC
10 INTVAL
f2252b4 @Whiteknight remove the two-stage initialization dance. We can now initialize an i…
Whiteknight authored
11 Parrot_api_make_interpreter(ARGIN_NULLOK(PMC *parent), INTVAL flags, ARGIN_NULLOK(Parrot_Init_Args *args), ARGOUT(PMC **interp))
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
12 {
f2252b4 @Whiteknight remove the two-stage initialization dance. We can now initialize an i…
Whiteknight authored
13 ASSERT_ARGS(Parrot_api_make_interpreter)
4a128d5 @Whiteknight lots of little changes
Whiteknight authored
14 int alt_stacktop;
f2252b4 @Whiteknight remove the two-stage initialization dance. We can now initialize an i…
Whiteknight authored
15 void *stacktop_ptr = &alt_stacktop;
16 Parrot_set_config_hash();
17 {
18 Parrot_Interp * const parent_raw = PMC_IS_NULL(parent) ? NULL : GET_RAW_INTERP(parent);
19 Parrot_Interp * const interp_raw = allocate_interpreter(parent_raw, flags);
20 if (args) {
21 if (args->stack_top)
22 stacktop_ptr = args->stacktop;
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
23 if (args->gc_system) {
24 const INTVAL sysid = Parrot_gc_get_system_id(interp, args->gc_system);
25 if (sysid == -1)
26 EMBED_API_FAILURE(interp_pmc, interp);
27 interp->gc_sys->sys_type = sysid;
28 }
f2252b4 @Whiteknight remove the two-stage initialization dance. We can now initialize an i…
Whiteknight authored
29 if (args->gc_threshold)
30 interp->gc_threshold = args->gc_threshold;
31 if (args->hash_seed)
32 interp->hash_seed = args->hash_seed;
33 }
34 }
35 initialize_interpreter(interp_raw, stacktop);
4a128d5 @Whiteknight lots of little changes
Whiteknight authored
36 *interp_pmc = VTABLE_get_pmc_keyed_int(interp, iglobals, (INTVAL)IGLOBALS_INTERPRETER);
f2252b4 @Whiteknight remove the two-stage initialization dance. We can now initialize an i…
Whiteknight authored
37 return !PMC_IS_NULL(*interp);
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
38 }
39
40 PARROT_API
41 INTVAL
42 Parrot_api_set_runcore(ARGIN(PMC *interp_pmc), Parrot_Run_core_t core, Parrot_Uint trace)
43 {
44 ASSERT_ARGS(Parrot_api_set_runcore)
45 if (trace)
46 core = PARROT_SLOW_CORE;
47 EMBED_API_CALLIN(interp_pmc, interp)
48 Parrot_set_trace(interp, (Parrot_trace_flags)trace);
49 Parrot_set_run_core(interp, core);
50 EMBED_API_CALLOUT(interp_pmc, interp)
51 }
52
53 PARROT_API
54 INTVAL
f68bf56 @Whiteknight add Parrot_api_flag and Parrot_api_debug_flag. Use these in main.c in…
Whiteknight authored
55 Parrot_api_debug_flag(ARGMOD(PMC *interp_pmc), INTVAL flags, INTVAL set)
56 {
57 ASSERT_ARGS(Parrot_api_debug_flag)
58 EMBED_API_CALLIN(interp_pmc, interp);
59 if (set)
60 interp->debug_flags |= flags;
61 else
62 interp->debug_flags &= ~flags;
63 EMBED_API_CALLOUT(interp_pmc, interp);
64 }
65
66 PARROT_API
67 INTVAL
68 Parrot_api_flag(ARGMOD(PMC *interp_pmc), INTVAL flags, INTVAL set)
69 {
70 ASSERT_ARGS(Parrot_api_flag)
71 EMBED_API_CALLIN(interp_pmc, interp);
72 if (set) {
73 Interp_flags_SET(interp, flag);
74 if (flag & (PARROT_BOUNDS_FLAG | PARROT_PROFILE_FLAG))
75 Parrot_runcore_switch(interp, Parrot_str_new_constant(interp, "slow"));
76 }
77 else
78 Interp_flags_CLEAR(interp, flag);
79 EMBED_API_CALLOUT(interp_pmc, interp);
80 }
81
82 PARROT_API
83 INTVAL
84 Parrot_api_set_executable_name(ARGMOD(PMC *interp_pmc), ARGIN(const char * name))
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
85 {
86 ASSERT_ARGS(Parrot_api_set_executable_name)
4a128d5 @Whiteknight lots of little changes
Whiteknight authored
87 EMBED_API_CALLIN(interp_pmc, interp);
1a692e9 @Whiteknight _set_executable_name takes a C string instead of a Parrot string, for…
Whiteknight authored
88 STRING * const name_str = Parrot_str_new(interp, name, 0);
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
89 PMC * const name_pmc = Parrot_pmc_new(interp, enum_class_String);
1a692e9 @Whiteknight _set_executable_name takes a C string instead of a Parrot string, for…
Whiteknight authored
90 VTABLE_set_string_native(interp, name_pmc, name_str);
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
91 VTABLE_set_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_EXECUTABLE,
92 name_pmc);
4a128d5 @Whiteknight lots of little changes
Whiteknight authored
93 EMBED_API_CALLOUT(interp_pmc, interp);
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
94 }
95
96 PARROT_API
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
97 INTVAL
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
98 Parrot_api_destroy_interpreter(ARGIN(PMC *interp_pmc))
99 {
100 ASSERT_ARGS(Parrot_api_destroy_interpreter)
4a128d5 @Whiteknight lots of little changes
Whiteknight authored
101 EMBED_API_CALLIN(interp_pmc, interp);
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
102 Parrot_destroy(interp);
1a692e9 @Whiteknight _set_executable_name takes a C string instead of a Parrot string, for…
Whiteknight authored
103 Parrot_exit(interp, 0);
4a128d5 @Whiteknight lots of little changes
Whiteknight authored
104 EMBED_API_CALLOUT(interp_pmc, interp);
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
105 }
106
107 /*
108
3f8ed92 @Whiteknight fix some file references and run headerizer to see my work so far
Whiteknight authored
109 =item C<PARROT_API INTVAL Parrot_api_load_bytecode_file(PMC *interp_pmc, const
110 char *filename, PMC **pbc)>
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
111
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
112 Load a bytecode file and return a bytecode PMC.
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
113
114 =cut
115
116 */
117
118 PARROT_API
119 INTVAL
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
120 Parrot_api_load_bytecode_file(ARGMOD(PMC *interp_pmc), ARGIN(const char *filename), ARGOUT(PMC **pbc))
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
121 {
122 ASSERT_ARGS(Parrot_api_load_bytecode_file)
123 EMBED_API_CALLIN(interp_pmc, interp);
124 PackFile * const pf = Parrot_pbc_read(interp, filename, 0);
125 if (!pf)
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
126 EMBED_API_FAILURE(interp_pmc, interp);
127 *pbc = Parrot_pmc_new(interp, enum_class_PackFile);
128 VTABLE_set_pointer(interp, *pbc, pf);
129 EMBED_API_CALLOUT(interp_pmc, interp);
130 }
131
132 PARROT_API
133 INTVAL
134 Parrot_api_run_bytecode(ARGMOD(PMC *interp_pmc), ARGIN(PMC *pbc), ARGIN(PMC *mainargs))
135 {
136 ASSERT_ARGS(Parrot_api_run_bytecode)
137 EMBED_API_CALLIN(interp_pmc, interp);
138 PackFile * const pf = VTABLE_get_pointer(interp, pbc);
139 if (!pf)
140 EMBED_API_FAILURE(interp_pmc, interp);
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
141 Parrot_pbc_load(interp, pf);
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
142 PackFile_fixup_subs(interp, PBC_IMMEDIATE, NULL);
143 PackFile_fixup_subs(interp, PBC_POSTCOMP, NULL);
144 PackFile_fixup_subs(interp, PBC_MAIN, NULL);
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
145 EMBED_API_CALLOUT(interp_pmc, interp);
146 }
4a128d5 @Whiteknight lots of little changes
Whiteknight authored
147
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
148 PARROT_API
149 INTVAL
150 Parrot_api_build_argv_array(ARGMOD(PMC *interp_pmc), INTVAL argc, ARGIN(char **argv), ARGOUT(PMC **args))
151 {
152 ASSERT_ARGS(Parrot_api_build_argv_array)
153 EMBED_API_CALLIN(interp_pmc, interp);
154 PMC * const userargv = Parrot_pmc_new(interp, enum_class_ResizableStringArray);
155 INTVAL i;
156
157 for (i = 0; i < argc; ++i) {
158 /* Run through argv, adding everything to the array */
159 STRING * const arg = Parrot_str_new_init(interp, argv[i], strlen(argv[i]),
160 Parrot_utf8_encoding_ptr, PObj_external_FLAG);
161 VTABLE_push_string(interp, userargv, arg);
162 }
163 *args = userargv;
164 EMBED_API_CALLIN(interp_pmc, interp);
165 }
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
166
167 PARROT_API
168 INTVAL
169 Parrot_api_set_warnings(ARGMOD(PMC *interp_pmc), INTVAL flags)
170 {
171 ASSERT_ARGS(Parrot_api_set_warnings)
172 EMBED_API_CALLIN(interp_pmc, interp);
173 /* Activates the given warnings. (Macro from warnings.h.) */
174 PARROT_WARNINGS_on(interp, (Parrot_warnclass)flags);
175 EMBED_API_CALLOUT(interp_pmc, interp);
176 }
177
178 PARROT_API
179 INTVAL
180 Parrot_api_set_output_file(ARGMOD(PMC *interp_pmc), ARGIN(const char * filename))
181 {
182 ASSERT_ARGS(Parrot_api_set_output_file)
183 EMBED_API_CALLIN(interp_pmc, interp);
184 if (!filename && !interp->output_file)
185 interp->output_file = "-";
186 else
187 interp->output_file = filename;
188 EMBED_API_CALLOUT(interp_pmc, interp);
189 }
190
191 PARROT_API
192 INTVAL
193 Parrt_api_add_library_search_path(ARGMOD(PMC *interp_pmc), ARGIN(const char *path))
194 {
195 ASSERT_ARGS(Parrot_api_add_library_search_path)
196 EMBED_API_CALLIN(interp_pmc, interp);
197 Parrot_lib_add_path_from_cstring(interp, path, PARROT_LIB_PATH_LIBRARY);
198 EMBED_API_CALLOUT(interp_pmc, interp);
199 }
200
201 PARROT_API
202 INTVAL
203 Parrt_api_add_include_search_path(ARGMOD(PMC *interp_pmc), ARGIN(const char *path))
204 {
205 ASSERT_ARGS(Parrot_api_add_include_search_path)
206 EMBED_API_CALLIN(interp_pmc, interp);
207 Parrot_lib_add_path_from_cstring(interp, path, PARROT_LIB_PATH_INCLUDE);
208 EMBED_API_CALLOUT(interp_pmc, interp);
209 }
210
211 PARROT_API
212 INTVAL
213 Parrt_api_add_dynext_search_path(ARGMOD(PMC *interp_pmc), ARGIN(const char *path))
214 {
215 ASSERT_ARGS(Parrot_api_add_dynext_search_path)
216 EMBED_API_CALLIN(interp_pmc, interp);
217 Parrot_lib_add_path_from_cstring(interp, path, PARROT_LIB_PATH_DYNEXT);
218 EMBED_API_CALLOUT(interp_pmc, interp);
219 }
3259cda First cut of Parrot_api_set_stdhandles API function
Mariano Wahlmann authored
220
221 /*
222
3f8ed92 @Whiteknight fix some file references and run headerizer to see my work so far
Whiteknight authored
223 =item C<PARROT_API INTVAL Parrot_api_set_stdhandles(PMC *interp_pmc, INTVAL
224 stdin, INTVAL stdout, INTVAL stderr)>
3259cda First cut of Parrot_api_set_stdhandles API function
Mariano Wahlmann authored
225
226 Set the std file descriptors for the embedded interpreter. Any file descriptor
227 passed as argument and set to C<PIO_INVALID_HANDLE> is ignored.
228
229 =cut
230
231 */
232
233 PARROT_API
234 INTVAL
235 Parrot_api_set_stdhandles(ARGIN(PMC *interp_pmc), INTVAL stdin, INTVAL stdout, INTVAL stderr)
236 {
237 ASSERT_ARGS(Parrot_api_set_stdhandles)
238 EMBED_API_CALLIN(interp_pmc, interp);
239
240 if(PIO_INVALID_HANDLE != (PIOHANDLE)stdin) {
241 PMC * const pmc = Parrot_pmc_new(interp, enum_class_FileHandle);
bce0e57 Fix typo in stdin branch
Mariano Wahlmann authored
242 Parrot_io_set_os_handle(interp, pmc, (PIOHANDLE)stdin);
3259cda First cut of Parrot_api_set_stdhandles API function
Mariano Wahlmann authored
243 Parrot_io_sethandle(interp,PIO_STDIN_FILENO,pmc);
244 }
245
246 if(PIO_INVALID_HANDLE != (PIOHANDLE)stdout) {
247 PMC * const pmc = Parrot_pmc_new(interp, enum_class_FileHandle);
3e24c1d Fix typos on stdout & stderr branches
Mariano Wahlmann authored
248 Parrot_io_set_os_handle(interp, pmc, (PIOHANDLE)stdout);
3259cda First cut of Parrot_api_set_stdhandles API function
Mariano Wahlmann authored
249 Parrot_io_sethandle(interp,PIO_STDOUT_FILENO,pmc);
250 }
251
252 if(PIO_INVALID_HANDLE != (PIOHANDLE)stderr) {
253 PMC * const pmc = Parrot_pmc_new(interp, enum_class_FileHandle);
3e24c1d Fix typos on stdout & stderr branches
Mariano Wahlmann authored
254 Parrot_io_set_os_handle(interp, pmc, (PIOHANDLE)stderr);
3259cda First cut of Parrot_api_set_stdhandles API function
Mariano Wahlmann authored
255 Parrot_io_sethandle(interp,PIO_STDERR_FILENO,pmc);
256 }
257
258 EMBED_API_CALLOUT(interp_pmc, interp);
259 }
Something went wrong with that request. Please try again.