* t/op/lexicals-2.t (added), MANIFEST:
[parrot.git] / src / extend.c
bloba401b56fbe8ef4c719916d6fdd487da8bb137988
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>.
86 PARROT_API
87 int
88 Parrot_vfprintf(PARROT_INTERP, ARGIN(Parrot_PMC pio),
89 ARGIN(const char *s), va_list args)
91 STRING * str;
92 INTVAL retval;
94 PARROT_CALLIN_START(interp);
95 str = Parrot_vsprintf_c(interp, s, args);
96 retval = PIO_putps(interp, pio, str);
97 PARROT_CALLIN_END(interp);
99 return retval;
102 PARROT_API
104 Parrot_fprintf(PARROT_INTERP, ARGIN(Parrot_PMC pio),
105 ARGIN(const char *s), ...)
107 va_list args;
108 INTVAL retval;
110 va_start(args, s);
111 retval = Parrot_vfprintf(interp, pio, s, args);
112 va_end(args);
114 return retval;
117 PARROT_API
119 Parrot_printf(NULLOK_INTERP, ARGIN(const char *s), ...)
121 va_list args;
122 INTVAL retval;
123 va_start(args, s);
125 if (interp) {
126 retval = Parrot_vfprintf(interp, PIO_STDOUT(interp), s, args);
128 else {
129 /* Be nice about this...
130 ** XXX BD Should this use the default PIO_STDOUT or something?
132 retval = vfprintf(stdout, s, args);
134 va_end(args);
136 return retval;
139 PARROT_API
141 Parrot_eprintf(NULLOK_INTERP, ARGIN(const char *s), ...)
143 va_list args;
144 INTVAL retval;
146 va_start(args, s);
148 if (interp) {
149 retval = Parrot_vfprintf(interp, PIO_STDERR(interp), s, args);
151 else {
152 /* Be nice about this...
153 ** XXX BD Should this use the default PIO_STDOUT or something?
155 retval=vfprintf(stderr, s, args);
158 va_end(args);
160 return retval;
165 =item C<Parrot_String Parrot_PMC_get_string_intkey>
167 Return the integer keyed string value of the passed-in PMC
169 =cut
173 PARROT_API
174 Parrot_String
175 Parrot_PMC_get_string_intkey(PARROT_INTERP,
176 Parrot_PMC pmc, Parrot_Int key)
178 Parrot_String retval;
179 PARROT_CALLIN_START(interp);
180 retval = VTABLE_get_string_keyed_int(interp, pmc, key);
181 PARROT_CALLIN_END(interp);
182 return retval;
188 =item C<void * Parrot_PMC_get_pointer_intkey>
190 Return a pointer to the PMC indicated by an integer key.
192 =cut
196 PARROT_API
197 PARROT_WARN_UNUSED_RESULT
198 PARROT_CAN_RETURN_NULL
199 void *
200 Parrot_PMC_get_pointer_intkey(PARROT_INTERP,
201 Parrot_PMC pmc, Parrot_Int key)
203 void *retval;
204 PARROT_CALLIN_START(interp);
205 retval = VTABLE_get_pointer_keyed_int(interp, pmc, key);
206 PARROT_CALLIN_END(interp);
207 return retval;
212 =item C<Parrot_PMC Parrot_PMC_get_pmc_intkey>
214 Return the integer keyed PMC value of the passed-in PMC
216 =cut
220 PARROT_API
221 Parrot_PMC
222 Parrot_PMC_get_pmc_intkey(PARROT_INTERP,
223 Parrot_PMC pmc, Parrot_Int key)
225 Parrot_PMC retval;
226 PARROT_CALLIN_START(interp);
227 retval = VTABLE_get_pmc_keyed_int(interp, pmc, key);
228 PARROT_CALLIN_END(interp);
229 return retval;
234 =item C<Parrot_Int Parrot_PMC_get_intval>
236 Return the signed integer value of the value in the PMC.
238 =cut
242 PARROT_API
243 Parrot_Int
244 Parrot_PMC_get_intval(PARROT_INTERP, Parrot_PMC pmc)
246 Parrot_Int retval;
247 PARROT_CALLIN_START(interp);
248 retval = VTABLE_get_integer(interp, pmc);
249 PARROT_CALLIN_END(interp);
250 return retval;
255 =item C<Parrot_Int Parrot_PMC_get_intval_intkey>
257 Return the keyed, signed integer value of the value in the PMC.
259 =cut
263 PARROT_API
264 Parrot_Int
265 Parrot_PMC_get_intval_intkey(PARROT_INTERP,
266 Parrot_PMC pmc, Parrot_Int key)
268 Parrot_Int retval;
269 PARROT_CALLIN_START(interp);
270 retval = VTABLE_get_integer_keyed_int(interp, pmc, key);
271 PARROT_CALLIN_END(interp);
272 return retval;
277 =item C<Parrot_Int Parrot_PMC_get_intval_pmckey>
279 Return the keyed, signed integer value of the value in the PMC.
281 =cut
285 PARROT_API
286 Parrot_Int
287 Parrot_PMC_get_intval_pmckey(PARROT_INTERP,
288 Parrot_PMC pmc, Parrot_PMC key)
290 Parrot_Int retval;
291 PARROT_CALLIN_START(interp);
292 retval = VTABLE_get_integer_keyed(interp, pmc, key);
293 PARROT_CALLIN_END(interp);
294 return retval;
299 =item C<Parrot_Float Parrot_PMC_get_numval>
301 Return the floating-point value of the PMC.
303 =cut
307 PARROT_API
308 Parrot_Float
309 Parrot_PMC_get_numval(PARROT_INTERP, Parrot_PMC pmc)
311 Parrot_Float retval;
312 PARROT_CALLIN_START(interp);
313 retval = VTABLE_get_number(interp, pmc);
314 PARROT_CALLIN_END(interp);
315 return retval;
320 =item C<Parrot_Float Parrot_PMC_get_numval_intkey>
322 Return the keyed, signed integer value of the value in the PMC.
324 =cut
328 PARROT_API
329 Parrot_Float
330 Parrot_PMC_get_numval_intkey(PARROT_INTERP,
331 Parrot_PMC pmc, Parrot_Int key)
333 Parrot_Float retval;
334 PARROT_CALLIN_START(interp);
335 retval = VTABLE_get_number_keyed_int(interp, pmc, key);
336 PARROT_CALLIN_END(interp);
337 return retval;
342 =item C<char * Parrot_PMC_get_cstring_intkey>
344 Return a null-terminated string that represents the string value of the PMC.
346 Note that you must free this string with C<string_cstring_free()>!
348 =cut
352 PARROT_API
353 PARROT_MALLOC
354 PARROT_CAN_RETURN_NULL
355 char *
356 Parrot_PMC_get_cstring_intkey(PARROT_INTERP,
357 Parrot_PMC pmc, Parrot_Int key)
359 STRING *intermediate;
360 char *retval;
362 PARROT_CALLIN_START(interp);
363 intermediate = VTABLE_get_string_keyed_int(interp, pmc, key);
364 retval = string_to_cstring(interp, intermediate);
365 PARROT_CALLIN_END(interp);
367 return retval;
372 =item C<char * Parrot_PMC_get_cstring>
374 Return a null-terminated string that represents the string value of the PMC.
376 Note that you must free this string with C<string_cstring_free()>!
378 =cut
382 PARROT_API
383 PARROT_MALLOC
384 PARROT_CAN_RETURN_NULL
385 char *
386 Parrot_PMC_get_cstring(PARROT_INTERP, Parrot_PMC pmc)
388 STRING *intermediate;
389 char *retval;
391 PARROT_CALLIN_START(interp);
392 intermediate = VTABLE_get_string(interp, pmc);
393 retval = string_to_cstring(interp, intermediate);
394 PARROT_CALLIN_END(interp);
396 return retval;
401 =item C<char * Parrot_PMC_get_cstringn>
403 Return a null-terminated string for the PMC, along with the length.
405 Yes, right now this is a bit of a cheat. It needs fixing, but without
406 disturbing the interface.
408 Note that you must free the string with C<string_cstring_free()>.
410 =cut
414 PARROT_API
415 PARROT_MALLOC
416 PARROT_CAN_RETURN_NULL
417 char *
418 Parrot_PMC_get_cstringn(PARROT_INTERP, ARGIN(Parrot_PMC pmc),
419 ARGOUT(Parrot_Int *length))
421 char *retval;
423 PARROT_CALLIN_START(interp);
424 retval = string_to_cstring(interp, VTABLE_get_string(interp, pmc));
425 *length = strlen(retval);
426 PARROT_CALLIN_END(interp);
428 return retval;
433 =item C<char * Parrot_PMC_get_cstringn_intkey>
435 Return a null-terminated string for the PMC, along with the length.
437 Yes, right now this is a bit of a cheat. It needs fixing, but without
438 disturbing the interface.
440 Note that you must free this string with C<string_cstring_free()>.
442 =cut
446 PARROT_API
447 PARROT_MALLOC
448 PARROT_CAN_RETURN_NULL
449 char *
450 Parrot_PMC_get_cstringn_intkey(PARROT_INTERP, ARGIN(Parrot_PMC pmc),
451 ARGOUT(Parrot_Int *length), Parrot_Int key)
453 char *retval;
455 PARROT_CALLIN_START(interp);
456 retval = string_to_cstring(interp,
457 VTABLE_get_string_keyed_int(interp, pmc, key));
458 *length = strlen(retval);
459 PARROT_CALLIN_END(interp);
461 return retval;
466 =item C<void Parrot_PMC_set_string>
468 Assign the passed-in Parrot string to the passed-in PMC.
470 =cut
474 PARROT_API
475 void
476 Parrot_PMC_set_string(PARROT_INTERP,
477 Parrot_PMC pmc, Parrot_String value)
479 PARROT_CALLIN_START(interp);
480 VTABLE_set_string_native(interp, pmc, value);
481 PARROT_CALLIN_END(interp);
486 =item C<void Parrot_PMC_set_string_intkey>
488 Assign the passed-in Parrot string to the passed-in PMC.
490 =cut
494 PARROT_API
495 void
496 Parrot_PMC_set_string_intkey(PARROT_INTERP,
497 Parrot_PMC pmc, Parrot_Int key, Parrot_String value)
499 PARROT_CALLIN_START(interp);
500 VTABLE_set_string_keyed_int(interp, pmc, key, value);
501 PARROT_CALLIN_END(interp);
506 =item C<void Parrot_PMC_set_pmc_intkey>
508 Assign the passed-in pmc to the passed-in slot of the passed-in PMC.
510 =cut
514 PARROT_API
515 void
516 Parrot_PMC_set_pmc_intkey(PARROT_INTERP,
517 Parrot_PMC pmc, Parrot_Int key, Parrot_PMC value)
519 PARROT_CALLIN_START(interp);
520 VTABLE_set_pmc_keyed_int(interp, pmc, key, value);
521 PARROT_CALLIN_END(interp);
526 =item C<void Parrot_PMC_set_pmc_pmckey>
528 Assign the passed-in pmc to the passed-in slot of the passed-in PMC.
530 =cut
534 PARROT_API
535 void
536 Parrot_PMC_set_pmc_pmckey(PARROT_INTERP,
537 Parrot_PMC pmc, Parrot_PMC key, Parrot_PMC value)
539 PARROT_CALLIN_START(interp);
540 VTABLE_set_pmc_keyed(interp, pmc, key, value);
541 PARROT_CALLIN_END(interp);
546 =item C<void Parrot_PMC_set_pointer_intkey>
548 Assign the passed-in pointer to the passed-in PMC.
550 =cut
554 PARROT_API
555 void
556 Parrot_PMC_set_pointer_intkey(PARROT_INTERP,
557 ARGIN(Parrot_PMC pmc), Parrot_Int key, ARGIN_NULLOK(void *value))
559 PARROT_CALLIN_START(interp);
560 VTABLE_set_pointer_keyed_int(interp, pmc, key, value);
561 PARROT_CALLIN_END(interp);
566 =item C<void Parrot_PMC_set_intval>
568 Assign the passed-in Parrot integer to the passed-in PMC.
570 =cut
574 PARROT_API
575 void
576 Parrot_PMC_set_intval(PARROT_INTERP, Parrot_PMC pmc, Parrot_Int value)
578 PARROT_CALLIN_START(interp);
579 VTABLE_set_integer_native(interp, pmc, value);
580 PARROT_CALLIN_END(interp);
585 =item C<void Parrot_PMC_set_intval_intkey>
587 Assign the passed-in Parrot integer to the passed-in PMC.
589 =cut
593 PARROT_API
594 void
595 Parrot_PMC_set_intval_intkey(PARROT_INTERP,
596 Parrot_PMC pmc, Parrot_Int key, Parrot_Int value)
598 PARROT_CALLIN_START(interp);
599 VTABLE_set_integer_keyed_int(interp, pmc, key, value);
600 PARROT_CALLIN_END(interp);
605 =item C<void Parrot_PMC_set_numval>
607 Assign the passed-in Parrot number to the passed-in PMC.
609 =cut
613 PARROT_API
614 void
615 Parrot_PMC_set_numval(PARROT_INTERP, Parrot_PMC pmc, Parrot_Float value)
617 PARROT_CALLIN_START(interp);
618 VTABLE_set_number_native(interp, pmc, value);
619 PARROT_CALLIN_END(interp);
624 =item C<void Parrot_PMC_set_numval_intkey>
626 Assign the passed-in Parrot number to the passed-in PMC.
628 =cut
632 PARROT_API
633 void
634 Parrot_PMC_set_numval_intkey(PARROT_INTERP,
635 Parrot_PMC pmc, Parrot_Int key, Parrot_Float value)
637 PARROT_CALLIN_START(interp);
638 VTABLE_set_number_keyed_int(interp, pmc, key, value);
639 PARROT_CALLIN_END(interp);
644 =item C<void Parrot_PMC_set_cstring>
646 Assign the passed-in null-terminated C string to the passed-in PMC.
648 =cut
652 PARROT_API
653 void
654 Parrot_PMC_set_cstring(PARROT_INTERP, Parrot_PMC pmc, ARGIN_NULLOK(const char *value))
656 PARROT_CALLIN_START(interp);
657 VTABLE_set_string_native(interp, pmc,
658 string_from_cstring(interp, value, 0));
659 PARROT_CALLIN_END(interp);
664 =item C<void Parrot_PMC_set_cstring_intkey>
666 Assign the passed-in null-terminated C string to the passed-in PMC.
668 =cut
672 PARROT_API
673 void
674 Parrot_PMC_set_cstring_intkey(PARROT_INTERP,
675 Parrot_PMC pmc, Parrot_Int key, ARGIN_NULLOK(const char *value))
677 PARROT_CALLIN_START(interp);
678 VTABLE_set_string_keyed_int(interp, pmc, key,
679 string_from_cstring(interp, value, 0));
680 PARROT_CALLIN_END(interp);
685 =item C<void Parrot_PMC_set_cstringn>
687 Assign the passed-in length-noted string to the passed-in PMC.
689 =cut
693 PARROT_API
694 void
695 Parrot_PMC_set_cstringn(PARROT_INTERP,
696 Parrot_PMC pmc, ARGIN_NULLOK(const char *value), Parrot_Int length)
698 PARROT_CALLIN_START(interp);
699 VTABLE_set_string_native(interp, pmc,
700 string_from_cstring(interp, value, length));
701 PARROT_CALLIN_END(interp);
706 =item C<void Parrot_PMC_push_intval>
708 Push the passed-in Parrot integer onto the passed in PMC
710 =cut
714 PARROT_API
715 void
716 Parrot_PMC_push_intval(PARROT_INTERP,
717 Parrot_PMC pmc, Parrot_Int value)
719 PARROT_CALLIN_START(interp);
720 VTABLE_push_integer(interp, pmc, value);
721 PARROT_CALLIN_END(interp);
726 =item C<void Parrot_PMC_push_numval>
728 Push the passed-in Parrot number onto the passed in PMC
730 =cut
734 PARROT_API
735 void
736 Parrot_PMC_push_numval(PARROT_INTERP, Parrot_PMC pmc, Parrot_Float value)
738 PARROT_CALLIN_START(interp);
739 VTABLE_push_float(interp, pmc, value);
740 PARROT_CALLIN_END(interp);
745 =item C<void Parrot_PMC_delete_pmckey>
747 Deletes the value associated with the passed-in PMC from the PMC.
749 =cut
753 PARROT_API
754 void
755 Parrot_PMC_delete_pmckey(PARROT_INTERP, Parrot_PMC pmc, Parrot_PMC key)
757 PARROT_CALLIN_START(interp);
758 VTABLE_delete_keyed(interp, pmc, key);
759 PARROT_CALLIN_END(interp);
764 =item C<void Parrot_PMC_set_cstringn_intkey>
766 Assign the passed-in length-noted string to the passed-in PMC.
768 =cut
772 PARROT_API
773 void
774 Parrot_PMC_set_cstringn_intkey(PARROT_INTERP,
775 Parrot_PMC pmc, Parrot_Int key, ARGIN_NULLOK(const char *value), Parrot_Int length)
777 PARROT_CALLIN_START(interp);
778 VTABLE_set_string_keyed_int(interp, pmc, key,
779 string_from_cstring(interp, value, length));
780 PARROT_CALLIN_END(interp);
785 =item C<Parrot_PMC Parrot_PMC_new>
787 Create and return a new PMC.
789 =cut
793 PARROT_API
794 Parrot_PMC
795 Parrot_PMC_new(PARROT_INTERP, Parrot_Int type)
797 Parrot_PMC newpmc;
798 PARROT_CALLIN_START(interp);
799 newpmc = pmc_new_noinit(interp, type);
800 VTABLE_init(interp, newpmc);
801 PARROT_CALLIN_END(interp);
802 return newpmc;
807 =item C<Parrot_Int Parrot_PMC_typenum>
809 Returns the internal identifier that represents the named class.
811 =cut
815 PARROT_API
816 Parrot_Int
817 Parrot_PMC_typenum(PARROT_INTERP, ARGIN_NULLOK(const char *_class))
819 Parrot_Int retval;
820 PARROT_CALLIN_START(interp);
821 retval = pmc_type(interp, string_from_cstring(interp, _class, 0));
822 PARROT_CALLIN_END(interp);
823 return retval;
828 =item C<Parrot_PMC Parrot_PMC_null>
830 Returns the special C<NULL> PMC.
832 =cut
836 PARROT_API
837 Parrot_PMC
838 Parrot_PMC_null(void)
840 return PMCNULL;
845 =item C<void Parrot_free_cstring>
847 Deallocate a C string that the interpreter has handed to you.
849 =cut
853 PARROT_API
854 void
855 Parrot_free_cstring(ARGIN_NULLOK(char *string))
857 string_cstring_free(string);
862 =item C<void* Parrot_call_sub>
864 Call a parrot subroutine with the given function signature. The first char in
865 C<signature> denotes the return value. Next chars are arguments.
867 The return value of this function can be void or a pointer type.
869 Signature chars are:
871 v ... void return
872 I ... Parrot_Int
873 N ... Parrot_Float
874 S ... Parrot_String
875 P ... Parrot_PMC
877 =cut
881 PARROT_API
882 PARROT_WARN_UNUSED_RESULT
883 PARROT_CAN_RETURN_NULL
884 void*
885 Parrot_call_sub(PARROT_INTERP, Parrot_PMC sub,
886 ARGIN(const char *signature), ...)
888 va_list ap;
889 void *result;
891 PARROT_CALLIN_START(interp);
893 va_start(ap, signature);
894 CONTEXT(interp)->constants =
895 PMC_sub(sub)->seg->const_table->constants;
896 result = Parrot_runops_fromc_arglist(interp, sub, signature, ap);
897 va_end(ap);
899 PARROT_CALLIN_END(interp);
900 return result;
905 =item C<Parrot_Int Parrot_call_sub_ret_int>
907 Like C<Parrot_call_sub>, with Parrot_Int return result.
909 =cut
913 PARROT_API
914 Parrot_Int
915 Parrot_call_sub_ret_int(PARROT_INTERP, Parrot_PMC sub,
916 ARGIN(const char *signature), ...)
918 va_list ap;
919 Parrot_Int result;
921 PARROT_CALLIN_START(interp);
923 va_start(ap, signature);
924 CONTEXT(interp)->constants =
925 PMC_sub(sub)->seg->const_table->constants;
926 result = Parrot_runops_fromc_arglist_reti(interp, sub, signature, ap);
927 va_end(ap);
929 PARROT_CALLIN_END(interp);
930 return result;
935 =item C<Parrot_Float Parrot_call_sub_ret_float>
937 Like C<Parrot_call_sub>, with Parrot_Float return result.
939 =cut
943 PARROT_API
944 Parrot_Float
945 Parrot_call_sub_ret_float(PARROT_INTERP, Parrot_PMC sub,
946 ARGIN(const char *signature), ...)
948 va_list ap;
949 Parrot_Float result;
951 PARROT_CALLIN_START(interp);
953 va_start(ap, signature);
954 CONTEXT(interp)->constants =
955 PMC_sub(sub)->seg->const_table->constants;
956 result = Parrot_runops_fromc_arglist_retf(interp, sub, signature, ap);
957 va_end(ap);
959 PARROT_CALLIN_END(interp);
960 return result;
965 =item C<void * Parrot_call_method>
967 Call a parrot method for the given object.
969 =cut
973 PARROT_API
974 PARROT_WARN_UNUSED_RESULT
975 PARROT_CAN_RETURN_NULL
976 void *
977 Parrot_call_method(PARROT_INTERP, Parrot_PMC sub, Parrot_PMC obj,
978 Parrot_String method, ARGIN(const char *signature), ...)
980 void *result;
981 va_list ap;
983 PARROT_CALLIN_START(interp);
984 va_start(ap, signature);
985 result = Parrot_run_meth_fromc_arglist(interp, sub,
986 obj, method, signature, ap);
987 va_end(ap);
988 PARROT_CALLIN_END(interp);
989 return result;
994 =item C<Parrot_Int Parrot_call_method_ret_int>
996 Call a parrot method for the given object.
998 =cut
1002 PARROT_API
1003 Parrot_Int
1004 Parrot_call_method_ret_int(PARROT_INTERP, Parrot_PMC sub,
1005 Parrot_PMC obj, Parrot_String method, ARGIN(const char *signature), ...)
1007 Parrot_Int result;
1008 va_list ap;
1010 PARROT_CALLIN_START(interp);
1011 va_start(ap, signature);
1012 result = Parrot_run_meth_fromc_arglist_reti(interp, sub,
1013 obj, method, signature, ap);
1014 va_end(ap);
1015 PARROT_CALLIN_END(interp);
1016 return result;
1021 =item C<Parrot_Float Parrot_call_method_ret_float>
1023 Call a parrot method for the given object.
1025 =cut
1029 PARROT_API
1030 Parrot_Float
1031 Parrot_call_method_ret_float(PARROT_INTERP, Parrot_PMC sub,
1032 Parrot_PMC obj, Parrot_String method, ARGIN(const char *signature), ...)
1034 Parrot_Float result;
1035 va_list ap;
1037 PARROT_CALLIN_START(interp);
1038 va_start(ap, signature);
1039 result = Parrot_run_meth_fromc_arglist_retf(interp, sub,
1040 obj, method, signature, ap);
1041 va_end(ap);
1042 PARROT_CALLIN_END(interp);
1043 return result;
1048 =item C<Parrot_Int Parrot_get_intreg>
1050 Return the value of an integer register.
1052 =cut
1056 PARROT_API
1057 Parrot_Int
1058 Parrot_get_intreg(PARROT_INTERP, Parrot_Int regnum)
1060 return REG_INT(interp, regnum);
1065 =item C<Parrot_Float Parrot_get_numreg>
1067 Return the value of a numeric register.
1069 =cut
1073 PARROT_API
1074 Parrot_Float
1075 Parrot_get_numreg(PARROT_INTERP, Parrot_Int regnum)
1077 return REG_NUM(interp, regnum);
1082 =item C<Parrot_String Parrot_get_strreg>
1084 Return the value of a string register.
1086 =cut
1090 PARROT_API
1091 Parrot_String
1092 Parrot_get_strreg(PARROT_INTERP, Parrot_Int regnum)
1094 return REG_STR(interp, regnum);
1099 =item C<Parrot_PMC Parrot_get_pmcreg>
1101 Return the value of a PMC register.
1103 =cut
1107 PARROT_API
1108 Parrot_PMC
1109 Parrot_get_pmcreg(PARROT_INTERP, Parrot_Int regnum)
1111 return REG_PMC(interp, regnum);
1116 =item C<void Parrot_set_intreg>
1118 Set the value of an I register.
1120 =cut
1124 PARROT_API
1125 void
1126 Parrot_set_intreg(PARROT_INTERP, Parrot_Int regnum,
1127 Parrot_Int value)
1129 REG_INT(interp, regnum) = value;
1134 =item C<void Parrot_set_numreg>
1136 Set the value of an N register.
1138 =cut
1142 PARROT_API
1143 void
1144 Parrot_set_numreg(PARROT_INTERP, Parrot_Int regnum,
1145 Parrot_Float value)
1147 REG_NUM(interp, regnum) = value;
1152 =item C<void Parrot_set_strreg>
1154 Set the value of an S register.
1158 PARROT_API
1159 void
1160 Parrot_set_strreg(PARROT_INTERP, Parrot_Int regnum,
1161 Parrot_String value)
1163 REG_STR(interp, regnum) = value;
1168 =item C<void Parrot_set_pmcreg>
1170 Set the value of a P register.
1172 =cut
1176 PARROT_API
1177 void
1178 Parrot_set_pmcreg(PARROT_INTERP, Parrot_Int regnum,
1179 Parrot_PMC value)
1181 REG_PMC(interp, regnum) = value;
1184 /*=for api extend Parrot_new_string
1189 =item C<Parrot_String Parrot_new_string>
1191 Create a new Parrot string from a passed-in buffer. Pass in a 0 for
1192 flags for right now.
1194 A copy of the buffer is made.
1196 =cut
1200 PARROT_API
1201 PARROT_WARN_UNUSED_RESULT
1202 PARROT_CANNOT_RETURN_NULL
1203 Parrot_String
1204 Parrot_new_string(PARROT_INTERP, ARGIN_NULLOK(const char *buffer), int length,
1205 ARGIN_NULLOK(const char * const encoding_name), Parrot_Int flags)
1207 Parrot_String retval;
1208 PARROT_CALLIN_START(interp);
1209 retval = string_make(interp, buffer, length, encoding_name, flags);
1210 PARROT_CALLIN_END(interp);
1211 return retval;
1216 =item C<Parrot_Language Parrot_find_language>
1218 Find the magic language token for a language, by language name.
1220 =cut
1224 PARROT_API
1225 PARROT_WARN_UNUSED_RESULT
1226 Parrot_Language
1227 Parrot_find_language(SHIM_INTERP, SHIM(char *language))
1229 return 0;
1234 =item C<void Parrot_register_pmc>
1236 Add a reference of the PMC to the interpreters DOD registry. This
1237 prevents PMCs only known to extension from getting destroyed during DOD
1238 runs.
1240 =cut
1244 PARROT_API
1245 void
1246 Parrot_register_pmc(PARROT_INTERP, Parrot_PMC pmc)
1248 PARROT_CALLIN_START(interp);
1249 dod_register_pmc(interp, pmc);
1250 PARROT_CALLIN_END(interp);
1255 =item C<void Parrot_unregister_pmc>
1257 Remove a reference of the PMC from the interpreters DOD registry. If the
1258 reference count reaches zero, the PMC will be destroyed during the next
1259 DOD run.
1261 =cut
1265 PARROT_API
1266 void
1267 Parrot_unregister_pmc(PARROT_INTERP, Parrot_PMC pmc)
1269 PARROT_CALLIN_START(interp);
1270 dod_unregister_pmc(interp, pmc);
1271 PARROT_CALLIN_END(interp);
1276 =item C<void Parrot_PMC_set_vtable>
1278 Replaces the vtable of the PMC.
1280 =cut
1284 PARROT_API
1285 void
1286 Parrot_PMC_set_vtable(SHIM_INTERP, Parrot_PMC pmc, Parrot_VTABLE vtable)
1288 pmc->vtable = vtable;
1293 =item C<Parrot_VTABLE Parrot_get_vtable>
1295 Returns the vtable corresponding to the given PMC ID.
1297 =cut
1301 PARROT_API
1302 PARROT_PURE_FUNCTION
1303 Parrot_VTABLE
1304 Parrot_get_vtable(PARROT_INTERP, Parrot_Int id)
1306 return interp->vtables[id];
1311 =back
1313 =head1 SEE ALSO
1315 See F<include/parrot/extend.h> and F<docs/pdds/pdd11_extending.pod>.
1317 =head1 HISTORY
1319 Initial version by Dan Sugalski.
1321 =cut
1327 * Local variables:
1328 * c-file-style: "parrot"
1329 * End:
1330 * vim: expandtab shiftwidth=4: