initial commit

This commit is contained in:
Alain Emilia Anna Zscheile 2024-02-22 23:10:54 +01:00
commit b1c99512da
7 changed files with 137 additions and 0 deletions

6
.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
/_build
/yanais.opam
*.cmi
*.cmx
*.exe
*.o

19
dune-project Normal file
View file

@ -0,0 +1,19 @@
(lang dune 2.7)
(using menhir 2.0)
(name yanaijepeux)
(version 0.0.1)
(authors "Alain Emilia Anna Zscheile <fogti+devel@ytrizja.de>")
(license "Apache-2.0 OR ISC")
(package
(name yanaijepeux)
(synopsis "Yanais-associated utilities")
(description "Yanais-associated utilities")
(depends
(gen (>= 0.5))
(integers (>= 0.2))
)
)
(generate_opam_files)

7
lib/dune Normal file
View file

@ -0,0 +1,7 @@
(library
(name yanaijepeux)
(public_name yanaijepeux)
(synopsis "Yanais-associated utilities")
(libraries))
(documentation)

45
lib/layout.ml Normal file
View file

@ -0,0 +1,45 @@
(** a memory layout *)
type t = {
size : int;
align_exp : char;
(** alignment = 1 << align_exp *)
}
open Int
let show x = "Layout { size = " ^ (string_of_int x.size) ^ "; align_exp = " ^ (Char.code x.align_exp |> string_of_int) ^ "}"
let alignment_of_exp x = shift_left 1 (Char.code x)
let alignment x = alignment_of_exp x.align_exp
let max_size_for_align_exp x =
let y = alignment_of_exp x in
let isz_max_sc = shift_right max_int 1 |> succ in
isz_max_sc - y
(** appends a layout to this one, returns new layout and the offset *)
let push orig next =
let align_exp = max (Char.code orig.align_exp) (Char.code next.align_exp) |> Char.chr in
let align_exp_cc = Char.code align_exp in
if (align_exp_cc >= 32) || (align_exp_cc < 0) then Option.none else
(* fill up ourselves so that the other element is correctly aligned *)
let smask_sh = alignment next in
let smask = pred smask_sh in
let smasked = logand orig.size smask in
(* align size *)
let size = if compare smasked zero == 0 then orig.size else (
add (sub orig.size smasked) smask_sh
) in
let offset = size in
let size = size + next.size in
if size <= max_size_for_align_exp align_exp
then Option.some ({ size; align_exp; }, offset)
else Option.none
(** finishes a layout by inserting padding at the end to ensure alignment *)
let finish orig = push orig { size = 0; align_exp = orig.align_exp }

17
lib/layout.mli Normal file
View file

@ -0,0 +1,17 @@
(** a memory layout *)
type t = {
size : int;
align_exp : char;
(** alignment = 1 << align_exp *)
}
val show : t -> string
val alignment : t -> int
(** appends a layout to this one, returns new layout and the offset *)
val push : t -> t -> (t * int) option
(** finishes a layout by inserting padding at the end to ensure alignment (might fail when overflowing) *)
val finish : t -> (t * int) option

16
lib/stackAction.ml Normal file
View file

@ -0,0 +1,16 @@
(** A stack action (pop is run first, then push sequentially) *)
type 'a t =
{ pop : int
; push : 'a list
}
let merge lhs rhs =
(* merge lhs.push and rhs.pop first *)
let rec compensate push pop = match (push, pop) with
| (_, 0) -> (push, pop)
| ([], _) -> (push, pop)
| (_::xs, _) -> compensate xs (pop - 1)
in let (push, pop) = compensate lhs.push rhs.pop in
{ pop = lhs.pop + pop; push = List.append push rhs.push; }
let empty = { pop = 0; push = []; }

27
yanaijepeux.opam Normal file
View file

@ -0,0 +1,27 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.0.1"
synopsis: "Yanais-associated utilities"
description: "Yanais-associated utilities"
authors: ["Alain Emilia Anna Zscheile <fogti+devel@ytrizja.de>"]
license: "Apache-2.0 OR ISC"
depends: [
"dune" {>= "2.7"}
"gen" {>= "0.5"}
"integers" {>= "0.2"}
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]