# Error in building program with patscc

**URL:** <https://discourse.ats-lang.org/t/error-in-building-program-with-patscc/721>\
**Category:** Google Group\
**Created:** [April 10, 2015, 6:51am UTC](https://discourse.ats-lang.org/t/error-in-building-program-with-patscc/721 "2015-04-10T06:51:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chotu\_S](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@Chotu\_S](https://discourse.ats-lang.org/u/Chotu_S)\
**Post date:** [April 10, 2015, 6:51am UTC](https://discourse.ats-lang.org/t/error-in-building-program-with-patscc/721/1 "2015-04-10T06:51:07Z")

</div>

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)  
}

---

<div class="post-metadata">

**Author:** ![Artyom\_Shalkhakov](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@Artyom\_Shalkhakov](https://discourse.ats-lang.org/u/Artyom_Shalkhakov)\
**Post date:** [April 10, 2015, 7:15am UTC](https://discourse.ats-lang.org/t/error-in-building-program-with-patscc/721/2 "2015-04-10T07:15:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [April 10, 2015, 2:31pm UTC](https://discourse.ats-lang.org/t/error-in-building-program-with-patscc/721/3 "2015-04-10T14:31:20Z")

</div>

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)  
> > > }

---

<div class="post-metadata">

**Author:** ![Chotu\_S](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@Chotu\_S](https://discourse.ats-lang.org/u/Chotu_S)\
**Post date:** [April 10, 2015, 2:27pm UTC](https://discourse.ats-lang.org/t/error-in-building-program-with-patscc/721/4 "2015-04-10T14:27:16Z")

</div>

Thanks a lot 🙂 . 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)  
> > }

---

<div class="post-metadata">

**Author:** ![Artyom\_Shalkhakov](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@Artyom\_Shalkhakov](https://discourse.ats-lang.org/u/Artyom_Shalkhakov)\
**Post date:** [April 10, 2015, 2:10pm UTC](https://discourse.ats-lang.org/t/error-in-building-program-with-patscc/721/5 "2015-04-10T14:10:53Z")

</div>

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)  
> }

---

<div class="post-metadata">

**Author:** ![Chotu\_S](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@Chotu\_S](https://discourse.ats-lang.org/u/Chotu_S)\
**Post date:** [April 10, 2015, 8:40am UTC](https://discourse.ats-lang.org/t/error-in-building-program-with-patscc/721/6 "2015-04-10T08:40:56Z")

</div>

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)  
> > }
