Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 528 lines (448 sloc) 16.43 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;
73f662d @Whiteknight some fixes so libparrot builds with g++
Whiteknight authored
33 if (PMC_IS_NULL(*exception)) {
2483c68 @Whiteknight implement the new error-handling mechanism. Instead of a string, we p…
Whiteknight authored
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)
f41cf98 @Whiteknight many more fixes. We build main.c now but fail in some of the alternat…
Whiteknight authored
44 }
45
46 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
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))
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
50 {
2483c68 @Whiteknight implement the new error-handling mechanism. Instead of a string, we p…
Whiteknight authored
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 {
6be2b4a @Whiteknight remove the ASSERT_ARGS stuff, and other things that are borking thebu…
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 {
6be2b4a @Whiteknight remove the ASSERT_ARGS stuff, and other things that are borking thebu…
Whiteknight authored
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 {
6be2b4a @Whiteknight remove the ASSERT_ARGS stuff, and other things that are borking thebu…
Whiteknight authored
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 {
6be2b4a @Whiteknight remove the ASSERT_ARGS stuff, and other things that are borking thebu…
Whiteknight authored
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 {
6be2b4a @Whiteknight remove the ASSERT_ARGS stuff, and other things that are borking thebu…
Whiteknight authored
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 {
6be2b4a @Whiteknight remove the ASSERT_ARGS stuff, and other things that are borking thebu…
Whiteknight authored
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
b9cdf9c @jkeenan After fixing C++ comments, I re-ran headerizer and modified these fil…
jkeenan authored
175 =item C<Parrot_Int Parrot_api_load_bytecode_file(Parrot_PMC interp_pmc, const
176 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
6be2b4a @Whiteknight remove the ASSERT_ARGS stuff, and other things that are borking thebu…
Whiteknight authored
184 /* TODO: This only works with the inital bytecode. After this we should use
185 Parrot_append_bytecode or something similar */
186
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
187 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
188 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
189 Parrot_api_load_bytecode_file(Parrot_PMC interp_pmc,
190 ARGIN(const char *filename), ARGOUT(Parrot_PMC * pbc))
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
191 {
6be2b4a @Whiteknight remove the ASSERT_ARGS stuff, and other things that are borking thebu…
Whiteknight authored
192 //ASSERT_ARGS(Parrot_api_load_bytecode_file)
c1ab56e More fixes, almost there
Mariano Wahlmann authored
193 EMBED_API_CALLIN(interp_pmc, interp)
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
194 PackFile * const pf = Parrot_pbc_read(interp, filename, 0);
195 if (!pf)
f41cf98 @Whiteknight many more fixes. We build main.c now but fail in some of the alternat…
Whiteknight authored
196 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
197 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
198 *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
199 VTABLE_set_pointer(interp, *pbc, pf);
c1ab56e More fixes, almost there
Mariano Wahlmann authored
200 EMBED_API_CALLOUT(interp_pmc, interp)
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
201 }
202
203 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
204 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
205 Parrot_api_load_bytecode_bytes(Parrot_PMC interp_pmc,
206 ARGIN(const unsigned char * const pbc), Parrot_Int bytecode_size,
207 ARGOUT(Parrot_PMC * pbcpmc))
46b7a9d @Whiteknight upconvert pbc_to_exe to use the new API. it builds, but segfaults bui…
Whiteknight authored
208 {
99428c2 Make src/embed/pmc.c & src/embed/api.c compile with gcc
Mariano Wahlmann authored
209 EMBED_API_CALLIN(interp_pmc, interp)
46b7a9d @Whiteknight upconvert pbc_to_exe to use the new API. it builds, but segfaults bui…
Whiteknight authored
210 PackFile * const pf = PackFile_new(interp, 0);
211 if (!pf)
212 Parrot_ex_throw_from_c_args(interp, NULL, 1, "Could not create packfile");
213
214 if (!PackFile_unpack(interp, pf, (const opcode_t *)pbc, bytecode_size))
215 Parrot_ex_throw_from_c_args(interp, NULL, 1, "could not unpack packfile");
216 do_sub_pragmas(interp, pf->cur_cs, PBC_PBC, NULL);
217 *pbcpmc = Parrot_pmc_new(interp, enum_class_UnManagedStruct);
218 VTABLE_set_pointer(interp, *pbcpmc, pf);
219 EMBED_API_CALLOUT(interp_pmc, interp);
220 }
221
6be2b4a @Whiteknight remove the ASSERT_ARGS stuff, and other things that are borking thebu…
Whiteknight authored
222 /* Load the bytecode into the interpreter, but don't execute it */
223 /* TODO: This only works with the inital bytecode. After this we should use
224 Parrot_append_bytecode or something similar */
225
709eae7 @Whiteknight add in a handful of additional API functions, though they aren't bein…
Whiteknight authored
226 PARROT_API
227 Parrot_Int
228 Parrot_api_ready_bytecode(Parrot_PMC interp_pmc, Parrot_PMC pbc,
229 ARGOUT(Parrot_PMC *main_sub))
230 {
231 EMBED_API_CALLIN(interp_pmc, interp)
232 PackFile * const pf = (PackFile *)VTABLE_get_pointer(interp, pbc);
233
234 /* Debugging mode nonsense. */
235 if (Interp_debug_TEST(interp, PARROT_START_DEBUG_FLAG)) {
236 Parrot_io_eprintf(interp, "*** Parrot VM: %Ss core ***\n",
237 interp->run_core->name);
238 }
239
240 if (!pf)
241 Parrot_ex_throw_from_c_args(interp, NULL, 1, "Could not get packfile");
242 if (pf->cur_cs != NULL)
243 Parrot_pbc_load(interp, pf);
244 PackFile_fixup_subs(interp, PBC_IMMEDIATE, NULL);
245 PackFile_fixup_subs(interp, PBC_POSTCOMP, NULL);
246 PackFile_fixup_subs(interp, PBC_MAIN, NULL);
247 *main_sub = Parrot_pcc_get_sub(interp, CURRENT_CONTEXT(interp));
248 Parrot_pcc_set_constants(interp, interp->ctx, interp->code->const_table);
249 EMBED_API_CALLOUT(interp_pmc, interp)
250 }
251
46b7a9d @Whiteknight upconvert pbc_to_exe to use the new API. it builds, but segfaults bui…
Whiteknight authored
252 PARROT_API
253 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
254 Parrot_api_run_bytecode(Parrot_PMC interp_pmc, Parrot_PMC pbc,
255 Parrot_PMC mainargs)
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
256 {
6be2b4a @Whiteknight remove the ASSERT_ARGS stuff, and other things that are borking thebu…
Whiteknight authored
257 //ASSERT_ARGS(Parrot_api_run_bytecode)
c1ab56e More fixes, almost there
Mariano Wahlmann authored
258 EMBED_API_CALLIN(interp_pmc, interp)
65bf81a @Whiteknight actually run the code, don't just look at it. Miniparrot runs now. pa…
Whiteknight authored
259 PMC * main_sub = NULL;
260
98cd26c @Whiteknight don't call Parrot_pbc_load if the PBC comes straight out of IMCC. IMC…
Whiteknight authored
261 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
262
704e3c4 @bluescreen10 Made another test case pass by putting debug information. Also remove…
bluescreen10 authored
263 /* Debugging mode nonsense. */
264 if (Interp_debug_TEST(interp, PARROT_START_DEBUG_FLAG)) {
265 Parrot_io_eprintf(interp, "*** Parrot VM: %Ss core ***\n",
266 interp->run_core->name);
709eae7 @Whiteknight add in a handful of additional API functions, though they aren't bein…
Whiteknight authored
267 }
704e3c4 @bluescreen10 Made another test case pass by putting debug information. Also remove…
bluescreen10 authored
268
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
269 if (!pf)
f41cf98 @Whiteknight many more fixes. We build main.c now but fail in some of the alternat…
Whiteknight authored
270 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
271 if (pf->cur_cs != NULL)
272 Parrot_pbc_load(interp, pf);
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
273 PackFile_fixup_subs(interp, PBC_IMMEDIATE, NULL);
274 PackFile_fixup_subs(interp, PBC_POSTCOMP, NULL);
275 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
276 main_sub = Parrot_pcc_get_sub(interp, CURRENT_CONTEXT(interp));
277
278 /* if no sub was marked being :main, we create a dummy sub with offset 0 */
279
280 if (!main_sub)
281 main_sub = set_current_sub(interp);
282
283 Parrot_pcc_set_sub(interp, CURRENT_CONTEXT(interp), NULL);
284 Parrot_pcc_set_constants(interp, interp->ctx, interp->code->const_table);
285
9f7a94c @Whiteknight make sure to set :main() args in the iglobals array. This makes ops2c…
Whiteknight authored
286 VTABLE_set_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_ARGV_LIST, mainargs);
73f662d @Whiteknight some fixes so libparrot builds with g++
Whiteknight authored
287 Parrot_pcc_invoke_sub_from_c_args(interp, main_sub, "P->", mainargs);
c1ab56e More fixes, almost there
Mariano Wahlmann authored
288 EMBED_API_CALLOUT(interp_pmc, interp)
687438e @Whiteknight add in the prototype embedding API functions I've been playing with
Whiteknight authored
289 }
4a128d5 @Whiteknight lots of little changes
Whiteknight authored
290
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
291 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
292 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
293 Parrot_api_disassemble_bytecode(Parrot_PMC interp_pmc, Parrot_PMC pbc,
294 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
295 {
e9934d7 Made it compile with gcc
Mariano Wahlmann authored
296 EMBED_API_CALLIN(interp_pmc, interp)
590f387 @Whiteknight update pbc_disassemble to the new API. Had to add a new API function …
Whiteknight authored
297 PackFile * const pf = (PackFile *)VTABLE_get_pointer(interp, pbc);
298 if (!pf)
299 Parrot_ex_throw_from_c_args(interp, NULL, 1, "Could not get packfile");
300 if (pf->cur_cs != NULL)
301 Parrot_pbc_load(interp, pf);
302 Parrot_disassemble(interp, outfile, (Parrot_disassemble_options)opts);
303 EMBED_API_CALLOUT(interp_pmc, interp);
304 }
305
306 PARROT_API
307 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
308 Parrot_api_build_argv_array(Parrot_PMC interp_pmc, Parrot_Int argc,
73f662d @Whiteknight some fixes so libparrot builds with g++
Whiteknight authored
309 ARGIN(const char ** argv), ARGOUT(Parrot_PMC * args))
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
310 {
6be2b4a @Whiteknight remove the ASSERT_ARGS stuff, and other things that are borking thebu…
Whiteknight authored
311 //ASSERT_ARGS(Parrot_api_build_argv_array)
c1ab56e More fixes, almost there
Mariano Wahlmann authored
312 EMBED_API_CALLIN(interp_pmc, interp)
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
313 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
314 Parrot_Int i;
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
315
316 for (i = 0; i < argc; ++i) {
317 /* Run through argv, adding everything to the array */
318 STRING * const arg = Parrot_str_new_init(interp, argv[i], strlen(argv[i]),
319 Parrot_utf8_encoding_ptr, PObj_external_FLAG);
320 VTABLE_push_string(interp, userargv, arg);
321 }
322 *args = userargv;
c1ab56e More fixes, almost there
Mariano Wahlmann authored
323 EMBED_API_CALLOUT(interp_pmc, interp)
d4e8708 @Whiteknight add a failure macro for when an API call fails. Implement a few more …
Whiteknight authored
324 }
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
325
326 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
327 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
328 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
329 {
6be2b4a @Whiteknight remove the ASSERT_ARGS stuff, and other things that are borking thebu…
Whiteknight authored
330 //ASSERT_ARGS(Parrot_api_set_warnings)
c1ab56e More fixes, almost there
Mariano Wahlmann authored
331 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
332 /* 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
333 PARROT_WARNINGS_on(interp, flags);
c1ab56e More fixes, almost there
Mariano Wahlmann authored
334 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
335 }
336
337 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
338 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
339 Parrot_api_set_output_file(Parrot_PMC interp_pmc,
340 ARGIN_NULLOK(const char * filename))
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
341 {
6be2b4a @Whiteknight remove the ASSERT_ARGS stuff, and other things that are borking thebu…
Whiteknight authored
342 //ASSERT_ARGS(Parrot_api_set_output_file)
c1ab56e More fixes, almost there
Mariano Wahlmann authored
343 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
344 if (!filename && !interp->output_file)
345 interp->output_file = "-";
346 else
347 interp->output_file = filename;
c1ab56e More fixes, almost there
Mariano Wahlmann authored
348 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
349 }
350
351 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
352 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
353 Parrot_api_add_library_search_path(Parrot_PMC interp_pmc,
354 ARGIN(const char *path))
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
355 {
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
356 //ASSERT_ARGS(Parrot_api_add_library_search_path)
c1ab56e More fixes, almost there
Mariano Wahlmann authored
357 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
358 Parrot_lib_add_path_from_cstring(interp, path, PARROT_LIB_PATH_LIBRARY);
c1ab56e More fixes, almost there
Mariano Wahlmann authored
359 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
360 }
361
362 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
363 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
364 Parrot_api_add_include_search_path(Parrot_PMC interp_pmc,
365 ARGIN(const char *path))
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
366 {
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
367 //ASSERT_ARGS(Parrot_api_add_include_search_path)
c1ab56e More fixes, almost there
Mariano Wahlmann authored
368 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
369 Parrot_lib_add_path_from_cstring(interp, path, PARROT_LIB_PATH_INCLUDE);
c1ab56e More fixes, almost there
Mariano Wahlmann authored
370 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
371 }
372
373 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
374 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
375 Parrot_api_add_dynext_search_path(Parrot_PMC interp_pmc,
376 ARGIN(const char *path))
9d25cd4 @Whiteknight change the imcc_run function to return a PackFile PMC so we can use i…
Whiteknight authored
377 {
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
378 //ASSERT_ARGS(Parrot_api_add_dynext_search_path)
c1ab56e More fixes, almost there
Mariano Wahlmann authored
379 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
380 Parrot_lib_add_path_from_cstring(interp, path, PARROT_LIB_PATH_DYNEXT);
c1ab56e More fixes, almost there
Mariano Wahlmann authored
381 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
382 }
3259cda First cut of Parrot_api_set_stdhandles API function
Mariano Wahlmann authored
383
384 /*
385
b9cdf9c @jkeenan After fixing C++ comments, I re-ran headerizer and modified these fil…
jkeenan authored
386 =item C<Parrot_Int Parrot_api_set_stdhandles(Parrot_PMC interp_pmc, Parrot_Int
387 stdin, Parrot_Int stdout, Parrot_Int stderr)>
3259cda First cut of Parrot_api_set_stdhandles API function
Mariano Wahlmann authored
388
389 Set the std file descriptors for the embedded interpreter. Any file descriptor
390 passed as argument and set to C<PIO_INVALID_HANDLE> is ignored.
391
392 =cut
393
394 */
395
396 PARROT_API
e98ef02 @Whiteknight lots of fixes. We still don't build completely, but we are much close…
Whiteknight authored
397 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
398 Parrot_api_set_stdhandles(Parrot_PMC interp_pmc, Parrot_Int stdin,
399 Parrot_Int stdout, Parrot_Int stderr)
3259cda First cut of Parrot_api_set_stdhandles API function
Mariano Wahlmann authored
400 {
6be2b4a @Whiteknight remove the ASSERT_ARGS stuff, and other things that are borking thebu…
Whiteknight authored
401 //ASSERT_ARGS(Parrot_api_set_stdhandles)
f41cf98 @Whiteknight many more fixes. We build main.c now but fail in some of the alternat…
Whiteknight authored
402 EMBED_API_CALLIN(interp_pmc, interp)
403 void *dummy;
404
405 if(PIO_INVALID_HANDLE != (PIOHANDLE)stdin) {
406 PMC * const pmc = Parrot_pmc_new(interp, enum_class_FileHandle);
407 Parrot_io_set_os_handle(interp, pmc, (PIOHANDLE)stdin);
408 dummy = (void *)Parrot_io_stdhandle(interp,PIO_STDIN_FILENO,pmc);
409 }
410
411 if(PIO_INVALID_HANDLE != (PIOHANDLE)stdout) {
412 PMC * const pmc = Parrot_pmc_new(interp, enum_class_FileHandle);
413 Parrot_io_set_os_handle(interp, pmc, (PIOHANDLE)stdout);
414 dummy = (void *)Parrot_io_stdhandle(interp,PIO_STDOUT_FILENO,pmc);
415 }
416
417 if(PIO_INVALID_HANDLE != (PIOHANDLE)stderr) {
418 PMC * const pmc = Parrot_pmc_new(interp, enum_class_FileHandle);
419 Parrot_io_set_os_handle(interp, pmc, (PIOHANDLE)stderr);
420 dummy = (void *)Parrot_io_stdhandle(interp,PIO_STDERR_FILENO,pmc);
421 }
422
423 EMBED_API_CALLOUT(interp_pmc, interp)
3259cda First cut of Parrot_api_set_stdhandles API function
Mariano Wahlmann authored
424 }
f41cf98 @Whiteknight many more fixes. We build main.c now but fail in some of the alternat…
Whiteknight authored
425
426 PARROT_API
427 Parrot_Int
1216a51 @Whiteknight quick initial pass for codestd
Whiteknight authored
428 Parrot_api_get_runtime_path(Parrot_PMC interp_pmc,
429 ARGOUT(Parrot_String *runtime))
f41cf98 @Whiteknight many more fixes. We build main.c now but fail in some of the alternat…
Whiteknight authored
430 {
e9934d7 Made it compile with gcc
Mariano Wahlmann authored
431 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
432 *runtime = Parrot_get_runtime_path(interp);
433 EMBED_API_CALLOUT(interp_pmc, interp);
434 }
435
c4ccd13 @Whiteknight first prototype of a new mechanism for setting the configuration hash…
Whiteknight authored
436 PARROT_API
437 Parrot_Int
438 Parrot_api_set_configuration_hash(Parrot_PMC interp_pmc, Parrot_PMC confighash)
439 {
e9934d7 Made it compile with gcc
Mariano Wahlmann authored
440 EMBED_API_CALLIN(interp_pmc, interp)
c4ccd13 @Whiteknight first prototype of a new mechanism for setting the configuration hash…
Whiteknight authored
441 Parrot_set_config_hash_pmc(interp, confighash);
5c2c3d4 @Whiteknight fix library paths. The build now progresses through all the parts tha…
Whiteknight authored
442 Parrot_lib_update_paths_from_config_hash(interp);
c4ccd13 @Whiteknight first prototype of a new mechanism for setting the configuration hash…
Whiteknight authored
443 EMBED_API_CALLOUT(interp_pmc, interp);
444 }
445
e1ced3e @Whiteknight add a note explaining this stupid function
Whiteknight authored
446 /*
447 This is an evil hack to provide a wrapper around IMCC to catch unhandled
448 exceptions without having to assume IMCC is linked in with libparrot. Delete
449 this as soon as we don't need it anymore.
450 */
451
5b6a239 @Whiteknight Add a new, temporary hack API for wrapping up IMCC so we can catch er…
Whiteknight authored
452 PARROT_API
453 Parrot_Int
e1ced3e @Whiteknight add a note explaining this stupid function
Whiteknight authored
454 Parrot_api_wrap_imcc_hack(Parrot_PMC interp_pmc, const char * sourcefile,
455 int argc, const char **argv, Parrot_PMC* bytecodepmc, int *result,
456 imcc_hack_func_t func)
5b6a239 @Whiteknight Add a new, temporary hack API for wrapping up IMCC so we can catch er…
Whiteknight authored
457 {
458 EMBED_API_CALLIN(interp_pmc, interp)
459 *result = func(interp_pmc, sourcefile, argc, argv, bytecodepmc);
460 EMBED_API_CALLOUT(interp_pmc, interp)
461 }
c4ccd13 @Whiteknight first prototype of a new mechanism for setting the configuration hash…
Whiteknight authored
462
7db7331 @jkeenan Correct C-comment syntax error.
jkeenan authored
463 /*
464
9703ef5 @jkeenan [codingstd] C-style coda needed. No cuddled elses.
jkeenan authored
465 =back
c4ccd13 @Whiteknight first prototype of a new mechanism for setting the configuration hash…
Whiteknight authored
466
3562b6b Unfished work implemented API functions
Mariano Wahlmann authored
467 /*
468
469 =item C<PARROT_API Parrot_Int Parrot_api_load_language(Parrot_PMC interp_pmc,
470 Parrot_String *lang)>
471
472 Load the compiler libraries for a given high-level language into the
473 interpreter.
474
475 =cut
476
477 */
478
479 PARROT_API
480 Parrot_Int
481 Parrot_api_load_language(ARGIN(Parrot_PMC interp_pmc),
482 ARGIN(Parrot_String *lang))
483 {
484 ASSERT_ARGS(Parrot_api_load_language)
485 EMBED_API_CALLIN(interp_pmc, interp)
486 STRING * const lang_pmc = Parrot_str_new(interp, lang, strlen(lang));
487 Parrot_load_language(interp, lang_pmc);
488 EMBED_API_CALLOUT(interp_pmc, interp);
489 }
490
491
492 /*
493
494 =item C<PARROT_API Parrot_Int Parrot_api_get_compiler(Parrot_PMC interp_pmc,
495 Parrot_String *lang, PMC **compiler) >
496
497 =cut
498
499 */
500
501 PARROT_API
502 Parrot_Int
503 Parrot_api_get_compiler(ARGIN(Parrot_PMC interp_pmc), ARGIN(Parrot_String *lang),
504 ARGOUT(PMC **compiler))
505 {
506 ASSERT_ARGS(Parrot_api_get_compiler)
507 EMBED_API_CALLIN(interp_pmc, interp)
508 PMC * const compreg_hash = VTABLE_get_pmc_keyed_int(interp,
509 interp->iglobals, IGLOBALS_COMPREG_HASH);
510 STRING * const lang_pmc = Parrot_str_new(interp, lang, strlen(lang));
511 *compiler = VTABLE_get_pmc_keyed_str(interp, compreg_hash, lang_pmc);
512 EMBED_API_CALLOUT(interp_pmc, interp);
513 }
0814f94 Merged changes with branch
Mariano Wahlmann authored
514
515 /*
516
9703ef5 @jkeenan [codingstd] C-style coda needed. No cuddled elses.
jkeenan authored
517 =cut
0814f94 Merged changes with branch
Mariano Wahlmann authored
518
7db7331 @jkeenan Correct C-comment syntax error.
jkeenan authored
519 */
9703ef5 @jkeenan [codingstd] C-style coda needed. No cuddled elses.
jkeenan authored
520
540a832 @jkeenan [codingstd] Mostly linelength fixes.
jkeenan authored
521 /*
522 * Local variables:
523 * c-file-style: "parrot"
524 * End:
525 * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
526 */
0814f94 Merged changes with branch
Mariano Wahlmann authored
527
Something went wrong with that request. Please try again.