How to use view in vtypedef?

21 views
Skip to first unread message

Kiwamu Okabe

unread,
Apr 6, 2021, 2:11:59 AM4/6/21
to ats-lang-users
Dear all,

I'm trying to write following code:

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

#define RTM_DELETE 0x2
#define ENOTSUP 45

typedef rtentry = @{
member_a = int
}

typedef nhop_object = @{
member_b = int
}

vtypedef rib_cmd_info = @{
rc_rt = [l:addr] (rtentry @ l | ptr l)
}

fun rtsock_routemsg
{l1,l2:addr}
(pfrt: !rtentry@l1, pfnh: !nhop_object@l2 | cmd: int, rt: ptr l1, nh:
ptr l2, fibnum: int):
int =
cmd + !rt.member_a + !nh.member_b

fun rib_del_route
{l:addr}
(pf: !rib_cmd_info? >> rib_cmd_info @ l | rc: ptr l):
int =
undefined()

fun rib_action
{l:addr}
(pf: !rib_cmd_info? >> rib_cmd_info @ l | action: int, rc: ptr l):
int =
case+ action of
| RTM_DELETE => rib_del_route(pf | rc)
| _ => ENOTSUP

implement main0 () = {
var rc: rib_cmd_info
prval pfrc = view@rc
val error = rib_action(pfrc | RTM_DELETE, addr@rc)
prval () = view@rc := pfrc
}
```

But above code causes following error:

```
$ patscc -D_GNU_SOURCE -DATS_MEMALLOC_LIBC main.dats -lpthread
/home/kiwamu/src/metasepi-postmortem/PR/FreeBSD-kernel/253800/Resolution/ATS2/fix/main.dats:
694(line=36, offs=35) -- 696(line=36, offs=37): error(3): the function
argument needs to be a left-va
lue.
/home/kiwamu/src/metasepi-postmortem/PR/FreeBSD-kernel/253800/Resolution/ATS2/fix/main.dats:
680(line=36, offs=21) -- 702(line=36, offs=43): error(3): the linear
dynamic variable [pf$4748(-1)] i
s preserved but with an incompatible type.
/home/kiwamu/src/metasepi-postmortem/PR/FreeBSD-kernel/253800/Resolution/ATS2/fix/main.dats:
680(line=36, offs=21) -- 702(line=36, offs=43): error(3): mismatch of
static terms (tyleq):
The actual term is: S2Etyrec(flt0; npf=-1; rc_rt=S2Etop(knd=0;
S2Eexi(l(8480); ; S2Etyrec(flt0; npf=1; 0=S2Eapp(S2Ecst(@);
S2Ecst(rtentry), S2Evar(l(8480))), 1=S2Eapp(S2Ecst(ptr);
S2Evar(l(8480)
))))))
The needed term is: S2Eat(S2Etyrec(flt0; npf=-1;
rc_rt=S2Eexi(l$8631(14298); ; S2Etyrec(flt0; npf=1;
0=S2Eapp(S2Ecst(@); S2Ecst(rtentry), S2Evar(l$8631(14298))),
1=S2Eapp(S2Ecst(ptr); S2Evar(l$8
631(14298)))))); S2Evar(l(8484)))
/home/kiwamu/src/metasepi-postmortem/PR/FreeBSD-kernel/253800/Resolution/ATS2/fix/main.dats:
817(line=42, offs=26) -- 821(line=42, offs=30): error(3): the dynamic
expression cannot be assigned t
he type [S2Etyrec(flt0; npf=-1; rc_rt=S2Etop(knd=0; S2Eexi(l(8480); ;
S2Etyrec(flt0; npf=1; 0=S2Eapp(S2Ecst(@); S2Ecst(rtentry),
S2Evar(l(8480))), 1=S2Eapp(S2Ecst(ptr); S2Evar(l(8480)))))))].
/home/kiwamu/src/metasepi-postmortem/PR/FreeBSD-kernel/253800/Resolution/ATS2/fix/main.dats:
817(line=42, offs=26) -- 821(line=42, offs=30): error(3): mismatch of
static terms (tyleq):
The actual term is: S2Eat(S2Etyrec(flt0; npf=-1; rc_rt=S2Etop(knd=0;
S2Eexi(l(8480); ; S2Etyrec(flt0; npf=1; 0=S2Eapp(S2Ecst(@);
S2Ecst(rtentry), S2Evar(l(8480))), 1=S2Eapp(S2Ecst(ptr); S2Evar(l
(8480))))))); S2Evar(rc(8485)))
The needed term is: S2Etyrec(flt0; npf=-1; rc_rt=S2Etop(knd=0;
S2Eexi(l(8480); ; S2Etyrec(flt0; npf=1; 0=S2Eapp(S2Ecst(@);
S2Ecst(rtentry), S2Evar(l(8480))), 1=S2Eapp(S2Ecst(ptr);
S2Evar(l(8480)
))))))
/home/kiwamu/src/metasepi-postmortem/PR/FreeBSD-kernel/253800/Resolution/ATS2/fix/main.dats:
744(line=39, offs=22) -- 875(line=44, offs=2): error(3): the linear
dynamic variable [rc$view$5549(-1
)] is preserved but with an incompatible type.
/home/kiwamu/src/metasepi-postmortem/PR/FreeBSD-kernel/253800/Resolution/ATS2/fix/main.dats:
744(line=39, offs=22) -- 875(line=44, offs=2): error(3): mismatch of
static terms (tyleq):
The actual term is: S2Etyrec(flt0; npf=1; 0=S2Eapp(S2Ecst(@);
S2Ecst(rtentry), S2Evar(l$8634$8635(14302))), 1=S2Eapp(S2Ecst(ptr);
S2Evar(l$8634$8635(14302))))
The needed term is: S2Ecst(ptr_type)
/home/kiwamu/src/metasepi-postmortem/PR/FreeBSD-kernel/253800/Resolution/ATS2/fix/main.dats:
744(line=39, offs=22) -- 875(line=44, offs=2): error(3): mismatch of
static terms (tyleq):
The actual term is: S2Eexi(l$8634(14301); ; S2Etyrec(flt0; npf=1;
0=S2Eapp(S2Ecst(@); S2Ecst(rtentry), S2Evar(l$8634(14301))),
1=S2Eapp(S2Ecst(ptr); S2Evar(l$8634(14301)))))
The needed term is: S2Ecst(ptr_type)
/home/kiwamu/src/metasepi-postmortem/PR/FreeBSD-kernel/253800/Resolution/ATS2/fix/main.dats:
744(line=39, offs=22) -- 875(line=44, offs=2): error(3): mismatch of
static terms (tyleq):
The actual term is: S2Etyrec(flt0; npf=-1; rc_rt=S2Eexi(l$8634(14301);
; S2Etyrec(flt0; npf=1; 0=S2Eapp(S2Ecst(@); S2Ecst(rtentry),
S2Evar(l$8634(14301))), 1=S2Eapp(S2Ecst(ptr); S2Evar(l$8634(14
301))))))
The needed term is: S2Etyrec(flt0; npf=-1; rc_rt=S2Etop(knd=0;
S2Eexi(l(8480); ; S2Etyrec(flt0; npf=1; 0=S2Eapp(S2Ecst(@);
S2Ecst(rtentry), S2Evar(l(8480))), 1=S2Eapp(S2Ecst(ptr);
S2Evar(l(8480)
))))))
/home/kiwamu/src/metasepi-postmortem/PR/FreeBSD-kernel/253800/Resolution/ATS2/fix/main.dats:
744(line=39, offs=22) -- 875(line=44, offs=2): error(3): mismatch of
static terms (tyleq):
The actual term is: S2Eat(S2Etyrec(flt0; npf=-1;
rc_rt=S2Eexi(l$8634(14301); ; S2Etyrec(flt0; npf=1;
0=S2Eapp(S2Ecst(@); S2Ecst(rtentry), S2Evar(l$8634(14301))),
1=S2Eapp(S2Ecst(ptr); S2Evar(l$8
634(14301)))))); S2Evar(rc(8485)))
The needed term is: S2Eat(S2Etyrec(flt0; npf=-1; rc_rt=S2Etop(knd=0;
S2Eexi(l(8480); ; S2Etyrec(flt0; npf=1; 0=S2Eapp(S2Ecst(@);
S2Ecst(rtentry), S2Evar(l(8480))), 1=S2Eapp(S2Ecst(ptr); S2Evar(l
(8480))))))); S2Evar(rc(8485)))

