5 our (@types, @funcs, @opers);
8 print "#include <stdlib.h>\n";
9 print "#include <stdbool.h>\n\n";
14 foreach my $type (@types) {
15 next if $type->{ROLE} eq 'fixed';
16 push (@atoms, "OP_$type->{NAME}");
18 print_operations ('atom', 1, \@atoms);
19 print_operations ('function', "OP_atom_last + 1", \@funcs);
20 print_operations ('operator', "OP_function_last + 1", \@opers);
21 print_range ("OP_composite", "OP_function_first", "OP_operator_last");
23 print_range ("OP", "OP_atom_first", "OP_composite_last");
25 print "operation_type, atom_type;\n";
27 print_predicate ('is_operation', 'OP');
28 print_predicate ("is_$_", "OP_$_")
29 foreach qw (atom composite function operator);
32 sub print_operations {
33 my ($type, $first, $names) = @_;
34 print " /* \u$type types. */\n";
35 print " $names->[0] = $first,\n";
36 print " $_,\n" foreach @$names[1...$#{$names}];
37 print_range ("OP_$type", $names->[0], $names->[$#{$names}]);
42 my ($prefix, $first, $last) = @_;
43 print " ${prefix}_first = $first,\n";
44 print " ${prefix}_last = $last,\n";
45 print " ${prefix}_cnt = ${prefix}_last - ${prefix}_first + 1";
49 my ($function, $category) = @_;
52 print "\nstatic inline bool\n";
53 print "$function (operation_type op)\n";
55 print " assert (is_operation (op));\n" if $function ne 'is_operation';
56 print " return op >= ${category}_first && op <= ${category}_last;\n";