[mercury-users] term_expansion (was Re: Microsoft Common Lisp?)

Peter Schachte pets at cs.mu.oz.au
Wed Feb 19 12:47:59 AEDT 1997


On Tue, 18 Feb 1997, Fergus Henderson wrote:
> Ok, how about the following technique?
> It seems to address most of your concerns in points 2 & 3 above.
> 
> 	GET_PREPROCESSORS = sed -n '/^%%% PREPROCESSORS = /{s///p;q;}'
> 
> 	%.m: %.pp
> 		@echo "cat $< | `$(GET_PREPROCESSORS) $<` > $@"
> 		@cat $< | eval `$(GET_PREPROCESSORS) $<` > $@
> 
> The sed command searches for the first string of the form
> 
> 	%%% PREPROCESSORS = blah ...
> 
> So, would that satisfy your requirements?

Almost.

What I'd like to see is a full-fledged language feature.  Having this
information in the source file is important, but putting in in a
comment seems like a strange language design decision.  I'm also not
sure it would work properly when dependencies and interface files are
being built.  And it doesn't address the issue of where the
transformer executable is installed.  Finally, it doesn't admit the
future use of the more efficient runtime code loading, rather than the
more expensive source-file-source-file transformation, to to implement
it.

Here's a concrete proposal.

Add new directive to the language:

	:- transformation Module.

This would name a module in just the same way as :- import_module does
(following its example linguistically).  The named module would be
responsible for defining or importing any predicates necessary to perform
the specified transformation.  The predicate(s) that perform the
transformation would be specified in the named module by one or more
directives of the form:

	:- transformation_pred(When,Pred).

Where Pred is a closure pred(T::in, io_state::in, T::out,
io_state::out) which performs a needed transformation, and When is a
symbol defining at what syntactic level Pred is called (and thereby
specifying what type T is).  When could be any transformation_phase from
the following:

	simple_transformation_phase ---> file ; predicate ; goal.
	transformation_phase ---> 
		initial(simple_transformation_phase)
	    ;   type_checked(simple_transformation_phase)
	    ;   mode_checked(simple_transformation_phase)
	    ;   det_checked(simple_transformation_phase).

In the initial(file) case, T would be a list of items; for
initial(predicate), it would be a predicate definition; for
initial(goal) it would be a simple (not conjunction, disjunction, etc)
goal.  For the type_checked/1, mode_checked/1 and det_checked/1
variants, the types would be similar, but the transformation would be
performed at later stages of the analysis.

I realize that all (but possibly the initial/1 versions) will not be
portable to other implementations of Mercury.  But they are features we
will need in implementing some of the optimizations we will need for HAL,
so I'm thinking ahead here.  For starters, just having :- transformation
and :- transformation_pred(initial(...),...) would be very nice. 

I wouldn't mind implementing this.

-Peter Schachte      URL:  http://www.cs.mu.oz.au/~pets/
pets at cs.mu.OZ.AU     PGP:  finger pets at 128.250.37.150 for key
    [A computer is] like an Old Testament god, with a lot of rules
    and no mercy.  -- Joseph Campbell




More information about the users mailing list