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

PDF
ATS2 updates 2017
KEY
Dart: A Replacement for JavaScript and Why You Should Care
PDF
Static typing and proof in ATS language
PDF
Embedded application designed by ATS language
PDF
ATS language overview'
PPTX
Lambda The Extreme: Test-Driving a Functional Language
PDF
Safer IoT using functional language
PPSX
Community Tech Days C# 4.0
ATS2 updates 2017
Dart: A Replacement for JavaScript and Why You Should Care
Static typing and proof in ATS language
Embedded application designed by ATS language
ATS language overview'
Lambda The Extreme: Test-Driving a Functional Language
Safer IoT using functional language
Community Tech Days C# 4.0

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

PDF
ATS Programming Tutorial
PPTX
ATS Programming
PDF
Arduino programming of ML-style in ATS
PDF
ATS/LF for Coq users
PDF
Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki...
PDF
Ajhc Haskell Compiler with Reentrant GC
PDF
C som-programmeringssprog-bt
PPTX
DOCX
Fundamentals of programming and problem solving
PDF
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
PDF
Metasepi team meeting #16: Safety on ATS language + MCU
PDF
Metasepi team meeting #14: ATS programming on MCU
PPT
Ch6.ppt
PDF
DTS s03e04 Typing
PDF
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakova
PDF
12TypeSystem.pdf
PPTX
Precedence and associativity (Computer programming and utilization)
PDF
Software analysis and testing
PPT
PPT
C plus plus
ATS Programming Tutorial
ATS Programming
Arduino programming of ML-style in ATS
ATS/LF for Coq users
Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki...
Ajhc Haskell Compiler with Reentrant GC
C som-programmeringssprog-bt
Fundamentals of programming and problem solving
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
Metasepi team meeting #16: Safety on ATS language + MCU
Metasepi team meeting #14: ATS programming on MCU
Ch6.ppt
DTS s03e04 Typing
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakova
12TypeSystem.pdf
Precedence and associativity (Computer programming and utilization)
Software analysis and testing
C plus plus
Ad

Recently uploaded (20)

PPTX
Spectroscopy.pptx food analysis technology
PDF
KodekX | Application Modernization Development
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Cloud computing and distributed systems.
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation theory and applications.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Programs and apps: productivity, graphics, security and other tools
Spectroscopy.pptx food analysis technology
KodekX | Application Modernization Development
Reach Out and Touch Someone: Haptics and Empathic Computing
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Chapter 3 Spatial Domain Image Processing.pdf
MYSQL Presentation for SQL database connectivity
Building Integrated photovoltaic BIPV_UPV.pdf
Cloud computing and distributed systems.
Digital-Transformation-Roadmap-for-Companies.pptx
Encapsulation_ Review paper, used for researhc scholars
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation theory and applications.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
20250228 LYD VKU AI Blended-Learning.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Programs and apps: productivity, graphics, security and other tools
Ad

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.