Multiple {DATS,SATS} directory

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

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.On Friday, September 12, 2014 2:53:59 PM UTC-4, Kiwamu Okabe wrote:

Hi Hongwei,

On Sat, Sep 13, 2014 at 3:41 AM, gmhwxi <gmh...@gmail.com <javascript:>> 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?

Thank’s,

Kiwamu Okabe at METASEPI DESIGN

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.On Saturday, September 13, 2014 1:44:09 AM UTC-4, Kiwamu Okabe wrote:

Hi Hongwei,

On Sat, Sep 13, 2014 at 1:38 PM, gmhwxi <gmh...@gmail.com <javascript:>> 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?

$ 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+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.

Thank’s,

Kiwamu Okabe at METASEPI DESIGN

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 …?On Saturday, September 13, 2014 2:58:50 AM UTC-4, Kiwamu Okabe wrote:

Hi Hongwei,

On Sat, Sep 13, 2014 at 3:03 PM, gmhwxi <gmh...@gmail.com <javascript:>> wrote:

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

Umm…

$ 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+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
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,

Kiwamu Okabe at METASEPI DESIGN

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_.On Saturday, September 13, 2014 2:18:13 PM UTC-4, gmhwxi wrote:

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 …

On Saturday, September 13, 2014 10:55:40 AM UTC-4, Kiwamu Okabe wrote:

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.

Use template and runnable · fpiot/arduino-ats@1ed48ae · GitHub

However, LCD_struct becomes public API…

Kiwamu Okabe at METASEPI DESIGN

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<>On Saturday, September 13, 2014 2:27:22 AM UTC-4, Kiwamu Okabe wrote:

Hi Hongwei,

On Sat, Sep 13, 2014 at 3:19 PM, gmhwxi <gmh...@gmail.com <javascript:>> 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.

Thank’s,

Kiwamu Okabe at METASEPI DESIGN

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.On Saturday, September 13, 2014 12:11:34 AM UTC-4, Kiwamu Okabe wrote:

Hi Hongwei,

On Sat, Sep 13, 2014 at 7:57 AM, gmhwxi <gmh...@gmail.com <javascript:>> 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.

GitHub - fpiot/arduino-ats at 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, PMVtmpltcstmat0(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?

Thank’s,

Kiwamu Okabe at METASEPI DESIGN

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:

---------- Forwarded message ----------

Hi all,

May I use multiple {DATS,SATS} directory?

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

GitHub - fpiot/arduino-ats: ATS programing on Arduino

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

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.On Saturday, September 13, 2014 2:09:47 AM UTC-4, Kiwamu Okabe wrote:

Hi Hongwei,

On Sat, Sep 13, 2014 at 3:03 PM, gmhwxi <gmh...@gmail.com <javascript:>> 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?

Thank’s,

Kiwamu Okabe at METASEPI DESIGN

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

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.On Saturday, September 13, 2014 2:20:11 AM UTC-4, Kiwamu Okabe wrote:

Hi Hongwei,

On Sat, Sep 13, 2014 at 3:09 PM, Kiwamu Okabe <kiw…@debian.or.jp <javascript:>> 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.

Thank’s,

Kiwamu Okabe at METASEPI DESIGN

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)On Monday, September 15, 2014 9:35:31 PM UTC-4, Kiwamu Okabe wrote:

Hi Hongwei,

On Fri, 12 Sep 2014 23:26:32 -0700 (PDT) gmhwxi <gmh...@gmail.com <javascript:>> 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 <javascript:>>

Hi Hongwei,

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.

Is your new code in this directory:

I would like to give it a try.On Monday, September 15, 2014 11:37:11 PM UTC-4, Kiwamu Okabe wrote:

Hi Hongwei,

On Mon, 15 Sep 2014 19:16:37 -0700 (PDT) gmhwxi <gmh...@gmail.com <javascript:>> 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 = git@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

Thank’s,

Kiwamu Okabe <kiw…@debian.or.jp <javascript:>>

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).On Saturday, September 13, 2014 2:34:22 AM UTC-4, Kiwamu Okabe wrote:

Hi Hongwei,

On Sat, Sep 13, 2014 at 3:26 PM, gmhwxi <gmh...@gmail.com <javascript:>> 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.

Thank’s,

Kiwamu Okabe at METASEPI DESIGN

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:

Hi Hongwei,

On Sat, Sep 13, 2014 at 3:41 AM, gmhwxi <gmh...@gmail.com <javascript:>> 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?

Thank’s,

Kiwamu Okabe at METASEPI DESIGN

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 …On Saturday, September 13, 2014 10:55:40 AM UTC-4, Kiwamu Okabe wrote:

Hi Hongwei,

On Sat, Sep 13, 2014 at 4:43 PM, gmhwxi <gmh...@gmail.com <javascript:>> 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.

Use template and runnable · fpiot/arduino-ats@1ed48ae · GitHub

However, LCD_struct becomes public API…

Kiwamu Okabe at METASEPI DESIGN

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.On Saturday, September 13, 2014 3:23:41 AM UTC-4, gmhwxi wrote:

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 …?

On Saturday, September 13, 2014 2:58:50 AM UTC-4, Kiwamu Okabe wrote:

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…

$ 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+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
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,

Kiwamu Okabe at METASEPI DESIGN