Skip to content
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

Protobuf [WIP] #12

Merged
merged 15 commits into from
Jun 20, 2018
Merged
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
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_build
_opam*
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ services:
- docker
env:
global:
- PINS="lambda:. crowbar:--dev"
- PINS="lambda:. lambda-protobuf:. crowbar:--dev"
- DISTRO="debian-stable"
matrix:
- PACKAGE="lambda" OCAML_VERSION="4.05.0"
- PACKAGE="lambda-protobuf" OCAML_VERSION="4.05.0"
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM ocaml/opam2:alpine-3.7

ENV OPAMYES=1

RUN opam pin add crowbar --dev -n
RUN opam install opam-depext
RUN opam depext -i jbuilder fmt logs lwt menhir higher ppx_deriving \
crowbar ocaml-protoc

COPY . /src
RUN sudo chown -R opam /src
WORKDIR /src

RUN opam exec -- make
14 changes: 14 additions & 0 deletions lambda-protobuf.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
opam-version: "1.2"
maintainer: "Thomas Gazagnaire <thomas@gazagnaire.org>"
authors: ["Thomas Gazagnaire" "Romain Calascibetta"]
homepage: "https://github.com/samoht/mirage-lambda"
license: "ISC"
dev-repo: "https://github.com/samoht/mirage-lambda.git"
bug-reports: "https://github.com/samoht/mirage-lambda/issues"

build: [ "jbuilder" "build" "-p" name "-j" jobs ]
depends: [
"jbuilder" {build}
"ocaml-protoc"
"lambda"
]
2 changes: 1 addition & 1 deletion lambda.opam
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license: "ISC"
dev-repo: "https://github.com/samoht/mirage-lambda.git"
bug-reports: "https://github.com/samoht/mirage-lambda/issues"

build: [ "jbuilder" "build" ]
build: [ "jbuilder" "build" "-p" name "-j" jobs ]
depends: [
"jbuilder" {build}
"fmt"
Expand Down
12 changes: 12 additions & 0 deletions proto/jbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(jbuild_version 1)

(rule
((targets (lambda_types.ml lambda_types.mli lambda_pb.ml lambda_pb.mli))
(deps (lambda.proto))
(action (run ocaml-protoc -binary -ml_out . lambda.proto))))

(library
((name lambda_protobuf)
(flags (:standard -w -30))
(public_name lambda-protobuf)
(libraries (lambda ocaml-protoc))))
196 changes: 196 additions & 0 deletions proto/lambda.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
syntax = "proto2";

message Type {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protoc complains about a missing line syntax = "proto2";.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted.

message Unit { }
message Int { }
message Int32 { }
message Int64 { }
message Bool { }
message String { }
message Lwt { }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to handle values of Lwt type? E.g. some block operations have lwt return types. Is the value serialization not implemented, yet, or am I overlooking something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to use Apply and Lwt (like Apply (Int, Lwt)). This about a limitation of the OCaml type-system (and the higher kind polymorphism). We can provide a sugar about that if you want.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks. Just to verify, would the following be a correct encoding of the program

λ (output_block : page_aligned_buffer).
  Block.read 42 output_block

(using the definitions from here)

lam {
  typ { abstract { witness: "Cstruct.t" } }
  var: "output_block"
  expr {
    app {
      a {
        app {
          a {
            prm {
              value {
                name: "Block.read"
                arguments { int64 { } }
                arguments { list { value { abstract { witness: "Cstruct.t" } } } }
                return {
                  apply {
                    a {
                      result { a { unit { } } b { abstract { witness: "Block.error" } } }
                    }
                    b { lwt { } }
                  }
                }
                smartptr: 4
              }
            }
          }
          b { val { value { int64 { value: 42 } } } }
        }
      }
      b { var { var: 0 } }
    }
  }
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly 👍 , as I said, we can provide a sugar and translate lwt { something } to apply { a { something } b { lwt { } } internally if it's better for you.

message List {
required Type value = 1;
}
message Array {
required Type value = 1;
}
message Option {
required Type value = 1;
}
message Apply {
required Type a = 1;
required Type b = 2;
}
message Arrow {
required Type a = 1;
required Type b = 2;
}
message Pair {
required Type a = 1;
required Type b = 2;
}
message Either {
required Type a = 1;
required Type b = 2;
}
message Result {
required Type a = 1;
required Type b = 2;
}
message Abstract {
required string witness = 1;
}

oneof t {
Unit unit = 1;
Int int = 2;
Int32 int32 = 3;
Int64 int64 = 4;
Bool bool = 5;
String string = 6;
Lwt lwt = 7;
List list = 8;
Array array = 9;
Option option = 10;
Apply apply = 11;
Arrow arrow = 12;
Pair pair = 13;
Either either = 14;
Result result = 15;
Abstract abstract = 16;
}
}

message Primitive {
required string name = 1;
repeated Type arguments = 2;
required Type return = 3;
}

enum Binop {
ADD = 1;
SUB = 2;
MUL = 3;
DIV = 4;
PAIR = 5;
EQ = 6;
}

message Unop {
message Fst { }
message Snd { }
message L { required Type value = 1; }
message R { required Type value = 1; }
message Ok { required Type value = 1; }
message Error { required Type value = 1; }

oneof t {
Fst fst = 1;
Snd snd = 2;
L l = 3;
R r = 4;
Ok ok = 5;
Error error = 6;
}
}

message Value {
message Unit { }
message Int { required int32 value = 1; }
message Int32 { required int32 value = 1; }
message Int64 { required int64 value = 1; }
message Bool { required bool value = 1; }
message String { required string value = 1; }
message List {
required Type typ = 1;
repeated Value value = 2;
}
message Array {
required Type typ = 1;
repeated Value value = 2;
}
message Option {
required Type typ = 1;
optional Value value = 2;
}
message Pair {
required Value a = 1;
required Value b = 2;
}

oneof t {
Unit unit = 1;
Int int = 2;
Int32 int32 = 3;
Int64 int64 = 4;
Bool bool = 5;
String string = 6;
List list = 7;
Array array = 8;
Option option = 9;
Pair pair = 10;
}
}

message Expr {
message Val { required Value value = 1; }
message Prm { required Primitive value = 1; }
message Lst { optional Type typ = 1;
repeated Expr expr = 2; }
message Arr { optional Type typ = 1;
repeated Expr expr = 2; }
message Opt { required Type typ = 1;
optional Expr expr = 2; }
message Var { required int32 var = 1; }
message Lam { required Type typ = 1;
required string var = 2;
required Expr expr = 3; }
message Rec { required Type ret = 1;
required string name = 2;
required Type argument = 3;
required Expr expr = 4; }
message App { required Expr a = 1;
required Expr b = 2; }
message Bin {
required Binop op = 1;
required Expr a = 2;
required Expr b = 3;
}
message Uno {
required Unop op = 1;
required Expr x = 2;
}
message Let {
required Type typ = 1;
required string name = 2;
required Expr expr = 3;
required Expr body = 4;
}
message Swt {
required Expr a = 1;
required Expr b = 2;
required Expr s = 3;
}
message If {
required Expr a = 1;
required Expr b = 2;
required Expr s = 3;
}

oneof t {
Val val = 1;
Prm prm = 2;
Lst lst = 3;
Arr arr = 4;
Opt opt = 5;
Var var = 6;
Lam lam = 7;
Rec rec = 8;
App app = 9;
Bin bin = 10;
Uno uno = 11;
Let let = 12;
Swt swt = 13;
If if = 14;
}
}
Loading