initial commit

This commit is contained in:
Alain Emilia Anna Zscheile 2024-02-22 23:10:54 +01:00
commit 414cc870c4
6 changed files with 119 additions and 0 deletions

6
.gitignore vendored Normal file
View file

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

21
dune-project Normal file
View file

@ -0,0 +1,21 @@
(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))
(sedlex (>= 3.0))
(uunf (>= 15.0))
)
)
(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)

40
lib/layout.ml Normal file
View file

@ -0,0 +1,40 @@
(** a memory layout *)
type t = {
size : int;
(* alignment = 1 << align_exp *)
align_exp : char;
}
open 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
(* 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 }

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 = []; }

29
yanaijepeux.opam Normal file
View file

@ -0,0 +1,29 @@
# 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"}
"sedlex" {>= "3.0"}
"uunf" {>= "15.0"}
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]