tagged release 0.7.1
[parrot.git] / src / extend.c
blob71b31f97e243fb650a3ee382dd0d12c39efc9107
1 /*
2 Copyright (C) 2001-2007, The Perl 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 DOD 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"
64 /* HEADERIZER HFILE: include/parrot/extend.h */
68 =item C<int Parrot_vfprintf>
70 Writes a C string format with a varargs list to a PIO.
72 =item C<int Parrot_fprintf>
74 Writes a C string format with varargs to a PIO.
76 =item C<int Parrot_printf>
78 Writes a C string format with varargs to C<stdout>.
80 =item C<int Parrot_eprintf>
82 Writes a C string format with varargs to C<stderr>.
84 =cut
88 PARROT_API
89 int
90 Parrot_vfprintf(PARROT_INTERP, ARGIN(Parrot_PMC pio),
91 ARGIN(const char *s), va_list args)
93 STRING * str;
94 INTVAL retval;
96 PARROT_CALLIN_START(interp);
97 str = Parrot_vsprintf_c(interp, s, args);
98 retval = PIO_putps(interp, pio, str);
99 PARROT_CALLIN_END(interp);
101 return retval;
104 PARROT_API
106 Parrot_fprintf(PARROT_INTERP, ARGIN(Parrot_PMC pio),
107 ARGIN(const char *s), ...)
109 va_list args;
110 INTVAL retval;
112 va_start(args, s);
113 retval = Parrot_vfprintf(interp, pio, s, args);
114 va_end(args);
116 return retval;
119 PARROT_API
121 Parrot_printf(NULLOK_INTERP, ARGIN(const char *s), ...)
123 va_list args;
124 INTVAL retval;
125 va_start(args, s);
127 if (interp) {
128 retval = Parrot_vfprintf(interp, PIO_STDOUT(interp), s, args);
130 else {
131 /* Be nice about this...
132 ** XXX BD Should this use the default PIO_STDOUT or something?
134 retval = vfprintf(stdout, s, args);
136 va_end(args);
138 return retval;
141 PARROT_API
143 Parrot_eprintf(NULLOK_INTERP, ARGIN(const char *s), ...)
145 va_list args;
146 INTVAL retval;
148 va_start(args, s);
150 if (interp) {
151 retval = Parrot_vfprintf(interp, PIO_STDERR(interp), s, args);
153 else {
154 /* Be nice about this...
155 ** XXX BD Should this use the default PIO_STDOUT or something?
157 retval=vfprintf(stderr, s, args);
160 va_end(args);
162 return retval;
167 =item C<Parrot_String Parrot_PMC_get_string_intkey>
169 Return the integer keyed string value of the passed-in PMC
171 =cut
175 PARROT_API
176 Parrot_String
177 Parrot_PMC_get_string_intkey(PARROT_INTERP,
178 Parrot_PMC pmc, Parrot_Int key)
180 Parrot_String retval;
181 PARROT_CALLIN_START(interp);
182 retval = VTABLE_get_string_keyed_int(interp, pmc, key);
183 PARROT_CALLIN_END(interp);
184 return retval;
190 =item C<void * Parrot_PMC_get_pointer_intkey>
192 Return a pointer to the PMC indicated by an integer key.
194 =cut
198 PARROT_API
199 PARROT_WARN_UNUSED_RESULT
200 PARROT_CAN_RETURN_NULL
201 void *
202 Parrot_PMC_get_pointer_intkey(PARROT_INTERP,
203 Parrot_PMC pmc, Parrot_Int key)
205 void *retval;
206 PARROT_CALLIN_START(interp);
207 retval = VTABLE_get_pointer_keyed_int(interp, pmc, key);
208 PARROT_CALLIN_END(interp);
209 return retval;
214 =item C<Parrot_PMC Parrot_PMC_get_pmc_intkey>
216 Return the integer keyed PMC value of the passed-in PMC
218 =cut
222 PARROT_API
223 Parrot_PMC
224 Parrot_PMC_get_pmc_intkey(PARROT_INTERP,
225 Parrot_PMC pmc, Parrot_Int key)
227 Parrot_PMC retval;
228 PARROT_CALLIN_START(interp);
229 retval = VTABLE_get_pmc_keyed_int(interp, pmc, key);
230 PARROT_CALLIN_END(interp);
231 return retval;
236 =item C<Parrot_Int Parrot_PMC_get_intval>
238 Return the signed integer value of the value in the PMC.
240 =cut
244 PARROT_API
245 Parrot_Int
246 Parrot_PMC_get_intval(PARROT_INTERP, Parrot_PMC pmc)
248 Parrot_Int retval;
249 PARROT_CALLIN_START(interp);
250 retval = VTABLE_get_integer(interp, pmc);
251 PARROT_CALLIN_END(interp);
252 return retval;
257 =item C<Parrot_Int Parrot_PMC_get_intval_intkey>
259 Return the keyed, signed integer value of the value in the PMC.
261 =cut
265 PARROT_API
266 Parrot_Int
267 Parrot_PMC_get_intval_intkey(PARROT_INTERP,
268 Parrot_PMC pmc, Parrot_Int key)
270 Parrot_Int retval;
271 PARROT_CALLIN_START(interp);
272 retval = VTABLE_get_integer_keyed_int(interp, pmc, key);
273 PARROT_CALLIN_END(interp);
274 return retval;
279 =item C<Parrot_Int Parrot_PMC_get_intval_pmckey>
281 Return the keyed, signed integer value of the value in the PMC.
283 =cut
287 PARROT_API
288 Parrot_Int
289 Parrot_PMC_get_intval_pmckey(PARROT_INTERP,
290 Parrot_PMC pmc, Parrot_PMC key)
292 Parrot_Int retval;
293 PARROT_CALLIN_START(interp);
294 retval = VTABLE_get_integer_keyed(interp, pmc, key);
295 PARROT_CALLIN_END(interp);
296 return retval;
301 =item C<Parrot_Float Parrot_PMC_get_numval>
303 Return the floating-point value of the PMC.
305 =cut
309 PARROT_API
310 Parrot_Float
311 Parrot_PMC_get_numval(PARROT_INTERP, Parrot_PMC pmc)
313 Parrot_Float retval;
314 PARROT_CALLIN_START(interp);
315 retval = VTABLE_get_number(interp, pmc);
316 PARROT_CALLIN_END(interp);
317 return retval;
322 =item C<Parrot_Float Parrot_PMC_get_numval_intkey>
324 Return the keyed, signed integer value of the value in the PMC.
326 =cut
330 PARROT_API
331 Parrot_Float
332 Parrot_PMC_get_numval_intkey(PARROT_INTERP,
333 Parrot_PMC pmc, Parrot_Int key)
335 Parrot_Float retval;
336 PARROT_CALLIN_START(interp);
337 retval = VTABLE_get_number_keyed_int(interp, pmc, key);
338 PARROT_CALLIN_END(interp);
339 return retval;
344 =item C<char * Parrot_PMC_get_cstring_intkey>
346 Return a null-terminated string that represents the string value of the PMC.
348 Note that you must free this string with C<string_cstring_free()>!
350 =cut
354 PARROT_API
355 PARROT_MALLOC
356 PARROT_CAN_RETURN_NULL
357 char *
358 Parrot_PMC_get_cstring_intkey(PARROT_INTERP,
359 Parrot_PMC pmc, Parrot_Int key)
361 STRING *intermediate;
362 char *retval;
364 PARROT_CALLIN_START(interp);
365 intermediate = VTABLE_get_string_keyed_int(interp, pmc, key);
366 retval = string_to_cstring(interp, intermediate);
367 PARROT_CALLIN_END(interp);
369 return retval;
374 =item C<char * Parrot_PMC_get_cstring>
376 Return a null-terminated string that represents the string value of the PMC.
378 Note that you must free this string with C<string_cstring_free()>!
380 =cut
384 PARROT_API
385 PARROT_MALLOC
386 PARROT_CAN_RETURN_NULL
387 char *
388 Parrot_PMC_get_cstring(PARROT_INTERP, Parrot_PMC pmc)
390 STRING *intermediate;
391 char *retval;
393 PARROT_CALLIN_START(interp);
394 intermediate = VTABLE_get_string(interp, pmc);
395 retval = string_to_cstring(interp, intermediate);
396 PARROT_CALLIN_END(interp);
398 return retval;
403 =item C<char * Parrot_PMC_get_cstringn>
405 Return a null-terminated string for the PMC, along with the length.
407 Yes, right now this is a bit of a cheat. It needs fixing, but without
408 disturbing the interface.
410 Note that you must free the string with C<string_cstring_free()>.
412 =cut
416 PARROT_API
417 PARROT_MALLOC
418 PARROT_CAN_RETURN_NULL
419 char *
420 Parrot_PMC_get_cstringn(PARROT_INTERP, ARGIN(Parrot_PMC pmc),
421 ARGOUT(Parrot_Int *length))
423 char *retval;
425 PARROT_CALLIN_START(interp);
426 retval = string_to_cstring(interp, VTABLE_get_string(interp, pmc));
427 *length = strlen(retval);
428 PARROT_CALLIN_END(interp);
430 return retval;
435 =item C<char * Parrot_PMC_get_cstringn_intkey>
437 Return a null-terminated string for the PMC, along with the length.
439 Yes, right now this is a bit of a cheat. It needs fixing, but without
440 disturbing the interface.
442 Note that you must free this string with C<string_cstring_free()>.
444 =cut
448 PARROT_API
449 PARROT_MALLOC
450 PARROT_CAN_RETURN_NULL
451 char *
452 Parrot_PMC_get_cstringn_intkey(PARROT_INTERP, ARGIN(Parrot_PMC pmc),
453 ARGOUT(Parrot_Int *length), Parrot_Int key)
455 char *retval;
457 PARROT_CALLIN_START(interp);
458 retval = string_to_cstring(interp,
459 VTABLE_get_string_keyed_int(interp, pmc, key));
460 *length = strlen(retval);
461 PARROT_CALLIN_END(interp);
463 return retval;
468 =item C<void Parrot_PMC_set_string>
470 Assign the passed-in Parrot string to the passed-in PMC.
472 =cut
476 PARROT_API
477 void
478 Parrot_PMC_set_string(PARROT_INTERP,
479 Parrot_PMC pmc, Parrot_String value)
481 PARROT_CALLIN_START(interp);
482 VTABLE_set_string_native(interp, pmc, value);
483 PARROT_CALLIN_END(interp);
488 =item C<void Parrot_PMC_set_string_intkey>
490 Assign the passed-in Parrot string to the passed-in PMC.
492 =cut
496 PARROT_API
497 void
498 Parrot_PMC_set_string_intkey(PARROT_INTERP,
499 Parrot_PMC pmc, Parrot_Int key, Parrot_String value)
501 PARROT_CALLIN_START(interp);
502 VTABLE_set_string_keyed_int(interp, pmc, key, value);
503 PARROT_CALLIN_END(interp);
508 =item C<void Parrot_PMC_set_pmc_intkey>
510 Assign the passed-in pmc to the passed-in slot of the passed-in PMC.
512 =cut
516 PARROT_API
517 void
518 Parrot_PMC_set_pmc_intkey(PARROT_INTERP,
519 Parrot_PMC pmc, Parrot_Int key, Parrot_PMC value)
521 PARROT_CALLIN_START(interp);
522 VTABLE_set_pmc_keyed_int(interp, pmc, key, value);
523 PARROT_CALLIN_END(interp);
528 =item C<void Parrot_PMC_set_pmc_pmckey>
530 Assign the passed-in pmc to the passed-in slot of the passed-in PMC.
532 =cut
536 PARROT_API
537 void
538 Parrot_PMC_set_pmc_pmckey(PARROT_INTERP,
539 Parrot_PMC pmc, Parrot_PMC key, Parrot_PMC value)
541 PARROT_CALLIN_START(interp);
542 VTABLE_set_pmc_keyed(interp, pmc, key, value);
543 PARROT_CALLIN_END(interp);
548 =item C<void Parrot_PMC_set_pointer_intkey>
550 Assign the passed-in pointer to the passed-in PMC.
552 =cut
556 PARROT_API
557 void
558 Parrot_PMC_set_pointer_intkey(PARROT_INTERP,
559 ARGIN(Parrot_PMC pmc), Parrot_Int key, ARGIN_NULLOK(void *value))
561 PARROT_CALLIN_START(interp);
562 VTABLE_set_pointer_keyed_int(interp, pmc, key, value);
563 PARROT_CALLIN_END(interp);
568 =item C<void Parrot_PMC_set_intval>
570 Assign the passed-in Parrot integer to the passed-in PMC.
572 =cut
576 PARROT_API
577 void
578 Parrot_PMC_set_intval(PARROT_INTERP, Parrot_PMC pmc, Parrot_Int value)
580 PARROT_CALLIN_START(interp);
581 VTABLE_set_integer_native(interp, pmc, value);
582 PARROT_CALLIN_END(interp);
587 =item C<void Parrot_PMC_set_intval_intkey>
589 Assign the passed-in Parrot integer to the passed-in PMC.
591 =cut
595 PARROT_API
596 void
597 Parrot_PMC_set_intval_intkey(PARROT_INTERP,
598 Parrot_PMC pmc, Parrot_Int key, Parrot_Int value)
600 PARROT_CALLIN_START(interp);
601 VTABLE_set_integer_keyed_int(interp, pmc, key, value);
602 PARROT_CALLIN_END(interp);
607 =item C<void Parrot_PMC_set_numval>
609 Assign the passed-in Parrot number to the passed-in PMC.
611 =cut
615 PARROT_API
616 void
617 Parrot_PMC_set_numval(PARROT_INTERP, Parrot_PMC pmc, Parrot_Float value)
619 PARROT_CALLIN_START(interp);
620 VTABLE_set_number_native(interp, pmc, value);
621 PARROT_CALLIN_END(interp);
626 =item C<void Parrot_PMC_set_numval_intkey>
628 Assign the passed-in Parrot number to the passed-in PMC.
630 =cut
634 PARROT_API
635 void
636 Parrot_PMC_set_numval_intkey(PARROT_INTERP,
637 Parrot_PMC pmc, Parrot_Int key, Parrot_Float value)
639 PARROT_CALLIN_START(interp);
640 VTABLE_set_number_keyed_int(interp, pmc, key, value);
641 PARROT_CALLIN_END(interp);
646 =item C<void Parrot_PMC_set_cstring>
648 Assign the passed-in null-terminated C string to the passed-in PMC.
650 =cut
654 PARROT_API
655 void
656 Parrot_PMC_set_cstring(PARROT_INTERP, Parrot_PMC pmc, ARGIN_NULLOK(const char *value))
658 PARROT_CALLIN_START(interp);
659 VTABLE_set_string_native(interp, pmc,
660 string_from_cstring(interp, value, 0));
661 PARROT_CALLIN_END(interp);
666 =item C<void Parrot_PMC_set_cstring_intkey>
668 Assign the passed-in null-terminated C string to the passed-in PMC.
670 =cut
674 PARROT_API
675 void
676 Parrot_PMC_set_cstring_intkey(PARROT_INTERP,
677 Parrot_PMC pmc, Parrot_Int key, ARGIN_NULLOK(const char *value))
679 PARROT_CALLIN_START(interp);
680 VTABLE_set_string_keyed_int(interp, pmc, key,
681 string_from_cstring(interp, value, 0));
682 PARROT_CALLIN_END(interp);
687 =item C<void Parrot_PMC_set_cstringn>
689 Assign the passed-in length-noted string to the passed-in PMC.
691 =cut
695 PARROT_API
696 void
697 Parrot_PMC_set_cstringn(PARROT_INTERP,
698 Parrot_PMC pmc, ARGIN_NULLOK(const char *value), Parrot_Int length)
700 PARROT_CALLIN_START(interp);
701 VTABLE_set_string_native(interp, pmc,
702 string_from_cstring(interp, value, length));
703 PARROT_CALLIN_END(interp);
708 =item C<void Parrot_PMC_push_intval>
710 Push the passed-in Parrot integer onto the passed in PMC
712 =cut
716 PARROT_API
717 void
718 Parrot_PMC_push_intval(PARROT_INTERP,
719 Parrot_PMC pmc, Parrot_Int value)
721 PARROT_CALLIN_START(interp);
722 VTABLE_push_integer(interp, pmc, value);
723 PARROT_CALLIN_END(interp);
728 =item C<void Parrot_PMC_push_numval>
730 Push the passed-in Parrot number onto the passed in PMC
732 =cut
736 PARROT_API
737 void
738 Parrot_PMC_push_numval(PARROT_INTERP, Parrot_PMC pmc, Parrot_Float value)
740 PARROT_CALLIN_START(interp);
741 VTABLE_push_float(interp, pmc, value);
742 PARROT_CALLIN_END(interp);
747 =item C<void Parrot_PMC_delete_pmckey>
749 Deletes the value associated with the passed-in PMC from the PMC.
751 =cut
755 PARROT_API
756 void
757 Parrot_PMC_delete_pmckey(PARROT_INTERP, Parrot_PMC pmc, Parrot_PMC key)
759 PARROT_CALLIN_START(interp);
760 VTABLE_delete_keyed(interp, pmc, key);
761 PARROT_CALLIN_END(interp);
766 =item C<void Parrot_PMC_set_cstringn_intkey>
768 Assign the passed-in length-noted string to the passed-in PMC.
770 =cut
774 PARROT_API
775 void
776 Parrot_PMC_set_cstringn_intkey(PARROT_INTERP,
777 Parrot_PMC pmc, Parrot_Int key, ARGIN_NULLOK(const char *value), Parrot_Int length)
779 PARROT_CALLIN_START(interp);
780 VTABLE_set_string_keyed_int(interp, pmc, key,
781 string_from_cstring(interp, value, length));
782 PARROT_CALLIN_END(interp);
787 =item C<Parrot_PMC Parrot_PMC_new>
789 Create and return a new PMC.
791 =cut
795 PARROT_API
796 Parrot_PMC
797 Parrot_PMC_new(PARROT_INTERP, Parrot_Int type)
799 Parrot_PMC newpmc;
800 PARROT_CALLIN_START(interp);
801 newpmc = pmc_new_noinit(interp, type);
802 VTABLE_init(interp, newpmc);
803 PARROT_CALLIN_END(interp);
804 return newpmc;
809 =item C<Parrot_Int Parrot_PMC_typenum>
811 Returns the internal identifier that represents the named class.
813 =cut
817 PARROT_API
818 Parrot_Int
819 Parrot_PMC_typenum(PARROT_INTERP, ARGIN_NULLOK(const char *_class))
821 Parrot_Int retval;
822 PARROT_CALLIN_START(interp);
823 retval = pmc_type(interp, string_from_cstring(interp, _class, 0));
824 PARROT_CALLIN_END(interp);
825 return retval;
830 =item C<Parrot_PMC Parrot_PMC_null>
832 Returns the special C<NULL> PMC.
834 =cut
838 PARROT_API
839 Parrot_PMC
840 Parrot_PMC_null(void)
842 return PMCNULL;
847 =item C<void Parrot_free_cstring>
849 Deallocate a C string that the interpreter has handed to you.
851 =cut
855 PARROT_API
856 void
857 Parrot_free_cstring(ARGIN_NULLOK(char *string))
859 string_cstring_free(string);
864 =item C<void* Parrot_call_sub>
866 Call a parrot subroutine with the given function signature. The first char in
867 C<signature> denotes the return value. Next chars are arguments.
869 The return value of this function can be void or a pointer type.
871 Signature chars are:
873 v ... void return
874 I ... Parrot_Int
875 N ... Parrot_Float
876 S ... Parrot_String
877 P ... Parrot_PMC
879 =cut
883 PARROT_API
884 PARROT_WARN_UNUSED_RESULT
885 PARROT_CAN_RETURN_NULL
886 void*
887 Parrot_call_sub(PARROT_INTERP, Parrot_PMC sub,
888 ARGIN(const char *signature), ...)
890 va_list ap;
891 void *result;
893 PARROT_CALLIN_START(interp);
895 va_start(ap, signature);
896 CONTEXT(interp)->constants =
897 PMC_sub(sub)->seg->const_table->constants;
898 result = Parrot_runops_fromc_arglist(interp, sub, signature, ap);
899 va_end(ap);
901 PARROT_CALLIN_END(interp);
902 return result;
907 =item C<Parrot_Int Parrot_call_sub_ret_int>
909 Like C<Parrot_call_sub>, with Parrot_Int return result.
911 =cut
915 PARROT_API
916 Parrot_Int
917 Parrot_call_sub_ret_int(PARROT_INTERP, Parrot_PMC sub,
918 ARGIN(const char *signature), ...)
920 va_list ap;
921 Parrot_Int result;
923 PARROT_CALLIN_START(interp);
925 va_start(ap, signature);
926 CONTEXT(interp)->constants =
927 PMC_sub(sub)->seg->const_table->constants;
928 result = Parrot_runops_fromc_arglist_reti(interp, sub, signature, ap);
929 va_end(ap);
931 PARROT_CALLIN_END(interp);
932 return result;
937 =item C<Parrot_Float Parrot_call_sub_ret_float>
939 Like C<Parrot_call_sub>, with Parrot_Float return result.
941 =cut
945 PARROT_API
946 Parrot_Float
947 Parrot_call_sub_ret_float(PARROT_INTERP, Parrot_PMC sub,
948 ARGIN(const char *signature), ...)
950 va_list ap;
951 Parrot_Float result;
953 PARROT_CALLIN_START(interp);
955 va_start(ap, signature);
956 CONTEXT(interp)->constants =
957 PMC_sub(sub)->seg->const_table->constants;
958 result = Parrot_runops_fromc_arglist_retf(interp, sub, signature, ap);
959 va_end(ap);
961 PARROT_CALLIN_END(interp);
962 return result;
967 =item C<void * Parrot_call_method>
969 Call the parrot subroutine C<sub> as a method on PMC object C<obj>. The method
970 should have the name C<method> as a Parrot_string, and should have a function
971 signature C<signature>. Any arguments to the method can be passed at the end
972 as a variadic argument list.
974 =cut
978 PARROT_API
979 PARROT_WARN_UNUSED_RESULT
980 PARROT_CAN_RETURN_NULL
981 void *
982 Parrot_call_method(PARROT_INTERP, Parrot_PMC sub, Parrot_PMC obj,
983 Parrot_String method, ARGIN(const char *signature), ...)
985 void *result;
986 va_list ap;
988 PARROT_CALLIN_START(interp);
989 va_start(ap, signature);
990 result = Parrot_run_meth_fromc_arglist(interp, sub,
991 obj, method, signature, ap);
992 va_end(ap);
993 PARROT_CALLIN_END(interp);
994 return result;
999 =item C<Parrot_Int Parrot_call_method_ret_int>
1001 Call a parrot method for the given object.
1003 =cut
1007 PARROT_API
1008 Parrot_Int
1009 Parrot_call_method_ret_int(PARROT_INTERP, Parrot_PMC sub,
1010 Parrot_PMC obj, Parrot_String method, ARGIN(const char *signature), ...)
1012 Parrot_Int result;
1013 va_list ap;
1015 PARROT_CALLIN_START(interp);
1016 va_start(ap, signature);
1017 result = Parrot_run_meth_fromc_arglist_reti(interp, sub,
1018 obj, method, signature, ap);
1019 va_end(ap);
1020 PARROT_CALLIN_END(interp);
1021 return result;
1026 =item C<Parrot_Float Parrot_call_method_ret_float>
1028 Call a parrot method for the given object.
1030 =cut
1034 PARROT_API
1035 Parrot_Float
1036 Parrot_call_method_ret_float(PARROT_INTERP, Parrot_PMC sub,
1037 Parrot_PMC obj, Parrot_String method, ARGIN(const char *signature), ...)
1039 Parrot_Float result;
1040 va_list ap;
1042 PARROT_CALLIN_START(interp);
1043 va_start(ap, signature);
1044 result = Parrot_run_meth_fromc_arglist_retf(interp, sub,
1045 obj, method, signature, ap);
1046 va_end(ap);
1047 PARROT_CALLIN_END(interp);
1048 return result;
1053 =item C<Parrot_Int Parrot_get_intreg>
1055 Return the value of an integer register.
1057 =cut
1061 PARROT_API
1062 Parrot_Int
1063 Parrot_get_intreg(PARROT_INTERP, Parrot_Int regnum)
1065 return REG_INT(interp, regnum);
1070 =item C<Parrot_Float Parrot_get_numreg>
1072 Return the value of a numeric register.
1074 =cut
1078 PARROT_API
1079 Parrot_Float
1080 Parrot_get_numreg(PARROT_INTERP, Parrot_Int regnum)
1082 return REG_NUM(interp, regnum);
1087 =item C<Parrot_String Parrot_get_strreg>
1089 Return the value of a string register.
1091 =cut
1095 PARROT_API
1096 Parrot_String
1097 Parrot_get_strreg(PARROT_INTERP, Parrot_Int regnum)
1099 return REG_STR(interp, regnum);
1104 =item C<Parrot_PMC Parrot_get_pmcreg>
1106 Return the value of a PMC register.
1108 =cut
1112 PARROT_API
1113 Parrot_PMC
1114 Parrot_get_pmcreg(PARROT_INTERP, Parrot_Int regnum)
1116 return REG_PMC(interp, regnum);
1121 =item C<void Parrot_set_intreg>
1123 Set the value of an I register.
1125 =cut
1129 PARROT_API
1130 void
1131 Parrot_set_intreg(PARROT_INTERP, Parrot_Int regnum,
1132 Parrot_Int value)
1134 REG_INT(interp, regnum) = value;
1139 =item C<void Parrot_set_numreg>
1141 Set the value of an N register.
1143 =cut
1147 PARROT_API
1148 void
1149 Parrot_set_numreg(PARROT_INTERP, Parrot_Int regnum,
1150 Parrot_Float value)
1152 REG_NUM(interp, regnum) = value;
1157 =item C<void Parrot_set_strreg>
1159 Set the value of an S register.
1163 PARROT_API
1164 void
1165 Parrot_set_strreg(PARROT_INTERP, Parrot_Int regnum,
1166 Parrot_String value)
1168 REG_STR(interp, regnum) = value;
1173 =item C<void Parrot_set_pmcreg>
1175 Set the value of a P register.
1177 =cut
1181 PARROT_API
1182 void
1183 Parrot_set_pmcreg(PARROT_INTERP, Parrot_Int regnum,
1184 Parrot_PMC value)
1186 REG_PMC(interp, regnum) = value;
1189 /*=for api extend Parrot_new_string
1194 =item C<Parrot_String Parrot_new_string>
1196 Create a new Parrot string from a passed-in buffer. Pass in a 0 for
1197 flags for right now.
1199 A copy of the buffer is made.
1201 =cut
1205 PARROT_API
1206 PARROT_WARN_UNUSED_RESULT
1207 PARROT_CANNOT_RETURN_NULL
1208 Parrot_String
1209 Parrot_new_string(PARROT_INTERP, ARGIN_NULLOK(const char *buffer), int length,
1210 ARGIN_NULLOK(const char * const encoding_name), Parrot_Int flags)
1212 Parrot_String retval;
1213 PARROT_CALLIN_START(interp);
1214 retval = string_make(interp, buffer, length, encoding_name, flags);
1215 PARROT_CALLIN_END(interp);
1216 return retval;
1221 =item C<Parrot_Language Parrot_find_language>
1223 Find the magic language token for a language, by language name.
1225 =cut
1229 PARROT_API
1230 PARROT_WARN_UNUSED_RESULT
1231 Parrot_Language
1232 Parrot_find_language(SHIM_INTERP, SHIM(char *language))
1234 return 0;
1239 =item C<void Parrot_register_pmc>
1241 Add a reference of the PMC to the interpreters DOD registry. This
1242 prevents PMCs only known to extension from getting destroyed during DOD
1243 runs.
1245 =cut
1249 PARROT_API
1250 void
1251 Parrot_register_pmc(PARROT_INTERP, Parrot_PMC pmc)
1253 PARROT_CALLIN_START(interp);
1254 dod_register_pmc(interp, pmc);
1255 PARROT_CALLIN_END(interp);
1260 =item C<void Parrot_unregister_pmc>
1262 Remove a reference of the PMC from the interpreters DOD registry. If the
1263 reference count reaches zero, the PMC will be destroyed during the next
1264 DOD run.
1266 =cut
1270 PARROT_API
1271 void
1272 Parrot_unregister_pmc(PARROT_INTERP, Parrot_PMC pmc)
1274 PARROT_CALLIN_START(interp);
1275 dod_unregister_pmc(interp, pmc);
1276 PARROT_CALLIN_END(interp);
1281 =item C<void Parrot_PMC_set_vtable>
1283 Replaces the vtable of the PMC.
1285 =cut
1289 PARROT_API
1290 void
1291 Parrot_PMC_set_vtable(SHIM_INTERP, Parrot_PMC pmc, Parrot_VTABLE vtable)
1293 pmc->vtable = vtable;
1298 =item C<Parrot_VTABLE Parrot_get_vtable>
1300 Returns the vtable corresponding to the given PMC ID.
1302 =cut
1306 PARROT_API
1307 PARROT_PURE_FUNCTION
1308 Parrot_VTABLE
1309 Parrot_get_vtable(PARROT_INTERP, Parrot_Int id)
1311 return interp->vtables[id];
1316 =back
1318 =head1 SEE ALSO
1320 See F<include/parrot/extend.h> and F<docs/pdds/pdd11_extending.pod>.
1322 =head1 HISTORY
1324 Initial version by Dan Sugalski.
1326 =cut
1332 * Local variables:
1333 * c-file-style: "parrot"
1334 * End:
1335 * vim: expandtab shiftwidth=4: