Skip to content

Commit

Permalink
Merge pull request #12 from lefessan/z-2021-06-15-solidity-for-freeton
Browse files Browse the repository at this point in the history
v0.3.1
  • Loading branch information
lefessan authored Jul 21, 2021
2 parents 38f165f + 5a3003f commit 0e42132
Show file tree
Hide file tree
Showing 29 changed files with 507 additions and 826 deletions.
28 changes: 14 additions & 14 deletions .drom
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# hash of toml configuration files
# used for generation of all files
1e61bf762d06039228fa40123986164f:.
0c9d153828991ed03dadaee3e6e912de:.
# end context for .

# begin context for .github/workflows/doc-deploy.yml
Expand Down Expand Up @@ -37,7 +37,7 @@ a8d1bcd6f62c6b813b77d3ff8959d8d2:.ocamlformat-ignore

# begin context for CHANGES.md
# file CHANGES.md
3c209b23d1c3cdcf988c1b2c17a062cb:CHANGES.md
873ca123aaa4f12aedad55595c52d1ea:CHANGES.md
# end context for CHANGES.md

# begin context for LICENSE.md
Expand Down Expand Up @@ -97,12 +97,12 @@ c8281f46ba9a11d0b61bc8ef67eaa357:docs/style.css

# begin context for dune-project
# file dune-project
a763e33bb9032a52af3d8b1d54c81a79:dune-project
b877b563b3a1da795b26be4319d5dcc2:dune-project
# end context for dune-project

# begin context for ez_hash.opam
# file ez_hash.opam
bfe0fe6557ac0067c0af0957776a218d:ez_hash.opam
62344d70f0815962091e077cca95a645:ez_hash.opam
# end context for ez_hash.opam

# begin context for scripts/after.sh
Expand All @@ -122,27 +122,27 @@ bb3a9d286f0dc64021db4194427263ee:scripts/copy-bin.sh

# begin context for solidity-alcotest.opam
# file solidity-alcotest.opam
e4c6d96c1d43a4212e0c6fd7eafa0bba:solidity-alcotest.opam
54623069b08f8d7342d62e5d21abf615:solidity-alcotest.opam
# end context for solidity-alcotest.opam

# begin context for solidity-common.opam
# file solidity-common.opam
c5dc9cb80350677af069005eea9029d5:solidity-common.opam
42a80a0071000e29f533534d2e640113:solidity-common.opam
# end context for solidity-common.opam

# begin context for solidity-parser.opam
# file solidity-parser.opam
74a335b608009f3bc87765de148b2eb9:solidity-parser.opam
c105f5cd63f7bdc137cacd90655d3960:solidity-parser.opam
# end context for solidity-parser.opam

# begin context for solidity-test.opam
# file solidity-test.opam
beb8811d7c7c23333e799d1717bc8b97:solidity-test.opam
386c907f168ab33fb2489810d9b8321d:solidity-test.opam
# end context for solidity-test.opam

# begin context for solidity-typechecker.opam
# file solidity-typechecker.opam
424bac9289a1103c40674f0b3433782e:solidity-typechecker.opam
4675cef4797ec67b1c5959d5973396db:solidity-typechecker.opam
# end context for solidity-typechecker.opam

# begin context for sphinx/_static/css/fixes.css
Expand Down Expand Up @@ -197,7 +197,7 @@ e86f9a67236dac57aaae3ca819cb7dbb:src/ocaml-solidity/package.toml

# begin context for src/solidity-alcotest/version.mlt
# file src/solidity-alcotest/version.mlt
1e501a85255c8330e7be2911d58f03d8:src/solidity-alcotest/version.mlt
47d835b1b3ec0a463928fd2af319b6c0:src/solidity-alcotest/version.mlt
# end context for src/solidity-alcotest/version.mlt

# begin context for src/solidity-common/dune
Expand All @@ -217,7 +217,7 @@ e86f9a67236dac57aaae3ca819cb7dbb:src/ocaml-solidity/package.toml

# begin context for src/solidity-common/version.mlt
# file src/solidity-common/version.mlt
1e501a85255c8330e7be2911d58f03d8:src/solidity-common/version.mlt
47d835b1b3ec0a463928fd2af319b6c0:src/solidity-common/version.mlt
# end context for src/solidity-common/version.mlt

# begin context for src/solidity-parser/dune
Expand All @@ -237,7 +237,7 @@ be413a351ddaf3cdf0d44e91ad35680e:src/solidity-parser/main.ml

# begin context for src/solidity-parser/version.mlt
# file src/solidity-parser/version.mlt
1e501a85255c8330e7be2911d58f03d8:src/solidity-parser/version.mlt
47d835b1b3ec0a463928fd2af319b6c0:src/solidity-parser/version.mlt
# end context for src/solidity-parser/version.mlt

# begin context for src/solidity-test/dune
Expand All @@ -247,7 +247,7 @@ be413a351ddaf3cdf0d44e91ad35680e:src/solidity-parser/main.ml

# begin context for src/solidity-test/version.mlt
# file src/solidity-test/version.mlt
1e501a85255c8330e7be2911d58f03d8:src/solidity-test/version.mlt
47d835b1b3ec0a463928fd2af319b6c0:src/solidity-test/version.mlt
# end context for src/solidity-test/version.mlt

# begin context for src/solidity-typechecker/dune
Expand All @@ -267,5 +267,5 @@ be413a351ddaf3cdf0d44e91ad35680e:src/solidity-parser/main.ml

# begin context for src/solidity-typechecker/version.mlt
# file src/solidity-typechecker/version.mlt
1e501a85255c8330e7be2911d58f03d8:src/solidity-typechecker/version.mlt
47d835b1b3ec0a463928fd2af319b6c0:src/solidity-typechecker/version.mlt
# end context for src/solidity-typechecker/version.mlt
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

## v0.1.0 ( 2021-07-19 )
## v0.1.0 ( 2021-07-20 )

* Initial commit
2 changes: 1 addition & 1 deletion drom.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ license = "LGPL2"
min-edition = "4.08.0"
name = "ocaml-solidity"
synopsis = "The ocaml-solidity project"
version = "0.3.0"
version = "0.3.1"

# keys that you could also define:
# odoc-target = "...odoc-target..."
Expand Down
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(name ocaml-solidity)
(allow_approximate_merlin)
(generate_opam_files false)
(version 0.3.0)
(version 0.3.1)
(formatting (enabled_for ocaml reason))
(using menhir 2.0)

Expand Down
2 changes: 1 addition & 1 deletion ez_hash.opam
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Do not modify, or add to the `skip` field of `drom.toml`.
opam-version: "2.0"
name: "ez_hash"
version: "0.3.0"
version: "0.3.1"
license: "LGPL-2.1-only with OCaml-LGPL-linking-exception"
synopsis: "Hash functions: sha3, sha256, blake2b"
description: """
Expand Down
2 changes: 1 addition & 1 deletion solidity-alcotest.opam
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Do not modify, or add to the `skip` field of `drom.toml`.
opam-version: "2.0"
name: "solidity-alcotest"
version: "0.3.0"
version: "0.3.1"
license: "LGPL-2.1-only with OCaml-LGPL-linking-exception"
synopsis: "The ocaml-solidity project"
description: """
Expand Down
2 changes: 1 addition & 1 deletion solidity-common.opam
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Do not modify, or add to the `skip` field of `drom.toml`.
opam-version: "2.0"
name: "solidity-common"
version: "0.3.0"
version: "0.3.1"
license: "LGPL-2.1-only with OCaml-LGPL-linking-exception"
synopsis: "The ocaml-solidity project"
description: """
Expand Down
2 changes: 1 addition & 1 deletion solidity-parser.opam
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Do not modify, or add to the `skip` field of `drom.toml`.
opam-version: "2.0"
name: "solidity-parser"
version: "0.3.0"
version: "0.3.1"
license: "LGPL-2.1-only with OCaml-LGPL-linking-exception"
synopsis: "The ocaml-solidity project"
description: """
Expand Down
2 changes: 1 addition & 1 deletion solidity-test.opam
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Do not modify, or add to the `skip` field of `drom.toml`.
opam-version: "2.0"
name: "solidity-test"
version: "0.3.0"
version: "0.3.1"
license: "LGPL-2.1-only with OCaml-LGPL-linking-exception"
synopsis: "The ocaml-solidity project"
description: """
Expand Down
2 changes: 1 addition & 1 deletion solidity-typechecker.opam
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Do not modify, or add to the `skip` field of `drom.toml`.
opam-version: "2.0"
name: "solidity-typechecker"
version: "0.3.0"
version: "0.3.1"
license: "LGPL-2.1-only with OCaml-LGPL-linking-exception"
synopsis: "The ocaml-solidity project"
description: """
Expand Down
2 changes: 1 addition & 1 deletion src/solidity-alcotest/version.mlt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let query cmd =

