4 print "#include <stdlib.h>\n";
5 print "#include <stdbool.h>\n\n";
10 foreach my $type (@types) {
11 next if $type->{ROLE} eq 'fixed';
12 push (@atoms, "OP_$type->{NAME}");
14 print_operations ('atom', 1, \@atoms);
15 print_operations ('function', "OP_atom_last + 1", \@funcs);
16 print_operations ('operator', "OP_function_last + 1", \@opers);
17 print_range ("OP_composite", "OP_function_first", "OP_operator_last");
19 print_range ("OP", "OP_atom_first", "OP_composite_last");
21 print "operation_type, atom_type;\n";
23 print_predicate ('is_operation', 'OP');
24 print_predicate ("is_$_", "OP_$_")
25 foreach qw (atom composite function operator);
28 sub print_operations {
29 my ($type, $first, $names) = @_;
30 print " /* \u$type types. */\n";
31 print " $names->[0] = $first,\n";
32 print " $_,\n" foreach @$names[1...$#{$names}];
33 print_range ("OP_$type", $names->[0], $names->[$#{$names}]);
38 my ($prefix, $first, $last) = @_;
39 print " ${prefix}_first = $first,\n";
40 print " ${prefix}_last = $last,\n";
41 print " ${prefix}_cnt = ${prefix}_last - ${prefix}_first + 1";
45 my ($function, $category) = @_;
48 print "\nstatic inline bool\n";
49 print "$function (operation_type op)\n";
51 print " assert (is_operation (op));\n" if $function ne 'is_operation';
52 print " return op >= ${category}_first && op <= ${category}_last;\n";