Commit Graph

135 Commits

Author SHA1 Message Date
Zoltan Somogyi
cb41c485ef Update a comment.
Estimated hours taken: 2

code_util:
	Update a comment.

dead_proc_elim:
	Fix a progress message.

hlds_out:
	Put a comment sign before each switch arm's "X has functor f"
	output, since this is not proper Prolog or Mercury syntax.

make_hlds:
	Temporarily allow the definition of builtins, to permit bootchecking
	while unary builtins are added.

prog_io:
	Improve the handling of DCG variables in if-then-elses the same way
	I recently improved disjunctions. Also factor out a bit of common
	code.
1996-05-31 01:16:43 +00:00
Zoltan Somogyi
c588526f03 Add a predicate to rename variables in the kinds of goals we have in
Estimated hours taken: 1

prog_util:
	Add a predicate to rename variables in the kinds of goals we have in
	items. (We already have similar predicates for terms and for
	hlds_goals).

prog_io:
	We used to expand ( p ; q ) in DCG clauses to become
	( p(DCG1, DCG2) ; q(DCG1, DCG3), DCG2 = DCG3 ). These extra
	unifications can pile up rather badly; in the new version of lexer.m,
	two 128-way switches each ended up with 90 unifications in the last
	arm. This is very bad for performance. Instead of adding unifications
	to make sure that both arms of a disjunction put the final stream value
	in the same variable, we now use renaming when possible.
1996-05-27 23:33:51 +00:00
Fergus Henderson
b4cf70fccc Rename the pragma' type as pragma_type', to avoid bootstrapping
Estimated hours taken: 0.25

prog_data.m, prog_io.m:
	Rename the `pragma' type as `pragma_type', to avoid bootstrapping
	problems caused by my change to make `pragma' an operator.
1996-05-25 04:10:49 +00:00
Fergus Henderson
a8acf00f9d Add a new pragma `:- pragma obsolete(Name/Arity).';
Estimated hours taken: 3

Add a new pragma `:- pragma obsolete(Name/Arity).';
the effect of this pragma is that we issue a warning for
any call to the specified predicate(s) or function(s).

prog_data.m:
	Add new pragma type `obsolete'.
prog_io.m:
	Parse pragma `obsolete'.
hlds_pred.m, hlds_out.m:
	Add new pred_marker `obsolete'
make_hlds.m:
	When we encounter a pragma `obsolete', insert `request(obsolete)'
	in the pred_marker list for the specified predicate(s) and function(s).
simplify.m:
	For each predicate call, check if the called predicate has been
	marked as obsolete.  If so, return a `warn_obsolete' warning.
det_report.m:
	Add a new warning type `warn_obsolete', and add code to print
	the warning for this warning type.
det_analysis.m:
	Add a comment.
1996-05-21 19:09:28 +00:00
Fergus Henderson
2a1d24f62e Make `pragma' a prefix operator, and change the syntax for
Estimated hours taken: 1

Make `pragma' a prefix operator, and change the syntax for
pragmas from `:- pragma(name, args)' to `pragma name(args)'.
(For backwards compatibility the old syntax is still allowed.)

mercury_to_mercury.m:
	Add `pragma' to the list of operators.
prog_io.m:
	Clean up the code for parsing pragmas: avoid overly deep
	nesting of if-then-elses over pages of code, and avoid
	some code duplication.
	Parse new pragma syntax.
1996-05-21 19:07:47 +00:00
Fergus Henderson
60b9fa83b6 Implement higher-order functions.
Estimated hours taken: 12

Implement higher-order functions.

Add higher-order function terms
(function lambda expressions, e.g. `Func = (func(X) = Y :- Y is 2 * X)'
and higher-order function calls (apply/N, e.g. `Z = apply(Func, 42)').
Add higher-order function insts and modes.

hlds_goal.m:
	Add a new field pred_or_func to lambda_goal.

prog_data.m:
	Add a new field pred_or_func to pred_inst_info.

prog_io.m:
	Add support for parsing higher-order function terms and
	higher-order function insts and modes.

make_hlds.m:
	Add support for parsing higher-order function terms.

typecheck.m:
	Add support for type-checking higher-order function calls
	and higher-order function terms.

modes.m, mode_errors.m:
	Add support for mode-checking higher-order function calls
	and higher-order function terms.

higher_order.m:
	Handle higher-order function types and insts.

hlds_pred.m:
	Add new predicate pred_args_to_func_args, for extracting the
	function arguments and function return from the arguments
	of a predicate that is really a function.

*.m:
	Minor changes to handle new pred_or_func field in lambda_goals
	and pred_inst_infos.
1996-05-14 10:07:46 +00:00
Fergus Henderson
e98fdf8fab Export parse_some_vars_goal, for use by make_hlds.m, for
Estimated hours taken: 0.25

compiler/prog_io.m:
	Export parse_some_vars_goal, for use by make_hlds.m, for
	my recent change to support if-then-else expressions.
1996-04-25 02:43:10 +00:00
Zoltan Somogyi
649b6908c3 Rename branch_delay_slot to have_delay_slot.
Estimated hours taken: 8

options.m:
	Rename branch_delay_slot to have_delay_slot.
	Set optimize_delay_slot in -O2 only if have_delay_slot was set earlier.
	This is possible now because the default optimization level is now
	set in mc.

mercury_compile:
	Change verbose output a bit to be more consistent.

dead_proc_elim:
	Export the predicates that will eventually be needed by inlining.m.

inlining.m:
	Use the information about the number of times each procedure is called
	to inline local nonrecursive procedures that are called exactly once.
	EXCEPT that this is turned off at the moment, since the inlining of
	parse_dcg_goal_2 in prog_io, which this change enables, causes the
	compiler to emit incorrect code.

prog_io:
	Moved the data type definitions to prog_data. (Even though prog_io.m
	is ten times the size of prog_data.m, the sizes of the .c files are
	not too dissimilar.)
1996-04-24 01:00:23 +00:00
David Jeffery
de1bce000c Its...
Estimated hours taken: 30 (?)

Its...

The C to Mercury Interface.

The following changes provide a C to Mercury interface. By making a declaration
such as

:- pragma(export, foo(in, in, out), "FunctionName").

you will be able to call the C function "FunctionName" from C. The arguments
are the same as the Mercury arguments, with outputs passed as pointers.

XXX We don't handle floats or strings properly.

A function prototype is output into <modulename>.h

Execution still has to start in Mercury.

Something went wrong with CVS when I tried to abort a commit just then, and it
thinks I've already commited some files... but here's a description of all
my changes anyway:

compiler/garbage_out.m:
	Ignore c_export c_modules.
compiler/hlds_module.m:
	Add an annotation to the hlds, indicating which procs are exported
	to C.
compiler/llds.m:
	Change the way labels are emitted - instead of emitting the label
	directly, it first generates a string and then prints the string. This
	is useful because I only want the string (to print later). The
	preds which return a string are now part of the interface.
compiler/make_hlds.:
	Take note of which procs are to be exported to C.
compiler/mercury_compile.pp:
	Generate a <module>.h file if necessary.
compiler/mercury_to_mercury.m:
	Spit out :- pragma(export, ...) decs.
compiler/prog_io.m:
	Read in :- pragma(export, ...) decs.

compiler/export.m:
	Handle the outputting of C exports. This includes the generation of
	the .h files and the generation of the C functions.
1996-04-22 19:28:36 +00:00
Fergus Henderson
b10f96b2c7 Remove most of the old hack which expanded calls to is/2 in the
Estimated hours taken: 0.25

compiler/prog_io.m:
	Remove most of the old hack which expanded calls to is/2 in the
	parser, since we now use functions instead.
1996-04-07 14:47:45 +00:00
Zoltan Somogyi
2833bfffb7 Divided the old hlds.m into four files:
Estimated hours taken: 10

hlds, hlds_module, hlds_pred, hlds_goal, hlds_data:
	Divided the old hlds.m into four files:

	hlds_module.m defines the data structures that deal with issues
	that are wider than a single predicate. These data structures are
	the module_info structure, dependency_info, the predicate table
	and the shape table.

	hlds_pred.m defined pred_info and proc_info, pred_id and proc_id.

	hlds_goal.m defines hlds__goal, hlds__goal_{expr,info}, and the
	other parts of goal structures.

	hlsd_data.m defines the HLDS types that deal with issues related
	to data and its representation: function symbols, types, insts, modes.
	It also defines the types related to determinism.

	hlds.m is now an empty module. I have not removed it from CVS
	because we may need the name hlds.m again, and CVS does not like
	the reuse of a name once removed.

other modules:
	Import the necessary part of hlds.

det_analysis:
	Define a type that was up to now improperly defined in hlds.m.

prog_io:
	Move the definition of type determinism to hlds_data. This decision
	may need to be revisited when prog_io is broken up.

dnf, lambda:
	Simplify the task of defining predicates.

llds:
	Fix some comments.

mercury_compile:
	If the option -d all is given, dump all HLDS stages.

shape, unused_args:
	Fix formatting.
1996-04-02 12:12:24 +00:00
Fergus Henderson
3b36da6e77 Implement functional syntax. You can now use `:- func' in a similar manner
Estimated hours taken: 12

Implement functional syntax.  You can now use `:- func' in a similar manner
to `:- pred'.  For example, `:- func foo(int, int) = int.' declares a function,
and `:- mode foo(in, in) = out.' defines a mode for it.  You can write clauses
for functions, such as `foo(X, Y) = Z :- Z is 2*X + Y.'  Any term in the
head or body of a clause can be a function call, e.g. `bar(X, Y, foo(X, Y))'.

Until we have implemented a proper Mercury debugger, this syntax
should not be used (except that I might reimplement the functions
provided by Prolog's is/2 predicate using this syntax, rather than
the current special-case hack in the parser).

prog_io.m:
	Add syntax for declaring and defining functions.
	Disallow the use of `=' to define modes, as in `:- mode foo = bar.'
	(Instead, you should use `::'.  `==' is also allowed.)
	Also, use higher-order predicates to simplify some of the rather
	repetitious parsing code.

mercury_to_mercury.m, mercury_to_goedel.m, make_hlds.m, modules.m:
	Handle new functional syntax.

typecheck.m:
	Add support for functions, function types such as `func(int) = int',
	and currying.  (But there's currently no equivalent to call/N for
	functions, so function types and currying aren't very useful yet.)

undef_types.m:
	Add support for function types.

modes.m:
	Convert function calls into predicate calls.
	(This must be done after typechecking is complete,
	so I put it in mode analysis.)

hlds.m:
	Add new field `pred_or_func' to the pred_info.

hlds_out.m:
	Print out the `pred_or_func' field.

higher_order.m, unused_args.m, lambda.m, dnf.m:
	Pass extra pred_or_func argument to pred_info_init to specify that
	the thing being created is a predicate, not a function.

constraint.m, dependency_graph.m, hlds_out.m:
	`mercury_output_mode_subdecl' has been renamed
	`mercury_output_pred_mode_subdecl'.

prog_util.m:
	Add new predicate split_type_and_mode/3.

llds.m:
	Print out
		/* code for predicate '*'/3 in mode 0 */
	rather than
		/* code for predicate */3 in mode 0 */
	to avoid a syntax error in the generated C code.
1996-03-25 07:41:54 +00:00
Zoltan Somogyi
3e4a019dcc Fix the pass structure, and start using a loose sequence of stage
Estimated hours taken: 8

mercury_compile:
	Fix the pass structure, and start using a loose sequence of stage
	numbers, to make it easier to add new stages without having to fiddle
	stage numbers.

	THIS DOES MEAN THAT ALL STAGE NUMBERS HAVE CHANGED NOW.

	The stage number assignment scheme assigns 1 to 25 to the front end,
	26 to 50 to the middle passes, and 51 to 99 to the back end.

hlds:
	We had two types that combined a pred_id and a proc_id. One,
	pred_proc_id, used a simple pair; the other, procedure_id, had a better
	definition using a specific function symbol but was not used
	anywhere else. I standardized on the name pred_proc_id, but using the
	definition with a dedicated function symbol (proc).

	I also defined a type pred_proc_list as a list of pred_proc_id.

	To prepare for memoing, I added a new field to pred_info, which is
	a list of markers, each requesting a specific transformation on the
	predicate or indicating that the transformation has been done.
	The inline request is now represented using such a marker. However,
	the interface is backwards compatible.

constraint, dead_proc_elim, dependency_graph, det_analysis, det_report,
higher_order, unused_args:
	Changes to conform to the new definition of pred_proc_id.
	In two places removed definitions of predproclist, whose
	equivalent pred_proc_list is now defined in hlds.m.

hlds_out, make_hlds, mercury_to_mercury, prog_io:
	Add code to handle memo pragma declarations, using whenever possible
	a version of the existing code for handling inline requests, but
	generalized for handling any pragma that sets a marker.

switch_detection:
	Rename the type cases_list to sorted_cases_list. This avoids a
	name clash that creates a duplicate label and therefore screws up
	the profiler, and is a better name anyway.

options:
	Add a new option, --opt-space, that turns on optimizations that save
	space and turns off optimizations that squander space.

handle_options:
	Pass the special option handler to getopt.

frameopt:
	For each labelled code sequence that tears down the stack frame but
	does not use it, we used to create a parallel code sequence that omits
	the teardown code, for use by gotos from locations that did not have
	a stack frame. However, peepholing may discover that it is better
	not to tear down the stack frame at the site of the goto after all,
	so we need the original code sequence as well.

	The current change fixes a bug that occurs if the original code
	sequence is modified by another part of frameopt to omit teardown
	code. In such cases, which are produced by --pred-value-number,
	peepholing redirects a goto to a code sequence that it thinks tears
	down the stack frame, but actually doesn't.

	With this change, --pred-value-number now works.

llds:
	Fix typos in a comment.
1996-03-24 06:39:33 +00:00
Zoltan Somogyi
c70dbe9e2b When we are processing the flushing of create expressions, make sure
Estimated hours taken: 2

code_exprn:
	When we are processing the flushing of create expressions, make sure
	the Lval we are creating into isn't a field reference. This avoids
	deep field of field of field of ... nesting. It does introduce
	references to high register numbers, but this is a lesser evil,
	and Tom and I plan to fix this anyway.

arg_info, globals, options:
	Change --args old to --args simple.

options:
	Make some help messages more specific.

code_aux, code_exprn, code_info, det_report, make_hlds, mercury_to_goedel,
prog_io, typecheck:
	Changes to accommodate the move from varset__lookup_name
	to varset__search_name.
1996-03-12 03:39:13 +00:00
Fergus Henderson
bd2093d8b4 Fixes for two bugs in mode analysis, and
Estimated hours taken: 12

Fixes for two bugs in mode analysis, and
a first cut at support for `any' insts.
(The support for `any' is very preliminary,
has had only the most minimal of testing, and
doubtless has some bugs.)

inst_match.m mercury_to_mercury.m mode_util.m modes.m undef_modes.m
unique_modes.m prog_io.m:
	Add new type of inst `any(uniqueness)' to prog_io.m, and
	change inst_match.m, mode_util.m, and other places to handle
	handle `any' insts.

inst_match.m:
	Fix bug in inst_merge: when merging `unique(f(ground)) and `unique',
	the result should be `ground', not `unique', since part of the
	data structure may be shared.  (This fix required adding several
	new predicates: `merge_uniq_bound' etc.)

inst_match.m mercury_to_mercury.m mode_util.m modes.m polymorphism.m
prog_io.m switch_detection.m unique_modes.m:
	Fix a design bug: in a `bound' inst, the list of bound_insts
	must be sorted on the name+arity, not on the name+arg_insts.
	To achieve this, I changed the type of the first argument of
	functor/2 in the type bound_inst from `const' (just name) to
	`cons_id' (name+arity).
1996-03-09 16:04:29 +00:00
Zoltan Somogyi
e7054745f2 Wrap parentheses around pred insts, since they are needed.
Estimated hours taken: 6

mercury_to_mercury:
	Wrap parentheses around pred insts, since they are needed.

value_number, vn_verify:
	Value numbering now reapplies itself to both halves of a block if
	it cannot optimize the block as a whole.
	Split the verification code into its own module, and fix line lengths.

vn_order:
	Fix the computation of the label at which blocks should be divided.
	Fix line lengths.

vn_debug:
	Add a message to support the new block dividing capability.

code_exprn:
	Redirect option lookup operations from options to getopt.

passes_aux:
	Prepare for some further changes.

prog_io:
	Formatting changes.
1996-03-05 23:55:48 +00:00
Fergus Henderson
6885f10d1c A bunch of changes to get `--split-c-files' to work better.
Estimated hours taken: 4

A bunch of changes to get `--split-c-files' to work better.

compiler/Mmake:
	Add a rule to create mercury_compile.opt using --split-c-files.
	Add dependency of mercury_compile_init.c on ../util/mkinit.
	Add a couple of things missing from the `mmake realclean' rule.

prog_io.m, hlds.m, make_hlds.m, llds.m, mercury_compile.pp,
mercury_to_mercury.m, garbage_out.m:
	Handle new c_code pragma `pragma(c_code, "...")'.
	This has a similar effect to `pragma(c_header_code, "...")',
	except that the code will only be output once if `--split-c-files'
	is enabled.

mercury_compile.pp:
	If --split-c-files option is enabled, pass -DSPLIT_C_FILES to
	the C compiler.

llds.m:
	Fix a bug which meant that --split-c-files didn't work in some grades:
	use the typedef now defined in goto.h when declaring module
	initialization functions, don't just assume they are `void f(void)'.
1996-03-05 03:56:56 +00:00
Fergus Henderson
6d7f4b9b30 Undo dylan's changes in the names of some library entities,
Estimated hours taken: 1.5

Undo dylan's changes in the names of some library entities,
by applying the following sed script

	s/term_atom/term__atom/g
	s/term_string/term__string/g
	s/term_integer/term__integer/g
	s/term_float/term__float/g
	s/term_context/term__context/g
	s/term_functor/term__functor/g
	s/term_variable/term__variable/g
	s/_term__/_term_/g
	s/std_util__bool_/bool__/g

to all the `.m' and `.pp' files in the compiler and library directories.
The reason for undoing these changes was to minimize incompatibilities
with 0.4 (and besides, the changes were not a really good idea in the first
place).

I also moved `bool' to a separate module.
The main reason for that change is to ensure that the `__' prefix is
only used when it genuinely represents a module qualifier.
(That's what dylan's changes were trying to acheive, but `term__'
does genuinely represent a module qualifier.)

compiler/*.m:
	Apply sed script above;
	where appropriate, add `bool' to the list of imported modules.
1996-02-03 17:30:14 +00:00
Fergus Henderson
4414b6c975 Print line numbers in "%03d" format, so that columns in the
Estimated hours taken: 0.5

prog_io.m, prog_out.m:
	Print line numbers in "%03d" format, so that columns in the
	error messages line up nicely.
1996-01-21 14:26:10 +00:00
Fergus Henderson
2fbdac6996 Implemented committed choice nondeterminism.
Estimated hours taken: 8

Implemented committed choice nondeterminism.

I have added new determisms `cc_nondet' and `cc_multi'.
These determinisms have the existing code model `model_semi',
so the only major changes I had to make were to determinism
analysis (and even that wasn't too hard).  Code generation
was pretty much unchanged, except that I had to add back
model_semi disjunctions again.

The one desireable part that won't work yet is overloading a
predicate to have both `nondet' and `cc_nondet' modes.
(Mode analysis will always pick the `cc_nondet' mode, and then if it
occurs in an all_soln context, determinism analysis will unfortunately
report an error rather than substituting the `nondet' mode.)

prog_io.m, hlds.m, hlds_out.m, mercury_to_mercury.m, prog_io.m:
	Add new determisms `cc_nondet' and `cc_multi'.
	Add new soln_count `at_most_many_cc'.

det_analysis.m, det_report.m:
	Changed determinism analysis to handle them, by traversing goals
	right-to-left and propagating a `call_context' down as we go.
	The call_context specifies whether we want `all_solns' to a goal,
	or just the `first_soln'.  Disjunctions which occur in a `first_soln'
	context will get inferred as `cc_nondet' or `cc_multi'.
	Determinism analysis will also check that any calls to predicates
	with a `cc_nondet' or `cc_multi' mode occur only in a `first_soln'
	context.

	(Also another minor improvement: warn if the condition of an
	if-then-else cannot fail.)

disj_gen.m:
	Put back the code to handle semidet disjunctions.
	It had suffered from a fair bit of software rot;
	I hope my fixes were correct.  (Tom, can you please
	have a look at the code and check that it looks OK?)
1996-01-15 16:42:09 +00:00
Fergus Henderson
ebe792f1d8 A large bunch of changes to improve unique mode checking.
Estimated hours taken: 18

---------------------------------------------------------
A large bunch of changes to improve unique mode checking.
---------------------------------------------------------

Unique mode checking is now quite similar to redoing mode checking,
except that as it goes along it changes the insts of variables which
may be used again on backtracking from `unique' to `mostly_unique',
and except that it doesn't do any rescheduling.

(This contrasts with my original very simple approach which just kept track
of which variables were nondet-live - that approach only works
for the top-level of the inst.  The new approach handles insts
such a list whose skeleton is unique and whose elements are mostly_unique.)

Another improvement is that we now also detect errors resulting from
shallow (semidet) backtracking in if-then-elses and negations, which
previously we missed.

Also, fix a bug in the handling of `X = f(_)' when X is unique:
it was inferring the delta instmap `X -> unique(f(ground))'
rather than `X -> unique(f(unique))'.

unique_modes.m:
	Major rewrite.

inst_match.m:
	Add new predicate `make_mostly_uniq_inst' which replaces
	every occurence of `unique' in an inst with `mostly_uniq'.
	Fix bug in abstractly_unify_inst_functor_3 which caused
	above-mentioned problem with `X = f(_)' when X is unique.

hlds.m, prog_io.m, mercury_to_mercury.m, mode_util.m, undef_modes.m:
	Add a new inst_name `mostly_unique(inst)'; the inst
	`defined_inst(mostly_unique(X))' is identical to the
	inst X with every occurrence of `unique' replaced with
	`mostly_unique'.  This change was required in order to
	implement the `make_mostly_uniq_inst' predicate for recursive
	insts.

mode_info.m:
	Add a new field holding the nondet-live variables,
	for use by unique_modes.m.

modes.m:
	Export a whole bunch of previously private predicates,
	for use by unique_modes.m.

det_analysis.m, det_report.m, make_hlds.m, mercury_compile.pp, prog_io.m,
value_number.m:
	Fix unique mode errors resulting from I/O operations (calls
	to io__lookup_bool_opt) in the conditions of if-then-elses.
1996-01-14 15:16:30 +00:00
Fergus Henderson
e2d7877b0f Improve error message for one of the internal errors.
code_exprn.m:
	Improve error message for one of the internal errors.

det_analysis.m:
	Make sure we don't generated unnecessary nested `some' goals.

prog_io.m, inst_match.m, mode_util.m, mercury_to_mercury.m:
	Add new insts `mostly_unique' and `mostly_clobbered', with
	semantics similar to `unique' and `clobbered', except that
	mostly-unique variables might be needed on backtracking.

unique_modes.m:
	A good start on the code to check that `unique' modes
	are not used for nondet live variables.  Still incomplete,
	but just about all the code is there except the code to
	actually compute the set of nondet live variables as you
	traverse the goal.
1996-01-01 13:19:22 +00:00
Fergus Henderson
13312a7344 Some changes to the syntax.
Estimated hours taken: 1

Some changes to the syntax.

make_hlds.m, prog_io.m:
	Allow arguments in lambda expressions to be arbitrary terms,
	not just variables.  (The scope rules are really wierd at
	the moment - if the argument is a variable, it introduces
	a new scope, but if it is a compound term containing a variable,
	then it doesn't.  We should change things so that a new scope
	is introduced only if the variables are explicitly universally
	quantified.)
	Allow a new syntax `pred(X::in, Y::out) is det :- ...'
	for lambda expressions.
	Allow the use of `==' in `:- inst' declarations (as a synonym for `=').
1995-12-30 21:59:17 +00:00
Dylan Shuttleworth
3ab8d92226 Change names with badly placed double underscores (ie where the part of
Estimated hours taken: _2___

Change names with badly placed double underscores (ie where the part of
a name before a double underscore is not the same as the module name.)

Reflect changes in the library interface.

compiler/*:
	Use the newer, more correct form of the term and bool names.
	Predicates "bool__" are now "std_util__bool" and labels of
	the term ADT are now "term_" instead of "term__".

compiler/vn*.m:
	change all names "vn__*" to a correct module prefix.  All the
	names remain qualified.

compiler/hlds.m:
	s/\<is_builtin__/hlds__is_builtin_/g
	s/\<dependency_info__/hlds__dependency_info_/g

compiler/unify_proc.m:
	s/\<unify_proc_info__/unify_proc__info_/g

compiler/transform.m:
	s/\<reschedule__conj/transform__reschedule_conj/g
1995-12-29 03:45:20 +00:00
Fergus Henderson
92b44d6f77 Improve error messages.
Estimated hours taken: 1

Improve error messages.

compiler/typecheck.m:
	Add missing new-line in error message.

compiler/prog_io.m:
	Improve error message for `_' variable in pragma(c_code, ...)
	declaration - make it clear that this is a "sorry, not implemented"
	error, and make it clear that `_' variable is causing the problem.

compiler/make_hlds.m:
	Minor change to error message.
1995-11-10 16:14:22 +00:00
Fergus Henderson
c68c5f07d4 Improve error message, as requested by Philip Dart and others.
Estimated hours taken: 0.5

Improve error message, as requested by Philip Dart and others.

compiler/prog_io.m:
	Report a more informative error message if the module
	name in a `:- module' declaration is a variable.
1995-11-02 11:32:51 +00:00
David Jeffery
07b9ac5c4a We now allow a declaration of the form:
:- pragma(inline, predicate/arity).

This declaration means that the corresponding predicate will be inlined.

hlds.m:		Add a field to the pred_info indicating whether or not to
		inline the pred automatically.
make_hlds.m:	Turn on the inline flag in the pred_info if there was a
		pragma(inline, ...) declaration.
prog_io.m:	Parse the new declaration.
mercury_to_mercury.m:
		Spit out the new dec.
inlining.m:	Inline the predicate if the inlining field is set in the
		pred_info.
polymorphism.m:
code_aux.m:	Add an extra paramater to calls to pred_info_init.
1995-10-23 04:51:50 +00:00
Fergus Henderson
7de2e6dd9c - For `mc --generate-dependencies', report an error if the
mercury_to_mercury.m:
	- For `mc --generate-dependencies', report an error if the
	  named module does not exist.
	- Write out the compiler version number in the generated `.dep' file.
	- Reorganize the code that writes out the `.dep' file to make it
	  clearer.
	- End error messages with a full stop (".").

prog_io.m:
	Fix some bugs in dylan's changes:
	- Wrap some >80 char source lines.
	- Fix incorrect formatting of an error message.
	- If the filename and the `:- module' declaration disagree,
	  use the filename, not the declaration.
1995-10-19 16:24:10 +00:00
Zoltan Somogyi
39c2701dd6 Added some code to fix up disjunctions that have at most one solution.
det_analysis:
	Added some code to fix up disjunctions that have at most one solution.
	We now transform a disjunction to an if-then-else only if the
	disjunction is locally nondet. If the disjunction cannot fail, we
	replace it with a disjunct that cannot fail and issue a warning;
	we issue a warning in several other cases as well.

mercury_to_mercury:
	Fix two duplicate fact bugs pointed out by the new det_analysis.

peephole:
	Add a new optimization: a stack frame teardown followed by a
	conditional branch to a label that builds a stack frame is now
	replaced by code that starts with the conditional branch to the
	code after the stack frame setup, and has the stack frame teardown
	only in the fall through code. This optimization is applied only
	after frameopt.

opt_util:
	Export a previously internal predicate for use by peephole.

optimize, value_number:
	Conform to the new interface of peephole.

frameopt:
	Add some debugging code (now commented out) that helped in making
	the above optimization.

prog_io:
	Cosmetic changes.
1995-10-19 00:28:40 +00:00
David Jeffery
f75693e80a The C interface.
The changes made allow declarations of the form:

:- pragma(c_code, predname(Varname1::mode1, Varname2::mode2, ...),
	"Some C code to execute instead of a mercury clause;").

There are still a couple of minor problems to be fixed in the near future:
If there is a regular clause given as well as a pragma(c_code, ...) dec, it
is not handled well, and variables names '_' are not handled well.

prog_io.m:
	parse the pragma(c_code, ...) dec.
hlds.m:
	define a new hlds__goal_expr 'pragma_c_code'.
make_hlds.m:
	insert the pragma(c_code, ...) dec. as a pragma_c_code into the hlds.
det_analysis.m:
	infer that pragma_c_code goals are det.
modes.m:
	convince the mode checker that the correct pragma variables are bound
	etc.
quantification.m:
	quantify the variables in the pragma(c_code, ...) dec.
code_gen.pp:
	convert pragma_c_code into pragma_c (in the llds).
llds.m:
	define a new instr, pragma_c. Output the pragma_c
hlds_out.m:
mercury_to_mercury.m:
mercury_to_goedel.m:
	spit out pragma(c_code, ...) decs properly

*.m: 	handle the new pragma_c_code in the hlds or the new pragma_c in the llds
1995-10-17 11:13:13 +00:00
Dylan Shuttleworth
7a37583c9c Allow predicate and mode definitions, and predicate calls to have
compiler/*
	Allow predicate and mode definitions, and predicate calls to have
	module qualifiers.  This allows a restricted form of predicate
	name overloading.

compiler/llds.m, prog_io.m
	In addition to above, these modules now write some labels in `*.c'
	output files with module-name qualifiers.  Predicate `main/2',
	predicates of `mercury_builtin' and special predicates with names
	like `__*__' are not qualified.

compiler/mercury_to_goedel.m
	This module is probably a little more broken than before, as
	module:qualifiers are ignored.
1995-10-17 04:53:02 +00:00
Fergus Henderson
2a1497bc31 A bunch of changes to fix another missing bit of unique modes.
Previously we didn't check if a unification was unifying with
a clobbered value.  With these changes, we now do.

inst_match.m:
	Add an extra parameter `unify_is_real' to `abstractly_unify_inst'.
	The extra parameter specifies whether this is a "real" or "fake"
	unification; if it is fake, unifications with clobbered values
	are allowed.

modes.m:
	Pass the above-mentioned new parameter to `abstractly_unify_inst'.

prog_io.m, hlds.m:
	Store the above-mentioned new parameter in the unify_inst table.

mode_util.m:
	Use the above-mentioned new parameter when looking up an inst
	in the unify_inst table.

undef_modes.m, mercury_to_mercury.m:
	More miscellaneous changes to handle new `unify_is_real' parameter.
1995-10-09 17:12:47 +00:00
Fergus Henderson
6794113037 Implement unary plus and minus.
compiler/prog_io.m:
	Implement unary plus and minus.
1995-09-21 06:47:24 +00:00
Dylan Shuttleworth
8e97eb0221 A new option called --halt-at-warn has been added.
options.m
	A new option called --halt-at-warn has been added.  The idea is for
	mmake to halt when a warning is reported by mc, by mc setting the
	exit status to one.  mc -h phrases this better.

det_analysis.m make_hlds.m mercury_compile.pp prog_io.m typecheck.m
	Recognise the new --halt-at-warn option.  Some of the error reports
	in det_analysis.m now also give an error exit status.
1995-08-29 05:25:53 +00:00
Zoltan Somogyi
bebe96be34 Look inside blocks introduced by value numbering when looking
frameopt:
	Look inside blocks introduced by value numbering when looking
	restorations of succip.

value_number, opt_util:
	If we are using conservative garbage collection, disable value
	numbering for blocks that allocate more than one cell on the heap.
	This allows value numbering of most blocks to work in the absence
	of -DALL_INTERIOR_POINTERS.

all other source files:
	Clean up "blank" lines that nevertheless contain space or tab
	characters.
1995-08-27 11:10:20 +00:00
Fergus Henderson
760b99015c Another big batch of changes for higher-order predicates.
This set of changes includes most of the work necessary for
mode and determinism checking of higher-order predicates.

prog_io.m:
	Change the syntax for lambda expressions: they need
	to have a determinism declaration.  Lambda
	expressions must now look like this:

		lambda([X::in, Y::out] is det, ...goal...).
				       ^^^^^^

	Note that both the modes and the determinism are mandatory,
	not optional.

hlds.m:
	Insert a determinism field in the lambda_goal structure.

hlds_out.m, inlining.m, make_hlds.m, modes.m, polymorphism.m, quantification.m,
switch_detection.m, typecheck.m:
	Modified to use lambda_goal/4 rather than lambda_goal/3.

prog_io.m:
	Add a new field to the `ground' inst, of type `maybe(pred_inst_info)'.
	We use this to store the modes and determinism of higher-order
	predicate terms.

code_info.m, inst_match.m, mercury_to_mercury.m, mode_util.m, modes.m,
polymorphism.m, shapes.m, undef_modes.m:
	Modified to handle higher-order pred modes:
	use ground/2 rather than ground/1.
	(Note that modes.m still requires a bit more work on this.)

llds.m:
	Add a new field to the call_closure/3 instruction to hold the
	caller address for use with profiling, since the C macros
	require a caller address.

dup_elim.m, frame_opt.m, garbage_out.m, live_map.m, middle_rec.m, opt_debug.m,
opt_util.m, value_number.m, vn_*.m:
	Modified to use call_closure/4 rather than call_closure/3.

mercury_to_mercury.m:
	Export mercury_output_det for use by hlds_out.m.
1995-08-26 20:04:46 +00:00
Fergus Henderson
67ab08e245 Rename list__sort' as list__sort_and_remove_dups'.
garbage_out.m, mercury_compile.pp, mode_util.m, prog_io.m, shapes.m,
switch_gen.m:
	Rename `list__sort' as `list__sort_and_remove_dups'.
1995-08-26 05:57:43 +00:00
Fergus Henderson
160a32038a More work on lambda expressions.
hlds.m:
	Insert new `list(mode)' field in the lambda_goal/2 structure.

hlds_out.m, inlining.m, quantification.m, switch_detection.m,
	Use lambda_goal/3 instead of lambda_goal/2.

parser.m, make_hlds.m, typecheck.m, modes.m:
	Parse, typecheck, and modecheck lambda expressions.

mercury_to_mercury.m:
	Export mercury_output_mode/4 for use by hlds_out.m.
1995-08-20 18:17:36 +00:00
Fergus Henderson
b87de68334 Implement unique modes. We do not handle local aliasing yet, so this
-------------------------------------------------------

Implement unique modes.  We do not handle local aliasing yet, so this
is still not very useful, except for io__state.  Destructive update is
not yet implemented.  Also note that this really only implements
"mostly unique" variables that may be non-unique on backtracking - we
don't check that you don't backtrack over I/O, for example.

prog_io.m, mode_util.m, modes.m, inst_match.m:
	Major changes to Handle unique modes.

mercury_to_mercury.m, polymorphism.m, prog_out.m, undef_modes.m:
	Use `ground(Uniqueness)' rather than just `ground'.

compiler/*.m:
	Fix compile errors now that unique modes are enforced: add a
	few calls to copy/2, and comment out lots of unique mode
	declarations that caused problems.

typecheck.m, mode_info.m:
	Hack around the use of unique modes, which doesn't work
	because we don't allow local aliasing yet: make the insts
	`uniq_type_info' and `uniq_mode_info' not unique at all,
	and add a call to copy/2 when extracting the io_state from
	type_info or mode_info.

-------------------------------------------------------

Plus a couple of unrelated changes:

hlds.m:
	Change the modes for the special predicates from `ground -> ground'
	to `in', so that any error messages that show those modes
	come out looking nicer.

	Add a new shared_inst_table for shared versions of user-defined
	insts.

mercury_to_goedel.m:
	Use string__is_alnum_or_underscore.
1995-08-02 07:53:53 +00:00
Zoltan Somogyi
2946fb475b Improved the format of the message about calls with wrong arity.
typecheck:
	Improved the format of the message about calls with wrong arity.

jumpopt, optimize:
	A goto whose target is the predicate entry label is replaced by
	the pointed-to code only if a flag is set; optimize sets the flag
	only after value numbering and frameopt. This means the pointed-to
	code is in better shape when it is "inlined".

peephole, opt_util:
	When optimizing incr_sp/decr_sp pairs, allow a restoration of succip
	between them to be optimized away. This works because the only way
	this can happen is if the store of succip in its slot was promoted
	before the incr_sp, and no calls may have been in the meantime,
	so the original copy is still in succip.

frameopt, optimize:
	Postponed the check for whether succip is ever restored, since
	peephole may affect the decision.

follow_code:
	We now push code from the outside context into this context before
	pushing code from this context into nested contexts, since this may
	give us more code to push. I also removed redundant references to
	ModuleInfo.

prog_io:
	Small formatting change.
1995-07-21 09:40:48 +00:00
Fergus Henderson
a049cd041e Allow "multi" as a synonym for "multidet", to be consistent
prog_io.m:
	Allow "multi" as a synonym for "multidet", to be consistent
	with the documentation (!).

	"multidet" will go away eventually, but I'd rather a gentle
	transition, so I haven't removed it yet.
1995-07-20 13:21:12 +00:00
David Jeffery
51d014833b Changed the representation of pragma declarations in the 'item' data type
prog_io.m:
	Changed the representation of pragma declarations in the 'item' data type
	to
	pragma(pragma) and introduced a new 'pragma' type. (At this stage, the
	pragma type is just
	:- type pragma ---> c_header_code(c_header_code).
	but this is more modifiable).

	Introduced a new predicate 'parse_pragma' to parse pragma declarations.

make_hlds.m:
mercury_compile.m:
mercury_to_goedel.m:
mercury_to_mercury.m:
	Follow through changes from the change to 'pragma' in 'item' in  prog_io.m.
1995-07-10 19:07:37 +00:00
David Jeffery
f52aa60eaf The 'pragma' declaration now requires a type of pragma (c_header_code only at
this stage). eg.
:- pragma(c_header_code, "#include <stdio.h>").

prog_io.m:
	Changed the predicate which parses the pragma declaration to require the
	inclusion of the pragma type ('c_header_code').

	Also changed the name of part of the 'item' type from pragma_verbatim to
	pragma_c_header.

make_hlds.m:
	Changed pragma_verbatim to pragma_c_header.

mercury_to_mercury.m:
	Changed pragma_verbatim to pragma_c_header.

mercury_to_goedel.m:
	Changed pragma_verbatim to pragma_c_header.

	Changed the predicate which handles producing code for a c header
	declaration. It now gives an error message and ignores the declaration
	instead of barfing.
1995-07-10 16:53:03 +00:00
David Jeffery
44a3c7eae2 Added the ability to use a "pragma" declaration, which adds a string verbatim
to the generated C source.  eg.

:- pragma("#include <stdio.h>").

This is the first part of the foreign language (well, C anyway) interface.
1995-07-10 06:13:46 +00:00
Fergus Henderson
231f9c5bb7 Don't replace multidet with nondet, since multidet has been
prog_io.m:
	Don't replace multidet with nondet, since multidet has been
	implemented now!
1995-04-15 08:41:37 +00:00
Fergus Henderson
b11e1dbae3 Call io__progname_base rather than io__progname.
mercury_compile.pp llds.m prog_io.m:
	Call io__progname_base rather than io__progname.
1995-04-08 07:31:35 +00:00
Zoltan Somogyi
389599b337 Revamped the determinism system.
prog_io, hlds:	Added the functor "multidet" to the type determinism.
		Added types and predicates to relate determinism to its
		two components, can_fail and soln_count.

		Removed the functor "unspecified" from the type determinism,
		substituting maybe(determinism) for determinism in proc_info.

		Replaced the type category with the type code_model,
		and added predicates to compute it from determinism.

det_analysis:	Redone the analyses to work with determinism, not category
		(or code_model). This should enable programmers to write
		their own erroneous (and failure) predicates.

other files:	Use the new and renamed types and access predicates.
1995-04-06 02:13:05 +00:00
Fergus Henderson
ac4f8ba0fb Add copyright messages.
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!!!)
1995-03-30 21:03:41 +00:00
Fergus Henderson
72947699b9 Associate a term__context with every goal:
prog_io.m:
	Associate a term__context with every goal:
	rename the type `goal' as `goal_expr' and add
	`:- type goal == pair(goal_expr, term__context)'.

make_hlds.m, negation.m, mercury_to_mercury.m, mercury_to_goedel.m:
	Change to handle new representation of goals.

modes.m, typecheck.m:
	Use the term__context from the goals, since the above changes
	make it meaningful now.

implication.m, make_hlds.m, mercury_compile.pp:
	Fold the implication transformation into the make_hlds pass.

Net result: better error messages, but compilation time is worse.
1995-03-19 11:13:50 +00:00
Fergus Henderson
f371ae0f49 Fix bug in last change: it was introducing X = X unifications,
prog_io.nl:
	Fix bug in last change: it was introducing X = X unifications,
	which caused problems with determinism analysis.
1995-03-13 14:09:56 +00:00