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.

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

  • 1.
    Generate ATS interfacefrom 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 levelprogrammingToday'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 theother 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 languageATSlanguageATS 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 ATSprogrammingReal 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 dousing c2ats...We can do using c2ats...We can do using c2ats...We can do using c2ats...We can do using c2ats...
  • 8.
    Rule: Translating primitivetypesRule: 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 andat-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 andat-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 forglobal 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 forglobal 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 applicationon 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 applicationon 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 applicationon 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 applicationon 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 applicationon 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 applicationon 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 lineartype #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 lineartype #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 lineartype #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 lineartype #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 lineartype #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 planFutureplanFuture 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 codeis 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.