From: <mr...@mr...> - 2005-04-02 19:54:34
|
# This is a BitKeeper generated diff -Nru style patch. # # ChangeSet # 2005/04/02 21:54:05+02:00 mr...@fo... = # allow extensions in interface definitions # = # tools/tc2make # 2005/04/02 21:54:05+02:00 mr...@fo... +37 -17 # allow extensions in interface definitions # = diff -Nru a/tools/tc2make b/tools/tc2make --- a/tools/tc2make 2005-04-02 21:54:18 +02:00 +++ b/tools/tc2make 2005-04-02 21:54:18 +02:00 @@ -100,7 +100,7 @@ my @confs; # Conf options my %types; # Types of exported symbols my %doc; -my @extensions; +my %extensions; my %extfiles; my %extdata; = @@ -132,7 +132,7 @@ undef @confs; undef %types; undef %doc; - undef @extensions; + undef %extensions; undef %extdata; } = @@ -154,6 +154,23 @@ return 0; } = +sub load_ext { + my($ext) =3D @_; + return if $extensions{$ext}; + + if (exist_scm "$topsrc/tc2ext/$ext.pm", 1) { + $extfiles{"tc2ext/$ext.pm"} =3D 1; + eval qq,require "$topsrc/tc2ext/$ext.pm", or + die "tc2make: error loading $ext\n"; + } else { + eval "require $ext" or + die "tc2make: extension $ext not found\n"; + } + + $extensions{$ext} =3D $ext; + &{"${ext}::init"}; +} + # Convert an interface and symbol name into its canonical C name. If # called in list context a list with the C type and the symbol name is # returned. @@ -272,16 +289,7 @@ push @confs, \@cf; } elsif (/([[:alpha:]_]\w*)\s*{/) { $ext =3D $1; - if (exist_scm "$topsrc/tc2ext/$ext.pm", 1) { - $extfiles{"tc2ext/$ext.pm"} =3D 1; - eval qq,require "$topsrc/tc2ext/$ext.pm", or - die "tc2make: error loading $ext\n"; - } else { - eval "require $ext" or - die "tc2make: extension $ext not found\n"; - } - &{"${ext}::init"}; - push @extensions, $ext; + load_ext $ext; } elsif ($doc) { $$doc .=3D "$_\n"; } else { @@ -544,7 +552,7 @@ #include <string.h> END_C = - &{"${_}::cmod"}(\*C) for(@extensions); + &{"${_}::cmod"}(\*C) for(keys %extensions); = print C <<END_C; typedef char *_char_p; @@ -614,7 +622,7 @@ printf C qq/ tc2_add_hook(\"%s\", %s);\n/, $$_[0], $$_[1]; } = - &{"${_}::postinit"}(\*C) for(@extensions); + &{"${_}::postinit"}(\*C) for(keys %extensions); = print C qq/ $postinit(opt);\n/ if $postinit; print C <<END_C; @@ -630,7 +638,7 @@ \{ END_C = - &{"${_}::unload"}(\*C) for(@extensions); + &{"${_}::unload"}(\*C) for(keys %extensions); = # unregister hooks in kernel for (@hooks) { @@ -650,13 +658,21 @@ my %int; my(@preinc, @postinc); my $doc =3D \$int{'doc'}{'main'}; + my($ext, $bc); = open $ifh, $file or print STDERR "$file: $!\n" and return; = while(<$ifh>){ s/#.*//; next if (/^\s*$/); - if(/^\s*symbol\s+\"(.*?)\"\s+(.*)/){ + s/^\s*|\s*$//g; + /{$/ and $bc++; + if (/^}/ and --$bc =3D=3D 0) { + $ext =3D undef; + } elsif ($ext) { + &{"${ext}::interface"}(\%int, $_) or + die "$file:$.: Syntax error\n"; + } elsif(/^\s*symbol\s+\"(.*?)\"\s+(.*)/){ $int{'symbols'}{$1} =3D $2; $doc =3D \$int{'doc'}{'symbols'}{$1}; } elsif(/^\s*((post|pre)?include)\s*(?:<<(.*))?$/){ @@ -679,6 +695,10 @@ $doc =3D \$int{'doc'}{'options'}{$1}; push @cf, $1 while $p =3D~ /([^\s\"]+(=3D\"[^\"]*\")?)(?=3D\s+\w|$)/g; push @{$int{'options'}}, \@cf; + } elsif (/([[:alpha:]_]\w*)\s*{/) { + $ext =3D $1; + load_ext $ext; + undef $doc; } elsif($doc){ $$doc .=3D $_; } else { @@ -874,7 +894,7 @@ printf H qq/extern int %s(void *);\n/, $$_[1]; } = - &{"${_}::hmod"}(\*H) for(@extensions); + &{"${_}::hmod"}(\*H) for(keys %extensions); = print H "\n#endif\n"; close H; |