How to use allocation out of POSIX?

43 views
Skip to first unread message

Kiwamu Okabe

unread,
Nov 15, 2015, 8:26:44 AM11/15/15
to ats-lang-users, ats-lang-users
Hi all,

Now, I'm porting ATS programming environment into tiny chip named ESP8266.

https://github.com/fpiot/esp8266-ats

And I'm trying to use strptr on the platform.

```
$ vi esp8266-ats/ESP8266_PRELUDE/CATS/memalloc.cats
#ifndef ATSLIB_PRELUDE_CATS_MEMALLOC
#define ATSLIB_PRELUDE_CATS_MEMALLOC

void atsruntime_mfree_undef (void *ptr) {
os_free(ptr);
return;
}
void *atsruntime_malloc_undef (size_t bsz) {
return ((void *)os_malloc(bsz));
}

#endif // ifndef ATSLIB_PRELUDE_CATS_MEMALLOC
$ vi esp8266-ats/ESP8266_PRELUDE/kernel_prelude.cats
--snip--
#include "ESP8266_PRELUDE/CATS/memalloc.cats"
$ vi esp8266-ats/dweet_ats/user/user_main.dats
--snip--
implement tcp_connected (arg) = {
val temperature = 55 (* test data *)
val conn = $UN.cast{cPtr1(espconn_t)}(arg)

val () = println! "tcp_connected()"
val _ = espconn_regist_recvcb (conn, data_received)

val json_data = string0_append ("{\"temperature\": ", "")
val () = free json_data
--snip--
```

However the code occurs following compile error:

```
$ cd esp8266-ats/dweet_ats
$ make
ATS user/user_main.dats
CC build/user/user_main_dats.c
In file included from build/user/user_main_dats.c:15:0:
build/user/user_main_dats.c: In function
'ATSLIB_056_prelude__string1_append__5__1':
/home/kiwamu/src/ATS-Postiats/ccomp/runtime/pats_ccomp_instrset.h:266:35:
error: assignment makes pointer from integer without a cast [-Werror]
#define ATSINSmove(tmp, val) (tmp = val)
^
build/user/user_main_dats.c:873:1: note: in expansion of macro 'ATSINSmove'
ATSINSmove(tmp19__1, atspre_malloc_gc(tmp20__1)) ;
^
cc1: all warnings being treated as errors
../Makefile.common:146: recipe for target 'build/user/user_main_dats.o' failed
make: *** [build/user/user_main_dats.o] Error 1
rm build/user/user_main_dats.c
```

What's wrong?

On POSIX, following code is available:

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

%{^
void atsruntime_mfree_undef (void *ptr) {
free(ptr);
return;
}
void *atsruntime_malloc_undef (size_t bsz) {
return malloc(bsz);
}
%}

implement main0 () = {
val json_data = string0_append ("{\"temperature\": ", "")
val () = println! json_data
val () = free json_data
}
```

Thanks,
--
Kiwamu Okabe at METASEPI DESIGN

Kiwamu Okabe

unread,
Nov 15, 2015, 8:44:45 AM11/15/15
to ats-lang-users, ats-lang-users
I make own prelude for the ESP8266 platform:

https://github.com/fpiot/esp8266-ats/tree/ats/ESP8266_PRELUDE
https://github.com/fpiot/esp8266-ats/blob/ats/Makefile.common#L42

The compile option is wrong?

```
ATSCFLAGS += -D_ATSTYPE_VAR_SIZE_=0X000F
-D_ATS_CCOMP_EXCEPTION_NONE_ -D_ATS_CCOMP_RUNTIME_NONE_
-D_ATS_CCOMP_PRELUDE_NONE_
-D_ATS_CCOMP_PRELUDE_USER_=\"../../ESP8266_PRELUDE/kernel_prelude.cats\"
```

Hongwei Xi

unread,
Nov 15, 2015, 8:53:33 AM11/15/15
to ats-lan...@googlegroups.com
I think your program was caused by not declaring some C functions before calling them. Should be easy to fix.


--
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.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/CAEvX6dn-ziE_%3Dod3Z_GvsUnqEoPsSieAHgjvV2RYXA6z_mo0_A%40mail.gmail.com.

Hongwei Xi

unread,
Nov 15, 2015, 8:57:54 AM11/15/15
to ats-lan...@googlegroups.com

Kiwamu Okabe

unread,
Nov 15, 2015, 9:58:50 AM11/15/15
to ats-lang-users
On Sun, Nov 15, 2015 at 10:53 PM, Hongwei Xi <gmh...@gmail.com> wrote:
> I think your program was caused by not declaring some C functions before
> calling them. Should be easy to fix.

I found how to fix it.
My own prelude doesn't include prelude/CATS/memory.cats, then the
atspre_malloc_gc function is undefined. It causes undefined function
return int value, but the value should be void * type.

https://github.com/fpiot/esp8266-ats/blob/ats/ESP8266_PRELUDE/kernel_prelude.cats

```
#include "prelude/CATS/integer.cats"
#include "prelude/CATS/pointer.cats"
#include "prelude/CATS/bool.cats"
#include "prelude/CATS/char.cats"
#include "prelude/CATS/integer_ptr.cats"
#include "prelude/CATS/integer_fixed.cats"
#include "prelude/CATS/memory.cats" // <= need it!
#include "prelude/CATS/string.cats"
#include "prelude/CATS/strptr.cats"
#include "prelude/CATS/array.cats"
#include "prelude/CATS/arrayptr.cats"
#include "prelude/CATS/arrayref.cats"

#include "ESP8266_PRELUDE/CATS/basics.cats"
#include "ESP8266_PRELUDE/CATS/fprintf.cats"
#include "ESP8266_PRELUDE/CATS/memalloc.cats"
```

Thanks,
Reply all
Reply to author
Forward
0 new messages