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 <kiw...@debian.or.jp>:

> 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.

Reply via email to