githwxi / ATS-Postiats

ATS2: Unleashing the Potentials of Types and Templates
www.ats-lang.org
Other
353 stars 54 forks source link

Is it correct that patsopt creates .c file while the .dats file occurs type error? #116

Closed master-q closed 9 years ago

master-q commented 9 years ago

Assign me.

master-q commented 9 years ago

Kiwamu Okabe

Is it correct that patsopt creates .c file while the .dats file occurs type error?

$ rm -f hoge.c
casper$ cat hoge.dats
implement main0 (a) = println! ("Hello world!")
casper$ patsopt -o hoge.c -d hoge.dats
/home/kiwamu/tmp/hoge.dats: 11(line=1, offs=11) -- 48(line=1,
offs=48): error(2): there is no suitable dynamic constant declared for
[main0].
TRANS2: there are [1] errors in total.
exit(ATS): uncaught exception:
_2home_2kiwamu_2src_2ATS_2dPostiats_2src_2pats_error_2esats__FatalErrorExn(1025)
casper$ ls -l hoge.c
-rw-r--r-- 1 kiwamu kiwamu 0 Jan  4 19:54 hoge.c

I think "hoge.c" should not be created on this case.

master-q commented 9 years ago

Hongwei

This issue requires some thoughts.

Patsopt can be used to compile several DATS files into a single C file. If Patsopt encounters a failure in the middle of a multi-file compilation, deleting the entire file may not be a good choice.

Also, I want to point out that a program in ATS may be still unable to be compiled into proper C code after the program passes typechecking. Sometimes, one needs to go over the (partially) generated C code in order to figure out what went wrong.

master-q commented 9 years ago

Shea Levy

For the Makefile issue, I suppose one can work around it by compiling to a temporary file and moving to the real file if compilation succeeds (all in the same rule of course)

master-q commented 9 years ago

Hongwei

Instead of generating an empty file, patsopt now generates a file containing one #error(...) directive if it encounters an error during typechecking, When such a file is compiled, the programmer is reminded of what went wrong. I will probably replace #error with something like PATSOPT_ERROR to make it easier for searching.

master-q commented 9 years ago

??? patsopt(TRANS3) does not return error number ???

master-q commented 9 years ago

Why auxerr(s) isn't care as error? Nonsense....

https://github.com/githwxi/ATS-Postiats/blob/041ba16d8ba146c6738c93977c45d7fdb0708ccc/src/pats_main.dats#L1212

Or, we should run process_cmdline function after recovering error case?

https://github.com/githwxi/ATS-Postiats/blob/041ba16d8ba146c6738c93977c45d7fdb0708ccc/src/pats_main.dats#L1435

master-q commented 9 years ago
  1. [x] Test to reproduce atsopt(TRANS*) https://github.com/master-q/ATS-Postiats/commit/3dfc0ba7c80f9f41daa09dad356ee963e5fe54da
  2. [x] Fix it (by Hongwei)
githwxi commented 9 years ago

I modified error-handling a bit. Now patsopt returns a non-zero value if it encounters an error.

githwxi commented 9 years ago

I modified error-handling a bit. Please give ATS2-github a try.

master-q commented 9 years ago

Thank's a lot!

$ cat main.dats
implement main0 () = print r where {
  val not_r = 0
}
$ patsopt -o main.c -d main.dats; echo $?
/home/kiwamu/tmp/main.dats: 28(line=1, offs=28) -- 29(line=1, offs=29): error(2): the dynamic identifier [r] is unrecognized.
patsopt(TRANS2): there are [1] errors in total.
exit(ATS): uncaught exception: _2home_2kiwamu_2src_2ATS_2dPostiats_2src_2pats_error_2esats__FatalErrorExn(1025)
1