* docs/pmc.pod:
[parrot.git] / src / extend.c
blobd05278bbdd5dd5870b1ed360e1e4cf884584dfe3
1 /*
2 Copyright (C) 2001-2003, 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(interpreter) 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(interpreter) 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_STRING Parrot_PMC_get_string_intkey(Parrot_INTERP interp,
77 Parrot_PMC pmc, Parrot_Int key) {
78 Parrot_STRING retval;
79 PARROT_CALLIN_START(interp);
80 retval = VTABLE_get_string_keyed_int(interp, pmc, key);
81 PARROT_CALLIN_END(interp);
82 return retval;
88 =item C<void *
89 Parrot_PMC_get_pointer_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
90 Parrot_Int key)>
92 Return the keyed, signed integer value of the value in the PMC.
94 =cut
98 void *Parrot_PMC_get_pointer_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
99 Parrot_Int key) {
100 void *retval;
101 PARROT_CALLIN_START(interp);
102 retval = VTABLE_get_pointer_keyed_int(interp, pmc, key);
103 PARROT_CALLIN_END(interp);
104 return retval;
109 =item C<Parrot_PMC
110 Parrot_PMC_get_pmc_intkey(Parrot_INTERP interp, Parrot_PMC pmc, Parrot_Int key)>
112 Return the integer keyed PMC value of the passed-in PMC
114 =cut
118 Parrot_PMC Parrot_PMC_get_pmc_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
119 Parrot_Int key) {
120 Parrot_PMC retval;
121 PARROT_CALLIN_START(interp);
122 retval = VTABLE_get_pmc_keyed_int(interp, pmc, key);
123 PARROT_CALLIN_END(interp);
124 return retval;
129 =item C<Parrot_Int
130 Parrot_PMC_get_intval(Parrot_INTERP interp, Parrot_PMC pmc)>
132 Return the signed integer value of the value in the PMC.
134 =cut
138 Parrot_Int Parrot_PMC_get_intval(Parrot_INTERP interp, Parrot_PMC pmc) {
139 Parrot_Int retval;
140 PARROT_CALLIN_START(interp);
141 retval = VTABLE_get_integer(interp, pmc);
142 PARROT_CALLIN_END(interp);
143 return retval;
148 =item C<Parrot_Int
149 Parrot_PMC_get_intval_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
150 Parrot_Int key)>
152 Return the keyed, signed integer value of the value in the PMC.
154 =cut
158 Parrot_Int Parrot_PMC_get_intval_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
159 Parrot_Int key) {
160 Parrot_Int retval;
161 PARROT_CALLIN_START(interp);
162 retval = VTABLE_get_integer_keyed_int(interp, pmc, key);
163 PARROT_CALLIN_END(interp);
164 return retval;
169 =item C<Parrot_Int
170 Parrot_PMC_get_intval_pmckey(Parrot_INTERP interp, Parrot_PMC pmc,
171 Parrot_PMC key)>
173 Return the keyed, signed integer value of the value in the PMC.
175 =cut
179 Parrot_Int Parrot_PMC_get_intval_pmckey(Parrot_INTERP interp, Parrot_PMC pmc,
180 Parrot_PMC key) {
181 Parrot_Int retval;
182 PARROT_CALLIN_START(interp);
183 retval = VTABLE_get_integer_keyed(interp, pmc, key);
184 PARROT_CALLIN_END(interp);
185 return retval;
190 =item C<Parrot_Float
191 Parrot_PMC_get_numval(Parrot_INTERP interp, Parrot_PMC pmc)>
193 Return the floating-point value of the PMC.
195 =cut
199 Parrot_Float Parrot_PMC_get_numval(Parrot_INTERP interp, Parrot_PMC pmc) {
200 Parrot_Float retval;
201 PARROT_CALLIN_START(interp);
202 retval = VTABLE_get_number(interp, pmc);
203 PARROT_CALLIN_END(interp);
204 return retval;
209 =item C<Parrot_Float
210 Parrot_PMC_get_numval_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
211 Parrot_Int key)>
213 Return the keyed, signed integer value of the value in the PMC.
215 =cut
219 Parrot_Float Parrot_PMC_get_numval_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
220 Parrot_Int key) {
221 Parrot_Float retval;
222 PARROT_CALLIN_START(interp);
223 retval = VTABLE_get_number_keyed_int(interp, pmc, key);
224 PARROT_CALLIN_END(interp);
225 return retval;
230 =item C<char *
231 Parrot_PMC_get_cstring_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
232 Parrot_Int key)>
234 Return a null-terminated string that represents the string value of the PMC.
236 =cut
240 char *Parrot_PMC_get_cstring_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
241 Parrot_Int key) {
242 STRING *intermediate;
243 char *retval;
244 PARROT_CALLIN_START(interp);
245 intermediate = VTABLE_get_string_keyed_int(interp, pmc, key);
246 retval = string_to_cstring(interp, intermediate);
247 PARROT_CALLIN_END(interp);
248 return retval;
253 =item C<char *Parrot_PMC_get_cstring(Parrot_INTERP interp, Parrot_PMC pmc)>
255 Return a null-terminated string that represents the string value of the PMC.
257 =cut
261 char *Parrot_PMC_get_cstring(Parrot_INTERP interp, Parrot_PMC pmc) {
262 STRING *intermediate;
263 char *retval;
264 PARROT_CALLIN_START(interp);
265 intermediate = VTABLE_get_string(interp, pmc);
266 retval = string_to_cstring(interp, intermediate);
267 PARROT_CALLIN_END(interp);
268 return retval;
273 =item C<char *
274 Parrot_PMC_get_cstringn(Parrot_INTERP interp, Parrot_PMC pmc,
275 Parrot_Int *length)>
277 Return a null-terminated string for the PMC, along with the length.
279 Yes, right now this is a bit of a cheat. It needs fixing, but without
280 disturbing the interface.
282 =cut
286 char *Parrot_PMC_get_cstringn(Parrot_INTERP interp, Parrot_PMC pmc,
287 Parrot_Int *length) {
288 char *retval;
289 PARROT_CALLIN_START(interp);
290 retval = string_to_cstring(interp, VTABLE_get_string(interp, pmc));
291 *length = strlen(retval);
292 PARROT_CALLIN_END(interp);
293 return retval;
298 =item C<char *
299 Parrot_PMC_get_cstringn_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
300 Parrot_Int *length, Parrot_Int key)>
302 Return a null-terminated string for the PMC, along with the length.
304 Yes, right now this is a bit of a cheat. It needs fixing, but without
305 disturbing the interface.
307 =cut
311 char *Parrot_PMC_get_cstringn_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
312 Parrot_Int *length, Parrot_Int key) {
313 char *retval;
314 PARROT_CALLIN_START(interp);
315 retval = string_to_cstring(interp,
316 VTABLE_get_string_keyed_int(interp, pmc, key));
317 *length = strlen(retval);
318 PARROT_CALLIN_END(interp);
319 return retval;
324 =item C<void
325 Parrot_PMC_set_string(Parrot_INTERP interp, Parrot_PMC pmc,
326 Parrot_STRING value)>
328 Assign the passed-in Parrot string to the passed-in PMC.
330 =cut
334 void
335 Parrot_PMC_set_string(Parrot_INTERP interp, Parrot_PMC pmc,
336 Parrot_STRING value) {
337 PARROT_CALLIN_START(interp);
338 VTABLE_set_string_native(interp, pmc, value);
339 PARROT_CALLIN_END(interp);
344 =item C<void
345 Parrot_PMC_set_string_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
346 Parrot_Int key, Parrot_STRING value)>
348 Assign the passed-in Parrot string to the passed-in PMC.
350 =cut
354 void
355 Parrot_PMC_set_string_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
356 Parrot_Int key, Parrot_STRING value)
358 PARROT_CALLIN_START(interp);
359 VTABLE_set_string_keyed_int(interp, pmc, key, value);
360 PARROT_CALLIN_END(interp);
365 =item C<void
366 Parrot_PMC_set_pmc_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
367 Parrot_Int key, Parrot_PMC value)>
369 Assign the passed-in pmc to the passed-in slot of the passed-in PMC.
371 =cut
375 void
376 Parrot_PMC_set_pmc_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
377 Parrot_Int key, Parrot_PMC value) {
378 PARROT_CALLIN_START(interp);
379 VTABLE_set_pmc_keyed_int(interp, pmc, key, value);
380 PARROT_CALLIN_END(interp);
385 =item C<void
386 Parrot_PMC_set_pmc_pmckey(Parrot_INTERP interp, Parrot_PMC pmc,
387 Parrot_PMC key, Parrot_PMC value)>
389 Assign the passed-in pmc to the passed-in slot of the passed-in PMC.
391 =cut
395 void
396 Parrot_PMC_set_pmc_pmckey(Parrot_INTERP interp, Parrot_PMC pmc,
397 Parrot_PMC key, Parrot_PMC value) {
398 PARROT_CALLIN_START(interp);
399 VTABLE_set_pmc_keyed(interp, pmc, key, value);
400 PARROT_CALLIN_END(interp);
405 =item C<void
406 Parrot_PMC_set_pointer_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
407 Parrot_Int key, void *value)>
409 Assign the passed-in pointer to the passed-in PMC.
411 =cut
415 void
416 Parrot_PMC_set_pointer_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
417 Parrot_Int key, void *value) {
418 PARROT_CALLIN_START(interp);
419 VTABLE_set_pointer_keyed_int(interp, pmc, key, value);
420 PARROT_CALLIN_END(interp);
425 =item C<void
426 Parrot_PMC_set_intval(Parrot_INTERP interp, Parrot_PMC pmc, Parrot_Int value)>
428 Assign the passed-in Parrot integer to the passed-in PMC.
430 =cut
434 void
435 Parrot_PMC_set_intval(Parrot_INTERP interp, Parrot_PMC pmc, Parrot_Int value) {
436 PARROT_CALLIN_START(interp);
437 VTABLE_set_integer_native(interp, pmc, value);
438 PARROT_CALLIN_END(interp);
443 =item C<void
444 Parrot_PMC_set_intval_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
445 Parrot_Int key, Parrot_Int value)>
447 Assign the passed-in Parrot integer to the passed-in PMC.
449 =cut
453 void
454 Parrot_PMC_set_intval_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
455 Parrot_Int key, Parrot_Int value) {
456 PARROT_CALLIN_START(interp);
457 VTABLE_set_integer_keyed_int(interp, pmc, key, value);
458 PARROT_CALLIN_END(interp);
463 =item C<void
464 Parrot_PMC_set_numval(Parrot_INTERP interp, Parrot_PMC pmc, Parrot_Float value)>
466 Assign the passed-in Parrot number to the passed-in PMC.
468 =cut
472 void
473 Parrot_PMC_set_numval(Parrot_INTERP interp, Parrot_PMC pmc, Parrot_Float value){
474 PARROT_CALLIN_START(interp);
475 VTABLE_set_number_native(interp, pmc, value);
476 PARROT_CALLIN_END(interp);
481 =item C<void
482 Parrot_PMC_set_numval_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
483 Parrot_Int key, Parrot_Float value)>
485 Assign the passed-in Parrot number to the passed-in PMC.
487 =cut
491 void
492 Parrot_PMC_set_numval_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
493 Parrot_Int key, Parrot_Float value) {
494 PARROT_CALLIN_START(interp);
495 VTABLE_set_number_keyed_int(interp, pmc, key, value);
496 PARROT_CALLIN_END(interp);
501 =item C<void
502 Parrot_PMC_set_cstring(Parrot_INTERP interp, Parrot_PMC pmc, const char *value)>
504 Assign the passed-in null-terminated C string to the passed-in PMC.
506 =cut
510 void
511 Parrot_PMC_set_cstring(Parrot_INTERP interp, Parrot_PMC pmc, const char *value){
512 PARROT_CALLIN_START(interp);
513 VTABLE_set_string_native(interp, pmc,
514 string_from_cstring(interp, value, 0));
515 PARROT_CALLIN_END(interp);
520 =item C<void
521 Parrot_PMC_set_cstring_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
522 Parrot_Int key, const char *value)>
524 Assign the passed-in null-terminated C string to the passed-in PMC.
526 =cut
530 void
531 Parrot_PMC_set_cstring_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
532 Parrot_Int key, const char *value) {
533 PARROT_CALLIN_START(interp);
534 VTABLE_set_string_keyed_int(interp, pmc, key,
535 string_from_cstring(interp, value, 0));
536 PARROT_CALLIN_END(interp);
541 =item C<void
542 Parrot_PMC_set_cstringn(Parrot_INTERP interp, Parrot_PMC pmc,
543 const char *value, Parrot_Int length)>
545 Assign the passed-in length-noted string to the passed-in PMC.
547 =cut
551 void
552 Parrot_PMC_set_cstringn(Parrot_INTERP interp, Parrot_PMC pmc,
553 const char *value, Parrot_Int length) {
554 PARROT_CALLIN_START(interp);
555 VTABLE_set_string_native(interp, pmc,
556 string_from_cstring(interp, value, length));
557 PARROT_CALLIN_END(interp);
562 =item C<void
563 Parrot_PMC_push_intval(Parrot_INTERP interp, Parrot_PMC pmc,
564 Parrot_Int value)>
566 Push the passed-in Parrot integer onto the passed in PMC
568 =cut
572 void
573 Parrot_PMC_push_intval(Parrot_INTERP interp, Parrot_PMC pmc,
574 Parrot_Int value) {
575 PARROT_CALLIN_START(interp);
576 VTABLE_push_integer(interp, pmc, value);
577 PARROT_CALLIN_END(interp);
582 =item C<void
583 Parrot_PMC_push_numval(Parrot_INTERP interp, Parrot_PMC pmc,
584 Parrot_Float value)>
586 Push the passed-in Parrot number onto the passed in PMC
588 =cut
592 void
593 Parrot_PMC_push_numval(Parrot_INTERP interp, Parrot_PMC pmc,
594 Parrot_Float value) {
595 PARROT_CALLIN_START(interp);
596 VTABLE_push_float(interp, pmc, value);
597 PARROT_CALLIN_END(interp);
602 =item C<void
603 Parrot_PMC_delete_pmckey(Parrot_INTERP interp, Parrot_PMC pmc,
604 Parrot_PMC key)>
606 Deletes the value associated with the passed-in PMC from the PMC.
608 =cut
612 void
613 Parrot_PMC_delete_pmckey(Parrot_INTERP interp, Parrot_PMC pmc,
614 Parrot_PMC key) {
615 PARROT_CALLIN_START(interp);
616 VTABLE_delete_keyed(interp, pmc, key);
617 PARROT_CALLIN_END(interp);
622 =item C<void
623 Parrot_PMC_set_cstringn_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
624 Parrot_Int key,
625 const char *value, Parrot_Int length)>
627 Assign the passed-in length-noted string to the passed-in PMC.
629 =cut
633 void
634 Parrot_PMC_set_cstringn_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
635 Parrot_Int key,
636 const char *value, Parrot_Int length) {
637 PARROT_CALLIN_START(interp);
638 VTABLE_set_string_keyed_int(interp, pmc, key,
639 string_from_cstring(interp, value, length));
640 PARROT_CALLIN_END(interp);
645 =item C<Parrot_PMC Parrot_PMC_new(Parrot_INTERP interp, Parrot_Int type)>
647 Create and return a new PMC.
649 =cut
653 Parrot_PMC Parrot_PMC_new(Parrot_INTERP interp, Parrot_Int type) {
654 Parrot_PMC newpmc;
655 PARROT_CALLIN_START(interp);
656 newpmc = pmc_new_noinit(interp, type);
657 VTABLE_init(interp, newpmc);
658 PARROT_CALLIN_END(interp);
659 return newpmc;
664 =item C<Parrot_Int Parrot_PMC_typenum(Parrot_INTERP interp, const char *class)>
666 Returns the internal identifier that represents the named class.
668 =cut
672 Parrot_Int Parrot_PMC_typenum(Parrot_INTERP interp, const char *class) {
673 Parrot_Int retval;
674 PARROT_CALLIN_START(interp);
675 retval = pmc_type(interp, string_from_cstring(interp, class, 0));
676 PARROT_CALLIN_END(interp);
677 return retval;
682 =item C<Parrot_PMC Parrot_PMC_null()>
684 Returns the special C<NULL> PMC.
686 =cut
690 Parrot_PMC
691 Parrot_PMC_null(void) {
692 return PMCNULL;
697 =item C<void Parrot_free_cstring(char *string)>
699 Deallocate a C string that the interpreter has handed to you.
701 =cut
705 void
706 Parrot_free_cstring(char *string) {
707 string_cstring_free(string);
712 =item C<void*
713 Parrot_call_sub(Parrot_INTERP interpreter, Parrot_PMC sub,
714 const char *signature, ...)>
716 Call a parrot subroutine with the given function signature. The first char in
717 C<signature> denotes the return value. Next chars are arguments.
719 The return value of this function can be void or a pointer type.
721 Signature chars are:
723 v ... void return
724 I ... Parrot_Int
725 N ... Parrot_Float
726 S ... Parrot_STRING
727 P ... Parrot_PMC
729 =item C<Parrot_Int>
730 Parrot_call_sub_ret_int(Parrot_INTERP interpreter, Parrot_PMC sub,
731 const char *signature, ...)>
733 =item C<Parrot_Float>
734 Parrot_call_sub_ret_float(Parrot_INTERP interpreter, Parrot_PMC sub,
735 const char *signature, ...)>
737 Like above, with Parrot_Int or Parrot_Float return result.
739 =cut
743 void*
744 Parrot_call_sub(Parrot_INTERP interpreter, Parrot_PMC sub,
745 const char *signature, ...)
747 va_list ap;
748 void *result;
750 PARROT_CALLIN_START(interpreter);
752 va_start(ap, signature);
753 CONTEXT(interpreter->ctx)->constants =
754 PMC_sub(sub)->seg->const_table->constants;
755 result = Parrot_runops_fromc_arglist(interpreter, sub, signature, ap);
756 va_end(ap);
758 PARROT_CALLIN_END(interpreter);
759 return result;
762 Parrot_Int
763 Parrot_call_sub_ret_int(Parrot_INTERP interpreter, Parrot_PMC sub,
764 const char *signature, ...)
766 va_list ap;
767 Parrot_Int result;
769 PARROT_CALLIN_START(interpreter);
771 va_start(ap, signature);
772 result = Parrot_runops_fromc_arglist_reti(interpreter, sub, signature, ap);
773 va_end(ap);
775 PARROT_CALLIN_END(interpreter);
776 return result;
779 Parrot_Float
780 Parrot_call_sub_ret_float(Parrot_INTERP interpreter, Parrot_PMC sub,
781 const char *signature, ...)
783 va_list ap;
784 Parrot_Float result;
786 PARROT_CALLIN_START(interpreter);
788 va_start(ap, signature);
789 result = Parrot_runops_fromc_arglist_retf(interpreter, sub, signature, ap);
790 va_end(ap);
792 PARROT_CALLIN_END(interpreter);
793 return result;
798 =item C<void* Parrot_call_method(Parrot_INTERP interp, Parrot_PMC sub,
799 Parrot_PMC object, Parrot_STRING method, const char *signature, ...)>
801 =item C<Parrot_Int Parrot_call_method_ret_int(Parrot_INTERP interp,
802 Parrot_PMC sub, Parrot_PMC object, Parrot_STRING method,
803 const char *signature, ...)>
805 =item C<Parrot_Float Parrot_call_method_ret_float(Parrot_INTERP interp,
806 Parrot_PMC sub, Parrot_PMC object, Parrot_STRING method,
807 const char *signature, ...)>
809 Call a parrot method for the given object.
811 =cut
815 void *
816 Parrot_call_method(Parrot_INTERP interpreter, Parrot_PMC sub, Parrot_PMC obj,
817 Parrot_STRING method, const char *signature, ...)
819 void *result;
820 va_list ap;
822 PARROT_CALLIN_START(interpreter);
823 va_start(ap, signature);
824 result = Parrot_run_meth_fromc_arglist(interpreter, sub,
825 obj, method, signature, ap);
826 va_end(ap);
827 PARROT_CALLIN_END(interpreter);
828 return result;
831 Parrot_Int
832 Parrot_call_method_ret_int(Parrot_INTERP interpreter, Parrot_PMC sub,
833 Parrot_PMC obj, Parrot_STRING method, const char *signature, ...)
835 Parrot_Int result;
836 va_list ap;
838 PARROT_CALLIN_START(interpreter);
839 va_start(ap, signature);
840 result = Parrot_run_meth_fromc_arglist_reti(interpreter, sub,
841 obj, method, signature, ap);
842 va_end(ap);
843 PARROT_CALLIN_END(interpreter);
844 return result;
847 Parrot_Float
848 Parrot_call_method_ret_float(Parrot_INTERP interpreter, Parrot_PMC sub,
849 Parrot_PMC obj, Parrot_STRING method, const char *signature, ...)
851 Parrot_Float result;
852 va_list ap;
854 PARROT_CALLIN_START(interpreter);
855 va_start(ap, signature);
856 result = Parrot_run_meth_fromc_arglist_retf(interpreter, sub,
857 obj, method, signature, ap);
858 va_end(ap);
859 PARROT_CALLIN_END(interpreter);
860 return result;
865 =item C<Parrot_Int
866 Parrot_get_intreg(Parrot_INTERP interpreter, Parrot_Int regnum)>
868 Return the value of an integer register.
870 =cut
874 Parrot_Int
875 Parrot_get_intreg(Parrot_INTERP interpreter, Parrot_Int regnum)
877 return REG_INT(regnum);
882 =item C<Parrot_Float
883 Parrot_get_numreg(Parrot_INTERP interpreter, Parrot_Int regnum)>
885 Return the value of a numeric register.
887 =cut
891 Parrot_Float
892 Parrot_get_numreg(Parrot_INTERP interpreter, Parrot_Int regnum)
894 return REG_NUM(regnum);
899 =item C<Parrot_STRING
900 Parrot_get_strreg(Parrot_INTERP interpreter, Parrot_Int regnum)>
902 Return the value of a string register.
904 =cut
908 Parrot_STRING
909 Parrot_get_strreg(Parrot_INTERP interpreter, Parrot_Int regnum)
911 return REG_STR(regnum);
916 =item C<Parrot_PMC
917 Parrot_get_pmcreg(Parrot_INTERP interpreter, Parrot_Int regnum)>
919 Return the value of a PMC register.
921 =cut
925 Parrot_PMC
926 Parrot_get_pmcreg(Parrot_INTERP interpreter, Parrot_Int regnum)
928 return REG_PMC(regnum);
933 =item C<void
934 Parrot_set_intreg(Parrot_INTERP interpreter, Parrot_Int regnum,
935 Parrot_Int value)>
937 Set the value of an I register.
939 =cut
943 void
944 Parrot_set_intreg(Parrot_INTERP interpreter, Parrot_Int regnum,
945 Parrot_Int value)
947 REG_INT(regnum) = value;
952 =item C<void
953 Parrot_set_numreg(Parrot_INTERP interpreter, Parrot_Int regnum,
954 Parrot_Float value)>
956 Set the value of an N register.
958 =cut
962 void
963 Parrot_set_numreg(Parrot_INTERP interpreter, Parrot_Int regnum,
964 Parrot_Float value)
966 REG_NUM(regnum) = value;
971 =item C<void
972 Parrot_set_strreg(Parrot_INTERP interpreter, Parrot_Int regnum,
973 Parrot_STRING value)>
975 Set the value of an S register.
977 =cut
981 void
982 Parrot_set_strreg(Parrot_INTERP interpreter, Parrot_Int regnum,
983 Parrot_STRING value)
985 REG_STR(regnum) = value;
990 =item C<void
991 Parrot_set_pmcreg(Parrot_INTERP interpreter, Parrot_Int regnum,
992 Parrot_PMC value) >
994 Set the value of a P register.
996 =cut
1000 void
1001 Parrot_set_pmcreg(Parrot_INTERP interpreter, Parrot_Int regnum,
1002 Parrot_PMC value)
1004 REG_PMC(regnum) = value;
1007 /*=for api extend Parrot_new_string
1012 =item C<Parrot_STRING Parrot_new_string(Parrot_INTERP interpreter,
1013 char *buffer, int length,
1014 const char * const encoding_name,
1015 Parrot_Int flags)>
1017 Create a new Parrot string from a passed-in buffer. Pass in a 0 for
1018 flags for right now.
1020 A copy of the buffer is made.
1022 =cut
1026 Parrot_STRING
1027 Parrot_new_string(Parrot_INTERP interpreter,
1028 char *buffer, int length,
1029 const char * const encoding_name,
1030 Parrot_Int flags)
1032 Parrot_STRING retval;
1033 PARROT_CALLIN_START(interpreter);
1034 retval = string_make(interpreter, buffer, length, encoding_name, flags);
1035 PARROT_CALLIN_END(interpreter);
1036 return retval;
1041 =item C<Parrot_Const_Encoding
1042 Parrot_find_encoding(Parrot_INTERP interpreter, char *encoding_name)>
1044 Find the magic token for an encoding, by name.
1046 =cut
1050 Parrot_Const_Encoding Parrot_find_encoding(Parrot_INTERP interpreter,
1051 char *encoding_name) {
1052 return Parrot_encoding_lookup(encoding_name);
1057 =item C<Parrot_Language
1058 Parrot_find_language(Parrot_INTERP interpreter, char *language)>
1060 Find the magic language token for a language, by language name.
1062 =cut
1066 Parrot_Language
1067 Parrot_find_language(Parrot_INTERP interpreter, char *language)
1069 return 0;
1074 =item C<void
1075 Parrot_register_pmc(Parrot_INTERP interpreter, Parrot_PMC pmc)>
1077 Add a reference of the PMC to the interpreters DOD registry. This
1078 prevents PMCs only known to extension from getting destroyed during DOD
1079 runs.
1081 =cut
1085 void
1086 Parrot_register_pmc(Parrot_INTERP interp, Parrot_PMC pmc)
1088 PARROT_CALLIN_START(interp);
1089 dod_register_pmc(interp, pmc);
1090 PARROT_CALLIN_END(interp);
1095 =item C<void
1096 Parrot_unregister_pmc(Parrot_INTERP interpreter, Parrot_PMC pmc)>
1098 Remove a reference of the PMC from the interpreters DOD registry. If the
1099 reference count reaches zero, the PMC will be destroyed during the next
1100 DOD run.
1102 =item C<Parrot_PMC Parrot_get_dod_registry(Parrot_INTERP)>
1104 Return Parrot's internal DOD registry PMC.
1105 See also: F<src/pmc/addrregistry.pmc>.
1107 =cut
1111 void
1112 Parrot_unregister_pmc(Parrot_INTERP interp, Parrot_PMC pmc)
1114 PARROT_CALLIN_START(interp);
1115 dod_unregister_pmc(interp, pmc);
1116 PARROT_CALLIN_END(interp);
1119 Parrot_PMC
1120 Parrot_get_dod_registry(Parrot_INTERP interp)
1122 PMC *registry = interp->DOD_registry;
1123 PARROT_CALLIN_START(interp);
1124 if (!registry) {
1125 registry = interp->DOD_registry =
1126 pmc_new(interp, enum_class_AddrRegistry);
1128 PARROT_CALLIN_END(interp);
1129 return registry;
1134 =item C<void
1135 Parrot_pmc_set_vtable(Parrot_INTERP interpreter, Parrot_PMC pmc,
1136 Parrot_VTABLE vtable)>
1138 Replaces the vtable of the PMC.
1140 =cut
1144 void
1145 Parrot_PMC_set_vtable(Parrot_INTERP interpreter, Parrot_PMC pmc,
1146 Parrot_VTABLE vtable)
1148 pmc->vtable = vtable;
1153 =item C<Parrot_VTABLE
1154 Parrot_get_vtable(Parrot_INTERP interpreter, Parrot_Int id)>
1156 Returns the vtable corresponding to the given PMC ID.
1158 =cut
1162 Parrot_VTABLE
1163 Parrot_get_vtable(Parrot_INTERP interpreter, Parrot_Int id)
1165 return interpreter->vtables[id];
1170 =back
1172 =head1 SEE ALSO
1174 See F<include/parrot/extend.h> and F<docs/pdds/pdd11_extending.pod>.
1176 =head1 HISTORY
1178 Initial version by Dan Sugalski.
1180 =cut
1186 * Local variables:
1187 * c-file-style: "parrot"
1188 * End:
1189 * vim: expandtab shiftwidth=4: