Error in building program with patscc

Program( shown below) type checks okay , but produce errors when building
with patscc . However when I comment the line :

val () = !p2.data := 200

patscc build the program without any error.

I invoke patscc like this :

patscc -DATS_MEMALLOC_LIBC -o ex1 ex1.dats

Any idea whats happening.

Thanks

ex1.dats :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

%{
struct slist {
int data;
struct slist *next;
} ;

%}

typedef CNode = $extype_struct"struct node {
int data;
struct node * next;
}"
of {data= int , next= ptr}

implement main0 () = () where {
val () = println! (“Example 1”)
//Allocate node in memory
val (pf, pfgc | p1) =
ptr_alloc ()

val () = !p1.data := 100

val (pf1, pfgc1 | p2) =
ptr_alloc ()

(* If I comment out the line below , then build have no probs *)
val () = !p2.data := 200

//Free node from memory
val () = ptr_free{…}{…} (pfgc , pf | p1)
val () = ptr_free{…}{…} (pfgc1 , pf1 | p2)
}

Hello Chotu,

Program( shown below) type checks okay , but produce errors when building
with patscc . However when I comment the line :

val () = !p2.data := 200

patscc build the program without any error.

I invoke patscc like this :

patscc -DATS_MEMALLOC_LIBC -o ex1 ex1.dats

Any idea whats happening.

Thanks

ex1.dats :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

%{
struct slist {
int data;
struct slist *next;
} ;

%}

typedef CNode = $extype_struct"struct node {
int data;
struct node * next;
}"
of {data= int , next= ptr}

Are you sure this $extype_struct usage is correct? How about defining the
struct in C code above, and then doing:

typedef CNode = $extype_struct “mynodetype” of {data=int, next=ptr}

?

I was under the impression that the first argument of $extype_struct must
be the struct name in C (syntactically an identifier), not the definition
in C itself.

In C, struct equality is nominal. For instance, two occurrences of struct{
int x; }
are always considered distinct. So doing something like
$extype"struct{…}" is almost
always leading to a compilation error when the generated C code (from ATS
source)
is compiled.On Friday, April 10, 2015 at 4:40:56 AM UTC-4, Chotu S wrote:

I still can’t seem to make it works. BTW there was a mistake in code that
I posted (sorry for that) .
Here is the new code :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

%{
struct node {
int data;
struct node *next;
} ;

%}

typedef CNode = $extype_struct"struct node {
int data;
struct node * next;
}"
of {data= int , next= ptr}

// This also does not work.
(* typedef CNode = $extype_struct"node" )
(
of {data= int , next= ptr} *)

implement main0 () = () where {
val () = println! (“Example 1”)
//Allocate node in memory
val (pf, pfgc | p1) =
ptr_alloc ()

val () = !p1.data := 100
val _ = println! (!p1.data)
val () = ptr_free{…}{…} (pfgc , pf | p1)
}

I am pretty sure I am making some silly mistake or overlooking something.

On Friday, April 10, 2015 at 12:45:05 PM UTC+5:30, Artyom Shalkhakov wrote:

Hello Chotu,

On Friday, April 10, 2015 at 12:51:07 PM UTC+6, Chotu S wrote:

Program( shown below) type checks okay , but produce errors when
building with patscc . However when I comment the line :

val () = !p2.data := 200

patscc build the program without any error.

I invoke patscc like this :

patscc -DATS_MEMALLOC_LIBC -o ex1 ex1.dats

Any idea whats happening.

Thanks

ex1.dats :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

%{
struct slist {
int data;
struct slist *next;
} ;

%}

typedef CNode = $extype_struct"struct node {
int data;
struct node * next;
}"
of {data= int , next= ptr}

Are you sure this $extype_struct usage is correct? How about defining the
struct in C code above, and then doing:

typedef CNode = $extype_struct “mynodetype” of {data=int, next=ptr}

?

I was under the impression that the first argument of $extype_struct must
be the struct name in C (syntactically an identifier), not the definition
in C itself.

implement main0 () = () where {
val () = println! (“Example 1”)
//Allocate node in memory
val (pf, pfgc | p1) =
ptr_alloc ()

val () = !p1.data := 100

val (pf1, pfgc1 | p2) =
ptr_alloc ()

(* If I comment out the line below , then build have no probs *)
val () = !p2.data := 200

//Free node from memory
val () = ptr_free{…}{…} (pfgc , pf | p1)
val () = ptr_free{…}{…} (pfgc1 , pf1 | p2)
}

Thanks a lot :slight_smile: . Program now builds without any error.On Friday, April 10, 2015 at 7:40:53 PM UTC+5:30, Artyom Shalkhakov wrote:

I think I figured it out.

