Setting up ATS-Contrib

221 views
Skip to first unread message

Matt Chelen

unread,
Apr 1, 2019, 11:53:00 AM4/1/19
to ats-lang-users
I'm trying to get ATS-Contrib set up and I'm concerned that I don't currently have it configured correctly. As per the documentation, I put the "contrib" folder in $PATSHOME and set $PATSCONTRIB to $PATSHOME.

The issue is that I tried compiling the SDL sample programs and, while the ATS compiler compiles them just fine, I get errors like the following from the resulting C source.

$ make
"/usr/local/lib/ats2-postiats-0.3.13"/bin/patscc -I"/usr/local/lib/ats2-postiats-0.3.13" -I"/usr/local/lib/ats2-postiats-0.3.13"/ccomp/runtime  -D_GNU_SOURCE -I/usr/include/SDL2 -D_REENTRANT  -o test00 test00.dats -L"/usr/local/lib/ats2-postiats-0.3.13"/ccomp/atslib/lib -latslib -lSDL2
test00_dats
.c:82:10: fatal error: SDL2/CATS/SDL.cats: No such file or directory
 
#include "SDL2/CATS/SDL.cats"
         
^~~~~~~~~~~~~~~~~~~~
compilation terminated
.
make
: *** [Makefile:41: test00] Error 1

The same thing happens if I set $PATSCONTRIB to $PATSHOME/contrib. Did I set something up incorrectly? Is this a problem with the library? Is this a Cygwin issue?

Thanks in advance.

Artyom Shalkhakov

unread,
Apr 2, 2019, 3:07:05 AM4/2/19
to ats-lang-users
Hi Matt,
Could you check what is in those -I directories? In particular, where are the SDL2/CATS/SDL.cats files located, and what is your $PATSCONTRIB, does it have an SDL2 subdirectory?
 
Thanks in advance.

Matt Chelen

unread,
Apr 2, 2019, 4:13:16 AM4/2/19
to ats-lang-users
My contrib folder is in $PATSHOME/contrib. I've tried setting both the $PATSCONTRIB environment variable to both $PATSHOME, which I think the documentation said to do (it is entirely possible that I misunderstood the phrasing), and $PATSHOME/contrib, both with the same result.

The SDL2 folder is in the contrib folder. It's just cloned from the GitHub repo and copied in there. The examples that I'm trying to build are in $PATSHOME/contrib/SDL2/TEST and the actual bindings are in $PATSHOME/contrib/SDL2/CATS/SDL.cats.

Here's the relevant part of the generated C file, showing that it has the correct path to the file in question in the comment.

/*
/usr/local/lib/ats2-postiats-0.3.13/contrib/SDL2/SATS/SDL.sats: 899(line=29, offs=1) -- 941(line=33, offs=3)
*/


//
#include "SDL2/CATS/SDL.cats"

What it looks like (to me) is that it's just not resolving properly. None of the prelude ATS files that are included before that point are throwing errors. Just that one. Manually changing the location to "contrib/SDL2/CATS/SDL.cats" allows patscc to get past the error, but I then run into similar errors with the files that it includes. I'm just not sure why it's not resolving properly. Adding contrib to the beginning is required to get it to resolve even if I set $PATSCONTRIB to $PATSHOME/contrib.

Do you think it might work properly if I move $PATSCONTRIB somewhere else or is something else going on?

Matt Chelen

unread,
Apr 2, 2019, 4:19:38 AM4/2/19
to ats-lang-users
I just realized now that the file referenced in the comment is the SATS file and that I had misread it, but it should hold that, if it can find the SATS file, which is simply in a different subdirectory of contrib/SDL2, it should be able to find the CATS file, unless I am mistaken about how this is supposed to be set up.

--
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/be4dd68f-82f5-4292-8b62-762a69bfcf9a%40googlegroups.com.


--
Matt Chelen

Artyom Shalkhakov

unread,
Apr 2, 2019, 4:23:06 AM4/2/19
to ats-lang-users
вт, 2 апр. 2019 г. в 11:19, Matt Chelen <mattc...@gmail.com>:
I just realized now that the file referenced in the comment is the SATS file and that I had misread it, but it should hold that, if it can find the SATS file, which is simply in a different subdirectory of contrib/SDL2, it should be able to find the CATS file, unless I am mistaken about how this is supposed to be set up.


