cvsuser 03/12/26 23:13:23
Modified: . MANIFEST
ops core.ops
Added: t/op calling.t
Log:
Added the foldup op to make PMC vararg calls easier
Revision Changes Path
1.521 +1 -0 parrot/MANIFEST
Index: MANIFEST
===================================================================
RCS file: /cvs/public/parrot/MANIFEST,v
retrieving revision 1.520
retrieving revision 1.521
diff -u -w -r1.520 -r1.521
--- MANIFEST 25 Dec 2003 13:00:18 -0000 1.520
+++ MANIFEST 27 Dec 2003 07:13:19 -0000 1.521
@@ -2220,6 +2220,7 @@
t/op/arithmetics.t []
t/op/basic.t []
t/op/bitwise.t []
+t/op/calling.t []
t/op/comp.t []
t/op/conv.t []
t/op/debuginfo.t []
1.341 +61 -0 parrot/ops/core.ops
Index: core.ops
===================================================================
RCS file: /cvs/public/parrot/ops/core.ops,v
retrieving revision 1.340
retrieving revision 1.341
diff -u -w -r1.340 -r1.341
--- core.ops 18 Dec 2003 16:15:06 -0000 1.340
+++ core.ops 27 Dec 2003 07:13:21 -0000 1.341
@@ -957,6 +957,67 @@
###############################################################################
+=head2 Function Utility ops
+
+Opcodes for handling function parameters, validating parameters, type
+and prototype checking, and generic whatnots.
+
+=over 4
+
+=cut
+
+########################################
+
+=item B<foldup>(out PMC)
+
+Take all the PMCs passed in as parameters and stick them into an Array
+PMC, in the register pointed to.
+
+B<NOTE!> IMCC and PDD03 aren't yet in conformance. This uses the current
+IMCC setup, but should be changed as soon as IMCC modified to the correct
+calling conventions.
+
+=cut
+
+op foldup(out PMC) {
+ /* Should be I3 when we're done */
+ INTVAL max_used_reg = REG_INT(2) + 5;
+ INTVAL reg;
+ INTVAL elems_in_array;
+ INTVAL current_offset = 0;
+ INTVAL total_size;
+ PMC *destination_pmc = NULL;
+ PMC *overflow = REG_PMC(3);
+
+ destination_pmc = pmc_new_noinit(interpreter, enum_class_Array);
+ VTABLE_init(interpreter, destination_pmc);
+ /* XXX This needs fixing when IMCC does calling conventions right */
+ total_size = REG_INT(2);
+ VTABLE_set_integer_native(interpreter, destination_pmc, total_size);
+ /* First move over the PMCs in registers */
+ for (reg = 5; reg < max_used_reg; reg++) {
+ VTABLE_set_pmc_keyed_int(interpreter, destination_pmc, current_offset,
REG_PMC(reg));
+ current_offset++;
+ }
+ /* Next see how many are in the overflow, if any */
+ if (max_used_reg == 16 && overflow != NULL &&
+ VTABLE_type(interpreter, overflow) != enum_class_Null &&
+ ((elems_in_array = VTABLE_get_integer(interpreter, overflow)) != 0)) {
+ INTVAL cur_elem;
+ total_size += elems_in_array;
+ VTABLE_set_integer_native(interpreter, destination_pmc, total_size);
+ for (cur_elem = 0; cur_elem < elems_in_array; cur_elem++) {
+ VTABLE_set_pmc_keyed_int(interpreter, destination_pmc, current_offset,
VTABLE_get_pmc_keyed_int(interpreter, overflow, cur_elem));
+ current_offset++;
+ }
+ }
+
+ $1 = destination_pmc;
+ goto NEXT();
+}
+
+###############################################################################
+
=head2 Native Call Interface
Opcodes for interfacing with C functions in shared libraries.
1.1 parrot/t/op/calling.t
Index: calling.t
===================================================================
#! perl -w
use Parrot::Test tests => 1;
use Test::More;
# Test calling convention operations
output_is(<<'CODE', <<OUTPUT, "foldup");
set P16,P1
new P19,36
new P18,36
new P17,36
new P16,36
new P21,36
new P20,36
new P22,36
new P24,36
new P28,36
new P29,36
new P30,36
new P27,36
new P26,36
new P25,36
new P23,36
set P20,"Foobar!"
set P23,"Baxman!"
newsub P0,45,74
set P5,P19
set P6,P18
set P7,P17
set P8,P16
set P9,P21
set P10,P20
set P11,P22
set P12,P24
set P13,P28
set P14,P29
set P15,P30
new P3,42
set P3,15
push P3,P27
push P3,P26
push P3,P25
push P3,P23
set P0,P0
set I0,1
set I1,4
set I2,11
set I3,0
savetop
invokecc
restoretop
end
foldup P17
set P16,P17[5]
print P16
print "\n"
set P16,P17[14]
print P16
print "\n"
set I0,1
set I1,0
set I2,0
set I3,0
set I4,0
invoke P1
end
CODE
Foobar!
Baxman!
OUTPUT