Browse Source

first commit

cleanup
zapashcanon 3 years ago
commit
b029115577
Signed by untrusted user who does not match committer: zapashcanon GPG Key ID: 8981C3C62D1D28F1
  1. 1
      .gitignore
  2. 61
      .ocamlformat
  3. 1
      CHANGES.md
  4. 8
      LICENSE.md
  5. 40
      README.md
  6. 3
      doc/dune
  7. 19
      doc/index.mld
  8. 26
      dune-project
  9. 3
      example/dune
  10. 1
      example/main.ml
  11. 8
      src/dune
  12. 24
      src/pp.ml
  13. 281
      src/types.ml
  14. 1
      src/woi.ml
  15. 3
      test/dune
  16. 1
      test/main.ml
  17. 28
      woi.opam

1
.gitignore

@ -0,0 +1 @@
_build

61
.ocamlformat

@ -0,0 +1,61 @@
version=0.19.0
align-cases=false
align-constructors-decl=false
align-variants-decl=false
assignment-operator=end-line
break-before-in=fit-or-vertical
break-cases=all
break-collection-expressions=fit-or-vertical
break-fun-decl=wrap
break-fun-sig=wrap
break-infix=wrap
break-infix-before-func=false
break-separators=before
break-sequences=true
break-string-literals=auto
break-struct=force
cases-exp-indent=2
cases-matching-exp-indent=normal
disambiguate-non-breaking-match=false
doc-comments=before
doc-comments-padding=2
doc-comments-tag-only=default
dock-collection-brackets=false
exp-grouping=preserve
extension-indent=2
field-space=loose
function-indent=2
function-indent-nested=never
if-then-else=k-r
indent-after-in=0
indicate-multiline-delimiters=space
indicate-nested-or-patterns=unsafe-no
infix-precedence=indent
leading-nested-match-parens=false
let-and=sparse
let-binding-indent=2
let-binding-spacing=compact
let-module=compact
margin=80
match-indent=0
match-indent-nested=never
max-indent=68
module-item-spacing=sparse
nested-match=wrap
ocp-indent-compat=false
parens-ite=false
parens-tuple=always
parens-tuple-patterns=multi-line-only
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
stritem-extension-indent=0
type-decl=sparse
type-decl-indent=2
wrap-comments=false
wrap-fun-args=true

1
CHANGES.md

@ -0,0 +1 @@
## unreleased

8
LICENSE.md

@ -0,0 +1,8 @@
The ISC License (ISC)
=====================
Copyright © 2021, TODO
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

40
README.md

@ -0,0 +1,40 @@
# woi
woi is an [OCaml] executable/library to TODO.
## Installation
`woi` can be installed with [opam]:
```sh
opam install woi
```
If you don't have `opam`, you can install it following the [how to install opam] guide.
If you can't or don't want to use `opam`, consult the [opam file] for build instructions.
## Quickstart
```ocaml
let () = Format.printf "TODO@."
```
For more, have a look at the [example] folder, at the [documentation] or at the [test suite].
## About
- [LICENSE]
- [CHANGELOG]
[CHANGELOG]: ./CHANGES.md
[example]: ./example/
[LICENSE]: ./LICENSE.md
[opam file]: ./woi.opam
[test suite]: ./test/
[documentation]: TODO
[how to install opam]: https://opam.ocaml.org/doc/Install.html
[OCaml]: https://ocaml.org
[opam]: https://opam.ocaml.org/
[woi]: TODO

3
doc/dune

@ -0,0 +1,3 @@
(documentation
(package woi)
(mld_files index))

19
doc/index.mld

@ -0,0 +1,19 @@
{0 woi}
{{:https://TODO} woi} is an {{:https://ocaml.org} OCaml} library/executable to TODO.
{1:api API}
{!modules:
Woi
}
{1:private_api Private API}
You shouldn't have to use any of these modules, they're used internally only.
{!modules:
TODO
}

26
dune-project

@ -0,0 +1,26 @@
(lang dune 2.8)
(name woi)
(license ISC)
(authors "TODO")
(maintainers "TODO")
;(source
; (github TODO/woi))
(generate_opam_files true)
(package
(name woi)
(synopsis "OCaml library/executable to TODO")
(description "woi is an OCaml library/executable to TODO.")
(tags
(woi TODO TODO TODO TODO))
(depends
(ocaml
(>= 4.08))
(integers
(>= 0.5.1))))

3
example/dune

@ -0,0 +1,3 @@
(executable
(name main)
(modules main))

1
example/main.ml

@ -0,0 +1 @@
let () = Format.printf "TODO@."

8
src/dune

@ -0,0 +1,8 @@
(library
(name woi)
(modules pp types)
(libraries integers))
(executable
(name woi)
(modules woi))

24
src/pp.ml

@ -0,0 +1,24 @@
open Types
let datas _fmt _datas = assert false
let elems _fmt _elems = assert false
let start _fmt _start = assert false
let exports _fmt _exports = assert false
let globals _fmt _globals = assert false
let mems _fmt _mems = assert false
let tables _fmt _tables = assert false
let funcs _fmt _funcs = assert false
let imports _fmt _imports = assert false
let types _fmt _types = assert false
let module_fields fmt m =
Format.fprintf fmt
"%a@.%a@.%a@.%a@%a@%a@%a@%a@%a@%a@." types m.types imports m.imports funcs m.funcs tables m.tables mems m.mems globals m.globals exports m.exports start m.start elems m.elems datas m.datas
let id fmt = function
| None -> ()
| Some id ->
Format.fprintf fmt "$%s" (String.init (List.length id) (fun i -> List.nth id i))
let module_ fmt m =
Format.fprintf fmt "(module %a@.%a)" id m.id module_fields m

281
src/types.ml

@ -0,0 +1,281 @@
(** Structure *)
(** Values *)
type nonrec byte = Char.t
type nonrec u8 = Unsigned.UInt8.t
type nonrec u16 = Unsigned.UInt16.t
type nonrec u32 = Unsigned.UInt32.t
type nonrec u64 = Unsigned.UInt64.t
(* TODO: no Int8 module ? *)
type nonrec s8 = Signed.Int32.t
(* TODO: no Int16 module ? *)
type nonrec s16 = Signed.Int32.t
type nonrec s32 = Signed.Int32.t
type nonrec s64 = Signed.Int64.t
type nonrec i8 = s8
type nonrec i16 = s16
type nonrec i32 = s32
type nonrec i64 = s64
(* TODO: Float32 module ? *)
type nonrec f32 = Float.t
type nonrec f64 = Float.t
(* TODO: stop being dumb :-) *)
type nonrec char_ = Uchar.t
type nonrec name = char_ list
(* TODO: this should only be 0..9 A..Z a..Z ! # $ % & ′ * + - . / : < = > ? @ \ ^ _ ` | ~ *)
type id_char = Char.t
type nonrec id = id_char list
(** Types *)
type nonrec num_type =
| I32 | I64 | F32 | F64
let bit_width = function
| I32 | F32 -> 32
| I64 | F64 -> 64
type nonrec ref_type =
| Func_ref | Extern_ref
(* TODO: gadt ? *)
type nonrec val_type =
| Num_type of num_type
| Ref_type of ref_type
type nonrec result_type = val_type list
type nonrec func_type = result_type * result_type
type nonrec limits = {
min : u32;
max : u32 option;
}
type nonrec mem_type = limits
(* TODO: the spec is weird, shouldn't it be just `limits` ? is it really a product ? *)
type nonrec table_type = limits * ref_type
type nonrec mut =
| Const | Var
type nonrec global_type = mut * val_type
(* TODO: gadt ? *)
type nonrec extern_type =
| Func of func_type
| Table of table_type
| Mem of mem_type
| Global of global_type
(** Instructions *)
type nonrec nn = | I32 | I64
type nonrec mm = nn
type nonrec sx = U | S
type nonrec iunop =
| Clz | Ctz | Popcnt
type nonrec funop =
| Abs | Neg | Sqrt | Ceil | Floor | Trunc | Nearest
type nonrec ibinop =
| Add | Sub | Mul | Div of sx | Rem of sx | And | Or | Xor | Shl | Shr of sx | Rotl | Rotr
type nonrec fbinop =
| Add | Sub | Mul | Div | Min | Max | Copysign
type nonrec itestop =
| Eqz
type nonrec irelop =
| Eq | Ne | Lt of sx | Gt of sx | Le of sx | Ge of sx
type nonrec frelop =
| Eq | Ne | Lt | Gt | Le | Ge
type nonrec type_idx = u32
type nonrec func_idx = u32
type nonrec table_idx = u32
type nonrec mem_idx = u32
type nonrec global_idx = u32
type nonrec elem_idx = u32
type nonrec data_idx = u32
type nonrec local_idx = u32
type nonrec label_idx = u32
type memarg = {
offset: u32;
align: u32;
}
type block_type =
| Type_idx of type_idx
| Val_type of val_type option (* TODO: where does the option goes ? *)
type instr =
(* Numeric Instructions *)
| I32_const of i32
| I64_const of i64
| F32_const of f32
| F64_const of f64
| I_unop of nn * iunop
| F_unop of nn * funop
| I_binop of nn * ibinop
| F_binop of nn * fbinop
| I_testop of nn * itestop
| I_relop of nn * irelop
| F_relop of nn * frelop
| I_extend8_s of nn
| I_extend16_s of nn
| I64_extend32_s
| I32_wrap_i64
| I64_extend_i32 of sx
| I_trunc_f of nn * nn * sx
| I_trunc_sat_f of nn * nn * sx
| F32_demote_f64
| F64_promote_f32
| F_convert_i of nn * nn * sx
| I_reinterpret_f of nn * nn
| F_reinterpret_i of nn * nn
(* Reference instructions *)
| Ref_null of ref_type
| Ref_is_null
| Ref_func of func_idx
(* Parametric instructions *)
| Drop
| Select of (val_type list) option (* TODO: why is it a list and not just tuple ? *)
(* Variable instructions *)
| Local_get of local_idx
| Local_set of local_idx
| Local_tee of local_idx
| Global_get of global_idx
| Global_set of global_idx
(* Table instructions *)
| Table_get of table_idx
| Table_set of table_idx
| Table_size of table_idx
| Table_grow of table_idx
| Table_fill of table_idx
| Table_copy of table_idx * table_idx
| Table_init of table_idx * elem_idx
| Elem_drop of elem_idx
(* Memory instructions *)
| I_load of nn * memarg
| F_load of nn * memarg
| I_store of nn * memarg
| F_store of nn * memarg
| I_load8 of nn * sx * memarg
| I_load16 of nn * sx * memarg
| I64_load32 of sx * memarg
| I_store8 of nn * memarg
| I_store16 of nn * memarg
| I64_store32 of memarg
| Memory_size
| Memory_grow
| Memory_fill
| Memory_copy
| Memory_init of data_idx
| Data_drop of data_idx
(* Control instructions *)
| Nop
| Unreachable
| Block of block_type * (instr list)
| Loop of block_type * (instr list)
| If_else of block_type * (instr list) * (instr list)
| Br of label_idx
| Br_if of label_idx
| Br_table of (label_idx list) * label_idx
| Return
| Call of func_idx
| Call_indirect of table_idx * type_idx
type expr = instr list
(** Modules *)
type func = {
type_ : type_idx;
locals : val_type list;
body : expr;
}
type table = table_type
type mem = mem_type
type global = {
type_ : global_type;
init : expr;
}
type elem_mode =
| Passive
| Active of table_idx * expr (* table * offset *)
| Declarative
type elem = {
type_ : ref_type;
init: expr list;
mode : elem_mode
}
type data_mode =
| Passive
| Active of mem_idx * expr (* memory * offset *)
type data = {
init : byte list;
mode : data_mode;
}
type start = func_idx
type import_desc =
| Func of type_idx
| Table of table_type
| Mem of mem_type
| Global of global_type
type import = {
module_ : name;
name : name;
desc : import_desc;
}
type export_desc =
| Func of func_idx
| Table of table_idx
| Mem of mem_idx
| Global of global_idx
type export = {
name : name;
desc : export_desc;
}
type module_ = {
id : id option; (* only for text mode *)
types: func_type list;
funcs: func list;
tables: table list;
mems: mem list;
globals: global list;
elems: elem list;
datas: data list;
start: start option;
imports: import list;
exports: export list;
}

1
src/woi.ml

@ -0,0 +1 @@
let () = Format.printf "Hello!@."

3
test/dune

@ -0,0 +1,3 @@
(test
(name main)
(modules main))

1
test/main.ml

@ -0,0 +1 @@
let () = assert true (* TODO *)

28
woi.opam

@ -0,0 +1,28 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "OCaml library/executable to TODO"
description: "woi is an OCaml library/executable to TODO."
maintainer: ["TODO"]
authors: ["TODO"]
license: "ISC"
tags: ["woi" "TODO" "TODO" "TODO" "TODO"]
depends: [
"dune" {>= "2.8"}
"ocaml" {>= "4.08"}
"integers" {>= "0.5.1"}
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
Loading…
Cancel
Save