Browse Source

first commit

main
zapashcanon 3 months ago
commit
8126ba5bda
Signed by: zapashcanon GPG Key ID: 8981C3C62D1D28F1
  1. 1
      .gitignore
  2. 43
      .ocamlformat
  3. 3
      dune-project
  4. 29
      src/article.tex
  5. 171
      src/bib.bib
  6. 42
      src/dune
  7. 98
      src/flambda_core_ast.ml
  8. 28
      src/main.tex
  9. 44
      src/packages.tex

1
.gitignore

@ -0,0 +1 @@
_build

43
.ocamlformat

@ -0,0 +1,43 @@
version=0.24.1
assignment-operator=end-line
break-cases=fit
break-fun-decl=wrap
break-fun-sig=wrap
break-infix=wrap
break-infix-before-func=false
break-separators=before
break-sequences=true
cases-exp-indent=2
cases-matching-exp-indent=normal
doc-comments=before
doc-comments-padding=2
doc-comments-tag-only=default
dock-collection-brackets=false
exp-grouping=preserve
field-space=loose
if-then-else=compact
indicate-multiline-delimiters=space
indicate-nested-or-patterns=unsafe-no
infix-precedence=indent
leading-nested-match-parens=false
let-and=sparse
let-binding-spacing=compact
let-module=compact
margin=80
max-indent=2
module-item-spacing=sparse
ocaml-version=4.14.0
ocp-indent-compat=false
parens-ite=false
parens-tuple=always
parse-docstrings=true
sequence-blank-line=preserve-one
sequence-style=terminator
single-case=compact
space-around-arrays=true
space-around-lists=true
space-around-records=true
space-around-variants=true
type-decl=sparse
wrap-comments=false
wrap-fun-args=true

3
dune-project

@ -0,0 +1,3 @@
(lang dune 3.0)
(using mdx 0.2)

29
src/article.tex

@ -0,0 +1,29 @@
\section{Core Flambda}
\subsection{Syntax}
\begin{align*}
&\text{(variable identifiers)} &v ::=&~string \\
&\text{(terms)} &t ::=&~~v \\
& & &| \texttt{ let } v \texttt{ = } named \texttt{ in } t \\
& & &|~v \texttt{ <- } v \texttt{;} \\
& & &|~v~v \\
& & &| \texttt{ if } v \texttt{ then } t \texttt{ else } t \texttt{ end }\\
& & &| \texttt{ switch } v \texttt{ with }\\
& & &~~~~(\texttt{ | int } int \texttt{ -> } t)^*\\
& & &~~~~(\texttt{ | tag } int \texttt{ -> } t)^*\\
& & &~~~~\texttt{end}\\
& & &| \texttt{ raise } v~v^* \texttt{;} \\
& & &| \texttt{ try } t \texttt{ catch } v~v^* \texttt{ -> } t \texttt{ end } \\
& & &| \texttt{ while } t \texttt{ do } t \texttt{ end } \\
&\text{(named values)} &named ::=&~ \texttt{ const } int\\
& & &|~v \texttt{ - } v \\
& & &|~v \texttt{ == } v \\
& & &| \texttt{ get\_field } int ~ v \\
& & &| \texttt{ make\_block } int ~ v^* \\
& & &| \texttt{ make\_closures } (\texttt { | } f)^* \texttt{ with vars } (\texttt{ | } v \texttt{ -> } v)^* \texttt{ end } \\
& & &| \texttt{ project\_closure } v \texttt{ from } v \\
& & &| \texttt{ project\_var } v \texttt{ from } v \\
& & &| \texttt{ move\_within\_closures } v~v\\
&\text{(closures)} &f ::=&~ v \texttt{ \{ } v \texttt{ \} } v \texttt{ -> } t \\
\end{align*}

171
src/bib.bib

@ -0,0 +1,171 @@
@incollection{SY74,
title={A survey of extensible programming languages},
author={Solntseff, Nf and Yezerski, Alexander},
booktitle={International Tracts in Computer Science and Technology and Their Application},
volume={7},
pages={267--307},
year={1974},
publisher={Elsevier}
}
@techreport{ND79,
title={RED language reference manual},
author={Nestor, John and Deusen, Mary Van},
year={1979},
institution={INTERMETRICS INC CAMBRIDGE MA}
}
@article{Bar80,
title={An overview of Ada},
author={Barnes, John G. P.},
journal={Software: Practice and Experience},
volume={10},
number={11},
pages={851--887},
year={1980},
publisher={Wiley Online Library}
}
@article{SW87,
title={The C preprocessor},
author={Stallman, Richard M and Weinberg, Zachary},
journal={Free Software Foundation},
pages={8},
year={1987}
}
@inproceedings{Str88,
title={Parameterized Types for C++.},
author={Stroustrup, Bjarne},
booktitle={C++ Conference},
pages={1--18},
year={1988}
}
@article{Bra+98,
title={Making the future safe for the past: Adding genericity to the Java programming language},
author={Bracha, Gilad and Odersky, Martin and Stoutamire, David and Wadler, Philip},
journal={Acm sigplan notices},
volume={33},
number={10},
pages={183--200},
year={1998},
publisher={ACM New York, NY, USA}
}
@book{Oka99,
title = {Purely functional data structures},
author = {Okasaki, Chris},
year = {1999},
publisher = {Cambridge University Press}
}
@article{KS01,
doi = {10.1145/381694.378797},
url = {https://doi.org/10.1145/381694.378797},
year = {2001},
month = may,
publisher = {Association for Computing Machinery ({ACM})},
volume = {36},
number = {5},
pages = {1--12},
author = {Andrew Kennedy and Don Syme},
title = {Design and implementation of generics for the .{NET} Common language runtime},
journal = {{ACM} {SIGPLAN} Notices}
}
@article{EBN02,
title={An empirical analysis of C preprocessor use},
author={Ernst, Michael D. and Badros, Greg J. and Notkin, David},
journal={IEEE Transactions on Software Engineering},
volume={28},
number={12},
pages={1146--1170},
year={2002},
publisher={IEEE}
}
@techreport{BP11,
title = {Expressing Polymorphic Types in a Many-Sorted Language},
author = {Bobot, François and Paskevich, Andrei},
url = {https://hal.inria.fr/inria-00591414},
year = {2011}
}
@misc{Reb17,
title = "SamR's Assorted Musings and Rants: Using macros for generic structures in C",
author = {Rebelsky, Samuel A.},
url = {https://rebelsky.cs.grinnell.edu/musings/cnix-macros-generics},
year = 2017
}
@misc{Con18,
title = "Guide to Rustc Development - Monomorphization",
author = {The Guide To Rustc Development Contributors},
url = {https://rustc-dev-guide.rust-lang.org/backend/monomorph.html},
year = 2018,
note = "Accessed: 2022-12-23"
}
@article{TAG18,
title={Safe low-level code generation in Coq using monomorphization and monadification},
author={Tanaka, Akira and Affeldt, Reynald and Garrigue, Jacques},
journal={Journal of Information Processing},
volume={26},
pages={54--72},
year={2018},
publisher={Information Processing Society of Japan}
}
@article{LS19,
title={A survey of metaprogramming languages},
author={Lilis, Yannis and Savidis, Anthony},
journal={ACM Computing Surveys (CSUR)},
volume={52},
number={6},
pages={1--39},
year={2019},
publisher={ACM New York, NY, USA}
}
@mastersthesis{Wo20,
author = "Wood, David",
title = "Polymorphisation: Improving Rust compilation times through intelligent monomorphisation",
school = "University of Glasgow",
year = 2020,
month = apr,
url = {https://davidtw.co/media/masters_dissertation.pdf}
}
@misc{Dev22,
title = "The Rust Language Reference - Procedural Macros",
author = {The Rust Project Developers},
url = {https://doc.rust-lang.org/reference/procedural-macros.html},
year = 2022
}
@misc{Fou22,
title = "String Mixins",
author = {D Language Foundation},
url = {https://dlang.org/articles/mixin.html},
year = 2022
}
@misc{Con22ppx,
title = "OCaml - Metaprogramming - PPXs",
author = {ocaml.org Contributors},
url = {https://ocaml.org/docs/metaprogramming#ppxs},
year = 2022
}
@codefragment{pyobject,
title = {CPython},
date = {2022},
url = {https://github.com/python/cpython/blob/main/Include/object.h},
subtitle = {PyObject header file},
swhid = {swh:1:cnt:3774f126730005469a7c3dc48bca0fd9a898b33f;
origin=https://github.com/python/cpython;
visit=swh:1:snp:413f8b76b7dd0aafb25c1451a4b43b824784cc4f;
anchor=swh:1:rev:84bc6a4f25fcf467813ee12b74118f7b1b54e285;
path=/Include/object.h}
}

42
src/dune

@ -0,0 +1,42 @@
(rule
(targets main.pdf)
(deps
article.tex
main.bbl
main.tex
packages.tex
)
(action
(pipe-outputs
(run texfot xelatex -halt-on-error -shell-escape main.tex)
(run sed "/\\/usr\\/bin\\/texfot:/d")
(run sed "/This is XeTeX/d")
(run sed "/LaTeX Warning: There were undefined references/d")
(run sed "/Package biblatex Warning/d")
(run sed "/Output written/d"))))
(rule
(targets main.bbl)
(deps bib.bib main.first.bcf)
(action
(run biber -quiet main.first.bcf --output-file main.bbl)))
(rule
(targets main.first.bcf)
(deps main.bcf)
(action
(run mv main.bcf main.first.bcf)))
(rule
(targets main.bcf)
(deps
article.tex
main.tex
packages.tex
)
(action
(run texfot xelatex -halt-on-error -shell-escape main.tex)))
(library
(name wasocaml_core)
(modules flambda_core_ast))

98
src/flambda_core_ast.ml

@ -0,0 +1,98 @@
type id = string
type term =
| Variable of id
| Let of id * named * term
| Mutate of id * id
| Apply of id * id
| If_then_else of id * term * term
| Switch of id * (int * term) list * (int * term) list
| Raise of id * id list
| Try_catch of term * id * id list * term
| While of term * term
and named =
| Const of int
| Sub of id * id
| Physical_eq of id * id
| Get_field of int * id
| Make_block of int * id list
| Make_closures of closure list * (id * id) list
| Project_closure of id * id
| Project_var of id * id
| Move_within_closure of id * id
and closure = id * id * id * term
let pp = Format.fprintf
let pp_id fmt id = Format.pp_print_string fmt id
let pp_ids fmt ids =
Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt " ")
pp_id fmt ids
let rec pp_term fmt = function
| Variable id -> pp_id fmt id
| Let (id, named, t) ->
pp fmt "let %a = %a in %a" pp_id id pp_named named pp_term t
| Mutate (id, id') -> pp fmt "%a <- %a;" pp_id id pp_id id'
| Apply (id, id') -> pp fmt "%a %a" pp_id id pp_id id'
| If_then_else (id, t, t') ->
pp fmt "if %a then %a else %a end" pp_id id pp_term t pp_term t'
| Switch (id, int_cases, tag_cases) ->
let pp_int_case fmt (n, t) =
Format.fprintf fmt "| int %d -> %a" n pp_term t
in
let pp_int_cases fmt cases =
Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt "@\n")
pp_int_case fmt cases
in
let pp_tag_case fmt (n, t) =
Format.fprintf fmt "| tag %d -> %a" n pp_term t
in
let pp_tag_cases fmt cases =
Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt "@\n")
pp_tag_case fmt cases
in
pp fmt "switch %a with %a %a end" pp_id id pp_int_cases int_cases
pp_tag_cases tag_cases
| Raise (id, ids) -> pp fmt "raise %a %a;" pp_id id pp_ids ids
| Try_catch (t, id, ids, t') ->
pp fmt "try %a catch %a %a -> %a end" pp_term t pp_id id pp_ids ids pp_term
t'
| While (t, t') -> pp fmt "while %a do %a end" pp_term t pp_term t'
and pp_named fmt = function
| Const n -> pp fmt "const %d" n
| Sub (id, id') -> pp fmt "%a - %a" pp_id id pp_id id'
| Physical_eq (id, id') -> pp fmt "%a == %a" pp_id id pp_id id'
| Get_field (n, id) -> pp fmt "get_field %d %a" n pp_id id
| Make_block (n, ids) -> pp fmt "make_block %d %a" n pp_ids ids
| Make_closures (closures, env) ->
let pp_closure fmt closure = Format.fprintf fmt "| %a" pp_closure closure in
let pp_closures fmt closures =
Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt "@\n")
pp_closure fmt closures
in
let pp_v_env fmt (id, id') =
Format.fprintf fmt "| %a -> %a" pp_id id pp_id id'
in
let pp_env fmt env =
Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt "@\n")
pp_v_env fmt env
in
pp fmt "make_closures %a with vars %a end" pp_closures closures pp_env env
| Project_closure (v, v') ->
pp fmt "project_closure %a from %a" pp_id v pp_id v'
| Project_var (v, v') -> pp fmt "project_var %a from %a" pp_id v pp_id v'
| Move_within_closure (v, v') ->
pp fmt "move_within_closure %a %a" pp_id v pp_id v'
and pp_closure fmt (id, id', id'', t) =
pp fmt "%a { %a } %a -> %a" pp_id id pp_id id' pp_id id'' pp_term t

28
src/main.tex

@ -0,0 +1,28 @@
\documentclass{article}
\input{packages.tex}
\title{Compiling OCaml to Wasm-GC}
\author[1,2]{Léo Andrès}
\affil[1]{OCamlPro SAS, 21 rue de Châtillon, 75014 Paris, France}
\affil[2]{Université Paris-Saclay, CNRS, ENS Paris-Saclay, Inria, Laboratoire Méthodes Formelles, 91190 Gif-sur-Yvette, France}
\bibliography{bib}
\begin{document}
\maketitle
\begin{abstract}
Lorem ipsum et dolor sit amet.
\end{abstract}
\tableofcontents
\input{article.tex}
\printbibliography{}
\end{document}

44
src/packages.tex

@ -0,0 +1,44 @@
\usepackage[english]{babel}
\usepackage{fontspec} % encoding
\usepackage{graphicx} % to include img
\usepackage[notransparent]{svg}
\usepackage{color} % color power
\usepackage{hyperref} % internal and external links (e.g. mail, www)
\usepackage{authblk} % author affiliation handling
\renewcommand\Affilfont{\itshape\small}
\usepackage{fancyvrb} % source code
\usepackage[most]{tcolorbox}
\definecolor{darkBackground}{HTML}{282c34} % source code background
\tcbset{colback=darkBackground}
\usepackage[
autolang=other,
backend=biber, % choix de l'outil de traitement
backref=true, % liens dans la bibliographie pour remonter dans le texte
backrefstyle=none, % afficher toutes les utilisations de la référence
bibstyle=alphabetic, % style pour les clés des références dans la bibliographie : [initialesAnnée]
citestyle=alphabetic, % style pour les clés des références dans le texte : [initialesAnnée]
%datamodel=software, % swh
sorting=ynt, % bibliographie triée par année, nom, titre
]{biblatex} % support des bibliographies
\usepackage{software-biblatex}
\ExecuteBibliographyOptions{
swhid=true,
shortswhid=true,
swlabels=true,
vcs=true,
license=false
}
\setmainfont{Linux Libertine O}
\setsansfont{Linux Biolinum O}
%\setsansfont{TeX Gyre Heros}
\setmonofont[Scale=MatchLowercase]{RobotoMono Nerd Font}
\hypersetup{colorlinks=true, pdfstartview=FitH}
Loading…
Cancel
Save