3 # Copyright (C) 2003-2007, Parrot Foundation.
8 Take an NCI library definition file and turn it into a
12 An NCI library definition file provides the information needed to
13 generate a parrot wrapper for the named library (or libraries). Its
14 format is simple, and looks like:
23 p new_field i i i i i i
31 Note that the assembly file is generated in the order you specify, so
32 if there are library dependencies, make sure you have them in the
37 Declares the package that all subsequent sub PMCs will be put
38 into. The name is a simple concatenation of the package name, double
39 colon, and the routine name, with no preceding punctuation.
43 The name of the library to be loaded. Should be as qualified as
44 necessary for your platform--generally the full filename is required,
45 though the directory generally isn't.
47 You may load multiple libraries here, but only the last one loaded
48 will be exposed to subsequent defs.
52 This section holds the definitions of functions. Each function is
53 assumed to be in the immediate preceding library. The definition of
56 return_type name [param [param [param ...]]]
58 The param and return_type parameters use the NCI standard, which for
65 Parameter is a void pointer, taken from the PMC's data pointer. PMC is
66 assumed to be an unmanagedstruct or child class.
68 Taken from a P register
72 Parameter is a character.
74 Taken from an I register
80 Taken from an I register
86 Taken from an I register
92 Taken from an I register
98 Taken from an N register.
102 Parameter is a double.
104 Taken from an N register.
108 Paramter is a char *, presumably a C string
110 Taken from an S register
114 Void. Only valid as a return type, noting that the function returns no data.
118 Interpreter pointer. The current interpreter pointer is passed in
128 Taken from an I register.
134 Taken from an I register
140 Taken from an I register
149 my ( $from_file, $to_file ) = @ARGV;
151 # If there is no destination file, strip off the extension of the
152 # source file and add a .pasm to it
153 if ( !defined $to_file ) {
154 $to_file = $from_file;
155 $to_file =~ s/\..*$//;
159 open my $INPUT, '<', "$from_file" or die "Can't open up $from_file, error $!";
160 open my $OUTPUT, '>', "$to_file" or die "Can't open up $to_file, error $!";
162 # To start, save all the registers, just in case
163 print $OUTPUT "saveall\n";
166 my ( $cur_package, $line, $cur_section );
170 package => \
&package_line
,
175 while ( $line = <$INPUT> ) {
177 # Throw away trailing newlines, comments, and whitespace. If the
178 # line's empty, then off to the next line
184 # Is it a section line? If so, extract the section and set it.
185 if ( $line =~ /\[(\w+)\]/ ) {
190 # Everything else goes to the handler
191 $dispatch{$cur_section}->($line);
195 # Put the registers back and end
196 print $OUTPUT "restoreall\n";
197 print $OUTPUT "end\n";
203 # Trim leading and trailing spaces
207 # Set the global current package
208 $cur_package = $line;
214 print $OUTPUT "loadlib P1, '$line'\n";
219 my ( $return_type, $name, @params ) = split ' ', $line;
220 unshift @params, $return_type;
221 my $signature = join( "", @params );
222 print $OUTPUT "dlfunc P2, P1, '$name', '$signature'\n";
223 print $OUTPUT "store_global '${cur_package}::${name}', P2\n";
228 # cperl-indent-level: 4
231 # vim: expandtab shiftwidth=4: