case expressions in let binding and dataviewtypes

2020-10-13 Thread Dambaev Alexander
Hi,

In this example, I am trying to define a binding of type Option_vt(int),

```
#include "share/atspre_staload.hats"

#define ATS_DYNLOADFLAG 0

implement main0() = {
  val a = 0
  val b =
case+ a of
| 0 => Some_vt(0) *(* 9 *)*
| _ => None_vt()  *(* 10 *)*
  val () =
case+ b of
| ~None_vt() => ()
| ~Some_vt(_) => ()
}
```
but I get the following error from the compiler:
```
patscc -O2 -DATS_MEMALLOC_LIBC -I"../libs/" -o issue   main.dats
/data/devel/ats2/issue/main.dats: 136(line=9, offs=12) -- 146(line=9,
offs=22): error(3): the dynamic expression cannot be assigned the type
[S2EVar(5243)].
/data/devel/ats2/issue/main.dats: 136(line=9, offs=12) -- 146(line=9,
offs=22): error(3): mismatch of sorts in unification:
The sort of variable is: S2RTbas(S2RTBASimp(1; t@ype))
The sort of solution is: S2RTbas(S2RTBASimp(2; viewtype))
/data/devel/ats2/issue/main.dats: 136(line=9, offs=12) -- 146(line=9,
offs=22): error(3): mismatch of static terms (tyleq):
The actual term is: S2Eapp(S2Ecst(option_vt0ype_bool_vtype);
S2Eapp(S2Ecst(g1int_int_t0ype); S2Eextkind(atstype_int), S2Eintinf(0)),
S2Ecst(true_bool))
The needed term is: S2EVar(5243)
/data/devel/ats2/issue/main.dats: 158(line=10, offs=12) -- 167(line=10,
offs=21): error(3): the dynamic expression cannot be assigned the type
[S2EVar(5243)].
/data/devel/ats2/issue/main.dats: 158(line=10, offs=12) -- 167(line=10,
offs=21): error(3): mismatch of sorts in unification:
The sort of variable is: S2RTbas(S2RTBASimp(1; t@ype))
The sort of solution is: S2RTbas(S2RTBASimp(2; viewtype))
/data/devel/ats2/issue/main.dats: 158(line=10, offs=12) -- 167(line=10,
offs=21): error(3): mismatch of static terms (tyleq):
The actual term is: S2Eapp(S2Ecst(option_vt0ype_bool_vtype); S2EVar(5245),
S2Ecst(false_bool))
The needed term is: S2EVar(5243)
/data/devel/ats2/issue/main.dats: 200(line=13, offs=7) -- 210(line=13,
offs=17): error(3): the constructor pattern cannot be assigned the type
[S2EVar(5243)].
/data/devel/ats2/issue/main.dats: 223(line=14, offs=7) -- 234(line=14,
offs=18): error(3): the constructor pattern cannot be assigned the type
[S2EVar(5243)].
```
what is wrong with this example?

Instead, this example is working:
```
#include "share/atspre_staload.hats"

#define ATS_DYNLOADFLAG 0

implement main0() = {
  val a = 0
  val b =
* f(a) where {fn f(a:int):<> Option_vt(int) =*
case+ a of
| 0 => Some_vt(0)
| _ => None_vt()
  }
  val () =
case+ b of
| ~None_vt() => ()
| ~Some_vt(_) => ()
```
I have tried to reread the tutorial, but haven't found something related to
this behavior

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KxcKRHMZxWkZZTqy7yQLLbx3LQ_FeTGrSn76xvXWh4%2BeQ%40mail.gmail.com.


Re: How to define array members in typedef?

2020-10-13 Thread Dambaev Alexander
Hi,

```
#include "share/atspre_define.hats"
#include "share/atspre_staload.hats"

#define ATS_DYNLOADFLAG 0

%{^

#define \
atstyarr_field_undef(fname) fname[]
%} // end of [%{]

#define MAXPATHLEN 1024

typedef kld_file_stat = @{ version = int, name = (@[char][MAXPATHLEN])}

fun kern_kldstat {l:addr} (pf: !kld_file_stat @ l | p: ptr l): int = 0
where {
  val () = !p.name.[0] := 'A'
}

implement main0 () = {
}
```
works, look in here:
http://ats-lang.steinwaywu.com/t/error-compiling-package-in-more-recent-ats-builds/704/6

пн, 12 окт. 2020 г. в 06:17, Kiwamu Okabe :

