* [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
Kiwamu OkabeSoftware Engineer at SELTECH CORPORATION
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
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
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