2 # Copyright (C) 2001-2008, The Perl Foundation.
7 use lib qw( . lib ../lib ../../lib );
15 t/src/compiler.t - Compile and run a PIR program from C.
19 % prove t/src/compiler.t
23 Show steps to run a program from C. Functionality should be
24 gathered in some API calls..
29 skip( 'compreg disabled/imcc_compile_pir() not exported', 1 );
30 c_output_is( <<'CODE', <<'OUTPUT', "compreg/compile" );
33 #include "parrot/parrot.h"
34 #include "parrot/embed.h"
37 run(Parrot_Interp interp, int argc, char *argv[])
39 const char *c_src = ".sub main :main\n" " print \"ok\\n\"\n" ".end\n";
45 /* get PIR compiler - TODO API */
46 PMC *compreg = Parrot_PMC_get_pmc_keyed_int(interp,
48 IGLOBALS_COMPREG_HASH);
49 STRING *pir = const_string(interp, "PIR");
50 PMC *comp = Parrot_PMC_get_pmc_keyed_str(interp, compreg, pir);
52 if (PMC_IS_NULL(comp) || !Parrot_PMC_defined(interp, comp)) {
53 PIO_eprintf(interp, "Pir compiler not loaded");
58 prog = imcc_compile_pir(interp, c_src);
60 if (PMC_IS_NULL(prog) || !Parrot_PMC_defined(interp, prog)) {
61 PIO_eprintf(interp, "Pir compiler returned no prog");
65 /* keep eval PMC alive */
66 dod_register_pmc(interp, prog);
68 /* locate function to run */
69 smain = const_string(interp, "main");
70 entry = Parrot_find_global_cur(interp, smain);
72 /* location of the entry */
73 interp->current_cont = new_ret_continuation_pmc(interp, NULL);
74 dest = Parrot_PMC_invoke(interp, entry, NULL);
77 interp->resume_offset = dest -interp->code->base.data;
80 Parrot_runcode(interp, argc, argv);
85 main(int margc, char *margv[])
90 char *argv[] = { "test", NULL };
92 PackFile_Segment *seg;
94 /* Interpreter set-up */
95 interp = Parrot_new(NULL);
99 /* dummy pf and segment to get things started */
100 pf = PackFile_new_dummy(interp, "test_code");
102 /* Parrot_set_flag(interp, PARROT_TRACE_FLAG); */
103 run(interp, argc, argv);
104 Parrot_exit(interp, 0);
112 c_output_is( <<'CODE', <<'OUTPUT', "Parrot Compile API Single call" );
115 #include "parrot/parrot.h"
116 #include "parrot/embed.h"
117 #include "parrot/extend.h"
120 run(Parrot_Interp interp, int argc, char *argv[])
122 const char *c_src = ".sub main :main\n" " print \"ok\\n\"\n" ".end\n";
129 /* get PIR compiler - TODO API */
130 PMC *compreg = Parrot_PMC_get_pmc_keyed_int(interp,
132 IGLOBALS_COMPREG_HASH);
133 STRING *pir = const_string(interp, "PIR");
134 PMC *comp = Parrot_PMC_get_pmc_keyed_str(interp, compreg, pir);
136 if (PMC_IS_NULL(comp) || !Parrot_PMC_defined(interp, comp)) {
137 PIO_eprintf(interp, "Pir compiler not loaded");
142 prog = Parrot_compile_string(interp, pir, c_src, &error);
144 if (PMC_IS_NULL(prog) || !Parrot_PMC_defined(interp, prog)) {
145 PIO_eprintf(interp, "Pir compiler returned no prog");
149 /* keep eval PMC alive */
150 dod_register_pmc(interp, prog);
152 /* locate function to run */
153 smain = const_string(interp, "main");
154 entry = Parrot_find_global_cur(interp, smain);
156 /* location of the entry */
157 interp->current_cont = new_ret_continuation_pmc(interp, NULL);
158 dest = Parrot_PMC_invoke(interp, entry, NULL);
161 interp->resume_offset = dest -interp->code->base.data;
164 Parrot_runcode(interp, argc, (char **)argv);
169 main(int margc, char *margv[])
171 Parrot_Interp interp;
174 const char *argv[] = { "test", NULL };
176 PackFile_Segment *seg;
178 /* Interpreter set-up */
179 interp = Parrot_new(NULL);
183 /* dummy pf and segment to get things started */
184 pf = PackFile_new_dummy(interp, "test_code");
186 /* Parrot_set_flag(interp, PARROT_TRACE_FLAG); */
187 run(interp, argc, (char **)argv);
188 Parrot_exit(interp, 0);
194 c_output_is( <<'CODE', <<'OUTPUT', "Parrot Compile API Multiple Calls" );
197 #include "parrot/parrot.h"
198 #include "parrot/embed.h"
199 #include "parrot/extend.h"
202 compile_run(Parrot_Interp interp, const char *src, STRING *type, int argc,
209 PMC *prog = Parrot_compile_string(interp, type, src, &error);
211 if (PMC_IS_NULL(prog) || !Parrot_PMC_defined(interp, prog)) {
212 PIO_eprintf(interp, "Pir compiler returned no prog");
216 /* keep eval PMC alive */
217 dod_register_pmc(interp, prog);
219 /* locate function to run */
220 smain = const_string(interp, "main");
221 entry = Parrot_find_global_cur(interp, smain);
223 /* location of the entry */
224 interp->current_cont = new_ret_continuation_pmc(interp, NULL);
225 dest = Parrot_PMC_invoke(interp, entry, NULL);
228 interp->resume_offset = dest -interp->code->base.data;
231 Parrot_runcode(interp, argc, (char **)argv);
235 run(Parrot_Interp interp, int argc, char *argv[])
237 const char *c_src = ".sub main :main\n" " print \"ok\\n\"\n" ".end\n";
240 ".sub main :main\n" " print \"hola\\n\"\n" ".end\n";
244 /* get PIR compiler - TODO API */
245 PMC *compreg = Parrot_PMC_get_pmc_keyed_int(interp,
247 IGLOBALS_COMPREG_HASH);
248 STRING *pir = const_string(interp, "PIR");
249 PMC *comp = Parrot_PMC_get_pmc_keyed_str(interp, compreg, pir);
251 if (PMC_IS_NULL(comp) || !Parrot_PMC_defined(interp, comp)) {
252 PIO_eprintf(interp, "Pir compiler not loaded");
256 compile_run(interp, c_src, pir, argc, argv);
257 compile_run(interp, c2_src, pir, argc, argv);
261 main(int margc, char *margv[])
263 Parrot_Interp interp;
266 const char *argv[] = { "test", NULL };
268 PackFile_Segment *seg;
270 /* Interpreter set-up */
271 interp = Parrot_new(NULL);
275 /* dummy pf and segment to get things started */
276 pf = PackFile_new_dummy(interp, "test_code");
278 /* Parrot_set_flag(interp, PARROT_TRACE_FLAG); */
279 run(interp, argc, (char **) argv);
280 Parrot_exit(interp, 0);
287 c_output_is( <<'CODE', <<'OUTPUT', "Parrot Compile API Multiple 1st bad PIR" );
290 #include "parrot/parrot.h"
291 #include "parrot/embed.h"
292 #include "parrot/extend.h"
295 compile_run(Parrot_Interp interp, const char *src, STRING *type, int argc,
302 PMC *prog = Parrot_compile_string(interp, type, src, &error);
304 if (PMC_IS_NULL(prog) || !Parrot_PMC_defined(interp, prog)) {
305 PIO_eprintf(interp, "Pir compiler returned no prog\n");
309 /* keep eval PMC alive */
310 dod_register_pmc(interp, prog);
312 /* locate function to run */
313 smain = const_string(interp, "main");
314 entry = Parrot_find_global_cur(interp, smain);
316 /* location of the entry */
317 interp->current_cont = new_ret_continuation_pmc(interp, NULL);
318 dest = Parrot_PMC_invoke(interp, entry, NULL);
321 interp->resume_offset = dest -interp->code->base.data;
324 Parrot_runcode(interp, argc, (char **) argv);
328 run(Parrot_Interp interp, int argc, char *argv[])
330 const char *c_src = ".sub main :main\n" " print ok\\n\"\n" ".end\n";
333 ".sub main :main\n" " print \"hola\\n\"\n" ".end\n";
337 /* get PIR compiler - TODO API */
338 PMC *compreg = Parrot_PMC_get_pmc_keyed_int(interp,
340 IGLOBALS_COMPREG_HASH);
341 STRING *pir = const_string(interp, "PIR");
342 PMC *comp = Parrot_PMC_get_pmc_keyed_str(interp, compreg, pir);
344 if (PMC_IS_NULL(comp) || !Parrot_PMC_defined(interp, comp)) {
345 PIO_eprintf(interp, "Pir compiler not loaded");
349 compile_run(interp, c_src, pir, argc, argv);
350 compile_run(interp, c2_src, pir, argc, argv);
354 main(int margc, char *margv[])
356 Parrot_Interp interp;
359 char *argv[] = { "test", NULL };
361 PackFile_Segment *seg;
363 /* Interpreter set-up */
364 interp = Parrot_new(NULL);
368 /* dummy pf and segment to get things started */
369 pf = PackFile_new_dummy(interp, "test_code");
371 /* Parrot_set_flag(interp, PARROT_TRACE_FLAG); */
372 run(interp, argc, argv);
373 Parrot_exit(interp, 0);
377 Pir compiler returned no prog
380 c_output_is( <<'CODE', <<'OUTPUT', "Parrot Compile API Multiple 2nd bad PIR" );
383 #include "parrot/parrot.h"
384 #include "parrot/embed.h"
385 #include "parrot/extend.h"
388 compile_run(Parrot_Interp interp, const char *src, STRING *type, int argc,
395 PMC *prog = Parrot_compile_string(interp, type, src, &error);
397 if (PMC_IS_NULL(prog) || !Parrot_PMC_defined(interp, prog)) {
398 PIO_eprintf(interp, "Pir compiler returned no prog\n");
402 /* keep eval PMC alive */
403 dod_register_pmc(interp, prog);
405 /* locate function to run */
406 smain = const_string(interp, "main");
407 entry = Parrot_find_global_cur(interp, smain);
409 /* location of the entry */
410 interp->current_cont = new_ret_continuation_pmc(interp, NULL);
411 dest = Parrot_PMC_invoke(interp, entry, NULL);
414 interp->resume_offset = dest -interp->code->base.data;
417 Parrot_runcode(interp, argc, (char **)argv);
421 run(Parrot_Interp interp, int argc, char *argv[])
423 const char *c_src = ".sub main :main\n" " print ok\\n\"\n" ".end\n";
426 ".sub main :main\n" " print \"hola\\n\"\n" ".end\n";
429 /* get PIR compiler - TODO API */
430 PMC *compreg = Parrot_PMC_get_pmc_keyed_int(interp,
432 IGLOBALS_COMPREG_HASH);
433 STRING *pir = const_string(interp, "PIR");
434 PMC *comp = Parrot_PMC_get_pmc_keyed_str(interp, compreg, pir);
436 if (PMC_IS_NULL(comp) || !Parrot_PMC_defined(interp, comp)) {
437 PIO_eprintf(interp, "Pir compiler not loaded");
441 compile_run(interp, c2_src, pir, argc, argv);
442 compile_run(interp, c_src, pir, argc, argv);
446 main(int margc, char *margv[])
448 Parrot_Interp interp;
451 char *argv[] = { "test", NULL };
453 PackFile_Segment *seg;
455 /* Interpreter set-up */
456 interp = Parrot_new(NULL);
460 /* dummy pf and segment to get things started */
461 pf = PackFile_new_dummy(interp, "test_code");
463 /* Parrot_set_flag(interp, PARROT_TRACE_FLAG); */
464 run(interp, argc, argv);
465 Parrot_exit(interp, 0);
470 Pir compiler returned no prog
472 c_output_is( <<'CODE', <<'OUTPUT', "Parrot Compile API Multiple bad PIR" );
475 #include "parrot/parrot.h"
476 #include "parrot/embed.h"
477 #include "parrot/extend.h"
480 compile_run(Parrot_Interp interp, const char *src, STRING *type, int argc,
487 PMC *prog = Parrot_compile_string(interp, type, src, &error);
489 if (PMC_IS_NULL(prog) || !Parrot_PMC_defined(interp, prog)) {
490 PIO_eprintf(interp, "Pir compiler returned no prog\n");
494 /* keep eval PMC alive */
495 dod_register_pmc(interp, prog);
497 /* locate function to run */
498 smain = const_string(interp, "main");
499 entry = Parrot_find_global_cur(interp, smain);
501 /* location of the entry */
502 interp->current_cont = new_ret_continuation_pmc(interp, NULL);
503 dest = Parrot_PMC_invoke(interp, entry, NULL);
506 interp->resume_offset = dest -interp->code->base.data;
509 Parrot_runcode(interp, argc, (char **)argv);
513 run(Parrot_Interp interp, int argc, char *argv[])
515 const char *c_src = ".sub main :main\n" " print ok\\n\"\n" ".end\n";
517 const char *c2_src = ".sub main :main\n" " print hola\\n\"\n" ".end\n";
520 /* get PIR compiler - TODO API */
521 PMC *compreg = Parrot_PMC_get_pmc_keyed_int(interp,
523 IGLOBALS_COMPREG_HASH);
524 STRING *pir = const_string(interp, "PIR");
525 PMC *comp = Parrot_PMC_get_pmc_keyed_str(interp, compreg, pir);
527 if (PMC_IS_NULL(comp) || !Parrot_PMC_defined(interp, comp)) {
528 PIO_eprintf(interp, "Pir compiler not loaded");
532 compile_run(interp, c_src, pir, argc, argv);
533 compile_run(interp, c2_src, pir, argc, argv);
537 main(int margc, char *margv[])
539 Parrot_Interp interp;
542 char *argv[] = { "test", NULL };
544 PackFile_Segment *seg;
546 /* Interpreter set-up */
547 interp = Parrot_new(NULL);
551 /* dummy pf and segment to get things started */
552 pf = PackFile_new_dummy(interp, "test_code");
554 /* Parrot_set_flag(interp, PARROT_TRACE_FLAG); */
555 run(interp, argc, argv);
556 Parrot_exit(interp, 0);
560 Pir compiler returned no prog
561 Pir compiler returned no prog
566 # cperl-indent-level: 4
569 # vim: expandtab shiftwidth=4: