Metasepi team meeting #19: ATS application on Arduino

Kiwamu Okabe
Kiwamu OkabeSoftware Engineer at SELTECH CORPORATION
Metasepi team meeting #19: 
  
ATS application on Arduino 
Kiwamu Okabe @ Metasepi Project
Demo: ATS on Arduino Uno 
☆ http://nico.ms/sm24680530 
☆ https://github.com/fpiot/arduino-ats 
☆ Without any GC, and any malloc
Demo: Arduino Uno 
☆ MCU: ATmega328 
☆ Flash Memory: 32 KB 
☆ SRAM: 2 KB 
hhhttttttppp::://////aaarrrddduuuiiinnnooo...cccccc///eeennn///MMMaaaiiinnn///AAArrrddduuuiiinnnoooBBBoooaaarrrdddUUUnnnooo
Demo: LCD Shield 
☆ LinkSprite 16X2 LCD Keypad Shield 
☆ 16x2 LCD 
☆ HD44780 compatible 
http://store.linksprite.com/linksprite-16x2-lcd-keypad-shield-for-arduino- 
version-b/
Demo: Software Architecture
Demo code: main.dats
Demo code: lcs.sats
Demo code: lcs.dats 
☆ We don't read it, today.
Agenda 
☆ [0] ATS application demo 
☆ [1] What is Metasepi? 
☆ [2] How to create Metasepi? 
☆ [3] What is ATS language? 
☆ [4] Let's read the demo code 
☆ [5] Japan ATS User Group
[1] What is Metasepi? 
http://metasepi.org/ 
☆ Unix-like OS designed by strong type. 
☆ We want to use Metasepi OS for daily 
desktop usage (e.g. web browser, 
programming, office suite, ... etc.) 
☆ We have surveyed may functional 
languages (e.g. Haskell, OCaml, 
MLton, ... etc.)
Kernel developer wants type 
☆ Kernels are developed with C. 
☆ We should design kernel with the 
greatest care. 
☆ C language is unsafe!
Kernel Bug #1: Buffer overrun 
☆ Pointer to array doesn't know the 
length.
Kernel Bug #2: Page fault 
☆ Page fault in user space => SEGV 
☆ Page fault in kernel space => Halt!
Kernel Bug #3: Weak type 
☆ Lots of (void *) and unsafe coercion. 
☆ NetBSD kernel uses it 45130 times! 
$ pwd 
/home/kiwamu/src/netbsd/sys 
$ grep "void *" `find . -name "*.c"` | wc -l 
45130 
☆ Kernel developers frequently use 
(void *) for flexibility. It's realy BAD, but 
there is no other option.
[2] How to create Metasepi? 
☆ Scratch or Rewrite
Snatch-driven development 
http://en.wikipedia.org/wiki/Snatcher
Which language should we use? 
☆ ATS http://www.ats-lang.org/
[3] What is ATS language? 
http://www.ats-lang.org/ 
☆ Syntax like ML 
☆ Dependent types 
☆ Linear types 
☆ Without any runtime 
☆ Optional GC 
☆ Developed at Boston University
ATS compile flow
[4] Let's read the demo code 
Start from main.dats. 
arduino-ats 
|-- DATS 
| `-- lcd.dats 
|-- SATS 
| |-- arduino.sats 
| `-- lcd.sats 
|-- avr_prelude 
| |-- DATS 
| | `-- string0.dats 
| |-- SATS 
| | `-- string0.sats 
| |-- kernel_prelude.cats 
| `-- kernel_staload.hats 
`-- demo 
`-- lcd_ats 
|-- DATS 
| `-- main.dats # <= Start from here. 
`-- config.hats
main.dats sequence
lcd.sats
Power of Dependent Type #1 
$ pwd 
/home/kiwamu/src/arduino-ats/demo/lcd_ats 
$ vi DATS/main.dats 
$ git diff 
diff --git a/demo/lcd_ats/DATS/main.dats b/demo/lcd_ats/DATS/ 
main.dats 
index ab94597..f00eccd 100644 
--- a/demo/lcd_ats/DATS/main.dats 
+++ b/demo/lcd_ats/DATS/main.dats 
@@ -13,7 +13,7 @@ val g_str_message = " ATS is a 
statically typed programming lang 
implement main0 () = { 
fun loop {n:int}{i:nat | i < n} 
(lcd: !lcd_t, str: string (n), pos: size_t (i)): void 
= { 
- val () = if pos + lcd_width <= length str then { 
+ val () = if pos + lcd_width <= 1 + length str then { 
val () = lcd_setCursor (lcd, 1, 0) 
val () = lcd_print (lcd, g_str_atsrun, i2sz 0, length 
g_str_atsrun) 
val () = lcd_setCursor (lcd, 0, 1)
Power of Dependent Type #2 
$ make 
--snip-- 
patsopt -o DATS/main_dats.c -d DATS/main.dats 
/home/kiwamu/src/arduino-ats/demo/lcd_ats/DATS/main.dats: 958 
(line=20, offs=25) -- 958(line=20, offs=25): error(3): unsolved 
constraint: C3NSTRprop(main; S2Eapp(S2Ecst(<=); S2Eapp(S2Ecst(+); 
S2EVar(1830->S2Evar(i(5501))), S2EVar(1831->S2Eintinf(16))), S2EVar 
(1829->S2Evar(n(5500))))) 
typechecking has failed: there are some unsolved constraints: 
please inspect the above reported error message(s) for information. 
☆ ATS2 finds issue at compile time! 
☆ Constraint "i + j <= n" is at lcd.sats 
☆ main.dats violates the constraint
Power of Linear Type #1 
$ pwd 
/home/kiwamu/src/arduino-ats/demo/lcd_ats 
$ vi DATS/main.dats 
$ git diff 
diff --git a/demo/lcd_ats/DATS/main.dats b/demo/lcd_ats/DATS/ 
main.dats 
index ab94597..4c73340 100644 
--- a/demo/lcd_ats/DATS/main.dats 
+++ b/demo/lcd_ats/DATS/main.dats 
@@ -25,6 +25,7 @@ implement main0 () = { 
fun forever {n:int}{i:nat | i < n} 
(lcd: !lcd_t, str: string (n), pos: size_t (i)): 
void = { 
val () = loop (lcd, str, pos) 
+ val () = lcd_close lcd 
val () = forever (lcd, str, pos) 
} 
val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7)
Power of Linear Type #2 
$ make 
--snip-- 
patsopt -o DATS/main_dats.c -d DATS/main.dats 
/home/kiwamu/src/arduino-ats/demo/lcd_ats/DATS/main.dats: 1263 
(line=29, offs=23) -- 1266(line=29, offs=26): error(3): the linear 
dynamic variable [lcd$1182(-1)] is no longer available. 
/home/kiwamu/src/arduino-ats/demo/lcd_ats/DATS/main.dats: 1263 
(line=29, offs=23) -- 1266(line=29, offs=26): error(3): the 
dynamic expression cannot be assigned the type [S2Ecst(lcd_t)]. 
☆ ATS2 finds issue at compile time! 
☆ Linear value "lcd" is consumed 
☆ However "lcd" is used by "forever"
[5] Japan ATS User Group 
http://jats-ug.metasepi.org/
Doc: ATSプログラミング入門
hhhttttttppp::://////jjjaaatttsss---uuuggg...mmmeeetttaaassseeepppiii...ooorrrggg///dddoooccc///AAATTTSSS222///IIINNNTTT222PPPRRROOOGGGIIINNNAAATTTSSS///
Doc: チュートリアル
hhhttttttppp::://////jjjaaatttsss---uuuggg...mmmeeetttaaassseeepppiii...ooorrrggg///dddoooccc///AAATTTSSS222///AAATTTSSS222TTTUUUTTTOOORRRIIIAAALLL///
Doc: MLプログラマ向けガイド
https://github.com/jats-ug/translate/blob/master/Web/cs.likai.org/ 
ats/ml-programmers-guide-to-ats.md
Doc: ATS2 wiki 
hhhttttttpppsss::://////gggiiittthhhuuubbb...cccooommm///gggiiittthhhwwwxxxiii///AAATTTSSS---PPPooossstttiiiaaatttsss///wwwiiikkkiii
Functional IoT 
hhhttttttppp::://////fffpppiiiooottt...mmmeeetttaaassseeepppiii...ooorrrggg///
Follow me! 
https://twitter.com/jats_ug
1 of 33

Recommended

Embedded application designed by ATS language by
Embedded application designed by ATS languageEmbedded application designed by ATS language
Embedded application designed by ATS languageKiwamu Okabe
5.6K views32 slides
Metasepi team meeting #14: ATS programming on MCU by
Metasepi team meeting #14: ATS programming on MCUMetasepi team meeting #14: ATS programming on MCU
Metasepi team meeting #14: ATS programming on MCUKiwamu Okabe
15.2K views22 slides
Metasepi team meeting #17: Invariant captured by ATS's API by
Metasepi team meeting #17: Invariant captured by ATS's APIMetasepi team meeting #17: Invariant captured by ATS's API
Metasepi team meeting #17: Invariant captured by ATS's APIKiwamu Okabe
15.1K views26 slides
ATS programming on ESP8266 by
ATS programming on ESP8266ATS programming on ESP8266
ATS programming on ESP8266Kiwamu Okabe
8.5K views10 slides
ATS Programming Tutorial by
ATS Programming TutorialATS Programming Tutorial
ATS Programming TutorialKiwamu Okabe
15.3K views30 slides
Start! ATS programming by
Start! ATS programmingStart! ATS programming
Start! ATS programmingKiwamu Okabe
16.3K views15 slides

More Related Content

What's hot

Real-time OS system state captured by ATS language by
Real-time OS system state captured by ATS languageReal-time OS system state captured by ATS language
Real-time OS system state captured by ATS languageKiwamu Okabe
7.1K views23 slides
ATS/LF for Coq users by
ATS/LF for Coq usersATS/LF for Coq users
ATS/LF for Coq usersKiwamu Okabe
13.6K views49 slides
Metasepi team meeting #16: Safety on ATS language + MCU by
Metasepi team meeting #16: Safety on ATS language + MCUMetasepi team meeting #16: Safety on ATS language + MCU
Metasepi team meeting #16: Safety on ATS language + MCUKiwamu Okabe
15.1K views33 slides
ATS2 updates 2017 by
ATS2 updates 2017ATS2 updates 2017
ATS2 updates 2017Kiwamu Okabe
4.6K views26 slides
Functional IoT: Programming Language and OS by
Functional IoT: Programming Language and OSFunctional IoT: Programming Language and OS
Functional IoT: Programming Language and OSKiwamu Okabe
1.6K views41 slides
ATS language overview' by
ATS language overview'ATS language overview'
ATS language overview'Kiwamu Okabe
11.6K views42 slides

What's hot(20)

Real-time OS system state captured by ATS language by Kiwamu Okabe
Real-time OS system state captured by ATS languageReal-time OS system state captured by ATS language
Real-time OS system state captured by ATS language
Kiwamu Okabe7.1K views
ATS/LF for Coq users by Kiwamu Okabe
ATS/LF for Coq usersATS/LF for Coq users
ATS/LF for Coq users
Kiwamu Okabe13.6K views
Metasepi team meeting #16: Safety on ATS language + MCU by Kiwamu Okabe
Metasepi team meeting #16: Safety on ATS language + MCUMetasepi team meeting #16: Safety on ATS language + MCU
Metasepi team meeting #16: Safety on ATS language + MCU
Kiwamu Okabe15.1K views
ATS2 updates 2017 by Kiwamu Okabe
ATS2 updates 2017ATS2 updates 2017
ATS2 updates 2017
Kiwamu Okabe4.6K views
Functional IoT: Programming Language and OS by Kiwamu Okabe
Functional IoT: Programming Language and OSFunctional IoT: Programming Language and OS
Functional IoT: Programming Language and OS
Kiwamu Okabe1.6K views
ATS language overview' by Kiwamu Okabe
ATS language overview'ATS language overview'
ATS language overview'
Kiwamu Okabe11.6K views
Hands-on VeriFast with STM32 microcontroller by Kiwamu Okabe
Hands-on VeriFast with STM32 microcontrollerHands-on VeriFast with STM32 microcontroller
Hands-on VeriFast with STM32 microcontroller
Kiwamu Okabe1.6K views
Functional IoT: Hardware and Platform by Kiwamu Okabe
Functional IoT: Hardware and PlatformFunctional IoT: Hardware and Platform
Functional IoT: Hardware and Platform
Kiwamu Okabe1.6K views
Functional IoT: Introduction by Kiwamu Okabe
Functional IoT: IntroductionFunctional IoT: Introduction
Functional IoT: Introduction
Kiwamu Okabe1.4K views
Past and today of Metasepi project by Kiwamu Okabe
Past and today of Metasepi projectPast and today of Metasepi project
Past and today of Metasepi project
Kiwamu Okabe666 views
Let's contribute, HTML5Rocks/ko! by Chang W. Doh
Let's contribute, HTML5Rocks/ko!Let's contribute, HTML5Rocks/ko!
Let's contribute, HTML5Rocks/ko!
Chang W. Doh502 views
2009 Eclipse Con by guest29922
2009 Eclipse Con2009 Eclipse Con
2009 Eclipse Con
guest29922444 views
Monkey-patching in Python: a magic trick or a powerful tool? by Elizaveta Shashkova
Monkey-patching in Python: a magic trick or a powerful tool?Monkey-patching in Python: a magic trick or a powerful tool?
Monkey-patching in Python: a magic trick or a powerful tool?
Elizaveta Shashkova8.7K views
NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo... by Hafez Kamal
NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...
NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...
Hafez Kamal155 views
Gareth Rushgrove (Puppet) - Ubiquity at #DOXLON by Outlyer
Gareth Rushgrove (Puppet) - Ubiquity at #DOXLONGareth Rushgrove (Puppet) - Ubiquity at #DOXLON
Gareth Rushgrove (Puppet) - Ubiquity at #DOXLON
Outlyer1.6K views
Debugging with pry by Creditas
Debugging with pryDebugging with pry
Debugging with pry
Creditas760 views
Ajhc Haskell Compiler with Reentrant GC by Kiwamu Okabe
Ajhc Haskell Compiler with Reentrant GCAjhc Haskell Compiler with Reentrant GC
Ajhc Haskell Compiler with Reentrant GC
Kiwamu Okabe2.8K views

Similar to Metasepi team meeting #19: ATS application on Arduino

Functional MCU programming by
Functional MCU programmingFunctional MCU programming
Functional MCU programmingKiwamu Okabe
5.1K views21 slides
Metasepi team meeting #7: Snatch application on tiny OS by
Metasepi team meeting #7: Snatch application on tiny OSMetasepi team meeting #7: Snatch application on tiny OS
Metasepi team meeting #7: Snatch application on tiny OSKiwamu Okabe
13.2K views37 slides
Functional MCU programming #0: Development environment by
Functional MCU programming #0: Development environmentFunctional MCU programming #0: Development environment
Functional MCU programming #0: Development environmentKiwamu Okabe
4.4K views30 slides
Cryptography and secure systems by
Cryptography and secure systemsCryptography and secure systems
Cryptography and secure systemsVsevolod Stakhov
1.3K views41 slides
Share the Experience of Using Embedded Development Board by
Share the Experience of Using Embedded Development BoardShare the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development BoardJian-Hong Pan
271 views50 slides
Mainline kernel on ARM Tegra20 devices that are left behind on 2.6 kernels by
Mainline kernel on ARM Tegra20 devices that are left behind on 2.6 kernelsMainline kernel on ARM Tegra20 devices that are left behind on 2.6 kernels
Mainline kernel on ARM Tegra20 devices that are left behind on 2.6 kernelsDobrica Pavlinušić
271 views17 slides

Similar to Metasepi team meeting #19: ATS application on Arduino(20)

Functional MCU programming by Kiwamu Okabe
Functional MCU programmingFunctional MCU programming
Functional MCU programming
Kiwamu Okabe5.1K views
Metasepi team meeting #7: Snatch application on tiny OS by Kiwamu Okabe
Metasepi team meeting #7: Snatch application on tiny OSMetasepi team meeting #7: Snatch application on tiny OS
Metasepi team meeting #7: Snatch application on tiny OS
Kiwamu Okabe13.2K views
Functional MCU programming #0: Development environment by Kiwamu Okabe
Functional MCU programming #0: Development environmentFunctional MCU programming #0: Development environment
Functional MCU programming #0: Development environment
Kiwamu Okabe4.4K views
Share the Experience of Using Embedded Development Board by Jian-Hong Pan
Share the Experience of Using Embedded Development BoardShare the Experience of Using Embedded Development Board
Share the Experience of Using Embedded Development Board
Jian-Hong Pan271 views
Mainline kernel on ARM Tegra20 devices that are left behind on 2.6 kernels by Dobrica Pavlinušić
Mainline kernel on ARM Tegra20 devices that are left behind on 2.6 kernelsMainline kernel on ARM Tegra20 devices that are left behind on 2.6 kernels
Mainline kernel on ARM Tegra20 devices that are left behind on 2.6 kernels
Schrödinger's ARM Assembly by Saumil Shah
Schrödinger's ARM AssemblySchrödinger's ARM Assembly
Schrödinger's ARM Assembly
Saumil Shah659 views
HackLU 2018 Make ARM Shellcode Great Again by Saumil Shah
HackLU 2018 Make ARM Shellcode Great AgainHackLU 2018 Make ARM Shellcode Great Again
HackLU 2018 Make ARM Shellcode Great Again
Saumil Shah1.7K views
Raspberry Pi - HW/SW Application Development by Corley S.r.l.
Raspberry Pi - HW/SW Application DevelopmentRaspberry Pi - HW/SW Application Development
Raspberry Pi - HW/SW Application Development
Corley S.r.l.4.2K views
리눅스 드라이버 실습 #3 by Sangho Park
리눅스 드라이버 실습 #3리눅스 드라이버 실습 #3
리눅스 드라이버 실습 #3
Sangho Park1.1K views
7nm "Navi" GPU - A GPU Built For Performance by AMD
7nm "Navi" GPU - A GPU Built For Performance 7nm "Navi" GPU - A GPU Built For Performance
7nm "Navi" GPU - A GPU Built For Performance
AMD2.8K views
HKG15-300: Art's Quick Compiler: An unofficial overview by Linaro
HKG15-300: Art's Quick Compiler: An unofficial overviewHKG15-300: Art's Quick Compiler: An unofficial overview
HKG15-300: Art's Quick Compiler: An unofficial overview
Linaro5.2K views
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015 by Windows Developer
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
Windows Developer908 views
20171206 PGconf.ASIA LT gstore_fdw by Kohei KaiGai
20171206 PGconf.ASIA LT gstore_fdw20171206 PGconf.ASIA LT gstore_fdw
20171206 PGconf.ASIA LT gstore_fdw
Kohei KaiGai355 views
Metasepi team meeting #6: "Snatch-driven development" by Kiwamu Okabe
Metasepi team meeting #6: "Snatch-driven development"Metasepi team meeting #6: "Snatch-driven development"
Metasepi team meeting #6: "Snatch-driven development"
Kiwamu Okabe4.2K views

Recently uploaded

Throughput by
ThroughputThroughput
ThroughputMoisés Armani Ramírez
36 views11 slides
STPI OctaNE CoE Brochure.pdf by
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdfmadhurjyapb
12 views1 slide
Transcript: The Details of Description Techniques tips and tangents on altern... by
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...BookNet Canada
130 views15 slides
PharoJS - Zürich Smalltalk Group Meetup November 2023 by
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023Noury Bouraqadi
120 views17 slides
Combining Orchestration and Choreography for a Clean Architecture by
Combining Orchestration and Choreography for a Clean ArchitectureCombining Orchestration and Choreography for a Clean Architecture
Combining Orchestration and Choreography for a Clean ArchitectureThomasHeinrichs1
69 views24 slides
20231123_Camunda Meetup Vienna.pdf by
20231123_Camunda Meetup Vienna.pdf20231123_Camunda Meetup Vienna.pdf
20231123_Camunda Meetup Vienna.pdfPhactum Softwareentwicklung GmbH
28 views73 slides

Recently uploaded(20)

STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb12 views
Transcript: The Details of Description Techniques tips and tangents on altern... by BookNet Canada
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...
BookNet Canada130 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi120 views
Combining Orchestration and Choreography for a Clean Architecture by ThomasHeinrichs1
Combining Orchestration and Choreography for a Clean ArchitectureCombining Orchestration and Choreography for a Clean Architecture
Combining Orchestration and Choreography for a Clean Architecture
ThomasHeinrichs169 views
Attacking IoT Devices from a Web Perspective - Linux Day by Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri15 views
How the World's Leading Independent Automotive Distributor is Reinventing Its... by NUS-ISS
How the World's Leading Independent Automotive Distributor is Reinventing Its...How the World's Leading Independent Automotive Distributor is Reinventing Its...
How the World's Leading Independent Automotive Distributor is Reinventing Its...
NUS-ISS15 views
Empathic Computing: Delivering the Potential of the Metaverse by Mark Billinghurst
Empathic Computing: Delivering  the Potential of the MetaverseEmpathic Computing: Delivering  the Potential of the Metaverse
Empathic Computing: Delivering the Potential of the Metaverse
Mark Billinghurst470 views
SAP Automation Using Bar Code and FIORI.pdf by Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdf
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica... by NUS-ISS
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
NUS-ISS16 views
AI: mind, matter, meaning, metaphors, being, becoming, life values by Twain Liu 刘秋艳
AI: mind, matter, meaning, metaphors, being, becoming, life valuesAI: mind, matter, meaning, metaphors, being, becoming, life values
AI: mind, matter, meaning, metaphors, being, becoming, life values
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen... by NUS-ISS
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
NUS-ISS28 views
Understanding GenAI/LLM and What is Google Offering - Felix Goh by NUS-ISS
Understanding GenAI/LLM and What is Google Offering - Felix GohUnderstanding GenAI/LLM and What is Google Offering - Felix Goh
Understanding GenAI/LLM and What is Google Offering - Felix Goh
NUS-ISS41 views
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum... by NUS-ISS
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...
NUS-ISS34 views
Future of Learning - Khoong Chan Meng by NUS-ISS
Future of Learning - Khoong Chan MengFuture of Learning - Khoong Chan Meng
Future of Learning - Khoong Chan Meng
NUS-ISS33 views
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software225 views
Voice Logger - Telephony Integration Solution at Aegis by Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma17 views

Metasepi team meeting #19: ATS application on Arduino

  • 1. Metasepi team meeting #19:   ATS application on Arduino Kiwamu Okabe @ Metasepi Project
  • 2. Demo: ATS on Arduino Uno ☆ http://nico.ms/sm24680530 ☆ https://github.com/fpiot/arduino-ats ☆ Without any GC, and any malloc
  • 3. Demo: Arduino Uno ☆ MCU: ATmega328 ☆ Flash Memory: 32 KB ☆ SRAM: 2 KB hhhttttttppp::://////aaarrrddduuuiiinnnooo...cccccc///eeennn///MMMaaaiiinnn///AAArrrddduuuiiinnnoooBBBoooaaarrrdddUUUnnnooo
  • 4. Demo: LCD Shield ☆ LinkSprite 16X2 LCD Keypad Shield ☆ 16x2 LCD ☆ HD44780 compatible http://store.linksprite.com/linksprite-16x2-lcd-keypad-shield-for-arduino- version-b/
  • 8. Demo code: lcs.dats ☆ We don't read it, today.
  • 9. Agenda ☆ [0] ATS application demo ☆ [1] What is Metasepi? ☆ [2] How to create Metasepi? ☆ [3] What is ATS language? ☆ [4] Let's read the demo code ☆ [5] Japan ATS User Group
  • 10. [1] What is Metasepi? http://metasepi.org/ ☆ Unix-like OS designed by strong type. ☆ We want to use Metasepi OS for daily desktop usage (e.g. web browser, programming, office suite, ... etc.) ☆ We have surveyed may functional languages (e.g. Haskell, OCaml, MLton, ... etc.)
  • 11. Kernel developer wants type ☆ Kernels are developed with C. ☆ We should design kernel with the greatest care. ☆ C language is unsafe!
  • 12. Kernel Bug #1: Buffer overrun ☆ Pointer to array doesn't know the length.
  • 13. Kernel Bug #2: Page fault ☆ Page fault in user space => SEGV ☆ Page fault in kernel space => Halt!
  • 14. Kernel Bug #3: Weak type ☆ Lots of (void *) and unsafe coercion. ☆ NetBSD kernel uses it 45130 times! $ pwd /home/kiwamu/src/netbsd/sys $ grep "void *" `find . -name "*.c"` | wc -l 45130 ☆ Kernel developers frequently use (void *) for flexibility. It's realy BAD, but there is no other option.
  • 15. [2] How to create Metasepi? ☆ Scratch or Rewrite
  • 17. Which language should we use? ☆ ATS http://www.ats-lang.org/
  • 18. [3] What is ATS language? http://www.ats-lang.org/ ☆ Syntax like ML ☆ Dependent types ☆ Linear types ☆ Without any runtime ☆ Optional GC ☆ Developed at Boston University
  • 20. [4] Let's read the demo code Start from main.dats. arduino-ats |-- DATS | `-- lcd.dats |-- SATS | |-- arduino.sats | `-- lcd.sats |-- avr_prelude | |-- DATS | | `-- string0.dats | |-- SATS | | `-- string0.sats | |-- kernel_prelude.cats | `-- kernel_staload.hats `-- demo `-- lcd_ats |-- DATS | `-- main.dats # <= Start from here. `-- config.hats
  • 23. Power of Dependent Type #1 $ pwd /home/kiwamu/src/arduino-ats/demo/lcd_ats $ vi DATS/main.dats $ git diff diff --git a/demo/lcd_ats/DATS/main.dats b/demo/lcd_ats/DATS/ main.dats index ab94597..f00eccd 100644 --- a/demo/lcd_ats/DATS/main.dats +++ b/demo/lcd_ats/DATS/main.dats @@ -13,7 +13,7 @@ val g_str_message = " ATS is a statically typed programming lang implement main0 () = { fun loop {n:int}{i:nat | i < n} (lcd: !lcd_t, str: string (n), pos: size_t (i)): void = { - val () = if pos + lcd_width <= length str then { + val () = if pos + lcd_width <= 1 + length str then { val () = lcd_setCursor (lcd, 1, 0) val () = lcd_print (lcd, g_str_atsrun, i2sz 0, length g_str_atsrun) val () = lcd_setCursor (lcd, 0, 1)
  • 24. Power of Dependent Type #2 $ make --snip-- patsopt -o DATS/main_dats.c -d DATS/main.dats /home/kiwamu/src/arduino-ats/demo/lcd_ats/DATS/main.dats: 958 (line=20, offs=25) -- 958(line=20, offs=25): error(3): unsolved constraint: C3NSTRprop(main; S2Eapp(S2Ecst(<=); S2Eapp(S2Ecst(+); S2EVar(1830->S2Evar(i(5501))), S2EVar(1831->S2Eintinf(16))), S2EVar (1829->S2Evar(n(5500))))) typechecking has failed: there are some unsolved constraints: please inspect the above reported error message(s) for information. ☆ ATS2 finds issue at compile time! ☆ Constraint "i + j <= n" is at lcd.sats ☆ main.dats violates the constraint
  • 25. Power of Linear Type #1 $ pwd /home/kiwamu/src/arduino-ats/demo/lcd_ats $ vi DATS/main.dats $ git diff diff --git a/demo/lcd_ats/DATS/main.dats b/demo/lcd_ats/DATS/ main.dats index ab94597..4c73340 100644 --- a/demo/lcd_ats/DATS/main.dats +++ b/demo/lcd_ats/DATS/main.dats @@ -25,6 +25,7 @@ implement main0 () = { fun forever {n:int}{i:nat | i < n} (lcd: !lcd_t, str: string (n), pos: size_t (i)): void = { val () = loop (lcd, str, pos) + val () = lcd_close lcd val () = forever (lcd, str, pos) } val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7)
  • 26. Power of Linear Type #2 $ make --snip-- patsopt -o DATS/main_dats.c -d DATS/main.dats /home/kiwamu/src/arduino-ats/demo/lcd_ats/DATS/main.dats: 1263 (line=29, offs=23) -- 1266(line=29, offs=26): error(3): the linear dynamic variable [lcd$1182(-1)] is no longer available. /home/kiwamu/src/arduino-ats/demo/lcd_ats/DATS/main.dats: 1263 (line=29, offs=23) -- 1266(line=29, offs=26): error(3): the dynamic expression cannot be assigned the type [S2Ecst(lcd_t)]. ☆ ATS2 finds issue at compile time! ☆ Linear value "lcd" is consumed ☆ However "lcd" is used by "forever"
  • 27. [5] Japan ATS User Group http://jats-ug.metasepi.org/
  • 31. Doc: ATS2 wiki hhhttttttpppsss::://////gggiiittthhhuuubbb...cccooommm///gggiiittthhhwwwxxxiii///AAATTTSSS---PPPooossstttiiiaaatttsss///wwwiiikkkiii