Well, the #includes in .cats files are resolved by the underlying C compiler, hence I think the issue is somehow in the C compiler (maybe it needs another -I flag or some such?)
 

Matt Chelen

unread,
Apr 2, 2019, 4:33:21 AM4/2/19
to ats-lang-users
Manually including the contrib folder with a -I flag seems to have worked (other than the SDL_GetVersion function causing an undefined reference error), but I'm still confused as to why it didn't just work. The documentation basically states that the way I had it set up is a valid way to set up the contrib folder, whereas having to manually include the contrib folder says the opposite.



--
Matt Chelen

Artyom Shalkhakov

unread,
Apr 2, 2019, 4:57:34 AM4/2/19
to ats-lang-users
Matt,

Indeed it's quite puzzling to me as well.

вт, 2 апр. 2019 г. в 11:33, Matt Chelen <mattc...@gmail.com>:
Manually including the contrib folder with a -I flag seems to have worked (other than the SDL_GetVersion function causing an undefined reference error), but I'm still confused as to why it didn't just work. The documentation basically states that the way I had it set up is a valid way to set up the contrib folder, whereas having to manually include the contrib folder says the opposite.


Could you tell me what the following command evaluates to in your terminal:

$ pkg-config sdl2 --cflags

I picked it up from here:


Notice that in this makefile, CFLAGS are added to the C compiler so that it can find SDL2. Maybe the makefile should also add an -I<directory of contrib/>.

Matt Chelen

unread,
Apr 2, 2019, 5:02:54 AM4/2/19
to ats-lang-users
$ pkg-config sdl2 --cflags
-I/usr/include/SDL2 -D_REENTRANT

As a side-note, I passed the $PATSCONTRIB -I flag to the make command and it built test00 and test01, but test02 failed and test01 will not run, instead throwing an error on the first use of assertloc.

/usr/local/lib/ats2-postiats-0.3.13/contrib/SDL2/test/test01.dats: 311(line=25, offs=18) -- 331(line=25, offs=38)

test02 throws the same error as I had originally due to having different cflags, so I think I am going to have to edit the makefile to get it to recognize the added -I flag.



--
Matt Chelen

Artyom Shalkhakov

unread,
Apr 2, 2019, 5:08:21 AM4/2/19
to ats-lang-users
вт, 2 апр. 2019 г. в 12:02, Matt Chelen <mattc...@gmail.com>:
$ pkg-config sdl2 --cflags
-I/usr/include/SDL2 -D_REENTRANT

As a side-note, I passed the $PATSCONTRIB -I flag to the make command and it built test00 and test01, but test02 failed and test01 will not run, instead throwing an error on the first use of assertloc.

/usr/local/lib/ats2-postiats-0.3.13/contrib/SDL2/test/test01.dats: 311(line=25, offs=18) -- 331(line=25, offs=38)


You use Windows and Cygwin, right? I'm wondering if SDL2 even works in this setting? The assertion has to do with SDL_Init returning an error code. Could you add a call to SDL_GetError() somewhere in there? As shown here, basically:

 

Matt Chelen

unread,
Apr 2, 2019, 6:08:33 AM4/2/19
to ats-lang-users
SDL2 does work in Cygwin. It even has its own environment-specific SDL DLL. Additionally, I tried running it outside of Cygwin, using the required DLLs, and it failed on startup.

I added the -I flag to test02 in the makefile and it is also erroring on the first use of assertloc.

However, test00 returns the SDL version as expected.

According to GitHub, the SDL2 wrapper hasn't been updated in five years. Is it possible that it (or the examples) just doesn't work properly anymore?

