1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
#! @PERL_PATH@
#Copyright (C) 2003-2013 The PARI group.
#
#This file is part of the GP2C package.
#
#PARI/GP is free software; you can redistribute it and/or modify it under the
#terms of the GNU General Public License as published by the Free Software
#Foundation. It is distributed in the hope that it will be useful, but WITHOUT
#ANY WARRANTY WHATSOEVER.
#
#Check the License for details. You should have received a copy of it, along
#with the package; see the file 'COPYING'. If not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#This is the description compiler for gp2c.
BEGIN
{
$pari_desc=shift @ARGV;
$compat_desc=shift @ARGV;
$override_desc=shift @ARGV;
-f "@PARI_DATADIR@/PARI/822.pm" || exit 1;
-f $pari_desc || exit 1;
}
use lib "@PARI_DATADIR@";
use PARI::822;
PARI::822::read(\%funcs,$override_desc,0) if defined($override_desc);
PARI::822::read(\%funcs,$pari_desc,0);
PARI::822::read(\%funcs,$compat_desc,0) if defined($compat_desc);
%accepted_class=(
''=>1, 'basic'=>1,
'gp'=>1,'highlevel'=>1,
'symbolic_operators'=>1,
'member_functions'=>1,
'gp2c'=>1,
'gp2c_internal'=>1);
%accepted_command=
(
'add'=>1, 'sub'=>1, 'neg'=>1,
'mul'=>1, 'div'=>1, 'mod'=>1,
'and'=>1, 'or'=>1, 'xor'=>1, 'not'=>1,
'parens'=>1, 'stdref'=>1,
'value'=>1, 'type'=>1, 'nbarg'=>1,
'str_format'=>1, 'str_raw'=>1,
'cast'=>1, 'code'=>1, 'prec'=>1, 'bitprec'=>1,
'format_string'=>1,'format_args'=>1,
'cookie' => 1, 'wrapper' => 1
);
sub check_cname
{
my ($gpname, $cname) = @_;
while($cname =~ /\$\{([^}]*)\}(.*)/)
{
my ($rpl) = $1;
$cname = $2;
for (split(' ', $rpl))
{
/^-?[0-9]+$/ and next;
/^:[a-z_A-Z]+$/ and next;
defined($accepted_command{$_}) and next;
print STDERR "Warning: $gpname unsupported command $_, skipped\n";
return 0;
}
}
return 1;
}
for $gpname (sort keys %funcs)
{
my $f=$funcs{$gpname};
next unless (defined($accepted_class{$f->{'Class'}}));
my $description=$f->{'Description'};
my $proto=$f->{'Prototype'};
my $wrapper=$f->{'Wrapper'};
my $iterator=$f->{'Iterator'};
print "$gpname\n";
my @entry=();
if (defined($description))
{
my @rules = split("\n",$description);
@rules = grep { $_ !~ /^[ \n\t]*$/ } @rules;
my @erules = ();
push @erules, join("\n",0,scalar(@rules));
foreach (@rules)
{
/^[ \n\t]*
\(([^)]*)\)
(?::([A-Za-z0-9_:]*))?
[ \n\t]*
([^\n]*)
[ \n\t]*$/x or die "badly formatted description $_";
my $arglist=$1;
my $cname=$3;
my $typelist=$2;
$arglist =~ tr/ \n\t//d;
my @args=split(',',$arglist,-1);
my @type=split(':',$typelist,-1);
$cname =~ s/\$%([0-9]+)/\${$1 str_format}/g;
$cname =~ s/\$#/\${nbarg}/g;
$cname =~ s/\$\(([0-9]+)\)/\${parens $1 code}/g;
$cname =~ s/\$([0-9]+)/\${$1 code}/g;
$cname =~ s/\$([a-z_A-Z]+):([0-9]+)/\${$2 :$1 cast}/g;
$cname =~ s/\$\(([a-z_A-Z]+):([0-9]+)\)/\${parens $2 :$1 cast}/g;
$cname =~ s/\$prec\b/\${prec}/g;
$cname =~ s/\$bitprec\b/\${bitprec}/g;
check_cname($gpname,$cname) or next;
push @erules, join("\n",$cname,scalar(@args),@args,scalar(@type),@type);
}
push @entry, join("\n",@erules);
}
if (defined($proto))
{
$type="gen";
$type="void" if ($proto =~ /^v/);
$type="small" if ($proto =~ /^l/);
$type="small_int" if ($proto =~ /^i/);
$type="usmall" if ($proto =~ /^u/);
@type=($type);
push @type,"copy" if ($proto =~ /^m/);
push @type,"prec" if ($proto =~ /[pb]/);
$proto =~ s/^[uilmv]//;
$proto =~ s/\\n.*$//;
push @entry, join("\n",1,$f->{'C-Name'},$proto,scalar(@type),@type);
}
if (defined($wrapper))
{
$wrapper =~ tr/ \n\t//d;
$wrapper =~ m/^\(([^)]*)\)/ or die "badly formatted wrapper $wrapper";
my $wraplist=$1;
my @wrap=map { ($_ eq "" || $_ eq "_") ? "$_":"_wrap_$_"; } split(',',$wraplist,-1);
push @entry, join("\n",2,scalar(@wrap),@wrap);
}
if (defined($iterator))
{
my @rules = split("\n",$iterator);
@rules = grep { $_ !~ /^[ \n\t]*$/ } @rules;
my @erules = ();
push @erules, join("\n",3,scalar(@rules));
foreach (@rules)
{
/^[ \n\t]*
\(([^)]*)\)
(?::([A-Za-z0-9_:]*))?
[ \n\t]*
\(([^\n]*)\)
[ \n\t]*$/x or die "badly formatted iterator $_";
my $arglist=$1;
my $iterlist=$3;
my $typelist=$2;
$arglist =~ tr/ \n\t//d;
$iterlist =~ tr/ \n\t//d;
my @args=split(',',$arglist,-1);
my @type=split(':',$typelist,-1);
my @iter=split(',',$iterlist,-1);
push @erules, join("\n",scalar(@iter),@iter, scalar(@args),@args,
scalar(@type),@type);
}
push @entry, join("\n",@erules);
}
print scalar(@entry),"\n";
print join("\n",@entry)."\n" if (@entry);
}
|