Files
mercury/tests/hard_coded/foreign_enum_switch.m
Zoltan Somogyi 0c87e77334 Fix a bug that caused an abort of the MLDS code generator when it was given a
Estimated hours taken: 1
Branches: main

Fix a bug that caused an abort of the MLDS code generator when it was given a
switch on a value of a foreign enum.

compiler/ml_switch_gen.m:
	The bug was caused by the fact that the code that handles switches
	handled only two kinds of tags (ints and strings), and did not list
	the kinds of tags it did NOT handle. Change that to handle foreign
	tags, and switch to using a switch instead of an if-then-else chain
	to prevent the problem from recurring in the future.

compiler/options.m:
	Add an option to allow the configure script to recognize the presence
	of the fix, since we can't add code to the compiler that switches on
	foreign enums unless the fix is installed.

tests/hard_coded/foreign_enum_switch.{m,exp}:
	A new test case to test the fix.

tests/hard_coded/Mmakefile:
	Enable the new test case.
2007-09-07 09:56:05 +00:00

64 lines
1.4 KiB
Mathematica

%-----------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%-----------------------------------------------------------------------------%
%
% Test switches on foreign enum types.
%
%-----------------------------------------------------------------------------%
:- module foreign_enum_switch.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module int.
:- import_module list.
:- import_module string.
main(!IO) :-
p(foo, Out1),
io.write_int(Out1, !IO),
io.nl(!IO),
p(bar, Out2),
io.write_int(Out2, !IO),
io.nl(!IO),
p(baz, Out3),
io.write_int(Out3, !IO),
io.nl(!IO).
:- pragma no_inline(p/2).
:- pred p(t::in, int::out) is det.
p(foo, 42).
p(bar, 43).
p(baz, 44).
:- type t
---> foo
; bar
; baz.
:- pragma foreign_decl("C", "
#define CONSTANT1 300
#define CONSTANT2 400
#define CONSTANT3 500
").
:- pragma foreign_enum("C", t/0,
[
foo - "CONSTANT1",
bar - "CONSTANT2",
baz - "CONSTANT3"
]).
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%