Simply to test if there was something weird going on with assertloc, I tested this example ( https://github.com/githwxi/ATS-Postiats/blob/6539444fe641f7fa493140bd9940e5acf00960e3/doc/EXAMPLE/INTRO/f91.dats ) and it works fine.

If I set SDL_GetError() to a variable, it goes past it and errors at the first assertloc. If I try to print it directly, it won't let me; compilation fails. SDL_Log is unrecognized. I've yet to go through any of the ATS tutorial material (I was just trying to get all of this set up and working), so I'm unsure how to proceed.



--
Matt Chelen

Artyom Shalkhakov

unread,
Apr 2, 2019, 7:00:58 AM4/2/19
to ats-lang-users
вт, 2 апр. 2019 г. в 13:08, Matt Chelen <mattc...@gmail.com>:
SDL2 does work in Cygwin. It even has its own environment-specific SDL DLL. Additionally, I tried running it outside of Cygwin, using the required DLLs, and it failed on startup.

I added the -I flag to test02 in the makefile and it is also erroring on the first use of assertloc.

However, test00 returns the SDL version as expected.

According to GitHub, the SDL2 wrapper hasn't been updated in five years. Is it possible that it (or the examples) just doesn't work properly anymore?


Well, it compiles to C. So I guess that if you can run a toy C program that initializes SDL2 video subsystem properly on Windows with Cygwin, then the corresponding ATS program should work just the same. Could you try that as well?

Matt Chelen

unread,
Apr 2, 2019, 7:27:48 AM4/2/19
to ats-lang-users
Alright, to test it out, I tried building Lazy Foo's fourth SDL tutorial. It does not work, though that may be in part due to the fact that Cygwin applications apparently expect that an X11 server will be available. So I tested it in MSYS2's MinGW64 shell with the same compilation flags (adjusted for differences in library locations); it works.

Furthermore, I've discovered that, according to the SDL installation page ( https://wiki.libsdl.org/Installation ), Cygwin is no longer supported. Even if it did work, the reliance on an X11 server is fairly frustrating. Disappointing results overall. I'll have to see how I want to proceed. Ultimately, it would be nice if it compiled in MSYS2's MinGW64 shell, but alas.



--
Matt Chelen

Artyom Shalkhakov

unread,
Apr 2, 2019, 7:33:10 AM4/2/19
to ats-lang-users
вт, 2 апр. 2019 г. в 14:27, Matt Chelen <mattc...@gmail.com>:
Alright, to test it out, I tried building Lazy Foo's fourth SDL tutorial. It does not work, though that may be in part due to the fact that Cygwin applications apparently expect that an X11 server will be available. So I tested it in MSYS2's MinGW64 shell with the same compilation flags (adjusted for differences in library locations); it works.


Interesting.
 
Furthermore, I've discovered that, according to the SDL installation page ( https://wiki.libsdl.org/Installation ), Cygwin is no longer supported. Even if it did work, the reliance on an X11 server is fairly frustrating. Disappointing results overall. I'll have to see how I want to proceed. Ultimately, it would be nice if it compiled in MSYS2's MinGW64 shell, but alas.


Yes, under Cygwin the programs would have to rely in X11 anyways. I used such apps in the past, they are slow but they work (e.g. Emacs works).

Compiling ATS2 programs in MinGW64 should be doable, but there are some parts of the prelude that depend on POSIX interfaces (the compiler itself could be just as useful as Cygwinized application; at least in the short term). Do you intend to do some graphics apps using ATS? I'd suggest switching to Linux or MacOS for now, if you can.
 

Matt Chelen

unread,
Apr 2, 2019, 7:46:06 AM4/2/19
to ats-lang-users
Yeah, I had intended on creating some graphical apps. Or, at the very least, I like that option to be open to me. I'd also like to be able to stay on Windows, ideally, as that's where the rest of my development environment is at the moment.



--
Matt Chelen

Artyom Shalkhakov

unread,
Apr 3, 2019, 2:33:49 AM4/3/19
to ats-lang-users
On Tuesday, April 2, 2019 at 2:46:06 PM UTC+3, Matt Chelen wrote:
Yeah, I had intended on creating some graphical apps. Or, at the very least, I like that option to be open to me. I'd also like to be able to stay on Windows, ideally, as that's where the rest of my development environment is at the moment.


Matt, I'm sorry about that. The current Windows support is only through Cygwin. The C generated by patsopt is very minimal though, so it should be possible to provide at least a prelude so as to make the code portable to MinGW64. Last time I tried this I had some issues with the (a) setjmp/longjmp (used for exception handling), (b) some file I/O primitives in [filebas], (c) forking in patscc (since I was a bit too ambitious I wanted to port the whole compiler, not just the compiled programs -- now, patscc can be re-implemented instead in a bash script that would run under MSYS2 shell).

One other thing that might be problematic in such a port is that of build system: ATS1 and ATS2 by default use the "make" utility, so of course we'd need MSYS2 at the very least to make the build process portable (or we'd have to support some other alternative build system, such as SCons, -- it has been tried, it works, but it hasn't gained traction).

Please ping me if you're interested. Maybe we can work something out (especially that ATS3 is in the works, and we'll of course carry over the experience gained in this project).
 
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lan...@googlegroups.com.


