mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-19 07:45:09 +00:00
Makefile.mercury: Override the MERCURY_LIB_OBJS variable when invoking ml. This avoids some bootstrapping problems. Also, add mercury_compile.nu. Makefile.common: Bump NU-Prolog's -u option up to 2000 (8M), to avoid some memory problems. array.nl, bintree.nl, char.nl, dir.nl, globals.nl, list.nl, map.nl, modes.nl, prog_util.nl, stack.nl, std_util.nl, string.nl, term.nl: Avoid the use of implied modes. code_info.nl, bimap.nl, make_hlds.nl, mercury_compile.nl, mercury_to_mercury.nl, unify_proc.nl: Fix determinism errors which had previously not been discovered because of either implied modes or running out of memory. (Note that I had to change the interface to bimap__lookup, since it's not possible to make it bidirectional.) code_util.nl, llds.nl, opt_debug.nl, value_number.nl: Rename `operator' as `binary_op'. hlds.nl, code_info.nl, unify_gen.nl, llds.nl, opt_debug.nl, switch_gen.nl: *** Handle simple cases of higher-order pred terms. *** (We don't yet handle taking the address of an overloaded predicate or a predicate with multiple modes. We don't handle closures. call/1 and call/N are not yet implemented. This has not yet been tested.) make_hlds.nl: Modify the mode priority ordering so that semidet modes get selected before det ones. llds.nl: Don't include the priority part of the mode number in the mangled label name. *** Note: this will break some things! *** mercury_compile.nl: Move the NU-Prolog hacks into mercury_compile.nu.nl. switch_gen.nl: Fix a simple logic bug in handling the grab/slap of the code_info. prog_io.nl, builtins.nl, int.nl: Fix bugs and omissions with handling of the new arithmetic operators. prog_io.nl: As a quick hack, strip off calls to io__gc_call (this avoids spurious error messages which are due to the fact that we don't get mode analysis right in those cases).
101 lines
2.7 KiB
Mathematica
101 lines
2.7 KiB
Mathematica
%--------------------------------------------------------------------------%
|
|
%--------------------------------------------------------------------------%
|
|
|
|
% File: stack.nl.
|
|
% Main author: fjh.
|
|
|
|
% This file contains a `stack' ADT.
|
|
% Stacks are implemented here using lists.
|
|
|
|
%--------------------------------------------------------------------------%
|
|
|
|
:- module stack.
|
|
:- interface.
|
|
:- import_module int.
|
|
|
|
:- type stack(_T).
|
|
|
|
% `stack__init(Stack)' is true iff `Stack' is an empty stack.
|
|
|
|
:- pred stack__init(stack(_T)).
|
|
:- mode stack__init(out) is det.
|
|
|
|
% `stack__is_empty(Stack)' is true iff `Stack' is an empty stack.
|
|
|
|
:- pred stack__is_empty(stack(_T)).
|
|
:- mode stack__is_empty(in) is semidet.
|
|
|
|
% `stack__is_full(Stack)' is intended to be true iff `Stack'
|
|
% is a stack whose capacity is exhausted. This
|
|
% implement allows arbitrary-sized stacks, so stack__is_full
|
|
% always fails.
|
|
|
|
:- pred stack__is_full(stack(_T)).
|
|
:- mode stack__is_full(in) is semidet.
|
|
|
|
% `stack__push(Stack0, Elem, Stack)' is true iff `Stack' is
|
|
% the stack which results from pushing `Elem' onto the top
|
|
% of `Stack0'.
|
|
|
|
:- pred stack__push(stack(T), T, stack(T)).
|
|
:- mode stack__push(in, in, out) is det.
|
|
|
|
% `stack__top(Stack, Elem)' is true iff `Stack' is a non-empty
|
|
% stack whose top element is `Elem'.
|
|
|
|
:- pred stack__top(stack(T), T).
|
|
:- mode stack__top(in, out) is semidet.
|
|
|
|
% `stack__pop(Stack0, Elem, Stack)' is true iff `Stack0' is
|
|
% a non-empty stack whose top element is `Elem', and `Stack'
|
|
% the stack which results from popping `Elem' off `Stack0'.
|
|
|
|
:- pred stack__pop(stack(T), T, stack(T)).
|
|
:- mode stack__pop(in, out, out) is semidet.
|
|
|
|
% `stack__pop_det' is like `stack__pop' except that it will
|
|
% call error/1 rather than failing if given an empty list.
|
|
|
|
:- pred stack__pop_det(stack(T), T, stack(T)).
|
|
:- mode stack__pop_det(in, out, out) is det.
|
|
|
|
% `stack__depth(Stack, Depth)' is true iff `Stack' is a stack
|
|
% containing `Depth' elements.
|
|
|
|
:- pred stack__depth(stack(_T), int).
|
|
:- mode stack__depth(in, out) is det.
|
|
:- mode stack__depth(in, in) is semidet. % implied
|
|
|
|
%--------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module list, require.
|
|
|
|
:- type stack(T) == list(T).
|
|
|
|
stack__init([]).
|
|
|
|
stack__is_empty([]).
|
|
|
|
stack__is_full(_) :- fail.
|
|
|
|
stack__push(Stack, Elem, [Elem | Stack]).
|
|
|
|
stack__top([Elem | _], Elem).
|
|
|
|
stack__pop([Elem | Stack], Elem, Stack).
|
|
|
|
stack__pop_det(Stack0, Elem, Stack) :-
|
|
( Stack0 = [Elem1 | Stack1] ->
|
|
Elem = Elem1,
|
|
Stack = Stack1
|
|
;
|
|
error("stack__pop_det: pop from empty stack")
|
|
).
|
|
|
|
stack__depth(Stack, Depth) :-
|
|
list__length(Stack, Depth).
|
|
|
|
%--------------------------------------------------------------------------%
|