Skip to content

Commit

Permalink
Merge pull request #23 from hra687261/ever-and-varint-support
Browse files Browse the repository at this point in the history
Added support for Evers
  • Loading branch information
lefessan authored Jan 2, 2022
2 parents 60d215e + 05eea3e commit 59cb39c
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 58 deletions.
72 changes: 43 additions & 29 deletions src/solidity-common/solidity_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,20 @@ and number_unit =
| Days
| Weeks
| Years
| Nanoton (* freeton *)
| Microton (* freeton *)
| Milliton (* freeton *)
| Ton (* freeton *)
| Kiloton (* freeton *)
| Megaton (* freeton *)
| Gigaton (* freeton *)
| Nanoton (* freeton / everscale *)
| Microton (* freeton / everscale *)
| Milliton (* freeton / everscale *)
| Ton (* freeton / everscale *)
| Kiloton (* freeton / everscale *)
| Megaton (* freeton / everscale *)
| Gigaton (* freeton / everscale *)
| Nanoever (* freeton / everscale *)
| Microever (* freeton / everscale *)
| Milliever (* freeton / everscale *)
| Ever (* freeton / everscale *)
| Kiloever (* freeton / everscale *)
| Megaever (* freeton / everscale *)
| Gigaever (* freeton / everscale *)

and unary_operator =
| UPlus
Expand Down Expand Up @@ -393,27 +400,34 @@ let convertible_visibility ~from ~to_ =
let unit_factor unit =
let z =
match unit with
| Unit -> Z.one
| Wei -> Z.one
| Kwei -> ExtZ._10_3
| Mwei -> ExtZ._10_6
| Gwei -> ExtZ._10_9
| Twei -> ExtZ._10_12
| Pwei -> ExtZ._10_15
| Ether -> ExtZ._10_18
| Hours -> ExtZ._3600
| Minutes -> ExtZ._60
| Seconds -> Z.one
| Days -> ExtZ._24x3600
| Weeks -> ExtZ._7x24x3600
| Years -> ExtZ._365x24x3600
| Nanoton -> Z.one
| Microton -> ExtZ._10_3
| Milliton -> ExtZ._10_6
| Ton -> ExtZ._10_9
| Kiloton -> ExtZ._10_12
| Megaton -> ExtZ._10_15
| Gigaton -> ExtZ._10_18
| Unit -> Z.one
| Wei -> Z.one
| Kwei -> ExtZ._10_3
| Mwei -> ExtZ._10_6
| Gwei -> ExtZ._10_9
| Twei -> ExtZ._10_12
| Pwei -> ExtZ._10_15
| Ether -> ExtZ._10_18
| Hours -> ExtZ._3600
| Minutes -> ExtZ._60
| Seconds -> Z.one
| Days -> ExtZ._24x3600
| Weeks -> ExtZ._7x24x3600
| Years -> ExtZ._365x24x3600
| Nanoton -> Z.one
| Microton -> ExtZ._10_3
| Milliton -> ExtZ._10_6
| Ton -> ExtZ._10_9
| Kiloton -> ExtZ._10_12
| Megaton -> ExtZ._10_15
| Gigaton -> ExtZ._10_18
| Nanoever -> Z.one
| Microever -> ExtZ._10_3
| Milliever -> ExtZ._10_6
| Ever -> ExtZ._10_9
| Kiloever -> ExtZ._10_12
| Megaever -> ExtZ._10_15
| Gigaever -> ExtZ._10_18
in
Q.of_bigint z

