Browse Source

first commit

main
zapashcanon 4 months ago
commit
ab89f9067b
Signed by: zapashcanon GPG Key ID: 8981C3C62D1D28F1
  1. 1
      .gitignore
  2. 1
      dune-project
  3. 26
      src/dune
  4. 436
      src/figures.ml
  5. 315
      src/figures2.ml
  6. 270
      src/logo_lmf.svg
  7. BIN
      src/logo_ocp.png
  8. 38
      src/main.tex
  9. BIN
      src/ocaml_chain.png
  10. 319
      src/slides.tex

1
.gitignore

@ -0,0 +1 @@
_build

1
dune-project

@ -0,0 +1 @@
(lang dune 3.0)

26
src/dune

@ -0,0 +1,26 @@
(rule
(target main.pdf)
(deps
;; tex
main.tex slides.tex
;; images
logo_lmf.svg
logo_ocp.png
ocaml_chain.png
;; generated images
figure_ocaml_bit1.mps
figure_ocaml_bit2.mps
figure_ocaml_bit3.mps
figure_type_hierarchy.mps
)
(action (run texfot xelatex -halt-on-error -shell-escape main.tex)))
(rule
(targets figure_ocaml_bit1.mps figure_ocaml_bit2.mps figure_ocaml_bit3.mps)
(deps figures.ml)
(action (run mlpost %{deps})))
(rule
(targets figure_type_hierarchy.mps)
(deps figures2.ml)
(action (run mlpost %{deps})))

436
src/figures.ml

@ -0,0 +1,436 @@
open Mlpost
open Box
(* a named box intended to be used as a pointer which implies empty content *)
let named_ptr name = box ~fill:Color.lightgreen ~name (tex " ")
(* a named scalar *)
let named_scalar ~name v = box ~fill:Color.lightcyan ~name (tex v)
(* a named taggeg pointer *)
let named_tagged_ptr name =
hbox ~stroke:(Some Color.black) ~fill:Color.lightgreen
[ box ~stroke:None (tex "") ~name; tex ~fill:Color.lightred "" ]
(* a named scalar *)
let named_tagged_scalar ~name v =
hbox ~stroke:(Some Color.black) ~fill:Color.lightcyan ~name
[ box ~stroke:None (tex v); tex ~fill:Color.lightmagenta "" ]
let tagged_scalar v =
hbox ~stroke:(Some Color.black) ~fill:Color.lightcyan
[ box ~stroke:None (tex v); tex ~fill:Color.lightmagenta "" ]
type scalar =
| Int of int
| Float of float
let value_to_string = function
| Int n -> string_of_int n
| Float f -> string_of_float f
let name_box name = tex (Format.sprintf "\\texttt{%s}:" name)
module Stack = struct
type value =
| Unboxed_ptr of string
| Unboxed_scalar of string * scalar
| Tagged_ptr of string
| Tagged_scalar of string * scalar
type t = value list
let value_to_box = function
| Unboxed_ptr name -> hbox [ name_box name; named_ptr name ]
| Unboxed_scalar (name, v) ->
let scalar = value_to_string v in
hbox [ name_box name; named_scalar ~name scalar ]
| Tagged_ptr name -> hbox [ name_box name; named_tagged_ptr name ]
| Tagged_scalar (name, v) ->
let scalar = value_to_string v in
hbox [ name_box name; named_tagged_scalar ~name scalar ]
let to_box l =
let l = List.map value_to_box l in
vbox ~padding:(Num.em 2.) [ tex "stack:"; vbox ~pos:`Right l ]
end
(* a named box intended to be used as a block metadata containing scalar *)
let named_meta_scalar name = box ~name ~fill:Color.lightmagenta (tex "")
(* a named box intended to be used as a block metadata containing ptr *)
let named_meta_ptr name = box ~name ~fill:Color.lightred (tex "")
module Block = struct
type tagged =
| Tagged_scalar of int
| Tagged_ptr of string
type t =
| Unboxed_ptr of string * string list
| Unboxed_scalar of string * scalar list
| Tagged of string * tagged list
| Untagged of string * string list
let named_meta_tagged name = box ~name ~fill:Color.lightblue (tex "")
let named_meta_untagged name = box ~name ~fill:Color.lightblue (tex "")
let tagged = function
| Tagged_scalar n ->
let v = string_of_int n in
tagged_scalar v
| Tagged_ptr name -> hbox [ named_tagged_ptr name ]
let untagged v = tex v
let to_box = function
| Unboxed_ptr (name, v) ->
hblock (named_meta_ptr name :: List.map named_ptr v)
| Unboxed_scalar (name, v) ->
let v = List.map value_to_string v in
hblock (named_meta_scalar name :: List.map (tex ~fill:Color.lightcyan) v)
| Tagged (name, v) -> hblock (named_meta_tagged name :: List.map tagged v)
| Untagged (name, v) ->
hblock (named_meta_untagged name :: List.map untagged v)
let unboxed_ptr name v = to_box @@ Unboxed_ptr (name, v)
let unboxed_scalar name v = to_box @@ Unboxed_scalar (name, v)
let tagged name v = to_box @@ Tagged (name, v)
let untagged name v = to_box @@ Untagged (name, v)
end
(* a named box intended to be used as a block metadata containing scalar *)
let named_meta_unboxed_float name = box ~name ~fill:Color.purple (tex "")
(* a block of unboxed floats *)
let unboxed_floats_block name values =
hblock
@@ named_meta_unboxed_float name
:: List.map (tex ~fill:Color.lightcyan) values
let scalar_array name values =
hblock ~name (List.map (tex ~fill:Color.lightcyan) values)
let figure_python_layout =
let stack =
let open Stack in
to_box
[ Unboxed_ptr "array1"
; Unboxed_ptr "array2"
; Unboxed_ptr "pair"
; Unboxed_ptr "x"
]
in
let heap =
let open Block in
vbox ~padding:(Num.em 2.)
[ tex "heap:"
; hbox ~padding:(Num.em 1.)
[ unboxed_scalar "1_meta" [ Int 1 ]
; unboxed_scalar "2_meta" [ Int 2 ]
; unboxed_scalar "3_meta" [ Int 3 ]
]
; unboxed_ptr "array1_meta" [ "array1_1"; "array1_2"; "array1_3" ]
; unboxed_ptr "pair_meta" [ "pair_1"; "pair_2" ]
; unboxed_ptr "array2_meta" [ "array2_1"; "array2_2"; "array2_3" ]
; hbox ~padding:(Num.em 1.)
[ unboxed_scalar "42_meta" [ Int 42 ]
; unboxed_scalar "99_meta" [ Int 99 ]
; unboxed_scalar "666_meta" [ Int 666 ]
]
]
in
let figure = hbox ~padding:(Num.em 2.) [ stack; heap ] in
let ptr a b = Helpers.box_pointer_arrow (get a figure) (get b figure) in
Command.seq
[ draw figure
; ptr "array1" "array1_meta"
; ptr "array1_1" "1_meta"
; ptr "array1_2" "2_meta"
; ptr "array1_3" "3_meta"
; ptr "array2" "array2_meta"
; ptr "array2_1" "42_meta"
; ptr "array2_2" "99_meta"
; ptr "array2_3" "666_meta"
; ptr "pair" "pair_meta"
; ptr "pair_1" "array1_meta"
; ptr "pair_2" "array2_meta"
; ptr "x" "42_meta"
]
let figure_python_layout2 =
let stack =
let open Stack in
to_box
[ Unboxed_ptr "array1"
; Unboxed_ptr "array2"
; Unboxed_ptr "pair"
; Unboxed_ptr "x"
]
in
let heap =
let open Block in
vbox ~padding:(Num.em 2.)
[ tex "heap:"
; unboxed_scalar "array1_meta" [ Int 1; Int 2; Int 3 ]
; unboxed_ptr "pair_meta" [ "pair_1"; "pair_2" ]
; unboxed_scalar "array2_meta" [ Int 42; Int 99; Int 666 ]
; unboxed_scalar "42_meta" [ Int 42 ]
]
in
let figure = hbox ~padding:(Num.em 2.) [ stack; heap ] in
let ptr a b = Helpers.box_pointer_arrow (get a figure) (get b figure) in
Command.seq
[ draw figure
; ptr "array1" "array1_meta"
; ptr "array2" "array2_meta"
; ptr "pair" "pair_meta"
; ptr "pair_1" "array1_meta"
; ptr "pair_2" "array2_meta"
; ptr "x" "42_meta"
]
let figure_ocaml_layout =
let stack =
let open Stack in
to_box
[ Tagged_ptr "array1"
; Tagged_ptr "array2"
; Tagged_ptr "pair"
; Tagged_scalar ("x", Int 42)
]
in
let heap =
let open Block in
vbox ~padding:(Num.em 2.)
[ tex "heap:"
; tagged "array1_meta"
[ Tagged_scalar 1; Tagged_scalar 2; Tagged_scalar 3 ]
; tagged "pair_meta" [ Tagged_ptr "pair_1"; Tagged_ptr "pair_2" ]
; tagged "array2_meta"
[ Tagged_scalar 42; Tagged_scalar 99; Tagged_scalar 666 ]
]
in
let figure = hbox ~padding:(Num.em 2.) [ stack; heap ] in
let ptr a b = Helpers.box_pointer_arrow (get a figure) (get b figure) in
Command.seq
[ draw figure
; ptr "array1" "array1_meta"
; ptr "array2" "array2_meta"
; ptr "pair" "pair_meta"
; ptr "pair_1" "array1_meta"
; ptr "pair_2" "array2_meta"
]
let figure_java_layout =
let stack =
let open Stack in
to_box
[ Unboxed_ptr "array1"
; Unboxed_ptr "array2"
; Unboxed_ptr "pair"
; Unboxed_scalar ("x", Int 42)
]
in
let heap =
let open Block in
vbox ~padding:(Num.em 2.)
[ tex "heap:"
; scalar_array "array1_array" [ "1"; "2"; "3" ]
; hbox ~padding:(Num.em 1.)
[ unboxed_scalar "1_meta" [ Int 1 ]
; unboxed_scalar "2_meta" [ Int 2 ]
; unboxed_scalar "3_meta" [ Int 3 ]
]
; unboxed_ptr "array1_meta" [ "array1_1"; "array1_2"; "array1_3" ]
; unboxed_ptr "pair_meta" [ "pair_1"; "pair_2" ]
; unboxed_ptr "array2_meta" [ "array2_1"; "array2_2"; "array2_3" ]
; hbox ~padding:(Num.em 1.)
[ unboxed_scalar "42_meta" [ Int 42 ]
; unboxed_scalar "99_meta" [ Int 99 ]
; unboxed_scalar "666_meta" [ Int 666 ]
]
]
in
let figure = hbox ~padding:(Num.em 2.) [ stack; heap ] in
let ptr a b = Helpers.box_pointer_arrow (get a figure) (get b figure) in
Command.seq
[ draw figure
; ptr "array1" "array1_array"
; ptr "array1_1" "1_meta"
; ptr "array1_2" "2_meta"
; ptr "array1_3" "3_meta"
; ptr "array2" "array2_meta"
; ptr "array2_1" "42_meta"
; ptr "array2_2" "99_meta"
; ptr "array2_3" "666_meta"
; ptr "pair" "pair_meta"
; ptr "pair_1" "array1_meta"
; ptr "pair_2" "array2_meta"
]
let figure_ocaml_bit1 =
let figure =
hblock
[ tex "$b_{n - 1}$"
; tex "$b_{n - 2}$"
; tex "\\ldots"
; tex "$b_{1}$"
; tex ~fill:Color.lightblue "$b_{0}$"
]
in
Command.seq [ draw figure ]
let figure_ocaml_bit2 =
let figure =
hbox ~padding:(Num.em 2.)
[ hblock
[ tex "$b_{n - 1}$"
; tex "$b_{n - 2}$"
; tex "\\ldots"
; tex "$b_{1}$"
; tex ~fill:Color.lightred "$0$"
]
; hblock
[ tex ~fill:Color.lightgreen "$b_{n - 1}$"
; tex ~fill:Color.lightgreen "$b_{n - 2}$"
; tex ~fill:Color.lightgreen "\\ldots"
; tex ~fill:Color.lightgreen "$b_{1}$"
; tex ~fill:Color.lightgreen "$0$"
]
]
in
Command.seq [ draw figure ]
let figure_ocaml_bit3 =
let figure =
hbox ~padding:(Num.em 2.)
[ hblock
[ tex "$b_{n - 1}$"
; tex "$b_{n - 2}$"
; tex "\\ldots"
; tex "$b_{1}$"
; tex ~fill:Color.lightmagenta "$1$"
]
; hblock
[ tex ~fill:Color.lightcyan "$b_{n - 1}$"
; tex ~fill:Color.lightcyan "$b_{n - 2}$"
; tex ~fill:Color.lightcyan "\\ldots"
; tex ~fill:Color.lightcyan "$b_{1}$"
; tex ~fill:Color.lightmagenta "$1$"
]
]
in
Command.seq [ draw figure ]
let figure_python_block1 =
let figure =
hblock
[ tex ~fill:Color.lightblue "$tag$"
; tex "$n$"
; tex ~fill:Color.lightyellow "$data_{0}$"
; tex ~fill:Color.lightyellow "\\ldots"
; tex ~fill:Color.lightyellow "$data_{n - 1}$"
]
in
Command.seq [ draw figure ]
let figure_python_block2 =
let figure =
hbox ~padding:(Num.em 2.)
[ hblock
[ tex ~fill:Color.lightred "pointer"
; tex "$2$"
; tex ~fill:Color.lightgreen "0x\\ldots"
; tex ~fill:Color.lightgreen "0x\\ldots"
]
; hblock
[ tex ~fill:Color.lightmagenta "scalar"
; tex "$1$"
; tex ~fill:Color.lightcyan "$42$"
]
]
in
Command.seq [ draw figure ]
let figure_ocaml_float1 =
let figure =
let open Block in
vbox ~padding:(Num.em 2.)
[ untagged "meta_abc" [ "$12.13$" ]
; hbox ~padding:(Num.em 1.)
[ tagged "array"
[ Tagged_ptr "array_1"
; Tagged_ptr "array_2"
; Tagged_ptr "array_3"
]
; untagged "meta_pi" [ "$6.28318530717958623$" ]
]
; untagged "meta_42" [ "$42.0$" ]
]
in
let ptr a b = Helpers.box_pointer_arrow (get a figure) (get b figure) in
Command.seq
[ draw figure
; ptr "array_1" "meta_abc"
; ptr "array_2" "meta_42"
; ptr "array_3" "meta_pi"
]
let figure_ocaml_float2 =
let figure =
unboxed_floats_block "meta_abc"
[ "$12.13$"; "$42.0$"; "$6.28318530717958623$" ]
in
Command.seq [ draw figure ]
let figure_wasm_layout =
let stack =
let open Stack in
to_box
[ Unboxed_ptr "array1"
; Unboxed_ptr "array2"
; Unboxed_ptr "pair"
; Unboxed_scalar ("x", Int 42)
]
in
let heap =
let open Block in
vbox ~padding:(Num.em 2.)
[ tex "heap:"
; unboxed_scalar "array1_meta" [ Int 1; Int 2; Int 3 ]
; unboxed_ptr "pair_meta" [ "pair_1"; "pair_2" ]
; unboxed_scalar "array2_meta" [ Int 42; Int 99; Int 666 ]
]
in
let figure = hbox ~padding:(Num.em 2.) [ stack; heap ] in
let ptr a b = Helpers.box_pointer_arrow (get a figure) (get b figure) in
Command.seq
[ draw figure
; ptr "array1" "array1_meta"
; ptr "array2" "array2_meta"
; ptr "pair" "pair_meta"
; ptr "pair_1" "array1_meta"
; ptr "pair_2" "array2_meta"
]
let () =
Array.iter
(fun (name, figure) -> Metapost.emit name (Picture.scale (Num.em 1.) figure))
[| ("figure_python_layout", figure_python_layout)
; ("figure_python_layout2", figure_python_layout2)
; ("figure_ocaml_layout", figure_ocaml_layout)
; ("figure_java_layout", figure_java_layout)
; ("figure_ocaml_bit1", figure_ocaml_bit1)
; ("figure_ocaml_bit2", figure_ocaml_bit2)
; ("figure_ocaml_bit3", figure_ocaml_bit3)
; ("figure_python_block1", figure_python_block1)
; ("figure_python_block2", figure_python_block2)
; ("figure_ocaml_float1", figure_ocaml_float1)
; ("figure_ocaml_float2", figure_ocaml_float2)
; ("figure_wasm_layout", figure_wasm_layout)
|]

315
src/figures2.ml

@ -0,0 +1,315 @@
open Mlpost
open Box
(* a named box intended to be used as a pointer which implies empty content *)
let named_ptr name = box ~fill:Color.lightgreen ~name (tex " ")
(* a named scalar *)
let named_scalar ~name v = box ~fill:Color.lightcyan ~name (tex v)
(* a named taggeg pointer *)
let named_tagged_ptr name =
hbox ~stroke:(Some Color.black) ~fill:Color.lightgreen
[ box ~stroke:None (tex "") ~name; tex ~fill:Color.lightred "" ]
(* a named scalar *)
let named_tagged_scalar ~name v =
hbox ~stroke:(Some Color.black) ~fill:Color.lightcyan ~name
[ box ~stroke:None (tex v); tex ~fill:Color.lightmagenta "" ]
let tagged_scalar v =
hbox ~stroke:(Some Color.black) ~fill:Color.lightcyan
[ box ~stroke:None (tex v); tex ~fill:Color.lightmagenta "" ]
type scalar =
| Int of int
| Float of float
let value_to_string = function
| Int n -> string_of_int n
| Float f -> string_of_float f
let name_box name = tex (Format.sprintf "\\texttt{%s}:" name)
module Stack = struct
type value =
| Unboxed_ptr of string
| Unboxed_scalar of string * scalar
| Tagged_ptr of string
| Tagged_scalar of string * scalar
type t = value list
let value_to_box = function
| Unboxed_ptr name -> hbox [ name_box name; named_ptr name ]
| Unboxed_scalar (name, v) ->
let scalar = value_to_string v in
hbox [ name_box name; named_scalar ~name scalar ]
| Tagged_ptr name -> hbox [ name_box name; named_tagged_ptr name ]
| Tagged_scalar (name, v) ->
let scalar = value_to_string v in
hbox [ name_box name; named_tagged_scalar ~name scalar ]
let to_box l =
let l = List.map value_to_box l in
vbox ~padding:(Num.em 2.) [ tex "stack:"; vbox ~pos:`Right l ]
end
(* a named box intended to be used as a block metadata containing scalar *)
let named_meta_scalar name = box ~name ~fill:Color.lightmagenta (tex "")
(* a named box intended to be used as a block metadata containing ptr *)
let named_meta_ptr name = box ~name ~fill:Color.lightred (tex "")
module Block = struct
type tagged =
| Tagged_scalar of int
| Tagged_ptr of string
type t =
| Unboxed_ptr of string * string list
| Unboxed_scalar of string * scalar list
| Tagged of string * tagged list
| Untagged of string * string list
let named_meta_tagged name = box ~name ~fill:Color.lightblue (tex "")
let named_meta_untagged name = box ~name ~fill:Color.lightblue (tex "")
let tagged = function
| Tagged_scalar n ->
let v = string_of_int n in
tagged_scalar v
| Tagged_ptr name -> hbox [ named_tagged_ptr name ]
let untagged v = tex v
let to_box = function
| Unboxed_ptr (name, v) ->
hblock (named_meta_ptr name :: List.map named_ptr v)
| Unboxed_scalar (name, v) ->
let v = List.map value_to_string v in
hblock (named_meta_scalar name :: List.map (tex ~fill:Color.lightcyan) v)
| Tagged (name, v) -> hblock (named_meta_tagged name :: List.map tagged v)
| Untagged (name, v) ->
hblock (named_meta_untagged name :: List.map untagged v)
let unboxed_ptr name v = to_box @@ Unboxed_ptr (name, v)
let unboxed_scalar name v = to_box @@ Unboxed_scalar (name, v)
let tagged name v = to_box @@ Tagged (name, v)
let untagged name v = to_box @@ Untagged (name, v)
end
(* a named box intended to be used as a block metadata containing scalar *)
let named_meta_unboxed_float name = box ~name ~fill:Color.purple (tex "")
(* a block of unboxed floats *)
let unboxed_floats_block name values =
hblock
@@ named_meta_unboxed_float name
:: List.map (tex ~fill:Color.lightcyan) values
let scalar_array name values =
hblock ~name (List.map (tex ~fill:Color.lightcyan) values)
let figure_ocaml_boxed =
let stack =
let open Stack in
to_box
[ Tagged_ptr "v"
]
in
let heap =
let open Block in
vbox ~padding:(Num.em 2.)
[ tex "heap:"
; tagged "v_meta"
[ Tagged_scalar 3 ]
]
in
let figure = hbox ~padding:(Num.em 2.) [ stack; heap ] in
let ptr a b = Helpers.box_pointer_arrow (get a figure) (get b figure) in
Command.seq
[ draw figure
; ptr "v" "v_meta"
]
let figure_ocaml_boxed2 =
let stack =
let open Stack in
to_box
[ Tagged_ptr "v"
]
in
let heap =
let open Block in
vbox ~padding:(Num.em 2.)
[ tex "heap:"
; tagged "v_meta"
[ Tagged_ptr "int_of_float" ]
]
in
let figure = hbox ~padding:(Num.em 2.) [ stack; heap ] in
let ptr a b = Helpers.box_pointer_arrow (get a figure) (get b figure) in
Command.seq
[ draw figure
; ptr "v" "v_meta"
]
let figure_ocaml_unboxed =
let stack =
let open Stack in
to_box
[
Tagged_scalar ("tag", (Int 0));
Tagged_scalar ("v", (Int 3));
]
in
let heap =
let open Block in
vbox ~padding:(Num.em 2.)
[ tex "heap:" ]
in
let figure = hbox ~padding:(Num.em 2.) [ stack; heap ] in
Command.seq
[ draw figure
]
let figure_ocaml_unboxed2 =
let stack =
let open Stack in
to_box
[
Tagged_scalar ("tag", (Int 1));
Tagged_ptr ("v");
]
in
let heap =
let open Block in
vbox ~padding:(Num.em 2.)
[ tex "heap:"
; tagged "v_meta"
[ Tagged_ptr "int_of_float" ]
]
in
let figure = hbox ~padding:(Num.em 2.) [ stack; heap ] in
let ptr a b = Helpers.box_pointer_arrow (get a figure) (get b figure) in
Command.seq
[ draw figure;
ptr "v" "v_meta"
]
let figure_ocaml_layout =
let stack =
let open Stack in
to_box
[ Tagged_ptr "array1"
; Tagged_ptr "array2"
; Tagged_ptr "pair"
; Tagged_scalar ("x", Int 42)
]
in
let heap =
let open Block in
vbox ~padding:(Num.em 2.)
[ tex "heap:"
; tagged "array1_meta"
[ Tagged_scalar 1; Tagged_scalar 2; Tagged_scalar 3 ]
; tagged "pair_meta" [ Tagged_ptr "pair_1"; Tagged_ptr "pair_2" ]
; tagged "array2_meta"
[ Tagged_scalar 42; Tagged_scalar 99; Tagged_scalar 666 ]
]
in
let figure = hbox ~padding:(Num.em 2.) [ stack; heap ] in
let ptr a b = Helpers.box_pointer_arrow (get a figure) (get b figure) in
Command.seq
[ draw figure
; ptr "array1" "array1_meta"
; ptr "array2" "array2_meta"
; ptr "pair" "pair_meta"
; ptr "pair_1" "array1_meta"
; ptr "pair_2" "array2_meta"
]
let figure_ocaml_bit1 =
let figure =
hblock
[ tex "$b_{n - 1}$"
; tex "$b_{n - 2}$"
; tex "\\ldots"
; tex "$b_{1}$"
; tex ~fill:Color.lightblue "$b_{0}$"
]
in
Command.seq [ draw figure ]
let figure_ocaml_bit2 =
let figure =
hbox ~padding:(Num.em 2.)
[ hblock
[ tex "$b_{n - 1}$"
; tex "$b_{n - 2}$"
; tex "\\ldots"
; tex "$b_{1}$"
; tex ~fill:Color.lightred "$0$"
]
; hblock
[ tex ~fill:Color.lightgreen "$b_{n - 1}$"
; tex ~fill:Color.lightgreen "$b_{n - 2}$"
; tex ~fill:Color.lightgreen "\\ldots"
; tex ~fill:Color.lightgreen "$b_{1}$"
; tex ~fill:Color.lightgreen "$0$"
]
]
in
Command.seq [ draw figure ]
let figure_ocaml_bit3 =
let figure =
hbox ~padding:(Num.em 2.)
[ hblock
[ tex "$b_{n - 1}$"
; tex "$b_{n - 2}$"
; tex "\\ldots"
; tex "$b_{1}$"
; tex ~fill:Color.lightmagenta "$1$"
]
; hblock
[ tex ~fill:Color.lightcyan "$b_{n - 1}$"
; tex ~fill:Color.lightcyan "$b_{n - 2}$"
; tex ~fill:Color.lightcyan "\\ldots"
; tex ~fill:Color.lightcyan "$b_{1}$"
; tex ~fill:Color.lightmagenta "$1$"
]
]
in
Command.seq [ draw figure ]
let figure_type_hierarchy =
let f =
let open Tree in
let leaf s = leaf (tex ~style:Rect s) in
let node s = node ~arrow_style:Undirected (tex ~style:Rect s) in
let t =
(node "any" [node "eq" [leaf "i31"; leaf "struct"; leaf "array"]])
in
hbox ~padding:(Num.em 2.) [
to_box t; to_box @@ node "func" [] ; to_box @@ node "extern" []
]
in
Command.seq [ draw f]
let () =
Array.iter
(fun (name, figure) -> Metapost.emit name (Picture.scale (Num.em 1.) figure))
[| ("figure_ocaml_boxed", figure_ocaml_boxed)
; ("figure_ocaml_boxed2", figure_ocaml_boxed2)
; ("figure_ocaml_unboxed", figure_ocaml_unboxed)
; ("figure_ocaml_unboxed2", figure_ocaml_unboxed2)
; ("figure_type_hierarchy", figure_type_hierarchy)
|]

