[m-dev.] context "macros"

Peter Wang novalazy at gmail.com
Wed Mar 26 17:38:15 AEDT 2008


On 2008-03-26, Julien Fischer <juliensf at csse.unimelb.edu.au> wrote:
>
> On Wed, 26 Mar 2008, Ralph Becket wrote:
>
>> Julien Fischer, Tuesday, 25 March 2008:
>>>
>>> On Tue, 25 Mar 2008, Peter Wang wrote:
>>>
>>>> What do you think of adding support for __file__, __pred__, __line__
>>>> "macros"?  These would expand into strings or integers like the
>>>> corresponding C macros.
>>>
>>> I have often though something like this would be useful, particularly
>>> given that the this_file/0 functions we use in the compiler don't
>>> extend well when sub-modules are involved (you have to qualify them
>>> if the parent also defines a this_file/0 function.)
>>>
>>>> My concern was just about the syntax.  __foo__ has the advantages of
>>>> following C and requiring no changes to the parser.
>>>
>>>> __line__ is a
>>>> little bit sticky for referential transparency, but __file__ and
>>>> __pred__ would just act like variables assigned at the start of the
>>>> predicate.
>>>
>>> An alternative syntax suggestion: @line@, @file@ etc ...
>>
>> We haven't used the # symbol yet, as I recall.
>
> Yes we do, it is used with #line directives (ref. man 2.2).
>
> (On an slightly related matter I think we should replace pragma
> source_file with #file.)

Here is what a change to the reference manual might look like.
Julien said __ wasn't a great idea because it's still used as a module
qualifier so we chose $foo or $foo$.  $pred is easier to support than
$proc and for most code should be equivalent.


Index: doc/reference_manual.texi
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/doc/reference_manual.texi,v
retrieving revision 1.424
diff -u -r1.424 reference_manual.texi
--- doc/reference_manual.texi	27 Feb 2008 09:46:07 -0000	1.424
+++ doc/reference_manual.texi	26 Mar 2008 06:33:27 -0000
@@ -294,6 +294,10 @@
 and then another sequence of decimal digits (the exponent).
 The fraction part or the exponent (but not both) may be omitted.
 
+ at item compiler_defined_literal
+A compiler-defined literal consists of a dollar sign (@code{$})
+followed by a name.
+
 @item open_ct
 A left parenthesis, @samp{(}, that is not preceded by whitespace.
 
@@ -1322,7 +1326,8 @@
 @subsection Data-functors
 
 A data-functor is an integer, a float, a string, a character literal
-(any single-character name), a name, or a compound data-term.
+(any single-character name), a name, a compiler-defined literal,
+or a compound data-term.
 A compound data-term is a compound term which does not match
 the form of a special data-term (@pxref{Data-terms}),
 and whose arguments are data-terms.
@@ -1330,6 +1335,33 @@
 must name a function, predicate, or data constructor declared
 in the program or in the interface of an imported module.
 
+A compiler-defined literal is one of the following. They will be
+replaced by constants reflecting the context in which they appear.
+
+ at table @asis
+ at item @samp{$file}
+the name of the file (string)
+
+ at item @samp{$line}
+the line number (integer)
+
+ at item @samp{$module}
+the module name (string)
+
+ at item @samp{$pred}
+the predicate or function name and arity (string)
+
+ at item @samp{$grade}
+the compilation grade (string)
+
+ at item @samp{$date}
+the date (string)
+
+ at item @samp{$time}
+the time (string)
+
+ at end table
+
 @node Record syntax
 @subsection Record syntax
 


--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions:          mercury-developers-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the developers mailing list