githwxi / ATS-Postiats

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

`patcc source -DATS CUSTOM_DEFINE_targetloc=\"/some/path\"` is not applied to the source file #275

Closed bobajeff closed 1 year ago

bobajeff commented 1 year ago

I this small source file I have the following at the top.

#include "share/atspre_staload.hats"
staload UN = "prelude/SATS/unsafe.sats"
staload "libats/libc/SATS/stdlib.sats"

// PACKAGE_LOCATION should be defined as "/home/monkeykong/ats/projects/ats_package_manager/src"
staload RG = "{$PACKAGE_LOCATION}/helpers/randgen.sats"
staload _ = "{$PACKAGE_LOCATION}/helpers/randgen.dats"

I compile it with -DATS PACKAGE_LOCATION_targetloc=\"/home/monkeykong/ats/projects/ats_package_manager/src\" similar to what's shown here

But PACKAGE_LOCATION doesn't get defined and instead it looks for the file /tmp/.PATSRELOCROOT-monkeykong instead resulting in this error:

$ patscc ../src/bin/arrays.dats -latslib -D_GNU_SOURCE -DATS_MEMALLOC_LIBC -DATS PACKAGE_LOCATION_targetloc=\"/home/monkeykong/ats/projects/ats_package_manager/src\" -O2
/home/monkeykong/ats/projects/ats_package_manager/src/bin/arrays.dats: 165(line=6, offs=1) -- 220(line=6, offs=56): error(1): the file [/tmp/.PATSRELOCROOT-monkeykong/helpers/randgen.sats] is not available for staloading.
/home/monkeykong/ats/projects/ats_package_manager/src/bin/arrays.dats: 221(line=7, offs=1) -- 275(line=7, offs=55): error(1): the file [/tmp/.PATSRELOCROOT-monkeykong/helpers/randgen.dats] is not available for staloading.
patsopt(TRANS1): there are [2] errors in total.
exit(ATS): uncaught exception: _2home_2monkeykong_2ats_2ATS_INSTALL4_2ATS2_2src_2pats_error_2esats__FatalErrorExn(1025)
githwxi commented 1 year ago

I tried the following command-line, and it seemed to work properly:

patscc -DATS PACKAGE_LOCATION_targetloc='\"/home/monkeykong/ats/projects/ats_package_manager/src\"'

bobajeff commented 1 year ago

I've attached a small test case: define_error.zip

This is what I get when I run it: canstaloaderror

I'm using the latest revision of ATS-Postiats:

$git log -1
commit 3e2cfab792d4d9f2598aca354297f06e5410b7df (HEAD -> master, origin/master, origin/HEAD)
Merge: fb1dc0bbf a620f96f8
Author: Hongwei Xi <gmhwxi@gmail.com>
Date:   Tue Jan 3 16:00:33 2023 -0500

    Merge pull request #274 from bobajeff/master

    fix broken Makefiles
githwxi commented 1 year ago

Thanks for your detailed reporting.

The order of the arguments passed to patscc is significant. The following order should work:

patscc -DATS CUSTOM_DEFINE_targetloc='\".\"' testload.dats test_define.dats && ./a.out

bobajeff commented 1 year ago

That results in:

patsopt: error(0): the command-line argument [CUSTOM_DEFINE_targetloc=.] cannot be properly parsed.
exit(ATS): uncaught exception: _2home_2monkeykong_2ats_2ATS_INSTALL4_2ATS2_2src_2pats_error_2esats__FatalErrorExn(1025)

Updated the test case: define_error_v2.zip

githwxi commented 1 year ago

'"."' should be '\".\"' (a backslash in front of each double-quote).

bobajeff commented 1 year ago

Well that works. Thanks for the clarification. I've got to say it's awfully specific.

It won't work with just the backslash in front of double-quotes it has to have single quotes around the whole value plus the backslash in front of the double-quotes.

Also, the wiki should be updated to:

patscc -DATS JNI_targetloc='\"'"${JNI}"'\"' ...

Because bash won't expand variables inside single quotes you have to close each quote around the escaped double-quote and also double-quote the variable. (note the above is for linux/bash; I don't know about cygwin)

githwxi commented 1 year ago

I took a note of this. Currently, a string-parser is used to parse targetloc-values. I suppose I could write a parser that does not require these values being surrounded by double-quotes.