let commit_hash = query "git show -s --pretty=format:%H"
let commit_date = query "git show -s --pretty=format:%ci"
let version = "0.3.0"
let version = "0.3.1"
let version =
match commit_hash with
| Some commit_hash ->
Expand Down
3 changes: 2 additions & 1 deletion src/solidity-common/solidity_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ and function_definition = {
fun_override : longident list option; (* fallback/receive: external *)
fun_virtual : bool; (* but public if missing... *)
fun_inline : bool; (* freeton *)
fun_responsible : bool; (* freeton *)
fun_body : block option; (* mutability : nonpayable by default *)
}

Expand Down Expand Up @@ -155,7 +156,7 @@ and raw_statement =
expression option * statement
| TryStatement of expression * return list * block * catch_clause list
| Emit of expression * function_call_arguments
| Return of expression option
| Return of expression option * (ident * expression) list
| Continue
| Break
| PlaceholderStatement
Expand Down
5 changes: 3 additions & 2 deletions src/solidity-common/solidity_ast.mli
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ and function_definition = {
fun_override : longident list option;
fun_virtual : bool;
fun_inline : bool; (* freeton *)
fun_responsible : bool; (* freeton *)
fun_body : block option;
}

Expand Down Expand Up @@ -224,8 +225,8 @@ and raw_statement =
| Emit of expression * function_call_arguments
(** Event emission *)

| Return of expression option
(** Return statement *)
| Return of expression option * (ident * expression) list
(** Return statement (second part only on FreeToN) *)

| Continue
(** Continue (loop statement) *)
Expand Down
22 changes: 18 additions & 4 deletions src/solidity-common/solidity_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,18 @@ and variable_definition b indent ~freeton {

and function_definition b indent {
fun_name; fun_params; fun_returns; fun_modifiers; fun_visibility;
fun_mutability; fun_override; fun_virtual; fun_inline ; fun_body } =
fun_mutability; fun_override; fun_virtual;
fun_inline ; fun_responsible ; fun_body } =
let name =
match strip fun_name with
| id when Ident.equal id Ident.fallback -> "fallback"
| id when Ident.equal id Ident.receive -> "receive"
| id when Ident.equal id Ident.constructor -> "constructor"
| id when Ident.equal id Ident.onBounce -> "onBounce"
| id -> "function " ^ (Ident.to_string id)
in
bprint b indent
(Format.sprintf "%s(%s) %s%s%s%s%s%s%s%s"
(Format.sprintf "%s(%s) %s%s%s%s%s%s%s%s%s"
(name)
(String.concat ", " (List.map string_of_function_param fun_params))
(string_of_visibility fun_visibility)
Expand All @@ -305,6 +307,7 @@ and function_definition b indent {
| m -> " " ^ (string_of_fun_mutability m))
(if fun_virtual then " virtual" else "")
(if fun_inline then " inline" else "")
(if fun_responsible then " responsible" else "")
(match fun_override with
| None -> ""
| Some [] -> " override"
Expand Down Expand Up @@ -415,9 +418,20 @@ and statement b indent s =
(string_of_function_call_arguments args))
| PlaceholderStatement ->
bprint b indent "_;"
| Return e_opt ->
| Return ( e_opt , options ) ->
bprint b indent
(Format.sprintf "return %s;" (string_of_expression_option e_opt))
(Format.sprintf "return %s %s;"
( match options with
| [] -> ""
| _ ->
Format.sprintf "{%s}"
(String.concat ","
(List.map (fun (id, e) ->
Format.sprintf "%s: %s"
(string_of_ident id) (string_of_expression e)
) options))
)
(string_of_expression_option e_opt))
| Block statement_list ->
bprint b indent "{" ;
block b (indent + 2) statement_list;
Expand Down
6 changes: 4 additions & 2 deletions src/solidity-common/solidity_visitor.ml
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ and visitFunctionDef (v : #ast_visitor) (fd : function_definition) : unit =
fun_override;
fun_virtual;
fun_inline = _;
fun_responsible = _;
fun_body
} : function_definition) : unit =
visitNode visitIdent v fun_name;
Expand Down Expand Up @@ -405,8 +406,9 @@ and visitStatement (v : #ast_visitor) (s : statement) : unit =
| Emit (e, fca) ->
visitExpression v e;
visitFunctionCallArguments v fca
| Return eo ->
visitOpt visitExpression v eo
| Return (eo, l) ->
visitOpt visitExpression v eo;
visitList (visitXY (visitNode visitIdent) visitExpression) v l
| Continue | Break | PlaceholderStatement -> ()
| RepeatStatement (e, s) ->
visitExpression v e;
Expand Down
2 changes: 1 addition & 1 deletion src/solidity-common/version.mlt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let query cmd =

let commit_hash = query "git show -s --pretty=format:%H"
let commit_date = query "git show -s --pretty=format:%ci"
let version = "0.3.0"
let version = "0.3.1"
let version =
match commit_hash with
| Some commit_hash ->
Expand Down
1 change: 1 addition & 0 deletions src/solidity-parser/solidity_lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ if freeton then
"optional", OPTIONAL;
"onBounce", ONBOUNCE;
"repeat", REPEAT;
"responsible", RESPONSIBLE;
];
()
end
Expand Down
16 changes: 14 additions & 2 deletions src/solidity-parser/solidity_raw_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
| Invocation of longident * expression list option
| Static
| Inline
| Responsible

let add_free_var_modifiers pos var ml =
let has_mut = ref false in
Expand Down Expand Up @@ -114,6 +115,10 @@
if fct.fun_inline then
error pos "Inline already specified";
{ fct with fun_inline = true }
| Responsible ->
if fct.fun_responsible then
error pos "responsible already specified";
{ fct with fun_responsible = true }
| Invocation (lid, exp_list_opt) ->
{ fct with fun_modifiers =
(lid, exp_list_opt) :: fct.fun_modifiers }
Expand Down Expand Up @@ -255,6 +260,7 @@
%token USING
%token PUBLIC
%token INLINE (* freeton *)
%token RESPONSIBLE (* freeton *)
%token STATIC (* freeton *)
%token OPTIONAL (* freeton *)
%token ONBOUNCE (* freeton *)
Expand Down Expand Up @@ -456,6 +462,7 @@ source_unit:
fun_override = None;
fun_virtual = false;
fun_inline = false;
fun_responsible = false;
fun_body = $5; } $3)) }
;;

