Commit Graph

28 Commits

Author SHA1 Message Date
Fergus Henderson
f862db3245 Lots of changes to implement compare/3.
*.nl:
	Lots of changes to implement compare/3.
1995-02-07 07:48:28 +00:00
Fergus Henderson
48e3dea925 Fix some bugs:
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").
1995-01-14 11:59:51 +00:00
Fergus Henderson
18b52a2d6c Change field(int, rval, int) to field(int, rval, rval), so
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.
1995-01-10 13:47:17 +00:00
Fergus Henderson
c074b02970 In term__create_var, use bit reversals rather than random numbers
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.
1994-12-29 01:12:12 +00:00
Zoltan Somogyi
67d15cc907 Added comprehensive optimization of detstack frame manipulation
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.
1994-12-09 01:12:45 +00:00
Fergus Henderson
ce78d4199d Remove the backward mode for list__length, so that we can
list.nl:
	Remove the backward mode for list__length, so that we can
	implement it using pure Mercury code.
	We weren't using the backward mode anyway.

mercury_builtin.nl, std_util.nl:
	Add some more "external" declarations.

prog_io.nl:
	Move join_error/3 to typecheck.nl.
1994-10-13 17:18:25 +00:00
Fergus Henderson
b92bc1b34f Add a couple of things for compiling the compiler to .o files.
Makefile.common, Makefile.mercury:
	Add a couple of things for compiling the compiler to .o files.

prog_io.nl:
	Fix bug in DCG expansion of ( { ... } -> { ... } ; ... ).

prog_io.nl, hlds.nl, make_hlds.nl,
nc_builtin.nl, np_builtin.nl, swi_builtin.nl:
	Implement a new `:- external(Pred/Arity)' declaration,
	for predicates which are defined elsewhere, e.g. in some
	other language.

int.nl, io.nl, std_util.nl, string.nl:
	Use the new `external' declaration.

llds.nl:
	Ouput the module name as mercury__xxx_module rather than
	just xxx_module.  (This avoids a name clash between code/io.mod
	and compiler/io.mod).

typecheck.nl:
	Avoid using implied modes.
1994-10-08 06:14:43 +00:00
Fergus Henderson
d8c9479872 Override the MERCURY_LIB_OBJS variable when invoking ml.
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).
1994-10-02 17:00:57 +00:00
Fergus Henderson
534e5c221e Fix lots of determinism problems.
*.nl:
	Fix lots of determinism problems.
1994-07-07 20:16:08 +00:00
Fergus Henderson
30f5e18b2f Remove map__search_insert; it's not needed and it's not
bintree.nl, map.nl, varset.nl:
	Remove map__search_insert; it's not needed and it's not
	really useful.

bintree.nl:
	Fix determinism problem in bintree__from_list_2.

options.nl, det_analysis.nl, make_hlds.nl:
	Add options to suppress determinism warnings.

det_analysis.nl, hlds.nl, modes.nl:
	Allow the delta-instmap to be `unreachable'.

hlds_out.nl:
	Output the delta-instmap.
	Output conjunctions differently in verbose mode.

llds.nl:
	Fix determinism problem.
	Change GOTO(LABEL(...)) into GOTO_LABEL(...) which can be
	more efficient.

map.nl:
	Add map__overlay/3.

typecheck.nl, modes.nl, mode_errors.nl, options.nl, hlds_out.nl.
	Split the old `debug' option into debug-types and debug-modes.
	Change the default for the `modecheck' option to `yes'.
	Add a new verbose-dump-hlds option, and use that instead
	of the very-verbose option in hlds_out.nl.

mode_util.nl:
	Export mode_get_insts/4.
	Add instmap_lookup_var (moved from modes.nl).
	Add apply_instmap_delta.

modes.nl, term.nl, prog_util.nl:
	Add determinism annotations.

term.nl, prog_io.nl:
	Fix bugs in when declarations.

std_util.nl, prog_io.nl:
	Add a maybe(T) type to std_util.nl.
	Rename the maybe(T) type in prog_io.nl as maybe1(T).
1994-06-16 16:05:59 +00:00
Thomas Conway
0b70d74836 added some detism decls...
group.nl, llds.nl, queue.nl std_util.nl:
	added some detism decls...
1994-06-16 06:44:25 +00:00
Fergus Henderson
94d9c1abb9 Use det_pred(...), semidet_pred(...), nondet_pred(...)
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...
1994-06-14 14:23:52 +00:00
Thomas Conway
0f6a3d59d1 added entries for the new files.
Makefile:
	added entries for the new files.

codegen.nl:
	This is really a new file (well almost). Contains the top level
	of the code generator.
doit.nl:
	Added the new files (and mode_error which was missing).

hlds.nl:
	Changed the type declaration for unifications to use arg_mode
	instead of mode.