Expand Down Expand Up @@ -449,7 +463,7 @@ let apply_binop q1 op q2 =
| BDiv ->
Some (Q.div q1 q2)
| BMod ->
(* TODO: Solidity allows this on fractions *)
(* TODO: Solidity allows this on fractions *)
if ExtQ.is_int q1 && ExtQ.is_int q2 then
Some (Q.of_bigint (snd (Z.ediv_rem (Q.num q1) (Q.num q2))))
else
Expand Down
21 changes: 14 additions & 7 deletions src/solidity-common/solidity_ast.mli
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,20 @@ and number_unit =
| Days
| Weeks
| Years
| Nanoton (* freeton *)
| Microton (* freeton *)
| Milliton (* freeton *)
| Ton (* freeton *)
| Kiloton (* freeton *)
| Megaton (* freeton *)
| Gigaton (* freeton *)
| Nanoton (* freeton / everscale *)
| Microton (* freeton / everscale *)
| Milliton (* freeton / everscale *)
| Ton (* freeton / everscale *)
| Kiloton (* freeton / everscale *)
| Megaton (* freeton / everscale *)
| Gigaton (* freeton / everscale *)
| Nanoever (* freeton / everscale *)
| Microever (* freeton / everscale *)
| Milliever (* freeton / everscale *)
| Ever (* freeton / everscale *)
| Kiloever (* freeton / everscale *)
| Megaever (* freeton / everscale *)
| Gigaever (* freeton / everscale *)

and unary_operator =
| UPlus
Expand Down
52 changes: 30 additions & 22 deletions src/solidity-common/solidity_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,36 @@ let string_of_visibility = function
| VPrivate -> "private"

let string_of_number_unit = function
| Unit -> ""
| Wei -> "wei"
| Kwei -> "kwei"
| Mwei -> "mwei"
| Gwei -> "gwei"
| Twei -> "szabo"
| Pwei -> "finney"
| Ether -> "ether"
| Hours -> "hours"
| Minutes -> "minutes"
| Seconds -> "seconds"
| Days -> "days"
| Weeks -> "weeks"
| Years -> "years"

| Nanoton -> "nanoton"
| Microton -> "microton"
| Milliton -> "milliton"
| Ton -> "ton"
| Kiloton -> "kiloton"
| Megaton -> "megaton"
| Gigaton -> "gigaton"
| Unit -> ""
| Wei -> "wei"
| Kwei -> "kwei"
| Mwei -> "mwei"
| Gwei -> "gwei"
| Twei -> "szabo"
| Pwei -> "finney"
| Ether -> "ether"
| Hours -> "hours"
| Minutes -> "minutes"
| Seconds -> "seconds"
| Days -> "days"
| Weeks -> "weeks"
| Years -> "years"

| Nanoton -> "nanoton"
| Microton -> "microton"
| Milliton -> "milliton"
| Ton -> "ton"
| Kiloton -> "kiloton"
| Megaton -> "megaton"
| Gigaton -> "gigaton"

| Nanoever -> "nanoever"
| Microever -> "microever"
| Milliever -> "milliever"
| Ever -> "ever"
| Kiloever -> "kiloever"
| Megaever -> "megaever"
| Gigaever -> "gigaever"

let string_of_unop = function
| UPlus -> "+"
Expand Down
22 changes: 22 additions & 0 deletions src/solidity-parser/solidity_lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,28 @@ if freeton then

"gigaton", NUMBERUNIT (Gigaton);
"GTon", NUMBERUNIT (Gigaton);

(* "nano", NUMBERUNIT (Ever); *)
"nanoever", NUMBERUNIT (Nanoever);
"nEver", NUMBERUNIT (Nanoever);

"micro", NUMBERUNIT (Microever);
"microever", NUMBERUNIT (Microever);

"milli", NUMBERUNIT (Milliever);
"milliever", NUMBERUNIT (Milliever);

"ever", NUMBERUNIT (Ever);
"Ever", NUMBERUNIT (Ever);

"kiloever", NUMBERUNIT (Kiloever);
"kEver", NUMBERUNIT (Kiloever);

"megaever", NUMBERUNIT (Megaever);
"MEver", NUMBERUNIT (Megaever);

"gigaever", NUMBERUNIT (Gigaever);
"GEver", NUMBERUNIT (Gigaever);
];
()
end
Expand Down

0 comments on commit 59cb39c

Please sign in to comment.