-# genSPEC processing:
- if ( /^\s*\{-#\s*GENERATE_SPECS/ ) {
- if ( $DoGenSpecs ) {
- $line = $_;
- $data_or_inst = 0;
- $data_inst_str = "";
- $remove_poly = 1;
- $space = "";
-
- if ( /^\s*\{-#\s*GENERATE_SPECS\s+(data)\s+(\S.*)\s*::(.*)#-\}\s*$/ ) {
- $data_or_inst = 1;
- $data_inst_str = $1;
- $vars = $2;
- $type = $3;
- } elsif ( /^\s*\{-#\s*GENERATE_SPECS\s+(instance)\s+(\S.*)\s*::(.*)#-\}\s*$/ ) {
- $data_or_inst = 1;
- $data_inst_str = $1;
- $vars = $2;
- $type = $3;
- } elsif ( /^(\s*)\{-#\s*GENERATE_SPECS\s+(\S+)\s+(.*)\s*#-\}\s*$/ ) {
- $space = $1;
- $fun = $2;
- $vars = $3;
-
- $tysig = <INPIPE>;
- while ( $tysig =~ /^\s*$/ ) {
- print $tysig;
- $tysig = <INPIPE>;
- }
- $funpat = $fun; # quote non alphanumeric characters in pattern
- $funpat =~ s/(\W)/\\\1/g;
- $tysig =~ /^\s*$funpat\s*::(.*)$/ || die "Error: GENERATE_SPECS not followed by type signature for $fun:\n$line$tysig\n";
- $type = $1;
- $type =~ s/^(.*)=>//; # remove context from type
- } else {
- die "Error: invlaid GENERATE_SPECS pragma:\n $_";
- }
-
- @tyvars = split(/\s+/, $vars);
- @tospec = ($type);
- foreach $var (@tyvars) {
- @specing = @tospec;
-
- if ( $var =~ /^(\w+)\{(.*)\}$/ ) {
- $var = $1;
- @specing_types = &split_types($2);
- if ($specing_types[0] eq '~') {
- shift(@specing_types);
- @tospec = (); # remove specs polymorphic in this tyvar
- $remove_poly = 0;
- }
- if ($specing_types[0] eq '+') {
- shift(@specing_types);
- unshift(@specing_types, @SpecingTypes);
- }
- } else {
- @specing_types = @SpecingTypes;
- }
-
- # If not $DoGenSpecsUnboxed we remove any unboxed types
- # (i.e. types containing a #) from the specing_types
-
- @specing_types = grep(!/#/, @specing_types) if ! $DoGenSpecsUnboxed;
-
- foreach $uty (@specing_types) {
- @speced = @specing;
- foreach $i (0..$#speced) {
- $speced[$i] =~ s/\b$var\b/$uty/g ;
- }
- push(@tospec, @speced);
- }
- }
- shift(@tospec) if $remove_poly; # remove fully polymorphic spec
-
- if ($#tospec >= 0) {
- $specty = shift(@tospec);
- print ($data_or_inst ? "\{-# SPECIALIZE $data_inst_str $specty #-\}" : "$space\{-# SPECIALIZE $fun :: $specty");
- while ($#tospec >= 0) {
- $specty = shift(@tospec);
- print ($data_or_inst ? "; \{-# SPECIALIZE $data_inst_str $specty #-\}" : ", $specty");
- }
- print ($data_or_inst ? "\n" : " #-}\n");
- } else {
- print "\{- NO_SPECS_GENERATED ", $data_or_inst ? $specty : $fun, " -\}\n";
- print STDERR "Warning: No specs for GENERATE_SPECS pre-processing pragma:\n $_";
- }
- print $tysig if ! $data_or_inst;
- } else {
- print STDERR "Warning: GENERATE_SPECS pre-processing pragma ignored:\n $_";
- print $_;
- }
- } else {
- print $_;
- }