live_vars.nl:
added code to reuse stack slots.
This algorithm is only preliminary. An algorithm to use
standard graph colouring techniques should replace this
eventually.
code_info.*, call_gen.*:
minor modifications so that stack slot reuse works.
switch_gen:
generate code to test primary tags from most shared to least shared.
frameopt:
separated out the pass that removes superfluous saves of succip.
llds, opt_debug:
added two new unary operators, unmktag and unmkbody, that reverse
the effects of mktag and mkbody.
graph, value_number:
fixed occurrences of implied modes.
code_info:
fixed a spelling error in a comment.
*** Tom, please fix the mismatch in the names of the unification procedures.
code_info.nl:
Improve an error message.
followcode.nl:
Add a comment.
hlds_out.nl:
Output ":=", "==", or "=" for the different types of unifications.
======> READ THIS: <======
(Known bug: the order of the operands for ":=" is wrong.)
make_hlds.nl, unify_proc.nl:
Make complicated unifications work!
code_info.nl:
fix the livevals stuff so that it includes saved heap pointers
(etc) in the set of livevals.
mercury_compile.pp:
rename a variable (trivial change)
term.nl:
enforce the invariant that new variable numbers should be
unique. This costs, but if we don't to it, it will kill us
one day.
value_number.nl:
a lot less functionality is missing now :-)
atsort.nl:
approximate topological sort for value numbering
opt_*.nl:
changes to supprt value numbering
llds.nl, *_gen.nl:
changed livevals/1 into livevals/2 to support value numbering
list.nl:
added a predicate to delete a list (set) of items from a list
peephole.nl:
implement shortcircuiting inside computed goto label lists. Not tested
since the only place we use computed gotos has no opportunities for
short circuiting.
options.nl:
added option to control the maximum number of repetitions of
the peephole optimizations; default value is 2.
dir.nl:
fixed spelling error
Makefile*:
Add some more stuff for compiling to .o
Makefile*, mercury_compile*, code_gen*:
Add some stuff for handling `.pp' files.
`.pp' files are Mercury source code containing
NU-Prolog hacks inside
#if NU_PROLOG
...
#endif
These hacks are preprocessed out (using sed, not cpp)
except when compiling with `mnc'.
term_io.nl, term_io.nu.nl, interpreter.nl, prog_out.nl:
Make sure all the predicates in term_io.nl are
prefixed with `term_io__', not `io__'.
term_io.nl, require.nl:
Add some `external' declarations.
call_gen.nl, unify_gen.nl:
A temporary hack - generate incorrect code for complicated/polymorphic
unifications, rather than aborting.
random.nl:
Make the code more efficient.
hlds.nl, term.nl:
Allocate pred_ids and variable numbers randomly rather than
sequentially, so that the binary trees remain reasonably balanced.
code_info.nl, unify_gen.nl, hlds_out.nl:
Generate informative comments for tag tests: say the name of
the variable being tested, and which constructor we are testing for.
llds.nl:
Cast field() expressions to (int) when used as rvals, so
that comparisons work as expected.
make_hlds.nl:
Improve error reporting.
code_info.nl, call_gen.nl, code_gen.nl:
fixes to the generation of livevals. These should
work _about_ right. zs?
re-add some of the declarations that I zapped on
fergus' advice. :-)
code_info.nl, mercury_to_mercury,
Fix a couple of typos - in string literals.
interpreter.nl:
Fix determinism error.
io.nl, io.nu.nl:
A large-scale reorganization of the I/O handling,
so that I can more easily re-implement the NU-Prolog
parts in C. `io__see' is now implemented using `io__open_input'
rather than vice versa. Added `io__open_append'.
list.nl:
Implement merge/3, member/3, reverse/2, and sort/2 in Mercury
rather than using the NU-Prolog versions.
XXX Note that it is not possible to implement length/2 in
Mercury in a way that is deterministic in both forwards
and backwards modes!
modes.nl:
Fix a mode error - the Mercury mode analysis didn't detect
this one, since it would have reordered the code to be
correct! I can't wait until we bootstrap ;-)
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).
call_gen.nl:
Make the handling of builtins a little more general.
code_info.nl, unify_gen.nl:
Use code_info__get_next_label_number rather than
the lower-level routines code_info__get_label_count
and set_label_count.
code_util.nl:
Rame atom_to_operator as code_util__atom_to_binop
and add code_util__atom_to_unop.
prog_io.nl, code_util.nl, llds.nl, int.nl, opt_debug.
Add bitwise operators.
Add array_index binary operator.
Add hash_string unary operator.
Add int__log2 predicate.
Cast operands to (int) in llds.nl, so that we
get integer comparisons and integer operations.
string.nl:
Add string__hash predicate.
interpreter.nl:
Use disjunction in semidet preds.
options.nl:
Add --smart-indexing option (enabled by default).
switch_gen.nl:
**** Generate a hash table lookup for string switches. ****
opt_util.nl:
Fix determinism error which was due to the lack of multi-level
indexing.
code_info.nl:
A very minor code simplification.
switch_gen.nl:
Generate better code for switches on atomic types.
We now use jump tables in more cases.
(This speeds up `crypt' by about 0.4% - not much).
code_{gen,info}.nl, llds.nl, peephole.nl:
changed the argument of the livevals instr from list to bintree_set
code_{gen,info}.nl:
we now generate livevals even if value numbering isn't being done,
since the new peephole optimizations work better this way
opt_util.nl:
made the code that deletes unwanted livevals info more robust
llds.nl:
Get rid of the "unused" rval, since it doesn't have any well-defined
semantics (as far as I can tell) and we don't need it. The only
thing it is used for is for fields of create() instructions which
do not need to be initialized, and I changed create() to take
a list(maybe(rval)) rather than a list(rval).
code_info.nl:
Get rid of register_status "unused" and variable_status "unused",
since they aren't needed.
Fix *some* of the (probably many) bugs with remembering
register contents and variable locations.
Change code_info__generate_expression_vars(var(Var), ...)
to just call code_info__produce_variable.
In shuffle_register, fix the test for determining whether
we need to swap the old value out by combining the test
for arguments and the test for live variables into a single
test. I had to disable this fix, because it triggers the
aforementioned bugs with remembering variable locations.
Change generate_livevals so that it doesn't do anything unless
the --peephole-value-number option has been set.
Slightly simplify the instruction sequence generated for
create() expressions.
peephole.nl, opt_util.nl:
Move peephole__instr_labels to opt_util.nl.
typecheck.nl:
A couple of extremely minor formatting changes.
code_info.nl, llds.nl, unify_gen.nl, options.nl:
Add a new option --static-ground-terms, which is enabled by default,
for generating ground terms at compile time and emitting a static
constant.
code_gen, code_info, call_gen llds:
Add the livevals instruction type and get the code generator
to emit livevals instructions just before calls and proceeds.
WARNING WARNING WARNING
These changes break the peephole optimiser.
Makefile.mercury:
- Add another rule to suppress the default Modula-2 rule.
- Remove the rule for making *_init.c; this has to be done
manually by the user's makefile, since the necessary
information isn't available here.
- Change the default MOD2INITFLAGS to -wmercury__main_predicate_3_0.
*_gen.nl, code_info.nl:
Generate fail() rather than redo() if we know the redoip
must point to do_fail.
*_gen.nl, code_info.nl:
Added a new pred code_info__produce_variable, which combines
flush_variable and variable_get_register, except that it
returns an rval rather than an lval. The idea is
that using produce_variable means we don't have to store
constants in registers before we can use them.
code_info.nl:
Avoid generate some unnecessary register shuffles.
mercury_compile.nl, Makefile.mercury.
Add some gross hackery to do manual memory management
with NU-Prolog. Up the -u option to 1200.
Makefile.common:
Add a reminder about fixing the permissions
code_info.nl:
Fix some determinism errors introduced by adding new
llds instruction types.
det_analysis.nl:
Count the number of determinism errors in the code
and pass this back to the top-level, so that we
don't attempt to compile code which contains determinism errors.
For if-then-elses with a deterministic condition,
optimize the else part away. This prevents the code
generator from getting confused when the else part is semidet
but the if-then-else as a whole is det.
hlds.nl, make_hlds.nl:
Change the predicate_table so that it allows more than
one predicate with the same module, name, and arity.
Move the checking for duplicate preds from hlds.nl to make_hlds.nl.
This is so we can insert automatically generated unification
predicates, which must be overloaded, into the predicate_table.
hlds.nl:
Add a few comments.
mercury_compile.nl:
Split mercury_compile/7, which was becoming huge, into
about a dozen smaller predicates.
Ensure that we report the memory/time usage statistics
after every pass.
mercury_to_mercury.nl, modes.nl, typecheck.nl, prog_io.nl:
Fix some determinism errors.
(There are still 6 determinism errors that remain, 5 in
mercury_compile and 1 in prog_io. These are caused
by calls to io__gc_call, because we haven't yet implemented
mode analysis for higher-order preds.)
llds.nl, code_info.nl, call_gen.nl, peephole.nl:
changed if_val so that its second argument can be either
goto(Label), fail or redo.
value_number.nl:
minor fix.
lots of files:
Make a start at implementing code generation for complicated
unifications. In the HLDS, change complicated_unify/4 to
complicated_unify/2 since we didn't need the extra two args
after all.
peephole.nl:
A couple of minor efficiency improvements.
queue.nl:
Add queue__queue_to_list/2.
list*:
added list__split3 which matches a list with a head and a
tail and returns the middle.
code_info.nl, disj_gen.nl:
patch things so that the first disjunct uses the registers
not the framevars.
*Makefile*:
Ensure that Makefile.mercury can be used as a generic
Makefile for Mercury programs. It now gets included by the
Makefiles in the tests/ directory.
(It's highly likely that these changes have broken something.)
code_util.nl, peephole.nl, code_info.nl:
Move peephole__neg_rval to code_util.nl, so that it can
also be used by code_info.nl. Improve it a bit.
disj_gen.nl:
Minor stylistic changes.
peephole.nl:
Use bintree_set(label) rather than map(label, bool).
ite_gen.nl:
Implement non-deterministic if-then-elses.
mercury_compile.nl:
Change the action in the automatically generated .dep makefile
to use `$(MNL)' rather than `$(NC)' to link the `.no' files
together.
mode_util.nl, mode_info.nl:
Fix some (recently detected) determinism errors.
options.nl:
Rearrange the options into a vaguely meaninful order and
add a couple of comments.
Makefile:
Install ml.sh.
*_gen.nl, code_info.nl:
Reorganize the handling of failure continuations and mixing
det/semidet/nondet code in the one procedure.
It should now work! ;-)
The category_context field has gone away.
The fall_though field is now a stack(maybe(label)) rather
than a stack(label). If Cont = yes(label), then we
fail by jumping to that label. If Cont = no, then we
fail by executing a redo(). Whenever we create a semidet
choice point, we just push a failure continuation label.
Whenever we create a nondet choice point, we do two things:
(1) generate code which does a `modframe()'
(2) push a failure continuation label
The failure continuation records what value is currently in the
redoip. This allows us to short-circuit redo() instructions
into direct jumps. Whenever we get to a nondet goal, we change
the current failure continuation to `no', since the nondet goal
might have left some choice points behind.
(TODO: The same sort of mechanism would allow us to optimize `redo()'
to `fail()' but we don't do that yet; also currently we generate
quite a few unnecessary modframe() instructions.)
`generate_[i]cond_branch' has gone away.
Instead, push a failure continuation and then call
generate_test_and_fail.
code_util.nl, llds.nl:
Fix newly discovered determinism errors.
code_info.nl, live_vars.nl:
framevars start at 0, not at 1!!!
backtracked over contains a construction unification or a
non-builtin call. Add code to save/restore the heap pointer
in one or two places where this was missing, e.g. semidet disjunctions.
Change switch/2 into switch/3 so that we can store the `local
determinism' of the switch there, rather than in the goal_info.
Fix code generation for semidet/nondet switches, so that
we omit the test for the last case if the switch is locally
det.
llds.nl, code_info.nl, unify_gen.nl, call_gen.nl:
RISC-ify the LLDS instruction set: remove the if_tag, if_not_val,
and test instructions, replacing them all with new uses of if_val.
arg_info.nl, call_gen.nl, code_gen.nl, live_vars.nl, hlds.nl:
Add a new pred proc_info_interface_determinism and
ensure that it is called from the appropriate places.
code_gen.nl:
Improve the code generation for commits (don't bother
to restore maxfr if the goal fails, since maxfr won't
have been modified).
llds.nl:
Add a generate way of inserting arbitrary C code in the LLDS.
switch_gen.nl, code_info.nl:
Generate correct code for switches whose determinism has
incorrectly been inferred as det.
disj_gen.nl, code_info.nl, code_gen.nl:
Remove the optimization of mkframe()/modframe() for the
first continuation, since it was broken.
hlds_out.nl:
Write the instmap deltas out on separate lines.
liveness.nl:
Fixed bugs in processing of if_then_elses.
live_vars.nl:
Fixed a bug in the processing of if_then_elses.
mode_util.nl:
Fix the recompute_instmap_delta so that it restricts the
instmap_delta to the non-local variables for the goal.
unify_gen.nl:
Implement string equality tests.
llds.nl:
Remove some unnecessary parentheses in the output.
Handle string equality.
code_info.nl:
Change the way code_info__push_rval and pop_lval work, so
that they just record the amount of space used, rather than
actually adjusting the stack pointer.
code_gen.nl:
Call code_info__total_stackslots rather than code_info_stackslots,
so that space for pushes and pops is allocated in the procedure
prolog.
disj_gen.nl:
Reclaim heap space on backtracking.
*.nl:
Rename globals__lookup*option as globals__io_lookup*option.
Create new globals__lookup*option predicates.
Fix up the option handling in the code generator.
code_gen.nl, code_info.nl, disj_gen.nl, ite_gen.nl, switch_gen.nl:
Various bug fixes for non-deterministic code.
(nqueens now works! ;-)
live_vars.nl:
Bug fix: initial liveness should be {input vars} not {output vars}.
(Apologies from Thomas ;-).
llds.nl:
Couple of minor bug fixes. Added code to output redo().
io.nl, portray.nl, prog_io.nl, std_util.nu.nl, term_io.nu.nl:
Change X.Xs into [X|Xs].
swi_builtin.nl, doit.pl:
Add some support for SWI-Prolog.
set.nl, stack.nl:
Suppress bogus SWI-Prolog singleton variables warnings in
type declarations.
term_io.nu.nl:
Remove some of the dependences on NU-Prologisms.
code_gen.nl, call_gen.nl:
Implement calls to nondet goals from semidet contexts (by
generating a commit).
Reduce the amount of cut-and-paste duplication in
generate_category_goal.
code_info.nl:
Add predicates to generate commits.
Fix a bug in store_map handling.
Fix a bug in code_info__generate_failure (I think the fix may
have introduced a different bug, because compiling qdelete now
results in a C compiler error: reference to an undefined label).
llds.nl:
Add the `curredoip' and `maxfr' registers (so that we can implement
commit).
code_gen.nl code_info.nl:
Fix assumptions about where variables go at the end of switches.
Add StoreMap.
live_vars.nl store_alloc.nl:
Passes to compute the stack allocations, and the "known" locations
for variables.
hlds.nl:
Add fields to procinfo for stack allocations.
options.nl:
Add options for eager and lazy code generation.
Eager code generation is still mostly untested. Its
even possible that there are unimplemented preds!
llds.nl:
Print the code in a slightly nicer format.
call_gen.nl, code_gen.nl, code_info.nl:
Combine the code for setting up input arguments in calls with the
code for seting up output unifications in the procedure epilogue
(which hopefully fixed a bug in the latter).
disj_gen.nl:
Fix a bug with label assignment in nested disjunctions,
tidy up the code a bit, and avoid generating some redundant
jumps-to-jumps.
code_info.nl ite_gen.nl unify_gen.nl
Generate code with field numbers 0.... rather than 1....
Add stuff for heap reclaiming on failure.
Add options in code generation (not patched through to the
top levels of the compiler yet.
liveness.nl:
fix some bugs.
options.nl mercury_compile.nl:
Add some options for follow[code|vars].
dir.nl:
Add a new library module for file and directory name handling.
string.nl, list.nl:
Add a bunch of new preds.
code_info.nl:
list__nth_member_lookup has been renamed list__index1_det.
io.nu.nl:
Change io__progname so that it uses the new dir__basename.
prog_io.nl:
Fix the type error left in my last change to prog_io.nl.
Change a few XXX comments, since the things they comment
about are wishlist items, not XXX-level problems.
ite_gen.nl, code_info.nl:
Fix determinism problem.
code_gen.nl code_info.nl disj_gen.nl:
More work on nondet code generation. Apart from problems with
implied modes which need to be dealt with, path/2 is correctly
generated.
liveness.nl:
Fix bugs in the generation of liveness information for
if-then-else constructs in the presence of erroneous predicates.
code_info.nl, *_gen.nl:
Bugfixes. Implement the basics of nondeterministic code.
Lots of cases still not handled, but look, you've got to
start somewhere :-)
liveness.nl:
Fix bugs shown up by the follow* transformations.
llds.nl:
Add a few extra things for nondeterministic code.
liveness.nl:
Fixed the handling of liveness in the presence of erroneous
predicates. Bug was shown up by the followcode/followvars
transformation.
*_gen.nl code_info.nl:
Bugfixes. Laid some of the groundwork in preparation for
nondeterministic code generation (long live bottom up design!)
hlds_out.nl:
Minor improvements to the output.
code_info.nl, type_util.nl:
Change make_type_id to fail rather than call error/1
if the type is not valid.
undef_types.nl:
Report invalid types.
mode_util.nl:
Add a new pred `type_constructors'.
modes.nl:
Detect determinism of deconstruction unifications properly,
using the type information.