Expand Down Expand Up @@ -545,6 +552,7 @@ contract_part:
fun_override = None;
fun_virtual = false;
fun_inline = false;
fun_responsible = false;
fun_body = $5; } $3)) }
| function_descriptor parameters function_modifier*
returns_opt function_body_opt
Expand All @@ -558,6 +566,7 @@ contract_part:
fun_override = None;
fun_virtual = false;
fun_inline = false;
fun_responsible = false;
fun_body = $5; } $3)) }
| EVENT identifier event_parameters boption(ANONYMOUS) SEMI
{ mk $loc (EventDefinition {
Expand Down Expand Up @@ -591,7 +600,7 @@ struct_fields:
function_descriptor:
| FUNCTION identifier { $2 }
| CONSTRUCTOR { mk $loc Ident.constructor }
| ONBOUNCE { freeton() ; mk $loc Ident.constructor }
| ONBOUNCE { freeton() ; mk $loc Ident.onBounce }
| RECEIVE { mk $loc Ident.receive }
| FALLBACK { mk $loc Ident.fallback }
;;
Expand Down Expand Up @@ -619,6 +628,7 @@ function_modifier:
| internal_external { $1 }
| public_private { $1 }
| INLINE { freeton() ; Inline }
| RESPONSIBLE { freeton() ; Responsible }
| VIRTUAL { Virtual }
| override_specifier { $1 }
;;
Expand Down Expand Up @@ -861,7 +871,9 @@ statement_no_semi:
statement_before_semi:
| simple_statement { $1 }
| do_while_statement { mk $loc ($1) }
| RETURN expression? { mk $loc (Return ($2)) }
| RETURN LBRACE name_value_nonempty_list RBRACE expression?
{ freeton() ; mk $loc (Return ($5, $3)) }
| RETURN expression? { mk $loc (Return ($2, [])) }
| CONTINUE { mk $loc (Continue) }
| BREAK { mk $loc (Break) }
| EMIT function_call { let (f, a) = $2 in mk $loc (Emit (f, a)) }
Expand Down
Loading

0 comments on commit 0e42132

Please sign in to comment.