[cage] Fix pgegrep, which was merely an innocent bystander in the Great Namespace...
[parrot.git] / src / extend.c
blob3d469d2203b1c91d3b2dc2398ec22bfed5551775
1 /*
2 Copyright (C) 2001-2007, Parrot Foundation.
3 $Id$
5 =head1 NAME
7 src/extend.c - Parrot extension interface
9 =head1 DESCRIPTION
11 These are the functions that parrot extensions (i.e. parrot subroutines
12 written in C, or some other compiled language, rather than in parrot
13 bytecode) may access.
15 There is a deliberate distancing from the internals here. Don't go
16 peeking inside -- you've as much access as bytecode does, but no more,
17 so we can provide backwards compatibility for as long as we possibly
18 can.
20 =head2 Functions
22 =over 4
24 =cut
28 /* Some internal notes. Parrot will die a horrible and bizarre death
29 if the stack start pointer's not set and a GC run is
30 triggered. The pointer *will* be set by the interpreter if the
31 interpreter calls code which calls these functions, so most
32 extension code is safe, no problem.
34 The problem comes in if these routines are called from *outside*
35 an interpreter. This happens when an embedding application calls
36 them to do stuff with PMCs, STRINGS, interpreter contents, and
37 suchlike things. This is perfectly legal -- in fact it's what
38 we've documented should be done -- but the problem is that the
39 stack base pointer will be NULL. This is Very Bad.
41 To deal with this there are two macros that are defined to handle
42 the problem.
44 PARROT_CALLIN_START(interp) will figure out if the stack
45 anchor needs setting and, if so, will set it. It must *always*
46 come immediately after the last variable declared in the block
47 making the calls into the interpreter, as it declares a variable
48 and has some code.
50 PARROT_CALLIN_END(interp) will put the stack anchor back to
51 the way it was, and should always be the last statement before a
52 return. (If you have multiple returns have it in multiple times)
54 Not doing this is a good way to introduce bizarre heisenbugs, so
55 just do it. This is the only place they ought to have to be put
56 in, and most of the functions are already written, so it's not
57 like it's an onerous requirement.
61 #include "parrot/parrot.h"
62 #include "parrot/extend.h"
63 #include "pmc/pmc_sub.h"
64 #include "pmc/pmc_context.h"
66 /* HEADERIZER HFILE: include/parrot/extend.h */
70 =item C<int Parrot_vfprintf(PARROT_INTERP, Parrot_PMC pio, const char *s,
71 va_list args)>
73 Writes a C string format with a varargs list to a PIO.
75 =item C<int Parrot_fprintf(PARROT_INTERP, Parrot_PMC pio, const char *s, ...)>
77 Writes a C string format with varargs to a PIO.
79 =item C<int Parrot_printf(NULLOK_INTERP, const char *s, ...)>
81 Writes a C string format with varargs to C<stdout>.
83 =item C<int Parrot_eprintf(NULLOK_INTERP, const char *s, ...)>
85 Writes a C string format with varargs to C<stderr>.
87 =cut
91 PARROT_EXPORT
92 int
93 Parrot_vfprintf(PARROT_INTERP, ARGIN(Parrot_PMC pio),
94 ARGIN(const char *s), va_list args)
96 ASSERT_ARGS(Parrot_vfprintf)
97 STRING * str;
98 INTVAL retval;
100 PARROT_CALLIN_START(interp);
101 str = Parrot_vsprintf_c(interp, s, args);
102 retval = Parrot_io_putps(interp, pio, str);
103 PARROT_CALLIN_END(interp);
105 return retval;
108 PARROT_EXPORT
110 Parrot_fprintf(PARROT_INTERP, ARGIN(Parrot_PMC pio),
111 ARGIN(const char *s), ...)
113 ASSERT_ARGS(Parrot_fprintf)
114 va_list args;
115 INTVAL retval;
117 va_start(args, s);
118 retval = Parrot_vfprintf(interp, pio, s, args);
119 va_end(args);
121 return retval;
124 PARROT_EXPORT
126 Parrot_printf(NULLOK_INTERP, ARGIN(const char *s), ...)
128 ASSERT_ARGS(Parrot_printf)
129 va_list args;
130 INTVAL retval;
131 va_start(args, s);
133 if (interp) {
134 retval = Parrot_vfprintf(interp, Parrot_io_STDOUT(interp), s, args);
136 else {
137 /* Be nice about this...
138 ** XXX BD Should this use the default Parrot_io_STDOUT or something?
140 retval = vfprintf(stdout, s, args);
142 va_end(args);
144 return retval;
147 PARROT_EXPORT
149 Parrot_eprintf(NULLOK_INTERP, ARGIN(const char *s), ...)
151 ASSERT_ARGS(Parrot_eprintf)
152 va_list args;
153 INTVAL retval;
155 va_start(args, s);
157 if (interp) {
158 retval = Parrot_vfprintf(interp, Parrot_io_STDERR(interp), s, args);
160 else {
161 /* Be nice about this...
162 ** XXX BD Should this use the default Parrot_io_STDOUT or something?
164 retval=vfprintf(stderr, s, args);
167 va_end(args);
169 return retval;
174 =item C<Parrot_PMC Parrot_get_root_namespace(PARROT_INTERP)>
176 Return the root namespace
178 =cut
182 PARROT_EXPORT
183 Parrot_PMC
184 Parrot_get_root_namespace(PARROT_INTERP)
186 ASSERT_ARGS(Parrot_get_root_namespace)
187 return interp->root_namespace;
192 =item C<Parrot_String Parrot_PMC_get_string_intkey(PARROT_INTERP, Parrot_PMC
193 pmc, Parrot_Int key)>
195 Return the integer keyed string value of the passed-in PMC
197 =cut
201 PARROT_EXPORT
202 Parrot_String
203 Parrot_PMC_get_string_intkey(PARROT_INTERP,
204 Parrot_PMC pmc, Parrot_Int key)
206 ASSERT_ARGS(Parrot_PMC_get_string_intkey)
207 Parrot_String retval;
208 PARROT_CALLIN_START(interp);
209 retval = VTABLE_get_string_keyed_int(interp, pmc, key);
210 PARROT_CALLIN_END(interp);
211 return retval;
217 =item C<void * Parrot_PMC_get_pointer_intkey(PARROT_INTERP, Parrot_PMC pmc,
218 Parrot_Int key)>
220 Return a pointer to the PMC indicated by an integer key.
222 =cut
226 PARROT_EXPORT
227 PARROT_WARN_UNUSED_RESULT
228 PARROT_CAN_RETURN_NULL
229 void *
230 Parrot_PMC_get_pointer_intkey(PARROT_INTERP,
231 Parrot_PMC pmc, Parrot_Int key)
233 ASSERT_ARGS(Parrot_PMC_get_pointer_intkey)
234 void *retval;
235 PARROT_CALLIN_START(interp);
236 retval = VTABLE_get_pointer_keyed_int(interp, pmc, key);
237 PARROT_CALLIN_END(interp);
238 return retval;
243 =item C<Parrot_PMC Parrot_PMC_get_pmc_intkey(PARROT_INTERP, Parrot_PMC pmc,
244 Parrot_Int key)>
246 Return the integer keyed PMC value of the passed-in PMC
248 =cut
252 PARROT_EXPORT
253 Parrot_PMC
254 Parrot_PMC_get_pmc_intkey(PARROT_INTERP,
255 Parrot_PMC pmc, Parrot_Int key)
257 ASSERT_ARGS(Parrot_PMC_get_pmc_intkey)
258 Parrot_PMC retval;
259 PARROT_CALLIN_START(interp);
260 retval = VTABLE_get_pmc_keyed_int(interp, pmc, key);
261 PARROT_CALLIN_END(interp);
262 return retval;
267 =item C<Parrot_PMC Parrot_PMC_get_pmc_strkey(PARROT_INTERP, Parrot_PMC pmc,
268 Parrot_String key)>
270 Return the string keyed PMC value of the passed-in PMC
272 =cut
276 PARROT_EXPORT
277 Parrot_PMC
278 Parrot_PMC_get_pmc_strkey(PARROT_INTERP,
279 Parrot_PMC pmc, Parrot_String key)
281 ASSERT_ARGS(Parrot_PMC_get_pmc_strkey)
282 Parrot_PMC retval;
283 PARROT_CALLIN_START(interp);
284 retval = VTABLE_get_pmc_keyed_str(interp, pmc, key);
285 PARROT_CALLIN_END(interp);
286 return retval;
291 =item C<Parrot_Int Parrot_PMC_get_intval(PARROT_INTERP, Parrot_PMC pmc)>
293 Return the signed integer value of the value in the PMC.
295 =cut
299 PARROT_EXPORT
300 Parrot_Int
301 Parrot_PMC_get_intval(PARROT_INTERP, Parrot_PMC pmc)
303 ASSERT_ARGS(Parrot_PMC_get_intval)
304 Parrot_Int retval;
305 PARROT_CALLIN_START(interp);
306 retval = VTABLE_get_integer(interp, pmc);
307 PARROT_CALLIN_END(interp);
308 return retval;
313 =item C<Parrot_Int Parrot_PMC_get_intval_intkey(PARROT_INTERP, Parrot_PMC pmc,
314 Parrot_Int key)>
316 Return the keyed, signed integer value of the value in the PMC.
318 =cut
322 PARROT_EXPORT
323 Parrot_Int
324 Parrot_PMC_get_intval_intkey(PARROT_INTERP,
325 Parrot_PMC pmc, Parrot_Int key)
327 ASSERT_ARGS(Parrot_PMC_get_intval_intkey)
328 Parrot_Int retval;
329 PARROT_CALLIN_START(interp);
330 retval = VTABLE_get_integer_keyed_int(interp, pmc, key);
331 PARROT_CALLIN_END(interp);
332 return retval;
337 =item C<Parrot_Int Parrot_PMC_get_intval_pmckey(PARROT_INTERP, Parrot_PMC pmc,
338 Parrot_PMC key)>
340 Return the keyed, signed integer value of the value in the PMC.
342 =cut
346 PARROT_EXPORT
347 Parrot_Int
348 Parrot_PMC_get_intval_pmckey(PARROT_INTERP,
349 Parrot_PMC pmc, Parrot_PMC key)
351 ASSERT_ARGS(Parrot_PMC_get_intval_pmckey)
352 Parrot_Int retval;
353 PARROT_CALLIN_START(interp);
354 retval = VTABLE_get_integer_keyed(interp, pmc, key);
355 PARROT_CALLIN_END(interp);
356 return retval;
361 =item C<Parrot_Float Parrot_PMC_get_numval(PARROT_INTERP, Parrot_PMC pmc)>
363 Return the floating-point value of the PMC.
365 =cut
369 PARROT_EXPORT
370 Parrot_Float
371 Parrot_PMC_get_numval(PARROT_INTERP, Parrot_PMC pmc)
373 ASSERT_ARGS(Parrot_PMC_get_numval)
374 Parrot_Float retval;
375 PARROT_CALLIN_START(interp);
376 retval = VTABLE_get_number(interp, pmc);
377 PARROT_CALLIN_END(interp);
378 return retval;
383 =item C<Parrot_Float Parrot_PMC_get_numval_intkey(PARROT_INTERP, Parrot_PMC pmc,
384 Parrot_Int key)>
386 Return the keyed, signed integer value of the value in the PMC.
388 =cut
392 PARROT_EXPORT
393 Parrot_Float
394 Parrot_PMC_get_numval_intkey(PARROT_INTERP,
395 Parrot_PMC pmc, Parrot_Int key)
397 ASSERT_ARGS(Parrot_PMC_get_numval_intkey)
398 Parrot_Float retval;
399 PARROT_CALLIN_START(interp);
400 retval = VTABLE_get_number_keyed_int(interp, pmc, key);
401 PARROT_CALLIN_END(interp);
402 return retval;
407 =item C<char * Parrot_PMC_get_cstring_intkey(PARROT_INTERP, Parrot_PMC pmc,
408 Parrot_Int key)>
410 Return a null-terminated string that represents the string value of the PMC.
412 Note that you must free this string with C<Parrot_str_free_cstring()>!
414 =cut
418 PARROT_EXPORT
419 PARROT_MALLOC
420 PARROT_CAN_RETURN_NULL
421 char *
422 Parrot_PMC_get_cstring_intkey(PARROT_INTERP,
423 Parrot_PMC pmc, Parrot_Int key)
425 ASSERT_ARGS(Parrot_PMC_get_cstring_intkey)
426 STRING *intermediate;
427 char *retval;
429 PARROT_CALLIN_START(interp);
430 intermediate = VTABLE_get_string_keyed_int(interp, pmc, key);
431 retval = Parrot_str_to_cstring(interp, intermediate);
432 PARROT_CALLIN_END(interp);
434 return retval;
439 =item C<char * Parrot_PMC_get_cstring(PARROT_INTERP, Parrot_PMC pmc)>
441 Return a null-terminated string that represents the string value of the PMC.
443 Note that you must free this string with C<Parrot_str_free_cstring()>!
445 =cut
449 PARROT_EXPORT
450 PARROT_MALLOC
451 PARROT_CAN_RETURN_NULL
452 char *
453 Parrot_PMC_get_cstring(PARROT_INTERP, Parrot_PMC pmc)
455 ASSERT_ARGS(Parrot_PMC_get_cstring)
456 STRING *intermediate;
457 char *retval;
459 PARROT_CALLIN_START(interp);
460 intermediate = VTABLE_get_string(interp, pmc);
461 retval = Parrot_str_to_cstring(interp, intermediate);
462 PARROT_CALLIN_END(interp);
464 return retval;
469 =item C<char * Parrot_PMC_get_cstringn(PARROT_INTERP, Parrot_PMC pmc, Parrot_Int
470 *length)>
472 Return a null-terminated string for the PMC, along with the length.
474 Yes, right now this is a bit of a cheat. It needs fixing, but without
475 disturbing the interface.
477 Note that you must free the string with C<Parrot_str_free_cstring()>.
479 =cut
483 PARROT_EXPORT
484 PARROT_MALLOC
485 PARROT_CAN_RETURN_NULL
486 char *
487 Parrot_PMC_get_cstringn(PARROT_INTERP, ARGIN(Parrot_PMC pmc),
488 ARGOUT(Parrot_Int *length))
490 ASSERT_ARGS(Parrot_PMC_get_cstringn)
491 char *retval;
493 PARROT_CALLIN_START(interp);
494 retval = Parrot_str_to_cstring(interp, VTABLE_get_string(interp, pmc));
495 *length = strlen(retval);
496 PARROT_CALLIN_END(interp);
498 return retval;
503 =item C<char * Parrot_PMC_get_cstringn_intkey(PARROT_INTERP, Parrot_PMC pmc,
504 Parrot_Int *length, Parrot_Int key)>
506 Return a null-terminated string for the PMC, along with the length.
508 Yes, right now this is a bit of a cheat. It needs fixing, but without
509 disturbing the interface.
511 Note that you must free this string with C<Parrot_str_free_cstring()>.
513 =cut
517 PARROT_EXPORT
518 PARROT_MALLOC
519 PARROT_CAN_RETURN_NULL
520 char *
521 Parrot_PMC_get_cstringn_intkey(PARROT_INTERP, ARGIN(Parrot_PMC pmc),
522 ARGOUT(Parrot_Int *length), Parrot_Int key)
524 ASSERT_ARGS(Parrot_PMC_get_cstringn_intkey)
525 char *retval;
527 PARROT_CALLIN_START(interp);
528 retval = Parrot_str_to_cstring(interp,
529 VTABLE_get_string_keyed_int(interp, pmc, key));
530 *length = strlen(retval);
531 PARROT_CALLIN_END(interp);
533 return retval;
538 =item C<void Parrot_PMC_set_string(PARROT_INTERP, Parrot_PMC pmc, Parrot_String
539 value)>
541 Assign the passed-in Parrot string to the passed-in PMC.
543 =cut
547 PARROT_EXPORT
548 void
549 Parrot_PMC_set_string(PARROT_INTERP,
550 Parrot_PMC pmc, Parrot_String value)
552 ASSERT_ARGS(Parrot_PMC_set_string)
553 PARROT_CALLIN_START(interp);
554 VTABLE_set_string_native(interp, pmc, value);
555 PARROT_CALLIN_END(interp);
560 =item C<void Parrot_PMC_set_string_intkey(PARROT_INTERP, Parrot_PMC pmc,
561 Parrot_Int key, Parrot_String value)>
563 Assign the passed-in Parrot string to the passed-in PMC.
565 =cut
569 PARROT_EXPORT
570 void
571 Parrot_PMC_set_string_intkey(PARROT_INTERP,
572 Parrot_PMC pmc, Parrot_Int key, Parrot_String value)
574 ASSERT_ARGS(Parrot_PMC_set_string_intkey)
575 PARROT_CALLIN_START(interp);
576 VTABLE_set_string_keyed_int(interp, pmc, key, value);
577 PARROT_CALLIN_END(interp);
582 =item C<void Parrot_PMC_set_pmc_intkey(PARROT_INTERP, Parrot_PMC pmc, Parrot_Int
583 key, Parrot_PMC value)>
585 Assign the passed-in pmc to the passed-in slot of the passed-in PMC.
587 =cut
591 PARROT_EXPORT
592 void
593 Parrot_PMC_set_pmc_intkey(PARROT_INTERP,
594 Parrot_PMC pmc, Parrot_Int key, Parrot_PMC value)
596 ASSERT_ARGS(Parrot_PMC_set_pmc_intkey)
597 PARROT_CALLIN_START(interp);
598 VTABLE_set_pmc_keyed_int(interp, pmc, key, value);
599 PARROT_CALLIN_END(interp);
604 =item C<void Parrot_PMC_set_pmc_strkey(PARROT_INTERP, Parrot_PMC pmc,
605 Parrot_String key, Parrot_PMC value)>
607 Assign the passed-in pmc to the passed-in slot of the passed-in PMC.
609 =cut
613 PARROT_EXPORT
614 void
615 Parrot_PMC_set_pmc_strkey(PARROT_INTERP,
616 Parrot_PMC pmc, Parrot_String key, Parrot_PMC value)
618 ASSERT_ARGS(Parrot_PMC_set_pmc_strkey)
619 PARROT_CALLIN_START(interp);
620 VTABLE_set_pmc_keyed_str(interp, pmc, key, value);
621 PARROT_CALLIN_END(interp);
626 =item C<void Parrot_PMC_set_pmc_pmckey(PARROT_INTERP, Parrot_PMC pmc, Parrot_PMC
627 key, Parrot_PMC value)>
629 Assign the passed-in pmc to the passed-in slot of the passed-in PMC.
631 =cut
635 PARROT_EXPORT
636 void
637 Parrot_PMC_set_pmc_pmckey(PARROT_INTERP,
638 Parrot_PMC pmc, Parrot_PMC key, Parrot_PMC value)
640 ASSERT_ARGS(Parrot_PMC_set_pmc_pmckey)
641 PARROT_CALLIN_START(interp);
642 VTABLE_set_pmc_keyed(interp, pmc, key, value);
643 PARROT_CALLIN_END(interp);
648 =item C<void Parrot_PMC_set_pointer_intkey(PARROT_INTERP, Parrot_PMC pmc,
649 Parrot_Int key, void *value)>
651 Assign the passed-in pointer to the passed-in PMC.
653 =cut
657 PARROT_EXPORT
658 void
659 Parrot_PMC_set_pointer_intkey(PARROT_INTERP,
660 ARGIN(Parrot_PMC pmc), Parrot_Int key, ARGIN_NULLOK(void *value))
662 ASSERT_ARGS(Parrot_PMC_set_pointer_intkey)
663 PARROT_CALLIN_START(interp);
664 VTABLE_set_pointer_keyed_int(interp, pmc, key, value);
665 PARROT_CALLIN_END(interp);
670 =item C<void Parrot_PMC_set_intval(PARROT_INTERP, Parrot_PMC pmc, Parrot_Int
671 value)>
673 Assign the passed-in Parrot integer to the passed-in PMC.
675 =cut
679 PARROT_EXPORT
680 void
681 Parrot_PMC_set_intval(PARROT_INTERP, Parrot_PMC pmc, Parrot_Int value)
683 ASSERT_ARGS(Parrot_PMC_set_intval)
684 PARROT_CALLIN_START(interp);
685 VTABLE_set_integer_native(interp, pmc, value);
686 PARROT_CALLIN_END(interp);
691 =item C<void Parrot_PMC_set_intval_intkey(PARROT_INTERP, Parrot_PMC pmc,
692 Parrot_Int key, Parrot_Int value)>
694 Assign the passed-in Parrot integer to the passed-in PMC.
696 =cut
700 PARROT_EXPORT
701 void
702 Parrot_PMC_set_intval_intkey(PARROT_INTERP,
703 Parrot_PMC pmc, Parrot_Int key, Parrot_Int value)
705 ASSERT_ARGS(Parrot_PMC_set_intval_intkey)
706 PARROT_CALLIN_START(interp);
707 VTABLE_set_integer_keyed_int(interp, pmc, key, value);
708 PARROT_CALLIN_END(interp);
713 =item C<void Parrot_PMC_set_numval(PARROT_INTERP, Parrot_PMC pmc, Parrot_Float
714 value)>
716 Assign the passed-in Parrot number to the passed-in PMC.
718 =cut
722 PARROT_EXPORT
723 void
724 Parrot_PMC_set_numval(PARROT_INTERP, Parrot_PMC pmc, Parrot_Float value)
726 ASSERT_ARGS(Parrot_PMC_set_numval)
727 PARROT_CALLIN_START(interp);
728 VTABLE_set_number_native(interp, pmc, value);
729 PARROT_CALLIN_END(interp);
734 =item C<void Parrot_PMC_set_numval_intkey(PARROT_INTERP, Parrot_PMC pmc,
735 Parrot_Int key, Parrot_Float value)>
737 Assign the passed-in Parrot number to the passed-in PMC.
739 =cut
743 PARROT_EXPORT
744 void
745 Parrot_PMC_set_numval_intkey(PARROT_INTERP,
746 Parrot_PMC pmc, Parrot_Int key, Parrot_Float value)
748 ASSERT_ARGS(Parrot_PMC_set_numval_intkey)
749 PARROT_CALLIN_START(interp);
750 VTABLE_set_number_keyed_int(interp, pmc, key, value);
751 PARROT_CALLIN_END(interp);
756 =item C<void Parrot_PMC_set_cstring(PARROT_INTERP, Parrot_PMC pmc, const char
757 *value)>
759 Assign the passed-in null-terminated C string to the passed-in PMC.
761 =cut
765 PARROT_EXPORT
766 void
767 Parrot_PMC_set_cstring(PARROT_INTERP, Parrot_PMC pmc, ARGIN_NULLOK(const char *value))
769 ASSERT_ARGS(Parrot_PMC_set_cstring)
770 PARROT_CALLIN_START(interp);
771 VTABLE_set_string_native(interp, pmc,
772 Parrot_str_new(interp, value, 0));
773 PARROT_CALLIN_END(interp);
778 =item C<void Parrot_PMC_set_cstring_intkey(PARROT_INTERP, Parrot_PMC pmc,
779 Parrot_Int key, const char *value)>
781 Assign the passed-in null-terminated C string to the passed-in PMC.
783 =cut
787 PARROT_EXPORT
788 void
789 Parrot_PMC_set_cstring_intkey(PARROT_INTERP,
790 Parrot_PMC pmc, Parrot_Int key, ARGIN_NULLOK(const char *value))
792 ASSERT_ARGS(Parrot_PMC_set_cstring_intkey)
793 PARROT_CALLIN_START(interp);
794 VTABLE_set_string_keyed_int(interp, pmc, key,
795 Parrot_str_new(interp, value, 0));
796 PARROT_CALLIN_END(interp);
801 =item C<void Parrot_PMC_set_cstringn(PARROT_INTERP, Parrot_PMC pmc, const char
802 *value, Parrot_UInt length)>
804 Assign the passed-in length-noted string to the passed-in PMC.
806 =cut
810 PARROT_EXPORT
811 void
812 Parrot_PMC_set_cstringn(PARROT_INTERP,
813 Parrot_PMC pmc, ARGIN_NULLOK(const char *value), Parrot_UInt length)
815 ASSERT_ARGS(Parrot_PMC_set_cstringn)
816 PARROT_CALLIN_START(interp);
817 VTABLE_set_string_native(interp, pmc,
818 Parrot_str_new(interp, value, length));
819 PARROT_CALLIN_END(interp);
824 =item C<void Parrot_PMC_push_intval(PARROT_INTERP, Parrot_PMC pmc, Parrot_Int
825 value)>
827 Push the passed-in Parrot integer onto the passed in PMC
829 =cut
833 PARROT_EXPORT
834 void
835 Parrot_PMC_push_intval(PARROT_INTERP,
836 Parrot_PMC pmc, Parrot_Int value)
838 ASSERT_ARGS(Parrot_PMC_push_intval)
839 PARROT_CALLIN_START(interp);
840 VTABLE_push_integer(interp, pmc, value);
841 PARROT_CALLIN_END(interp);
846 =item C<void Parrot_PMC_push_numval(PARROT_INTERP, Parrot_PMC pmc, Parrot_Float
847 value)>
849 Push the passed-in Parrot number onto the passed in PMC
851 =cut
855 PARROT_EXPORT
856 void
857 Parrot_PMC_push_numval(PARROT_INTERP, Parrot_PMC pmc, Parrot_Float value)
859 ASSERT_ARGS(Parrot_PMC_push_numval)
860 PARROT_CALLIN_START(interp);
861 VTABLE_push_float(interp, pmc, value);
862 PARROT_CALLIN_END(interp);
867 =item C<void Parrot_PMC_push_pmcval(PARROT_INTERP, Parrot_PMC pmc, Parrot_PMC
868 value)>
870 Push the passed-in Parrot PMC onto the passed in PMC
872 =cut
876 PARROT_EXPORT
877 void
878 Parrot_PMC_push_pmcval(PARROT_INTERP, Parrot_PMC pmc, Parrot_PMC value)
880 ASSERT_ARGS(Parrot_PMC_push_pmcval)
881 PARROT_CALLIN_START(interp);
882 VTABLE_push_pmc(interp, pmc, value);
883 PARROT_CALLIN_END(interp);
888 =item C<void Parrot_PMC_delete_pmckey(PARROT_INTERP, Parrot_PMC pmc, Parrot_PMC
889 key)>
891 Deletes the value associated with the passed-in PMC from the PMC.
893 =cut
897 PARROT_EXPORT
898 void
899 Parrot_PMC_delete_pmckey(PARROT_INTERP, Parrot_PMC pmc, Parrot_PMC key)
901 ASSERT_ARGS(Parrot_PMC_delete_pmckey)
902 PARROT_CALLIN_START(interp);
903 VTABLE_delete_keyed(interp, pmc, key);
904 PARROT_CALLIN_END(interp);
909 =item C<void Parrot_PMC_set_cstringn_intkey(PARROT_INTERP, Parrot_PMC pmc,
910 Parrot_Int key, const char *value, Parrot_UInt length)>
912 Assign the passed-in length-noted string to the passed-in PMC.
914 =cut
918 PARROT_EXPORT
919 void
920 Parrot_PMC_set_cstringn_intkey(PARROT_INTERP,
921 Parrot_PMC pmc, Parrot_Int key, ARGIN_NULLOK(const char *value),
922 Parrot_UInt length)
924 ASSERT_ARGS(Parrot_PMC_set_cstringn_intkey)
925 PARROT_CALLIN_START(interp);
926 VTABLE_set_string_keyed_int(interp, pmc, key,
927 Parrot_str_new(interp, value, length));
928 PARROT_CALLIN_END(interp);
933 =item C<Parrot_PMC Parrot_PMC_new(PARROT_INTERP, Parrot_Int type)>
935 Create and return a new PMC.
937 =cut
941 PARROT_EXPORT
942 Parrot_PMC
943 Parrot_PMC_new(PARROT_INTERP, Parrot_Int type)
945 ASSERT_ARGS(Parrot_PMC_new)
946 Parrot_PMC newpmc;
947 PARROT_CALLIN_START(interp);
948 newpmc = pmc_new_noinit(interp, type);
949 VTABLE_init(interp, newpmc);
950 PARROT_CALLIN_END(interp);
951 return newpmc;
956 =item C<Parrot_Int Parrot_PMC_typenum(PARROT_INTERP, const char *_class)>
958 Returns the internal identifier that represents the named class.
960 =cut
964 PARROT_EXPORT
965 Parrot_Int
966 Parrot_PMC_typenum(PARROT_INTERP, ARGIN_NULLOK(const char *_class))
968 ASSERT_ARGS(Parrot_PMC_typenum)
969 Parrot_Int retval;
970 PARROT_CALLIN_START(interp);
971 retval = pmc_type(interp, Parrot_str_new(interp, _class, 0));
972 PARROT_CALLIN_END(interp);
973 return retval;
978 =item C<Parrot_PMC Parrot_PMC_null(void)>
980 Returns the special C<NULL> PMC.
982 =cut
986 PARROT_EXPORT
987 Parrot_PMC
988 Parrot_PMC_null(void)
990 ASSERT_ARGS(Parrot_PMC_null)
991 return PMCNULL;
996 =item C<void Parrot_free_cstring(char *string)>
998 Deallocate a C string that the interpreter has handed to you.
1000 =cut
1004 PARROT_EXPORT
1005 void
1006 Parrot_free_cstring(ARGIN_NULLOK(char *string))
1008 ASSERT_ARGS(Parrot_free_cstring)
1009 Parrot_str_free_cstring(string);
1014 =item C<void Parrot_ext_call(PARROT_INTERP, Parrot_PMC sub_pmc, const char
1015 *signature, ...)>
1017 Call a Parrot subroutine or method with the given function signature. The
1018 function signature holds one type character for each argument or return, these
1019 are:
1021 I ... Parrot_Int
1022 N ... Parrot_Float
1023 S ... Parrot_String
1024 P ... Parrot_PMC
1026 Returns come after the arguments, separated by an arrow, so "PN->S" takes a PMC
1027 and a float as arguments and returns a string.
1029 Pass the variables for the arguments and returns in the same order as the
1030 signature, with returns as reference to the variable (so it can be modified).
1032 Parrot_ext_call(interp, sub, "P->S", pmc_arg, &string_result);
1034 To call a method, pass the object for the method as the first argument, and
1035 mark it in the signature as "Pi" ("i" stands for "invocant").
1037 Parrot_ext_call(interp, sub, "PiP->S", object_arg, pmc_arg, &string_result);
1039 =cut
1043 PARROT_EXPORT
1044 void
1045 Parrot_ext_call(PARROT_INTERP, ARGIN(Parrot_PMC sub_pmc),
1046 ARGIN(const char *signature), ...)
1048 ASSERT_ARGS(Parrot_ext_call)
1049 va_list args;
1050 PMC *sig_object;
1052 va_start(args, signature);
1053 sig_object = Parrot_pcc_build_sig_object_from_varargs(interp, PMCNULL, signature, args);
1054 va_end(args);
1056 Parrot_pcc_invoke_from_sig_object(interp, sub_pmc, sig_object);
1061 =item C<void * Parrot_call_sub(PARROT_INTERP, Parrot_PMC sub_pmc, const char
1062 *signature, ...)>
1064 Call a parrot subroutine with the given function signature. The first char in
1065 C<signature> denotes the return value. Next chars are arguments.
1067 The return value of this function can be void or a pointer type.
1069 Signature chars are:
1071 v ... void return
1072 I ... Parrot_Int
1073 N ... Parrot_Float
1074 S ... Parrot_String
1075 P ... Parrot_PMC
1077 =cut
1081 PARROT_EXPORT
1082 PARROT_WARN_UNUSED_RESULT
1083 PARROT_CAN_RETURN_NULL
1084 void *
1085 Parrot_call_sub(PARROT_INTERP, Parrot_PMC sub_pmc,
1086 ARGIN(const char *signature), ...)
1088 ASSERT_ARGS(Parrot_call_sub)
1089 va_list args;
1090 PMC *sig_object;
1091 Parrot_sub *sub;
1092 void *result = NULL;
1093 const char *arg_sig = signature;
1094 char return_sig = signature[0];
1096 arg_sig++;
1097 va_start(args, signature);
1098 sig_object = Parrot_pcc_build_sig_object_from_varargs(interp, PMCNULL,
1099 arg_sig, args);
1100 va_end(args);
1102 /* Add the return argument onto the call signature object (a bit
1103 * hackish, added for backward compatibility in deprecated API function,
1104 * see TT #1145). */
1105 switch (return_sig) {
1106 case 'v':
1108 Parrot_String full_sig = VTABLE_get_string(interp, sig_object);
1109 Parrot_str_concat(interp, full_sig,
1110 Parrot_str_new_constant(interp, "->"), 0);
1111 break;
1113 case 'V':
1114 case 'P':
1116 Parrot_pcc_append_result(interp, sig_object, Parrot_str_new_constant(interp, "P"),
1117 &result);
1118 break;
1120 default:
1121 Parrot_ex_throw_from_c_args(interp, NULL,
1122 EXCEPTION_INVALID_OPERATION,
1123 "Dispatch: invalid return type %c!", return_sig);
1126 PMC_get_sub(interp, sub_pmc, sub);
1127 Parrot_pcc_set_constants(interp, CURRENT_CONTEXT(interp),
1128 sub->seg->const_table->constants);
1129 Parrot_pcc_invoke_from_sig_object(interp, sub_pmc, sig_object);
1131 return result;
1137 =item C<Parrot_Int Parrot_call_sub_ret_int(PARROT_INTERP, Parrot_PMC sub_pmc,
1138 const char *signature, ...)>
1140 Like C<Parrot_call_sub>, with Parrot_Int return result.
1142 =cut
1146 PARROT_EXPORT
1147 Parrot_Int
1148 Parrot_call_sub_ret_int(PARROT_INTERP, Parrot_PMC sub_pmc,
1149 ARGIN(const char *signature), ...)
1151 ASSERT_ARGS(Parrot_call_sub_ret_int)
1152 va_list args;
1153 PMC *sig_object;
1154 Parrot_Int result;
1155 char return_sig = signature[0];
1156 const char *arg_sig = signature;
1157 Parrot_sub *sub;
1159 arg_sig++;
1160 va_start(args, signature);
1161 sig_object = Parrot_pcc_build_sig_object_from_varargs(interp, PMCNULL, arg_sig, args);
1162 va_end(args);
1164 /* Add the return argument onto the call signature object (a bit
1165 * hackish, added for backward compatibility in deprecated API function,
1166 * see TT #1145). */
1167 Parrot_pcc_append_result(interp, sig_object, Parrot_str_new_constant(interp, "I"), &result);
1168 Parrot_pcc_invoke_from_sig_object(interp, sub_pmc, sig_object);
1170 return result;
1175 =item C<Parrot_Float Parrot_call_sub_ret_float(PARROT_INTERP, Parrot_PMC
1176 sub_pmc, const char *signature, ...)>
1178 Like C<Parrot_call_sub>, with Parrot_Float return result.
1180 =cut
1184 PARROT_EXPORT
1185 Parrot_Float
1186 Parrot_call_sub_ret_float(PARROT_INTERP, Parrot_PMC sub_pmc,
1187 ARGIN(const char *signature), ...)
1189 ASSERT_ARGS(Parrot_call_sub_ret_float)
1190 va_list args;
1191 PMC *sig_object;
1192 Parrot_Float result;
1193 char return_sig = signature[0];
1194 const char *arg_sig = signature;
1195 Parrot_sub *sub;
1197 arg_sig++;
1198 va_start(args, signature);
1199 sig_object = Parrot_pcc_build_sig_object_from_varargs(interp, PMCNULL, arg_sig, args);
1200 va_end(args);
1202 /* Add the return argument onto the call signature object (a bit
1203 * hackish, added for backward compatibility in deprecated API function,
1204 * see TT #1145). */
1205 Parrot_pcc_append_result(interp, sig_object, Parrot_str_new_constant(interp, "N"), &result);
1206 PMC_get_sub(interp, sub_pmc, sub);
1207 Parrot_pcc_set_constants(interp, CURRENT_CONTEXT(interp), sub->seg->const_table->constants);
1208 Parrot_pcc_invoke_from_sig_object(interp, sub_pmc, sig_object);
1210 return result;
1215 =item C<void * Parrot_call_method(PARROT_INTERP, Parrot_PMC sub_pmc, Parrot_PMC
1216 obj, Parrot_String method, const char *signature, ...)>
1218 Call the parrot subroutine C<sub> as a method on PMC object C<obj>. The method
1219 should have the name C<method> as a Parrot_string, and should have a function
1220 signature C<signature>. Any arguments to the method can be passed at the end
1221 as a variadic argument list.
1223 =cut
1227 PARROT_EXPORT
1228 PARROT_WARN_UNUSED_RESULT
1229 PARROT_CAN_RETURN_NULL
1230 void *
1231 Parrot_call_method(PARROT_INTERP, Parrot_PMC sub_pmc, Parrot_PMC obj,
1232 Parrot_String method, ARGIN(const char *signature), ...)
1234 ASSERT_ARGS(Parrot_call_method)
1235 va_list args;
1236 PMC *sig_object;
1237 void *result = NULL;
1238 char return_sig = signature[0];
1239 char *arg_sig = (char*)malloc(strlen(signature)+2);
1240 Parrot_sub *sub;
1241 arg_sig[0] = 'P';
1242 arg_sig[1] = 'i';
1243 arg_sig[2] = 0;
1244 strcat(arg_sig, signature);
1246 va_start(args, signature);
1247 sig_object = Parrot_pcc_build_sig_object_from_varargs(interp, obj, arg_sig, args);
1248 va_end(args);
1249 free(arg_sig);
1251 /* Add the return argument onto the call signature object (a bit
1252 * hackish, added for backward compatibility in deprecated API function,
1253 * see TT #1145). */
1254 switch (return_sig) {
1255 case 'v':
1257 Parrot_String full_sig = VTABLE_get_string(interp, sig_object);
1258 Parrot_str_concat(interp, full_sig,
1259 Parrot_str_new_constant(interp, "->"), 0);
1260 break;
1262 case 'V':
1263 case 'P':
1265 Parrot_pcc_append_result(interp, sig_object, Parrot_str_new_constant(interp, "P"),
1266 &result);
1267 break;
1269 default:
1270 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
1271 "Dispatch: invalid return type %c!", return_sig);
1274 PMC_get_sub(interp, sub_pmc, sub);
1275 Parrot_pcc_set_constants(interp, CURRENT_CONTEXT(interp), sub->seg->const_table->constants);
1276 Parrot_pcc_invoke_from_sig_object(interp, sub_pmc, sig_object);
1278 return result;
1283 =item C<Parrot_Int Parrot_call_method_ret_int(PARROT_INTERP, Parrot_PMC sub_pmc,
1284 Parrot_PMC obj, Parrot_String method, const char *signature, ...)>
1286 Call the parrot subroutine C<sub> as a method on PMC object C<obj>. The method
1287 should have the name C<method> as a Parrot_string, and should have a function
1288 signature C<signature>. Any arguments to the method can be passed at the end
1289 as a variadic argument list.
1291 =cut
1295 PARROT_EXPORT
1296 Parrot_Int
1297 Parrot_call_method_ret_int(PARROT_INTERP, Parrot_PMC sub_pmc,
1298 Parrot_PMC obj, Parrot_String method, ARGIN(const char *signature), ...)
1300 ASSERT_ARGS(Parrot_call_method_ret_int)
1301 va_list args;
1302 PMC *sig_object;
1303 Parrot_Int result = 0;
1304 char return_sig = signature[0];
1305 char *arg_sig = (char*)malloc(strlen(signature)+2);
1306 Parrot_sub *sub;
1307 arg_sig[0] = 'P';
1308 arg_sig[1] = 'i';
1309 arg_sig[2] = 0;
1310 strcat(arg_sig, signature);
1312 va_start(args, signature);
1313 sig_object = Parrot_pcc_build_sig_object_from_varargs(interp, obj, arg_sig, args);
1314 va_end(args);
1315 free(arg_sig);
1317 Parrot_pcc_append_result(interp, sig_object, Parrot_str_new_constant(interp, "I"), &result);
1318 PMC_get_sub(interp, sub_pmc, sub);
1319 Parrot_pcc_set_constants(interp, CURRENT_CONTEXT(interp), sub->seg->const_table->constants);
1320 Parrot_pcc_invoke_from_sig_object(interp, sub_pmc, sig_object);
1322 return result;
1327 =item C<Parrot_Float Parrot_call_method_ret_float(PARROT_INTERP, Parrot_PMC
1328 sub_pmc, Parrot_PMC obj, Parrot_String method, const char *signature, ...)>
1330 Call a parrot method for the given object.
1332 =cut
1336 PARROT_EXPORT
1337 Parrot_Float
1338 Parrot_call_method_ret_float(PARROT_INTERP, Parrot_PMC sub_pmc,
1339 Parrot_PMC obj, Parrot_String method, ARGIN(const char *signature), ...)
1341 ASSERT_ARGS(Parrot_call_method_ret_float)
1342 va_list args;
1343 PMC *sig_object;
1344 Parrot_Float result = 0.0;
1345 char return_sig = signature[0];
1346 char *arg_sig = (char*)malloc(strlen(signature)+2);
1347 Parrot_sub *sub;
1348 arg_sig[0] = 'P';
1349 arg_sig[1] = 'i';
1350 arg_sig[2] = 0;
1351 strcat(arg_sig, signature);
1353 va_start(args, signature);
1354 sig_object = Parrot_pcc_build_sig_object_from_varargs(interp, obj, arg_sig, args);
1355 va_end(args);
1356 free(arg_sig);
1358 Parrot_pcc_append_result(interp, sig_object, Parrot_str_new_constant(interp, "N"), &result);
1359 PMC_get_sub(interp, sub_pmc, sub);
1360 Parrot_pcc_set_constants(interp, CURRENT_CONTEXT(interp), sub->seg->const_table->constants);
1361 Parrot_pcc_invoke_from_sig_object(interp, sub_pmc, sig_object);
1363 return result;
1368 =item C<Parrot_Int Parrot_get_intreg(PARROT_INTERP, Parrot_Int regnum)>
1370 Return the value of an integer register.
1372 =cut
1376 PARROT_EXPORT
1377 Parrot_Int
1378 Parrot_get_intreg(PARROT_INTERP, Parrot_Int regnum)
1380 ASSERT_ARGS(Parrot_get_intreg)
1381 return REG_INT(interp, regnum);
1386 =item C<Parrot_Float Parrot_get_numreg(PARROT_INTERP, Parrot_Int regnum)>
1388 Return the value of a numeric register.
1390 =cut
1394 PARROT_EXPORT
1395 Parrot_Float
1396 Parrot_get_numreg(PARROT_INTERP, Parrot_Int regnum)
1398 ASSERT_ARGS(Parrot_get_numreg)
1399 return REG_NUM(interp, regnum);
1404 =item C<Parrot_String Parrot_get_strreg(PARROT_INTERP, Parrot_Int regnum)>
1406 Return the value of a string register.
1408 =cut
1412 PARROT_EXPORT
1413 Parrot_String
1414 Parrot_get_strreg(PARROT_INTERP, Parrot_Int regnum)
1416 ASSERT_ARGS(Parrot_get_strreg)
1417 return REG_STR(interp, regnum);
1422 =item C<Parrot_PMC Parrot_get_pmcreg(PARROT_INTERP, Parrot_Int regnum)>
1424 Return the value of a PMC register.
1426 =cut
1430 PARROT_EXPORT
1431 Parrot_PMC
1432 Parrot_get_pmcreg(PARROT_INTERP, Parrot_Int regnum)
1434 ASSERT_ARGS(Parrot_get_pmcreg)
1435 return REG_PMC(interp, regnum);
1440 =item C<void Parrot_set_intreg(PARROT_INTERP, Parrot_Int regnum, Parrot_Int
1441 value)>
1443 Set the value of an I register.
1445 =cut
1449 PARROT_EXPORT
1450 void
1451 Parrot_set_intreg(PARROT_INTERP, Parrot_Int regnum,
1452 Parrot_Int value)
1454 ASSERT_ARGS(Parrot_set_intreg)
1455 REG_INT(interp, regnum) = value;
1460 =item C<void Parrot_set_numreg(PARROT_INTERP, Parrot_Int regnum, Parrot_Float
1461 value)>
1463 Set the value of an N register.
1465 =cut
1469 PARROT_EXPORT
1470 void
1471 Parrot_set_numreg(PARROT_INTERP, Parrot_Int regnum,
1472 Parrot_Float value)
1474 ASSERT_ARGS(Parrot_set_numreg)
1475 REG_NUM(interp, regnum) = value;
1480 =item C<void Parrot_set_strreg(PARROT_INTERP, Parrot_Int regnum, Parrot_String
1481 value)>
1483 Set the value of an S register.
1485 =cut
1489 PARROT_EXPORT
1490 void
1491 Parrot_set_strreg(PARROT_INTERP, Parrot_Int regnum,
1492 Parrot_String value)
1494 ASSERT_ARGS(Parrot_set_strreg)
1495 REG_STR(interp, regnum) = value;
1500 =item C<void Parrot_set_pmcreg(PARROT_INTERP, Parrot_Int regnum, Parrot_PMC
1501 value)>
1503 Set the value of a P register.
1505 =cut
1509 PARROT_EXPORT
1510 void
1511 Parrot_set_pmcreg(PARROT_INTERP, Parrot_Int regnum,
1512 Parrot_PMC value)
1514 ASSERT_ARGS(Parrot_set_pmcreg)
1515 REG_PMC(interp, regnum) = value;
1518 /*=for api extend Parrot_new_string
1523 =item C<Parrot_String Parrot_new_string(PARROT_INTERP, const char *buffer,
1524 Parrot_UInt length, const char * const encoding_name, Parrot_UInt flags)>
1526 Create a new Parrot string from a passed-in buffer. Pass in a 0 for
1527 flags for right now.
1529 A copy of the buffer is made.
1531 =cut
1535 PARROT_EXPORT
1536 PARROT_WARN_UNUSED_RESULT
1537 PARROT_CANNOT_RETURN_NULL
1538 Parrot_String
1539 Parrot_new_string(PARROT_INTERP, ARGIN_NULLOK(const char *buffer),
1540 Parrot_UInt length, ARGIN_NULLOK(const char * const encoding_name),
1541 Parrot_UInt flags)
1543 ASSERT_ARGS(Parrot_new_string)
1544 Parrot_String retval;
1545 PARROT_CALLIN_START(interp);
1546 retval = string_make(interp, buffer, length, encoding_name, flags);
1547 PARROT_CALLIN_END(interp);
1548 return retval;
1553 =item C<Parrot_Language Parrot_find_language(PARROT_INTERP, char *language)>
1555 Find the magic language token for a language, by language name.
1557 =cut
1561 PARROT_EXPORT
1562 PARROT_WARN_UNUSED_RESULT
1563 Parrot_Language
1564 Parrot_find_language(SHIM_INTERP, SHIM(char *language))
1566 ASSERT_ARGS(Parrot_find_language)
1567 return 0;
1572 =item C<void Parrot_register_pmc(PARROT_INTERP, Parrot_PMC pmc)>
1574 Add a reference of the PMC to the interpreter's GC registry. This prevents PMCs
1575 only known to extension from getting destroyed during GC runs.
1577 =cut
1581 PARROT_EXPORT
1582 void
1583 Parrot_register_pmc(PARROT_INTERP, Parrot_PMC pmc)
1585 ASSERT_ARGS(Parrot_register_pmc)
1586 PARROT_CALLIN_START(interp);
1587 gc_register_pmc(interp, pmc);
1588 PARROT_CALLIN_END(interp);
1593 =item C<void Parrot_unregister_pmc(PARROT_INTERP, Parrot_PMC pmc)>
1595 Remove a reference of the PMC from the interpreter's GC registry. If the
1596 reference count reaches zero, the PMC will be destroyed during the next GC run.
1598 =cut
1602 PARROT_EXPORT
1603 void
1604 Parrot_unregister_pmc(PARROT_INTERP, Parrot_PMC pmc)
1606 ASSERT_ARGS(Parrot_unregister_pmc)
1607 PARROT_CALLIN_START(interp);
1608 gc_unregister_pmc(interp, pmc);
1609 PARROT_CALLIN_END(interp);
1614 =item C<void Parrot_PMC_set_vtable(PARROT_INTERP, Parrot_PMC pmc, Parrot_VTABLE
1615 vtable)>
1617 Replaces the vtable of the PMC.
1619 =cut
1623 PARROT_EXPORT
1624 void
1625 Parrot_PMC_set_vtable(SHIM_INTERP, Parrot_PMC pmc, Parrot_VTABLE vtable)
1627 ASSERT_ARGS(Parrot_PMC_set_vtable)
1628 pmc->vtable = vtable;
1633 =item C<Parrot_VTABLE Parrot_get_vtable(PARROT_INTERP, Parrot_Int id)>
1635 Returns the vtable corresponding to the given PMC ID.
1637 =cut
1641 PARROT_EXPORT
1642 PARROT_PURE_FUNCTION
1643 Parrot_VTABLE
1644 Parrot_get_vtable(PARROT_INTERP, Parrot_Int id)
1646 ASSERT_ARGS(Parrot_get_vtable)
1647 return interp->vtables[id];
1652 =item C<Parrot_PMC Parrot_sub_new_from_c_func(PARROT_INTERP, void (*func(void)),
1653 const char * signature)>
1655 Returns a PMC sub wrapper for a c function.
1657 =cut
1661 PARROT_EXPORT
1662 Parrot_PMC
1663 Parrot_sub_new_from_c_func(PARROT_INTERP,
1664 ARGIN(void (*func)(void)), ARGIN(const char * signature))
1666 ASSERT_ARGS(Parrot_sub_new_from_c_func)
1667 Parrot_String sig = Parrot_new_string(interp, signature, strlen(signature),
1668 (char *) NULL, 0);
1669 Parrot_PMC sub = pmc_new(interp, enum_class_NCI);
1670 VTABLE_set_pointer_keyed_str(interp, sub, sig, F2DPTR(func));
1671 PObj_get_FLAGS(sub) |= PObj_private1_FLAG;
1672 return sub;
1677 =item C<Parrot_PMC Parrot_PMC_newclass(PARROT_INTERP, Parrot_PMC classtype)>
1679 Create a class with the type given
1681 =cut
1685 PARROT_EXPORT
1686 Parrot_PMC
1687 Parrot_PMC_newclass(PARROT_INTERP, Parrot_PMC classtype)
1689 ASSERT_ARGS(Parrot_PMC_newclass)
1690 Parrot_PMC result;
1691 PARROT_CALLIN_START(interp);
1693 result = pmc_new_init(interp, enum_class_Class, classtype);
1695 PARROT_CALLIN_END(interp);
1696 return result;
1701 =back
1703 =head1 SEE ALSO
1705 See F<include/parrot/extend.h> and F<docs/pdds/pdd11_extending.pod>.
1707 =head1 HISTORY
1709 Initial version by Dan Sugalski.
1711 =cut
1717 * Local variables:
1718 * c-file-style: "parrot"
1719 * End:
1720 * vim: expandtab shiftwidth=4: