Request for some comments on ats code

You can use alloca to allocate memory on stack at run-time.
Here is an example I did:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATS-QA-LIST/alloca.datsOn Friday, February 14, 2014 8:23:49 AM UTC-5, Brandon Barker wrote:

For stack allocation my impression is that you allocate it as a tuple:
See this page and the next page:
http://www.ats-lang.org/DOCUMENT/INTPROGINATS/HTML/x273.html

I don’t know how to write a function to allocate a tuple of arbitrary
size, however.

Brandon Barker
brand...@gmail.com <javascript:>

On Fri, Feb 14, 2014 at 2:16 AM, chotu s <cho...@gmail.com <javascript:>>wrote:

Thanks I’ll take a look soon.

On Fri, Feb 14, 2014 at 11:27 AM, gmhwxi <gmh...@gmail.com <javascript:>>wrote:

Here is an interface for vectors:

http://www.ats-lang.org/LIBRARY/libats/gvector.html

On Friday, February 14, 2014 12:52:16 AM UTC-5, gmhwxi wrote:

In general, if the index n occurs in the type vector(a, n), then the
size (of the type int(n)) should not be
stored inside a vector (of the type vector(a, n)). A big point in
having dependent types is to allow a vector
and its size information to be stored separately.

On Friday, February 14, 2014 12:39:37 AM UTC-5, gmhwxi wrote:

When you say ‘allocate the vector on a stack’, do you mean allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for vectors in
ats. If anyone can quickly go through it (whenever they get free time) and
comment on the points below will be great. I have tried the code to be
similar to examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack instead on a
    heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks


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...@googlegroups.com <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com<javascript:>
.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/2c3bcbb2-cad6-46da-956c-b0da4c129450%40googlegroups.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...@googlegroups.com <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com<javascript:>
.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/CAAZxu4zZHWYAW2AD8sU6VVdsQ7Fk%3DGbG81JdpMV5ZYPzYurAsg%40mail.gmail.com
.

Thanks I’ll take a look soon.On Fri, Feb 14, 2014 at 11:27 AM, gmhwxi gmh...@gmail.com wrote:

Here is an interface for vectors:

http://www.ats-lang.org/LIBRARY/libats/gvector.html

On Friday, February 14, 2014 12:52:16 AM UTC-5, gmhwxi wrote:

In general, if the index n occurs in the type vector(a, n), then the size
(of the type int(n)) should not be
stored inside a vector (of the type vector(a, n)). A big point in having
dependent types is to allow a vector
and its size information to be stored separately.

On Friday, February 14, 2014 12:39:37 AM UTC-5, gmhwxi wrote:

When you say ‘allocate the vector on a stack’, do you mean allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for vectors in ats.
If anyone can quickly go through it (whenever they get free time) and
comment on the points below will be great. I have tried the code to be
similar to examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack instead on a
    heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks


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 post to this group, send email to ats-lan...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/2c3bcbb2-cad6-46da-956c-b0da4c129450%40googlegroups.com
.

Yes, you can alway pass it. Dependent typing ensures what is passed is
always correct.
You can then build a convenience wrapper:

http://www.ats-lang.org/LIBRARY/contrib/libfloats/lavector.htmlOn Friday, February 14, 2014 2:15:15 AM UTC-5, chotu s wrote:

So how do I determine the number of elements in arrayptr array.

One way I think I could determine the total size in bytes of an array and
then divide size of individual type , but how do I do this ?
Or you are asking to pass “n” the size of vector to functions that need it.

Thanks

On Fri, Feb 14, 2014 at 11:22 AM, gmhwxi <gmh...@gmail.com <javascript:>>wrote:

In general, if the index n occurs in the type vector(a, n), then the size
(of the type int(n)) should not be
stored inside a vector (of the type vector(a, n)). A big point in having
dependent types is to allow a vector
and its size information to be stored separately.

On Friday, February 14, 2014 12:39:37 AM UTC-5, gmhwxi wrote:

When you say ‘allocate the vector on a stack’, do you mean allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for vectors in ats.
If anyone can quickly go through it (whenever they get free time) and
comment on the points below will be great. I have tried the code to be
similar to examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack instead on a
    heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks


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...@googlegroups.com <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com<javascript:>
.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/a2e3bd7e-44d5-4c25-a9a7-e6acfb2b07f0%40googlegroups.com
.