Please take a look at the source below. Note that, in C, “struct S” is to
be used whenever you refer to a struct; if you want to refer to it by using
“S”, you have to typedef it. Also, the embedded C code is to be pasted at
the top of the C compilation unit (%{ → %{^).

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

%{^

typedef struct node {
int data;
struct node *next;
} c_node ;

%}

typedef CNode = $extype_struct"c_node"
of {data= int , next= ptr}

implement main0 () = () where {
val () = println! (“Example 1”)
//Allocate node in memory
val (pf, pfgc | p1) =
ptr_alloc ()

val () = !p1.data := 100
val _ = println! (!p1.data)
val () = ptr_free (pfgc , pf | p1)
}

I compiled it with: patscc -DATS_MEMALLOC_LIBC -fdats ex.dats

On Friday, April 10, 2015 at 12:51:07 PM UTC+6, Chotu S wrote:

Program( shown below) type checks okay , but produce errors when building
with patscc . However when I comment the line :

val () = !p2.data := 200

patscc build the program without any error.

I invoke patscc like this :

patscc -DATS_MEMALLOC_LIBC -o ex1 ex1.dats

Any idea whats happening.

Thanks

ex1.dats :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

%{
struct slist {
int data;
struct slist *next;
} ;

%}

typedef CNode = $extype_struct"struct node {
int data;
struct node * next;
}"
of {data= int , next= ptr}

implement main0 () = () where {
val () = println! (“Example 1”)
//Allocate node in memory
val (pf, pfgc | p1) =
ptr_alloc ()

val () = !p1.data := 100

val (pf1, pfgc1 | p2) =
ptr_alloc ()

(* If I comment out the line below , then build have no probs *)
val () = !p2.data := 200

//Free node from memory
val () = ptr_free{…}{…} (pfgc , pf | p1)
val () = ptr_free{…}{…} (pfgc1 , pf1 | p2)
}

I think I figured it out.

Please take a look at the source below. Note that, in C, “struct S” is to
be used whenever you refer to a struct; if you want to refer to it by using
“S”, you have to typedef it. Also, the embedded C code is to be pasted at
the top of the C compilation unit (%{ → %{^).

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

%{^

typedef struct node {
int data;
struct node *next;
} c_node ;

%}

typedef CNode = $extype_struct"c_node"
of {data= int , next= ptr}

implement main0 () = () where {
val () = println! (“Example 1”)
//Allocate node in memory
val (pf, pfgc | p1) =
ptr_alloc ()

val () = !p1.data := 100
val _ = println! (!p1.data)
val () = ptr_free (pfgc , pf | p1)
}

I compiled it with: patscc -DATS_MEMALLOC_LIBC -fdats ex.datsOn Friday, April 10, 2015 at 12:51:07 PM UTC+6, Chotu S wrote:

Program( shown below) type checks okay , but produce errors when building
with patscc . However when I comment the line :

val () = !p2.data := 200

patscc build the program without any error.

I invoke patscc like this :

patscc -DATS_MEMALLOC_LIBC -o ex1 ex1.dats

Any idea whats happening.

Thanks

ex1.dats :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

%{
struct slist {
int data;
struct slist *next;
} ;

%}

typedef CNode = $extype_struct"struct node {
int data;
struct node * next;
}"
of {data= int , next= ptr}

implement main0 () = () where {
val () = println! (“Example 1”)
//Allocate node in memory
val (pf, pfgc | p1) =
ptr_alloc ()

val () = !p1.data := 100

val (pf1, pfgc1 | p2) =
ptr_alloc ()

(* If I comment out the line below , then build have no probs *)
val () = !p2.data := 200

//Free node from memory
val () = ptr_free{…}{…} (pfgc , pf | p1)
val () = ptr_free{…}{…} (pfgc1 , pf1 | p2)
}

I still can’t seem to make it works. BTW there was a mistake in code that I
posted (sorry for that) .
Here is the new code :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

%{
struct node {
int data;
struct node *next;
} ;

%}

typedef CNode = $extype_struct"struct node {
int data;
struct node * next;
}"
of {data= int , next= ptr}

// This also does not work.
(* typedef CNode = $extype_struct"node" )
(
of {data= int , next= ptr} *)

implement main0 () = () where {
val () = println! (“Example 1”)
//Allocate node in memory
val (pf, pfgc | p1) =
ptr_alloc ()

val () = !p1.data := 100
val _ = println! (!p1.data)
val () = ptr_free{…}{…} (pfgc , pf | p1)
}

I am pretty sure I am making some silly mistake or overlooking something.On Friday, April 10, 2015 at 12:45:05 PM UTC+5:30, Artyom Shalkhakov wrote:

Hello Chotu,

On Friday, April 10, 2015 at 12:51:07 PM UTC+6, Chotu S wrote:

Program( shown below) type checks okay , but produce errors when building
with patscc . However when I comment the line :

val () = !p2.data := 200

patscc build the program without any error.

I invoke patscc like this :

patscc -DATS_MEMALLOC_LIBC -o ex1 ex1.dats

Any idea whats happening.

Thanks

ex1.dats :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

%{
struct slist {
int data;
struct slist *next;
} ;

%}

typedef CNode = $extype_struct"struct node {
int data;
struct node * next;
}"
of {data= int , next= ptr}

Are you sure this $extype_struct usage is correct? How about defining the
struct in C code above, and then doing:

typedef CNode = $extype_struct “mynodetype” of {data=int, next=ptr}

?

I was under the impression that the first argument of $extype_struct must
be the struct name in C (syntactically an identifier), not the definition
in C itself.

implement main0 () = () where {
val () = println! (“Example 1”)
//Allocate node in memory
val (pf, pfgc | p1) =
ptr_alloc ()

val () = !p1.data := 100

val (pf1, pfgc1 | p2) =
ptr_alloc ()

(* If I comment out the line below , then build have no probs *)
val () = !p2.data := 200

//Free node from memory
val () = ptr_free{…}{…} (pfgc , pf | p1)
val () = ptr_free{…}{…} (pfgc1 , pf1 | p2)
}