tests/hard_coded/backend_external.m:
tests/hard_coded/backend_external_pred.m:
tests/hard_coded/c_write_string.m:
tests/hard_coded/ee_dummy.m:
tests/hard_coded/pragma_c_code.m:
tests/hard_coded/pragma_foreign_export.m:
tests/hard_coded/target_mlobjs.m:
tests/hard_coded/type_tables.m:
tests/submodules/sm_exp_bug.m:
Use don't-care variables to handle the I/O state in foreign procs.
Assigning the I/O state at the end of the foreign_proc body results
in spurious warnings about uninitialized variables from MSVC.
Fix a test failure in spf grades.
tests/hard_coded/backend_external.m:
tests/hard_coded/from_int_uint32.m:
tests/hard_coded/parse_number_from_io.m:
tests/hard_coded/remove_file.m:
tests/hard_coded/uint_arith.m:
As above.
tests/hard_coded/parse_number_from_io.exp4:
Alternative expected output for spf grades.
compiler/parse_item.m:
Don't accept `:- external' items.
compiler/prog_item.m:
Require the presence of a pred_or_func flag on external pragmas.
They are specified by `:- pragma external_{pred/func}' pragmas,
which are still supported.
compiler/parse_pragma.m:
When parsing external_{pred/func} pragmas, allow the predicate name
to contain a module qualifier; they were allowed on `:- external' items.
We do require the module qualifier to specify the expected (i.e. the
current) module.
compiler/add_pragma.m:
compiler/parse_tree_out_pragma.m:
compiler/recompilation.version.m:
Conform to the changes above.
tests/hard_coded/backend_external.m:
tests/hard_coded/constant_prop_2.m:
tests/invalid/external.err_exp:
tests/invalid/external.m:
tests/invalid/io_in_ite_cond.err_exp:
tests/invalid/io_in_ite_cond.m:
tests/invalid/overloading.m:
tests/invalid/tricky_assert1.m:
tests/invalid/type_spec.err_exp:
tests/invalid/type_spec.m:
tests/invalid/uniq_neg.err_exp:
tests/invalid/uniq_neg.m:
tests/valid/dcg_test.m:
tests/valid/inst_perf_bug_1.m:
tests/valid/lambda_recompute.m:
tests/valid/semidet_disj.m:
tests/valid/solv.m:
tests/valid/solver_type_bug.m:
tests/valid/stack_alloc.m:
tests/valid/tricky_assert2.m:
Replace `:- external' items with external_{pred/func} pragmas.
Modernize the code where needed, replacing DCGs with state variables.
We used to have only the first of these three forms, we now have all three:
:- external(low_level_backend, a/2).
% declared pred a/2 and func a/2 to be external on llds
:- pragma external_pred(a/2, [low_level_backend]).
% declared pred a/2 (and NOT func a/2) to be external on llds
:- pragma external_func(a/2, [low_level_backend]).
% declared func a/2 (and NOT pred a/2) to be external on llds
The new forms allow for more precise control of what is declared to be
external. The difference in syntax (the options coming after the name,
and the options being in a list, even though this pragma allows only
one option at present) are to fit in with the style of the other pragmas.
Of course, the backend does not have to be specified, so these are
also allowed:
:- pragma external_pred(a/2).
:- pragma external_func(a/2, []).
Using `:- external' declarations is for implementors only, since using it
requires writing target language code by hand in a way that conforms to all
the compiler's conventions for e.g. symbol naming and parameter passing.
It is not a documented part of Mercury. Therefore the new external_{func,pred}
pragmas are not documented either.
compiler/prog_item.m:
Change the representation of the `:- external' declaration from being
a module_defn to being a pragma. Generalize it to allow the new pragmas,
by allowing the recording of an option pred_or_func indication.
Add a function that returns a description of a pragma for use as a context
in error messages. We need this to avoid confusing users by having an
error message refer to a `:- external' declaration when they wrote e.g.
`:- pragma external_pred', or vice versa.
compiler/add_pragma.m:
Move the code for handling external declarations from make_hlds_passes
(which handles module_defns) to this module (which handles pragmas),
and update it.
Execute this code in pass 2, not pass 1, since we need to record
the "external" flag in the pred_info, and that is created in pass 1.
(I think this worked in the past ONLY if the declaration of the affected
predicate or function came textually before the `:- external' declaration.)
compiler/make_hlds_passes.m:
Remove the code that is now in add_pragma.m (in adapted form).
compiler/prog_io_item.m:
Change the code for parsing old-style `:- external' declarations to
generate the new pragma internally.
compiler/prog_io_pragma.m:
Add code for parsing the new pragmas.
compiler/equiv_type.m:
compiler/item_util.m:
compiler/mercury_to_mercury.m:
compiler/module_imports.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/recompilation.version.m:
compiler/write_module_interface_files.m:
Conform to the changes above.
compiler/make_hlds_error.m:
Improve a variable name.
compiler/pred_table.m:
Improve the documentation of several predicates.
tests/hard_coded/backend_external.m:
Improve the documetation of this old test case, which tests the
handling of backend-specific `:- external' declarations.
tests/hard_coded/backend_external_{func,pred}.m:
Two copies of the old backend_external.m test case, which test the
handling of backend-specific `:- pragma external_func' and
`:- pragma external_pred' declarations respectively.
tests/hard_coded/backend_external_func.exp:
tests/hard_coded/backend_external_pred.{exp,exp2}:
The expected outputs of the new test cases.
tests/hard_coded/Mmakefile:
Enable the new test cases.
tests/invalid/type_spec.err_exp:
Expect an error message for a `:- external' declaration in the interface
of type_spec.m. Since declaring a procedure to be external is in essence
a representation of the implementation of that procedure, the previous
absence of an error message for this implementation detail in the interface
was a bug.
tests/invalid/external.err_exp:
We always generated an error for a `:- external' declaration that
did not specify an arity, but the text of the error message used to say
"warning", not "error" (even though the severity level was "error").
Expect the corrected error message.
tests/invalid/not_in_interface.err_exp:
Expect the updated, more precise form of an error message.
vim/syntax/mercury.vim:
Add the two new keywords.
tests/accumulator/*.m:
tests/analysis_*/*.m:
tests/benchmarks*/*.m:
tests/debugger*/*.{m,exp,inp}:
tests/declarative_debugger*/*.{m,exp,inp}:
tests/dppd*/*.m:
tests/exceptions*/*.m:
tests/general*/*.m:
tests/grade_subdirs*/*.m:
tests/hard_coded*/*.m:
Make these tests use four-space indentation, and ensure that
each module is imported on its own line. (I intend to use the latter
to figure out which subdirectories' tests can be executed in parallel.)
These changes usually move code to different lines. For the debugger tests,
specify the new line numbers in .inp files and expect them in .exp files.
Estimated hours taken: 0.5
Branches: main
tests/hard_coded/backend_external.m:
Fix this test in the hl* grades by shifting an #endif that is
in the wrong spot. (It looks as though this has always been
in the wrong place but has only started showing up because of
the recent changes to mkinit.)
Eliminate warnings from the C compiler on 64-bit architectures.
Estimated hours taken: 10
Branches: main
Provide a mechanism to allow a predicate to be defined as a foreign_proc for
one backend and as external for another backend. The intended use is to
implement builtin_catch in exception.m, which cannot be implemented as a
foreign_proc for hlc grades, but whose implementation as external for the
LLDS grades requires handwriting extremely error-prone code and data structures
that the compiler could generate reliably.
The mechanism is two language extensions. One allows :- external declarations
such as
:- external(high_level_backend, p/3).
The second allows foreign_procs such as
:- pragma foreign_proc("C",
p(N::in, IO0::di, IO::uo),
[will_not_call_mercury, promise_pure, low_level_backend],
...
compiler/prog_data.m:
Add an extra field to the items for `:- external' declarations to
allow hold the optional backend designation.
Add an extra optional attribute to foreign_procs to handle the
backend designation.
compiler/prog_io_pragma.m:
Change the code for reading external declarations to handle the new
attribute.
compiler/prog_io_pragma.m:
Change the code for reading foreign_proc attributes to handle the new
attribute.
compiler/make_hlds.m:
Ignore external declarations and foreign_proc definitions if they are
for the wrong backend.
Use state variables in a place that can benefit from it.
compiler/hlds_module.m:
Clean up some formatting.
compiler/equiv_type.m:
compiler/ml_code_gen.m:
compiler/module_qual.m:
compiler/modules.m:
Conform to the changed data structures in prog_data.
doc/reference_manual.texi:
Add commented-out documentation of the extension to foreign_procs.
There is no existing documentation of :- external to update.
tests/hard_coded/backend_external.{m,exp,exp2}:
New test case for the new language extensions.
tests/hard_coded/Mmakefile:
Enable the new test case.