hlds_out.nl:
	Small change for the above alteration.

llds.nl:
	Minor changes.

mode_util.nl:
	Change the modes to arg_modes for unifications.

modes.nl:
	ditto.

std_util.nl:
	more assoc_list predicates...

term.nl:
	Fixed a small but nasty by in term__vars_list (and don't forget
	Fergus that you owe me a chocolate biscuit).
1994-06-06 08:57:53 +00:00
Fergus Henderson
346f5b88fd Add arity' as an alias for int'.
prog_io.nl, hlds.nl:
	Add `arity' as an alias for `int'.

map.nl:
	Improve the code for map__merge.
	Add map__optimize.
	Work-around a bug in the determinism analysis.

make_hlds.nl:
	Use map__optimize rather than bintree__balance.

codegen.nl, std_util.nl:
	Add a call to `semidet_succeed' in codegen.nl, and
	implement that pred in std_util.nl, in an
	attempt to suppress a determinism warning.
	(The attempt failed, due to an as-yet unknown bug in
	the determinism analysis.)

hlds.nl, modes.nl, mode_util.nl, mercury_to_mercury.nl, undef_modes.nl.
	Replace the inst table with four tables, one for
	user-defined insts, and three for compiler-generated
	insts. Modify all the routines dealing with insts to
	handle this.  Change `inst_merge' in modes.nl to return
	a compiler-generated recursive inst if necessary.

term_io.nl:
	Fix bugs caused by recent changes to io__xxx_op preds.

Makefile, apply_sed_script, fix_errs.sed:
	A quick hack to avoid the spurious determinism errors.

term_io.nl, char.nl, string.nl:
	Add a few additional utility preds to string.nl.
	Add some more preds to handle quoting to term_io.nl.
	Remove the stuff which handled quoting in char.nl.
1994-06-02 12:56:00 +00:00
Thomas Conway
b12de99abf add set__a_member
set.nl:
	add set__a_member

std_util.nl:
	Add assoc_list__reverse_members
1994-05-23 10:44:28 +00:00
Fergus Henderson
dc1e47af29 Update the todo list.
typecheck.nl:
	Update the todo list.

std_util.nl:
	Add a type pair(T) == pair(T,T).
1994-05-08 15:38:59 +00:00
Fergus Henderson
0ad664520e Rename various things for consistency:
s/term_functor/term__functor/g
	s/term_atom/term__atom/g
	s/term_string/term__string/g
	s/term_int/term__int/g
	s/term_float/term__float/g
	s/term_variable/term__variable/g

	/:- mode.*[^a-zA-Z_]input,/s/input,/in,/g
	/[^a-zA-Z_]input,.*)/s/input,/in,/g
	/:- mode.*[^a-zA-Z_]output,/s/output,/out,/g
	/[^a-zA-Z_]output,.*)/s/output,/out,/g

	/:- mode.*[^a-zA-Z_]input)/s/input)/in)/g
	/:- mode.*[^a-zA-Z_]output)/s/output)/out)/g

	/[a-z]info/s/info/_info/g
	/__info/s/__info/_info/g
1994-05-03 12:28:54 +00:00
Fergus Henderson
62a70e436b Use assoc_list/2 rather than list(pair(...)).
bintree.nl, map.nl, std_util.nl:
	Use assoc_list/2 rather than list(pair(...)).

hlds.nl, det_analysis.nl:
	Make instmap delta an association list rather than a map;
	fix the determinism analysis to use that.

Makefile, doit.nl:
	Add det_analysis.nl and builtins.nl.

builins.nl:
	Fix bug.

codegen.nl:
	Make unimplemented cases abort rather than just fail.

modes.nl, typecheck.nl:
	Fix bugs introduced by the performance fixes.
	(I wonder if the performance problem will come back now? ;-)

options.nl, toplevel.nl:
	Add a new pred `maybe_flush_output' and use it in toplevel.nl.
1994-03-30 11:53:25 +00:00
Fergus Henderson
8047b837c7 Add a `unit' type.
std_util.nl:
	Add a `unit' type.
1994-03-22 03:49:24 +00:00
Fergus Henderson
92d1371b4c New file: converts the prog_io data structure back into Mercury source
mercury_to_mercury.nl:
	New file: converts the prog_io data structure back into Mercury source
	code.

term_io.nl:
	Export mercury_quote_string for use by mercury_to_mercury.nl.

Makefile, doit.nl:
	Add mercury_to_mercury.

options.nl, toplevel.nl:
	Add a new option to save the interface of a module to a `.int' file,
	using mercury_to_mercury.

Makefile:
	Modify the rule for the `clean' target so that it removes `.int' files.

mercury_builtin.nl:
	Fix the module name.

std_util.nl:
	Suppress warnings from nit.
