SlideShare a Scribd company logo
Generate ATS interface from C code,
and introduce linear type
Generate ATS interface from C code,
and introduce linear type
Generate ATS interface from C code,
and introduce linear type
Generate ATS interface from C code,
and introduce linear type
Generate ATS interface from C code,
and introduce linear type
Kiwamu Okabe @ RIKEN AICSKiwamu Okabe @ RIKEN AICSKiwamu Okabe @ RIKEN AICSKiwamu Okabe @ RIKEN AICSKiwamu Okabe @ RIKEN AICS
Today's low level programmingToday's low level programmingToday's low level programmingToday's low level programmingToday's low level programming
☆ uses C programming language.☆ uses C programming language.☆ uses C programming language.☆ uses C programming language.☆ uses C programming language.
☆ may causes buffer overflow.☆ may causes buffer overflow.☆ may causes buffer overflow.☆ may causes buffer overflow.☆ may causes buffer overflow.
☆ may violate invariant in the code.☆ may violate invariant in the code.☆ may violate invariant in the code.☆ may violate invariant in the code.☆ may violate invariant in the code.
☆ may violate specification of the design.☆ may violate specification of the design.☆ may violate specification of the design.☆ may violate specification of the design.☆ may violate specification of the design.
☆ These errors occur at run-time.☆ These errors occur at run-time.☆ These errors occur at run-time.☆ These errors occur at run-time.☆ These errors occur at run-time.
Why need the other language?Why need the other language?Why need the other language?Why need the other language?Why need the other language?
☆ We want to find these errors at compile-time.☆ We want to find these errors at compile-time.☆ We want to find these errors at compile-time.☆ We want to find these errors at compile-time.☆ We want to find these errors at compile-time.
☆ Of course, we can use verification on C language.☆ Of course, we can use verification on C language.☆ Of course, we can use verification on C language.☆ Of course, we can use verification on C language.☆ Of course, we can use verification on C language.
☆ e.g. Coverity, Frama-C, Infer, VeriFast, vcc, etc...☆ e.g. Coverity, Frama-C, Infer, VeriFast, vcc, etc...☆ e.g. Coverity, Frama-C, Infer, VeriFast, vcc, etc...☆ e.g. Coverity, Frama-C, Infer, VeriFast, vcc, etc...☆ e.g. Coverity, Frama-C, Infer, VeriFast, vcc, etc...
☆ But also we want to use more rich type system.☆ But also we want to use more rich type system.☆ But also we want to use more rich type system.☆ But also we want to use more rich type system.☆ But also we want to use more rich type system.
☆ Today is the day to choose the other language
for low level programming?
☆ Today is the day to choose the other language
for low level programming?
☆ Today is the day to choose the other language
for low level programming?
☆ Today is the day to choose the other language
for low level programming?
☆ Today is the day to choose the other language
for low level programming?
ATS languageATS languageATS languageATS languageATS language
☆ http://www.ats-lang.org/☆ http://www.ats-lang.org/☆ http://www.ats-lang.org/☆ http://www.ats-lang.org/☆ http://www.ats-lang.org/
☆ Syntax like ML☆ Syntax like ML☆ Syntax like ML☆ Syntax like ML☆ Syntax like ML
☆ DML-style dependent types☆ DML-style dependent types☆ DML-style dependent types☆ DML-style dependent types☆ DML-style dependent types
☆ Linear types☆ Linear types☆ Linear types☆ Linear types☆ Linear types
☆ Optional GC, malloc/free, run-time☆ Optional GC, malloc/free, run-time☆ Optional GC, malloc/free, run-time☆ Optional GC, malloc/free, run-time☆ Optional GC, malloc/free, run-time
Real of ATS programmingReal of ATS programmingReal of ATS programmingReal of ATS programmingReal of ATS programming
But, there is no paradise. Real ATS programming
needs many interfaces imported from C.
But, there is no paradise. Real ATS programming
needs many interfaces imported from C.
But, there is no paradise. Real ATS programming
needs many interfaces imported from C.
But, there is no paradise. Real ATS programming
needs many interfaces imported from C.
But, there is no paradise. Real ATS programming
needs many interfaces imported from C.
A tool "c2ats" resolves it!A tool "c2ats" resolves it!A tool "c2ats" resolves it!A tool "c2ats" resolves it!A tool "c2ats" resolves it!
☆ https://github.com/metasepi/c2ats/☆ https://github.com/metasepi/c2ats/☆ https://github.com/metasepi/c2ats/☆ https://github.com/metasepi/c2ats/☆ https://github.com/metasepi/c2ats/
☆ parse C header and generate ATS interface.☆ parse C header and generate ATS interface.☆ parse C header and generate ATS interface.☆ parse C header and generate ATS interface.☆ parse C header and generate ATS interface.
☆ made by Haskell language.☆ made by Haskell language.☆ made by Haskell language.☆ made by Haskell language.☆ made by Haskell language.
☆ using "language-c" library to parse C code.☆ using "language-c" library to parse C code.☆ using "language-c" library to parse C code.☆ using "language-c" library to parse C code.☆ using "language-c" library to parse C code.
We can do using c2ats...We can do using c2ats...We can do using c2ats...We can do using c2ats...We can do using c2ats...
Rule: Translating primitive typesRule: Translating primitive typesRule: Translating primitive typesRule: Translating primitive typesRule: Translating primitive types
ATS's unboxed type is one-to-one for C's one.ATS's unboxed type is one-to-one for C's one.ATS's unboxed type is one-to-one for C's one.ATS's unboxed type is one-to-one for C's one.ATS's unboxed type is one-to-one for C's one.
C�language��������│�ATS�language
------------------+------------------
bool��������������│�bool
char��������������│�char
signed�char�������│�schar
unsigned�char�����│�uchar
short�������������│�sint
unsigned�short����│�usint
int���������������│�int
unsigned�int������│�uint
long�int����������│�lint
unsigned�long�int�│�ulint
...���������������│�...
C�language��������│�ATS�language
------------------+------------------
bool��������������│�bool
char��������������│�char
signed�char�������│�schar
unsigned�char�����│�uchar
short�������������│�sint
unsigned�short����│�usint
int���������������│�int
unsigned�int������│�uint
long�int����������│�lint
unsigned�long�int�│�ulint
...���������������│�...
C�language��������│�ATS�language
------------------+------------------
bool��������������│�bool
char��������������│�char
signed�char�������│�schar
unsigned�char�����│�uchar
short�������������│�sint
unsigned�short����│�usint
int���������������│�int
unsigned�int������│�uint
long�int����������│�lint
unsigned�long�int�│�ulint
...���������������│�...
C�language��������│�ATS�language
------------------+------------------
bool��������������│�bool
char��������������│�char
signed�char�������│�schar
unsigned�char�����│�uchar
short�������������│�sint
unsigned�short����│�usint
int���������������│�int
unsigned�int������│�uint
long�int����������│�lint
unsigned�long�int�│�ulint
...���������������│�...
C�language��������│�ATS�language
------------------+------------------
bool��������������│�bool
char��������������│�char
signed�char�������│�schar
unsigned�char�����│�uchar
short�������������│�sint
unsigned�short����│�usint
int���������������│�int
unsigned�int������│�uint
long�int����������│�lint
unsigned�long�int�│�ulint
...���������������│�...
Rule: FunctionsRule: FunctionsRule: FunctionsRule: FunctionsRule: Functions
☆ If you have following C function declaration:☆ If you have following C function declaration:☆ If you have following C function declaration:☆ If you have following C function declaration:☆ If you have following C function declaration:
int�func_a(int,�char);int�func_a(int,�char);int�func_a(int,�char);int�func_a(int,�char);int�func_a(int,�char);
☆ c2ats generate following ATS interface:☆ c2ats generate following ATS interface:☆ c2ats generate following ATS interface:☆ c2ats generate following ATS interface:☆ c2ats generate following ATS interface:
fun�fun_c2ats_func_a:�(int,�char)�->�int�=�"mac#func_a"fun�fun_c2ats_func_a:�(int,�char)�->�int�=�"mac#func_a"fun�fun_c2ats_func_a:�(int,�char)�->�int�=�"mac#func_a"fun�fun_c2ats_func_a:�(int,�char)�->�int�=�"mac#func_a"fun�fun_c2ats_func_a:�(int,�char)�->�int�=�"mac#func_a"
Rule: StructRule: StructRule: StructRule: StructRule: Struct
//�If�you�have�following�C�structure:
struct�t�{
��int�a;
��struct�{int�b;}�c;
};
//�If�you�have�following�C�structure:
struct�t�{
��int�a;
��struct�{int�b;}�c;
};
//�If�you�have�following�C�structure:
struct�t�{
��int�a;
��struct�{int�b;}�c;
};
//�If�you�have�following�C�structure:
struct�t�{
��int�a;
��struct�{int�b;}�c;
};
//�If�you�have�following�C�structure:
struct�t�{
int�a;
struct�{int�b;}�c;
};
//�c2ats�generate�following�ATS�type�definition:
typedef�struct_c2ats_anon_10�=�$extype_struct"struct�{�int�b;�}"�of�{
��b�=�int
}
typedef�struct_c2ats_t�=�$extype_struct"struct�t"�of�{
��a�=�int,
��c�=�struct_c2ats_anon_10
}
//�c2ats�generate�following�ATS�type�definition:
typedef�struct_c2ats_anon_10�=�$extype_struct"struct�{�int�b;�}"�of�{
��b�=�int
}
typedef�struct_c2ats_t�=�$extype_struct"struct�t"�of�{
��a�=�int,
��c�=�struct_c2ats_anon_10
}
//�c2ats�generate�following�ATS�type�definition:
typedef�struct_c2ats_anon_10�=�$extype_struct"struct�{�int�b;�}"�of�{
��b�=�int
}
typedef�struct_c2ats_t�=�$extype_struct"struct�t"�of�{
��a�=�int,
��c�=�struct_c2ats_anon_10
}
//�c2ats�generate�following�ATS�type�definition:
typedef�struct_c2ats_anon_10�=�$extype_struct"struct�{�int�b;�}"�of�{
��b�=�int
}
typedef�struct_c2ats_t�=�$extype_struct"struct�t"�of�{
��a�=�int,
��c�=�struct_c2ats_anon_10
}
//�c2ats�generate�following�ATS�type�definition:
typedef�struct_c2ats_anon_10�=�$extype_struct"struct�{�int�b;�}"�of�{
��b�=�int
}
typedef�struct_c2ats_t�=�$extype_struct"struct�t"�of�{
��a�=�int,
��c�=�struct_c2ats_anon_10
}
Rule: Pointers and at-view #1Rule: Pointers and at-view #1Rule: Pointers and at-view #1Rule: Pointers and at-view #1Rule: Pointers and at-view #1
☆ If you have following C declaration:☆ If you have following C declaration:☆ If you have following C declaration:☆ If you have following C declaration:☆ If you have following C declaration:
int�getopt�(int�___argc,�char�**___argv,�char�*__shortopts);int�getopt�(int�___argc,�char�**___argv,�char�*__shortopts);int�getopt�(int�___argc,�char�**___argv,�char�*__shortopts);int�getopt�(int�___argc,�char�**___argv,�char�*__shortopts);int�getopt�(int�___argc,�char�**___argv,�char�*__shortopts);
☆ c2ats generate following ATS definition:☆ c2ats generate following ATS definition:☆ c2ats generate following ATS definition:☆ c2ats generate following ATS definition:☆ c2ats generate following ATS definition:
viewdef�ptr_v_1�(a:t@ype,�l:addr)�=�a�@�l
dataview�ptr_v_2�(a:t@ype+,�l0:�addr,�l1:�addr)�=
��│�ptr_v_2_cons(a,�l0,�l1)�of�(ptr�l1�@�l0,�ptr_v_1�(a,�l1))
fun�fun_c2ats_getopt:�{l1,l1_1,l2:addr}�(!ptr_v_2(char,�l1,�l1_1),�!ptr_v_1
(char,�l2)�│�int,�ptr�l1,�ptr�l2)�->�int�=�"mac#getopt"
viewdef�ptr_v_1�(a:t@ype,�l:addr)�=�a�@�l
dataview�ptr_v_2�(a:t@ype+,�l0:�addr,�l1:�addr)�=
��│�ptr_v_2_cons(a,�l0,�l1)�of�(ptr�l1�@�l0,�ptr_v_1�(a,�l1))
fun�fun_c2ats_getopt:�{l1,l1_1,l2:addr}�(!ptr_v_2(char,�l1,�l1_1),�!ptr_v_1
(char,�l2)�│�int,�ptr�l1,�ptr�l2)�->�int�=�"mac#getopt"
viewdef�ptr_v_1�(a:t@ype,�l:addr)�=�a�@�l
dataview�ptr_v_2�(a:t@ype+,�l0:�addr,�l1:�addr)�=
��│�ptr_v_2_cons(a,�l0,�l1)�of�(ptr�l1�@�l0,�ptr_v_1�(a,�l1))
fun�fun_c2ats_getopt:�{l1,l1_1,l2:addr}�(!ptr_v_2(char,�l1,�l1_1),�!ptr_v_1
(char,�l2)�│�int,�ptr�l1,�ptr�l2)�->�int�=�"mac#getopt"
viewdef�ptr_v_1�(a:t@ype,�l:addr)�=�a�@�l
dataview�ptr_v_2�(a:t@ype+,�l0:�addr,�l1:�addr)�=
��│�ptr_v_2_cons(a,�l0,�l1)�of�(ptr�l1�@�l0,�ptr_v_1�(a,�l1))
fun�fun_c2ats_getopt:�{l1,l1_1,l2:addr}�(!ptr_v_2(char,�l1,�l1_1),�!ptr_v_1
(char,�l2)�│�int,�ptr�l1,�ptr�l2)�->�int�=�"mac#getopt"
viewdef�ptr_v_1�(a:t@ype,�l:addr)�=�a�@�l
dataview�ptr_v_2�(a:t@ype+,�l0:�addr,�l1:�addr)�=
��│�ptr_v_2_cons(a,�l0,�l1)�of�(ptr�l1�@�l0,�ptr_v_1�(a,�l1))
fun�fun_c2ats_getopt:�{l1,l1_1,l2:addr}�(!ptr_v_2(char,�l1,�l1_1),�!ptr_v_1
(char,�l2)�│�int,�ptr�l1,�ptr�l2)�->�int�=�"mac#getopt"
Rule: Pointers and at-view #2Rule: Pointers and at-view #2Rule: Pointers and at-view #2Rule: Pointers and at-view #2Rule: Pointers and at-view #2
You can dereference pointer "ptr l1", "ptr l1_1",
"ptr l2" because they has own at-view.
You can dereference pointer "ptr l1", "ptr l1_1",
"ptr l2" because they has own at-view.
You can dereference pointer "ptr l1", "ptr l1_1",
"ptr l2" because they has own at-view.
You can dereference pointer "ptr l1", "ptr l1_1",
"ptr l2" because they has own at-view.
You can dereference pointer "ptr l1", "ptr l1_1",
"ptr l2" because they has own at-view.
Rule: Accessor for global variables #1Rule: Accessor for global variables #1Rule: Accessor for global variables #1Rule: Accessor for global variables #1Rule: Accessor for global variables #1
//�If�you�have�following�C�declaration:
struct�foo�{int�i;�char�*s;};
extern�struct�foo�g_foo;
//�If�you�have�following�C�declaration:
struct�foo�{int�i;�char�*s;};
extern�struct�foo�g_foo;
//�If�you�have�following�C�declaration:
struct�foo�{int�i;�char�*s;};
extern�struct�foo�g_foo;
//�If�you�have�following�C�declaration:
struct�foo�{int�i;�char�*s;};
extern�struct�foo�g_foo;
//�If�you�have�following�C�declaration:
struct�foo�{int�i;�char�*s;};
extern struct�foo�g_foo;
//�c2ats�generate�following�ATS�definition:
typedef�struct_c2ats_foo�=�$extype_struct"struct�foo"�of�{
��i�=�int,
��s�=�ptr�(*�cPtr0(char)�*)
}
macdef�takeout_c2ats_g_foo�=�$extval([l1:addr]�(ptr_v_1(struct_c2ats_foo,�
l1)�│�ptr�l1),�"&g_foo")
praxi�addback_c2ats_g_foo�{l1:addr}�(ptr_v_1(struct_c2ats_foo,�l1)�│�ptr�
l1):�void
//�c2ats�generate�following�ATS�definition:
typedef�struct_c2ats_foo�=�$extype_struct"struct�foo"�of�{
��i�=�int,
��s�=�ptr�(*�cPtr0(char)�*)
}
macdef�takeout_c2ats_g_foo�=�$extval([l1:addr]�(ptr_v_1(struct_c2ats_foo,�
l1)�│�ptr�l1),�"&g_foo")
praxi�addback_c2ats_g_foo�{l1:addr}�(ptr_v_1(struct_c2ats_foo,�l1)�│�ptr�
l1):�void
//�c2ats�generate�following�ATS�definition:
typedef�struct_c2ats_foo�=�$extype_struct"struct�foo"�of�{
��i�=�int,
��s�=�ptr�(*�cPtr0(char)�*)
}
macdef�takeout_c2ats_g_foo�=�$extval([l1:addr]�(ptr_v_1(struct_c2ats_foo,�
l1)�│�ptr�l1),�"&g_foo")
praxi�addback_c2ats_g_foo�{l1:addr}�(ptr_v_1(struct_c2ats_foo,�l1)�│�ptr�
l1):�void
//�c2ats�generate�following�ATS�definition:
typedef�struct_c2ats_foo�=�$extype_struct"struct�foo"�of�{
��i�=�int,
��s�=�ptr�(*�cPtr0(char)�*)
}
macdef�takeout_c2ats_g_foo�=�$extval([l1:addr]�(ptr_v_1(struct_c2ats_foo,�
l1)�│�ptr�l1),�"&g_foo")
praxi�addback_c2ats_g_foo�{l1:addr}�(ptr_v_1(struct_c2ats_foo,�l1)�│�ptr�
l1):�void
//�c2ats�generate�following�ATS�definition:
typedef�struct_c2ats_foo�=�$extype_struct"struct�foo"�of�{
��i�=�int,
��s�=�ptr�(*�cPtr0(char)�*)
}
macdef�takeout_c2ats_g_foo�=�$extval([l1:addr]�(ptr_v_1(struct_c2ats_foo,�
l1)�│�ptr�l1),�"&g_foo")
praxi�addback_c2ats_g_foo�{l1:addr}�(ptr_v_1(struct_c2ats_foo,�l1)�│�ptr�
l1):�void
Rule: Accessor for global variables #2Rule: Accessor for global variables #2Rule: Accessor for global variables #2Rule: Accessor for global variables #2Rule: Accessor for global variables #2
//�You�can�write�following�code�with�the�definition:
staload�"example.sats"
implement�main0�()�=�{
��//�g_foo
��val�(pfg_foo�│�g_foo)�=�takeout_c2ats_g_foo
��val�i�=�g_foo->i
��val�s�=�$UN.cast{string}(g_foo->s)
��val�()�=�println!�("g_foo�=�{",�i,�",�"",�s,�""}")
��val�()�=�assertloc�(i�=�1234)
��val�()�=�assertloc�(strcmp�("Hello,�world!",�s)�=�0)
��prval�()�=�addback_c2ats_g_foo�(pfg_foo�│�g_foo)
}
//�You�can�write�following�code�with�the�definition:
staload�"example.sats"
implement�main0�()�=�{
��//�g_foo
��val�(pfg_foo�│�g_foo)�=�takeout_c2ats_g_foo
��val�i�=�g_foo->i
��val�s�=�$UN.cast{string}(g_foo->s)
��val�()�=�println!�("g_foo�=�{",�i,�",�"",�s,�""}")
��val�()�=�assertloc�(i�=�1234)
��val�()�=�assertloc�(strcmp�("Hello,�world!",�s)�=�0)
��prval�()�=�addback_c2ats_g_foo�(pfg_foo�│�g_foo)
}
//�You�can�write�following�code�with�the�definition:
staload�"example.sats"
implement�main0�()�=�{
��//�g_foo
��val�(pfg_foo�│�g_foo)�=�takeout_c2ats_g_foo
��val�i�=�g_foo->i
��val�s�=�$UN.cast{string}(g_foo->s)
��val�()�=�println!�("g_foo�=�{",�i,�",�"",�s,�""}")
��val�()�=�assertloc�(i�=�1234)
��val�()�=�assertloc�(strcmp�("Hello,�world!",�s)�=�0)
��prval�()�=�addback_c2ats_g_foo�(pfg_foo�│�g_foo)
}
//�You�can�write�following�code�with�the�definition:
staload�"example.sats"
implement�main0�()�=�{
��//�g_foo
��val�(pfg_foo�│�g_foo)�=�takeout_c2ats_g_foo
��val�i�=�g_foo->i
��val�s�=�$UN.cast{string}(g_foo->s)
��val�()�=�println!�("g_foo�=�{",�i,�",�"",�s,�""}")
��val�()�=�assertloc�(i�=�1234)
��val�()�=�assertloc�(strcmp�("Hello,�world!",�s)�=�0)
��prval�()�=�addback_c2ats_g_foo�(pfg_foo�│�g_foo)
}
//�You�can�write�following�code�with�the�definition:
staload�"example.sats"
implement�main0�()�=�{
//�g_foo
val�(pfg_foo�│�g_foo)�=�takeout_c2ats_g_foo
val�i�=�g_foo->i
val�s�=�$UN.cast{string}(g_foo->s)
val�()�=�println!�("g_foo�=�{",�i,�",�"",�s,�""}")
val�()�=�assertloc�(i�=�1234)
val�()�=�assertloc�(strcmp�("Hello,�world!",�s)�=�0)
prval�()�=�addback_c2ats_g_foo�(pfg_foo�│�g_foo)
}
Unsafe ATS application on API #1Unsafe ATS application on API #1Unsafe ATS application on API #1Unsafe ATS application on API #1Unsafe ATS application on API #1
☆ First, generate ATS interfaces from C header:☆ First, generate ATS interfaces from C header:☆ First, generate ATS interfaces from C header:☆ First, generate ATS interfaces from C header:☆ First, generate ATS interfaces from C header:
$�cat�example.h
#include�<stdio.h>
$�c2ats�gen�example.h�>�example.sats
$�cat�example.sats
$�cat�example.h
#include�<stdio.h>
$�c2ats�gen�example.h�>�example.sats
$�cat�example.sats
$�cat�example.h
#include�<stdio.h>
$�c2ats�gen�example.h�>�example.sats
$�cat�example.sats
$�cat�example.h
#include�<stdio.h>
$�c2ats�gen�example.h�>�example.sats
$�cat�example.sats
$�cat�example.h
#include�<stdio.h>
$�c2ats�gen�example.h�>�example.sats
$�cat�example.sats
//--snip--
fun�fun_c2ats_fread:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,�
type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=�
"mac#fread"
fun�fun_c2ats_fwrite:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,�
type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=�
"mac#fwrite"
fun�fun_c2ats_fseek:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1,�
lint,�int)�->�int�=�"mac#fseek"
//--snip--
fun�fun_c2ats_fread:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,�
type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=�
"mac#fread"
fun�fun_c2ats_fwrite:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,�
type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=�
"mac#fwrite"
fun�fun_c2ats_fseek:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1,�
lint,�int)�->�int�=�"mac#fseek"
//--snip--
fun�fun_c2ats_fread:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,�
type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=�
"mac#fread"
fun�fun_c2ats_fwrite:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,�
type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=�
"mac#fwrite"
fun�fun_c2ats_fseek:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1,�
lint,�int)�->�int�=�"mac#fseek"
//--snip--
fun�fun_c2ats_fread:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,�
type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=�
"mac#fread"
fun�fun_c2ats_fwrite:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,�
type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=�
"mac#fwrite"
fun�fun_c2ats_fseek:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1,�
lint,�int)�->�int�=�"mac#fseek"
//--snip--
fun�fun_c2ats_fread:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,�
type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=�
"mac#fread"
fun�fun_c2ats_fwrite:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,�
type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=�
"mac#fwrite"
fun�fun_c2ats_fseek:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1,�
lint,�int)�->�int�=�"mac#fseek"
Unsafe ATS application on API #2Unsafe ATS application on API #2Unsafe ATS application on API #2Unsafe ATS application on API #2Unsafe ATS application on API #2
☆ Next, write ATS code with unsafe manner:☆ Next, write ATS code with unsafe manner:☆ Next, write ATS code with unsafe manner:☆ Next, write ATS code with unsafe manner:☆ Next, write ATS code with unsafe manner:
$�vi�main.dats$�vi�main.dats$�vi�main.dats$�vi�main.dats$�vi�main.dats
#include�"share/atspre_define.hats"
#include�"share/atspre_staload.hats"
staload�UN�=�"prelude/SATS/unsafe.sats"�//�Unsafe!
staload�STRING�=�"libats/libc/SATS/string.sats"
staload�"example.sats"
extern�praxi�__create_view�{to:view}�():<prf>�to�//�Unsafe!
extern�praxi�__consume_view�{from:view}�(pf:�from):<prf>�void�//�Unsafe!
//�continue...
#include�"share/atspre_define.hats"
#include�"share/atspre_staload.hats"
staload�UN�=�"prelude/SATS/unsafe.sats"�//�Unsafe!
staload�STRING�=�"libats/libc/SATS/string.sats"
staload�"example.sats"
extern�praxi�__create_view�{to:view}�():<prf>�to�//�Unsafe!
extern�praxi�__consume_view�{from:view}�(pf:�from):<prf>�void�//�Unsafe!
//�continue...
#include�"share/atspre_define.hats"
#include�"share/atspre_staload.hats"
staload�UN�=�"prelude/SATS/unsafe.sats"�//�Unsafe!
staload�STRING�=�"libats/libc/SATS/string.sats"
staload�"example.sats"
extern�praxi�__create_view�{to:view}�():<prf>�to�//�Unsafe!
extern�praxi�__consume_view�{from:view}�(pf:�from):<prf>�void�//�Unsafe!
//�continue...
#include�"share/atspre_define.hats"
#include�"share/atspre_staload.hats"
staload�UN�=�"prelude/SATS/unsafe.sats"�//�Unsafe!
staload�STRING�=�"libats/libc/SATS/string.sats"
staload�"example.sats"
extern�praxi�__create_view�{to:view}�():<prf>�to�//�Unsafe!
extern�praxi�__consume_view�{from:view}�(pf:�from):<prf>�void�//�Unsafe!
//�continue...
#include�"share/atspre_define.hats"
#include�"share/atspre_staload.hats"
staload�UN�=�"prelude/SATS/unsafe.sats"�//�Unsafe!
staload�STRING�=�"libats/libc/SATS/string.sats"
staload�"example.sats"
extern praxi�__create_view�{to:view}�():<prf>�to�//�Unsafe!
extern praxi�__consume_view�{from:view}�(pf:�from):<prf>�void�//�Unsafe!
//�continue...
Unsafe ATS application on API #3Unsafe ATS application on API #3Unsafe ATS application on API #3Unsafe ATS application on API #3Unsafe ATS application on API #3
fun�my_fopen�(file:�string,�mode:�string):
����[l:agz]�(type_c2ats_FILE@l�│�ptr(l))�=�ret�where�{
��val�pn�=�string2ptr(file)
��val�(pfnat,�fpfnat�│�pn)�=�$UN.ptr_vtake(pn)�//�Unsafe!
��val�pm�=�string2ptr(mode)
��val�(pfmat,�fpfmat�│�pm)�=�$UN.ptr_vtake(pm)�//�Unsafe!
��val�(pffp�│�fp)�=�fun_c2ats_fopen(pfnat,�pfmat�│�pn,�pm)
��prval�()�=�fpfnat(pfnat)
��prval�()�=�fpfmat(pfmat)
��val�()�=�assertloc(fp�>�0)
��val�ret�=�(pffp�│�fp)
}
//�continue...
fun�my_fopen�(file:�string,�mode:�string):
����[l:agz]�(type_c2ats_FILE@l�│�ptr(l))�=�ret�where�{
��val�pn�=�string2ptr(file)
��val�(pfnat,�fpfnat�│�pn)�=�$UN.ptr_vtake(pn)�//�Unsafe!
��val�pm�=�string2ptr(mode)
��val�(pfmat,�fpfmat�│�pm)�=�$UN.ptr_vtake(pm)�//�Unsafe!
��val�(pffp�│�fp)�=�fun_c2ats_fopen(pfnat,�pfmat�│�pn,�pm)
��prval�()�=�fpfnat(pfnat)
��prval�()�=�fpfmat(pfmat)
��val�()�=�assertloc(fp�>�0)
��val�ret�=�(pffp�│�fp)
}
//�continue...
fun�my_fopen�(file:�string,�mode:�string):
����[l:agz]�(type_c2ats_FILE@l�│�ptr(l))�=�ret�where�{
��val�pn�=�string2ptr(file)
��val�(pfnat,�fpfnat�│�pn)�=�$UN.ptr_vtake(pn)�//�Unsafe!
��val�pm�=�string2ptr(mode)
��val�(pfmat,�fpfmat�│�pm)�=�$UN.ptr_vtake(pm)�//�Unsafe!
��val�(pffp�│�fp)�=�fun_c2ats_fopen(pfnat,�pfmat�│�pn,�pm)
��prval�()�=�fpfnat(pfnat)
��prval�()�=�fpfmat(pfmat)
��val�()�=�assertloc(fp�>�0)
��val�ret�=�(pffp�│�fp)
}
//�continue...
fun�my_fopen�(file:�string,�mode:�string):
����[l:agz]�(type_c2ats_FILE@l�│�ptr(l))�=�ret�where�{
��val�pn�=�string2ptr(file)
��val�(pfnat,�fpfnat�│�pn)�=�$UN.ptr_vtake(pn)�//�Unsafe!
��val�pm�=�string2ptr(mode)
��val�(pfmat,�fpfmat�│�pm)�=�$UN.ptr_vtake(pm)�//�Unsafe!
��val�(pffp�│�fp)�=�fun_c2ats_fopen(pfnat,�pfmat�│�pn,�pm)
��prval�()�=�fpfnat(pfnat)
��prval�()�=�fpfmat(pfmat)
��val�()�=�assertloc(fp�>�0)
��val�ret�=�(pffp�│�fp)
}
//�continue...
fun�my_fopen�(file:�string,�mode:�string):
[l:agz]�(type_c2ats_FILE@l�│�ptr(l))�=�ret�where�{
val�pn�=�string2ptr(file)
val�(pfnat,�fpfnat�│�pn)�=�$UN.ptr_vtake(pn)�//�Unsafe!
val�pm�=�string2ptr(mode)
val�(pfmat,�fpfmat�│�pm)�=�$UN.ptr_vtake(pm)�//�Unsafe!
val�(pffp�│�fp)�=�fun_c2ats_fopen(pfnat,�pfmat�│�pn,�pm)
prval�()�=�fpfnat(pfnat)
prval�()�=�fpfmat(pfmat)
val�()�=�assertloc(fp�>�0)
val�ret�=�(pffp�│�fp)
}
//�continue...
Unsafe ATS application on API #4Unsafe ATS application on API #4Unsafe ATS application on API #4Unsafe ATS application on API #4Unsafe ATS application on API #4
fun�my_fread�{l:agz}{n:nat}
����(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l),�len:�size_t(n)):
����[m:int]�(size_t(m),�strnptr(m))�=�ret�where�{
��implement{}�string_tabulate$fopr(s)�=�'_'
��val�buf_strptr�=�strnptr2strptr(string_tabulate(len))
��val�buf_ptr�=�strptr2ptr(buf_strptr)
��val�_�=�$STRING.memset_unsafe(buf_ptr,�0,�len)
��val�r�=�fun_c2ats_fread(pffp�│�buf_ptr,�1UL,�$UN.cast2ulint(len),�fp)�//�
Unsafe!
��val�r�=�$UN.cast(r)�//�Unsafe!
��val�buf_strnptr�=�strptr2strnptr(buf_strptr)
��val�ret�=�(r,�buf_strnptr)
}
//�continue...
fun�my_fread�{l:agz}{n:nat}
����(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l),�len:�size_t(n)):
����[m:int]�(size_t(m),�strnptr(m))�=�ret�where�{
��implement{}�string_tabulate$fopr(s)�=�'_'
��val�buf_strptr�=�strnptr2strptr(string_tabulate(len))
��val�buf_ptr�=�strptr2ptr(buf_strptr)
��val�_�=�$STRING.memset_unsafe(buf_ptr,�0,�len)
��val�r�=�fun_c2ats_fread(pffp�│�buf_ptr,�1UL,�$UN.cast2ulint(len),�fp)�//�
Unsafe!
��val�r�=�$UN.cast(r)�//�Unsafe!
��val�buf_strnptr�=�strptr2strnptr(buf_strptr)
��val�ret�=�(r,�buf_strnptr)
}
//�continue...
fun�my_fread�{l:agz}{n:nat}
����(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l),�len:�size_t(n)):
����[m:int]�(size_t(m),�strnptr(m))�=�ret�where�{
��implement{}�string_tabulate$fopr(s)�=�'_'
��val�buf_strptr�=�strnptr2strptr(string_tabulate(len))
��val�buf_ptr�=�strptr2ptr(buf_strptr)
��val�_�=�$STRING.memset_unsafe(buf_ptr,�0,�len)
��val�r�=�fun_c2ats_fread(pffp�│�buf_ptr,�1UL,�$UN.cast2ulint(len),�fp)�//�
Unsafe!
��val�r�=�$UN.cast(r)�//�Unsafe!
��val�buf_strnptr�=�strptr2strnptr(buf_strptr)
��val�ret�=�(r,�buf_strnptr)
}
//�continue...
fun�my_fread�{l:agz}{n:nat}
����(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l),�len:�size_t(n)):
����[m:int]�(size_t(m),�strnptr(m))�=�ret�where�{
��implement{}�string_tabulate$fopr(s)�=�'_'
��val�buf_strptr�=�strnptr2strptr(string_tabulate(len))
��val�buf_ptr�=�strptr2ptr(buf_strptr)
��val�_�=�$STRING.memset_unsafe(buf_ptr,�0,�len)
��val�r�=�fun_c2ats_fread(pffp�│�buf_ptr,�1UL,�$UN.cast2ulint(len),�fp)�//�
Unsafe!
��val�r�=�$UN.cast(r)�//�Unsafe!
��val�buf_strnptr�=�strptr2strnptr(buf_strptr)
��val�ret�=�(r,�buf_strnptr)
}
//�continue...
fun�my_fread�{l:agz}{n:nat}
����(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l),�len:�size_t(n)):
[m:int]�(size_t(m),�strnptr(m))�=�ret�where�{
implement{}�string_tabulate$fopr(s)�=�'_'
val�buf_strptr�=�strnptr2strptr(string_tabulate(len))
val�buf_ptr�=�strptr2ptr(buf_strptr)
val�_�=�$STRING.memset_unsafe(buf_ptr,�0,�len)
val�r�=�fun_c2ats_fread(pffp�│�buf_ptr,�1UL,�$UN.cast2ulint(len),�fp)�//�
Unsafe!
val�r�=�$UN.cast(r)�//�Unsafe!
val�buf_strnptr�=�strptr2strnptr(buf_strptr)
val�ret�=�(r,�buf_strnptr)
}
//�continue...
Unsafe ATS application on API #5Unsafe ATS application on API #5Unsafe ATS application on API #5Unsafe ATS application on API #5Unsafe ATS application on API #5
fun�my_fclose�{l:agz}�(pffp:�type_c2ats_FILE@l�│�fp:�ptr(l)):�int
����=�ret�where�{
��val�ret�=�fun_c2ats_fclose(pffp�│�fp)
��prval�()�=�__consume_view(pffp)
}
fun�readshow�{l:agz}�(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l)):�void�=�{
��val�(r,�str)�=�my_fread(pffp�│�fp,�i2sz(128))
��val�str�=�strnptr2strptr(str)
��val�()�=�print(str)
��val�()�=�free(str)
��val�()�=�if�r�>�0�then�readshow(pffp�│�fp)
}
//�continue...
fun�my_fclose�{l:agz}�(pffp:�type_c2ats_FILE@l�│�fp:�ptr(l)):�int
����=�ret�where�{
��val�ret�=�fun_c2ats_fclose(pffp�│�fp)
��prval�()�=�__consume_view(pffp)
}
fun�readshow�{l:agz}�(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l)):�void�=�{
��val�(r,�str)�=�my_fread(pffp�│�fp,�i2sz(128))
��val�str�=�strnptr2strptr(str)
��val�()�=�print(str)
��val�()�=�free(str)
��val�()�=�if�r�>�0�then�readshow(pffp�│�fp)
}
//�continue...
fun�my_fclose�{l:agz}�(pffp:�type_c2ats_FILE@l�│�fp:�ptr(l)):�int
����=�ret�where�{
��val�ret�=�fun_c2ats_fclose(pffp�│�fp)
��prval�()�=�__consume_view(pffp)
}
fun�readshow�{l:agz}�(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l)):�void�=�{
��val�(r,�str)�=�my_fread(pffp�│�fp,�i2sz(128))
��val�str�=�strnptr2strptr(str)
��val�()�=�print(str)
��val�()�=�free(str)
��val�()�=�if�r�>�0�then�readshow(pffp�│�fp)
}
//�continue...
fun�my_fclose�{l:agz}�(pffp:�type_c2ats_FILE@l�│�fp:�ptr(l)):�int
����=�ret�where�{
��val�ret�=�fun_c2ats_fclose(pffp�│�fp)
��prval�()�=�__consume_view(pffp)
}
fun�readshow�{l:agz}�(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l)):�void�=�{
��val�(r,�str)�=�my_fread(pffp�│�fp,�i2sz(128))
��val�str�=�strnptr2strptr(str)
��val�()�=�print(str)
��val�()�=�free(str)
��val�()�=�if�r�>�0�then�readshow(pffp�│�fp)
}
//�continue...
fun�my_fclose�{l:agz}�(pffp:�type_c2ats_FILE@l�│�fp:�ptr(l)):�int
����=�ret�where�{
val�ret�=�fun_c2ats_fclose(pffp�│�fp)
prval�()�=�__consume_view(pffp)
}
fun�readshow�{l:agz}�(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l)):�void�=�{
val�(r,�str)�=�my_fread(pffp�│�fp,�i2sz(128))
val�str�=�strnptr2strptr(str)
val�()�=�print(str)
val�()�=�free(str)
val�()�=�if�r�>�0 then�readshow(pffp�│�fp)
}
//�continue...
Unsafe ATS application on API #6Unsafe ATS application on API #6Unsafe ATS application on API #6Unsafe ATS application on API #6Unsafe ATS application on API #6
implement�main0�()�=�{
��val�(pffp�│�fp)�=�my_fopen("main.dats",�"r")
��val�()�=�readshow(pffp�│�fp)
��val�r�=�my_fclose(pffp�│�fp)
}
implement�main0�()�=�{
��val�(pffp�│�fp)�=�my_fopen("main.dats",�"r")
��val�()�=�readshow(pffp�│�fp)
��val�r�=�my_fclose(pffp�│�fp)
}
implement�main0�()�=�{
��val�(pffp�│�fp)�=�my_fopen("main.dats",�"r")
��val�()�=�readshow(pffp�│�fp)
��val�r�=�my_fclose(pffp�│�fp)
}
implement�main0�()�=�{
��val�(pffp�│�fp)�=�my_fopen("main.dats",�"r")
��val�()�=�readshow(pffp�│�fp)
��val�r�=�my_fclose(pffp�│�fp)
}
implement�main0�()�=�{
val�(pffp�│�fp)�=�my_fopen("main.dats",�"r")
val�()�=�readshow(pffp�│�fp)
val�r�=�my_fclose(pffp�│�fp)
}
Manually introduce linear type #1Manually introduce linear type #1Manually introduce linear type #1Manually introduce linear type #1Manually introduce linear type #1
☆ Generated ATS interfaces are:☆ Generated ATS interfaces are:☆ Generated ATS interfaces are:☆ Generated ATS interfaces are:☆ Generated ATS interfaces are:
$�cat�example.h
#include�<stdio.h>
$�c2ats�gen�example.h�>�example.sats
$�cat�example.sats
$�cat�example.h
#include�<stdio.h>
$�c2ats�gen�example.h�>�example.sats
$�cat�example.sats
$�cat�example.h
#include�<stdio.h>
$�c2ats�gen�example.h�>�example.sats
$�cat�example.sats
$�cat�example.h
#include�<stdio.h>
$�c2ats�gen�example.h�>�example.sats
$�cat�example.sats
$�cat�example.h
#include�<stdio.h>
$�c2ats�gen�example.h�>�example.sats
$�cat�example.sats
//�--snip--
fun�fun_c2ats_fclose:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1)�->�
int�=�"mac#fclose"
fun�fun_c2ats_fopen:�{l1,l2:addr}�(!ptr_v_1(char,�l1),�!ptr_v_1(char,�l2)�│�
ptr�l1,�ptr�l2)�->�[l3:addr]�(ptr_v_1(type_c2ats_FILE,�l3)�│�ptr�l3)�=�
"mac#fopen"
fun�fun_c2ats_fread:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,�
type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=�
"mac#fread"
//�--snip--
fun�fun_c2ats_fclose:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1)�->�
int�=�"mac#fclose"
fun�fun_c2ats_fopen:�{l1,l2:addr}�(!ptr_v_1(char,�l1),�!ptr_v_1(char,�l2)�│�
ptr�l1,�ptr�l2)�->�[l3:addr]�(ptr_v_1(type_c2ats_FILE,�l3)�│�ptr�l3)�=�
"mac#fopen"
fun�fun_c2ats_fread:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,�
type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=�
"mac#fread"
//�--snip--
fun�fun_c2ats_fclose:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1)�->�
int�=�"mac#fclose"
fun�fun_c2ats_fopen:�{l1,l2:addr}�(!ptr_v_1(char,�l1),�!ptr_v_1(char,�l2)�│�
ptr�l1,�ptr�l2)�->�[l3:addr]�(ptr_v_1(type_c2ats_FILE,�l3)�│�ptr�l3)�=�
"mac#fopen"
fun�fun_c2ats_fread:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,�
type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=�
"mac#fread"
//�--snip--
fun�fun_c2ats_fclose:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1)�->�
int�=�"mac#fclose"
fun�fun_c2ats_fopen:�{l1,l2:addr}�(!ptr_v_1(char,�l1),�!ptr_v_1(char,�l2)�│�
ptr�l1,�ptr�l2)�->�[l3:addr]�(ptr_v_1(type_c2ats_FILE,�l3)�│�ptr�l3)�=�
"mac#fopen"
fun�fun_c2ats_fread:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,�
type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=�
"mac#fread"
//�--snip--
fun�fun_c2ats_fclose:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1)�->�
int�=�"mac#fclose"
fun�fun_c2ats_fopen:�{l1,l2:addr}�(!ptr_v_1(char,�l1),�!ptr_v_1(char,�l2)�│�
ptr�l1,�ptr�l2)�->�[l3:addr]�(ptr_v_1(type_c2ats_FILE,�l3)�│�ptr�l3)�=�
"mac#fopen"
fun�fun_c2ats_fread:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,�
type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=�
"mac#fread"
Manually introduce linear type #2Manually introduce linear type #2Manually introduce linear type #2Manually introduce linear type #2Manually introduce linear type #2
☆ If you modify the interfaces with safe manner:☆ If you modify the interfaces with safe manner:☆ If you modify the interfaces with safe manner:☆ If you modify the interfaces with safe manner:☆ If you modify the interfaces with safe manner:
$�cp�example.sats�example_welltyped.sats
$�vi�example_welltyped.sats
$�cp�example.sats�example_welltyped.sats
$�vi�example_welltyped.sats
$�cp�example.sats�example_welltyped.sats
$�vi�example_welltyped.sats
$�cp�example.sats�example_welltyped.sats
$�vi�example_welltyped.sats
$�cp�example.sats�example_welltyped.sats
$�vi�example_welltyped.sats
//�--snip--
fun�fun_c2ats_fclose:�{l1:agz}�(ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1)�->�
int�=�"mac#fclose"
fun�fun_c2ats_fopen:�(string,�string)�->�[l3:addr]�(ptr_v_1(type_c2ats_FILE,�
l3)�│�ptr�l3)�=�"mac#fopen"
fun�fun_c2ats_fread:�{l1:agz}{n,m:nat}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�!
strnptr(n*m)>>strnptr(o),�size_t(n),�size_t(m),�ptr�l1)�->�#[o:nat�│�o�<=�
n*m]�size_t(o)�=�"mac#fread"
//�--snip--
fun�fun_c2ats_fclose:�{l1:agz}�(ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1)�->�
int�=�"mac#fclose"
fun�fun_c2ats_fopen:�(string,�string)�->�[l3:addr]�(ptr_v_1(type_c2ats_FILE,�
l3)�│�ptr�l3)�=�"mac#fopen"
fun�fun_c2ats_fread:�{l1:agz}{n,m:nat}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�!
strnptr(n*m)>>strnptr(o),�size_t(n),�size_t(m),�ptr�l1)�->�#[o:nat�│�o�<=�
n*m]�size_t(o)�=�"mac#fread"
//�--snip--
fun�fun_c2ats_fclose:�{l1:agz}�(ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1)�->�
int�=�"mac#fclose"
fun�fun_c2ats_fopen:�(string,�string)�->�[l3:addr]�(ptr_v_1(type_c2ats_FILE,�
l3)�│�ptr�l3)�=�"mac#fopen"
fun�fun_c2ats_fread:�{l1:agz}{n,m:nat}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�!
strnptr(n*m)>>strnptr(o),�size_t(n),�size_t(m),�ptr�l1)�->�#[o:nat�│�o�<=�
n*m]�size_t(o)�=�"mac#fread"
//�--snip--
fun�fun_c2ats_fclose:�{l1:agz}�(ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1)�->�
int�=�"mac#fclose"
fun�fun_c2ats_fopen:�(string,�string)�->�[l3:addr]�(ptr_v_1(type_c2ats_FILE,�
l3)�│�ptr�l3)�=�"mac#fopen"
fun�fun_c2ats_fread:�{l1:agz}{n,m:nat}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�!
strnptr(n*m)>>strnptr(o),�size_t(n),�size_t(m),�ptr�l1)�->�#[o:nat�│�o�<=�
n*m]�size_t(o)�=�"mac#fread"
//�--snip--
fun�fun_c2ats_fclose:�{l1:agz}�(ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1)�->�
int�=�"mac#fclose"
fun�fun_c2ats_fopen:�(string,�string)�->�[l3:addr]�(ptr_v_1(type_c2ats_FILE,�
l3)�│�ptr�l3)�=�"mac#fopen"
fun�fun_c2ats_fread:�{l1:agz}{n,m:nat}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�!
strnptr(n*m)>>strnptr(o),�size_t(n),�size_t(m),�ptr�l1)�->�#[o:nat�│�o�<=�
n*m]�size_t(o)�=�"mac#fread"
Manually introduce linear type #3Manually introduce linear type #3Manually introduce linear type #3Manually introduce linear type #3Manually introduce linear type #3
☆ you can rite safe application:☆ you can rite safe application:☆ you can rite safe application:☆ you can rite safe application:☆ you can rite safe application:
$�vi�main.dats$�vi�main.dats$�vi�main.dats$�vi�main.dats$�vi�main.dats
#include�"share/atspre_define.hats"
#include�"share/atspre_staload.hats"
staload�STRING�=�"libats/libc/SATS/string.sats"
staload�"example_welltyped.sats"
fun�my_fopen�(file:�string,�mode:�string):
����[l:agz]�(type_c2ats_FILE@l�│�ptr(l))�=�ret�where�{
��val�(pffp�│�fp)�=�fun_c2ats_fopen(file,�mode)
��val�()�=�assertloc(fp�>�0)
��val�ret�=�(pffp�│�fp)
}
//�continue...
#include�"share/atspre_define.hats"
#include�"share/atspre_staload.hats"
staload�STRING�=�"libats/libc/SATS/string.sats"
staload�"example_welltyped.sats"
fun�my_fopen�(file:�string,�mode:�string):
����[l:agz]�(type_c2ats_FILE@l�│�ptr(l))�=�ret�where�{
��val�(pffp�│�fp)�=�fun_c2ats_fopen(file,�mode)
��val�()�=�assertloc(fp�>�0)
��val�ret�=�(pffp�│�fp)
}
//�continue...
#include�"share/atspre_define.hats"
#include�"share/atspre_staload.hats"
staload�STRING�=�"libats/libc/SATS/string.sats"
staload�"example_welltyped.sats"
fun�my_fopen�(file:�string,�mode:�string):
����[l:agz]�(type_c2ats_FILE@l�│�ptr(l))�=�ret�where�{
��val�(pffp�│�fp)�=�fun_c2ats_fopen(file,�mode)
��val�()�=�assertloc(fp�>�0)
��val�ret�=�(pffp�│�fp)
}
//�continue...
#include�"share/atspre_define.hats"
#include�"share/atspre_staload.hats"
staload�STRING�=�"libats/libc/SATS/string.sats"
staload�"example_welltyped.sats"
fun�my_fopen�(file:�string,�mode:�string):
����[l:agz]�(type_c2ats_FILE@l�│�ptr(l))�=�ret�where�{
��val�(pffp�│�fp)�=�fun_c2ats_fopen(file,�mode)
��val�()�=�assertloc(fp�>�0)
��val�ret�=�(pffp�│�fp)
}
//�continue...
#include�"share/atspre_define.hats"
#include�"share/atspre_staload.hats"
staload�STRING�=�"libats/libc/SATS/string.sats"
staload�"example_welltyped.sats"
fun�my_fopen�(file:�string,�mode:�string):
[l:agz]�(type_c2ats_FILE@l�│�ptr(l))�=�ret�where�{
val�(pffp�│�fp)�=�fun_c2ats_fopen(file,�mode)
val�()�=�assertloc(fp�>�0)
val�ret�=�(pffp�│�fp)
}
//�continue...
Manually introduce linear type #4Manually introduce linear type #4Manually introduce linear type #4Manually introduce linear type #4Manually introduce linear type #4
fun�my_fread�{l:agz}{n:nat}
����(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l),�len:�size_t(n)):
����[m:nat�│�m�<=�n]�(size_t(m),�strnptr(m))�=�ret�where�{
��implement{}�string_tabulate$fopr(s)�=�'_'
��val�buf_strnptr�=�string_tabulate(len)
��val�buf_ptr�=�strnptr2ptr(buf_strnptr)
��val�_�=�$STRING.memset_unsafe(buf_ptr,�0,�len)
��val�r�=�fun_c2ats_fread(pffp�│�buf_strnptr,�i2sz(1),�len,�fp)
��val�ret�=�(r,�buf_strnptr)
}
//�continue...
fun�my_fread�{l:agz}{n:nat}
����(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l),�len:�size_t(n)):
����[m:nat�│�m�<=�n]�(size_t(m),�strnptr(m))�=�ret�where�{
��implement{}�string_tabulate$fopr(s)�=�'_'
��val�buf_strnptr�=�string_tabulate(len)
��val�buf_ptr�=�strnptr2ptr(buf_strnptr)
��val�_�=�$STRING.memset_unsafe(buf_ptr,�0,�len)
��val�r�=�fun_c2ats_fread(pffp�│�buf_strnptr,�i2sz(1),�len,�fp)
��val�ret�=�(r,�buf_strnptr)
}
//�continue...
fun�my_fread�{l:agz}{n:nat}
����(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l),�len:�size_t(n)):
����[m:nat�│�m�<=�n]�(size_t(m),�strnptr(m))�=�ret�where�{
��implement{}�string_tabulate$fopr(s)�=�'_'
��val�buf_strnptr�=�string_tabulate(len)
��val�buf_ptr�=�strnptr2ptr(buf_strnptr)
��val�_�=�$STRING.memset_unsafe(buf_ptr,�0,�len)
��val�r�=�fun_c2ats_fread(pffp�│�buf_strnptr,�i2sz(1),�len,�fp)
��val�ret�=�(r,�buf_strnptr)
}
//�continue...
fun�my_fread�{l:agz}{n:nat}
����(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l),�len:�size_t(n)):
����[m:nat�│�m�<=�n]�(size_t(m),�strnptr(m))�=�ret�where�{
��implement{}�string_tabulate$fopr(s)�=�'_'
��val�buf_strnptr�=�string_tabulate(len)
��val�buf_ptr�=�strnptr2ptr(buf_strnptr)
��val�_�=�$STRING.memset_unsafe(buf_ptr,�0,�len)
��val�r�=�fun_c2ats_fread(pffp�│�buf_strnptr,�i2sz(1),�len,�fp)
��val�ret�=�(r,�buf_strnptr)
}
//�continue...
fun�my_fread�{l:agz}{n:nat}
����(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l),�len:�size_t(n)):
[m:nat�│�m�<=�n]�(size_t(m),�strnptr(m))�=�ret�where�{
implement{}�string_tabulate$fopr(s)�=�'_'
val�buf_strnptr�=�string_tabulate(len)
val�buf_ptr�=�strnptr2ptr(buf_strnptr)
val�_�=�$STRING.memset_unsafe(buf_ptr,�0,�len)
val�r�=�fun_c2ats_fread(pffp�│�buf_strnptr,�i2sz(1),�len,�fp)
val�ret�=�(r,�buf_strnptr)
}
//�continue...
Manually introduce linear type #5Manually introduce linear type #5Manually introduce linear type #5Manually introduce linear type #5Manually introduce linear type #5
fun�readshow�{l:agz}�(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l)):�void�=�{
��val�(r,�str)�=�my_fread(pffp�│�fp,�i2sz(128))
��val�str�=�strnptr2strptr(str)
��val�()�=�print(str)
��val�()�=�free(str)
��val�()�=�if�r�>�0�then�readshow(pffp�│�fp)
}
implement�main0�()�=�{
��val�(pffp�│�fp)�=�my_fopen("main.dats",�"r")
��val�()�=�readshow(pffp�│�fp)
��val�r�=�fun_c2ats_fclose(pffp�│�fp)
}
fun�readshow�{l:agz}�(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l)):�void�=�{
��val�(r,�str)�=�my_fread(pffp�│�fp,�i2sz(128))
��val�str�=�strnptr2strptr(str)
��val�()�=�print(str)
��val�()�=�free(str)
��val�()�=�if�r�>�0�then�readshow(pffp�│�fp)
}
implement�main0�()�=�{
��val�(pffp�│�fp)�=�my_fopen("main.dats",�"r")
��val�()�=�readshow(pffp�│�fp)
��val�r�=�fun_c2ats_fclose(pffp�│�fp)
}
fun�readshow�{l:agz}�(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l)):�void�=�{
��val�(r,�str)�=�my_fread(pffp�│�fp,�i2sz(128))
��val�str�=�strnptr2strptr(str)
��val�()�=�print(str)
��val�()�=�free(str)
��val�()�=�if�r�>�0�then�readshow(pffp�│�fp)
}
implement�main0�()�=�{
��val�(pffp�│�fp)�=�my_fopen("main.dats",�"r")
��val�()�=�readshow(pffp�│�fp)
��val�r�=�fun_c2ats_fclose(pffp�│�fp)
}
fun�readshow�{l:agz}�(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l)):�void�=�{
��val�(r,�str)�=�my_fread(pffp�│�fp,�i2sz(128))
��val�str�=�strnptr2strptr(str)
��val�()�=�print(str)
��val�()�=�free(str)
��val�()�=�if�r�>�0�then�readshow(pffp�│�fp)
}
implement�main0�()�=�{
��val�(pffp�│�fp)�=�my_fopen("main.dats",�"r")
��val�()�=�readshow(pffp�│�fp)
��val�r�=�fun_c2ats_fclose(pffp�│�fp)
}
fun�readshow�{l:agz}�(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l)):�void�=�{
val�(r,�str)�=�my_fread(pffp�│�fp,�i2sz(128))
val�str�=�strnptr2strptr(str)
val�()�=�print(str)
val�()�=�free(str)
val�()�=�if�r�>�0 then�readshow(pffp�│�fp)
}
implement�main0�()�=�{
val�(pffp�│�fp)�=�my_fopen("main.dats",�"r")
val�()�=�readshow(pffp�│�fp)
val�r�=�fun_c2ats_fclose(pffp�│�fp)
}
Future planFuture planFuture planFuture planFuture plan
☆ Hongwei, who is author of ATS, said:☆ Hongwei, who is author of ATS, said:☆ Hongwei, who is author of ATS, said:☆ Hongwei, who is author of ATS, said:☆ Hongwei, who is author of ATS, said:
"Once�you�become�familiar�with�ATS,�you�can�readily�visualize�the�C�code�
that�your�ATS�source�is�to�be�compiled�into."
"Once�you�become�familiar�with�ATS,�you�can�readily�visualize�the�C�code�
that�your�ATS�source�is�to�be�compiled�into."
"Once�you�become�familiar�with�ATS,�you�can�readily�visualize�the�C�code�
that�your�ATS�source�is�to�be�compiled�into."
"Once�you�become�familiar�with�ATS,�you�can�readily�visualize�the�C�code�
that�your�ATS�source�is�to�be�compiled�into."
"Once�you�become�familiar�with�ATS,�you�can�readily�visualize�the�C�code�
that�your�ATS�source�is�to�be�compiled�into."
☆ So, we can create decompiler for ATS language?☆ So, we can create decompiler for ATS language?☆ So, we can create decompiler for ATS language?☆ So, we can create decompiler for ATS language?☆ So, we can create decompiler for ATS language?
ConclusionConclusionConclusionConclusionConclusion
☆ ATS code is more safe than C code.☆ ATS code is more safe than C code.☆ ATS code is more safe than C code.☆ ATS code is more safe than C code.☆ ATS code is more safe than C code.
☆ The c2ats generates ATS interface from C header.☆ The c2ats generates ATS interface from C header.☆ The c2ats generates ATS interface from C header.☆ The c2ats generates ATS interface from C header.☆ The c2ats generates ATS interface from C header.
☆ Unsafe ATS application can run on the interface.☆ Unsafe ATS application can run on the interface.☆ Unsafe ATS application can run on the interface.☆ Unsafe ATS application can run on the interface.☆ Unsafe ATS application can run on the interface.
☆ Make safety of the application with introducing
linear type manually.
☆ Make safety of the application with introducing
linear type manually.
☆ Make safety of the application with introducing
linear type manually.
☆ Make safety of the application with introducing
linear type manually.
☆ Make safety of the application with introducing
linear type manually.

More Related Content

Similar to Poster: Generate ATS interface from C code, and introduce linear type

Functional IoT: Programming Language and OS
Functional IoT: Programming Language and OSFunctional IoT: Programming Language and OS
Functional IoT: Programming Language and OS
Kiwamu Okabe
 
Ajhc Haskell Compiler with Reentrant GC
Ajhc Haskell Compiler with Reentrant GCAjhc Haskell Compiler with Reentrant GC
Ajhc Haskell Compiler with Reentrant GC
Kiwamu Okabe
 
Metasepi team meeting #14: ATS programming on MCU
Metasepi team meeting #14: ATS programming on MCUMetasepi team meeting #14: ATS programming on MCU
Metasepi team meeting #14: ATS programming on MCU
Kiwamu Okabe
 
Poster: Comparing ATS and VeriFast on RTOS system state
Poster: Comparing ATS and VeriFast on RTOS system statePoster: Comparing ATS and VeriFast on RTOS system state
Poster: Comparing ATS and VeriFast on RTOS system state
Kiwamu Okabe
 
ATS Programming Tutorial
ATS Programming TutorialATS Programming Tutorial
ATS Programming Tutorial
Kiwamu Okabe
 
Real-time OS system state captured by ATS language
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 Okabe
 
Metasepi team meeting #16: Safety on ATS language + MCU
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 Okabe
 
Functional IoT: Introduction
Functional IoT: IntroductionFunctional IoT: Introduction
Functional IoT: Introduction
Kiwamu Okabe
 
Does Infer dream of design by contract?
Does Infer dream of design by contract?Does Infer dream of design by contract?
Does Infer dream of design by contract?
Kiwamu Okabe
 
Past and today of Metasepi project
Past and today of Metasepi projectPast and today of Metasepi project
Past and today of Metasepi project
Kiwamu Okabe
 
TDC 2020 - Implementing a Mini-Language
TDC 2020 - Implementing a Mini-LanguageTDC 2020 - Implementing a Mini-Language
TDC 2020 - Implementing a Mini-Language
Luciano Sabença
 
ATS programming on ESP8266
ATS programming on ESP8266ATS programming on ESP8266
ATS programming on ESP8266
Kiwamu Okabe
 
ATS/LF for Coq users
ATS/LF for Coq usersATS/LF for Coq users
ATS/LF for Coq users
Kiwamu Okabe
 
Start! ATS programming
Start! ATS programmingStart! ATS programming
Start! ATS programming
Kiwamu Okabe
 
Programming in HTML5 with JavaScript and CSS3
Programming in HTML5 with JavaScript and CSS3Programming in HTML5 with JavaScript and CSS3
Programming in HTML5 with JavaScript and CSS3
Ali Fallahi
 
Types are eating the world
Types are eating the worldTypes are eating the world
Types are eating the world
Fangda Wang
 
Software Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with ScalaSoftware Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with Scala
Brian Topping
 
An OCaml newbie meets Camlp4 parser
An OCaml newbie meets Camlp4 parserAn OCaml newbie meets Camlp4 parser
An OCaml newbie meets Camlp4 parser
Kiwamu Okabe
 
The Perl API for the Mortally Terrified (beta)
The Perl API for the Mortally Terrified (beta)The Perl API for the Mortally Terrified (beta)
The Perl API for the Mortally Terrified (beta)
Mike Friedman
 
Jay Phillips's Presentation at eComm 2009
Jay Phillips's Presentation at eComm 2009Jay Phillips's Presentation at eComm 2009
Jay Phillips's Presentation at eComm 2009
eCommConf
 

Similar to Poster: Generate ATS interface from C code, and introduce linear type (20)

Functional IoT: Programming Language and OS
Functional IoT: Programming Language and OSFunctional IoT: Programming Language and OS
Functional IoT: Programming Language and OS
 
Ajhc Haskell Compiler with Reentrant GC
Ajhc Haskell Compiler with Reentrant GCAjhc Haskell Compiler with Reentrant GC
Ajhc Haskell Compiler with Reentrant GC
 
Metasepi team meeting #14: ATS programming on MCU
Metasepi team meeting #14: ATS programming on MCUMetasepi team meeting #14: ATS programming on MCU
Metasepi team meeting #14: ATS programming on MCU
 
Poster: Comparing ATS and VeriFast on RTOS system state
Poster: Comparing ATS and VeriFast on RTOS system statePoster: Comparing ATS and VeriFast on RTOS system state
Poster: Comparing ATS and VeriFast on RTOS system state
 
ATS Programming Tutorial
ATS Programming TutorialATS Programming Tutorial
ATS Programming Tutorial
 
Real-time OS system state captured by ATS language
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
 
Metasepi team meeting #16: Safety on ATS language + MCU
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
 
Functional IoT: Introduction
Functional IoT: IntroductionFunctional IoT: Introduction
Functional IoT: Introduction
 
Does Infer dream of design by contract?
Does Infer dream of design by contract?Does Infer dream of design by contract?
Does Infer dream of design by contract?
 
Past and today of Metasepi project
Past and today of Metasepi projectPast and today of Metasepi project
Past and today of Metasepi project
 
TDC 2020 - Implementing a Mini-Language
TDC 2020 - Implementing a Mini-LanguageTDC 2020 - Implementing a Mini-Language
TDC 2020 - Implementing a Mini-Language
 
ATS programming on ESP8266
ATS programming on ESP8266ATS programming on ESP8266
ATS programming on ESP8266
 
ATS/LF for Coq users
ATS/LF for Coq usersATS/LF for Coq users
ATS/LF for Coq users
 
Start! ATS programming
Start! ATS programmingStart! ATS programming
Start! ATS programming
 
Programming in HTML5 with JavaScript and CSS3
Programming in HTML5 with JavaScript and CSS3Programming in HTML5 with JavaScript and CSS3
Programming in HTML5 with JavaScript and CSS3
 
Types are eating the world
Types are eating the worldTypes are eating the world
Types are eating the world
 
Software Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with ScalaSoftware Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with Scala
 
An OCaml newbie meets Camlp4 parser
An OCaml newbie meets Camlp4 parserAn OCaml newbie meets Camlp4 parser
An OCaml newbie meets Camlp4 parser
 
The Perl API for the Mortally Terrified (beta)
The Perl API for the Mortally Terrified (beta)The Perl API for the Mortally Terrified (beta)
The Perl API for the Mortally Terrified (beta)
 
Jay Phillips's Presentation at eComm 2009
Jay Phillips's Presentation at eComm 2009Jay Phillips's Presentation at eComm 2009
Jay Phillips's Presentation at eComm 2009
 

Recently uploaded

Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
TIPNGVN2
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 

Recently uploaded (20)

Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 

Poster: Generate ATS interface from C code, and introduce linear type

  • 1. Generate ATS interface from C code, and introduce linear type Generate ATS interface from C code, and introduce linear type Generate ATS interface from C code, and introduce linear type Generate ATS interface from C code, and introduce linear type Generate ATS interface from C code, and introduce linear type Kiwamu Okabe @ RIKEN AICSKiwamu Okabe @ RIKEN AICSKiwamu Okabe @ RIKEN AICSKiwamu Okabe @ RIKEN AICSKiwamu Okabe @ RIKEN AICS
  • 2. Today's low level programmingToday's low level programmingToday's low level programmingToday's low level programmingToday's low level programming ☆ uses C programming language.☆ uses C programming language.☆ uses C programming language.☆ uses C programming language.☆ uses C programming language. ☆ may causes buffer overflow.☆ may causes buffer overflow.☆ may causes buffer overflow.☆ may causes buffer overflow.☆ may causes buffer overflow. ☆ may violate invariant in the code.☆ may violate invariant in the code.☆ may violate invariant in the code.☆ may violate invariant in the code.☆ may violate invariant in the code. ☆ may violate specification of the design.☆ may violate specification of the design.☆ may violate specification of the design.☆ may violate specification of the design.☆ may violate specification of the design. ☆ These errors occur at run-time.☆ These errors occur at run-time.☆ These errors occur at run-time.☆ These errors occur at run-time.☆ These errors occur at run-time.
  • 3. Why need the other language?Why need the other language?Why need the other language?Why need the other language?Why need the other language? ☆ We want to find these errors at compile-time.☆ We want to find these errors at compile-time.☆ We want to find these errors at compile-time.☆ We want to find these errors at compile-time.☆ We want to find these errors at compile-time. ☆ Of course, we can use verification on C language.☆ Of course, we can use verification on C language.☆ Of course, we can use verification on C language.☆ Of course, we can use verification on C language.☆ Of course, we can use verification on C language. ☆ e.g. Coverity, Frama-C, Infer, VeriFast, vcc, etc...☆ e.g. Coverity, Frama-C, Infer, VeriFast, vcc, etc...☆ e.g. Coverity, Frama-C, Infer, VeriFast, vcc, etc...☆ e.g. Coverity, Frama-C, Infer, VeriFast, vcc, etc...☆ e.g. Coverity, Frama-C, Infer, VeriFast, vcc, etc... ☆ But also we want to use more rich type system.☆ But also we want to use more rich type system.☆ But also we want to use more rich type system.☆ But also we want to use more rich type system.☆ But also we want to use more rich type system. ☆ Today is the day to choose the other language for low level programming? ☆ Today is the day to choose the other language for low level programming? ☆ Today is the day to choose the other language for low level programming? ☆ Today is the day to choose the other language for low level programming? ☆ Today is the day to choose the other language for low level programming?
  • 4. ATS languageATS languageATS languageATS languageATS language ☆ http://www.ats-lang.org/☆ http://www.ats-lang.org/☆ http://www.ats-lang.org/☆ http://www.ats-lang.org/☆ http://www.ats-lang.org/ ☆ Syntax like ML☆ Syntax like ML☆ Syntax like ML☆ Syntax like ML☆ Syntax like ML ☆ DML-style dependent types☆ DML-style dependent types☆ DML-style dependent types☆ DML-style dependent types☆ DML-style dependent types ☆ Linear types☆ Linear types☆ Linear types☆ Linear types☆ Linear types ☆ Optional GC, malloc/free, run-time☆ Optional GC, malloc/free, run-time☆ Optional GC, malloc/free, run-time☆ Optional GC, malloc/free, run-time☆ Optional GC, malloc/free, run-time
  • 5. Real of ATS programmingReal of ATS programmingReal of ATS programmingReal of ATS programmingReal of ATS programming But, there is no paradise. Real ATS programming needs many interfaces imported from C. But, there is no paradise. Real ATS programming needs many interfaces imported from C. But, there is no paradise. Real ATS programming needs many interfaces imported from C. But, there is no paradise. Real ATS programming needs many interfaces imported from C. But, there is no paradise. Real ATS programming needs many interfaces imported from C.
  • 6. A tool "c2ats" resolves it!A tool "c2ats" resolves it!A tool "c2ats" resolves it!A tool "c2ats" resolves it!A tool "c2ats" resolves it! ☆ https://github.com/metasepi/c2ats/☆ https://github.com/metasepi/c2ats/☆ https://github.com/metasepi/c2ats/☆ https://github.com/metasepi/c2ats/☆ https://github.com/metasepi/c2ats/ ☆ parse C header and generate ATS interface.☆ parse C header and generate ATS interface.☆ parse C header and generate ATS interface.☆ parse C header and generate ATS interface.☆ parse C header and generate ATS interface. ☆ made by Haskell language.☆ made by Haskell language.☆ made by Haskell language.☆ made by Haskell language.☆ made by Haskell language. ☆ using "language-c" library to parse C code.☆ using "language-c" library to parse C code.☆ using "language-c" library to parse C code.☆ using "language-c" library to parse C code.☆ using "language-c" library to parse C code.
  • 7. We can do using c2ats...We can do using c2ats...We can do using c2ats...We can do using c2ats...We can do using c2ats...
  • 8. Rule: Translating primitive typesRule: Translating primitive typesRule: Translating primitive typesRule: Translating primitive typesRule: Translating primitive types ATS's unboxed type is one-to-one for C's one.ATS's unboxed type is one-to-one for C's one.ATS's unboxed type is one-to-one for C's one.ATS's unboxed type is one-to-one for C's one.ATS's unboxed type is one-to-one for C's one. C�language��������│�ATS�language ------------------+------------------ bool��������������│�bool char��������������│�char signed�char�������│�schar unsigned�char�����│�uchar short�������������│�sint unsigned�short����│�usint int���������������│�int unsigned�int������│�uint long�int����������│�lint unsigned�long�int�│�ulint ...���������������│�... C�language��������│�ATS�language ------------------+------------------ bool��������������│�bool char��������������│�char signed�char�������│�schar unsigned�char�����│�uchar short�������������│�sint unsigned�short����│�usint int���������������│�int unsigned�int������│�uint long�int����������│�lint unsigned�long�int�│�ulint ...���������������│�... C�language��������│�ATS�language ------------------+------------------ bool��������������│�bool char��������������│�char signed�char�������│�schar unsigned�char�����│�uchar short�������������│�sint unsigned�short����│�usint int���������������│�int unsigned�int������│�uint long�int����������│�lint unsigned�long�int�│�ulint ...���������������│�... C�language��������│�ATS�language ------------------+------------------ bool��������������│�bool char��������������│�char signed�char�������│�schar unsigned�char�����│�uchar short�������������│�sint unsigned�short����│�usint int���������������│�int unsigned�int������│�uint long�int����������│�lint unsigned�long�int�│�ulint ...���������������│�... C�language��������│�ATS�language ------------------+------------------ bool��������������│�bool char��������������│�char signed�char�������│�schar unsigned�char�����│�uchar short�������������│�sint unsigned�short����│�usint int���������������│�int unsigned�int������│�uint long�int����������│�lint unsigned�long�int�│�ulint ...���������������│�...
  • 9. Rule: FunctionsRule: FunctionsRule: FunctionsRule: FunctionsRule: Functions ☆ If you have following C function declaration:☆ If you have following C function declaration:☆ If you have following C function declaration:☆ If you have following C function declaration:☆ If you have following C function declaration: int�func_a(int,�char);int�func_a(int,�char);int�func_a(int,�char);int�func_a(int,�char);int�func_a(int,�char); ☆ c2ats generate following ATS interface:☆ c2ats generate following ATS interface:☆ c2ats generate following ATS interface:☆ c2ats generate following ATS interface:☆ c2ats generate following ATS interface: fun�fun_c2ats_func_a:�(int,�char)�->�int�=�"mac#func_a"fun�fun_c2ats_func_a:�(int,�char)�->�int�=�"mac#func_a"fun�fun_c2ats_func_a:�(int,�char)�->�int�=�"mac#func_a"fun�fun_c2ats_func_a:�(int,�char)�->�int�=�"mac#func_a"fun�fun_c2ats_func_a:�(int,�char)�->�int�=�"mac#func_a"
  • 10. Rule: StructRule: StructRule: StructRule: StructRule: Struct //�If�you�have�following�C�structure: struct�t�{ ��int�a; ��struct�{int�b;}�c; }; //�If�you�have�following�C�structure: struct�t�{ ��int�a; ��struct�{int�b;}�c; }; //�If�you�have�following�C�structure: struct�t�{ ��int�a; ��struct�{int�b;}�c; }; //�If�you�have�following�C�structure: struct�t�{ ��int�a; ��struct�{int�b;}�c; }; //�If�you�have�following�C�structure: struct�t�{ int�a; struct�{int�b;}�c; }; //�c2ats�generate�following�ATS�type�definition: typedef�struct_c2ats_anon_10�=�$extype_struct"struct�{�int�b;�}"�of�{ ��b�=�int } typedef�struct_c2ats_t�=�$extype_struct"struct�t"�of�{ ��a�=�int, ��c�=�struct_c2ats_anon_10 } //�c2ats�generate�following�ATS�type�definition: typedef�struct_c2ats_anon_10�=�$extype_struct"struct�{�int�b;�}"�of�{ ��b�=�int } typedef�struct_c2ats_t�=�$extype_struct"struct�t"�of�{ ��a�=�int, ��c�=�struct_c2ats_anon_10 } //�c2ats�generate�following�ATS�type�definition: typedef�struct_c2ats_anon_10�=�$extype_struct"struct�{�int�b;�}"�of�{ ��b�=�int } typedef�struct_c2ats_t�=�$extype_struct"struct�t"�of�{ ��a�=�int, ��c�=�struct_c2ats_anon_10 } //�c2ats�generate�following�ATS�type�definition: typedef�struct_c2ats_anon_10�=�$extype_struct"struct�{�int�b;�}"�of�{ ��b�=�int } typedef�struct_c2ats_t�=�$extype_struct"struct�t"�of�{ ��a�=�int, ��c�=�struct_c2ats_anon_10 } //�c2ats�generate�following�ATS�type�definition: typedef�struct_c2ats_anon_10�=�$extype_struct"struct�{�int�b;�}"�of�{ ��b�=�int } typedef�struct_c2ats_t�=�$extype_struct"struct�t"�of�{ ��a�=�int, ��c�=�struct_c2ats_anon_10 }
  • 11. Rule: Pointers and at-view #1Rule: Pointers and at-view #1Rule: Pointers and at-view #1Rule: Pointers and at-view #1Rule: Pointers and at-view #1 ☆ If you have following C declaration:☆ If you have following C declaration:☆ If you have following C declaration:☆ If you have following C declaration:☆ If you have following C declaration: int�getopt�(int�___argc,�char�**___argv,�char�*__shortopts);int�getopt�(int�___argc,�char�**___argv,�char�*__shortopts);int�getopt�(int�___argc,�char�**___argv,�char�*__shortopts);int�getopt�(int�___argc,�char�**___argv,�char�*__shortopts);int�getopt�(int�___argc,�char�**___argv,�char�*__shortopts); ☆ c2ats generate following ATS definition:☆ c2ats generate following ATS definition:☆ c2ats generate following ATS definition:☆ c2ats generate following ATS definition:☆ c2ats generate following ATS definition: viewdef�ptr_v_1�(a:t@ype,�l:addr)�=�a�@�l dataview�ptr_v_2�(a:t@ype+,�l0:�addr,�l1:�addr)�= ��│�ptr_v_2_cons(a,�l0,�l1)�of�(ptr�l1�@�l0,�ptr_v_1�(a,�l1)) fun�fun_c2ats_getopt:�{l1,l1_1,l2:addr}�(!ptr_v_2(char,�l1,�l1_1),�!ptr_v_1 (char,�l2)�│�int,�ptr�l1,�ptr�l2)�->�int�=�"mac#getopt" viewdef�ptr_v_1�(a:t@ype,�l:addr)�=�a�@�l dataview�ptr_v_2�(a:t@ype+,�l0:�addr,�l1:�addr)�= ��│�ptr_v_2_cons(a,�l0,�l1)�of�(ptr�l1�@�l0,�ptr_v_1�(a,�l1)) fun�fun_c2ats_getopt:�{l1,l1_1,l2:addr}�(!ptr_v_2(char,�l1,�l1_1),�!ptr_v_1 (char,�l2)�│�int,�ptr�l1,�ptr�l2)�->�int�=�"mac#getopt" viewdef�ptr_v_1�(a:t@ype,�l:addr)�=�a�@�l dataview�ptr_v_2�(a:t@ype+,�l0:�addr,�l1:�addr)�= ��│�ptr_v_2_cons(a,�l0,�l1)�of�(ptr�l1�@�l0,�ptr_v_1�(a,�l1)) fun�fun_c2ats_getopt:�{l1,l1_1,l2:addr}�(!ptr_v_2(char,�l1,�l1_1),�!ptr_v_1 (char,�l2)�│�int,�ptr�l1,�ptr�l2)�->�int�=�"mac#getopt" viewdef�ptr_v_1�(a:t@ype,�l:addr)�=�a�@�l dataview�ptr_v_2�(a:t@ype+,�l0:�addr,�l1:�addr)�= ��│�ptr_v_2_cons(a,�l0,�l1)�of�(ptr�l1�@�l0,�ptr_v_1�(a,�l1)) fun�fun_c2ats_getopt:�{l1,l1_1,l2:addr}�(!ptr_v_2(char,�l1,�l1_1),�!ptr_v_1 (char,�l2)�│�int,�ptr�l1,�ptr�l2)�->�int�=�"mac#getopt" viewdef�ptr_v_1�(a:t@ype,�l:addr)�=�a�@�l dataview�ptr_v_2�(a:t@ype+,�l0:�addr,�l1:�addr)�= ��│�ptr_v_2_cons(a,�l0,�l1)�of�(ptr�l1�@�l0,�ptr_v_1�(a,�l1)) fun�fun_c2ats_getopt:�{l1,l1_1,l2:addr}�(!ptr_v_2(char,�l1,�l1_1),�!ptr_v_1 (char,�l2)�│�int,�ptr�l1,�ptr�l2)�->�int�=�"mac#getopt"
  • 12. Rule: Pointers and at-view #2Rule: Pointers and at-view #2Rule: Pointers and at-view #2Rule: Pointers and at-view #2Rule: Pointers and at-view #2 You can dereference pointer "ptr l1", "ptr l1_1", "ptr l2" because they has own at-view. You can dereference pointer "ptr l1", "ptr l1_1", "ptr l2" because they has own at-view. You can dereference pointer "ptr l1", "ptr l1_1", "ptr l2" because they has own at-view. You can dereference pointer "ptr l1", "ptr l1_1", "ptr l2" because they has own at-view. You can dereference pointer "ptr l1", "ptr l1_1", "ptr l2" because they has own at-view.
  • 13. Rule: Accessor for global variables #1Rule: Accessor for global variables #1Rule: Accessor for global variables #1Rule: Accessor for global variables #1Rule: Accessor for global variables #1 //�If�you�have�following�C�declaration: struct�foo�{int�i;�char�*s;}; extern�struct�foo�g_foo; //�If�you�have�following�C�declaration: struct�foo�{int�i;�char�*s;}; extern�struct�foo�g_foo; //�If�you�have�following�C�declaration: struct�foo�{int�i;�char�*s;}; extern�struct�foo�g_foo; //�If�you�have�following�C�declaration: struct�foo�{int�i;�char�*s;}; extern�struct�foo�g_foo; //�If�you�have�following�C�declaration: struct�foo�{int�i;�char�*s;}; extern struct�foo�g_foo; //�c2ats�generate�following�ATS�definition: typedef�struct_c2ats_foo�=�$extype_struct"struct�foo"�of�{ ��i�=�int, ��s�=�ptr�(*�cPtr0(char)�*) } macdef�takeout_c2ats_g_foo�=�$extval([l1:addr]�(ptr_v_1(struct_c2ats_foo,� l1)�│�ptr�l1),�"&g_foo") praxi�addback_c2ats_g_foo�{l1:addr}�(ptr_v_1(struct_c2ats_foo,�l1)�│�ptr� l1):�void //�c2ats�generate�following�ATS�definition: typedef�struct_c2ats_foo�=�$extype_struct"struct�foo"�of�{ ��i�=�int, ��s�=�ptr�(*�cPtr0(char)�*) } macdef�takeout_c2ats_g_foo�=�$extval([l1:addr]�(ptr_v_1(struct_c2ats_foo,� l1)�│�ptr�l1),�"&g_foo") praxi�addback_c2ats_g_foo�{l1:addr}�(ptr_v_1(struct_c2ats_foo,�l1)�│�ptr� l1):�void //�c2ats�generate�following�ATS�definition: typedef�struct_c2ats_foo�=�$extype_struct"struct�foo"�of�{ ��i�=�int, ��s�=�ptr�(*�cPtr0(char)�*) } macdef�takeout_c2ats_g_foo�=�$extval([l1:addr]�(ptr_v_1(struct_c2ats_foo,� l1)�│�ptr�l1),�"&g_foo") praxi�addback_c2ats_g_foo�{l1:addr}�(ptr_v_1(struct_c2ats_foo,�l1)�│�ptr� l1):�void //�c2ats�generate�following�ATS�definition: typedef�struct_c2ats_foo�=�$extype_struct"struct�foo"�of�{ ��i�=�int, ��s�=�ptr�(*�cPtr0(char)�*) } macdef�takeout_c2ats_g_foo�=�$extval([l1:addr]�(ptr_v_1(struct_c2ats_foo,� l1)�│�ptr�l1),�"&g_foo") praxi�addback_c2ats_g_foo�{l1:addr}�(ptr_v_1(struct_c2ats_foo,�l1)�│�ptr� l1):�void //�c2ats�generate�following�ATS�definition: typedef�struct_c2ats_foo�=�$extype_struct"struct�foo"�of�{ ��i�=�int, ��s�=�ptr�(*�cPtr0(char)�*) } macdef�takeout_c2ats_g_foo�=�$extval([l1:addr]�(ptr_v_1(struct_c2ats_foo,� l1)�│�ptr�l1),�"&g_foo") praxi�addback_c2ats_g_foo�{l1:addr}�(ptr_v_1(struct_c2ats_foo,�l1)�│�ptr� l1):�void
  • 14. Rule: Accessor for global variables #2Rule: Accessor for global variables #2Rule: Accessor for global variables #2Rule: Accessor for global variables #2Rule: Accessor for global variables #2 //�You�can�write�following�code�with�the�definition: staload�"example.sats" implement�main0�()�=�{ ��//�g_foo ��val�(pfg_foo�│�g_foo)�=�takeout_c2ats_g_foo ��val�i�=�g_foo->i ��val�s�=�$UN.cast{string}(g_foo->s) ��val�()�=�println!�("g_foo�=�{",�i,�",�"",�s,�""}") ��val�()�=�assertloc�(i�=�1234) ��val�()�=�assertloc�(strcmp�("Hello,�world!",�s)�=�0) ��prval�()�=�addback_c2ats_g_foo�(pfg_foo�│�g_foo) } //�You�can�write�following�code�with�the�definition: staload�"example.sats" implement�main0�()�=�{ ��//�g_foo ��val�(pfg_foo�│�g_foo)�=�takeout_c2ats_g_foo ��val�i�=�g_foo->i ��val�s�=�$UN.cast{string}(g_foo->s) ��val�()�=�println!�("g_foo�=�{",�i,�",�"",�s,�""}") ��val�()�=�assertloc�(i�=�1234) ��val�()�=�assertloc�(strcmp�("Hello,�world!",�s)�=�0) ��prval�()�=�addback_c2ats_g_foo�(pfg_foo�│�g_foo) } //�You�can�write�following�code�with�the�definition: staload�"example.sats" implement�main0�()�=�{ ��//�g_foo ��val�(pfg_foo�│�g_foo)�=�takeout_c2ats_g_foo ��val�i�=�g_foo->i ��val�s�=�$UN.cast{string}(g_foo->s) ��val�()�=�println!�("g_foo�=�{",�i,�",�"",�s,�""}") ��val�()�=�assertloc�(i�=�1234) ��val�()�=�assertloc�(strcmp�("Hello,�world!",�s)�=�0) ��prval�()�=�addback_c2ats_g_foo�(pfg_foo�│�g_foo) } //�You�can�write�following�code�with�the�definition: staload�"example.sats" implement�main0�()�=�{ ��//�g_foo ��val�(pfg_foo�│�g_foo)�=�takeout_c2ats_g_foo ��val�i�=�g_foo->i ��val�s�=�$UN.cast{string}(g_foo->s) ��val�()�=�println!�("g_foo�=�{",�i,�",�"",�s,�""}") ��val�()�=�assertloc�(i�=�1234) ��val�()�=�assertloc�(strcmp�("Hello,�world!",�s)�=�0) ��prval�()�=�addback_c2ats_g_foo�(pfg_foo�│�g_foo) } //�You�can�write�following�code�with�the�definition: staload�"example.sats" implement�main0�()�=�{ //�g_foo val�(pfg_foo�│�g_foo)�=�takeout_c2ats_g_foo val�i�=�g_foo->i val�s�=�$UN.cast{string}(g_foo->s) val�()�=�println!�("g_foo�=�{",�i,�",�"",�s,�""}") val�()�=�assertloc�(i�=�1234) val�()�=�assertloc�(strcmp�("Hello,�world!",�s)�=�0) prval�()�=�addback_c2ats_g_foo�(pfg_foo�│�g_foo) }
  • 15. Unsafe ATS application on API #1Unsafe ATS application on API #1Unsafe ATS application on API #1Unsafe ATS application on API #1Unsafe ATS application on API #1 ☆ First, generate ATS interfaces from C header:☆ First, generate ATS interfaces from C header:☆ First, generate ATS interfaces from C header:☆ First, generate ATS interfaces from C header:☆ First, generate ATS interfaces from C header: $�cat�example.h #include�<stdio.h> $�c2ats�gen�example.h�>�example.sats $�cat�example.sats $�cat�example.h #include�<stdio.h> $�c2ats�gen�example.h�>�example.sats $�cat�example.sats $�cat�example.h #include�<stdio.h> $�c2ats�gen�example.h�>�example.sats $�cat�example.sats $�cat�example.h #include�<stdio.h> $�c2ats�gen�example.h�>�example.sats $�cat�example.sats $�cat�example.h #include�<stdio.h> $�c2ats�gen�example.h�>�example.sats $�cat�example.sats //--snip-- fun�fun_c2ats_fread:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,� type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=� "mac#fread" fun�fun_c2ats_fwrite:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,� type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=� "mac#fwrite" fun�fun_c2ats_fseek:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1,� lint,�int)�->�int�=�"mac#fseek" //--snip-- fun�fun_c2ats_fread:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,� type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=� "mac#fread" fun�fun_c2ats_fwrite:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,� type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=� "mac#fwrite" fun�fun_c2ats_fseek:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1,� lint,�int)�->�int�=�"mac#fseek" //--snip-- fun�fun_c2ats_fread:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,� type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=� "mac#fread" fun�fun_c2ats_fwrite:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,� type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=� "mac#fwrite" fun�fun_c2ats_fseek:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1,� lint,�int)�->�int�=�"mac#fseek" //--snip-- fun�fun_c2ats_fread:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,� type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=� "mac#fread" fun�fun_c2ats_fwrite:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,� type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=� "mac#fwrite" fun�fun_c2ats_fseek:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1,� lint,�int)�->�int�=�"mac#fseek" //--snip-- fun�fun_c2ats_fread:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,� type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=� "mac#fread" fun�fun_c2ats_fwrite:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,� type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=� "mac#fwrite" fun�fun_c2ats_fseek:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1,� lint,�int)�->�int�=�"mac#fseek"
  • 16. Unsafe ATS application on API #2Unsafe ATS application on API #2Unsafe ATS application on API #2Unsafe ATS application on API #2Unsafe ATS application on API #2 ☆ Next, write ATS code with unsafe manner:☆ Next, write ATS code with unsafe manner:☆ Next, write ATS code with unsafe manner:☆ Next, write ATS code with unsafe manner:☆ Next, write ATS code with unsafe manner: $�vi�main.dats$�vi�main.dats$�vi�main.dats$�vi�main.dats$�vi�main.dats #include�"share/atspre_define.hats" #include�"share/atspre_staload.hats" staload�UN�=�"prelude/SATS/unsafe.sats"�//�Unsafe! staload�STRING�=�"libats/libc/SATS/string.sats" staload�"example.sats" extern�praxi�__create_view�{to:view}�():<prf>�to�//�Unsafe! extern�praxi�__consume_view�{from:view}�(pf:�from):<prf>�void�//�Unsafe! //�continue... #include�"share/atspre_define.hats" #include�"share/atspre_staload.hats" staload�UN�=�"prelude/SATS/unsafe.sats"�//�Unsafe! staload�STRING�=�"libats/libc/SATS/string.sats" staload�"example.sats" extern�praxi�__create_view�{to:view}�():<prf>�to�//�Unsafe! extern�praxi�__consume_view�{from:view}�(pf:�from):<prf>�void�//�Unsafe! //�continue... #include�"share/atspre_define.hats" #include�"share/atspre_staload.hats" staload�UN�=�"prelude/SATS/unsafe.sats"�//�Unsafe! staload�STRING�=�"libats/libc/SATS/string.sats" staload�"example.sats" extern�praxi�__create_view�{to:view}�():<prf>�to�//�Unsafe! extern�praxi�__consume_view�{from:view}�(pf:�from):<prf>�void�//�Unsafe! //�continue... #include�"share/atspre_define.hats" #include�"share/atspre_staload.hats" staload�UN�=�"prelude/SATS/unsafe.sats"�//�Unsafe! staload�STRING�=�"libats/libc/SATS/string.sats" staload�"example.sats" extern�praxi�__create_view�{to:view}�():<prf>�to�//�Unsafe! extern�praxi�__consume_view�{from:view}�(pf:�from):<prf>�void�//�Unsafe! //�continue... #include�"share/atspre_define.hats" #include�"share/atspre_staload.hats" staload�UN�=�"prelude/SATS/unsafe.sats"�//�Unsafe! staload�STRING�=�"libats/libc/SATS/string.sats" staload�"example.sats" extern praxi�__create_view�{to:view}�():<prf>�to�//�Unsafe! extern praxi�__consume_view�{from:view}�(pf:�from):<prf>�void�//�Unsafe! //�continue...
  • 17. Unsafe ATS application on API #3Unsafe ATS application on API #3Unsafe ATS application on API #3Unsafe ATS application on API #3Unsafe ATS application on API #3 fun�my_fopen�(file:�string,�mode:�string): ����[l:agz]�(type_c2ats_FILE@l�│�ptr(l))�=�ret�where�{ ��val�pn�=�string2ptr(file) ��val�(pfnat,�fpfnat�│�pn)�=�$UN.ptr_vtake(pn)�//�Unsafe! ��val�pm�=�string2ptr(mode) ��val�(pfmat,�fpfmat�│�pm)�=�$UN.ptr_vtake(pm)�//�Unsafe! ��val�(pffp�│�fp)�=�fun_c2ats_fopen(pfnat,�pfmat�│�pn,�pm) ��prval�()�=�fpfnat(pfnat) ��prval�()�=�fpfmat(pfmat) ��val�()�=�assertloc(fp�>�0) ��val�ret�=�(pffp�│�fp) } //�continue... fun�my_fopen�(file:�string,�mode:�string): ����[l:agz]�(type_c2ats_FILE@l�│�ptr(l))�=�ret�where�{ ��val�pn�=�string2ptr(file) ��val�(pfnat,�fpfnat�│�pn)�=�$UN.ptr_vtake(pn)�//�Unsafe! ��val�pm�=�string2ptr(mode) ��val�(pfmat,�fpfmat�│�pm)�=�$UN.ptr_vtake(pm)�//�Unsafe! ��val�(pffp�│�fp)�=�fun_c2ats_fopen(pfnat,�pfmat�│�pn,�pm) ��prval�()�=�fpfnat(pfnat) ��prval�()�=�fpfmat(pfmat) ��val�()�=�assertloc(fp�>�0) ��val�ret�=�(pffp�│�fp) } //�continue... fun�my_fopen�(file:�string,�mode:�string): ����[l:agz]�(type_c2ats_FILE@l�│�ptr(l))�=�ret�where�{ ��val�pn�=�string2ptr(file) ��val�(pfnat,�fpfnat�│�pn)�=�$UN.ptr_vtake(pn)�//�Unsafe! ��val�pm�=�string2ptr(mode) ��val�(pfmat,�fpfmat�│�pm)�=�$UN.ptr_vtake(pm)�//�Unsafe! ��val�(pffp�│�fp)�=�fun_c2ats_fopen(pfnat,�pfmat�│�pn,�pm) ��prval�()�=�fpfnat(pfnat) ��prval�()�=�fpfmat(pfmat) ��val�()�=�assertloc(fp�>�0) ��val�ret�=�(pffp�│�fp) } //�continue... fun�my_fopen�(file:�string,�mode:�string): ����[l:agz]�(type_c2ats_FILE@l�│�ptr(l))�=�ret�where�{ ��val�pn�=�string2ptr(file) ��val�(pfnat,�fpfnat�│�pn)�=�$UN.ptr_vtake(pn)�//�Unsafe! ��val�pm�=�string2ptr(mode) ��val�(pfmat,�fpfmat�│�pm)�=�$UN.ptr_vtake(pm)�//�Unsafe! ��val�(pffp�│�fp)�=�fun_c2ats_fopen(pfnat,�pfmat�│�pn,�pm) ��prval�()�=�fpfnat(pfnat) ��prval�()�=�fpfmat(pfmat) ��val�()�=�assertloc(fp�>�0) ��val�ret�=�(pffp�│�fp) } //�continue... fun�my_fopen�(file:�string,�mode:�string): [l:agz]�(type_c2ats_FILE@l�│�ptr(l))�=�ret�where�{ val�pn�=�string2ptr(file) val�(pfnat,�fpfnat�│�pn)�=�$UN.ptr_vtake(pn)�//�Unsafe! val�pm�=�string2ptr(mode) val�(pfmat,�fpfmat�│�pm)�=�$UN.ptr_vtake(pm)�//�Unsafe! val�(pffp�│�fp)�=�fun_c2ats_fopen(pfnat,�pfmat�│�pn,�pm) prval�()�=�fpfnat(pfnat) prval�()�=�fpfmat(pfmat) val�()�=�assertloc(fp�>�0) val�ret�=�(pffp�│�fp) } //�continue...
  • 18. Unsafe ATS application on API #4Unsafe ATS application on API #4Unsafe ATS application on API #4Unsafe ATS application on API #4Unsafe ATS application on API #4 fun�my_fread�{l:agz}{n:nat} ����(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l),�len:�size_t(n)): ����[m:int]�(size_t(m),�strnptr(m))�=�ret�where�{ ��implement{}�string_tabulate$fopr(s)�=�'_' ��val�buf_strptr�=�strnptr2strptr(string_tabulate(len)) ��val�buf_ptr�=�strptr2ptr(buf_strptr) ��val�_�=�$STRING.memset_unsafe(buf_ptr,�0,�len) ��val�r�=�fun_c2ats_fread(pffp�│�buf_ptr,�1UL,�$UN.cast2ulint(len),�fp)�//� Unsafe! ��val�r�=�$UN.cast(r)�//�Unsafe! ��val�buf_strnptr�=�strptr2strnptr(buf_strptr) ��val�ret�=�(r,�buf_strnptr) } //�continue... fun�my_fread�{l:agz}{n:nat} ����(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l),�len:�size_t(n)): ����[m:int]�(size_t(m),�strnptr(m))�=�ret�where�{ ��implement{}�string_tabulate$fopr(s)�=�'_' ��val�buf_strptr�=�strnptr2strptr(string_tabulate(len)) ��val�buf_ptr�=�strptr2ptr(buf_strptr) ��val�_�=�$STRING.memset_unsafe(buf_ptr,�0,�len) ��val�r�=�fun_c2ats_fread(pffp�│�buf_ptr,�1UL,�$UN.cast2ulint(len),�fp)�//� Unsafe! ��val�r�=�$UN.cast(r)�//�Unsafe! ��val�buf_strnptr�=�strptr2strnptr(buf_strptr) ��val�ret�=�(r,�buf_strnptr) } //�continue... fun�my_fread�{l:agz}{n:nat} ����(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l),�len:�size_t(n)): ����[m:int]�(size_t(m),�strnptr(m))�=�ret�where�{ ��implement{}�string_tabulate$fopr(s)�=�'_' ��val�buf_strptr�=�strnptr2strptr(string_tabulate(len)) ��val�buf_ptr�=�strptr2ptr(buf_strptr) ��val�_�=�$STRING.memset_unsafe(buf_ptr,�0,�len) ��val�r�=�fun_c2ats_fread(pffp�│�buf_ptr,�1UL,�$UN.cast2ulint(len),�fp)�//� Unsafe! ��val�r�=�$UN.cast(r)�//�Unsafe! ��val�buf_strnptr�=�strptr2strnptr(buf_strptr) ��val�ret�=�(r,�buf_strnptr) } //�continue... fun�my_fread�{l:agz}{n:nat} ����(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l),�len:�size_t(n)): ����[m:int]�(size_t(m),�strnptr(m))�=�ret�where�{ ��implement{}�string_tabulate$fopr(s)�=�'_' ��val�buf_strptr�=�strnptr2strptr(string_tabulate(len)) ��val�buf_ptr�=�strptr2ptr(buf_strptr) ��val�_�=�$STRING.memset_unsafe(buf_ptr,�0,�len) ��val�r�=�fun_c2ats_fread(pffp�│�buf_ptr,�1UL,�$UN.cast2ulint(len),�fp)�//� Unsafe! ��val�r�=�$UN.cast(r)�//�Unsafe! ��val�buf_strnptr�=�strptr2strnptr(buf_strptr) ��val�ret�=�(r,�buf_strnptr) } //�continue... fun�my_fread�{l:agz}{n:nat} ����(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l),�len:�size_t(n)): [m:int]�(size_t(m),�strnptr(m))�=�ret�where�{ implement{}�string_tabulate$fopr(s)�=�'_' val�buf_strptr�=�strnptr2strptr(string_tabulate(len)) val�buf_ptr�=�strptr2ptr(buf_strptr) val�_�=�$STRING.memset_unsafe(buf_ptr,�0,�len) val�r�=�fun_c2ats_fread(pffp�│�buf_ptr,�1UL,�$UN.cast2ulint(len),�fp)�//� Unsafe! val�r�=�$UN.cast(r)�//�Unsafe! val�buf_strnptr�=�strptr2strnptr(buf_strptr) val�ret�=�(r,�buf_strnptr) } //�continue...
  • 19. Unsafe ATS application on API #5Unsafe ATS application on API #5Unsafe ATS application on API #5Unsafe ATS application on API #5Unsafe ATS application on API #5 fun�my_fclose�{l:agz}�(pffp:�type_c2ats_FILE@l�│�fp:�ptr(l)):�int ����=�ret�where�{ ��val�ret�=�fun_c2ats_fclose(pffp�│�fp) ��prval�()�=�__consume_view(pffp) } fun�readshow�{l:agz}�(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l)):�void�=�{ ��val�(r,�str)�=�my_fread(pffp�│�fp,�i2sz(128)) ��val�str�=�strnptr2strptr(str) ��val�()�=�print(str) ��val�()�=�free(str) ��val�()�=�if�r�>�0�then�readshow(pffp�│�fp) } //�continue... fun�my_fclose�{l:agz}�(pffp:�type_c2ats_FILE@l�│�fp:�ptr(l)):�int ����=�ret�where�{ ��val�ret�=�fun_c2ats_fclose(pffp�│�fp) ��prval�()�=�__consume_view(pffp) } fun�readshow�{l:agz}�(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l)):�void�=�{ ��val�(r,�str)�=�my_fread(pffp�│�fp,�i2sz(128)) ��val�str�=�strnptr2strptr(str) ��val�()�=�print(str) ��val�()�=�free(str) ��val�()�=�if�r�>�0�then�readshow(pffp�│�fp) } //�continue... fun�my_fclose�{l:agz}�(pffp:�type_c2ats_FILE@l�│�fp:�ptr(l)):�int ����=�ret�where�{ ��val�ret�=�fun_c2ats_fclose(pffp�│�fp) ��prval�()�=�__consume_view(pffp) } fun�readshow�{l:agz}�(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l)):�void�=�{ ��val�(r,�str)�=�my_fread(pffp�│�fp,�i2sz(128)) ��val�str�=�strnptr2strptr(str) ��val�()�=�print(str) ��val�()�=�free(str) ��val�()�=�if�r�>�0�then�readshow(pffp�│�fp) } //�continue... fun�my_fclose�{l:agz}�(pffp:�type_c2ats_FILE@l�│�fp:�ptr(l)):�int ����=�ret�where�{ ��val�ret�=�fun_c2ats_fclose(pffp�│�fp) ��prval�()�=�__consume_view(pffp) } fun�readshow�{l:agz}�(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l)):�void�=�{ ��val�(r,�str)�=�my_fread(pffp�│�fp,�i2sz(128)) ��val�str�=�strnptr2strptr(str) ��val�()�=�print(str) ��val�()�=�free(str) ��val�()�=�if�r�>�0�then�readshow(pffp�│�fp) } //�continue... fun�my_fclose�{l:agz}�(pffp:�type_c2ats_FILE@l�│�fp:�ptr(l)):�int ����=�ret�where�{ val�ret�=�fun_c2ats_fclose(pffp�│�fp) prval�()�=�__consume_view(pffp) } fun�readshow�{l:agz}�(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l)):�void�=�{ val�(r,�str)�=�my_fread(pffp�│�fp,�i2sz(128)) val�str�=�strnptr2strptr(str) val�()�=�print(str) val�()�=�free(str) val�()�=�if�r�>�0 then�readshow(pffp�│�fp) } //�continue...
  • 20. Unsafe ATS application on API #6Unsafe ATS application on API #6Unsafe ATS application on API #6Unsafe ATS application on API #6Unsafe ATS application on API #6 implement�main0�()�=�{ ��val�(pffp�│�fp)�=�my_fopen("main.dats",�"r") ��val�()�=�readshow(pffp�│�fp) ��val�r�=�my_fclose(pffp�│�fp) } implement�main0�()�=�{ ��val�(pffp�│�fp)�=�my_fopen("main.dats",�"r") ��val�()�=�readshow(pffp�│�fp) ��val�r�=�my_fclose(pffp�│�fp) } implement�main0�()�=�{ ��val�(pffp�│�fp)�=�my_fopen("main.dats",�"r") ��val�()�=�readshow(pffp�│�fp) ��val�r�=�my_fclose(pffp�│�fp) } implement�main0�()�=�{ ��val�(pffp�│�fp)�=�my_fopen("main.dats",�"r") ��val�()�=�readshow(pffp�│�fp) ��val�r�=�my_fclose(pffp�│�fp) } implement�main0�()�=�{ val�(pffp�│�fp)�=�my_fopen("main.dats",�"r") val�()�=�readshow(pffp�│�fp) val�r�=�my_fclose(pffp�│�fp) }
  • 21. Manually introduce linear type #1Manually introduce linear type #1Manually introduce linear type #1Manually introduce linear type #1Manually introduce linear type #1 ☆ Generated ATS interfaces are:☆ Generated ATS interfaces are:☆ Generated ATS interfaces are:☆ Generated ATS interfaces are:☆ Generated ATS interfaces are: $�cat�example.h #include�<stdio.h> $�c2ats�gen�example.h�>�example.sats $�cat�example.sats $�cat�example.h #include�<stdio.h> $�c2ats�gen�example.h�>�example.sats $�cat�example.sats $�cat�example.h #include�<stdio.h> $�c2ats�gen�example.h�>�example.sats $�cat�example.sats $�cat�example.h #include�<stdio.h> $�c2ats�gen�example.h�>�example.sats $�cat�example.sats $�cat�example.h #include�<stdio.h> $�c2ats�gen�example.h�>�example.sats $�cat�example.sats //�--snip-- fun�fun_c2ats_fclose:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1)�->� int�=�"mac#fclose" fun�fun_c2ats_fopen:�{l1,l2:addr}�(!ptr_v_1(char,�l1),�!ptr_v_1(char,�l2)�│� ptr�l1,�ptr�l2)�->�[l3:addr]�(ptr_v_1(type_c2ats_FILE,�l3)�│�ptr�l3)�=� "mac#fopen" fun�fun_c2ats_fread:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,� type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=� "mac#fread" //�--snip-- fun�fun_c2ats_fclose:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1)�->� int�=�"mac#fclose" fun�fun_c2ats_fopen:�{l1,l2:addr}�(!ptr_v_1(char,�l1),�!ptr_v_1(char,�l2)�│� ptr�l1,�ptr�l2)�->�[l3:addr]�(ptr_v_1(type_c2ats_FILE,�l3)�│�ptr�l3)�=� "mac#fopen" fun�fun_c2ats_fread:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,� type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=� "mac#fread" //�--snip-- fun�fun_c2ats_fclose:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1)�->� int�=�"mac#fclose" fun�fun_c2ats_fopen:�{l1,l2:addr}�(!ptr_v_1(char,�l1),�!ptr_v_1(char,�l2)�│� ptr�l1,�ptr�l2)�->�[l3:addr]�(ptr_v_1(type_c2ats_FILE,�l3)�│�ptr�l3)�=� "mac#fopen" fun�fun_c2ats_fread:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,� type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=� "mac#fread" //�--snip-- fun�fun_c2ats_fclose:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1)�->� int�=�"mac#fclose" fun�fun_c2ats_fopen:�{l1,l2:addr}�(!ptr_v_1(char,�l1),�!ptr_v_1(char,�l2)�│� ptr�l1,�ptr�l2)�->�[l3:addr]�(ptr_v_1(type_c2ats_FILE,�l3)�│�ptr�l3)�=� "mac#fopen" fun�fun_c2ats_fread:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,� type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=� "mac#fread" //�--snip-- fun�fun_c2ats_fclose:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1)�->� int�=�"mac#fclose" fun�fun_c2ats_fopen:�{l1,l2:addr}�(!ptr_v_1(char,�l1),�!ptr_v_1(char,�l2)�│� ptr�l1,�ptr�l2)�->�[l3:addr]�(ptr_v_1(type_c2ats_FILE,�l3)�│�ptr�l3)�=� "mac#fopen" fun�fun_c2ats_fread:�{l1:addr}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�ptr,� type_c2ats_size_t,�type_c2ats_size_t,�ptr�l1)�->�type_c2ats_size_t�=� "mac#fread"
  • 22. Manually introduce linear type #2Manually introduce linear type #2Manually introduce linear type #2Manually introduce linear type #2Manually introduce linear type #2 ☆ If you modify the interfaces with safe manner:☆ If you modify the interfaces with safe manner:☆ If you modify the interfaces with safe manner:☆ If you modify the interfaces with safe manner:☆ If you modify the interfaces with safe manner: $�cp�example.sats�example_welltyped.sats $�vi�example_welltyped.sats $�cp�example.sats�example_welltyped.sats $�vi�example_welltyped.sats $�cp�example.sats�example_welltyped.sats $�vi�example_welltyped.sats $�cp�example.sats�example_welltyped.sats $�vi�example_welltyped.sats $�cp�example.sats�example_welltyped.sats $�vi�example_welltyped.sats //�--snip-- fun�fun_c2ats_fclose:�{l1:agz}�(ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1)�->� int�=�"mac#fclose" fun�fun_c2ats_fopen:�(string,�string)�->�[l3:addr]�(ptr_v_1(type_c2ats_FILE,� l3)�│�ptr�l3)�=�"mac#fopen" fun�fun_c2ats_fread:�{l1:agz}{n,m:nat}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�! strnptr(n*m)>>strnptr(o),�size_t(n),�size_t(m),�ptr�l1)�->�#[o:nat�│�o�<=� n*m]�size_t(o)�=�"mac#fread" //�--snip-- fun�fun_c2ats_fclose:�{l1:agz}�(ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1)�->� int�=�"mac#fclose" fun�fun_c2ats_fopen:�(string,�string)�->�[l3:addr]�(ptr_v_1(type_c2ats_FILE,� l3)�│�ptr�l3)�=�"mac#fopen" fun�fun_c2ats_fread:�{l1:agz}{n,m:nat}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�! strnptr(n*m)>>strnptr(o),�size_t(n),�size_t(m),�ptr�l1)�->�#[o:nat�│�o�<=� n*m]�size_t(o)�=�"mac#fread" //�--snip-- fun�fun_c2ats_fclose:�{l1:agz}�(ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1)�->� int�=�"mac#fclose" fun�fun_c2ats_fopen:�(string,�string)�->�[l3:addr]�(ptr_v_1(type_c2ats_FILE,� l3)�│�ptr�l3)�=�"mac#fopen" fun�fun_c2ats_fread:�{l1:agz}{n,m:nat}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�! strnptr(n*m)>>strnptr(o),�size_t(n),�size_t(m),�ptr�l1)�->�#[o:nat�│�o�<=� n*m]�size_t(o)�=�"mac#fread" //�--snip-- fun�fun_c2ats_fclose:�{l1:agz}�(ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1)�->� int�=�"mac#fclose" fun�fun_c2ats_fopen:�(string,�string)�->�[l3:addr]�(ptr_v_1(type_c2ats_FILE,� l3)�│�ptr�l3)�=�"mac#fopen" fun�fun_c2ats_fread:�{l1:agz}{n,m:nat}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�! strnptr(n*m)>>strnptr(o),�size_t(n),�size_t(m),�ptr�l1)�->�#[o:nat�│�o�<=� n*m]�size_t(o)�=�"mac#fread" //�--snip-- fun�fun_c2ats_fclose:�{l1:agz}�(ptr_v_1(type_c2ats_FILE,�l1)�│�ptr�l1)�->� int�=�"mac#fclose" fun�fun_c2ats_fopen:�(string,�string)�->�[l3:addr]�(ptr_v_1(type_c2ats_FILE,� l3)�│�ptr�l3)�=�"mac#fopen" fun�fun_c2ats_fread:�{l1:agz}{n,m:nat}�(!ptr_v_1(type_c2ats_FILE,�l1)�│�! strnptr(n*m)>>strnptr(o),�size_t(n),�size_t(m),�ptr�l1)�->�#[o:nat�│�o�<=� n*m]�size_t(o)�=�"mac#fread"
  • 23. Manually introduce linear type #3Manually introduce linear type #3Manually introduce linear type #3Manually introduce linear type #3Manually introduce linear type #3 ☆ you can rite safe application:☆ you can rite safe application:☆ you can rite safe application:☆ you can rite safe application:☆ you can rite safe application: $�vi�main.dats$�vi�main.dats$�vi�main.dats$�vi�main.dats$�vi�main.dats #include�"share/atspre_define.hats" #include�"share/atspre_staload.hats" staload�STRING�=�"libats/libc/SATS/string.sats" staload�"example_welltyped.sats" fun�my_fopen�(file:�string,�mode:�string): ����[l:agz]�(type_c2ats_FILE@l�│�ptr(l))�=�ret�where�{ ��val�(pffp�│�fp)�=�fun_c2ats_fopen(file,�mode) ��val�()�=�assertloc(fp�>�0) ��val�ret�=�(pffp�│�fp) } //�continue... #include�"share/atspre_define.hats" #include�"share/atspre_staload.hats" staload�STRING�=�"libats/libc/SATS/string.sats" staload�"example_welltyped.sats" fun�my_fopen�(file:�string,�mode:�string): ����[l:agz]�(type_c2ats_FILE@l�│�ptr(l))�=�ret�where�{ ��val�(pffp�│�fp)�=�fun_c2ats_fopen(file,�mode) ��val�()�=�assertloc(fp�>�0) ��val�ret�=�(pffp�│�fp) } //�continue... #include�"share/atspre_define.hats" #include�"share/atspre_staload.hats" staload�STRING�=�"libats/libc/SATS/string.sats" staload�"example_welltyped.sats" fun�my_fopen�(file:�string,�mode:�string): ����[l:agz]�(type_c2ats_FILE@l�│�ptr(l))�=�ret�where�{ ��val�(pffp�│�fp)�=�fun_c2ats_fopen(file,�mode) ��val�()�=�assertloc(fp�>�0) ��val�ret�=�(pffp�│�fp) } //�continue... #include�"share/atspre_define.hats" #include�"share/atspre_staload.hats" staload�STRING�=�"libats/libc/SATS/string.sats" staload�"example_welltyped.sats" fun�my_fopen�(file:�string,�mode:�string): ����[l:agz]�(type_c2ats_FILE@l�│�ptr(l))�=�ret�where�{ ��val�(pffp�│�fp)�=�fun_c2ats_fopen(file,�mode) ��val�()�=�assertloc(fp�>�0) ��val�ret�=�(pffp�│�fp) } //�continue... #include�"share/atspre_define.hats" #include�"share/atspre_staload.hats" staload�STRING�=�"libats/libc/SATS/string.sats" staload�"example_welltyped.sats" fun�my_fopen�(file:�string,�mode:�string): [l:agz]�(type_c2ats_FILE@l�│�ptr(l))�=�ret�where�{ val�(pffp�│�fp)�=�fun_c2ats_fopen(file,�mode) val�()�=�assertloc(fp�>�0) val�ret�=�(pffp�│�fp) } //�continue...
  • 24. Manually introduce linear type #4Manually introduce linear type #4Manually introduce linear type #4Manually introduce linear type #4Manually introduce linear type #4 fun�my_fread�{l:agz}{n:nat} ����(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l),�len:�size_t(n)): ����[m:nat�│�m�<=�n]�(size_t(m),�strnptr(m))�=�ret�where�{ ��implement{}�string_tabulate$fopr(s)�=�'_' ��val�buf_strnptr�=�string_tabulate(len) ��val�buf_ptr�=�strnptr2ptr(buf_strnptr) ��val�_�=�$STRING.memset_unsafe(buf_ptr,�0,�len) ��val�r�=�fun_c2ats_fread(pffp�│�buf_strnptr,�i2sz(1),�len,�fp) ��val�ret�=�(r,�buf_strnptr) } //�continue... fun�my_fread�{l:agz}{n:nat} ����(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l),�len:�size_t(n)): ����[m:nat�│�m�<=�n]�(size_t(m),�strnptr(m))�=�ret�where�{ ��implement{}�string_tabulate$fopr(s)�=�'_' ��val�buf_strnptr�=�string_tabulate(len) ��val�buf_ptr�=�strnptr2ptr(buf_strnptr) ��val�_�=�$STRING.memset_unsafe(buf_ptr,�0,�len) ��val�r�=�fun_c2ats_fread(pffp�│�buf_strnptr,�i2sz(1),�len,�fp) ��val�ret�=�(r,�buf_strnptr) } //�continue... fun�my_fread�{l:agz}{n:nat} ����(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l),�len:�size_t(n)): ����[m:nat�│�m�<=�n]�(size_t(m),�strnptr(m))�=�ret�where�{ ��implement{}�string_tabulate$fopr(s)�=�'_' ��val�buf_strnptr�=�string_tabulate(len) ��val�buf_ptr�=�strnptr2ptr(buf_strnptr) ��val�_�=�$STRING.memset_unsafe(buf_ptr,�0,�len) ��val�r�=�fun_c2ats_fread(pffp�│�buf_strnptr,�i2sz(1),�len,�fp) ��val�ret�=�(r,�buf_strnptr) } //�continue... fun�my_fread�{l:agz}{n:nat} ����(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l),�len:�size_t(n)): ����[m:nat�│�m�<=�n]�(size_t(m),�strnptr(m))�=�ret�where�{ ��implement{}�string_tabulate$fopr(s)�=�'_' ��val�buf_strnptr�=�string_tabulate(len) ��val�buf_ptr�=�strnptr2ptr(buf_strnptr) ��val�_�=�$STRING.memset_unsafe(buf_ptr,�0,�len) ��val�r�=�fun_c2ats_fread(pffp�│�buf_strnptr,�i2sz(1),�len,�fp) ��val�ret�=�(r,�buf_strnptr) } //�continue... fun�my_fread�{l:agz}{n:nat} ����(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l),�len:�size_t(n)): [m:nat�│�m�<=�n]�(size_t(m),�strnptr(m))�=�ret�where�{ implement{}�string_tabulate$fopr(s)�=�'_' val�buf_strnptr�=�string_tabulate(len) val�buf_ptr�=�strnptr2ptr(buf_strnptr) val�_�=�$STRING.memset_unsafe(buf_ptr,�0,�len) val�r�=�fun_c2ats_fread(pffp�│�buf_strnptr,�i2sz(1),�len,�fp) val�ret�=�(r,�buf_strnptr) } //�continue...
  • 25. Manually introduce linear type #5Manually introduce linear type #5Manually introduce linear type #5Manually introduce linear type #5Manually introduce linear type #5 fun�readshow�{l:agz}�(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l)):�void�=�{ ��val�(r,�str)�=�my_fread(pffp�│�fp,�i2sz(128)) ��val�str�=�strnptr2strptr(str) ��val�()�=�print(str) ��val�()�=�free(str) ��val�()�=�if�r�>�0�then�readshow(pffp�│�fp) } implement�main0�()�=�{ ��val�(pffp�│�fp)�=�my_fopen("main.dats",�"r") ��val�()�=�readshow(pffp�│�fp) ��val�r�=�fun_c2ats_fclose(pffp�│�fp) } fun�readshow�{l:agz}�(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l)):�void�=�{ ��val�(r,�str)�=�my_fread(pffp�│�fp,�i2sz(128)) ��val�str�=�strnptr2strptr(str) ��val�()�=�print(str) ��val�()�=�free(str) ��val�()�=�if�r�>�0�then�readshow(pffp�│�fp) } implement�main0�()�=�{ ��val�(pffp�│�fp)�=�my_fopen("main.dats",�"r") ��val�()�=�readshow(pffp�│�fp) ��val�r�=�fun_c2ats_fclose(pffp�│�fp) } fun�readshow�{l:agz}�(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l)):�void�=�{ ��val�(r,�str)�=�my_fread(pffp�│�fp,�i2sz(128)) ��val�str�=�strnptr2strptr(str) ��val�()�=�print(str) ��val�()�=�free(str) ��val�()�=�if�r�>�0�then�readshow(pffp�│�fp) } implement�main0�()�=�{ ��val�(pffp�│�fp)�=�my_fopen("main.dats",�"r") ��val�()�=�readshow(pffp�│�fp) ��val�r�=�fun_c2ats_fclose(pffp�│�fp) } fun�readshow�{l:agz}�(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l)):�void�=�{ ��val�(r,�str)�=�my_fread(pffp�│�fp,�i2sz(128)) ��val�str�=�strnptr2strptr(str) ��val�()�=�print(str) ��val�()�=�free(str) ��val�()�=�if�r�>�0�then�readshow(pffp�│�fp) } implement�main0�()�=�{ ��val�(pffp�│�fp)�=�my_fopen("main.dats",�"r") ��val�()�=�readshow(pffp�│�fp) ��val�r�=�fun_c2ats_fclose(pffp�│�fp) } fun�readshow�{l:agz}�(pffp:�!type_c2ats_FILE@l�│�fp:�ptr(l)):�void�=�{ val�(r,�str)�=�my_fread(pffp�│�fp,�i2sz(128)) val�str�=�strnptr2strptr(str) val�()�=�print(str) val�()�=�free(str) val�()�=�if�r�>�0 then�readshow(pffp�│�fp) } implement�main0�()�=�{ val�(pffp�│�fp)�=�my_fopen("main.dats",�"r") val�()�=�readshow(pffp�│�fp) val�r�=�fun_c2ats_fclose(pffp�│�fp) }
  • 26. Future planFuture planFuture planFuture planFuture plan ☆ Hongwei, who is author of ATS, said:☆ Hongwei, who is author of ATS, said:☆ Hongwei, who is author of ATS, said:☆ Hongwei, who is author of ATS, said:☆ Hongwei, who is author of ATS, said: "Once�you�become�familiar�with�ATS,�you�can�readily�visualize�the�C�code� that�your�ATS�source�is�to�be�compiled�into." "Once�you�become�familiar�with�ATS,�you�can�readily�visualize�the�C�code� that�your�ATS�source�is�to�be�compiled�into." "Once�you�become�familiar�with�ATS,�you�can�readily�visualize�the�C�code� that�your�ATS�source�is�to�be�compiled�into." "Once�you�become�familiar�with�ATS,�you�can�readily�visualize�the�C�code� that�your�ATS�source�is�to�be�compiled�into." "Once�you�become�familiar�with�ATS,�you�can�readily�visualize�the�C�code� that�your�ATS�source�is�to�be�compiled�into." ☆ So, we can create decompiler for ATS language?☆ So, we can create decompiler for ATS language?☆ So, we can create decompiler for ATS language?☆ So, we can create decompiler for ATS language?☆ So, we can create decompiler for ATS language?
  • 27. ConclusionConclusionConclusionConclusionConclusion ☆ ATS code is more safe than C code.☆ ATS code is more safe than C code.☆ ATS code is more safe than C code.☆ ATS code is more safe than C code.☆ ATS code is more safe than C code. ☆ The c2ats generates ATS interface from C header.☆ The c2ats generates ATS interface from C header.☆ The c2ats generates ATS interface from C header.☆ The c2ats generates ATS interface from C header.☆ The c2ats generates ATS interface from C header. ☆ Unsafe ATS application can run on the interface.☆ Unsafe ATS application can run on the interface.☆ Unsafe ATS application can run on the interface.☆ Unsafe ATS application can run on the interface.☆ Unsafe ATS application can run on the interface. ☆ Make safety of the application with introducing linear type manually. ☆ Make safety of the application with introducing linear type manually. ☆ Make safety of the application with introducing linear type manually. ☆ Make safety of the application with introducing linear type manually. ☆ Make safety of the application with introducing linear type manually.