> Dear all,
>
> I wrote following code:
>
> ```ats
> #include "share/atspre_define.hats"
> #include "share/atspre_staload.hats"
>
> #define MAXPATHLEN 1024
>
> typedef kld_file_stat = @{ version = int, name = @[char][MAXPATHLEN]}
>
> fun kern_kldstat {l:addr} (pf: !kld_file_stat @ l | p: ptr l): int = 0
> where {
>   val () = !p.name.[0] := 'A'
> }
>
> implement main0 () = {
> }
> ```
>
> But it causes following compile error:
>
> ```
> $ patscc -D_GNU_SOURCE -DATS_MEMALLOC_LIBC main.dats -lpthread
> main_dats.c:122:1: warning: parameter names (without types) in
> function declaration
>   122 | atstkind_t0ype(atstype_char) atstyarr_field(atslab__name) ;
>   | ^~
> In file included from main_dats.c:14:
> /home/kiwamu/src/ATS-Postiats/ccomp/runtime/pats_ccomp_typedefs.h:176:31:
> error: field ‘atstyarr_field_undef’ declared as a function
>   176 | #define atstyarr_field(fname) atstyarr_field_undef(fname)
>   |   ^~~~
> main_dats.c:122:30: note: in expansion of macro ‘atstyarr_field’
>   122 | atstkind_t0ype(atstype_char) atstyarr_field(atslab__name) ;
>   |  ^~
> main_dats.c:127:1: warning: parameter names (without types) in
> function declaration
>   127 | atstkind_t0ype(atstype_char) atstyarr_field(atslab__name) ;
>   | ^~
> In file included from main_dats.c:14:
> /home/kiwamu/src/ATS-Postiats/ccomp/runtime/pats_ccomp_typedefs.h:176:31:
> error: field ‘atstyarr_field_undef’ declared as a function
>   176 | #define atstyarr_field(fname) atstyarr_field_undef(fname)
>   |   ^~~~
> main_dats.c:127:30: note: in expansion of macro ‘atstyarr_field’
>   127 | atstkind_t0ype(atstype_char) atstyarr_field(atslab__name) ;
>   |  ^~
> In file included from main_dats.c:15:
> main_dats.c: In function ‘kern_kldstat_0’:
> /home/kiwamu/src/ATS-Postiats/ccomp/runtime/pats_ccomp_instrset.h:226:45:
> error: ‘postiats_tyrec_0’ has no member named ‘atslab__name’
>   226 | #define ATSSELfltrec(pmv, tyrec, lab) ((pmv).lab)
>   | ^
> /home/kiwamu/src/ATS-Postiats/ccomp/runtime/pats_ccomp_instrset.h:339:34:
> note: in definition of macro ‘ATSINSstore’
>   339 | #define ATSINSstore(pmv1, pmv2) (pmv1 = pmv2)
>   |  ^~~~
> main_dats.c:218:13: note: in expansion of macro ‘ATSSELarrptrind’
>   218 | ATSINSstore(ATSSELarrptrind(ATSSELfltrec(ATSderef(arg0,
> postiats_tyrec_0), postiats_tyrec_1, atslab__name),
> atstkind_t0ype(atstype_char), [ATSPMVi0nt(0)]), ATSPMVchar('A')) ;
>   | ^~~
> main_dats.c:218:29: note: in expansion of macro ‘ATSSELfltrec’
>   218 | ATSINSstore(ATSSELarrptrind(ATSSELfltrec(ATSderef(arg0,
> postiats_tyrec_0), postiats_tyrec_1, atslab__name),
> atstkind_t0ype(atstype_char), [ATSPMVi0nt(0)]), ATSPMVchar('A')) ;
>   | ^~~~
> make: *** [../../../../../../mk/ats2-fix.mk:2: all] Error 1
> ```
>
> How to define array members in typedef using pure ATS language?
> Or should we use the following idiom with C language?
>
>
> https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/TESTATS/fieldarr.dats#L20
>
> Best regards,
> --
> Kiwamu Okabe at METASEPI DESIGN
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAEvX6dny%2BLS%2B4NDyGeon0j6VPPwKHATvsKFYOsT09ZD1rOEzUw%40mail.gmail.com
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KwCUDO%2BxbnJ7D2aua%3DuCU-scq9pqfkxGef0owZFX5UJcw%40mail.gmail.com.


Re: case expressions in let binding and dataviewtypes

2020-10-13 Thread Hongwei Xi
The support for type inference in ATS2 is weak.
Often you need a type annotation for a case-expression
(or an if-expression):

implement main0() = {
  val a = 0
  val b =
(
case+ a of
| 0 => Some_vt(0) *(* 9 *)*
| _ => None_vt()  *(* 10 *)*
) : Option_vt(int)
  val () =
case+ b of
| ~None_vt() => ()
| ~Some_vt(_) => ()
}