1994-03-14 14:53:58 +00:00
Fergus Henderson
30f46e92b0 New file. At the moment it just checks for undefined modes and
modes.nl:
	New file.  At the moment it just checks for undefined modes and
	undefined insts.

Makefile, doit.nl:
	Add new files modes.nl and prog_util.nl.

term.nl:
	Add term__var_to_int.

toplevel.nl:
	Call the mode checker.

prog_io.nl, make_hlds.nl, hlds.nl:
	Allow for the possibility of abstract `inst' definitions,
	just like abstract type definitions.  Currently they
	are allowed for in the data structure, but they aren't
	parsed correctly, and the utilities in hlds.nl don't handle
	them that well.

hlds.nl:
	Move `unqualify_name' to prog_util.nl.

make_hlds.nl:
	Move `split_types_and_modes' to prog_util.nl.

mercury_to_goedel.nl, toplevel.nl:
	Move the equivalence type expansion code to prog_util.nl.

builtin.nl, toplevel.nl:
	Add a new module `builtin.nl' which gets automatically imported
	into every module.  In it, define the standard modes input,
	output, etc., and various other stuff.

std_util.nl:
	Move the defintion for \= to builtin.nl.
	Remove the definition of ~=.

prog_io.nl:
	Export parse_goal/2, since it's used by mercury_to_goedel.

mercury_to_goedel.nl:
	Fix various type errors.

list.nl, int.nl, io.nl, codegen.nl, det_analysis.nl, llds.nl, hlds_out.nl:
	Fix various syntax errors, typos and errors in type and mode
	declarations discovered by mercury_compile.
1994-03-04 12:39:43 +00:00
Fergus Henderson
c7da2813cd Added the universal type `univ'. 1994-03-02 02:48:54 +00:00
Fergus Henderson
f302152b3a fix bug in error message code
typecheck.nl:
	fix bug in error message code

Makefile:
	remove pathname from NC definition

make_hlds.nl:
	initialize the unify_context field.

std_util.nl, std_util.nu.nl:
	move the implementation of solutions/2 from std_util to std_util.nu
	(where it should have been in the first place).
1994-02-23 14:09:57 +00:00
Fergus Henderson
e7d5e01767 added handling of higher-order predicates and the builtin types
typecheck.nl:
	added handling of higher-order predicates and the builtin types
	pred, pred(T), pred(T1, T2), etc.

hlds.nl:
	added new field pred_name_index to the moduleinfo data structure
	(needed for higher-order pred handling in typecheck.nl).

make_hlds.nl:
	update the pred_name_index

make_hlds.nl:
	detect and report as an error any attempts to define multiple
	constructors for a single type with the same name and arity.

Makefile:
	minor fixes.

hlds_out.nl:
	fix type errors introduce when pred_mode_id was renamed as proc_id.

mercury_to_goedel.nl:
	fix problems causes by modifications to prog_io.nl.

various places:
	change to use the new builtin higher-order pred types.
1994-02-23 13:35:54 +00:00
Fergus Henderson
02c2a93c4c typecheck.nl: A couple of minor fixes; fix bug with constants of builtin types.
Optimize for the common case of non-polymorphic types & predicates.

term.nl: Rename term__apply_substitution as term__apply_rec_substitution
	and add a new term__apply_substitution for when you want
	non-recursive application.  Fix logic bug in
	term__substitute_corresponding.

varset.nl: Fix logic bug in varset__merge.

io.nu.nl: Fix typo in error message.

term_io.nu.nl: Fix bug in the code used to work-around the NU-Prolog
	getToken bug for empty strings.

prog_io.nl: Fix bug: the string "\+" should have been "\\+".
	Also fixed LOTS of type errors (discovered by the typechecker,
	hurray it now works!).

int.nl, list.nl, std_util.nl: Added pred & mode declarations for some
	NU-Prolog predicates that we are using.
1994-02-10 15:02:25 +00:00
Fergus Henderson
1e4edbe9fc Bug fixes.
Also rearranged the interface declarations in a couple of modules.
1994-02-02 11:24:56 +00:00
Fergus Henderson
cc6a44c2bb term_io.nl: add io__write_variable.
Added a couple of new preds to std_util.nl and added std_util.nu.nl.

Fixed some bugs in the typechecker, and improved error reporting
a bit.

Did a bit of work on memory management.
1994-02-02 10:26:45 +00:00
Fergus Henderson
955c1512de mercury_to_goedel.nl: hack it to work for llds.nl.
prog_out.nl: remove various bits of crud and clean it up a little.

hlds.nl: add some stuff needed by typecheck.nl

typecheck.nl: did a bit more work on this.

renamed module.nl as toplevel.nl and also rewrote it using stuff
from mercury_to_goedel.nl.
1994-01-26 15:20:07 +00:00