Files
mercury/tests/hard_coded/backend_external.exp
Zoltan Somogyi 99af5e671a Provide a mechanism to allow a predicate to be defined as a foreign_proc for
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.
2005-03-10 02:36:04 +00:00

3 lines
88 B
Plaintext

p(1): expected lowlevel, found lowlevel, OK
q(2): expected lowlevel, found lowlevel, OK