Skip to content

Commit

Permalink
Merge pull request #12 from dinosaure/protobuf
Browse files Browse the repository at this point in the history
Protobuf [WIP]
  • Loading branch information
samoht authored Jun 20, 2018
2 parents 230c639 + e4284de commit 1f10738
Show file tree
Hide file tree
Showing 12 changed files with 472 additions and 2 deletions.
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 {
message Unit { }
message Int { }
message Int32 { }
message Int64 { }
message Bool { }
message String { }
message Lwt { }
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

0 comments on commit 1f10738

Please sign in to comment.