Contenu connexe Similaire à ocamloptの全体像 (20) ocamloptの全体像2. 私は誰?私は誰?私は誰?私は誰?私は誰?
☆ Twitter: @master_q☆ Twitter: @master_q☆ Twitter: @master_q☆ Twitter: @master_q☆ Twitter: @master_q
☆ Metasepiプロジェクト主催☆ Metasepiプロジェクト主催☆ Metasepiプロジェクト主催☆ Metasepiプロジェクト主催☆ Metasepiプロジェクト主催
☆ Ajhc Haskellコンパイラ開発者☆ Ajhc Haskellコンパイラ開発者☆ Ajhc Haskellコンパイラ開発者☆ Ajhc Haskellコンパイラ開発者☆ Ajhc Haskellコンパイラ開発者
☆ Debian Maintainer☆ Debian Maintainer☆ Debian Maintainer☆ Debian Maintainer☆ Debian Maintainer
☆ 前はデジタルサイネージの開発してました☆ 前はデジタルサイネージの開発してました☆ 前はデジタルサイネージの開発してました☆ 前はデジタルサイネージの開発してました☆ 前はデジタルサイネージの開発してました
☆ その昔はNetBSDでコピー機作ってた☆ その昔はNetBSDでコピー機作ってた☆ その昔はNetBSDでコピー機作ってた☆ その昔はNetBSDでコピー機作ってた☆ その昔はNetBSDでコピー機作ってた
3. ぼくとOCamlぼくとOCamlぼくとOCamlぼくとOCamlぼくとOCaml
☆ 最初の会社で社内勉強会☆ 最初の会社で社内勉強会☆ 最初の会社で社内勉強会☆ 最初の会社で社内勉強会☆ 最初の会社で社内勉強会
☆ letの嵐にとまどう☆ letの嵐にとまどう☆ letの嵐にとまどう☆ letの嵐にとまどう☆ letの嵐にとまどう
☆ 数年後にPFDSを読む☆ 数年後にPFDSを読む☆ 数年後にPFDSを読む☆ 数年後にPFDSを読む☆ 数年後にPFDSを読む
☆ lazyきもちいい!☆ lazyきもちいい!☆ lazyきもちいい!☆ lazyきもちいい!☆ lazyきもちいい!
☆ camlp4に脳味噌を焼きはらわれる...☆ camlp4に脳味噌を焼きはらわれる...☆ camlp4に脳味噌を焼きはらわれる...☆ camlp4に脳味噌を焼きはらわれる...☆ camlp4に脳味噌を焼きはらわれる...
☆ camloebaさんに脅されてocamlopt読む☆ camloebaさんに脅されてocamlopt読む☆ camloebaさんに脅されてocamlopt読む☆ camloebaさんに脅されてocamlopt読む☆ camloebaさんに脅されてocamlopt読む
☆ OCamlコードわかりやすい! <= イマココ☆ OCamlコードわかりやすい! <= イマココ☆ OCamlコードわかりやすい! <= イマココ☆ OCamlコードわかりやすい! <= イマココ☆ OCamlコードわかりやすい! <= イマココ
4. 今日のもくじ今日のもくじ今日のもくじ今日のもくじ今日のもくじ
☆ [1] ocamloptについて簡単に☆ [1] ocamloptについて簡単に☆ [1] ocamloptについて簡単に☆ [1] ocamloptについて簡単に☆ [1] ocamloptについて簡単に
☆ [2] ソース探検のシナリオ☆ [2] ソース探検のシナリオ☆ [2] ソース探検のシナリオ☆ [2] ソース探検のシナリオ☆ [2] ソース探検のシナリオ
☆ [3] プログラムの起動☆ [3] プログラムの起動☆ [3] プログラムの起動☆ [3] プログラムの起動☆ [3] プログラムの起動
☆ [4] 文字列を画面に印字☆ [4] 文字列を画面に印字☆ [4] 文字列を画面に印字☆ [4] 文字列を画面に印字☆ [4] 文字列を画面に印字
☆ [5] シグナルの扱い☆ [5] シグナルの扱い☆ [5] シグナルの扱い☆ [5] シグナルの扱い☆ [5] シグナルの扱い
5. [1] ocamloptについて簡単に[1] ocamloptについて簡単に[1] ocamloptについて簡単に[1] ocamloptについて簡単に[1] ocamloptについて簡単に
まずはOCaml 4.00.1をインストールまずはOCaml 4.00.1をインストールまずはOCaml 4.00.1をインストールまずはOCaml 4.00.1をインストールまずはOCaml 4.00.1をインストール
$ git clone git@github.com:ocaml/ocaml.git
$ cd ocaml
$ git checkout 4.00.1
$ sudo apt-get build-dep ocaml
$ ./configure -with-debug-runtime
$ make world.opt
$ sudo make install
$ which ocamlopt
/usr/local/bin/ocamlopt
$ ocamlopt -version
4.00.1
$ git clone git@github.com:ocaml/ocaml.git
$ cd ocaml
$ git checkout 4.00.1
$ sudo apt-get build-dep ocaml
$ ./configure -with-debug-runtime
$ make world.opt
$ sudo make install
$ which ocamlopt
/usr/local/bin/ocamlopt
$ ocamlopt -version
4.00.1
$ git clone git@github.com:ocaml/ocaml.git
$ cd ocaml
$ git checkout 4.00.1
$ sudo apt-get build-dep ocaml
$ ./configure -with-debug-runtime
$ make world.opt
$ sudo make install
$ which ocamlopt
/usr/local/bin/ocamlopt
$ ocamlopt -version
4.00.1
$ git clone git@github.com:ocaml/ocaml.git
$ cd ocaml
$ git checkout 4.00.1
$ sudo apt-get build-dep ocaml
$ ./configure -with-debug-runtime
$ make world.opt
$ sudo make install
$ which ocamlopt
/usr/local/bin/ocamlopt
$ ocamlopt -version
4.00.1
$ git clone git@github.com:ocaml/ocaml.git
$ cd ocaml
$ git checkout 4.00.1
$ sudo apt-get build-dep ocaml
$ ./configure -with-debug-runtime
$ make world.opt
$ sudo make install
$ which ocamlopt
/usr/local/bin/ocamlopt
$ ocamlopt -version
4.00.1
想定環境想定環境想定環境想定環境想定環境
☆ Debian GNU/Linux sid amd64☆ Debian GNU/Linux sid amd64☆ Debian GNU/Linux sid amd64☆ Debian GNU/Linux sid amd64☆ Debian GNU/Linux sid amd64
6. ocamloptってなんどすか?ocamloptってなんどすか?ocamloptってなんどすか?ocamloptってなんどすか?ocamloptってなんどすか?
OCamlソースを実行バイナリにするコンパイラOCamlソースを実行バイナリにするコンパイラOCamlソースを実行バイナリにするコンパイラOCamlソースを実行バイナリにするコンパイラOCamlソースを実行バイナリにするコンパイラ
$ cat hello.ml
let hello _ = print_endline "Hello world!";;
let _ = hello ();
$ ocamlopt -g -runtime-variant d -o hello.bin hello.ml
$ file hello.bin
hello.bin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV),
dynamically linked (uses shared libs), for GNU/Linux 2.6.32,
BuildID[sha1]=402030a9bb82606a9d38f73e6ec25455f96d3caf, not
stripped
$ ./hello.bin
### OCaml runtime: debug mode ###
Initial minor heap size: 2048k bytes
Initial major heap size: 992k bytes
Initial space overhead: 80%
Initial max overhead: 500%
Initial heap increment: 992k bytes
Initial allocation policy: 0
Hello world!
$ cat hello.ml
let hello _ = print_endline "Hello world!";;
let _ = hello ();
$ ocamlopt -g -runtime-variant d -o hello.bin hello.ml
$ file hello.bin
hello.bin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV),
dynamically linked (uses shared libs), for GNU/Linux 2.6.32,
BuildID[sha1]=402030a9bb82606a9d38f73e6ec25455f96d3caf, not
stripped
$ ./hello.bin
### OCaml runtime: debug mode ###
Initial minor heap size: 2048k bytes
Initial major heap size: 992k bytes
Initial space overhead: 80%
Initial max overhead: 500%
Initial heap increment: 992k bytes
Initial allocation policy: 0
Hello world!
$ cat hello.ml
let hello _ = print_endline "Hello world!";;
let _ = hello ();
$ ocamlopt -g -runtime-variant d -o hello.bin hello.ml
$ file hello.bin
hello.bin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV),
dynamically linked (uses shared libs), for GNU/Linux 2.6.32,
BuildID[sha1]=402030a9bb82606a9d38f73e6ec25455f96d3caf, not
stripped
$ ./hello.bin
### OCaml runtime: debug mode ###
Initial minor heap size: 2048k bytes
Initial major heap size: 992k bytes
Initial space overhead: 80%
Initial max overhead: 500%
Initial heap increment: 992k bytes
Initial allocation policy: 0
Hello world!
$ cat hello.ml
let hello _ = print_endline "Hello world!";;
let _ = hello ();
$ ocamlopt -g -runtime-variant d -o hello.bin hello.ml
$ file hello.bin
hello.bin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV),
dynamically linked (uses shared libs), for GNU/Linux 2.6.32,
BuildID[sha1]=402030a9bb82606a9d38f73e6ec25455f96d3caf, not
stripped
$ ./hello.bin
### OCaml runtime: debug mode ###
Initial minor heap size: 2048k bytes
Initial major heap size: 992k bytes
Initial space overhead: 80%
Initial max overhead: 500%
Initial heap increment: 992k bytes
Initial allocation policy: 0
Hello world!
$ cat hello.ml
let hello _ = print_endline "Hello world!";;
let _ = hello ();
$ ocamlopt -g -runtime-variant d -o hello.bin hello.ml
$ file hello.bin
hello.bin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV),
dynamically linked (uses shared libs), for GNU/Linux 2.6.32,
BuildID[sha1]=402030a9bb82606a9d38f73e6ec25455f96d3caf, not
stripped
$ ./hello.bin
### OCaml runtime: debug mode ###
Initial minor heap size: 2048k bytes
Initial major heap size: 992k bytes
Initial space overhead: 80%
Initial max overhead: 500%
Initial heap increment: 992k bytes
Initial allocation policy: 0
Hello world!
10. [3] プログラムの起動[3] プログラムの起動[3] プログラムの起動[3] プログラムの起動[3] プログラムの起動
☆ main関数から実行が開始されて☆ main関数から実行が開始されて☆ main関数から実行が開始されて☆ main関数から実行が開始されて☆ main関数から実行が開始されて
☆ camlHello__entry関数がプログラム入口☆ camlHello__entry関数がプログラム入口☆ camlHello__entry関数がプログラム入口☆ camlHello__entry関数がプログラム入口☆ camlHello__entry関数がプログラム入口
$ ocamlopt -o hello.bin hello.ml
$ gdb hello.bin
(gdb) b camlHello__entry
Breakpoint 1 at 0x402260
(gdb) run
...
Breakpoint 1, 0x0000000000402260 in camlHello__entry ()
(gdb) bt
#0 0x0000000000402260 in camlHello__entry ()
#1 0x0000000000401e89 in caml_program ()
#2 0x0000000000410d82 in caml_start_program ()
#3 0x0000000000411245 in caml_main ()
#4 0x000000000040414e in main ()
$ ocamlopt -o hello.bin hello.ml
$ gdb hello.bin
(gdb) b camlHello__entry
Breakpoint 1 at 0x402260
(gdb) run
...
Breakpoint 1, 0x0000000000402260 in camlHello__entry ()
(gdb) bt
#0 0x0000000000402260 in camlHello__entry ()
#1 0x0000000000401e89 in caml_program ()
#2 0x0000000000410d82 in caml_start_program ()
#3 0x0000000000411245 in caml_main ()
#4 0x000000000040414e in main ()
$ ocamlopt -o hello.bin hello.ml
$ gdb hello.bin
(gdb) b camlHello__entry
Breakpoint 1 at 0x402260
(gdb) run
...
Breakpoint 1, 0x0000000000402260 in camlHello__entry ()
(gdb) bt
#0 0x0000000000402260 in camlHello__entry ()
#1 0x0000000000401e89 in caml_program ()
#2 0x0000000000410d82 in caml_start_program ()
#3 0x0000000000411245 in caml_main ()
#4 0x000000000040414e in main ()
$ ocamlopt -o hello.bin hello.ml
$ gdb hello.bin
(gdb) b camlHello__entry
Breakpoint 1 at 0x402260
(gdb) run
...
Breakpoint 1, 0x0000000000402260 in camlHello__entry ()
(gdb) bt
#0 0x0000000000402260 in camlHello__entry ()
#1 0x0000000000401e89 in caml_program ()
#2 0x0000000000410d82 in caml_start_program ()
#3 0x0000000000411245 in caml_main ()
#4 0x000000000040414e in main ()
$ ocamlopt -o hello.bin hello.ml
$ gdb hello.bin
(gdb) b camlHello__entry
Breakpoint 1 at 0x402260
(gdb) run
...
Breakpoint 1, 0x0000000000402260 in camlHello__entry ()
(gdb) bt
#0 0x0000000000402260 in camlHello__entry ()
#1 0x0000000000401e89 in caml_program ()
#2 0x0000000000410d82 in caml_start_program ()
#3 0x0000000000411245 in caml_main ()
#4 0x000000000040414e in main ()
11. main関数はどこに?main関数はどこに?main関数はどこに?main関数はどこに?main関数はどこに?
☆ "byterun/main.c"です☆ "byterun/main.c"です☆ "byterun/main.c"です☆ "byterun/main.c"です☆ "byterun/main.c"です
☆ え?バイトコード?☆ え?バイトコード?☆ え?バイトコード?☆ え?バイトコード?☆ え?バイトコード?
☆ "{byte,asm}run"のディレクトリがある☆ "{byte,asm}run"のディレクトリがある☆ "{byte,asm}run"のディレクトリがある☆ "{byte,asm}run"のディレクトリがある☆ "{byte,asm}run"のディレクトリがある
☆ でもなんかきっちり分離されていない☆ でもなんかきっちり分離されていない☆ でもなんかきっちり分離されていない☆ でもなんかきっちり分離されていない☆ でもなんかきっちり分離されていない
☆ バイナリでも適宜byterunの下を使います☆ バイナリでも適宜byterunの下を使います☆ バイナリでも適宜byterunの下を使います☆ バイナリでも適宜byterunの下を使います☆ バイナリでも適宜byterunの下を使います
12. main関数ソースmain関数ソースmain関数ソースmain関数ソースmain関数ソース
デバッグ機能なしだとこんなんデバッグ機能なしだとこんなんデバッグ機能なしだとこんなんデバッグ機能なしだとこんなんデバッグ機能なしだとこんなん
/* File: byterun/main.c */
int main(int argc, char **argv)
{
caml_main(argv);
caml_sys_exit(Val_int(0));
return 0;
}
/* File: byterun/main.c */
int main(int argc, char **argv)
{
caml_main(argv);
caml_sys_exit(Val_int(0));
return 0;
}
/* File: byterun/main.c */
int main(int argc, char **argv)
{
caml_main(argv);
caml_sys_exit(Val_int(0));
return 0;
}
/* File: byterun/main.c */
int main(int argc, char **argv)
{
caml_main(argv);
caml_sys_exit(Val_int(0));
return 0;
}
/* File: byterun/main.c */
int main(int argc, char **argv)
{
caml_main(argv);
caml_sys_exit(Val_int(0));
return 0;
}
むちゃくちゃ簡単ですむちゃくちゃ簡単ですむちゃくちゃ簡単ですむちゃくちゃ簡単ですむちゃくちゃ簡単です
14. caml_init_ieee_floats関数caml_init_ieee_floats関数caml_init_ieee_floats関数caml_init_ieee_floats関数caml_init_ieee_floats関数
/* File: byterun/floats.c */
/* The [caml_init_ieee_float] function should initialize
floating-point hardware so that it behaves as much as possible
like the IEEE standard.
In particular, return special numbers like Infinity and NaN
instead of signalling exceptions. Currently, everyone is in
IEEE mode at program startup, except FreeBSD prior to 4.0R. */
/* --snip-- */
void caml_init_ieee_floats(void)
{
#if defined(__FreeBSD__) && (__FreeBSD_version < 400017)
fpsetmask(0);
#endif
}
/* File: byterun/floats.c */
/* The [caml_init_ieee_float] function should initialize
floating-point hardware so that it behaves as much as possible
like the IEEE standard.
In particular, return special numbers like Infinity and NaN
instead of signalling exceptions. Currently, everyone is in
IEEE mode at program startup, except FreeBSD prior to 4.0R. */
/* --snip-- */
void caml_init_ieee_floats(void)
{
#if defined(__FreeBSD__) && (__FreeBSD_version < 400017)
fpsetmask(0);
#endif
}
/* File: byterun/floats.c */
/* The [caml_init_ieee_float] function should initialize
floating-point hardware so that it behaves as much as possible
like the IEEE standard.
In particular, return special numbers like Infinity and NaN
instead of signalling exceptions. Currently, everyone is in
IEEE mode at program startup, except FreeBSD prior to 4.0R. */
/* --snip-- */
void caml_init_ieee_floats(void)
{
#if defined(__FreeBSD__) && (__FreeBSD_version < 400017)
fpsetmask(0);
#endif
}
/* File: byterun/floats.c */
/* The [caml_init_ieee_float] function should initialize
floating-point hardware so that it behaves as much as possible
like the IEEE standard.
In particular, return special numbers like Infinity and NaN
instead of signalling exceptions. Currently, everyone is in
IEEE mode at program startup, except FreeBSD prior to 4.0R. */
/* --snip-- */
void caml_init_ieee_floats(void)
{
#if defined(__FreeBSD__) && (__FreeBSD_version < 400017)
fpsetmask(0);
#endif
}
/* File: byterun/floats.c */
/* The [caml_init_ieee_float] function should initialize
floating-point hardware so that it behaves as much as possible
like the IEEE standard.
In particular, return special numbers like Infinity and NaN
instead of signalling exceptions. Currently, everyone is in
IEEE mode at program startup, except FreeBSD prior to 4.0R. */
/* --snip-- */
void caml_init_ieee_floats(void)
{
#if defined(__FreeBSD__) && (__FreeBSD_version < 400017)
fpsetmask(0);
#endif
}
☆ FreeBSDへのバグ対策?☆ FreeBSDへのバグ対策?☆ FreeBSDへのバグ対策?☆ FreeBSDへのバグ対策?☆ FreeBSDへのバグ対策?
☆ 気にしないことにしましょう☆ 気にしないことにしましょう☆ 気にしないことにしましょう☆ 気にしないことにしましょう☆ 気にしないことにしましょう
15. caml_init_custom_operations #1caml_init_custom_operations #1caml_init_custom_operations #1caml_init_custom_operations #1caml_init_custom_operations #1
ボックス化されたintのプリミティブ関数を登録ボックス化されたintのプリミティブ関数を登録ボックス化されたintのプリミティブ関数を登録ボックス化されたintのプリミティブ関数を登録ボックス化されたintのプリミティブ関数を登録
/* File: byterun/custom.c */
void caml_init_custom_operations(void)
{
caml_register_custom_operations(&caml_int32_ops);
caml_register_custom_operations(&caml_nativeint_ops);
caml_register_custom_operations(&caml_int64_ops);
}
/* File: byterun/custom.c */
void caml_init_custom_operations(void)
{
caml_register_custom_operations(&caml_int32_ops);
caml_register_custom_operations(&caml_nativeint_ops);
caml_register_custom_operations(&caml_int64_ops);
}
/* File: byterun/custom.c */
void caml_init_custom_operations(void)
{
caml_register_custom_operations(&caml_int32_ops);
caml_register_custom_operations(&caml_nativeint_ops);
caml_register_custom_operations(&caml_int64_ops);
}
/* File: byterun/custom.c */
void caml_init_custom_operations(void)
{
caml_register_custom_operations(&caml_int32_ops);
caml_register_custom_operations(&caml_nativeint_ops);
caml_register_custom_operations(&caml_int64_ops);
}
/* File: byterun/custom.c */
void caml_init_custom_operations(void)
{
caml_register_custom_operations(&caml_int32_ops);
caml_register_custom_operations(&caml_nativeint_ops);
caml_register_custom_operations(&caml_int64_ops);
}
16. caml_init_custom_operations #2caml_init_custom_operations #2caml_init_custom_operations #2caml_init_custom_operations #2caml_init_custom_operations #2
でもたぶんこれバイトコードでだけ必要?でもたぶんこれバイトコードでだけ必要?でもたぶんこれバイトコードでだけ必要?でもたぶんこれバイトコードでだけ必要?でもたぶんこれバイトコードでだけ必要?
$ grep "caml_.*_ops" asmcomp/cmmgen.ml
Pnativeint -> "caml_nativeint_ops"
| Pint32 -> "caml_int32_ops"
| Pint64 -> "caml_int64_ops"
Csymbol_address("caml_int32_ops") :: Cint32 n :: Cint32 0n ::
cont
Csymbol_address("caml_int32_ops") :: Cint n :: cont
Csymbol_address("caml_nativeint_ops") :: Cint n :: cont
Csymbol_address("caml_int64_ops") :: Cint lo :: cont
Csymbol_address("caml_int64_ops") :: Cint hi :: Cint lo ::
cont
Csymbol_address("caml_int64_ops") :: Cint lo :: Cint hi ::
cont
$ grep "caml_.*_ops" asmcomp/cmmgen.ml
Pnativeint -> "caml_nativeint_ops"
| Pint32 -> "caml_int32_ops"
| Pint64 -> "caml_int64_ops"
Csymbol_address("caml_int32_ops") :: Cint32 n :: Cint32 0n ::
cont
Csymbol_address("caml_int32_ops") :: Cint n :: cont
Csymbol_address("caml_nativeint_ops") :: Cint n :: cont
Csymbol_address("caml_int64_ops") :: Cint lo :: cont
Csymbol_address("caml_int64_ops") :: Cint hi :: Cint lo ::
cont
Csymbol_address("caml_int64_ops") :: Cint lo :: Cint hi ::
cont
$ grep "caml_.*_ops" asmcomp/cmmgen.ml
Pnativeint -> "caml_nativeint_ops"
| Pint32 -> "caml_int32_ops"
| Pint64 -> "caml_int64_ops"
Csymbol_address("caml_int32_ops") :: Cint32 n :: Cint32 0n ::
cont
Csymbol_address("caml_int32_ops") :: Cint n :: cont
Csymbol_address("caml_nativeint_ops") :: Cint n :: cont
Csymbol_address("caml_int64_ops") :: Cint lo :: cont
Csymbol_address("caml_int64_ops") :: Cint hi :: Cint lo ::
cont
Csymbol_address("caml_int64_ops") :: Cint lo :: Cint hi ::
cont
$ grep "caml_.*_ops" asmcomp/cmmgen.ml
Pnativeint -> "caml_nativeint_ops"
| Pint32 -> "caml_int32_ops"
| Pint64 -> "caml_int64_ops"
Csymbol_address("caml_int32_ops") :: Cint32 n :: Cint32 0n ::
cont
Csymbol_address("caml_int32_ops") :: Cint n :: cont
Csymbol_address("caml_nativeint_ops") :: Cint n :: cont
Csymbol_address("caml_int64_ops") :: Cint lo :: cont
Csymbol_address("caml_int64_ops") :: Cint hi :: Cint lo ::
cont
Csymbol_address("caml_int64_ops") :: Cint lo :: Cint hi ::
cont
$ grep "caml_.*_ops" asmcomp/cmmgen.ml
Pnativeint -> "caml_nativeint_ops"
| Pint32 -> "caml_int32_ops"
| Pint64 -> "caml_int64_ops"
Csymbol_address("caml_int32_ops") :: Cint32 n :: Cint32 0n ::
cont
Csymbol_address("caml_int32_ops") :: Cint n :: cont
Csymbol_address("caml_nativeint_ops") :: Cint n :: cont
Csymbol_address("caml_int64_ops") :: Cint lo :: cont
Csymbol_address("caml_int64_ops") :: Cint hi :: Cint lo ::
cont
Csymbol_address("caml_int64_ops") :: Cint lo :: Cint hi ::
cont
ocamloptではシンボルから直接呼び出しにocamloptではシンボルから直接呼び出しにocamloptではシンボルから直接呼び出しにocamloptではシンボルから直接呼び出しにocamloptではシンボルから直接呼び出しに
17. parse_camlrunparam関数parse_camlrunparam関数parse_camlrunparam関数parse_camlrunparam関数parse_camlrunparam関数
OCAMLRUNPARAM環境変数を見るだけOCAMLRUNPARAM環境変数を見るだけOCAMLRUNPARAM環境変数を見るだけOCAMLRUNPARAM環境変数を見るだけOCAMLRUNPARAM環境変数を見るだけ
http://caml.inria.fr/pub/docs/manual-ocaml/manual024.htmlhttp://caml.inria.fr/pub/docs/manual-ocaml/manual024.htmlhttp://caml.inria.fr/pub/docs/manual-ocaml/manual024.htmlhttp://caml.inria.fr/pub/docs/manual-ocaml/manual024.htmlhttp://caml.inria.fr/pub/docs/manual-ocaml/manual024.html
/* File: asmrun/startup.c */
static void parse_camlrunparam(void)
{
char *opt = getenv ("OCAMLRUNPARAM");
uintnat p;
if (opt == NULL) opt = getenv ("CAMLRUNPARAM");
if (opt != NULL){
while (*opt != '0'){
switch (*opt++){
case 's': scanmult (opt, &minor_heap_init); break;
case 'i': scanmult (opt, &heap_chunk_init); break;
case 'h': scanmult (opt, &heap_size_init); break;
case 'l': scanmult (opt, &max_stack_init); break;
case 'o': scanmult (opt, &percent_free_init); break;
case 'O': scanmult (opt, &max_percent_free_init); break;
case 'v': scanmult (opt, &caml_verb_gc); break;
/* File: asmrun/startup.c */
static void parse_camlrunparam(void)
{
char *opt = getenv ("OCAMLRUNPARAM");
uintnat p;
if (opt == NULL) opt = getenv ("CAMLRUNPARAM");
if (opt != NULL){
while (*opt != '0'){
switch (*opt++){
case 's': scanmult (opt, &minor_heap_init); break;
case 'i': scanmult (opt, &heap_chunk_init); break;
case 'h': scanmult (opt, &heap_size_init); break;
case 'l': scanmult (opt, &max_stack_init); break;
case 'o': scanmult (opt, &percent_free_init); break;
case 'O': scanmult (opt, &max_percent_free_init); break;
case 'v': scanmult (opt, &caml_verb_gc); break;
/* File: asmrun/startup.c */
static void parse_camlrunparam(void)
{
char *opt = getenv ("OCAMLRUNPARAM");
uintnat p;
if (opt == NULL) opt = getenv ("CAMLRUNPARAM");
if (opt != NULL){
while (*opt != '0'){
switch (*opt++){
case 's': scanmult (opt, &minor_heap_init); break;
case 'i': scanmult (opt, &heap_chunk_init); break;
case 'h': scanmult (opt, &heap_size_init); break;
case 'l': scanmult (opt, &max_stack_init); break;
case 'o': scanmult (opt, &percent_free_init); break;
case 'O': scanmult (opt, &max_percent_free_init); break;
case 'v': scanmult (opt, &caml_verb_gc); break;
/* File: asmrun/startup.c */
static void parse_camlrunparam(void)
{
char *opt = getenv ("OCAMLRUNPARAM");
uintnat p;
if (opt == NULL) opt = getenv ("CAMLRUNPARAM");
if (opt != NULL){
while (*opt != '0'){
switch (*opt++){
case 's': scanmult (opt, &minor_heap_init); break;
case 'i': scanmult (opt, &heap_chunk_init); break;
case 'h': scanmult (opt, &heap_size_init); break;
case 'l': scanmult (opt, &max_stack_init); break;
case 'o': scanmult (opt, &percent_free_init); break;
case 'O': scanmult (opt, &max_percent_free_init); break;
case 'v': scanmult (opt, &caml_verb_gc); break;
/* File: asmrun/startup.c */
static void parse_camlrunparam(void)
{
char *opt = getenv ("OCAMLRUNPARAM");
uintnat p;
if (opt == NULL) opt = getenv ("CAMLRUNPARAM");
if (opt != NULL){
while (*opt != '0'){
switch (*opt++){
case 's': scanmult (opt, &minor_heap_init); break;
case 'i': scanmult (opt, &heap_chunk_init); break;
case 'h': scanmult (opt, &heap_size_init); break;
case 'l': scanmult (opt, &max_stack_init); break;
case 'o': scanmult (opt, &percent_free_init); break;
case 'O': scanmult (opt, &max_percent_free_init); break;
case 'v': scanmult (opt, &caml_verb_gc); break;
19. init_atoms関数init_atoms関数init_atoms関数init_atoms関数init_atoms関数
☆ これよくわからなかったです orz☆ これよくわからなかったです orz☆ これよくわからなかったです orz☆ これよくわからなかったです orz☆ これよくわからなかったです orz
☆ caml_data_segmentsと☆ caml_data_segmentsと☆ caml_data_segmentsと☆ caml_data_segmentsと☆ caml_data_segmentsと
☆ caml_code_segmentsを解析している?☆ caml_code_segmentsを解析している?☆ caml_code_segmentsを解析している?☆ caml_code_segmentsを解析している?☆ caml_code_segmentsを解析している?
☆ 目的がよくわからない...☆ 目的がよくわからない...☆ 目的がよくわからない...☆ 目的がよくわからない...☆ 目的がよくわからない...
20. caml_init_signals関数caml_init_signals関数caml_init_signals関数caml_init_signals関数caml_init_signals関数
SEGVシグナルハンドラを通常コンテキストと
は別のスタックで実行するように設定
SEGVシグナルハンドラを通常コンテキストと
は別のスタックで実行するように設定
SEGVシグナルハンドラを通常コンテキストと
は別のスタックで実行するように設定
SEGVシグナルハンドラを通常コンテキストと
は別のスタックで実行するように設定
SEGVシグナルハンドラを通常コンテキストと
は別のスタックで実行するように設定
/* File: asmrun/signals_asm.c */
void caml_init_signals(void)
{
/* Stack overflow handling */
stack_t stk;
struct sigaction act;
stk.ss_sp = sig_alt_stack;
stk.ss_size = SIGSTKSZ;
stk.ss_flags = 0;
SET_SIGACT(act, segv_handler);
act.sa_flags |= SA_ONSTACK | SA_NODEFER;
sigemptyset(&act.sa_mask);
system_stack_top = (char *) &act;
if (sigaltstack(&stk, NULL) == 0) {
sigaction(SIGSEGV, &act, NULL);
}
}
/* File: asmrun/signals_asm.c */
void caml_init_signals(void)
{
/* Stack overflow handling */
stack_t stk;
struct sigaction act;
stk.ss_sp = sig_alt_stack;
stk.ss_size = SIGSTKSZ;
stk.ss_flags = 0;
SET_SIGACT(act, segv_handler);
act.sa_flags |= SA_ONSTACK | SA_NODEFER;
sigemptyset(&act.sa_mask);
system_stack_top = (char *) &act;
if (sigaltstack(&stk, NULL) == 0) {
sigaction(SIGSEGV, &act, NULL);
}
}
/* File: asmrun/signals_asm.c */
void caml_init_signals(void)
{
/* Stack overflow handling */
stack_t stk;
struct sigaction act;
stk.ss_sp = sig_alt_stack;
stk.ss_size = SIGSTKSZ;
stk.ss_flags = 0;
SET_SIGACT(act, segv_handler);
act.sa_flags |= SA_ONSTACK | SA_NODEFER;
sigemptyset(&act.sa_mask);
system_stack_top = (char *) &act;
if (sigaltstack(&stk, NULL) == 0) {
sigaction(SIGSEGV, &act, NULL);
}
}
/* File: asmrun/signals_asm.c */
void caml_init_signals(void)
{
/* Stack overflow handling */
stack_t stk;
struct sigaction act;
stk.ss_sp = sig_alt_stack;
stk.ss_size = SIGSTKSZ;
stk.ss_flags = 0;
SET_SIGACT(act, segv_handler);
act.sa_flags |= SA_ONSTACK | SA_NODEFER;
sigemptyset(&act.sa_mask);
system_stack_top = (char *) &act;
if (sigaltstack(&stk, NULL) == 0) {
sigaction(SIGSEGV, &act, NULL);
}
}
/* File: asmrun/signals_asm.c */
void caml_init_signals(void)
{
/* Stack overflow handling */
stack_t stk;
struct sigaction act;
stk.ss_sp = sig_alt_stack;
stk.ss_size = SIGSTKSZ;
stk.ss_flags = 0;
SET_SIGACT(act, segv_handler);
act.sa_flags |= SA_ONSTACK | SA_NODEFER;
sigemptyset(&act.sa_mask);
system_stack_top = (char *) &act;
if (sigaltstack(&stk, NULL) == 0) {
sigaction(SIGSEGV, &act, NULL);
}
}
24. つまり?つまり?つまり?つまり?つまり?
OCamlサイドOCamlサイドOCamlサイドOCamlサイドOCamlサイド
☆ r14レジスタ: try時スタック☆ r14レジスタ: try時スタック☆ r14レジスタ: try時スタック☆ r14レジスタ: try時スタック☆ r14レジスタ: try時スタック
☆ r15レジスタ: GCヒープへのポインタ☆ r15レジスタ: GCヒープへのポインタ☆ r15レジスタ: GCヒープへのポインタ☆ r15レジスタ: GCヒープへのポインタ☆ r15レジスタ: GCヒープへのポインタ
C言語サイドC言語サイドC言語サイドC言語サイドC言語サイド
☆ caml_exception_pointer: try時スタック☆ caml_exception_pointer: try時スタック☆ caml_exception_pointer: try時スタック☆ caml_exception_pointer: try時スタック☆ caml_exception_pointer: try時スタック
☆ caml_young_ptr: GCヒープへのポインタ☆ caml_young_ptr: GCヒープへのポインタ☆ caml_young_ptr: GCヒープへのポインタ☆ caml_young_ptr: GCヒープへのポインタ☆ caml_young_ptr: GCヒープへのポインタ
いつでも戻れますねいつでも戻れますねいつでも戻れますねいつでも戻れますねいつでも戻れますね
26. caml_sys_init関数caml_sys_init関数caml_sys_init関数caml_sys_init関数caml_sys_init関数
プログラム名と引数の保管プログラム名と引数の保管プログラム名と引数の保管プログラム名と引数の保管プログラム名と引数の保管
/* File: byterun/sys.c */
void caml_sys_init(char * exe_name, char **argv)
{
caml_exe_name = exe_name;
caml_main_argv = argv;
}
/* File: byterun/sys.c */
void caml_sys_init(char * exe_name, char **argv)
{
caml_exe_name = exe_name;
caml_main_argv = argv;
}
/* File: byterun/sys.c */
void caml_sys_init(char * exe_name, char **argv)
{
caml_exe_name = exe_name;
caml_main_argv = argv;
}
/* File: byterun/sys.c */
void caml_sys_init(char * exe_name, char **argv)
{
caml_exe_name = exe_name;
caml_main_argv = argv;
}
/* File: byterun/sys.c */
void caml_sys_init(char * exe_name, char **argv)
{
caml_exe_name = exe_name;
caml_main_argv = argv;
}
まぁありがちまぁありがちまぁありがちまぁありがちまぁありがち
28. caml_start_program関数caml_start_program関数caml_start_program関数caml_start_program関数caml_start_program関数
☆ calleeのレジスタ退避☆ calleeのレジスタ退避☆ calleeのレジスタ退避☆ calleeのレジスタ退避☆ calleeのレジスタ退避
☆ caml_gc_regsをpush☆ caml_gc_regsをpush☆ caml_gc_regsをpush☆ caml_gc_regsをpush☆ caml_gc_regsをpush
☆ caml_last_return_addressをpush☆ caml_last_return_addressをpush☆ caml_last_return_addressをpush☆ caml_last_return_addressをpush☆ caml_last_return_addressをpush
☆ caml_bottom_of_stackをpush☆ caml_bottom_of_stackをpush☆ caml_bottom_of_stackをpush☆ caml_bottom_of_stackをpush☆ caml_bottom_of_stackをpush
☆ caml_young_ptrを%r15に☆ caml_young_ptrを%r15に☆ caml_young_ptrを%r15に☆ caml_young_ptrを%r15に☆ caml_young_ptrを%r15に
☆ caml_exception_pointerを%r14に☆ caml_exception_pointerを%r14に☆ caml_exception_pointerを%r14に☆ caml_exception_pointerを%r14に☆ caml_exception_pointerを%r14に
☆ caml_program関数呼び出し☆ caml_program関数呼び出し☆ caml_program関数呼び出し☆ caml_program関数呼び出し☆ caml_program関数呼び出し
33. [4] 文字列を画面に印字[4] 文字列を画面に印字[4] 文字列を画面に印字[4] 文字列を画面に印字[4] 文字列を画面に印字
☆ print_endlineが開始☆ print_endlineが開始☆ print_endlineが開始☆ print_endlineが開始☆ print_endlineが開始
35. [5] シグナルの扱い[5] シグナルの扱い[5] シグナルの扱い[5] シグナルの扱い[5] シグナルの扱い
blocking_sectionって何?blocking_sectionって何?blocking_sectionって何?blocking_sectionって何?blocking_sectionって何?
/* File: byterun/io.c */
CAMLexport struct channel * caml_open_descriptor_in(int fd)
{
struct channel * channel;
channel = (struct channel *)
caml_stat_alloc(sizeof(struct channel));
channel->fd = fd;
caml_enter_blocking_section();
channel->offset = lseek(fd, 0, SEEK_CUR);
caml_leave_blocking_section();
channel->curr = channel->max = channel->buff;
channel->end = channel->buff + IO_BUFFER_SIZE;
/* File: byterun/io.c */
CAMLexport struct channel * caml_open_descriptor_in(int fd)
{
struct channel * channel;
channel = (struct channel *)
caml_stat_alloc(sizeof(struct channel));
channel->fd = fd;
caml_enter_blocking_section();
channel->offset = lseek(fd, 0, SEEK_CUR);
caml_leave_blocking_section();
channel->curr = channel->max = channel->buff;
channel->end = channel->buff + IO_BUFFER_SIZE;
/* File: byterun/io.c */
CAMLexport struct channel * caml_open_descriptor_in(int fd)
{
struct channel * channel;
channel = (struct channel *)
caml_stat_alloc(sizeof(struct channel));
channel->fd = fd;
caml_enter_blocking_section();
channel->offset = lseek(fd, 0, SEEK_CUR);
caml_leave_blocking_section();
channel->curr = channel->max = channel->buff;
channel->end = channel->buff + IO_BUFFER_SIZE;
/* File: byterun/io.c */
CAMLexport struct channel * caml_open_descriptor_in(int fd)
{
struct channel * channel;
channel = (struct channel *)
caml_stat_alloc(sizeof(struct channel));
channel->fd = fd;
caml_enter_blocking_section();
channel->offset = lseek(fd, 0, SEEK_CUR);
caml_leave_blocking_section();
channel->curr = channel->max = channel->buff;
channel->end = channel->buff + IO_BUFFER_SIZE;
/* File: byterun/io.c */
CAMLexport struct channel * caml_open_descriptor_in(int fd)
{
struct channel * channel;
channel = (struct channel *)
caml_stat_alloc(sizeof(struct channel));
channel->fd = fd;
caml_enter_blocking_section();
channel->offset = lseek(fd, 0, SEEK_CUR);
caml_leave_blocking_section();
channel->curr = channel->max = channel->buff;
channel->end = channel->buff + IO_BUFFER_SIZE;
システムコールを囲むように配置されている...システムコールを囲むように配置されている...システムコールを囲むように配置されている...システムコールを囲むように配置されている...システムコールを囲むように配置されている...
38. 宣伝: Ajhc Haskellコンパイラ宣伝: Ajhc Haskellコンパイラ宣伝: Ajhc Haskellコンパイラ宣伝: Ajhc Haskellコンパイラ宣伝: Ajhc Haskellコンパイラ
☆ http://ajhc.metasepi.org/☆ http://ajhc.metasepi.org/☆ http://ajhc.metasepi.org/☆ http://ajhc.metasepi.org/☆ http://ajhc.metasepi.org/
☆ 組込を狙ったHaskellコンパイラ☆ 組込を狙ったHaskellコンパイラ☆ 組込を狙ったHaskellコンパイラ☆ 組込を狙ったHaskellコンパイラ☆ 組込を狙ったHaskellコンパイラ
☆ Haskell => C言語 への変換器☆ Haskell => C言語 への変換器☆ Haskell => C言語 への変換器☆ Haskell => C言語 への変換器☆ Haskell => C言語 への変換器
☆ jhc Haskellコンパイラのfork☆ jhc Haskellコンパイラのfork☆ jhc Haskellコンパイラのfork☆ jhc Haskellコンパイラのfork☆ jhc Haskellコンパイラのfork
☆ mbedプラットフォームなどで動作☆ mbedプラットフォームなどで動作☆ mbedプラットフォームなどで動作☆ mbedプラットフォームなどで動作☆ mbedプラットフォームなどで動作
☆ 要求RAMサイズ = 30kBぐらい☆ 要求RAMサイズ = 30kBぐらい☆ 要求RAMサイズ = 30kBぐらい☆ 要求RAMサイズ = 30kBぐらい☆ 要求RAMサイズ = 30kBぐらい
☆ もちろんPOSIXの上でも動きます☆ もちろんPOSIXの上でも動きます☆ もちろんPOSIXの上でも動きます☆ もちろんPOSIXの上でも動きます☆ もちろんPOSIXの上でも動きます
39. 宣伝: 「簡約!?λカ娘 Go!」はイカが?宣伝: 「簡約!?λカ娘 Go!」はイカが?宣伝: 「簡約!?λカ娘 Go!」はイカが?宣伝: 「簡約!?λカ娘 Go!」はイカが?宣伝: 「簡約!?λカ娘 Go!」はイカが?
http://www.paraiso-lang.org/ikmsm/http://www.paraiso-lang.org/ikmsm/http://www.paraiso-lang.org/ikmsm/http://www.paraiso-lang.org/ikmsm/http://www.paraiso-lang.org/ikmsm/
☆ Lensライブラリの解説☆ Lensライブラリの解説☆ Lensライブラリの解説☆ Lensライブラリの解説☆ Lensライブラリの解説
☆ パーサの解説☆ パーサの解説☆ パーサの解説☆ パーサの解説☆ パーサの解説
☆ 圏論とモナド☆ 圏論とモナド☆ 圏論とモナド☆ 圏論とモナド☆ 圏論とモナド
☆ 囲碁AI☆ 囲碁AI☆ 囲碁AI☆ 囲碁AI☆ 囲碁AI
☆ Ajhcコンパイラの開発秘話☆ Ajhcコンパイラの開発秘話☆ Ajhcコンパイラの開発秘話☆ Ajhcコンパイラの開発秘話☆ Ajhcコンパイラの開発秘話
などなどの話題を掲載!などなどの話題を掲載!などなどの話題を掲載!などなどの話題を掲載!などなどの話題を掲載!