On Tue, Oct 13, 2020 at 10:09 AM Dambaev Alexander 
wrote:

> Hi,
>
> In this example, I am trying to define a binding of type Option_vt(int),
>
> ```
> #include "share/atspre_staload.hats"
>
> #define ATS_DYNLOADFLAG 0
>
> implement main0() = {
>   val a = 0
>   val b =
> case+ a of
> | 0 => Some_vt(0) *(* 9 *)*
> | _ => None_vt()  *(* 10 *)*
>   val () =
> case+ b of
> | ~None_vt() => ()
> | ~Some_vt(_) => ()
> }
> ```
> but I get the following error from the compiler:
> ```
> patscc -O2 -DATS_MEMALLOC_LIBC -I"../libs/" -o issue   main.dats
> /data/devel/ats2/issue/main.dats: 136(line=9, offs=12) -- 146(line=9,
> offs=22): error(3): the dynamic expression cannot be assigned the type
> [S2EVar(5243)].
> /data/devel/ats2/issue/main.dats: 136(line=9, offs=12) -- 146(line=9,
> offs=22): error(3): mismatch of sorts in unification:
> The sort of variable is: S2RTbas(S2RTBASimp(1; t@ype))
> The sort of solution is: S2RTbas(S2RTBASimp(2; viewtype))
> /data/devel/ats2/issue/main.dats: 136(line=9, offs=12) -- 146(line=9,
> offs=22): error(3): mismatch of static terms (tyleq):
> The actual term is: S2Eapp(S2Ecst(option_vt0ype_bool_vtype);
> S2Eapp(S2Ecst(g1int_int_t0ype); S2Eextkind(atstype_int), S2Eintinf(0)),
> S2Ecst(true_bool))
> The needed term is: S2EVar(5243)
> /data/devel/ats2/issue/main.dats: 158(line=10, offs=12) -- 167(line=10,
> offs=21): error(3): the dynamic expression cannot be assigned the type
> [S2EVar(5243)].
> /data/devel/ats2/issue/main.dats: 158(line=10, offs=12) -- 167(line=10,
> offs=21): error(3): mismatch of sorts in unification:
> The sort of variable is: S2RTbas(S2RTBASimp(1; t@ype))
> The sort of solution is: S2RTbas(S2RTBASimp(2; viewtype))
> /data/devel/ats2/issue/main.dats: 158(line=10, offs=12) -- 167(line=10,
> offs=21): error(3): mismatch of static terms (tyleq):
> The actual term is: S2Eapp(S2Ecst(option_vt0ype_bool_vtype); S2EVar(5245),
> S2Ecst(false_bool))
> The needed term is: S2EVar(5243)
> /data/devel/ats2/issue/main.dats: 200(line=13, offs=7) -- 210(line=13,
> offs=17): error(3): the constructor pattern cannot be assigned the type
> [S2EVar(5243)].
> /data/devel/ats2/issue/main.dats: 223(line=14, offs=7) -- 234(line=14,
> offs=18): error(3): the constructor pattern cannot be assigned the type
> [S2EVar(5243)].
> ```
> what is wrong with this example?
>
> Instead, this example is working:
> ```
> #include "share/atspre_staload.hats"
>
> #define ATS_DYNLOADFLAG 0
>
> implement main0() = {
>   val a = 0
>   val b =
> * f(a) where {fn f(a:int):<> Option_vt(int) =*
> case+ a of
> | 0 => Some_vt(0)
> | _ => None_vt()
>   }
>   val () =
> case+ b of
> | ~None_vt() => ()
> | ~Some_vt(_) => ()
> ```
> I have tried to reread the tutorial, but haven't found something related
> to this behavior
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KxcKRHMZxWkZZTqy7yQLLbx3LQ_FeTGrSn76xvXWh4%2BeQ%40mail.gmail.com
> 
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLot_wFq%2BbqZT4PAUoUM8EEgv_N_uc1FMYb%3Dbn9fhDs%2BEg%40mail.gmail.com.


Re: How to define array members in typedef?

2020-10-13 Thread Kiwamu Okabe
Thanks for your kind reply.

On Tue, Oct 13, 2020 at 11:49 PM Dambaev Alexander
 wrote:
> %{^
> #define \
> atstyarr_field_undef(fname) fname[]
> %} // end of [%{]

That works for me!
But I have questions. > Hongwei

A. Why is it not supported by the official ATS compiler?
B. Will it be supported by the ATS3 compiler?

Best regards,
-- 
Kiwamu Okabe at METASEPI DESIGN

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAEvX6dktjOpdJF11M4q1_S%2BNQ8wTej2KWwrxRZcpxZWOFkUVuw%40mail.gmail.com.