270
src/logo_lmf.svg

@ -0,0 +1,270 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
id="Warstwa_1"
data-name="Warstwa 1"
viewBox="0 0 916.54 308.37"
version="1.1"
sodipodi:docname="lmf-logo-black.svg"
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<metadata
id="metadata146">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="2560"
inkscape:window-height="1440"
id="namedview144"
showgrid="true"
inkscape:zoom="1.6301143"
inkscape:cx="517.14165"
inkscape:cy="164.40565"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="Warstwa_1"
inkscape:showpageshadow="2"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1">
<inkscape:grid
type="xygrid"
id="grid202" />
</sodipodi:namedview>
<defs
id="defs71">
<style
id="style69">.cls-1{fill:#fff;}</style>
</defs>
<path
class="cls-1"
d="M747.38,308.7v4H724.87v-36l4.37.05v32Z"
transform="translate(-205.53 -205.59)"
id="path73"
style="fill:#000000" />
<path
class="cls-1"
d="M777.57,308.85v3.81h-6.32l-1.54-3c-1.6,2.31-4.27,3.49-7.71,3.49-5.19,0-8.69-2.62-8.69-7.4,0-10.28,16.35-3.75,16.35-9.25v-.16c0-2.26-1.55-4.52-5.3-4.52-3.34,0-5.24,1.8-6.27,4.57l-3.6-1.85a10.17,10.17,0,0,1,10-6.58c5.65,0,9.45,3.4,9.45,8.59v12.28Zm-7.91-5v-3.14c-4.12,2.11-12.08.16-12.08,5.19,0,3,2.67,3.4,4.57,3.4C768,309.32,769.66,305.92,769.66,303.87Z"
transform="translate(-205.53 -205.59)"
id="path75"
style="fill:#000000" />
<path
class="cls-1"
d="M807.58,300.58c0,5.75-3.14,12.59-11.05,12.59a9.08,9.08,0,0,1-7.51-3.34l-1.75,2.83h-2.62v-36h4.27l-.16,14.9a9.23,9.23,0,0,1,7.77-3.6C804.44,288,807.58,294.87,807.58,300.58Zm-4.27,0c0-5.35-2.62-8.74-7.14-8.74s-7.82,3.34-7.82,8.48c0,5.65,3.29,9,7.82,9S803.31,305.92,803.31,300.58Z"
transform="translate(-205.53 -205.59)"
id="path77"
style="fill:#000000" />
<path
class="cls-1"
d="M815.21,300.32c0-5.91,3.34-12.34,11.46-12.34s11.46,6.43,11.46,12.34c0,6.43-3.34,12.85-11.46,12.85S815.21,306.75,815.21,300.32Zm18.66,0c0-5.14-2.57-8.48-7.2-8.48s-7.19,3.34-7.19,8.48c0,5.65,2.57,9,7.19,9S833.87,306,833.87,300.32Z"
transform="translate(-205.53 -205.59)"
id="path79"
style="fill:#000000" />
<path
class="cls-1"
d="M868.75,294.56l-3.65,1.7c-1.23-3.13-2.31-4.42-5-4.42-5.7,0-6.63,5.7-6.63,9.92v7h5v3.86H844.59V308.8h4.58V292.35h-4.06V288.5h6.68l2,3.19a7.69,7.69,0,0,1,6.69-3.71C864,288,867,289.84,868.75,294.56Z"
transform="translate(-205.53 -205.59)"
id="path81"
style="fill:#000000" />
<path
class="cls-1"
d="M899.51,308.85v3.81h-6.32l-1.54-3c-1.59,2.31-4.27,3.49-7.71,3.49-5.19,0-8.69-2.62-8.69-7.4,0-10.28,16.35-3.75,16.35-9.25v-.16c0-2.26-1.54-4.52-5.3-4.52-3.34,0-5.24,1.8-6.27,4.57l-3.59-1.85a10.15,10.15,0,0,1,10-6.58c5.65,0,9.46,3.4,9.46,8.59v12.28Zm-7.91-5v-3.14c-4.11,2.11-12.08.16-12.08,5.19,0,3,2.67,3.4,4.57,3.4C890,309.32,891.6,305.92,891.6,303.87Z"
transform="translate(-205.53 -205.59)"
id="path83"
style="fill:#000000" />
<path
class="cls-1"
d="M928.05,306.54c-1.49,4.27-4.31,6.63-9,6.63-5.66,0-8.94-3.44-8.94-9.3V292.35h-6.48V288.5h6.48v-8.64h4.26v8.64h12.49v3.85H914.38V303.2c0,2,0,6.12,4.73,6.12,3.34,0,4.32-2,5.35-4.58Z"
transform="translate(-205.53 -205.59)"
id="path85"
style="fill:#000000" />
<path
class="cls-1"
d="M935.31,300.32c0-5.91,3.34-12.34,11.47-12.34s11.46,6.43,11.46,12.34c0,6.43-3.34,12.85-11.46,12.85S935.31,306.75,935.31,300.32Zm18.66,0c0-5.14-2.57-8.48-7.19-8.48s-7.2,3.34-7.2,8.48c0,5.65,2.57,9,7.2,9S954,306,954,300.32Z"
transform="translate(-205.53 -205.59)"
id="path87"
style="fill:#000000" />
<path
class="cls-1"
d="M987.64,308.8v3.86H964.92V308.8h9.2V292.35H966V288.5h12.44l.05,20.3Zm-8.74-26.16h-6v-6h6Z"
transform="translate(-205.53 -205.59)"
id="path89"
style="fill:#000000" />
<path
class="cls-1"
d="M1019.3,294.56l-3.65,1.7c-1.23-3.13-2.31-4.42-5-4.42-5.71,0-6.63,5.7-6.63,9.92v7h5v3.86H995.15V308.8h4.57V292.35h-4.06V288.5h6.68l2,3.19A7.66,7.66,0,0,1,1011,288C1014.52,288,1017.56,289.84,1019.3,294.56Z"
transform="translate(-205.53 -205.59)"
id="path91"
style="fill:#000000" />
<path
class="cls-1"
d="M1049.22,300.58l0,1.13-18.87,0c.36,4.73,3,7.66,8,7.66,3.44,0,5.65-1.44,6.68-4.58l3.6,1.85c-1.54,3.65-4.58,6.58-10.44,6.58-8.78,0-12.12-6.53-12.12-12.64s3.23-12.55,11.87-12.55C1046.29,288,1049.53,294.1,1049.22,300.58Zm-18.71-2.68,14.24.06c-.31-4.22-2.93-6.12-6.79-6.12C1033.7,291.84,1031.23,294.15,1030.51,297.9Z"
transform="translate(-205.53 -205.59)"
id="path93"
style="fill:#000000" />
<path
class="cls-1"
d="M743.07,376.9l.15-27.86-6.68,12.18h-2.78L727.08,349l.16,27.86h-4.37l0-36h3.49l8.74,15.27,8.74-15.27h3.49l.06,36Z"
transform="translate(-205.53 -205.59)"
id="path95"
style="fill:#000000" />
<path
class="cls-1"
d="M777.5,364.82l-.06,1.13-18.86-.05c.36,4.73,3,7.66,8,7.66,3.44,0,5.65-1.44,6.68-4.58l3.6,1.86c-1.54,3.64-4.58,6.57-10.44,6.57-8.79,0-12.13-6.52-12.13-12.64s3.24-12.54,11.88-12.54C774.57,352.23,777.8,358.35,777.5,364.82Zm-18.71-2.67,14.23.05c-.3-4.21-2.93-6.12-6.78-6.12C762,356.08,759.51,358.4,758.79,362.15Zm9-15.06h-4.06l3.5-8.74h4.57Z"
transform="translate(-205.53 -205.59)"
id="path97"
style="fill:#000000" />
<path
class="cls-1"
d="M807.93,370.78c-1.49,4.27-4.32,6.63-9,6.63-5.66,0-9-3.44-9-9.3V356.6h-6.47v-3.86H790v-8.63h4.27v8.63h12.49v3.86H794.26v10.84c0,2,0,6.12,4.73,6.12,3.34,0,4.31-2,5.34-4.58Z"
transform="translate(-205.53 -205.59)"
id="path99"
style="fill:#000000" />
<path
class="cls-1"
d="M836.91,362.2l-.06,14.7h-4.26l0-13.57V362.2c0-1.23,0-6.12-5.55-6.12-6.27,0-6.68,6.17-6.68,9.87V376.9h-4.27v-36h4.27l-.16,15.73a8.35,8.35,0,0,1,7.61-4.42C833.31,352.23,836.91,356.29,836.91,362.2Z"
transform="translate(-205.53 -205.59)"
id="path101"
style="fill:#000000" />
<path
class="cls-1"
d="M845.47,364.56c0-5.91,3.34-12.33,11.46-12.33s11.46,6.42,11.46,12.33c0,6.43-3.33,12.85-11.46,12.85S845.47,371,845.47,364.56Zm18.66,0c0-5.14-2.57-8.48-7.2-8.48s-7.19,3.34-7.19,8.48c0,5.66,2.57,9,7.19,9S864.13,370.22,864.13,364.56Z"
transform="translate(-205.53 -205.59)"
id="path103"
style="fill:#000000" />
<path
class="cls-1"
d="M899,340.92v36h-2.62l-1.74-2.83a9.07,9.07,0,0,1-7.51,3.34c-7.92,0-11.05-6.83-11.05-12.59s3.13-12.59,11.05-12.59a9.17,9.17,0,0,1,7.76,3.6l-.15-14.91Zm-3.7,23.64c0-5.14-3.29-8.48-7.81-8.48s-7.14,3.4-7.14,8.74,2.62,8.74,7.14,8.74S895.25,370.22,895.25,364.56Z"
transform="translate(-205.53 -205.59)"
id="path105"
style="fill:#000000" />
<path
class="cls-1"
d="M930.31,364.82l0,1.13-18.87-.05c.36,4.73,3,7.66,8,7.66,3.45,0,5.66-1.44,6.68-4.58l3.6,1.86c-1.54,3.64-4.57,6.57-10.43,6.57-8.79,0-12.13-6.52-12.13-12.64s3.23-12.54,11.87-12.54C927.38,352.23,930.62,358.35,930.31,364.82Zm-18.71-2.67,14.24.05c-.31-4.21-2.93-6.12-6.79-6.12C914.79,356.08,912.32,358.4,911.6,362.15Z"
transform="translate(-205.53 -205.59)"
id="path107"
style="fill:#000000" />
<path
class="cls-1"
d="M941.55,369c1.29,2.83,2.68,4.58,7.51,4.58,2.72,0,5.08-.57,5.08-3.45,0-2.62-2-2.82-5.65-3.54-4.52-.88-9.1-2.06-9.1-7.15,0-4.78,4-7.19,9-7.19,5.19,0,8.58,2.62,10,6.58l-3.6,1.85c-1-2.47-2.36-4.58-6.53-4.58-2.67,0-4.57.88-4.57,3.34,0,1.85,1,2.42,4.88,3.19,4.47.87,9.87,1.75,9.87,7.5,0,5.2-4.27,7.3-9.92,7.3-5.35,0-9-2.62-10.54-6.57Z"
transform="translate(-205.53 -205.59)"
id="path109"
style="fill:#000000" />
<path
class="cls-1"
d="M728.26,409.12v11.67h15.53v4H728.26v16.39H723.9v-36h22.46v4Z"
transform="translate(-205.53 -205.59)"
id="path111"
style="fill:#000000" />
<path
class="cls-1"
d="M751.52,428.81c0-5.91,3.34-12.34,11.47-12.34s11.46,6.43,11.46,12.34c0,6.42-3.34,12.85-11.46,12.85S751.52,435.23,751.52,428.81Zm18.66,0c0-5.14-2.57-8.48-7.19-8.48s-7.2,3.34-7.2,8.48c0,5.65,2.57,9,7.2,9S770.18,434.46,770.18,428.81Z"
transform="translate(-205.53 -205.59)"
id="path113"
style="fill:#000000" />
<path
class="cls-1"
d="M805.06,423.05l-3.65,1.7c-1.23-3.14-2.31-4.42-5-4.42-5.71,0-6.63,5.7-6.63,9.92v7h5v3.85H780.91v-3.85h4.57V420.84h-4.06V417h6.68l2,3.18a7.66,7.66,0,0,1,6.68-3.7C800.28,416.47,803.32,418.32,805.06,423.05Z"
transform="translate(-205.53 -205.59)"
id="path115"
style="fill:#000000" />
<path
class="cls-1"
d="M838.32,427.32v14h-4.27v-14c0-2.78,0-7-3-7-2.36,0-4.16,2.62-4.16,9.87v10.94h-4.17l-.1-14c0-3.44-.26-7-3-7-2.37,0-4.16,2.62-4.16,9.87v11.1h-4.12V417h2.63l1.38,2.21a5.5,5.5,0,0,1,4.94-2.73c3,0,4.68,1.85,5.6,4.11,1.08-2.31,2.93-4.11,6-4.11C838.53,416.47,838.32,424.18,838.32,427.32Z"
transform="translate(-205.53 -205.59)"
id="path117"
style="fill:#000000" />
<path
class="cls-1"
d="M868.52,429.06l0,1.14-18.87-.06c.36,4.73,3,7.66,8,7.66,3.44,0,5.66-1.44,6.68-4.57l3.6,1.85c-1.54,3.65-4.57,6.58-10.43,6.58-8.79,0-12.13-6.53-12.13-12.65s3.23-12.54,11.87-12.54C865.59,416.47,868.83,422.59,868.52,429.06Zm-18.71-2.67,14.24.05c-.31-4.21-2.93-6.11-6.79-6.11C853,420.33,850.53,422.64,849.81,426.39Z"
transform="translate(-205.53 -205.59)"
id="path119"
style="fill:#000000" />
<path
class="cls-1"
d="M897.36,437.29v3.85H875.67v-3.85h8.74l0-28.27h-7.15v-3.86h11.41V409h0l0,28.27Z"
transform="translate(-205.53 -205.59)"
id="path121"
style="fill:#000000" />
<path
class="cls-1"
d="M927.29,437.29v3.85H905.6v-3.85h8.73L914.28,409h-7.14v-3.86h11.41V409h0l0,28.27Z"
transform="translate(-205.53 -205.59)"
id="path123"
style="fill:#000000" />
<path
class="cls-1"
d="M957.36,429.06l-.05,1.14-18.87-.06c.36,4.73,3,7.66,8,7.66,3.44,0,5.65-1.44,6.68-4.57l3.6,1.85c-1.54,3.65-4.58,6.58-10.44,6.58-8.79,0-12.13-6.53-12.13-12.65s3.24-12.54,11.88-12.54C954.43,416.47,957.67,422.59,957.36,429.06Zm-18.71-2.67,14.24.05c-.31-4.21-2.93-6.11-6.79-6.11C941.84,420.33,939.37,422.64,938.65,426.39Z"
transform="translate(-205.53 -205.59)"
id="path125"
style="fill:#000000" />
<path
class="cls-1"
d="M968.6,433.23c1.29,2.83,2.67,4.57,7.5,4.57,2.73,0,5.09-.56,5.09-3.44,0-2.62-2-2.83-5.65-3.55-4.52-.87-9.1-2.05-9.1-7.14,0-4.78,4-7.2,8.95-7.2,5.19,0,8.58,2.62,10,6.58l-3.6,1.85c-1-2.47-2.37-4.57-6.53-4.57-2.67,0-4.57.87-4.57,3.34,0,1.85,1,2.41,4.88,3.18,4.47.88,9.87,1.75,9.87,7.51,0,5.19-4.27,7.3-9.92,7.3-5.35,0-9-2.62-10.54-6.58Z"
transform="translate(-205.53 -205.59)"
id="path127"
style="fill:#000000" />
<rect
class="cls-1"
x="308.37"
y="152.58"
width="137.05"
height="3.21"
id="rect129"
style="fill:#000000" />
<path
class="cls-1"
d="M1118.85,225.93V493.61H654.16V225.93h464.69m3.22-3.21H651v274.1h471.12V222.72Z"
transform="translate(-205.53 -205.59)"
id="path131"
style="fill:#000000" />
<polygon
class="cls-1"
points="59.96 119.92 38.55 119.92 38.55 168.1 38.55 188.45 59.96 188.45 102.79 188.45 102.79 168.1 59.96 168.1 59.96 119.92"
id="polygon133"
style="fill:#000000" />
<polygon
class="cls-1"
points="231.28 119.92 209.86 119.92 209.86 140.26 209.86 188.45 231.28 188.45 231.28 140.26 278.39 140.26 278.39 119.92 231.28 119.92"
id="polygon135"
style="fill:#000000" />
<circle
class="cls-1"
cx="253.58"
cy="162.75"
r="12.85"
id="circle137"
style="fill:#000000" />
<path
class="cls-1"
d="M381.13,329.51l-21.27,36.83L338.3,329l-2-3.49h-19.4V394H338.3V377.16c0-6.67-2.19-17.39-2.19-17.39l12.68,25.76,2.4,4.16h17.22l2.46-4.29L383.27,360s-2.14,10.52-2.14,16.92V394h21.41V325.51h-19.1Z"
transform="translate(-205.53 -205.59)"
id="path139"
style="fill:#000000" />
<path
class="cls-1"
d="M359.71,205.59A154.18,154.18,0,1,0,513.9,359.77,154.18,154.18,0,0,0,359.71,205.59Zm0,305.24c-83.29,0-151.06-67.77-151.06-151.06s67.77-151.06,151.06-151.06,151.06,67.77,151.06,151.06S443,510.83,359.71,510.83Z"
transform="translate(-205.53 -205.59)"
id="path141"
style="fill:#000000" />
</svg>

After

Width:  |  Height:  |  Size: 13 KiB

BIN
src/logo_ocp.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

38
src/main.tex

@ -0,0 +1,38 @@
\documentclass[12pt]{beamer}
\usetheme[]{metropolis}
\usepackage{graphicx} % to include img
\usepackage[notransparent]{svg} % to include svg
\usepackage{minted} % source code highlighting
\setminted{autogobble=true} % remove unneeded indentation
\setmainfont{Linux Libertine O}
\setsansfont{Linux Biolinum O}
\setmonofont{RobotoMono Nerd Font}
\newcommand{\auth}[3]{#1 {\tiny{\texttt{<#2>}}}\textsuperscript{#3}}
\title{Wasocaml: compiling OCaml to WebAssembly}
\author{\auth{Léo Andrès}{l@ndrs.fr}{1, 2}\\
\auth{Pierre Chambart}{pierre.chambart@ocamlpro.com}{1}\\
\auth{Jean-Christophe Filliâtre}{jean-christophe.filliatre@cnrs.fr}{2}
}
\date{August 2023 -- IFL'23 -- Braga}
\institute{1. OCamlPro\\
2. Université Paris-Saclay, CNRS, ENS Paris-Saclay, Inria, Laboratoire Méthodes Formelles\\
\\
\includegraphics[width=16.5em]{logo_ocp.png}
\hspace{5em}
\includesvg[width=14.5em]{logo_lmf}
}
\begin{document}
\begin{frame}
\titlepage{}
\end{frame}
\input{slides.tex}
\end{document}

BIN
src/ocaml_chain.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

319
src/slides.tex

@ -0,0 +1,319 @@
\newcommand{\ocaml}[1]{\mintinline{ocaml}{#1}}
\newcommand{\wasm}[1]{\mintinline{wast}{#1}}
% TODO: about part (me, ocp, lmf) ?
% JavaScript / Wasm
\begin{frame}
JavaScript:
\begin{itemize}
\item bad/unpredictable performances
\item unsafe
\end{itemize}
WebAssembly (Wasm) is safe and has good/predictable performances, used:
\begin{itemize}
\item on the Web: V8, SpiderMonkey
\item on the Cloud: Fastly, CloudFlare
\item as a portable binary format
\item to interface with C from other languages
\end{itemize}
\end{frame}
% Wasm1
% TODO: talk about the embedder somewhere
\begin{frame}
Wasm1:
\begin{itemize}
\item compact binary format (Wasm) and text format (Wat)
\item functions
\item stack machine (stack can not be inspected)
\item static verification and typecheck (few dynamic tests)
\item one \wasm{memory} per module
\item only scalar types: \wasm{i32}, \wasm{i64}, \wasm{f32}, \wasm{f64}
\item only exported items can be used by other modules
\item can be seen as a simplified C
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\begin{minted}{wast}
(func $fact (param $x i32) (result i32)
(if (i32.eq (local.get $x) (i32.const 0))
(then (i32.const 1))
(else
(i32.mul
(local.get $x)
(call $fact
(i32.sub
(local.get $x)
(i32.const 1)))))))
\end{minted}
\end{frame}
\begin{frame}[fragile]
\begin{minted}{wast}
(func $fact (param $x i32) (result i32)
i32.const 0
local.get $x
i32.eq
(if
(then i32.const 1)
(else
local.get $x
i32.const 1
i32.sub
call $fact
local.get $x
i32.mul)))
\end{minted}
\end{frame}
% C/C++/Rust to Wasm1
\begin{frame}
Compiling runtime-free languages such as C/C++/Rust to Wasm is straightforward.\\
Some primitives such as \mintinline{c}{malloc} need to be rewritten in Wasm and provided by the compiler.
\end{frame}
% TODO: how do GC work
% GC languages to Wasm1
\begin{frame}
Compiling garbage-collected languages to Wasm1 is more involved:
\begin{itemize}
\item runtime must be rewritten, or compiled from C to Wasm: difficult because of Wasm safety properties
\item GC need to inspect the stack to find roots, not possible in Wasm, requires a shallow stack
\item interactions with the GC of the embedder are difficult (cycles can't be collected)
\end{itemize}
Need for a proper GC in Wasm.
\end{frame}
\begin{frame}
Requirements:
\begin{itemize}
\item safe and fast
\item do not make Wasm1 code slower
\item fit with many existing value representation strategies
\end{itemize}
\end{frame}
% Flambda1
\begin{frame}
\includegraphics[width=25em]{ocaml_chain.png}
\end{frame}
\begin{frame}
\begin{center}
\begin{description}
\item[Lambda] closures are still implicit, not optimised
\item[Bytecode] not enough optimised
\item[Clambda] code pointers and values mixed in closures
\item[Cmm] even more low-level (pointer arithmetic)
\item[Flambda] our choice for the first prototype
\item[Flambda2] our choice for the future
\end{description}
\end{center}
Flambda:
\begin{itemize}
\item ANF
\item explicit closures
\item high-level: works on abstract values and not directly on the actual memory layout (this is done by \texttt{Cmm})
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\begin{minted}{ocaml}
let f = print_int
let rec iter f l =
match l with
| [] -> ()
| hd :: tl ->
f hd;
iter f tl
let () =
let iter_print = iter f in
iter_print [2; 1]
\end{minted}
\end{frame}
\begin{frame}[fragile]
\begin{minted}{ocaml}
let f =
let s =
make_closures
| cl_f { x } env -> print_int x
with vars
end
in
project_closure cl_f from s
in
let iter =
let set =
make_closures
| cl_iter { f } env ->
let otherset =
make_closures
| cl_iter_f { l } envtwo ->
switch l
with int
| 0 -> const 0
with tag
| 0 ->
let x = get_field 0 l in
let f = project_var f from envtwo in
let dummy = f x in
let tl = get_field 1 l in
envtwo tl
end
with vars
| f -> f
end
in
project_closure cl_iter_f from otherset
with vars
end
in
project_closure cl_iter from set
in
let lempty = const 0 in
let one = const 1 in
let lone = make_block 0 one lempty in
let two = const 2 in
let ltwo = make_block 0 two lone in
let iter_print = iter f in
iter_print ltwo
\end{minted}
\end{frame}
% Compiling Flambda1 to WasmGC
\begin{frame}
Value representation strategies:
\begin{itemize}
\item monomorphisation (C++/Rust)
\item boxing everything (Python)
\item boxing only in polymorphic places (Java)
\item pointer-tagging: unboxing small scalars (OCaml)
\item tagged union (Lua)
% TODO: add it back ?
%\item type-passing (TIL, AliceML)
\item runtime monomorphisation (F\#)
\end{itemize}
\end{frame}
\begin{frame}
uniform representation using a tagged single machine word:
\begin{center}
\includegraphics[width=10em]{figure_ocaml_bit1.mps}
\end{center}
if $b_{0} = 0$, the value is a pointer to a heap-allocated block:
\begin{center}
\includegraphics[width=20em]{figure_ocaml_bit2.mps}
\end{center}
if $b_{1} = 1$, the $n - 1$ most significant bits are a small scalar:
\begin{center}
\includegraphics[width=20em]{figure_ocaml_bit3.mps}
\end{center}
small scalars: \ocaml{bool}, \ocaml{char}, \ocaml{int}, constant constructors of ADTs
\end{frame}
\begin{frame}
A type system to represent values from any kind of source language is too complex.\\
Instead, WasmGC introduces reference types and a subtyping hierarchy:
\begin{center}
\includegraphics[width=20em]{figure_type_hierarchy.mps}
\end{center}
The hierarchy tells which casts are allowed.\\
Upcasts are implicit.\\
Downcasts are explicit and lead to runtime errors if incorrect.\\
Casts are cheap.\\
Possible to dynamically test for compatibility.
\end{frame}
\begin{frame}
\begin{center}
\includegraphics[width=20em]{figure_type_hierarchy.mps}
\end{center}
Uniform representation through \wasm{eqref} (\ocaml{==} operator).\\
Can't be more precise because of \ocaml{Obj.magic}, GADTs and types that have scalar/blocks values.\\
Small scalars are \wasm{i31ref}.\\
OCaml arrays are \wasm{array}.\\
Others heap-allocated blocks are \wasm{struct} or \wasm{array}.
\end{frame}
% TODO: example with i31 ?
\begin{frame}
In \ocaml{get_field n x} the type of \ocaml{x} is unknown.\\
Could propagate more types but breaks some optimisations.\\
Not enough because of \ocaml{Obj.field}.\\
All we know is that \ocaml{x} is a block of size $n + 1$ at least.
\end{frame}
\begin{frame}[fragile]
Blocks as structs:
\begin{minted}{wast}
(type $block1 (struct
(field $tag i8)
(field $field0 eqref)))
(type $block2 (sub $block1) (struct
(field $tag i8)
(field $field0 eqref)
(field $field1 eqref)))
;; and so on...
\end{minted}
We cast \ocaml{x} to \wasm{$block}$(n+1)$.
\end{frame}
\begin{frame}[fragile]
swrup/ocaml-emoji:
\setmonofont{Symbola}
\begin{minted}{ocaml}
let fox = "🦊"
let framed_picture = "🖼"
let free_button = "🆓"
let french_fries = "🍟"
let fried_shrimp = "🍤"
let frog = "🐸"
let front_facing_baby_chick = "🐥"
\end{minted}
\setmonofont{RobotoMono Nerd Font}
Modules represented as blocks: each toplevel value is a field.
\begin{center}
\emph{too long subtyping chain}
\end{center}
We have two variations to avoid this problem, not implemented yet.
% TODO: ^ split on many slides
\end{frame}
\begin{frame}
Blocks as arrays: an array of \wasm{eqref} with the tag stored at position 0.
\end{frame}
% Formalized compilation
% Wasocaml
% Benchmarks
% FFI
% Effects
% Related works
% Future works
% Symbolic execution
Loading…
Cancel
Save