Fwd: [ats-lang-users] Multiple {DATS,SATS} directory

86 views
Skip to first unread message

Hongwei Xi

unread,
Sep 12, 2014, 1:32:05 PM9/12/14
to ats-lan...@googlegroups.com

---------- Forwarded message ----------
From: Kiwamu Okabe <kiw...@debian.or.jp>
Date: Fri, Sep 12, 2014 at 7:54 AM
Subject: [ats-lang-users] Multiple {DATS,SATS} directory
To: ats-lang-users <ats-lan...@lists.sourceforge.net>


Hi all,

May I use multiple {DATS,SATS} directory?

Now I'm trying to create an Arduino platform for ATS programming.

  https://github.com/fpiot/arduino-mega2560-ats

It has source code tree as following:

arduino-mega2560-ats
|-- Makefile
|-- Makefile.common
|-- _library
|   |-- DATS
|   `-- SATS
|-- blink_ats
|   |-- DATS
|   |   `-- main.dats
|   `-- Makefile
|-- lcd_ats
|   |-- DATS
|   |   |-- lcd.dats
|   |   `-- main.dats
|   |-- Makefile
|   `-- SATS
|       |-- arduino.sats
|       `-- lcd.sats
`-- serial_ats
    |-- DATS
    |   |-- hardware_serial.dats
    |   `-- main.dats
    |-- Makefile
    `-- SATS
        |-- arduino.sats
        `-- hardware_serial.sats

The {blink,lcd,serial}_ats/ directories are projects of Arduino.
However, they have own {DATS,SATS} directories.

How to put {arduino,hardware_serial,lcd}.sats into
arduino-mega2560-ats/_library/SATS/,
and {hardware_serial,lcd}.dats into arduino-mega2560-ats/_library/DATS/?
Also, I would like to main.dats {arduino,hardware_serial,lcd}_ats/DATS/.

Thank's,
--
Kiwamu Okabe at METASEPI DESIGN

------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
_______________________________________________
ats-lang-users mailing list
ats-lan...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ats-lang-users

gmhwxi

unread,
Sep 12, 2014, 2:41:14 PM9/12/14
to ats-lan...@googlegroups.com
You can just put arduino.sats inside _library/SATS.

To access it from blink_ats/DATS, you can just do:

staload "./../../_library/SATS/arduino.sats" // the first dot means to start from the current directory

Or you can do

#define LIBARDUINO_targetloc "/path/to/_library"

staload "{$LIBARDUINO}/SATS/arduino.sats"

On Friday, September 12, 2014 1:32:05 PM UTC-4, gmhwxi wrote:

gmhwxi

unread,
Sep 12, 2014, 2:48:14 PM9/12/14
to ats-lan...@googlegroups.com

To clean things up, I suggest the following structure:


arduino-mega2560-ats
|-- Makefile
|-- Makefile.common
|-- SATS
    |-- ardunio.sats
    |--blink
    |--lcd
    |--serial
|-- DATS
    |--blink
    |--lcd
    |--serial
|--- TEST/DEMO

Kiwamu Okabe

unread,
Sep 12, 2014, 2:51:22 PM9/12/14
to ats-lang-users
Hi Hongwei,
O.K.
I'll try to decide the source tree like this.

Kiwamu Okabe

unread,
Sep 12, 2014, 2:53:59 PM9/12/14
to ats-lang-users
Hi Hongwei,

On Sat, Sep 13, 2014 at 3:41 AM, gmhwxi <gmh...@gmail.com> wrote:
> #define LIBARDUINO_targetloc "/path/to/_library"
>
> staload "{$LIBARDUINO}/SATS/arduino.sats"

Ah, I know this now.
I think DATS files are compiled into "libarduino.a" file.

BTW, he other question: when we should compile SATS file?

gmhwxi

unread,
Sep 12, 2014, 3:05:56 PM9/12/14
to ats-lan...@googlegroups.com, kiw...@debian.or.jp
You may also need a 'CATS' directory.

The macdef code in your DATS-files should probably all be moved into
SATS-files.

The functions in DATS-files can be written as templates. So you don't need
to generate libarduino.a.

gmhwxi

unread,
Sep 12, 2014, 3:27:55 PM9/12/14
to ats-lan...@googlegroups.com, kiw...@debian.or.jp
>> BTW, the other question: when we should compile SATS file?

For now, a SATS-file does not need to be compiled (This is a place where ATS2 differs from ATS).


On Friday, September 12, 2014 2:53:59 PM UTC-4, Kiwamu Okabe wrote:

Kiwamu Okabe

unread,
Sep 12, 2014, 3:44:44 PM9/12/14
to ats-lang-users
Hi Hongwei,

On Sat, Sep 13, 2014 at 4:05 AM, gmhwxi <gmh...@gmail.com> wrote:
> The macdef code in your DATS-files should probably all be moved into
> SATS-files.

Following?

$ grep macdef serial_ats/DATS/hardware_serial.dats | head -5
macdef hserial = $extval(cPtr0(hardware_serial), "(&Serial)")
macdef F_CPU = $extval(ulint, "F_CPU")
macdef rx_buffer = $extval(cPtr0(ring_buffer), "&rx_buffer")
macdef tx_buffer = $extval(cPtr0(ring_buffer), "&tx_buffer")
macdef ADDR_UBRRH = $extval(ptr, "&ADDR_UBRRH")

But they are only for using in hardware_serial.dats, and not for main.dats...
I think they are private and not public.


> The functions in DATS-files can be written as templates. So you don't need
> to generate libarduino.a.

I should change all functions into template function?
Now I compile DATS files as following.

$ pwd
/home/kiwamu/src/arduino-mega2560-ats/lcd_ats
$ make
$ find . -name "*.o"
./wiring_analog.o
./wiring_digital.o
./DATS/lcd_dats.o
./DATS/main_dats.o

In the case, libarduino.a is a bad idea?

gmhwxi

unread,
Sep 12, 2014, 6:57:05 PM9/12/14
to ats-lan...@googlegroups.com, kiw...@debian.or.jp

On Friday, September 12, 2014 3:44:44 PM UTC-4, Kiwamu Okabe wrote:
Hi Hongwei,

On Sat, Sep 13, 2014 at 4:05 AM, gmhwxi <gmh...@gmail.com> wrote:
> The macdef code in your DATS-files should probably all be moved into
> SATS-files.

Following?

$ grep macdef serial_ats/DATS/hardware_serial.dats | head -5
macdef hserial   = $extval(cPtr0(hardware_serial), "(&Serial)")
macdef F_CPU = $extval(ulint, "F_CPU")
macdef rx_buffer = $extval(cPtr0(ring_buffer), "&rx_buffer")
macdef tx_buffer = $extval(cPtr0(ring_buffer), "&tx_buffer")
macdef ADDR_UBRRH = $extval(ptr, "&ADDR_UBRRH")

But they are only for using in hardware_serial.dats, and not for main.dats...
I think they are private and not public.

I see, Then they should stay in the DATS file.
 
> The functions in DATS-files can be written as templates. So you don't need
> to generate libarduino.a.

I should change all functions into template function?
Now I compile DATS files as following.

$ pwd
/home/kiwamu/src/arduino-mega2560-ats/lcd_ats
$ make
$ find . -name "*.o"
./wiring_analog.o
./wiring_digital.o
./DATS/lcd_dats.o
./DATS/main_dats.o

In the case, libarduino.a is a bad idea?
 
I need to take a closer look at your code. In general, short functions
should almost always be templates, allowing aggressive inlining. Also,
templates can give you many forms of programming freedom.

Kiwamu Okabe

unread,
Sep 13, 2014, 12:11:34 AM9/13/14
to ats-lang-users
Hi Hongwei,

On Sat, Sep 13, 2014 at 7:57 AM, gmhwxi <gmh...@gmail.com> wrote:
> I need to take a closer look at your code. In general, short functions
> should almost always be templates, allowing aggressive inlining. Also,
> templates can give you many forms of programming freedom.

Umm.... Not make sense.
I tried to use it.

https://github.com/fpiot/arduino-mega2560-ats/tree/feature/use-template

However, following error occurs.

$ cd arduino-mega2560-ats/demo/lcd_ats
$ grep include DATS/main.dats
#include "share/atspre_define.hats"
#include "share/atspre_staload.hats"
$ make
avr-gcc -g -Wall -Os -mmcu=atmega2560 -DF_CPU=16000000UL -std=c99
-D_XOPEN_SOURCE -D_ATS_CCOMP_EXCEPTION_NONE -D_ATSTYPE_VAR_SIZE=0X000F
-Wno-unused-variable -Wno-unused-label -Wno-unused-but-set-variable
-Wno-implicit-function-declaration -I. -I/home/kiwamu/src/ATS-Postiats
-I/home/kiwamu/src/ATS-Postiats/ccomp/runtime -I../..//_arduino
-I../..//_dummy -c -o wiring_digital.o wiring_digital.c
patsopt -o DATS/main_dats.c -d DATS/main.dats
avr-gcc -g -Wall -Os -mmcu=atmega2560 -DF_CPU=16000000UL -std=c99
-D_XOPEN_SOURCE -D_ATS_CCOMP_EXCEPTION_NONE -D_ATSTYPE_VAR_SIZE=0X000F
-Wno-unused-variable -Wno-unused-label -Wno-unused-but-set-variable
-Wno-implicit-function-declaration -I. -I/home/kiwamu/src/ATS-Postiats
-I/home/kiwamu/src/ATS-Postiats/ccomp/runtime -I../..//_arduino
-I../..//_dummy -c -o DATS/main_dats.o DATS/main_dats.c
In file included from DATS/main_dats.c:41:0:
/home/kiwamu/src/ATS-Postiats/prelude/CATS/filebas.cats: In function
‘atspre_fileref_open_exn’:
/home/kiwamu/src/ATS-Postiats/prelude/CATS/filebas.cats:177:8:
warning: assignment makes pointer from integer without a cast [enabled
by default]
filr = fopen((char*)path, (char*)fm) ;
^
In file included from DATS/main_dats.c:15:0:
DATS/main_dats.c: In function ‘mainats_void_0’:
DATS/main_dats.c:343:19: error: ‘PMVtmpltcstmat’ undeclared (first use
in this function)
ATSINSmove(tmp25, PMVtmpltcstmat[0](lcd_open<>)(ATSPMVi0nt(8),
ATSPMVi0nt(13), ATSPMVi0nt(9), ATSPMVi0nt(4), ATSPMVi0nt(5),
ATSPMVi0nt(6), ATSPMVi0nt(7))) ;
^

