tag_switch:
Fixed two bugs. First, if a primary tag value did not have cases for
all its secondary tag values, we now emit a goto the failure label
if the secondary tag does not match any case; we used to just fall
through. Second, the failure code itself used to be generated in
the context of the end of one of the cases; this should now be fixed,
although I want to go over it with Tom to make sure.
The computation of the secondary tag is now done once, instead of
being repeated at every secondary tag test.
options:
Set tag_switch_size to 4 by default, reduced from 8. It was this change
that exposed the two bugs above. After the fix, the compiler is smaller
by about 2 Kb.
switch_gen:
Add some comments.
code_util:
Fixed nonstandard indentation.
compiler/Mmake:
Add EXTRA_MLFLAGS variable, so that you can set
EXTRA_MLFLAGS=--no-strip if you want to preserve
the debugging info.
code_util.m, polymorphism.m, hlds.m, special_pred.m:
Move the stuff dealing with special_preds from hlds.m into
a new module special_pred. Add a new predicate special_pred_get_type
to that module, and use it in code_util.m and polymorphism.m
(replacing some fairly non-maintainable hacks).
make_hlds.m, unify_proc.m:
Import special_pred.m.
instructions, and the last argument from local labels. All these were
placeholders for info put in there by prof.m and used when emitting C
code.
The set of labels that serve as return points are now calculated in llds.m
just before each procedure has its C code generated. This set is passed to
output_instruction along with the label at the start of the procedure.
Lambda expressions now work, and you can now use polymorphic predicates
as higher-order pred terms. (Mode checking and determinism checking
are still not implemented, and the modes of call/N are very restrictive.
But these change makes solutions/2 a lot more useful now.)
hlds.m:
Comment out the stuff for recording num_warnings, since it
wasn't being used. Instead we now use that slot in the
module_info for a counter which holds a number to use to
name the predicates for lambda expressions. Add a new
predicate module_info_next_lambda_count/3 to get and
increment this counter.
modes.m:
Transform higher-order pred constants into lambda expressions.
(Also, use slightly more meaningful variable names in a few places.)
polymorphism.m:
Use module_info_next_lambda_count/3 to name the predicates
created for lambda expressions.
code_util.m:
Handle __LambdaGoal__ labels correctly.
context of the unification from which call was made. We we use this to generate
significantly better error messages. (There should be no more messages of the
form "call to __Unify__(blah blah blah) can fail".) Most of the files are
changed just to reflect this.
An unrelated change in det_analysis is that we now ensure the absence of
cycles by modifying the new inferred determinism in the light of the old
one, ensuring that any changes are monotonic.
In hlds_out, inhibit the printing of pseudo-imported predicates (unifications)
since nobody cares about them except sometimes Fergus.
unifications. See the comments at the top of unify_proc.m for
details of how it's done.
hlds.m:
Add new export statuses `pseudo_imported' and `pseudo_exported'
to handle unification predicates, which can now have complicated
modes.
code_gen.pp, code_info.m, common.m, constraint.m, cse_detection.m,
follow_code.m, follow_vars.m, hlds_out.m, inlining.m, live_vars,
make_hlds.m, mercury_compile.pp, modes.m, store_alloc.m,
switch_detection.m:
Handle pseudo_imported predicates.
modes.m, constraint.m:
Change modecheck to return an updated module_info, since
modechecking may insert new entries into the unify_requests
queue in the module_info. Make sure that modechecking
never inserts requests into the unify_requests queue
for code that has mode errors (or needs rescheduling).
call_gen.m, polymorphism.m:
Move duplicated code into unify_proc.m.
clause_to_proc.m:
Add new predicate clauses_to_proc for use by unify_proc.m.
unify_proc.m:
Implement complicated unifications with complicated modes.
*.m:
Changed the way the extra field in the label type is defined. Now
all labels are initially assumed to be 'unknown' and a seperate
profiling pass (to be implemented) will determine whether the label can
be accessed externally.
modes.m, typecheck.m, code_util.m:
Don't report a compile error if there is a higher-order pred
unification in a compiler-generated predicate. (Instead, delay
the error until run-time so that it only occurs if the higher-order
pred unification in question actually gets executed.)
options.m call_gen.m code_gen.pp code_info.m code_util.m llds.m unify_gen.m:
A bunch of changes to implement the procs-per-c-function option.
This default is now `--procs-per-c-function 1', for reasonable
efficiency of compilation, but for efficiency of generated code
(e.g. when compiling benchmarks!)
use `--procs-per-c-function 0' (0 really means infinity).
I haven't tested this in any mode except asm_fast, so it's possible
that this change might break the other modes. If that turns out
to be the case, let me know. The symptom will be an error from
the C compiler or linker.
compiler/*:
Add copyright messages.
Change all occurences of *.nl in comments to *.m.
compiler/mercury_compile.pp:
Change the output to the .dep files to use *.m rather than *.nl.
(NOTE: this means that `mmake' will not work any more if you
call your files *.nl!!!)
code_util.nl, float.nl, llds.nl, mercury_builtin.nl, opt_debug.nl,
parser.nl, polymorphism.nl, sp_lib.nl, string.nl, string.nu.nl,
type_util.nl, typecheck.nl, unify_gen.nl:
Implement floating point.
Makefile.common:
Remove `-include test.dep' line. Use Mmake.
int.nl:
Update a few of the comments.
io.nu.nl:
For Sicstus Prolog, if main/2 is not defined then enter the
debugger.
io.nl:
Introduced a new predicate which ignore's any whitespace in the input.
Needs to have all the whitespace character's added to it.
*.nl and *.pp:
Changed the implementation of time profiling. Now during a compile,
the compiler identifies all the internal labels which can be accessed
externally, and marks them. At the moment, these are the continuation
labels of calls and the next disjunct in nondet disjunctions. Then
at the .mod output, it places a macro 'update_prof_current_proc' to
restore the profiling counter.
llds.nl:
Introduced an extra argument to the LLDS goto. It is the label
address of the Caller and is used for the profiling of tailcall's.
*.nl and *.pp:
Propagated the extra argument to all the appropiate files.
call_gen.nl:
Fix the code generation for call/N to handle input args.
code_util.nl:
Recognise all call/Ns as builtin
options.nl:
Turn off common subexpression elimination by default
code_util.nl:
Fix bug in make_proc_label: for unification predicates,
look at the _last_ argument to determine the type for
name mangling, not the first, since we introduce extra
higher-order arguments at the start.
make_hlds.nl, hlds.nl:
Ensure that the proc_info head_vars has the right length even for
imported predicates. This fixes a problem with --polymorphism.
make_hlds, unify_proc.nl, prog_util.nl:
Output unification procedures for equivalence types.
polymorphism.nl:
Ensure that this works even for unification procedures for
equivalence types, which are a bit wierd since they are not
quite type correct.
typecheck.nl:
Don't attempt to typecheck unification predicates, since
they are already type-correct when we construct them.
In particular don't typecheck unification procedures for
equivalence types, since it would report a spurious error.
mercury_to_mercury.nl:
Remove a superfluous duplicate clause.
code_util.nl, polymorphism.nl, mercury_builtin.nl:
Change things so that only call/1 is builtin.
For call/N, we can implement them by hand in mercury_builtin.nl.
(Procedure call overhead is the least of our worries right now.)
Note that call/N still only works in the following mode.
:- call (in, in, ..., in) is semidet.
You can't use it to call det predicates.
polymorphism.nl:
Fix some bugs:
- I had forgotten to update the argmodes of the modified
procedures
- I was updating the argtypes and attempting to use there
old value. I fixed this by splitting the algorithm
into two passes.
- to compute the types of the arguments to a call,
apply the type mapping from the _caller_ not the callee.
Also improve efficiency in a couple of places.
hlds.nl:
Add some new access predicates required by polymorphism.nl.
list.nl:
Add a new predicate list__duplicate, which is used by polymorphism.nl.
typecheck.nl, type_util.nl:
Move the type_unify routines from typecheck.nl into type_util.nl,
since they're also needed by polymorphism.nl.
term.nl:
Export term__apply_rec_substitution_to_list, since it's needed
by polymorphism.nl.
- - - - - - - - - - - - - - - - - - - - - - - - -
mode_util.nl, type_util.nl:
Move some routines from mode_util.nl to type_util.nl, where they
really belong.
- - - - - - - - - - - - - - - - - - - - - - - - -
make_hlds.nl, code_util.nl, typecheck.nl:
Mark builtin predicates as "external" in make_hlds.nl,
rather than checking for them as a special case in typecheck.nl.
- - - - - - - - - - - - - - - - - - - - - - - - -
prog_io.nl, hlds.nl, typecheck.nl:
For documentation purposes, define equivalent types `tvar',
`tvarset', `tsubst' for type variables, type varsets, and
type substitutions.
- - - - - - - - - - - - - - - - - - - - - - - - -
mercury_compile.pp, options.nl:
Change the handling of the --dump-hlds option so that you can
now dump the HLDS after any of the 12 HLDS transformation passes.
- - - - - - - - - - - - - - - - - - - - - - - - -
make_hlds.nl:
Report an error if there are clauses for an imported predicate.
- - - - - - - - - - - - - - - - - - - - - - - - -
io.nu.nl:
Add a new predicate r/1 which is like run/1 except that
you pass it a string rather than a list of atoms.
So now you can do
$ mercury_compile.debug
Mercury Interpreter 0.1
NU-Prolog 1.6.4
1?- r("mc -options blah blah blah").
*.nl:
Replace all occurrences of `not(Vars, Goal)' with just
plain `not(Goal)'.
type_util.nl, switch_gen.nl:
Higher-order pred types are not user-defined types.
Add a `predtype' type category for them.
call_gen.nl:
Change call_closure/2 to call_closure/3 (with liveinfo).
Plus a little bit of random hacking.
llds.nl, *.nl:
Change field(int, rval, int) to field(int, rval, rval), so
that the field number can be calculated at runtime
(We need this for predicate closures).
Also, remove the incr_hp(int) instruction and replace it
with a heap_alloc(rval) rval.
(We need to determine the space allocated at runtime
for predicate closures, and also we want it to be an rval
not an instruction so we can get conservative garbage collection
to work.)
unify_gen.nl:
More work for higher-order predicate closures.
std_util.nl:
Recode `bool__and' and `bool__or' more elegantly.
term.nl:
In term__create_var, use bit reversals rather than random numbers
to ensure that the binary trees remain balanced.
call_gen.nl:
For polymorphic unifications, generate a call to fatal_error().
code_gen.nl, hlds.nl, make_hlds.nl, modes.nl, unify_proc.nl:
Move the unify_request data structure from code_info to the HLDS,
and move the unify_request handling from code_gen.nl to modes.nl.
This is because we now generate HLDS code rather than LLDS code
for complicated unifications.
code_util.nl, hlds_out.nl:
Do some special name mangling for =/2.
float.nl, typecheck.nl, undef_types.nl, term.nl, hlds.nl:
Until we implement `float' properly, define it as an abstract type
in float.nl.
hlds.nl, make_hlds.nl:
Rename `local_pred, imported_pred, exported_pred' to just
`local, imported, exported' since they also apply to types, etc.,
not just to preds.
mercury_compile.pp, mercury_to_goedel.nl, prog_util.nl:
Replace to goedel__ prefixes in prog_util.nl with prog_util__.
std_util.nl:
Change the code for semidet_succeed to avoid determinism warning.
frameopt, opt_util, code_uti, middle_recl:
Added comprehensive optimization of detstack frame manipulation
instructions, replacing the earlier limited one. In the process,
moved a function from middle_rec to code_util, since frameopt
could also use it.
switch_gen:
Specialized the handling of switches with two cases to avoid
pipeline breaks.
std_util:
Added boolean and and or predicates.
set:
Added membership enquiry function.
mercury_compile:
Commented out a manual garbage collection point that was causing
trouble.
doit.pl, doit.swi:
Renamed doit.pl as doit.swi.
error.nl, code_util.nl, io.nu.nl, mercury_builtin.nl, portray.nl,
typecheck.nl, term_io.nl:
Various changes required by SWI-Prolog and/or Sicstus Prolog.
swi_builtin.nl, swi_lib.nl, doit.swi, mc.swi, mercury_compile.doit.swi:
Various stuff to get it working under SWI-Prolog.
doit.sp, mercury_compile.doit.sp:
Various stuff used in an (as yet unsuccessful) attempt to get
it to work under Sicstus Prolog.
make_hlds.nl, unify_proc.nl:
Do some stuff for complicated unifications.
(Note: this may break things! If things stop working,
let me know and I'll fix it.)
builtins.nl, call_gen.nl, code_util.nl, mercury_compile.nl, modes.nl:
Remove the "detect builtins" pass.
Instead, determing which predicate calls are builtins
happens during the mode analysis pass. modes.nl calls
code_util__is_builtin.
io.nl, io.nu.nl:
Move io__get/set_globals from io.nu.nl to io.nl.
modes.nl, mode_errors.nl:
Warn about predicates which have no modes.
arg_info.nl:
Generate correct arg_info for all predicates, including
imported predicates and predicates with no clauses.
typecheck.nl:
Don't warn about predicate having no clauses if the
the predicate is a builtin.
code_util.nl, llds.nl:
Make sure that we output a local entry label, not a global one,
when generating code for local (non-exported) procedures.
mercury_to_mercury.nl, hlds.nl:
Remove declarations for some undefined predicates,
caught by the new warning I added recently.
make_hlds.nl:
Oops, forgot to check that in with my last change.
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. ****
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.
*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.
call_gen.nl code_info.nl unify_gen.nl:
Fix the handling of assignments to dead variables,
Fix several problems where live registers got clobbered.
llds.nl:
Fix the output for nonlocal calls.
code_util.nl:
Fix the interface dependencies so that they are not circular.
group.nl:
Fix a determinism error.
switch_gen.nl unify_gen.nl:
Bug fixes - survive a whole lot more test cases.
make_hlds.nl:
Output introduced unifications in the correct order:
they should be generated top-down, not bottom up.
hlds_out.nl:
Don't output lines which don't contain any information.
modes.nl:
Avoid spurious determinism warnings for complicated
unifies.
code_util.nl:
Fix a couple of bugs.
llds.nl:
Added mkbody and body rvals which expand to macros.
*_gen.nl code_info.nl:
Fixed tag stuff. String things call error/1 but the
rest is approximately right. Still wants for testing.
mercury_builtin.nl:
Use det_pred(...), semidet_pred(...), nondet_pred(...)
rather than call_pred(...) for the higher-order predicate modes.
prog_io.nl, io.nl, varset.nl, etc.
Add determinism annotations.
hlds.nl, make_hlds.nl, LOTS of other files:
Reorganize the way the predicate table works.
Make hlds.nl a bit more modular.
Change call/4 to call/5.
Remove all/2 from the hlds.
Changed pred_id to an integer.
Added pred_call_id which is similar to the old pred_id.
Makefile:
Add a rule for creating *.hlds_dump.
array.nl:
Fix determinism error.
det_analysis.nl:
Fix a bug in printing determinism warnings.
fix_errors.sed:
Modify this so it allows all the `inferred nondet' determinism
errors but none of the `inferred semidet' ones.
llds.nl:
Rename llds__pred_mode_id as llds__proc_id.
mode_errors.nl:
Finally got around to implementing Zoltan's suggestions
about the error messages from the mode analysis.
If an error occurs in a conjunction, only one error message
is printed out - the first error which doesn't relate to
a head unification.
modes.nl:
Handle X = f(X) properly. NB: determinism analysis and code
generation still get it wrong!
undef_modes, undef_insts:
I've broken the error message code, since it's not easy
to print pred_ids. I just changed it so that it didn't
print the pred_ids out. Should fix this properly at some stage...