Skip to content

capnproto ocapn flailing in ocaml (WIP) #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions packages/ocproto/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Contributing - Design Notes

## see playgroud PR

notes are moving to https://github.com/endojs/playground/pull/9

## ocaml.org curl bash

```
bash -c "sh <(curl -fsSL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh)"
opam init
```

hm... `Do you want opam to modify ~/.profile?`
I'd rather use direnv. Yay! it's a supported option: [Using direnv](https://ocaml.org/docs/opam-path#using-direnv).

... ocaml-base-compiler.5.1.1 ...

```
eval $(opam env --switch=default)
```

devtools:

```
opam install ocaml-lsp-server odoc ocamlformat utop
```

195 dependencies... pretty quick, though...

```
opam exec -- dune init proj ocproto
```

... [OCaml Platform \- Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=ocamllabs.ocaml-platform)

```
dune build --watch --terminal-persistence=clear-on-rebuild
```

crikey! that was fast.

## Road not taken: opam-nix

Following a [Feb 2023 item on opam-nix](https://www.tweag.io/blog/2023-02-16-opam-nix/), we begin with:

```console
$ nix flake init -t github:tweag/opam-nix
$ git add flake.nix
```

But then `nix develop` failed with `error: attribute 'ocproto' missing`.
4 changes: 4 additions & 0 deletions packages/ocproto/bin/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(executable
(public_name ocproto)
(name main)
(libraries ocproto))
5 changes: 5 additions & 0 deletions packages/ocproto/bin/main.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let () = print_endline "Hello, World!"

open Ocproto

let () = print_endline (Ocapnimpl.show Ocapnimpl.val1)
26 changes: 26 additions & 0 deletions packages/ocproto/dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(lang dune 3.14)

(name ocproto)

(generate_opam_files true)

(source
(github username/reponame))

(authors "Author Name")

(maintainers "Maintainer Name")

(license LICENSE)

(documentation https://url/to/documentation)

(package
(name ocproto)
(synopsis "A short synopsis")
(description "A longer description")
(depends ocaml dune)
(tags
(topics "to describe" your project)))

; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project
3 changes: 3 additions & 0 deletions packages/ocproto/lib/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(library
(name ocproto)
(libraries capnp))
53 changes: 53 additions & 0 deletions packages/ocproto/lib/ocapn.capnp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# ocapn.capnp
@0xcd301da1d95b8242;

struct Value {
union {
## Atoms ##

undefined @0 :Void;
null @1 :Void;
bool @2 :Bool;
float64 @3 :Float64;

unsignedInt @4 :Data;
# Non-negative integer, in big-endian format
negativeInt @5 :Data;
# Negative integer. value is `-1 - n`, where `n`
# is the data interpreted as an unsigned big-endian integer.

string @6 :Text;
byteString @7 :Data;
symbol @8 :Text; # Might be removed, pending #46.

## Containers ##

list @9 :List(Value);

struct @10 :List(StructField);
# Duplicate keys are not allowed; will need to enforce this at a higher level
# of abstraction.

tagged :group {
label @11 :Text;
value @12 :Value;
}

capability @13 :Cap;

error @14 :Error;
}
}

struct StructField {
key @0 :Text;
value @1 :Value;
}

interface Cap {
# TODO
}

struct Error {
# TODO, pending #10.
}
Loading