-
Notifications
You must be signed in to change notification settings - Fork 5
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
Protobuf [WIP] #12
Changes from all commits
b8cef0a
f830114
23128e2
85be012
9383653
da75789
840a65e
0dd7d3c
3cfd9d4
0a7ed65
b8117a8
ec59656
5a57f3d
5c5fcad
e4284de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
_build | ||
_opam* |
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 |
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" | ||
] |
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)))) |
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 { } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How to handle values of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to use There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
(using the definitions from here)
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly 👍 , as I said, we can provide a sugar and translate |
||
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; | ||
} | ||
} |
There was a problem hiding this comment.
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 linesyntax = "proto2";
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted.