Please try the following code:
                                                                                
                    

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

%{^
struct foo {
  int a;
  int *p;
};
struct foo foo_var;
%}

absvt@ype struct_foo
vtypedef struct_foo_impl = $extype_struct"struct foo" of {
  a = int,
  p = [l:addr] (int@l | ptr l)
}

vtypedef pstruct_foo = [l:addr] (struct_foo@l | ptr(l))

assume struct_foo = struct_foo_impl
macdef takeout_pstruct_foo = $extval(pstruct_foo, "&foo_var")
extern praxi addback_pstruct_foo (pstruct_foo): void

implement main0 () = {
  val (pf | p) = takeout_pstruct_foo
//  val () = foo.a := 1 // error(3): a non-proof component is replaced of 
the type[S2Ecst(int)].
  val () = println! !p.a
//  val () = println! foo.p // error(3): the symbol [print] cannot be 
resolved as no match is found.
  prval () = addback_pstruct_foo @(pf | p)
}

I put a running version here:

https://github.com/githwxi/ATS-Postiats-test/blob/master/contrib/hwxi/TEST30/test39.dats

On Friday, August 19, 2016 at 8:56:08 PM UTC-4, Kiwamu Okabe wrote:
>
> Hi all, 
>
> I'm writing following code, because seeking better way to use global 
> struct. 
>
> https://github.com/jats-ug/practice-ats/blob/master/extval/main.dats 
>
> ``` 
> #include "share/atspre_define.hats" 
> #include "share/atspre_staload.hats" 
>
> %{^ 
> struct foo { 
>   int a; 
>   int *p; 
> }; 
> struct foo foo_var; 
> %} 
>
> absvt@ype struct_foo 
> vtypedef struct_foo_impl = $extype_struct"struct foo" of { 
>   a = int, 
>   p = [l:addr] (int@l | ptr l) 
> } 
> assume struct_foo = struct_foo_impl 
> macdef takeout_struct_foo = $extval(struct_foo, "foo_var") 
> extern praxi addback_struct_foo (struct_foo): void 
>
> implement main0 () = { 
>   val foo = takeout_struct_foo 
> //  val () = foo.a := 1 // error(3): a non-proof component is replaced 
> of the type[S2Ecst(int)]. 
>   val () = println! foo.a 
> //  val () = println! foo.p // error(3): the symbol [print] cannot be 
> resolved as no match is found. 
>   prval () = addback_struct_foo foo 
> } 
> ``` 
>
> However, the code can't touch the member of the struct. 
> Is it non-sense code? 
>
> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/e9974a6b-0fb5-41ad-968f-8d7f71fdf6b0%40googlegroups.com.

Reply via email to