Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 471 lines (409 sloc) 15.119 kb
540a832 @jkeenan [codingstd] Mostly linelength fixes.
jkeenan authored
1 /*
2 Copyright (C) 2010, Parrot Foundation.
3
4 =head1 NAME
5
6 src/embed/api.c - TO COME
7
8 =head1 DESCRIPTION
9
10 TO COME.
11
12 =cut
13
14 */
15
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
16 #include "parrot/parrot.h"
704e3c4 @bluescreen10 Made another test case pass by putting debug information. Also remove…
bluescreen10 authored
17 #include "parrot/runcore_api.h"
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
18 #include "parrot/embed.h"
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
19 #include "parrot/api.h"
1b6d1ce @Whiteknight start breaking up the embedding stuff into multiple files. Add embed_…
Whiteknight authored
20 #include "embed_private.h"
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
21
3f8ed92 @Whiteknight fix some file references and run headerizer to see my work so far
Whiteknight authored
22 /* HEADERIZER HFILE: include/parrot/api.h */
23
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
24 PARROT_API
f41cf98 @Whiteknight many more fixes. We build main.c now but fail in some of the alternat…
Whiteknight authored
25 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
26 Parrot_api_get_result(Parrot_PMC interp_pmc, ARGOUT(Parrot_Int *is_error),
27 ARGOUT(Parrot_PMC * exception), ARGOUT(Parrot_Int *exit_code),
28 ARGOUT(Parrot_String * errmsg))
f41cf98 @Whiteknight many more fixes. We build main.c now but fail in some of the alternat…
Whiteknight authored
29 {
2483c68 @Whiteknight implement the new error-handling mechanism. Instead of a string, we p…
Whiteknight authored
30 EMBED_API_CALLIN(interp_pmc, interp)
be50d63 @bluescreen10 Implemented first version of Parrot_get_result, now a lot of failing …
bluescreen10 authored
31 *exit_code = interp->exit_code;
2483c68 @Whiteknight implement the new error-handling mechanism. Instead of a string, we p…
Whiteknight authored
32 *exception = interp->final_exception;
33 if (PMC_IS_NULL(exception)) {
34 *is_error = 0;
35 *errmsg = STRINGNULL;
9703ef5 @jkeenan [codingstd] C-style coda needed. No cuddled elses.
jkeenan authored
36 }
37 else {
2483c68 @Whiteknight implement the new error-handling mechanism. Instead of a string, we p…
Whiteknight authored
38 *is_error = !interp->exit_code;
39 *errmsg = VTABLE_get_string(interp, *exception);
40 }
41 interp->final_exception = PMCNULL;
be50d63 @bluescreen10 Implemented first version of Parrot_get_result, now a lot of failing …
bluescreen10 authored
42 interp->exit_code = 0;
2483c68 @Whiteknight implement the new error-handling mechanism. Instead of a string, we p…
Whiteknight authored
43 EMBED_API_CALLOUT(interp_pmc, interp)
44 }
45
46 PARROT_API
47 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
48 Parrot_api_get_exception_backtrace(Parrot_PMC interp_pmc,
49 Parrot_PMC exception, ARGOUT(Parrot_String * bt))
2483c68 @Whiteknight implement the new error-handling mechanism. Instead of a string, we p…
Whiteknight authored
50 {
51 EMBED_API_CALLIN(interp_pmc, interp)
52 STRING * const bts = Parrot_dbg_get_exception_backtrace(interp, exception);
53 *bt = bts;
54 EMBED_API_CALLOUT(interp_pmc, interp)
f41cf98 @Whiteknight many more fixes. We build main.c now but fail in some of the alternat…
Whiteknight authored
55 }
56
57 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
58 Parrot_Int
709eae7 @Whiteknight add in a handful of additional API functions, though they aren't bein…
Whiteknight authored
59 Parrot_api_make_interpreter(Parrot_PMC parent, Parrot_Int flags,
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
60 ARGIN_NULLOK(Parrot_Init_Args *args), ARGOUT(Parrot_PMC *interp))
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
61 {
f2252b4 @Whiteknight remove the two-stage initialization dance. We can now initialize an i…
Whiteknight authored
62 ASSERT_ARGS(Parrot_api_make_interpreter)
4a128d5 @Whiteknight lots of little changes
Whiteknight authored
63 int alt_stacktop;
c1ab56e More fixes, almost there
Mariano Wahlmann authored
64 Parrot_Interp interp_raw;
f2252b4 @Whiteknight remove the two-stage initialization dance. We can now initialize an i…
Whiteknight authored
65 void *stacktop_ptr = &alt_stacktop;
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
66 PMC * iglobals;
82cbd84 @Whiteknight parrot executable compiles, but miniparrot does not link. I need to s…
Whiteknight authored
67 const Parrot_Interp parent_raw = PMC_IS_NULL(parent) ? NULL : GET_RAW_INTERP(parent);
68 interp_raw = allocate_interpreter(parent_raw, flags);
69 if (args) {
70 if (args->stacktop)
71 stacktop_ptr = args->stacktop;
72 if (args->gc_system)
73 Parrot_gc_set_system_type(interp_raw, args->gc_system);
74 if (args->gc_threshold)
75 interp_raw->gc_threshold = args->gc_threshold;
76 if (args->hash_seed)
77 interp_raw->hash_seed = args->hash_seed;
f2252b4 @Whiteknight remove the two-stage initialization dance. We can now initialize an i…
Whiteknight authored
78 }
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
79 initialize_interpreter(interp_raw, stacktop_ptr);
80 iglobals = interp_raw->iglobals;
540a832 @jkeenan [codingstd] Mostly linelength fixes.
jkeenan authored
81 *interp = VTABLE_get_pmc_keyed_int(
82 interp_raw, interp_raw->iglobals, (Parrot_Int)IGLOBALS_INTERPRETER);
f2252b4 @Whiteknight remove the two-stage initialization dance. We can now initialize an i…
Whiteknight authored
83 return !PMC_IS_NULL(*interp);
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
84 }
85
86 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
87 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
88 Parrot_api_set_runcore(Parrot_PMC interp_pmc, ARGIN(const char * corename),
89 Parrot_UInt trace)
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
90 {
91 ASSERT_ARGS(Parrot_api_set_runcore)
3ea891c First round of syntax error fixes
Mariano Wahlmann authored
92 EMBED_API_CALLIN(interp_pmc, interp)
f41cf98 @Whiteknight many more fixes. We build main.c now but fail in some of the alternat…
Whiteknight authored
93 if (trace) {
704e3c4 @bluescreen10 Made another test case pass by putting debug information. Also remove…
bluescreen10 authored
94 Parrot_pcc_trace_flags_on(interp, interp->ctx, trace);
95 Parrot_runcore_switch(interp, Parrot_str_new_constant(interp, "slow"));
9703ef5 @jkeenan [codingstd] C-style coda needed. No cuddled elses.
jkeenan authored
96 }
97 else {
372f8f7 @bluescreen10 Make bounds runcore available
bluescreen10 authored
98 if (!strcmp(corename, "slow") || !strcmp(corename, "bounds"))
704e3c4 @bluescreen10 Made another test case pass by putting debug information. Also remove…
bluescreen10 authored
99 Parrot_runcore_switch(interp, Parrot_str_new_constant(interp, "slow"));
540a832 @jkeenan [codingstd] Mostly linelength fixes.
jkeenan authored
100 else if (!strcmp(corename, "fast") ||
101 !strcmp(corename, "jit") || !strcmp(corename, "function"))
704e3c4 @bluescreen10 Made another test case pass by putting debug information. Also remove…
bluescreen10 authored
102 Parrot_runcore_switch(interp, Parrot_str_new_constant(interp, "fast"));
f41cf98 @Whiteknight many more fixes. We build main.c now but fail in some of the alternat…
Whiteknight authored
103 else if (!strcmp(corename, "exec"))
704e3c4 @bluescreen10 Made another test case pass by putting debug information. Also remove…
bluescreen10 authored
104 Parrot_runcore_switch(interp, Parrot_str_new_constant(interp, "exec"));
f41cf98 @Whiteknight many more fixes. We build main.c now but fail in some of the alternat…
Whiteknight authored
105 else if (!strcmp(corename, "trace"))
704e3c4 @bluescreen10 Made another test case pass by putting debug information. Also remove…
bluescreen10 authored
106 Parrot_runcore_switch(interp, Parrot_str_new_constant(interp, "slow"));
f41cf98 @Whiteknight many more fixes. We build main.c now but fail in some of the alternat…
Whiteknight authored
107 else if (!strcmp(corename, "profiling"))
704e3c4 @bluescreen10 Made another test case pass by putting debug information. Also remove…
bluescreen10 authored
108 Parrot_runcore_switch(interp, Parrot_str_new_constant(interp, "profiling"));
f41cf98 @Whiteknight many more fixes. We build main.c now but fail in some of the alternat…
Whiteknight authored
109 else if (!strcmp(corename, "gcdebug"))
704e3c4 @bluescreen10 Made another test case pass by putting debug information. Also remove…
bluescreen10 authored
110 Parrot_runcore_switch(interp, Parrot_str_new_constant(interp, "gcdebug"));
f41cf98 @Whiteknight many more fixes. We build main.c now but fail in some of the alternat…
Whiteknight authored
111 else
112 Parrot_ex_throw_from_c_args(interp, NULL, 1, "Invalid runcore type %s", corename);
113 }
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
114 EMBED_API_CALLOUT(interp_pmc, interp)
115 }
116
117 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
118 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
119 Parrot_api_debug_flag(Parrot_PMC interp_pmc, Parrot_Int flags, Parrot_Int set)
f68bf56 @Whiteknight add Parrot_api_flag and Parrot_api_debug_flag. Use these in main.c in…
Whiteknight authored
120 {
121 ASSERT_ARGS(Parrot_api_debug_flag)
c1ab56e More fixes, almost there
Mariano Wahlmann authored
122 EMBED_API_CALLIN(interp_pmc, interp)
f68bf56 @Whiteknight add Parrot_api_flag and Parrot_api_debug_flag. Use these in main.c in…
Whiteknight authored
123 if (set)
124 interp->debug_flags |= flags;
125 else
126 interp->debug_flags &= ~flags;
127 EMBED_API_CALLOUT(interp_pmc, interp);
128 }
129
130 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
131 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
132 Parrot_api_flag(Parrot_PMC interp_pmc, Parrot_Int flags, Parrot_Int set)
f68bf56 @Whiteknight add Parrot_api_flag and Parrot_api_debug_flag. Use these in main.c in…
Whiteknight authored
133 {
134 ASSERT_ARGS(Parrot_api_flag)
c1ab56e More fixes, almost there
Mariano Wahlmann authored
135 EMBED_API_CALLIN(interp_pmc, interp)
f68bf56 @Whiteknight add Parrot_api_flag and Parrot_api_debug_flag. Use these in main.c in…
Whiteknight authored
136 if (set) {
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
137 Interp_flags_SET(interp, flags);
138 if (flags & (PARROT_BOUNDS_FLAG | PARROT_PROFILE_FLAG))
f68bf56 @Whiteknight add Parrot_api_flag and Parrot_api_debug_flag. Use these in main.c in…
Whiteknight authored
139 Parrot_runcore_switch(interp, Parrot_str_new_constant(interp, "slow"));
140 }
141 else
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
142 Interp_flags_CLEAR(interp, flags);
f68bf56 @Whiteknight add Parrot_api_flag and Parrot_api_debug_flag. Use these in main.c in…
Whiteknight authored
143 EMBED_API_CALLOUT(interp_pmc, interp);
144 }
145
146 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
147 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
148 Parrot_api_set_executable_name(Parrot_PMC interp_pmc, ARGIN(const char * name))
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
149 {
150 ASSERT_ARGS(Parrot_api_set_executable_name)
c1ab56e More fixes, almost there
Mariano Wahlmann authored
151 EMBED_API_CALLIN(interp_pmc, interp)
1a692e9 @Whiteknight _set_executable_name takes a C string instead of a Parrot string, for…
Whiteknight authored
152 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
153 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
154 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
155 VTABLE_set_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_EXECUTABLE,
156 name_pmc);
4a128d5 @Whiteknight lots of little changes
Whiteknight authored
157 EMBED_API_CALLOUT(interp_pmc, interp);
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
158 }
159
160 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
161 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
162 Parrot_api_destroy_interpreter(Parrot_PMC interp_pmc)
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
163 {
164 ASSERT_ARGS(Parrot_api_destroy_interpreter)
c1ab56e More fixes, almost there
Mariano Wahlmann authored
165 EMBED_API_CALLIN(interp_pmc, interp)
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
166 Parrot_destroy(interp);
ae620cc @Whiteknight changes necessary so we build. Run fails horribly, but we build
Whiteknight authored
167 Parrot_x_exit(interp, 0);
4a128d5 @Whiteknight lots of little changes
Whiteknight authored
168 EMBED_API_CALLOUT(interp_pmc, interp);
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
169 }
170
171 /*
172
9703ef5 @jkeenan [codingstd] C-style coda needed. No cuddled elses.
jkeenan authored
173 =over 4
174
709eae7 @Whiteknight add in a handful of additional API functions, though they aren't bein…
Whiteknight authored
175 =item C<PARROT_API Parrot_Int Parrot_api_load_bytecode_file(Parrot_PMC
176 interp_pmc, const char *filename, Parrot_PMC * pbc)>
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
177
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
178 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
179
180 =cut
181
182 */
183
709eae7 @Whiteknight add in a handful of additional API functions, though they aren't bein…
Whiteknight authored
184 // TODO: This only works with the inital bytecode. After this we should use
185 // Parrot_append_bytecode or something similar
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
186 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
187 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
188 Parrot_api_load_bytecode_file(Parrot_PMC interp_pmc,
189 ARGIN(const char *filename), ARGOUT(Parrot_PMC * pbc))
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
190 {
191 ASSERT_ARGS(Parrot_api_load_bytecode_file)
c1ab56e More fixes, almost there
Mariano Wahlmann authored
192 EMBED_API_CALLIN(interp_pmc, interp)
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
193 PackFile * const pf = Parrot_pbc_read(interp, filename, 0);
194 if (!pf)
f41cf98 @Whiteknight many more fixes. We build main.c now but fail in some of the alternat…
Whiteknight authored
195 Parrot_ex_throw_from_c_args(interp, NULL, 1, "Could not load packfile");
46b7a9d @Whiteknight upconvert pbc_to_exe to use the new API. it builds, but segfaults bui…
Whiteknight authored
196 do_sub_pragmas(interp, pf->cur_cs, PBC_PBC, NULL);
950d701 @Whiteknight Packfile PMCs don't do what I need them to do (yet). Use UnManagedStr…
Whiteknight authored
197 *pbc = Parrot_pmc_new(interp, enum_class_UnManagedStruct);
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
198 VTABLE_set_pointer(interp, *pbc, pf);
c1ab56e More fixes, almost there
Mariano Wahlmann authored
199 EMBED_API_CALLOUT(interp_pmc, interp)
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
200 }
201
202 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
203 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
204 Parrot_api_load_bytecode_bytes(Parrot_PMC interp_pmc,
205 ARGIN(const unsigned char * const pbc), Parrot_Int bytecode_size,
206 ARGOUT(Parrot_PMC * pbcpmc))
46b7a9d @Whiteknight upconvert pbc_to_exe to use the new API. it builds, but segfaults bui…
Whiteknight authored
207 {
99428c2 Make src/embed/pmc.c & src/embed/api.c compile with gcc
Mariano Wahlmann authored
208 EMBED_API_CALLIN(interp_pmc, interp)
46b7a9d @Whiteknight upconvert pbc_to_exe to use the new API. it builds, but segfaults bui…
Whiteknight authored
209 PackFile * const pf = PackFile_new(interp, 0);
210 if (!pf)
211 Parrot_ex_throw_from_c_args(interp, NULL, 1, "Could not create packfile");
212
213 if (!PackFile_unpack(interp, pf, (const opcode_t *)pbc, bytecode_size))
214 Parrot_ex_throw_from_c_args(interp, NULL, 1, "could not unpack packfile");
215 do_sub_pragmas(interp, pf->cur_cs, PBC_PBC, NULL);
216 *pbcpmc = Parrot_pmc_new(interp, enum_class_UnManagedStruct);
217 VTABLE_set_pointer(interp, *pbcpmc, pf);
218 EMBED_API_CALLOUT(interp_pmc, interp);
219 }
220
709eae7 @Whiteknight add in a handful of additional API functions, though they aren't bein…
Whiteknight authored
221 // Load the bytecode into the interpreter, but don't execute it
222 // TODO: This only works with the inital bytecode. After this we should use
223 // Parrot_append_bytecode or something similar
224 PARROT_API
225 Parrot_Int
226 Parrot_api_ready_bytecode(Parrot_PMC interp_pmc, Parrot_PMC pbc,
227 ARGOUT(Parrot_PMC *main_sub))
228 {
229 EMBED_API_CALLIN(interp_pmc, interp)
230 PackFile * const pf = (PackFile *)VTABLE_get_pointer(interp, pbc);
231
232 /* Debugging mode nonsense. */
233 if (Interp_debug_TEST(interp, PARROT_START_DEBUG_FLAG)) {
234 Parrot_io_eprintf(interp, "*** Parrot VM: %Ss core ***\n",
235 interp->run_core->name);
236 }
237
238 if (!pf)
239 Parrot_ex_throw_from_c_args(interp, NULL, 1, "Could not get packfile");
240 if (pf->cur_cs != NULL)
241 Parrot_pbc_load(interp, pf);
242 PackFile_fixup_subs(interp, PBC_IMMEDIATE, NULL);
243 PackFile_fixup_subs(interp, PBC_POSTCOMP, NULL);
244 PackFile_fixup_subs(interp, PBC_MAIN, NULL);
245 *main_sub = Parrot_pcc_get_sub(interp, CURRENT_CONTEXT(interp));
246 Parrot_pcc_set_constants(interp, interp->ctx, interp->code->const_table);
247 EMBED_API_CALLOUT(interp_pmc, interp)
248 }
249
46b7a9d @Whiteknight upconvert pbc_to_exe to use the new API. it builds, but segfaults bui…
Whiteknight authored
250 PARROT_API
251 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
252 Parrot_api_run_bytecode(Parrot_PMC interp_pmc, Parrot_PMC pbc,
253 Parrot_PMC mainargs)
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
254 {
255 ASSERT_ARGS(Parrot_api_run_bytecode)
c1ab56e More fixes, almost there
Mariano Wahlmann authored
256 EMBED_API_CALLIN(interp_pmc, interp)
65bf81a @Whiteknight actually run the code, don't just look at it. Miniparrot runs now. pa…
Whiteknight authored
257 PMC * main_sub = NULL;
258
98cd26c @Whiteknight don't call Parrot_pbc_load if the PBC comes straight out of IMCC. IMC…
Whiteknight authored
259 PackFile * const pf = (PackFile *)VTABLE_get_pointer(interp, pbc);
9f7a94c @Whiteknight make sure to set :main() args in the iglobals array. This makes ops2c…
Whiteknight authored
260
704e3c4 @bluescreen10 Made another test case pass by putting debug information. Also remove…
bluescreen10 authored
261 /* Debugging mode nonsense. */
262 if (Interp_debug_TEST(interp, PARROT_START_DEBUG_FLAG)) {
263 Parrot_io_eprintf(interp, "*** Parrot VM: %Ss core ***\n",
264 interp->run_core->name);
709eae7 @Whiteknight add in a handful of additional API functions, though they aren't bein…
Whiteknight authored
265 }
704e3c4 @bluescreen10 Made another test case pass by putting debug information. Also remove…
bluescreen10 authored
266
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
267 if (!pf)
f41cf98 @Whiteknight many more fixes. We build main.c now but fail in some of the alternat…
Whiteknight authored
268 Parrot_ex_throw_from_c_args(interp, NULL, 1, "Could not get packfile");
98cd26c @Whiteknight don't call Parrot_pbc_load if the PBC comes straight out of IMCC. IMC…
Whiteknight authored
269 if (pf->cur_cs != NULL)
270 Parrot_pbc_load(interp, pf);
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
271 PackFile_fixup_subs(interp, PBC_IMMEDIATE, NULL);
272 PackFile_fixup_subs(interp, PBC_POSTCOMP, NULL);
273 PackFile_fixup_subs(interp, PBC_MAIN, NULL);
65bf81a @Whiteknight actually run the code, don't just look at it. Miniparrot runs now. pa…
Whiteknight authored
274 main_sub = Parrot_pcc_get_sub(interp, CURRENT_CONTEXT(interp));
275
276 /* if no sub was marked being :main, we create a dummy sub with offset 0 */
277
278 if (!main_sub)
279 main_sub = set_current_sub(interp);
280
281 Parrot_pcc_set_sub(interp, CURRENT_CONTEXT(interp), NULL);
282 Parrot_pcc_set_constants(interp, interp->ctx, interp->code->const_table);
283
9f7a94c @Whiteknight make sure to set :main() args in the iglobals array. This makes ops2c…
Whiteknight authored
284 VTABLE_set_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_ARGV_LIST, mainargs);
65bf81a @Whiteknight actually run the code, don't just look at it. Miniparrot runs now. pa…
Whiteknight authored
285 Parrot_ext_call(interp, main_sub, "P->", mainargs);
c1ab56e More fixes, almost there
Mariano Wahlmann authored
286 EMBED_API_CALLOUT(interp_pmc, interp)
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
287 }
4a128d5 @Whiteknight lots of little changes
Whiteknight authored
288
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
289 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
290 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
291 Parrot_api_disassemble_bytecode(Parrot_PMC interp_pmc, Parrot_PMC pbc,
292 ARGIN(const char * const outfile), Parrot_Int opts)
590f387 @Whiteknight update pbc_disassemble to the new API. Had to add a new API function …
Whiteknight authored
293 {
e9934d7 Made it compile with gcc
Mariano Wahlmann authored
294 EMBED_API_CALLIN(interp_pmc, interp)
590f387 @Whiteknight update pbc_disassemble to the new API. Had to add a new API function …
Whiteknight authored
295 PackFile * const pf = (PackFile *)VTABLE_get_pointer(interp, pbc);
296 if (!pf)
297 Parrot_ex_throw_from_c_args(interp, NULL, 1, "Could not get packfile");
298 if (pf->cur_cs != NULL)
299 Parrot_pbc_load(interp, pf);
300 Parrot_disassemble(interp, outfile, (Parrot_disassemble_options)opts);
301 EMBED_API_CALLOUT(interp_pmc, interp);
302 }
303
304 PARROT_API
305 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
306 Parrot_api_build_argv_array(Parrot_PMC interp_pmc, Parrot_Int argc,
307 ARGIN(char ** argv), ARGOUT(Parrot_PMC * args))
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
308 {
309 ASSERT_ARGS(Parrot_api_build_argv_array)
c1ab56e More fixes, almost there
Mariano Wahlmann authored
310 EMBED_API_CALLIN(interp_pmc, interp)
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
311 PMC * const userargv = Parrot_pmc_new(interp, enum_class_ResizableStringArray);
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
312 Parrot_Int i;
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
313
314 for (i = 0; i < argc; ++i) {
315 /* Run through argv, adding everything to the array */
316 STRING * const arg = Parrot_str_new_init(interp, argv[i], strlen(argv[i]),
317 Parrot_utf8_encoding_ptr, PObj_external_FLAG);
318 VTABLE_push_string(interp, userargv, arg);
319 }
320 *args = userargv;
c1ab56e More fixes, almost there
Mariano Wahlmann authored
321 EMBED_API_CALLOUT(interp_pmc, interp)
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
322 }
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
323
324 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
325 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
326 Parrot_api_set_warnings(Parrot_PMC interp_pmc, Parrot_Int flags)
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
327 {
328 ASSERT_ARGS(Parrot_api_set_warnings)
c1ab56e More fixes, almost there
Mariano Wahlmann authored
329 EMBED_API_CALLIN(interp_pmc, interp)
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
330 /* Activates the given warnings. (Macro from warnings.h.) */
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
331 PARROT_WARNINGS_on(interp, flags);
c1ab56e More fixes, almost there
Mariano Wahlmann authored
332 EMBED_API_CALLOUT(interp_pmc, interp)
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
333 }
334
335 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
336 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
337 Parrot_api_set_output_file(Parrot_PMC interp_pmc,
338 ARGIN_NULLOK(const char * filename))
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
339 {
340 ASSERT_ARGS(Parrot_api_set_output_file)
c1ab56e More fixes, almost there
Mariano Wahlmann authored
341 EMBED_API_CALLIN(interp_pmc, interp)
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
342 if (!filename && !interp->output_file)
343 interp->output_file = "-";
344 else
345 interp->output_file = filename;
c1ab56e More fixes, almost there
Mariano Wahlmann authored
346 EMBED_API_CALLOUT(interp_pmc, interp)
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
347 }
348
349 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
350 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
351 Parrot_api_add_library_search_path(Parrot_PMC interp_pmc,
352 ARGIN(const char *path))
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
353 {
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
354 //ASSERT_ARGS(Parrot_api_add_library_search_path)
c1ab56e More fixes, almost there
Mariano Wahlmann authored
355 EMBED_API_CALLIN(interp_pmc, interp)
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
356 Parrot_lib_add_path_from_cstring(interp, path, PARROT_LIB_PATH_LIBRARY);
c1ab56e More fixes, almost there
Mariano Wahlmann authored
357 EMBED_API_CALLOUT(interp_pmc, interp)
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
358 }
359
360 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
361 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
362 Parrot_api_add_include_search_path(Parrot_PMC interp_pmc,
363 ARGIN(const char *path))
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
364 {
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
365 //ASSERT_ARGS(Parrot_api_add_include_search_path)
c1ab56e More fixes, almost there
Mariano Wahlmann authored
366 EMBED_API_CALLIN(interp_pmc, interp)
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
367 Parrot_lib_add_path_from_cstring(interp, path, PARROT_LIB_PATH_INCLUDE);
c1ab56e More fixes, almost there
Mariano Wahlmann authored
368 EMBED_API_CALLOUT(interp_pmc, interp)
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
369 }
370
371 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
372 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
373 Parrot_api_add_dynext_search_path(Parrot_PMC interp_pmc,
374 ARGIN(const char *path))
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
375 {
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
376 //ASSERT_ARGS(Parrot_api_add_dynext_search_path)
c1ab56e More fixes, almost there
Mariano Wahlmann authored
377 EMBED_API_CALLIN(interp_pmc, interp)
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
378 Parrot_lib_add_path_from_cstring(interp, path, PARROT_LIB_PATH_DYNEXT);
c1ab56e More fixes, almost there
Mariano Wahlmann authored
379 EMBED_API_CALLOUT(interp_pmc, interp)
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
380 }
3259cda First cut of Parrot_api_set_stdhandles API function
Mariano Wahlmann authored
381
382 /*
383
709eae7 @Whiteknight add in a handful of additional API functions, though they aren't bein…
Whiteknight authored
384 =item C<PARROT_API Parrot_Int Parrot_api_set_stdhandles(Parrot_PMC interp_pmc,
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
385 Parrot_Int stdin, Parrot_Int stdout, Parrot_Int stderr)>
3259cda First cut of Parrot_api_set_stdhandles API function
Mariano Wahlmann authored
386
387 Set the std file descriptors for the embedded interpreter. Any file descriptor
388 passed as argument and set to C<PIO_INVALID_HANDLE> is ignored.
389
390 =cut
391
392 */
393
394 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
395 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
396 Parrot_api_set_stdhandles(Parrot_PMC interp_pmc, Parrot_Int stdin,
397 Parrot_Int stdout, Parrot_Int stderr)
3259cda First cut of Parrot_api_set_stdhandles API function
Mariano Wahlmann authored
398 {
f41cf98 @Whiteknight many more fixes. We build main.c now but fail in some of the alternat…
Whiteknight authored
399 ASSERT_ARGS(Parrot_api_set_stdhandles)
400 EMBED_API_CALLIN(interp_pmc, interp)
401 void *dummy;
402
403 if(PIO_INVALID_HANDLE != (PIOHANDLE)stdin) {
404 PMC * const pmc = Parrot_pmc_new(interp, enum_class_FileHandle);
405 Parrot_io_set_os_handle(interp, pmc, (PIOHANDLE)stdin);
406 dummy = (void *)Parrot_io_stdhandle(interp,PIO_STDIN_FILENO,pmc);
407 }
408
409 if(PIO_INVALID_HANDLE != (PIOHANDLE)stdout) {
410 PMC * const pmc = Parrot_pmc_new(interp, enum_class_FileHandle);
411 Parrot_io_set_os_handle(interp, pmc, (PIOHANDLE)stdout);
412 dummy = (void *)Parrot_io_stdhandle(interp,PIO_STDOUT_FILENO,pmc);
413 }
414
415 if(PIO_INVALID_HANDLE != (PIOHANDLE)stderr) {
416 PMC * const pmc = Parrot_pmc_new(interp, enum_class_FileHandle);
417 Parrot_io_set_os_handle(interp, pmc, (PIOHANDLE)stderr);
418 dummy = (void *)Parrot_io_stdhandle(interp,PIO_STDERR_FILENO,pmc);
419 }
420
421 EMBED_API_CALLOUT(interp_pmc, interp)
3259cda First cut of Parrot_api_set_stdhandles API function
Mariano Wahlmann authored
422 }
f41cf98 @Whiteknight many more fixes. We build main.c now but fail in some of the alternat…
Whiteknight authored
423
424 PARROT_API
425 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
426 Parrot_api_get_runtime_path(Parrot_PMC interp_pmc,
427 ARGOUT(Parrot_String *runtime))
f41cf98 @Whiteknight many more fixes. We build main.c now but fail in some of the alternat…
Whiteknight authored
428 {
e9934d7 Made it compile with gcc
Mariano Wahlmann authored
429 EMBED_API_CALLIN(interp_pmc, interp)
f41cf98 @Whiteknight many more fixes. We build main.c now but fail in some of the alternat…
Whiteknight authored
430 *runtime = Parrot_get_runtime_path(interp);
431 EMBED_API_CALLOUT(interp_pmc, interp);
432 }
433
c4ccd13 @Whiteknight first prototype of a new mechanism for setting the configuration hash…
Whiteknight authored
434 PARROT_API
435 Parrot_Int
436 Parrot_api_set_configuration_hash(Parrot_PMC interp_pmc, Parrot_PMC confighash)
437 {
e9934d7 Made it compile with gcc
Mariano Wahlmann authored
438 EMBED_API_CALLIN(interp_pmc, interp)
c4ccd13 @Whiteknight first prototype of a new mechanism for setting the configuration hash…
Whiteknight authored
439 Parrot_set_config_hash_pmc(interp, confighash);
5c2c3d4 @Whiteknight fix library paths. The build now progresses through all the parts tha…
Whiteknight authored
440 Parrot_lib_update_paths_from_config_hash(interp);
c4ccd13 @Whiteknight first prototype of a new mechanism for setting the configuration hash…
Whiteknight authored
441 EMBED_API_CALLOUT(interp_pmc, interp);
442 }
443
e1ced3e @Whiteknight add a note explaining this stupid function
Whiteknight authored
444 /*
445 This is an evil hack to provide a wrapper around IMCC to catch unhandled
446 exceptions without having to assume IMCC is linked in with libparrot. Delete
447 this as soon as we don't need it anymore.
448 */
449
5b6a239 @Whiteknight Add a new, temporary hack API for wrapping up IMCC so we can catch er…
Whiteknight authored
450 PARROT_API
451 Parrot_Int
e1ced3e @Whiteknight add a note explaining this stupid function
Whiteknight authored
452 Parrot_api_wrap_imcc_hack(Parrot_PMC interp_pmc, const char * sourcefile,
453 int argc, const char **argv, Parrot_PMC* bytecodepmc, int *result,
454 imcc_hack_func_t func)
5b6a239 @Whiteknight Add a new, temporary hack API for wrapping up IMCC so we can catch er…
Whiteknight authored
455 {
456 EMBED_API_CALLIN(interp_pmc, interp)
457 *result = func(interp_pmc, sourcefile, argc, argv, bytecodepmc);
458 EMBED_API_CALLOUT(interp_pmc, interp)
459 }
c4ccd13 @Whiteknight first prototype of a new mechanism for setting the configuration hash…
Whiteknight authored
460
9703ef5 @jkeenan [codingstd] C-style coda needed. No cuddled elses.
jkeenan authored
461 =back
462
463 =cut
464
540a832 @jkeenan [codingstd] Mostly linelength fixes.
jkeenan authored
465 /*
466 * Local variables:
467 * c-file-style: "parrot"
468 * End:
469 * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
470 */
Something went wrong with that request. Please try again.