Re: How to define array members in typedef?

2020-10-13 Thread Kiwamu Okabe
Dear all,

On Tue, Oct 13, 2020 at 11:49 PM Dambaev Alexander
 wrote:
> %{^
> #define \
> atstyarr_field_undef(fname) fname[]
> %} // end of [%{]
>
> #define MAXPATHLEN 1024
>
> typedef kld_file_stat = @{ version = int, name = (@[char][MAXPATHLEN])}

And following more complex code is not compilable:

https://github.com/jats-ug/practice-ats/blob/master/array_typedef/main.dats

```ats
#include "share/atspre_define.hats"
#include "share/atspre_staload.hats"

%{^
#define atstyarr_field_undef(fname) fname[]
%} // end of [%{]

#define MAXPATHLEN 1024

typedef kld_file_stat = @{ version = int, name = @[char][MAXPATHLEN],
refs = int }

fun kern_kldstat {l:addr} (pf: !kld_file_stat @ l | p: ptr l): int = 0 where {
  val () = !p.name.[0] := 'A'
  val () = !p.refs := 1
}

implement main0 () = {
}
```

Best regards,
-- 
Kiwamu Okabe at METASEPI DESIGN

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAEvX6dmJBL%2ByRRzgRUq5dT1qr3wVk6_LBOxj_Op%2B1UNGXSoqEw%40mail.gmail.com.


Re: How to define array members in typedef?

2020-10-13 Thread Dambaev Alexander
GCC says, that it wants array field at the end of the struct, so:
```
typedef kld_file_stat = @{ version = int, refs = int, name =
@[char][MAXPATHLEN] }
```
works

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KyZvn6%3DP8pjFPPtj_ncPkMeok__gUz0kNO-XWq1o3%3DyHw%40mail.gmail.com.


Re: How to define array members in typedef?

2020-10-13 Thread Kiwamu Okabe
Thanks for your reply:

On Wed, Oct 14, 2020 at 8:50 AM Dambaev Alexander  wrote:
> GCC says, that it wants array field at the end of the struct, so:
> ```
> typedef kld_file_stat = @{ version = int, refs = int, name = 
> @[char][MAXPATHLEN] }
> ```

Yes. But there are more complex examples such as:

https://github.com/freebsd/freebsd/blob/master/sys/sys/linker.h#L334

```c
struct kld_file_stat {
intversion;/* set to sizeof(struct kld_file_stat) */
charname[MAXPATHLEN];
intrefs;
intid;
caddr_taddress;/* load address */
size_tsize;/* size in bytes */
charpathname[MAXPATHLEN];
};
```

It should have two arrays in a typedef.

Best regards,
-- 
Kiwamu Okabe at METASEPI DESIGN

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAEvX6dkS0QF0ngakogPuR51wwH6_-TW2wPLvns3Z2sud4uv%3DyQ%40mail.gmail.com.


Re: How to define array members in typedef?

2020-10-13 Thread Dambaev Alexander
in this case the issue is that ```fname[]``` contains no size information.
This one works:
```
#define MAXPATHLEN 1024
%{^
#define MAXPATHLEN 1024
#define atstyarr_field_undef(fname) fname[MAXPATHLEN]
%} // end of [%{]


typedef kld_file_stat = @{ version = int, name = @[char][MAXPATHLEN], refs
= int }
```

but I can't say how to make size not hardcoded

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KyP8xrSEVVm-eMFjL0STzf8ytkBN-3NqTW0_jv7aDxd2A%40mail.gmail.com.


Re: How to define array members in typedef?

2020-10-13 Thread Dambaev Alexander
so in this particular case it will work, but proper fix is to dig into
codegen in order to fix the generation of atstyarr_field to have a size
information

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KzQRKmz6kLAVO8aR93y4M_ogUOJA6eZD4Q7y5dke-L8hQ%40mail.gmail.com.


Re: How to define array members in typedef?

2020-10-13 Thread Kiwamu Okabe
Thanks for your kind reply.

On Wed, Oct 14, 2020 at 10:07 AM Dambaev Alexander
 wrote:
> so in this particular case it will work, but proper fix is to dig into 
> codegen in order
> to fix the generation of atstyarr_field to have a size information

Does it mean I should apply some patch to the ATS2 compiler?
If so, I would like to wait for the initial release of ATS3 and try that.

Best regards,
-- 
Kiwamu Okabe at METASEPI DESIGN

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAEvX6d%3DrURjS1TcPSF5meh91dzj2gBcyLBsC28jVxJg0OeTrTA%40mail.gmail.com.