xref: /netbsd-src/external/lgpl3/gmp/dist/demos/perl/typemap (revision ce54336801cf28877c3414aa2fcb251dddd543a2)
1# GMP module external subroutine type mappings.
2
3# Copyright 2001, 2003 Free Software Foundation, Inc.
4#
5#  This file is part of the GNU MP Library.
6#
7#  The GNU MP Library is free software; you can redistribute it and/or modify
8#  it under the terms of either:
9#
10#    * the GNU Lesser General Public License as published by the Free
11#      Software Foundation; either version 3 of the License, or (at your
12#      option) any later version.
13#
14#  or
15#
16#    * the GNU General Public License as published by the Free Software
17#      Foundation; either version 2 of the License, or (at your option) any
18#      later version.
19#
20#  or both in parallel, as here.
21#
22#  The GNU MP Library is distributed in the hope that it will be useful, but
23#  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24#  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25#  for more details.
26#
27#  You should have received copies of the GNU General Public License and the
28#  GNU Lesser General Public License along with the GNU MP Library.  If not,
29#  see https://www.gnu.org/licenses/.
30
31
32TYPEMAP
33const_string		T_PV
34const_string_assume	CONST_STRING_ASSUME
35mpz			MPZ
36mpq			MPQ
37mpf			MPF
38mpz_assume		MPZ_ASSUME
39mpq_assume		MPQ_ASSUME
40mpf_assume		MPF_ASSUME
41mpz_coerce		MPZ_COERCE
42mpq_coerce		MPQ_COERCE
43mpf_coerce_st0		MPF_COERCE_ST0
44mpf_coerce_def		MPF_COERCE_DEF
45randstate		RANDSTATE
46ulong_coerce		ULONG_COERCE
47malloced_string		MALLOCED_STRING
48order_noswap		ORDER_NOSWAP
49dummy			DUMMY
50# perl 5.005 doesn't have UV in its standard typemap, so use this instead
51gmp_UV			GMP_UV
52
53
54INPUT
55MPZ
56	class_or_croak ($arg, mpz_class); $var = SvMPZ($arg);
57MPQ
58	class_or_croak ($arg, mpq_class); $var = SvMPQ($arg);
59MPF
60	class_or_croak ($arg, mpf_class); $var = SvMPF($arg);
61MPZ_ASSUME
62        MPZ_ASSUME ($var, $arg)
63MPQ_ASSUME
64        MPQ_ASSUME ($var, $arg)
65MPF_ASSUME
66        MPF_ASSUME ($var, $arg)
67MPZ_COERCE
68	$var = coerce_mpz (tmp_mpz_${(my $stnum=$arg)=~s/[^0-9]//g;\$stnum}, $arg)
69MPQ_COERCE
70	$var = coerce_mpq (tmp_mpq_${(my $stnum=$arg)=~s/[^0-9]//g;\$stnum}, $arg)
71MPF_COERCE_ST0
72        /* precision follows ST(0) */
73        assert (sv_derived_from (ST(0), mpf_class));
74	$var = coerce_mpf (tmp_mpf_${(my $stnum=$arg)=~s/[^0-9]//g;\$stnum},
75	                   $arg, mpf_get_prec (SvMPF(ST(0))))
76MPF_COERCE_DEF
77        /* default precision used */
78	$var = coerce_mpf (tmp_mpf_${(my $stnum=$arg)=~s/[^0-9]//g;\$stnum},
79	                   $arg, mpf_get_default_prec())
80RANDSTATE
81	class_or_croak ($arg, rand_class); $var = SvRANDSTATE($arg);
82ULONG_COERCE
83	$var = coerce_ulong ($arg)
84ORDER_NOSWAP
85	assert ($arg != &PL_sv_yes);
86DUMMY
87	/* dummy $var */
88CONST_STRING_ASSUME
89        /* No need to check for SvPOKp and use SvPV, this mapping is
90           only used for overload_constant, which always gets literal
91           strings.  */
92	assert (SvPOK ($arg));
93	$var = SvPVX ($arg);
94
95
96OUTPUT
97MPZ
98    sv_bless (sv_setref_pv ($arg, NULL, $var), mpz_class_hv);
99MPQ
100    sv_bless (sv_setref_pv ($arg, NULL, $var), mpq_class_hv);
101MPF
102    sv_bless (sv_setref_pv ($arg, NULL, $var), mpf_class_hv);
103RANDSTATE
104    sv_setref_pv ($arg, rand_class, $var);
105MALLOCED_STRING
106    sv_usepvn_mg ($arg, $var, strlen($var));
107GMP_UV
108    sv_setuv ($arg, (UV) ($var));
109