Line pragmas in ATS2 source

106 views
Skip to first unread message

Artyom Shalkhakov

unread,
Jan 10, 2016, 1:06:27 AM1/10/16
to ats-lang-users
Is it possible to emit a line pragma in ATS2 source?

I've written a (soon to be released) preprocessor for ATS2, and pragmas would be very valuable addition to help with debugging.

gmhwxi

unread,
Jan 10, 2016, 1:14:35 AM1/10/16
to ats-lang-users
If you pass the flag '--gline' to patscc or patsopt, the generated
C code should contain line pragmas.

gmhwxi

unread,
Jan 10, 2016, 1:37:42 AM1/10/16
to ats-lang-users
You said 'a line pragma in ATS2 source'.

I may not have understood your question correctly.

I am looking forward to the preprocessor!

Artyom Shalkhakov

unread,
Jan 10, 2016, 3:54:41 AM1/10/16
to ats-lang-users
On Sunday, January 10, 2016 at 12:37:42 PM UTC+6, gmhwxi wrote:
You said 'a line pragma in ATS2 source'.

I may not have understood your question correctly.

I am looking forward to the preprocessor!


Yes, I am generating ATS code for printing HTML fragments, kind of like a templating engine. I would like to retain positions from the source HTML file in the generated ATS code, for easier debugging.

The input file is plain HTML (or a fragment, but I haven't tested fragments yet...) with some ATS directives embedded in it. For instance, the input is:

<p>${1 + 2}</p>

and the output is basically:

val () = fprint!(out, "<p>")
#pragma 1 "input.html"
val
() = fprint!(out, 1 + 2)
val
() = fprint!(out, "</p>")

I'd like to specify that the second line in the above code is generated from the input (see the pragma, but it is rejected currently). So I need to put a #line pragma before the expression. It would be much easier to debug if line information was retained.

Sorry for the confusion.

Hongwei Xi

unread,
Jan 10, 2016, 10:13:41 AM1/10/16
to ats-lan...@googlegroups.com
There is currently no support for line pragmas in ATS source code.

For the moment, I suggest that you generate the following line for your example:

#print "input.html: line 1\n"

Such a line is printed out to the stderr. It can help debugging as well.


--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at https://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/cdcbea1e-9bdb-431a-9cea-f0fe0be7f3f0%40googlegroups.com.

gmhwxi

unread,
Jan 10, 2016, 11:35:30 AM1/10/16
to ats-lang-users

Sorry, what I suggested does not really work.


On Sunday, January 10, 2016 at 10:13:41 AM UTC-5, gmhwxi wrote:
There is currently no support for line pragmas in ATS source code.

For the moment, I suggest that you generate the following line for your example:

#print "input.html: line 1\n"

Such a line is printed out to the stderr. It can help debugging as well.

On Sun, Jan 10, 2016 at 3:54 AM, Artyom Shalkhakov <artyom...> wrote:
On Sunday, January 10, 2016 at 12:37:42 PM UTC+6, gmhwxi wrote:
You said 'a line pragma in ATS2 source'.

I may not have understood your question correctly.

I am looking forward to the preprocessor!


Yes, I am generating ATS code for printing HTML fragments, kind of like a templating engine. I would like to retain positions from the source HTML file in the generated ATS code, for easier debugging.

The input file is plain HTML (or a fragment, but I haven't tested fragments yet...) with some ATS directives embedded in it. For instance, the input is:

<p>${1 + 2}</p>

and the output is basically:

val () = fprint!(out, "<p>")
#pragma 1 "input.html"
val
() = fprint!(out, 1 + 2)
val
() = fprint!(out, "</p>")

I'd like to specify that the second line in the above code is generated from the input (see the pragma, but it is rejected currently). So I need to put a #line pragma before the expression. It would be much easier to debug if line information was retained.

Sorry for the confusion.
 
On Sunday, January 10, 2016 at 1:14:35 AM UTC-5, gmhwxi wrote:
If you pass the flag '--gline' to patscc or patsopt, the generated
C code should contain line pragmas.

On Sunday, January 10, 2016 at 1:06:27 AM UTC-5, Artyom Shalkhakov wrote:
Is it possible to emit a line pragma in ATS2 source?

I've written a (soon to be released) preprocessor for ATS2, and pragmas would be very valuable addition to help with debugging.

--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-users+unsubscribe@googlegroups.com.
To post to this group, send email to ats-lang-users@googlegroups.com.

gmhwxi

unread,
Jan 10, 2016, 12:08:19 PM1/10/16
to ats-lang-users
Because ATS will be used more and more as a target language,
supporting various forms of #pragma is becoming a very important issue.

I will find some time to do this (hopefully before the next release). A general
pragma should look like:

#pragma(CATEGORY, arg1, arg2, ...)

So a line pragma looks like:

#pragma(line, FILENAME, LINE_NUMBER)

This issue is now mention on ats-lang-devel:

https://groups.google.com/forum/?fromgroups=#!topic/ats-lang-devel/S3bGXL2OLnM

Artyom Shalkhakov

unread,
Jan 10, 2016, 10:22:19 PM1/10/16
to ats-lang-users
On Sunday, January 10, 2016 at 11:08:19 PM UTC+6, gmhwxi wrote:
Because ATS will be used more and more as a target language,
supporting various forms of #pragma is becoming a very important issue.

I will find some time to do this (hopefully before the next release). A general
pragma should look like:

#pragma(CATEGORY, arg1, arg2, ...)

So a line pragma looks like:

#pragma(line, FILENAME, LINE_NUMBER)

This issue is now mention on ats-lang-devel:

https://groups.google.com/forum/?fromgroups=#!topic/ats-lang-devel/S3bGXL2OLnM


Thanks, Hongwei!

May I also mention right away that specifying column would be useful as well?

I couldn't find something similar in GCC right away (seems like they don't support column specification), but MLton does support it, linking for reference:

gmhwxi

unread,
Jan 11, 2016, 12:20:43 AM1/11/16
to ats-lang-users
Okay.

I can introduce something like:

//
#pragma
( location
, "abcde.dats"
, "69(line=4, offs=31) -- 88(line=4, offs=50)"
)
//

This should be pretty straightforward to support.

My plan is to use pragma to support meta-programming.
For instance, #codegen2 is such an example. Supporting
line pragma is really just a very simple and special case.

gmhwxi

unread,
Jan 18, 2016, 9:44:46 AM1/18/16
to ats-lang-users
This style of #pragma is now supported.
It should be going into the next release of ATS2.
Reply all
Reply to author
Forward
0 new messages