--
Matt Chelen

--
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-lan...@googlegroups.com.


--
Cheers,
Artyom Shalkhakov

--
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-lan...@googlegroups.com.


--
Matt Chelen

--
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-lan...@googlegroups.com.


--
Cheers,
Artyom Shalkhakov

--
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-lan...@googlegroups.com.


--
Matt Chelen

--
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-lan...@googlegroups.com.


--
Cheers,
Artyom Shalkhakov

--
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-lan...@googlegroups.com.


--
Matt Chelen

--
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-lan...@googlegroups.com.


--
Cheers,
Artyom Shalkhakov

--
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-lan...@googlegroups.com.


--
Matt Chelen

--
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-lan...@googlegroups.com.


--
Cheers,
Artyom Shalkhakov

--
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-lan...@googlegroups.com.


--
Matt Chelen

Matt Chelen

unread,
Apr 3, 2019, 2:59:39 AM4/3/19
to ats-lang-users
I'd definitely be interested in such a project, but I don't know that I have the requisite knowledge to actually be of any help. I could certainly try (I've always been a "learn as you go" sort of person), but I feel fair warning that I may not be able to do much is in order.

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.


--
Matt Chelen

Artyom Shalkhakov

unread,
Apr 3, 2019, 9:05:29 AM4/3/19
to ats-lang-users
Hi Matt!

On Wednesday, April 3, 2019 at 9:59:39 AM UTC+3, Matt Chelen wrote:
I'd definitely be interested in such a project, but I don't know that I have the requisite knowledge to actually be of any help. I could certainly try (I've always been a "learn as you go" sort of person), but I feel fair warning that I may not be able to do much is in order.


Well it seems to me that this project is actually not as difficult as I thought!

I managed to compile some test programs and they run natively on Windows:


Now, the setup is of course quite difficult. Here's what I did:

  1. install MSYS2 and setup a development environment
  2. compile both ATS1 and ATS2 from sources under MSYS2
  3. in MSYS2 shell, install via pacman the mingw-w64-x86_64-toolchain (just hit ENTER to install all tools) -- of course I assume you run an x86_64 system
  4. try to compile a very simple program, but now with this toolchain.. how?
Basically the idea is that, to build a windows native app, you open the "MSYS2 MinGW 64-bit" shell (it's added to your Start Menu so it's easy to find).

To build an MSYS2 (aka non-native) app, you open the "MSYS2" shell. and then after opening the shell you just run "./configure&&make&&make install" as usual.

So, taking the example of arrinit.dats in $PATSHOME/doc/EXAMPLE/TESTATS, let us see what we can do.

The generated C file contains the prelude block (which just indiscriminately #includes all sorts of headers). We could also make our own user prelude tailored to Windows, I think.

Some notes:
  • the extensive symbolic linking that is used in ATS2 source repo is horribly broken in MSYS2 (see the note in my gist; basically, instead of symlinking, just copy the files over to their targets...)
    • oh, and I used git from MSYS2 to clone the ATS2/ATS2-contrib repos when following my own script, maybe that is why the symlinks got broken.
  • the whole ATS2 toolchain still works in MSYS2, which is a kind of Cygwin (meaning that all the binaries depend on msys dll) -- and we need a better solution for general building... or perhaps, just leave it at that
  • I created a branch that contains some fixes to ATS2 prelude to make this compilation possible -- the upside is that fixing is VERY minimal! it will get worse as we come to various system-provides functions, but shouldn't be too bad, I think.

Artyom Shalkhakov

unread,
Apr 4, 2019, 2:12:19 AM4/4/19
to ats-lang-users
 I've also found it experimentally that atslib needs to be built in the correct environment (and probably prelude as well). That is to say, build the libats and prelude in a "MSYS2 MinGW 64-bit shell".

Assuming that your working dir is $PATSHOME:

$ make -C ccomp/atslib -f Makefile clean
$ make -C ccomp/atslib -f Makefile all

Then the samples in doc/EXAMPLE/ATSLIB mostly work too. For now I'm just excluding the POSIX-specific functionality.
Reply all
Reply to author
Forward
0 new messages