Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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