```

Using view in vtypedef is bad manner on ATS2?

Best regards,
--
Kiwamu Okabe at METASEPI DESIGN

Hongwei Xi

unread,
Apr 6, 2021, 2:50:26 AM4/6/21
to ats-lan...@googlegroups.com
It is difficult to work as the following type as one cannot easily take out the rc_rt
component:

vtypedef rib_cmd_info = @{
  rc_rt = [l:addr] (rtentry @ l | ptr l)
}

It seems that you are trying to do C-style programming in ATS directly. This would
be difficult; it may not even be practical for large scale programming.


--
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 view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/CAEvX6d%3DoBJV8NS9nVh3gjaWYhduuxuCeEBSTa3%2BzdjFU1XpgSA%40mail.gmail.com.

Kiwamu Okabe

unread,
Apr 7, 2021, 12:50:43 AM4/7/21
to ats-lang-users
On Tue, Apr 6, 2021 at 3:50 PM Hongwei Xi <gmh...@gmail.com> wrote:
> vtypedef rib_cmd_info = @{
> rc_rt = [l:addr] (rtentry @ l | ptr l)
> }
>
> It seems that you are trying to do C-style programming in ATS directly. This would
> be difficult; it may not even be practical for large scale programming.

But... Another person tried to use the style:

https://github.com/xlq/aos/blob/master/vga-text.dats#L37

Hongwei Xi

unread,
Apr 7, 2021, 1:41:37 AM4/7/21
to ats-lan...@googlegroups.com
I see.

It may help if the existential quantifier [l:addr] is moved
out of the record:

vtypedef
rib_cmd_info = [l:addr]
@{
    rc_rt = (rtentry @ l | ptr l)
}

But programming using such a type is still quite burdensome.
I do have some designs for low-level programming in ATS3 but
right now my hands are tied with the very task of implementing ATS3.


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

Kiwamu Okabe

unread,
Apr 7, 2021, 1:52:04 AM4/7/21
to ats-lang-users
Dear Hongwei,

On Wed, Apr 7, 2021 at 2:41 PM Hongwei Xi <gmh...@gmail.com> wrote:
> But programming using such a type is still quite burdensome.

OK. I'll try the other implementation.

> I do have some designs for low-level programming in ATS3 but
> right now my hands are tied with the very task of implementing ATS3.

I can't wait use C language backend of ATS3 instead of JS!
Reply all
Reply to author
Forward
0 new messages