* t/configure/25-options_test.t:
[parrot.git] / src / extend.c
blobe07165a3769ea82e95b6a00adf5fe45a4f72bdf4
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"
66 =item C<Parrot_String
67 Parrot_PMC_get_string_intkey(Parrot_Interp interp, Parrot_PMC pmc,
68 Parrot_Int key)>
70 Return the integer keyed string value of the passed-in PMC
72 =cut
76 PARROT_API Parrot_String
77 Parrot_PMC_get_string_intkey(Parrot_Interp interp,
78 Parrot_PMC pmc, Parrot_Int key) {
79 Parrot_String retval;
80 PARROT_CALLIN_START(interp);
81 retval = VTABLE_get_string_keyed_int(interp, pmc, key);
82 PARROT_CALLIN_END(interp);
83 return retval;
89 =item C<void *
90 Parrot_PMC_get_pointer_intkey(Parrot_Interp interp, Parrot_PMC pmc,
91 Parrot_Int key)>
93 Return the keyed, signed integer value of the value in the PMC.
95 =cut
99 PARROT_API void *
100 Parrot_PMC_get_pointer_intkey(Parrot_Interp interp, Parrot_PMC pmc,
101 Parrot_Int key) {
102 void *retval;
103 PARROT_CALLIN_START(interp);
104 retval = VTABLE_get_pointer_keyed_int(interp, pmc, key);
105 PARROT_CALLIN_END(interp);
106 return retval;
111 =item C<Parrot_PMC
112 Parrot_PMC_get_pmc_intkey(Parrot_Interp interp, Parrot_PMC pmc, Parrot_Int key)>
114 Return the integer keyed PMC value of the passed-in PMC
116 =cut
120 PARROT_API Parrot_PMC
121 Parrot_PMC_get_pmc_intkey(Parrot_Interp interp, Parrot_PMC pmc,
122 Parrot_Int key) {
123 Parrot_PMC retval;
124 PARROT_CALLIN_START(interp);
125 retval = VTABLE_get_pmc_keyed_int(interp, pmc, key);
126 PARROT_CALLIN_END(interp);
127 return retval;
132 =item C<Parrot_Int
133 Parrot_PMC_get_intval(Parrot_Interp interp, Parrot_PMC pmc)>
135 Return the signed integer value of the value in the PMC.
137 =cut
141 PARROT_API Parrot_Int
142 Parrot_PMC_get_intval(Parrot_Interp interp, Parrot_PMC pmc) {
143 Parrot_Int retval;
144 PARROT_CALLIN_START(interp);
145 retval = VTABLE_get_integer(interp, pmc);
146 PARROT_CALLIN_END(interp);
147 return retval;
152 =item C<Parrot_Int
153 Parrot_PMC_get_intval_intkey(Parrot_Interp interp, Parrot_PMC pmc,
154 Parrot_Int key)>
156 Return the keyed, signed integer value of the value in the PMC.
158 =cut
162 PARROT_API Parrot_Int
163 Parrot_PMC_get_intval_intkey(Parrot_Interp interp, Parrot_PMC pmc,
164 Parrot_Int key) {
165 Parrot_Int retval;
166 PARROT_CALLIN_START(interp);
167 retval = VTABLE_get_integer_keyed_int(interp, pmc, key);
168 PARROT_CALLIN_END(interp);
169 return retval;
174 =item C<Parrot_Int
175 Parrot_PMC_get_intval_pmckey(Parrot_Interp interp, Parrot_PMC pmc,
176 Parrot_PMC key)>
178 Return the keyed, signed integer value of the value in the PMC.
180 =cut
184 PARROT_API Parrot_Int
185 Parrot_PMC_get_intval_pmckey(Parrot_Interp interp, Parrot_PMC pmc,
186 Parrot_PMC key) {
187 Parrot_Int retval;
188 PARROT_CALLIN_START(interp);
189 retval = VTABLE_get_integer_keyed(interp, pmc, key);
190 PARROT_CALLIN_END(interp);
191 return retval;
196 =item C<Parrot_Float
197 Parrot_PMC_get_numval(Parrot_Interp interp, Parrot_PMC pmc)>
199 Return the floating-point value of the PMC.
201 =cut
205 PARROT_API Parrot_Float
206 Parrot_PMC_get_numval(Parrot_Interp interp, Parrot_PMC pmc) {
207 Parrot_Float retval;
208 PARROT_CALLIN_START(interp);
209 retval = VTABLE_get_number(interp, pmc);
210 PARROT_CALLIN_END(interp);
211 return retval;
216 =item C<Parrot_Float
217 Parrot_PMC_get_numval_intkey(Parrot_Interp interp, Parrot_PMC pmc,
218 Parrot_Int key)>
220 Return the keyed, signed integer value of the value in the PMC.
222 =cut
226 PARROT_API Parrot_Float
227 Parrot_PMC_get_numval_intkey(Parrot_Interp interp, Parrot_PMC pmc,
228 Parrot_Int key) {
229 Parrot_Float retval;
230 PARROT_CALLIN_START(interp);
231 retval = VTABLE_get_number_keyed_int(interp, pmc, key);
232 PARROT_CALLIN_END(interp);
233 return retval;
238 =item C<char *
239 Parrot_PMC_get_cstring_intkey(Parrot_Interp interp, Parrot_PMC pmc,
240 Parrot_Int key)>
242 Return a null-terminated string that represents the string value of the PMC.
244 Note that you must free this string with C<string_cstring_free()>!
246 =cut
250 PARROT_API char *
251 Parrot_PMC_get_cstring_intkey(Parrot_Interp interp, Parrot_PMC pmc,
252 Parrot_Int key) {
253 STRING *intermediate;
254 char *retval;
256 PARROT_CALLIN_START(interp);
257 intermediate = VTABLE_get_string_keyed_int(interp, pmc, key);
258 retval = string_to_cstring(interp, intermediate);
259 PARROT_CALLIN_END(interp);
261 return retval;
266 =item C<char *Parrot_PMC_get_cstring(Parrot_Interp interp, Parrot_PMC pmc)>
268 Return a null-terminated string that represents the string value of the PMC.
270 Note that you must free this string with C<string_cstring_free()>!
272 =cut
276 PARROT_API char *
277 Parrot_PMC_get_cstring(Parrot_Interp interp, Parrot_PMC pmc) {
278 STRING *intermediate;
279 char *retval;
281 PARROT_CALLIN_START(interp);
282 intermediate = VTABLE_get_string(interp, pmc);
283 retval = string_to_cstring(interp, intermediate);
284 PARROT_CALLIN_END(interp);
286 return retval;
291 =item C<char *
292 Parrot_PMC_get_cstringn(Parrot_Interp interp, Parrot_PMC pmc,
293 Parrot_Int *length)>
295 Return a null-terminated string for the PMC, along with the length.
297 Yes, right now this is a bit of a cheat. It needs fixing, but without
298 disturbing the interface.
300 Note that you must free the string with C<string_cstring_free()>.
302 =cut
306 PARROT_API char *
307 Parrot_PMC_get_cstringn(Parrot_Interp interp, Parrot_PMC pmc,
308 Parrot_Int *length) {
309 char *retval;
311 PARROT_CALLIN_START(interp);
312 retval = string_to_cstring(interp, VTABLE_get_string(interp, pmc));
313 *length = strlen(retval);
314 PARROT_CALLIN_END(interp);
316 return retval;
321 =item C<char *
322 Parrot_PMC_get_cstringn_intkey(Parrot_Interp interp, Parrot_PMC pmc,
323 Parrot_Int *length, Parrot_Int key)>
325 Return a null-terminated string for the PMC, along with the length.
327 Yes, right now this is a bit of a cheat. It needs fixing, but without
328 disturbing the interface.
330 Note that you must free this string with C<string_cstring_free()>.
332 =cut
336 PARROT_API char *
337 Parrot_PMC_get_cstringn_intkey(Parrot_Interp interp, Parrot_PMC pmc,
338 Parrot_Int *length, Parrot_Int key) {
339 char *retval;
341 PARROT_CALLIN_START(interp);
342 retval = string_to_cstring(interp,
343 VTABLE_get_string_keyed_int(interp, pmc, key));
344 *length = strlen(retval);
345 PARROT_CALLIN_END(interp);
347 return retval;
352 =item C<void
353 Parrot_PMC_set_string(Parrot_Interp interp, Parrot_PMC pmc,
354 Parrot_String value)>
356 Assign the passed-in Parrot string to the passed-in PMC.
358 =cut
362 PARROT_API void
363 Parrot_PMC_set_string(Parrot_Interp interp, Parrot_PMC pmc,
364 Parrot_String value) {
365 PARROT_CALLIN_START(interp);
366 VTABLE_set_string_native(interp, pmc, value);
367 PARROT_CALLIN_END(interp);
372 =item C<void
373 Parrot_PMC_set_string_intkey(Parrot_Interp interp, Parrot_PMC pmc,
374 Parrot_Int key, Parrot_String value)>
376 Assign the passed-in Parrot string to the passed-in PMC.
378 =cut
382 PARROT_API void
383 Parrot_PMC_set_string_intkey(Parrot_Interp interp, Parrot_PMC pmc,
384 Parrot_Int key, Parrot_String value)
386 PARROT_CALLIN_START(interp);
387 VTABLE_set_string_keyed_int(interp, pmc, key, value);
388 PARROT_CALLIN_END(interp);
393 =item C<void
394 Parrot_PMC_set_pmc_intkey(Parrot_Interp interp, Parrot_PMC pmc,
395 Parrot_Int key, Parrot_PMC value)>
397 Assign the passed-in pmc to the passed-in slot of the passed-in PMC.
399 =cut
403 PARROT_API void
404 Parrot_PMC_set_pmc_intkey(Parrot_Interp interp, Parrot_PMC pmc,
405 Parrot_Int key, Parrot_PMC value) {
406 PARROT_CALLIN_START(interp);
407 VTABLE_set_pmc_keyed_int(interp, pmc, key, value);
408 PARROT_CALLIN_END(interp);
413 =item C<void
414 Parrot_PMC_set_pmc_pmckey(Parrot_Interp interp, Parrot_PMC pmc,
415 Parrot_PMC key, Parrot_PMC value)>
417 Assign the passed-in pmc to the passed-in slot of the passed-in PMC.
419 =cut
423 PARROT_API void
424 Parrot_PMC_set_pmc_pmckey(Parrot_Interp interp, Parrot_PMC pmc,
425 Parrot_PMC key, Parrot_PMC value) {
426 PARROT_CALLIN_START(interp);
427 VTABLE_set_pmc_keyed(interp, pmc, key, value);
428 PARROT_CALLIN_END(interp);
433 =item C<void
434 Parrot_PMC_set_pointer_intkey(Parrot_Interp interp, Parrot_PMC pmc,
435 Parrot_Int key, void *value)>
437 Assign the passed-in pointer to the passed-in PMC.
439 =cut
443 PARROT_API void
444 Parrot_PMC_set_pointer_intkey(Parrot_Interp interp, Parrot_PMC pmc,
445 Parrot_Int key, void *value) {
446 PARROT_CALLIN_START(interp);
447 VTABLE_set_pointer_keyed_int(interp, pmc, key, value);
448 PARROT_CALLIN_END(interp);
453 =item C<void
454 Parrot_PMC_set_intval(Parrot_Interp interp, Parrot_PMC pmc, Parrot_Int value)>
456 Assign the passed-in Parrot integer to the passed-in PMC.
458 =cut
462 PARROT_API void
463 Parrot_PMC_set_intval(Parrot_Interp interp, Parrot_PMC pmc, Parrot_Int value) {
464 PARROT_CALLIN_START(interp);
465 VTABLE_set_integer_native(interp, pmc, value);
466 PARROT_CALLIN_END(interp);
471 =item C<void
472 Parrot_PMC_set_intval_intkey(Parrot_Interp interp, Parrot_PMC pmc,
473 Parrot_Int key, Parrot_Int value)>
475 Assign the passed-in Parrot integer to the passed-in PMC.
477 =cut
481 PARROT_API void
482 Parrot_PMC_set_intval_intkey(Parrot_Interp interp, Parrot_PMC pmc,
483 Parrot_Int key, Parrot_Int value) {
484 PARROT_CALLIN_START(interp);
485 VTABLE_set_integer_keyed_int(interp, pmc, key, value);
486 PARROT_CALLIN_END(interp);
491 =item C<void
492 Parrot_PMC_set_numval(Parrot_Interp interp, Parrot_PMC pmc, Parrot_Float value)>
494 Assign the passed-in Parrot number to the passed-in PMC.
496 =cut
500 PARROT_API void
501 Parrot_PMC_set_numval(Parrot_Interp interp, Parrot_PMC pmc, Parrot_Float value){
502 PARROT_CALLIN_START(interp);
503 VTABLE_set_number_native(interp, pmc, value);
504 PARROT_CALLIN_END(interp);
509 =item C<void
510 Parrot_PMC_set_numval_intkey(Parrot_Interp interp, Parrot_PMC pmc,
511 Parrot_Int key, Parrot_Float value)>
513 Assign the passed-in Parrot number to the passed-in PMC.
515 =cut
519 PARROT_API void
520 Parrot_PMC_set_numval_intkey(Parrot_Interp interp, Parrot_PMC pmc,
521 Parrot_Int key, Parrot_Float value) {
522 PARROT_CALLIN_START(interp);
523 VTABLE_set_number_keyed_int(interp, pmc, key, value);
524 PARROT_CALLIN_END(interp);
529 =item C<void
530 Parrot_PMC_set_cstring(Parrot_Interp interp, Parrot_PMC pmc, const char *value)>
532 Assign the passed-in null-terminated C string to the passed-in PMC.
534 =cut
538 PARROT_API void
539 Parrot_PMC_set_cstring(Parrot_Interp interp, Parrot_PMC pmc, const char *value){
540 PARROT_CALLIN_START(interp);
541 VTABLE_set_string_native(interp, pmc,
542 string_from_cstring(interp, value, 0));
543 PARROT_CALLIN_END(interp);
548 =item C<void
549 Parrot_PMC_set_cstring_intkey(Parrot_Interp interp, Parrot_PMC pmc,
550 Parrot_Int key, const char *value)>
552 Assign the passed-in null-terminated C string to the passed-in PMC.
554 =cut
558 PARROT_API void
559 Parrot_PMC_set_cstring_intkey(Parrot_Interp interp, Parrot_PMC pmc,
560 Parrot_Int key, const char *value) {
561 PARROT_CALLIN_START(interp);
562 VTABLE_set_string_keyed_int(interp, pmc, key,
563 string_from_cstring(interp, value, 0));
564 PARROT_CALLIN_END(interp);
569 =item C<void
570 Parrot_PMC_set_cstringn(Parrot_Interp interp, Parrot_PMC pmc,
571 const char *value, Parrot_Int length)>
573 Assign the passed-in length-noted string to the passed-in PMC.
575 =cut
579 PARROT_API void
580 Parrot_PMC_set_cstringn(Parrot_Interp interp, Parrot_PMC pmc,
581 const char *value, Parrot_Int length) {
582 PARROT_CALLIN_START(interp);
583 VTABLE_set_string_native(interp, pmc,
584 string_from_cstring(interp, value, length));
585 PARROT_CALLIN_END(interp);
590 =item C<void
591 Parrot_PMC_push_intval(Parrot_Interp interp, Parrot_PMC pmc,
592 Parrot_Int value)>
594 Push the passed-in Parrot integer onto the passed in PMC
596 =cut
600 PARROT_API void
601 Parrot_PMC_push_intval(Parrot_Interp interp, Parrot_PMC pmc,
602 Parrot_Int value) {
603 PARROT_CALLIN_START(interp);
604 VTABLE_push_integer(interp, pmc, value);
605 PARROT_CALLIN_END(interp);
610 =item C<void
611 Parrot_PMC_push_numval(Parrot_Interp interp, Parrot_PMC pmc,
612 Parrot_Float value)>
614 Push the passed-in Parrot number onto the passed in PMC
616 =cut
620 PARROT_API void
621 Parrot_PMC_push_numval(Parrot_Interp interp, Parrot_PMC pmc,
622 Parrot_Float value) {
623 PARROT_CALLIN_START(interp);
624 VTABLE_push_float(interp, pmc, value);
625 PARROT_CALLIN_END(interp);
630 =item C<void
631 Parrot_PMC_delete_pmckey(Parrot_Interp interp, Parrot_PMC pmc,
632 Parrot_PMC key)>
634 Deletes the value associated with the passed-in PMC from the PMC.
636 =cut
640 PARROT_API void
641 Parrot_PMC_delete_pmckey(Parrot_Interp interp, Parrot_PMC pmc,
642 Parrot_PMC key) {
643 PARROT_CALLIN_START(interp);
644 VTABLE_delete_keyed(interp, pmc, key);
645 PARROT_CALLIN_END(interp);
650 =item C<void
651 Parrot_PMC_set_cstringn_intkey(Parrot_Interp interp, Parrot_PMC pmc,
652 Parrot_Int key,
653 const char *value, Parrot_Int length)>
655 Assign the passed-in length-noted string to the passed-in PMC.
657 =cut
661 PARROT_API void
662 Parrot_PMC_set_cstringn_intkey(Parrot_Interp interp, Parrot_PMC pmc,
663 Parrot_Int key,
664 const char *value, Parrot_Int length) {
665 PARROT_CALLIN_START(interp);
666 VTABLE_set_string_keyed_int(interp, pmc, key,
667 string_from_cstring(interp, value, length));
668 PARROT_CALLIN_END(interp);
673 =item C<Parrot_PMC Parrot_PMC_new(Parrot_Interp interp, Parrot_Int type)>
675 Create and return a new PMC.
677 =cut
681 PARROT_API Parrot_PMC
682 Parrot_PMC_new(Parrot_Interp interp, Parrot_Int type) {
683 Parrot_PMC newpmc;
684 PARROT_CALLIN_START(interp);
685 newpmc = pmc_new_noinit(interp, type);
686 VTABLE_init(interp, newpmc);
687 PARROT_CALLIN_END(interp);
688 return newpmc;
693 =item C<Parrot_Int Parrot_PMC_typenum(Parrot_Interp interp, const char *_class)>
695 Returns the internal identifier that represents the named class.
697 =cut
701 PARROT_API Parrot_Int
702 Parrot_PMC_typenum(Parrot_Interp interp, const char *_class) {
703 Parrot_Int retval;
704 PARROT_CALLIN_START(interp);
705 retval = pmc_type(interp, string_from_cstring(interp, _class, 0));
706 PARROT_CALLIN_END(interp);
707 return retval;
712 =item C<Parrot_PMC Parrot_PMC_null()>
714 Returns the special C<NULL> PMC.
716 =cut
720 PARROT_API Parrot_PMC
721 Parrot_PMC_null(void) {
722 return PMCNULL;
727 =item C<void Parrot_free_cstring(char *string)>
729 Deallocate a C string that the interpreter has handed to you.
731 =cut
735 PARROT_API void
736 Parrot_free_cstring(char *string) {
737 string_cstring_free(string);
742 =item C<void*
743 Parrot_call_sub(Parrot_Interp interp, Parrot_PMC sub,
744 const char *signature, ...)>
746 Call a parrot subroutine with the given function signature. The first char in
747 C<signature> denotes the return value. Next chars are arguments.
749 The return value of this function can be void or a pointer type.
751 Signature chars are:
753 v ... void return
754 I ... Parrot_Int
755 N ... Parrot_Float
756 S ... Parrot_String
757 P ... Parrot_PMC
759 =item C<Parrot_Int>
760 Parrot_call_sub_ret_int(Parrot_Interp interp, Parrot_PMC sub,
761 const char *signature, ...)>
763 =item C<Parrot_Float>
764 Parrot_call_sub_ret_float(Parrot_Interp interp, Parrot_PMC sub,
765 const char *signature, ...)>
767 Like above, with Parrot_Int or Parrot_Float return result.
769 =cut
773 PARROT_API void*
774 Parrot_call_sub(Parrot_Interp interp, Parrot_PMC sub,
775 const char *signature, ...)
777 va_list ap;
778 void *result;
780 PARROT_CALLIN_START(interp);
782 va_start(ap, signature);
783 CONTEXT(interp->ctx)->constants =
784 PMC_sub(sub)->seg->const_table->constants;
785 result = Parrot_runops_fromc_arglist(interp, sub, signature, ap);
786 va_end(ap);
788 PARROT_CALLIN_END(interp);
789 return result;
792 PARROT_API Parrot_Int
793 Parrot_call_sub_ret_int(Parrot_Interp interp, Parrot_PMC sub,
794 const char *signature, ...)
796 va_list ap;
797 Parrot_Int result;
799 PARROT_CALLIN_START(interp);
801 va_start(ap, signature);
802 CONTEXT(interp->ctx)->constants =
803 PMC_sub(sub)->seg->const_table->constants;
804 result = Parrot_runops_fromc_arglist_reti(interp, sub, signature, ap);
805 va_end(ap);
807 PARROT_CALLIN_END(interp);
808 return result;
811 PARROT_API Parrot_Float
812 Parrot_call_sub_ret_float(Parrot_Interp interp, Parrot_PMC sub,
813 const char *signature, ...)
815 va_list ap;
816 Parrot_Float result;
818 PARROT_CALLIN_START(interp);
820 va_start(ap, signature);
821 CONTEXT(interp->ctx)->constants =
822 PMC_sub(sub)->seg->const_table->constants;
823 result = Parrot_runops_fromc_arglist_retf(interp, sub, signature, ap);
824 va_end(ap);
826 PARROT_CALLIN_END(interp);
827 return result;
832 =item C<void* Parrot_call_method(Parrot_Interp interp, Parrot_PMC sub,
833 Parrot_PMC object, Parrot_String method, const char *signature, ...)>
835 =item C<Parrot_Int Parrot_call_method_ret_int(Parrot_Interp interp,
836 Parrot_PMC sub, Parrot_PMC object, Parrot_String method,
837 const char *signature, ...)>
839 =item C<Parrot_Float Parrot_call_method_ret_float(Parrot_Interp interp,
840 Parrot_PMC sub, Parrot_PMC object, Parrot_String method,
841 const char *signature, ...)>
843 Call a parrot method for the given object.
845 =cut
849 PARROT_API void *
850 Parrot_call_method(Parrot_Interp interp, Parrot_PMC sub, Parrot_PMC obj,
851 Parrot_String method, const char *signature, ...)
853 void *result;
854 va_list ap;
856 PARROT_CALLIN_START(interp);
857 va_start(ap, signature);
858 result = Parrot_run_meth_fromc_arglist(interp, sub,
859 obj, method, signature, ap);
860 va_end(ap);
861 PARROT_CALLIN_END(interp);
862 return result;
865 PARROT_API Parrot_Int
866 Parrot_call_method_ret_int(Parrot_Interp interp, Parrot_PMC sub,
867 Parrot_PMC obj, Parrot_String method, const char *signature, ...)
869 Parrot_Int result;
870 va_list ap;
872 PARROT_CALLIN_START(interp);
873 va_start(ap, signature);
874 result = Parrot_run_meth_fromc_arglist_reti(interp, sub,
875 obj, method, signature, ap);
876 va_end(ap);
877 PARROT_CALLIN_END(interp);
878 return result;
881 PARROT_API Parrot_Float
882 Parrot_call_method_ret_float(Parrot_Interp interp, Parrot_PMC sub,
883 Parrot_PMC obj, Parrot_String method, const char *signature, ...)
885 Parrot_Float result;
886 va_list ap;
888 PARROT_CALLIN_START(interp);
889 va_start(ap, signature);
890 result = Parrot_run_meth_fromc_arglist_retf(interp, sub,
891 obj, method, signature, ap);
892 va_end(ap);
893 PARROT_CALLIN_END(interp);
894 return result;
899 =item C<Parrot_Int
900 Parrot_get_intreg(Parrot_Interp interp, Parrot_Int regnum)>
902 Return the value of an integer register.
904 =cut
908 PARROT_API Parrot_Int
909 Parrot_get_intreg(Parrot_Interp interp, Parrot_Int regnum)
911 return REG_INT(regnum);
916 =item C<Parrot_Float
917 Parrot_get_numreg(Parrot_Interp interp, Parrot_Int regnum)>
919 Return the value of a numeric register.
921 =cut
925 PARROT_API Parrot_Float
926 Parrot_get_numreg(Parrot_Interp interp, Parrot_Int regnum)
928 return REG_NUM(regnum);
933 =item C<Parrot_String
934 Parrot_get_strreg(Parrot_Interp interp, Parrot_Int regnum)>
936 Return the value of a string register.
938 =cut
942 PARROT_API Parrot_String
943 Parrot_get_strreg(Parrot_Interp interp, Parrot_Int regnum)
945 return REG_STR(regnum);
950 =item C<Parrot_PMC
951 Parrot_get_pmcreg(Parrot_Interp interp, Parrot_Int regnum)>
953 Return the value of a PMC register.
955 =cut
959 PARROT_API Parrot_PMC
960 Parrot_get_pmcreg(Parrot_Interp interp, Parrot_Int regnum)
962 return REG_PMC(regnum);
967 =item C<void
968 Parrot_set_intreg(Parrot_Interp interp, Parrot_Int regnum,
969 Parrot_Int value)>
971 Set the value of an I register.
973 =cut
977 PARROT_API void
978 Parrot_set_intreg(Parrot_Interp interp, Parrot_Int regnum,
979 Parrot_Int value)
981 REG_INT(regnum) = value;
986 =item C<void
987 Parrot_set_numreg(Parrot_Interp interp, Parrot_Int regnum,
988 Parrot_Float value)>
990 Set the value of an N register.
992 =cut
996 PARROT_API void
997 Parrot_set_numreg(Parrot_Interp interp, Parrot_Int regnum,
998 Parrot_Float value)
1000 REG_NUM(regnum) = value;
1005 =item C<void
1006 Parrot_set_strreg(Parrot_Interp interp, Parrot_Int regnum,
1007 Parrot_String value)>
1009 Set the value of an S register.
1011 =cut
1015 PARROT_API void
1016 Parrot_set_strreg(Parrot_Interp interp, Parrot_Int regnum,
1017 Parrot_String value)
1019 REG_STR(regnum) = value;
1024 =item C<void
1025 Parrot_set_pmcreg(Parrot_Interp interp, Parrot_Int regnum,
1026 Parrot_PMC value) >
1028 Set the value of a P register.
1030 =cut
1034 PARROT_API void
1035 Parrot_set_pmcreg(Parrot_Interp interp, Parrot_Int regnum,
1036 Parrot_PMC value)
1038 REG_PMC(regnum) = value;
1041 /*=for api extend Parrot_new_string
1046 =item C<Parrot_String Parrot_new_string(Parrot_Interp interp,
1047 char *buffer, int length,
1048 const char * const encoding_name,
1049 Parrot_Int flags)>
1051 Create a new Parrot string from a passed-in buffer. Pass in a 0 for
1052 flags for right now.
1054 A copy of the buffer is made.
1056 =cut
1060 PARROT_API Parrot_String
1061 Parrot_new_string(Parrot_Interp interp,
1062 char *buffer, int length,
1063 const char * const encoding_name,
1064 Parrot_Int flags)
1066 Parrot_String retval;
1067 PARROT_CALLIN_START(interp);
1068 retval = string_make(interp, buffer, length, encoding_name, flags);
1069 PARROT_CALLIN_END(interp);
1070 return retval;
1075 =item C<Parrot_Const_Encoding
1076 Parrot_find_encoding(Parrot_Interp interp, char *encoding_name)>
1078 Find the magic token for an encoding, by name.
1080 =cut
1084 PARROT_API Parrot_Const_Encoding
1085 Parrot_find_encoding(Parrot_Interp interp,
1086 char *encoding_name) {
1087 return Parrot_encoding_lookup(encoding_name);
1092 =item C<Parrot_Language
1093 Parrot_find_language(Parrot_Interp interp, char *language)>
1095 Find the magic language token for a language, by language name.
1097 =cut
1101 PARROT_API Parrot_Language
1102 Parrot_find_language(Parrot_Interp interp, char *language)
1104 return 0;
1109 =item C<void
1110 Parrot_register_pmc(Parrot_Interp interp, Parrot_PMC pmc)>
1112 Add a reference of the PMC to the interpreters DOD registry. This
1113 prevents PMCs only known to extension from getting destroyed during DOD
1114 runs.
1116 =cut
1120 PARROT_API void
1121 Parrot_register_pmc(Parrot_Interp interp, Parrot_PMC pmc)
1123 PARROT_CALLIN_START(interp);
1124 dod_register_pmc(interp, pmc);
1125 PARROT_CALLIN_END(interp);
1130 =item C<void
1131 Parrot_unregister_pmc(Parrot_Interp interp, Parrot_PMC pmc)>
1133 Remove a reference of the PMC from the interpreters DOD registry. If the
1134 reference count reaches zero, the PMC will be destroyed during the next
1135 DOD run.
1137 =item C<Parrot_PMC Parrot_get_dod_registry(Parrot_Interp)>
1139 Return Parrot's internal DOD registry PMC.
1140 See also: F<src/pmc/addrregistry.pmc>.
1142 =cut
1146 PARROT_API void
1147 Parrot_unregister_pmc(Parrot_Interp interp, Parrot_PMC pmc)
1149 PARROT_CALLIN_START(interp);
1150 dod_unregister_pmc(interp, pmc);
1151 PARROT_CALLIN_END(interp);
1154 PARROT_API Parrot_PMC
1155 Parrot_get_dod_registry(Parrot_Interp interp)
1157 PMC *registry = interp->DOD_registry;
1158 PARROT_CALLIN_START(interp);
1159 if (!registry) {
1160 registry = interp->DOD_registry =
1161 pmc_new(interp, enum_class_AddrRegistry);
1163 PARROT_CALLIN_END(interp);
1164 return registry;
1169 =item C<void
1170 Parrot_pmc_set_vtable(Parrot_Interp interp, Parrot_PMC pmc,
1171 Parrot_VTABLE vtable)>
1173 Replaces the vtable of the PMC.
1175 =cut
1179 PARROT_API void
1180 Parrot_PMC_set_vtable(Parrot_Interp interp, Parrot_PMC pmc,
1181 Parrot_VTABLE vtable)
1183 pmc->vtable = vtable;
1188 =item C<Parrot_VTABLE
1189 Parrot_get_vtable(Parrot_Interp interp, Parrot_Int id)>
1191 Returns the vtable corresponding to the given PMC ID.
1193 =cut
1197 PARROT_API Parrot_VTABLE
1198 Parrot_get_vtable(Parrot_Interp interp, Parrot_Int id)
1200 return interp->vtables[id];
1205 =back
1207 =head1 SEE ALSO
1209 See F<include/parrot/extend.h> and F<docs/pdds/pdd11_extending.pod>.
1211 =head1 HISTORY
1213 Initial version by Dan Sugalski.
1215 =cut
1221 * Local variables:
1222 * c-file-style: "parrot"
1223 * End:
1224 * vim: expandtab shiftwidth=4: