mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-18 10:53:40 +00:00
from code generation for them.
compiler/fact_table.m:
Add a separate predicate to do all the required type and mode checks
on the fact table predicate and all its procedures. If this finds errors,
return error messages describing them. If there are no errors, then return
a data structure containing all the semantic information that later passes
will need, which records both type and mode information in a form
in which unsupported types and modes cannot be represented.
Significantly improve the text of most error messages.
Rewrite large chunks of this module to use this data structure (GenInfo)
instead of the predicate's arg types and the procedure's arg modes,
since the latter could not be used without effectively being checked
for validity over and over again. The rewrite of the call tree of the
first exported pred also cuts out of it the semantic checks that are
now in their own pass.
Replace some uses of the ok/error type with empty/nonempty lists
of error_specs.
Replace several uses of bools with bespoke types.
In several related predicates, replace a flag argument and a set of
other arguments that were meaningful only with one setting of the flag
with a maybe-like type that specified those other arguments only when
needed.
Use the tight new types to replace some if-then-else chains
with switches.
Move the task of generating the pragma_vars and the prog_varset
of the foreign_proc implementing each procedure from add_pragma.m
to here, to let fact_table.m control this aspect of the foreign_proc
along with all the others.
Reorder several argument vectors to put bigger/slower-moving inputs
first.
compiler/add_pragma.m:
If a fact table pragma is for a predicate that whose declarations
are not compatible with fact tables, then do not try to generate
those fact tables, but do record the presence of the error.
Don't do work that is now done in fact_table.m.
Reorder several argument vectors to put bigger/slower-moving inputs
first.
compiler/hlds_pred.m:
Provide a mechanism for add_pragma to record the presence of those errors.
compiler/typecheck_errors.m:
If a predicate has a fact_table for it, then its clauses (actually,
foreign_procs) are supposed to be provided by the compiler;
the absence of user-supplied clauses is to be expected.
If, due to incompatibility between the predicate's declarations
and the requirements of fact tables, the compiler cannot generate
those foreign_procs, do not generate an error message about
the absence of clauses, since such an error message would be misleading.
The problem *will* be reported by fact_table.m.
compiler/hlds_out_pred.m:
compiler/intermod.m:
compiler/table_gen.m:
Conform to the change in hlds_pred.m.
compiler/export.m:
Note the fact that fact_table.m now contains cut-down versions
of two of the predicates here.
tests/invalid/bad_fact_table_decls.{m,err_exp}:
A new test case testing the error messages involving problems
with the type and mode declarations of fact table predicates.
tests/invalid/bad_fact_table_data.{m,err_exp}:
tests/invalid/fact_table_data_file_x:
A new test case testing the error messages involving problems
with the contents of fact table files.
tests/invalid/Mmakefile:
Enable the two new test cases.
34 lines
956 B
Mathematica
34 lines
956 B
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module bad_fact_table_data.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module bool.
|
|
:- import_module list.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
main(!IO) :-
|
|
( if table_x(0, 1.1, "c") then
|
|
io.write_string("yes", !IO)
|
|
else
|
|
io.write_string("no\n", !IO)
|
|
).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- pred table_x(int, float, string).
|
|
:- mode table_x(in, in, in) is semidet.
|
|
:- pragma fact_table(pred(table_x/3), "fact_table_data_file_x").
|
|
|
|
%---------------------------------------------------------------------------%
|