I'm confusing about the compiling process of template.
The "demo/lcd_ats/DATS/main.dats" file calls template function lcd_open{}.
The "SATS/lcd.sats" file has the declaration of lcd_open{}.
The "DATS/lcd.dats" file has the definition of lcd_open{}.

Why no need to compile lcs.dats file?

gmhwxi

unread,
Sep 13, 2014, 12:38:21 AM9/13/14
to ats-lan...@googlegroups.com, kiw...@debian.or.jp
You need to add the following line

staload
_ = "{$LIBARDUINO}/DATS/lcd.dats"

Templates in lcd.dats are "copied" into the file where they are used.
So they do not need to be compiled. Just like .h files do not need to be compiled.

Kiwamu Okabe

unread,
Sep 13, 2014, 1:44:09 AM9/13/14
to ats-lang-users
Hi Hongwei,

On Sat, Sep 13, 2014 at 1:38 PM, gmhwxi <gmh...@gmail.com> wrote:
> You need to add the following line
>
> staload _ = "{$LIBARDUINO}/DATS/lcd.dats"

Thank's! But............... The lcd.dats file can't include C language function?
-I../..//_dummy -Wl,-Map,main.map -o main.elf wiring_digital.o
DATS/main_dats.o
DATS/main_dats.o: In function `main':
/home/kiwamu/src/ATS-Postiats/ccomp/runtime/pats_ccomp_runtime.c:(.text+0x4):
undefined reference to `PMVerr'
/home/kiwamu/src/ATS-Postiats/ccomp/runtime/pats_ccomp_runtime.c:(.text+0x12):
undefined reference to `PMVerr'
/home/kiwamu/src/ATS-Postiats/ccomp/runtime/pats_ccomp_runtime.c:(.text+0x20):
undefined reference to `PMVerr'
/home/kiwamu/src/ATS-Postiats/ccomp/runtime/pats_ccomp_runtime.c:(.text+0x2e):
undefined reference to `PMVerr'
/home/kiwamu/src/ATS-Postiats/ccomp/runtime/pats_ccomp_runtime.c:(.text+0x48):
undefined reference to `PMVerr'
DATS/main_dats.o:/home/kiwamu/src/ATS-Postiats/ccomp/runtime/pats_ccomp_runtime.c:(.text+0x5a):
more undefined references to `PMVerr' follow
DATS/main_dats.o: In function `main':
/home/kiwamu/src/ATS-Postiats/ccomp/runtime/pats_ccomp_runtime.c:(.text+0x82):
undefined reference to `atspre_uint8_bit_or'
/home/kiwamu/src/ATS-Postiats/ccomp/runtime/pats_ccomp_runtime.c:(.text+0x8e):
undefined reference to `atspre_uint8_bit_or'
/home/kiwamu/src/ATS-Postiats/ccomp/runtime/pats_ccomp_runtime.c:(.text+0x98):
undefined reference to `PMVerr'
/home/kiwamu/src/ATS-Postiats/ccomp/runtime/pats_ccomp_runtime.c:(.text+0xa4):
undefined reference to `PMVerr'
/home/kiwamu/src/ATS-Postiats/ccomp/runtime/pats_ccomp_runtime.c:(.text+0xec):
undefined reference to `atspre_uint8_bit_and'

> Templates in lcd.dats are "copied" into the file where they are used.
> So they do not need to be compiled. Just like .h files do not need to be
> compiled.

BTW, is template really good for embedded application?
Arduino Uno board only has 32kB ROM and 2kB RAM.
And lcd_open function is large function.
I think space-efficient is very important in embedded application such
like Linux kernel.

gmhwxi

unread,
Sep 13, 2014, 2:03:11 AM9/13/14
to ats-lan...@googlegroups.com, kiw...@debian.or.jp

The C code in lcd.dats can be moved into CATS/lcd.cats.


BTW, is template really good for embedded application?
Arduino Uno board only has 32kB ROM and 2kB RAM.
And lcd_open function is large function.
I think space-efficient is very important in embedded application such
like Linux kernel.

You can control the use of templates.

Say you don't want to inline lcd_open. Then you can always do

fun lcd_open_ () = lcd_open<> ()

And then use lcd_open_ instead.

Using templates can help you adjust/adapt your code must more easily.

Kiwamu Okabe

unread,
Sep 13, 2014, 2:09:47 AM9/13/14
to ats-lang-users
Hi Hongwei,

On Sat, Sep 13, 2014 at 3:03 PM, gmhwxi <gmh...@gmail.com> wrote:
> You can control the use of templates.
>
> Say you don't want to inline lcd_open. Then you can always do
>
> fun lcd_open_ () = lcd_open<> ()
>
> And then use lcd_open_ instead.
>
> Using templates can help you adjust/adapt your code must more easily.

Where should I write the "lcd_open_" definition?

Please imagine a Linux kernel module.
The module provides "lcd_open" as a template.
The other modules depend on the "lcd_open".
How many "lcd_open" instance in the kernel, if they use "lcd_open_" style?

gmhwxi

unread,
Sep 13, 2014, 2:19:48 AM9/13/14
to ats-lan...@googlegroups.com, kiw...@debian.or.jp
Maybe lcd_open is not a good example to illustrate this point.

lcd_open_ is also declared in lcd.sats.

If lcd_open_ suffices, then one just calls lcd_open_.

The lcd_open template allows you to quickly build lcd_open2_ and lcd_open3_,
which are similar to lcd_open_ but with some small changes.

Kiwamu Okabe

unread,
Sep 13, 2014, 2:20:11 AM9/13/14
to ats-lang-users
Hi Hongwei,

On Sat, Sep 13, 2014 at 3:09 PM, Kiwamu Okabe <kiw...@debian.or.jp> wrote:
> Please imagine a Linux kernel module.
> The module provides "lcd_open" as a template.
> The other modules depend on the "lcd_open".
> How many "lcd_open" instance in the kernel, if they use "lcd_open_" style?

Or, should I write all DATS files other than main.dats in template style?
However, I think gcc will get single and BIG C language source file in
this case.

gmhwxi

unread,
Sep 13, 2014, 2:26:32 AM9/13/14
to ats-lan...@googlegroups.com, kiw...@debian.or.jp
Yes, a single and possibly BIG file of C code, which can enable gcc to do
very aggressive optimizations.

By the way, the generated object code may not be a lot bigger. You can do
some experiments to compare.

Kiwamu Okabe

unread,
Sep 13, 2014, 2:27:22 AM9/13/14
to ats-lang-users
Hi Hongwei,

On Sat, Sep 13, 2014 at 3:19 PM, gmhwxi <gmh...@gmail.com> wrote:
> Maybe lcd_open is not a good example to illustrate this point.

Umm.... I think it's a good example for embedded system.
In real programming, initialize function sometimes has many logics.
And also it should be library such like kernel module.


> lcd_open_ is also declared in lcd.sats.
>
> If lcd_open_ suffices, then one just calls lcd_open_.

Now, lcd.{sats,dats} user is only one, as main.dats.
However, theother.dats may staload lcd.{sats,dats} in the future?
In the case, I think there are two lcd_open instances.


> The lcd_open template allows you to quickly build lcd_open2_ and lcd_open3_,
> which are similar to lcd_open_ but with some small changes.

Of course, the template is good, if there are the variations.

gmhwxi

unread,
Sep 13, 2014, 2:33:43 AM9/13/14
to ats-lan...@googlegroups.com, kiw...@debian.or.jp
Now, lcd.{sats,dats} user is only one, as main.dats.
However, theother.dats may staload lcd.{sats,dats} in the future?
In the case, I think there are two lcd_open instances.

Only if theother.dats uses the lcd_open template. If it uses lcd_open_,
then there is only one instance, which is in lcd.dats:

implement lcd_open_ () = lcd_open<>

Kiwamu Okabe

unread,
Sep 13, 2014, 2:34:22 AM9/13/14
to ats-lang-users
Hi Hongwei,

On Sat, Sep 13, 2014 at 3:26 PM, gmhwxi <gmh...@gmail.com> wrote:
> Yes, a single and possibly BIG file of C code, which can enable gcc to do
> very aggressive optimizations.

Yeah.
However, we will lose binary modularity, such like kernel module....


> By the way, the generated object code may not be a lot bigger. You can do
> some experiments to compare.

My problem is that we should choose only following:

A. BIG single C code style, using fully template
B. Many small C code style, using partly template

A style has no binary modularity. It's a big rock.
B style has binary modularity. It can load by insmod or dlopen.

Kiwamu Okabe

unread,
Sep 13, 2014, 2:39:29 AM9/13/14
to ats-lang-users
Hi Hongwei,

On Sat, Sep 13, 2014 at 3:33 PM, gmhwxi <gmh...@gmail.com> wrote:
> Only if theother.dats uses the lcd_open template. If it uses lcd_open_,
> then there is only one instance, which is in lcd.dats:
>
> implement lcd_open_ () = lcd_open<>

Thank's, make sense!
I try to do it.

gmhwxi

unread,
Sep 13, 2014, 2:41:23 AM9/13/14
to ats-lan...@googlegroups.com, kiw...@debian.or.jp

By providing a template-based library, you can give the freedom to the user:
he or she can decide whether A or B or somewhere in between is good for his
or her project.

When I program, I often do not use a library directly. I often build a thin layer of
library code for my own project. In this thin layer, I have functions like lcd_open_,
lcd_open2_, lcd_open3_ (if needed).

Kiwamu Okabe

unread,
Sep 13, 2014, 2:58:50 AM9/13/14
to ats-lang-users
Hi Hongwei,

On Sat, Sep 13, 2014 at 3:03 PM, gmhwxi <gmh...@gmail.com> wrote:
> The C code in lcd.dats can be moved into CATS/lcd.cats.

Umm...
collect2: error: ld returned 1 exit status
../..//Makefile.common:30: recipe for target 'main.elf' failed
make: *** [main.elf] Error 1
$ grep -r PMVerr DATS/main_dats.c|head -5
ATSINSstore(ATSSELfltrec(ATSderef(ATSPMVcastfn(LCD_takeout_struct,
atstkind_type(atstype_ptrk), ATSPMVrefarg0(ATSPMVcastfn(castvwtp0,
atstype_boxed, PMVerr("/home/kiwamu/src/arduino-mega2560-ats/DATS/lcd.dats:
1942(line=55, offs=30) -- 1965(line=55, offs=53)")))),
postiats_tyrec_1), postiats_tyrec_1, atslab__rs_pin),
ATSPMVcastfn(cast, atstkind_t0ype(atstype_uint8), arg0)) ;
ATSINSstore(ATSSELfltrec(ATSderef(ATSPMVcastfn(LCD_takeout_struct,
atstkind_type(atstype_ptrk), ATSPMVrefarg0(ATSPMVcastfn(castvwtp0,
atstype_boxed, PMVerr("/home/kiwamu/src/arduino-mega2560-ats/DATS/lcd.dats:
1942(line=55, offs=30) -- 1965(line=55, offs=53)")))),
postiats_tyrec_1), postiats_tyrec_1, atslab__rw_pin),
ATSPMVcastfn(cast, atstkind_t0ype(atstype_uint8), arg1)) ;
ATSINSstore(ATSSELfltrec(ATSderef(ATSPMVcastfn(LCD_takeout_struct,
atstkind_type(atstype_ptrk), ATSPMVrefarg0(ATSPMVcastfn(castvwtp0,
atstype_boxed, PMVerr("/home/kiwamu/src/arduino-mega2560-ats/DATS/lcd.dats:
1942(line=55, offs=30) -- 1965(line=55, offs=53)")))),
postiats_tyrec_1), postiats_tyrec_1, atslab__enable_pin),
ATSPMVcastfn(cast, atstkind_t0ype(atstype_uint8), arg2)) ;
ATSINSstore(ATSSELfltrec(ATSderef(ATSPMVcastfn(LCD_takeout_struct,
atstkind_type(atstype_ptrk), ATSPMVrefarg0(ATSPMVcastfn(castvwtp0,
atstype_boxed, PMVerr("/home/kiwamu/src/arduino-mega2560-ats/DATS/lcd.dats:
1942(line=55, offs=30) -- 1965(line=55, offs=53)")))),
postiats_tyrec_1), postiats_tyrec_1, atslab__data_pins), tmp356) ;
ATSINSmove_void(tmp357,
pinMode(ATSSELfltrec(ATSderef(ATSPMVcastfn(LCD_takeout_struct,
atstkind_type(atstype_ptrk), ATSPMVrefarg0(ATSPMVcastfn(castvwtp0,
atstype_boxed, PMVerr("/home/kiwamu/src/arduino-mega2560-ats/DATS/lcd.dats:
1942(line=55, offs=30) -- 1965(line=55, offs=53)")))),
postiats_tyrec_1), postiats_tyrec_1, atslab__rs_pin),
ATSextval(OUTPUT))) ;

What is PMVerr?

Regards,
Message has been deleted

gmhwxi

unread,
Sep 13, 2014, 3:23:41 AM9/13/14
to ats-lan...@googlegroups.com, kiw...@debian.or.jp
val lcd = $UN.castvwtp0 (addr@_global_lcd_struct)

When using a cast function, please provide the type of the returned value:

val lcd = $UN.castvwtp0{...}
(addr@_global_lcd_struct)

What is ...?

gmhwxi

unread,
Sep 13, 2014, 3:43:26 AM9/13/14
to ats-lan...@googlegroups.com, kiw...@debian.or.jp
After seeing the following code:

local
var _global_lcd_struct: LCD_struct
in
...
end

I think it makes sense to introduce a template

fun{} lcd_get (): LCD // or use LCD_unintized

Use lcd_get to implement lcd_open. You can implement
lcd_get in main.dats if you like.



Kiwamu Okabe

unread,
Sep 13, 2014, 5:07:27 AM9/13/14
to ats-lang-users
Hi Hongwei,

On Sat, Sep 13, 2014 at 4:43 PM, gmhwxi <gmh...@gmail.com> wrote:
> local
> var _global_lcd_struct: LCD_struct
> in
> ...
> end
>
> I think it makes sense to introduce a template
>
> fun{} lcd_get (): LCD // or use LCD_unintized
>
> Use lcd_get to implement lcd_open. You can implement
> lcd_get in main.dats if you like.

Umm............................
I think "lcd_get" implementation is unsafe, and would like to it as
private to hide for main.dats....

Thank's,

Kiwamu Okabe

unread,
Sep 13, 2014, 5:37:17 AM9/13/14
to ats-lang-users
Ah!

On Sat, Sep 13, 2014 at 4:43 PM, gmhwxi <gmh...@gmail.com> wrote:
> After seeing the following code:
>
> local
> var _global_lcd_struct: LCD_struct
> in
> ...
> end

This trick doesn't work???
The main branch has following BUG, that data_pins[] array isn't
collectly allocated.

$ cat DATS/lcd.dats
--snip--
vtypedef LCD_struct = @{
rs_pin = uint8 // LOW: command. HIGH: character.
, rw_pin = uint8 // LOW: write to LCD. HIGH: read from LCD.
, enable_pin = uint8 // activated by a HIGH pulse.
, displayfunction = uint8
, displaycontrol = uint8
, displaymode = uint8
, numlines = uint8
, currline = uint8
, data_pins = @[uint8][4]
}
--snip--
local
var _global_lcd_struct: LCD_struct
in
implement lcd_open (rs, rw, enable, d0, d1, d2, d3) = let
val lcd = $UN.castvwtp0 (addr@_global_lcd_struct)
val (pfat | p) = LCD_takeout_struct (lcd)
val () = p->rs_pin := rs
val () = p->rw_pin := rw
val () = p->enable_pin := enable
val () = p->data_pins.[0] := d0
val () = p->data_pins.[1] := d1
val () = p->data_pins.[2] := d2
val () = p->data_pins.[3] := d3
--snip--
$ make
$ avr-gcc -Os -E -mmcu=atmega2560 -DF_CPU=16000000UL -std=c99
-D_XOPEN_SOURCE -D_ATS_CCOMP_EXCEPTION_NONE -D_ATSTYPE_VAR_SIZE=0X000F
-Wno-unused-variable -Wno-unused-label -Wno-unused-but-set-variable
-I. -I/home/kiwamu/src/ATS-Postiats
-I/home/kiwamu/src/ATS-Postiats/ccomp/runtime -I../_arduino
-I../_dummy DATS/lcd_dats.c
typedef
struct {
atstype_uint8 atslab__rs_pin;
atstype_uint8 atslab__rw_pin;
atstype_uint8 atslab__enable_pin;
atstype_uint8 atslab__displayfunction;
atstype_uint8 atslab__displaycontrol;
atstype_uint8 atslab__displaymode;
atstype_uint8 atslab__numlines;
atstype_uint8 atslab__currline;
atstype_uint8 atslab__data_pins[];
} postiats_tyrec_0 ;
--snip--
static postiats_tyrec_0 statmpref0 ;
--snip--
((((atstype_uint8*)(((*(postiats_tyrec_7*)((atstype_ptrk)(((atstype_boxed)(&(statmpref0))))))).atslab__data_pins))[(0)])
= arg3) ;
((((atstype_uint8*)(((*(postiats_tyrec_9*)((atstype_ptrk)(((atstype_boxed)(&(statmpref0))))))).atslab__data_pins))[(1)])
= arg4) ;
((((atstype_uint8*)(((*(postiats_tyrec_11*)((atstype_ptrk)(((atstype_boxed)(&(statmpref0))))))).atslab__data_pins))[(2)])
= arg5) ;
((((atstype_uint8*)(((*(postiats_tyrec_13*)((atstype_ptrk)(((atstype_boxed)(&(statmpref0))))))).atslab__data_pins))[(3)])
= arg6) ;

Thank's,

Kiwamu Okabe

unread,
Sep 13, 2014, 5:41:29 AM9/13/14
to ats-lang-users
Um....

On Sat, Sep 13, 2014 at 6:36 PM, Kiwamu Okabe <kiw...@debian.or.jp> wrote:
> $ cat DATS/lcd.dats
> --snip--
> vtypedef LCD_struct = @{
> rs_pin = uint8 // LOW: command. HIGH: character.
> , rw_pin = uint8 // LOW: write to LCD. HIGH: read from LCD.
> , enable_pin = uint8 // activated by a HIGH pulse.
> , displayfunction = uint8
> , displaycontrol = uint8
> , displaymode = uint8
> , numlines = uint8
> , currline = uint8
> , data_pins = @[uint8][4]
> }
> --snip--
> $ avr-gcc -Os -E -mmcu=atmega2560 -DF_CPU=16000000UL -std=c99
> -D_XOPEN_SOURCE -D_ATS_CCOMP_EXCEPTION_NONE -D_ATSTYPE_VAR_SIZE=0X000F
> -Wno-unused-variable -Wno-unused-label -Wno-unused-but-set-variable
> -I. -I/home/kiwamu/src/ATS-Postiats
> -I/home/kiwamu/src/ATS-Postiats/ccomp/runtime -I../_arduino
> -I../_dummy DATS/lcd_dats.c
> typedef
> struct {
> atstype_uint8 atslab__rs_pin;
> atstype_uint8 atslab__rw_pin;
> atstype_uint8 atslab__enable_pin;
> atstype_uint8 atslab__displayfunction;
> atstype_uint8 atslab__displaycontrol;
> atstype_uint8 atslab__displaymode;
> atstype_uint8 atslab__numlines;
> atstype_uint8 atslab__currline;
> atstype_uint8 atslab__data_pins[];
> } postiats_tyrec_0 ;

Does it say that unbox record should only have one array member?

Kiwamu Okabe

unread,
Sep 13, 2014, 10:55:40 AM9/13/14
to ats-lang-users
Hi Hongwei,

On Sat, Sep 13, 2014 at 4:43 PM, gmhwxi <gmh...@gmail.com> wrote:
> I think it makes sense to introduce a template
>
> fun{} lcd_get (): LCD // or use LCD_unintized
>
> Use lcd_get to implement lcd_open. You can implement
> lcd_get in main.dats if you like.

Thank's! It's fixed and runnable.

https://github.com/fpiot/arduino-mega2560-ats/commit/1ed48ae653a9f4430604a00c4bfb7f267f0e6070#diff-d286c2b60b4101c3f21181e0f66793e6R15

However, LCD_struct becomes public API....

gmhwxi

unread,
Sep 13, 2014, 2:18:13 PM9/13/14
to ats-lan...@googlegroups.com, kiw...@debian.or.jp
It is good that it worked.


>>However, LCD_struct becomes public API....

You could do something like this:

1) Introduce lcd_initize (!LCD0 >> LCD1, ...)

where LCD0 means uninitialized LCD and LCD1 means initialized.

implement
{}(*tmp*)
lcd_open (...) = let
  val lcd = lcd_get () in lcd_initize (lcd, ...)
end // end of [lcd_open]

Both LCD0 and LCD1 are abstract.

In low-level programming, it is often a good practice to separate resource-acquisition
(lcd_get) and resource-initialization (lcd_initize).

If you like, you can now allocate LCD on the call stack of main; or you can have a lock
on the use of lcd_get to avoid potential conflicts; or ...

gmhwxi

unread,
Sep 13, 2014, 2:52:35 PM9/13/14
to ats-lan...@googlegroups.com, kiw...@debian.or.jp

>>However, LCD_struct becomes public API....

I see what you meant here. One possibility is to
move LCD_struct to lcd.cats, and then add the following
line:

abst@ype LCD_struct = $extype"LCD_struct"

In lcd.dats, you can have

typedef LCD_struct_ = $extype_struct"LCD_struct" of
{
....
}

Then use $UN.cast to go between LCD_struct and LCD_struct_.

Kiwamu Okabe

unread,
Sep 15, 2014, 9:35:31 PM9/15/14
to ats-lan...@googlegroups.com
Hi Hongwei,

On Fri, 12 Sep 2014 23:26:32 -0700 (PDT)
gmhwxi <gmh...@gmail.com> wrote:
> By the way, the generated object code may not be a lot bigger. You can do
> some experiments to compare.

I compared them that are compiled with -Os option.

## Not use template
$ size main.elf
text data bss dec hex filename
3442 448 16 3906 f42 main.elf

## Use template
$ size main.elf
text data bss dec hex filename
6044 448 20 6512 1970 main.elf

Umm........
I think template system is not good for tiny embedded system.
And it can't control safe API...

Thank's,
--
Kiwamu Okabe <kiw...@debian.or.jp>

gmhwxi

unread,
Sep 15, 2014, 10:16:37 PM9/15/14
to ats-lan...@googlegroups.com, kiw...@debian.or.jp

I think this requires further investigation. I don't see why using templates
in your example would cause a large increase in the size of the generated
object code. It would be very useful to know what code really got duplicated.


>>And it can't control safe API...

I think it can. You can just move the following code into lcd.dats:

var _global_lcd_struct: LCD_struct
implement lcd_get
<> () = $UN.castvwtp0 (addr@_global_lcd_struct)

Kiwamu Okabe

unread,
Sep 15, 2014, 11:37:11 PM9/15/14
to ats-lan...@googlegroups.com
Hi Hongwei,

On Mon, 15 Sep 2014 19:16:37 -0700 (PDT)
gmhwxi <gmh...@gmail.com> wrote:
> I think this requires further investigation. I don't see why using templates
> in your example would cause a large increase in the size of the generated
> object code. It would be very useful to know what code really got
> duplicated.

O.K.
I try more.

> >>And it can't control safe API...
>
> I think it can. You can just move the following code into lcd.dats:
>
> var _global_lcd_struct: LCD_struct
> implement lcd_get<> () = $UN.castvwtp0 (addr@_global_lcd_struct)

I think I can't that.

$ grep github ../../.git/config
url = g...@github.com:fpiot/arduino-ats.git
$ git branch
* feature/use-template
master
$ git diff
diff --git a/DATS/lcd.dats b/DATS/lcd.dats
index ed3ee3b..f279be2 100644
--- a/DATS/lcd.dats
+++ b/DATS/lcd.dats
@@ -95,6 +95,13 @@ in
lcd
end

+local
+ var _global_lcd_struct: LCD_struct
+ implement lcd_get<> () = $UN.castvwtp0 (addr@_global_lcd_struct)
+in
+ implement lcd_open_ (rs, rw, enable, d0, d1, d2, d3) = lcd_open (rs, rw, enable, d0, d1, d2, d3)
+end
+
implement{} lcd_close (lcd) = {
val () = $UN.castvwtp0(lcd) (* Consume lcd *)
}
diff --git a/demo/lcd_ats/DATS/main.dats b/demo/lcd_ats/DATS/main.dats
index 1ba72a6..b90361e 100644
--- a/demo/lcd_ats/DATS/main.dats
+++ b/demo/lcd_ats/DATS/main.dats
@@ -12,13 +12,6 @@ staload UN = "prelude/SATS/unsafe.sats"

val g_string = " ATS is a statically typed programming language that unifies implementation with formal specification. It is equipped with a h
ighly expressive type system rooted in the framework Applied Type System, which gives the language its name. In particular, both dependent types and linear typ
es are available in ATS. "

-local
- var _global_lcd_struct: LCD_struct
- implement lcd_get<> () = $UN.castvwtp0 (addr@_global_lcd_struct)
-in
- implement lcd_open_ (rs, rw, enable, d0, d1, d2, d3) = lcd_open (rs, rw, enable, d0, d1, d2, d3)
-end
-
implement main0 () = {
fun loop {n:int}{i:nat | i < n}
(lcd: !LCD, str: string (n), pos: size_t (i)): void = {
$ make
avr-gcc -g -Wall -Os -mmcu=atmega2560 -DF_CPU=16000000UL -std=c99 -D_XOPEN_SOURCE -D_ATS_CCOMP_EXCEPTION_NONE -D_ATSTYPE_VAR_SIZE=0X000F -Wno-unused-variable -Wno-unused-label -Wno-unused-but-set-variable -Wno-implicit-function-declaration -I. -I/home/kiwamu/src/ATS-Postiats -I/home/kiwamu/src/ATS-Postiats/ccomp/runtime -I../..//_arduino -I../..//_dummy -c -o wiring_digital.o wiring_digital.c
patsopt -o DATS/main_dats.c -d DATS/main.dats
avr-gcc -g -Wall -Os -mmcu=atmega2560 -DF_CPU=16000000UL -std=c99 -D_XOPEN_SOURCE -D_ATS_CCOMP_EXCEPTION_NONE -D_ATSTYPE_VAR_SIZE=0X000F -Wno-unused-variable -Wno-unused-label -Wno-unused-but-set-variable -Wno-implicit-function-declaration -I. -I/home/kiwamu/src/ATS-Postiats -I/home/kiwamu/src/ATS-Postiats/ccomp/runtime -I../..//_arduino -I../..//_dummy -c -o DATS/main_dats.o DATS/main_dats.c
In file included from DATS/main_dats.c:41:0:
/home/kiwamu/src/ATS-Postiats/prelude/CATS/filebas.cats: In function 'atspre_fileref_open_exn':
/home/kiwamu/src/ATS-Postiats/prelude/CATS/filebas.cats:177:8: warning: assignment makes pointer from integer without a cast [enabled by default]
filr = fopen((char*)path, (char*)fm) ;
^
avr-gcc -g -Wall -Os -mmcu=atmega2560 -DF_CPU=16000000UL -std=c99 -D_XOPEN_SOURCE -D_ATS_CCOMP_EXCEPTION_NONE -D_ATSTYPE_VAR_SIZE=0X000F -Wno-unused-variable -Wno-unused-label -Wno-unused-but-set-variable -Wno-implicit-function-declaration -I. -I/home/kiwamu/src/ATS-Postiats -I/home/kiwamu/src/ATS-Postiats/ccomp/runtime -I../..//_arduino -I../..//_dummy -Wl,-Map,main.map -o main.elf wiring_digital.o DATS/main_dats.o
DATS/main_dats.o: In function `main':
/home/kiwamu/src/ATS-Postiats/ccomp/runtime/pats_ccomp_runtime.c:(.text+0x20): undefined reference to `_057_home_057_kiwamu_057_src_057_arduino_055_ats_057_SATS_057_lcd_056_sats__lcd_open_'
collect2: error: ld returned 1 exit status
../..//Makefile.common:30: recipe for target 'main.elf' failed
make: *** [main.elf] Error 1

gmhwxi

unread,
Sep 15, 2014, 11:54:56 PM9/15/14
to ats-lan...@googlegroups.com, kiw...@debian.or.jp
Is your new code in this directory:

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

I would like to give it a try.

Kiwamu Okabe

unread,
Sep 16, 2014, 12:03:06 AM9/16/14
to ats-lang-users
Hi Hongwei,

On Tue, Sep 16, 2014 at 12:54 PM, gmhwxi <gmh...@gmail.com> wrote:
> Is your new code in this directory:
>
> https://github.com/fpiot/arduino-ats/

Yes. It is.
Now it supports Arduino Uno in the master branch.
Therefore, I change the repo name.


> I would like to give it a try.

Thank's!,

P.S.
I think ATS language needs killer demo application.
Arduino Uno is a very big brand.
Also, the other language can't write code for the platform.
I think Arduino is good for the first step.
Reply all
Reply to author
Forward
0 new messages