implement main0 () = {
var bytes = @[char]100
}On Saturday, February 15, 2014 5:23:51 AM UTC-5, chotu s wrote:

I can’t seem to compile the code for :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”
staload UN = “prelude/SATS/unsafe.sats”

implement main0 () = {
var bytes = @100
}

Or did you meant :

var bytes = @[byte][100]

On Fri, Feb 14, 2014 at 9:48 PM, gmhwxi <gmh...@gmail.com <javascript:>>wrote:

You are welcome.

A good design should decouple the issue of memory allocation
and object initialization:

extern
fun vector_make_ngc{n:int}{l:addr} (bytes(n) @ l | ptr (l)): vector

var bytes = @100 // statically allocated stack memory of 100 bytes
val vector = vector_make_ngc (view@bytes | addr@bytes)

Take a look at:

http://www.ats-lang.org/LIBRARY/libats/qlist.html

The functions qstruct_objectify and qstruct_unobjectify may shed some
light on this.

On Friday, February 14, 2014 10:56:05 AM UTC-5, chotu s wrote:

Thanks a “lot” guys , I’ll read all the suggestions and links
tomorrow(as it is late here) and will ask related question after that.

Regarding stack allocation , what I had in mind was small size and
temporary arrays whose size is known at compile time , some thing like val
v = make_local_vector_n(n) , where n is known at compile time.

I think stack allocation idea came to me from the udacity parallel
programming competition where allocating main memory on gpu was costly(if I
remember correctly) , but they had different types of memory layer so one
can also use the fast shared memory whose capacity ranged from 64K to
256K(subject to correction).

Thanks for great suggestions.

On Fri, Feb 14, 2014 at 8:50 PM, gmhwxi gmh...@gmail.com wrote:

Actually, most people do not realize that a real danger with alloca is
that tail-recursion,
which should be done in constant space, may easily cause stack-overflow
when it is coupled
with stack-allocation. The issue is very similar to inlining a function
that calls alloca.

On Friday, February 14, 2014 10:09:12 AM UTC-5, Brandon Barker wrote:

Thanks, also here’s some related discussion http://stackoverflow.com/
questions/1018853/why-is-alloca-not-considered-good-practice.
On Feb 14, 2014 9:43 AM, “gmhwxi” gmh...@gmail.com wrote:

You can use alloca to allocate memory on stack at run-time.
Here is an example I did:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAM
PLE/ATS-QA-LIST/alloca.dats

On Friday, February 14, 2014 8:23:49 AM UTC-5, Brandon Barker wrote:

For stack allocation my impression is that you allocate it as a
tuple:
See this page and the next page:
http://www.ats-lang.org/DOCUMENT/INTPROGINATS/HTML/x273.html

I don’t know how to write a function to allocate a tuple of
arbitrary size, however.

Brandon Barker
brand...@gmail.com

On Fri, Feb 14, 2014 at 2:16 AM, chotu s cho...@gmail.com wrote:

Thanks I’ll take a look soon.

On Fri, Feb 14, 2014 at 11:27 AM, gmhwxi gmh...@gmail.com wrote:

Here is an interface for vectors:

http://www.ats-lang.org/LIBRARY/libats/gvector.html

On Friday, February 14, 2014 12:52:16 AM UTC-5, gmhwxi wrote:

In general, if the index n occurs in the type vector(a, n), then
the size (of the type int(n)) should not be
stored inside a vector (of the type vector(a, n)). A big point in
having dependent types is to allow a vector
and its size information to be stored separately.

On Friday, February 14, 2014 12:39:37 AM UTC-5, gmhwxi wrote:

When you say ‘allocate the vector on a stack’, do you mean
allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for vectors
in ats. If anyone can quickly go through it (whenever they get free time)
and comment on the points below will be great. I have tried the code to be
similar to examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack
    instead on a heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks


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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/2c3bcbb2-ca
d6-46da-956c-b0da4c129450%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/CAAZxu4zZHW
YAW2AD8sU6VVdsQ7Fk%3DGbG81JdpMV5ZYPzYurAsg%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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/57f1a0bb-f0ba-4a06-95b3-15f988245530%40go
oglegroups.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...@googlegroups.com <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com<javascript:>
.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/3b808393-f696-4513-b065-f978e68e751b%40googlegroups.com
.