mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-15 22:03:26 +00:00
Estimated hours taken: 2 Fix bugs which caused compilation of Tom Conway's XML parser to fail during deforestation. compiler/inlining.m: If some of the output variables of an inlined call are not used by the caller, run quantification on the goal to push that information into the inlined goal. compiler/modes.m: compiler/unique_modes.m: When a unification with a dead variable is replaced with `true', make sure the instmap_delta of the goal is empty. tests/valid/Mmakefile: tests/valid/deforest_bug.m: Test case.
91 lines
2.1 KiB
Mathematica
91 lines
2.1 KiB
Mathematica
:- module deforest_bug.
|
|
|
|
:- interface.
|
|
|
|
:- type catalog ---> catalog(publicId -> systemId).
|
|
|
|
:- type [] ---> [].
|
|
:- type [T1|T2] == list(T1).
|
|
:- type (A -> B) == map(A, B).
|
|
|
|
:- type dirs == [path].
|
|
|
|
:- type publicId == string.
|
|
|
|
:- type systemId == string.
|
|
|
|
:- type path == string.
|
|
|
|
:- type catRes(T)
|
|
---> ok(T)
|
|
; error(string)
|
|
.
|
|
|
|
:- pred deforest_load([(int, [char])], [string], catalog).
|
|
:- mode deforest_load(in, out, out) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module char, int, list, map, std_util, string.
|
|
|
|
:- type entry
|
|
---> dtd(publicId, systemId)
|
|
; none
|
|
.
|
|
|
|
:- pragma no_inline(deforest_load/3).
|
|
deforest_load(CatLines, Errors, Cat) :-
|
|
parse(Entries, Errors, CatLines),
|
|
init(Cat0),
|
|
my_foldl(addEntry, Entries, catalog(Cat0), Cat).
|
|
|
|
:- type (A, B) ---> (A, B).
|
|
|
|
:- pred parse([entry], [string], [(int, [char])]).
|
|
:- mode parse(out, out, in) is det.
|
|
|
|
parse([], [], []).
|
|
parse(Entries, Errors, [Line|Lines]) :-
|
|
Line = (N, Cs),
|
|
( parseEntry(Entry, Cs, _) ->
|
|
Entries = [Entry|Entries0],
|
|
parse(Entries0, Errors, Lines)
|
|
;
|
|
format("%d: syntax error", [i(N)], Msg),
|
|
Errors = [Msg|Errors0],
|
|
parse(Entries, Errors0, Lines)
|
|
).
|
|
|
|
:- pred addEntry(entry, catalog, catalog).
|
|
:- mode addEntry(in, in, out) is det.
|
|
|
|
addEntry(none, Cat, Cat).
|
|
addEntry(dtd(PublicId, SystemId), catalog(Cat0), catalog(Cat)) :-
|
|
det_insert(Cat0, PublicId, SystemId, Cat).
|
|
|
|
:- pred parseEntry(entry, [char], [char]).
|
|
:- mode parseEntry(out, in, out) is semidet.
|
|
|
|
parseEntry(Entry) -->
|
|
( ['P'], string(PublicId), string(SystemId) ->
|
|
{ Entry = dtd(PublicId, SystemId) }
|
|
; =([]) ->
|
|
{ Entry = none }
|
|
;
|
|
{ fail }
|
|
).
|
|
|
|
:- pred string(string, [char], [char]).
|
|
:- mode string(out, in, out) is semidet.
|
|
:- pragma no_inline(string/3).
|
|
|
|
string("") --> { semidet_succeed }.
|
|
|
|
:- pred my_foldl(pred(T, U, U), list(T), U, U).
|
|
:- mode my_foldl(pred(in, in, out) is det, in, in, out) is det.
|
|
|
|
my_foldl(_, [], A, A).
|
|
my_foldl(P, [Head | Tail], A0, A) :-
|
|
P(Head, A0, A1),
|
|
my_foldl(P, Tail, A1, A).
|