Mini_c: Identify more pure constants

This commit is contained in:
Tom Jack 2019-11-25 18:10:49 -06:00
parent 66d2cda107
commit 06603b594a
2 changed files with 53 additions and 49 deletions

View File

@ -5,7 +5,7 @@ let contract basename =
let%expect_test _ =
run_ligo_good [ "measure-contract" ; contract "coase.ligo" ; "main" ] ;
[%expect {| 2068 bytes |}] ;
[%expect {| 2066 bytes |}] ;
run_ligo_good [ "measure-contract" ; contract "multisig.ligo" ; "main" ] ;
[%expect {| 1093 bytes |}] ;
@ -14,7 +14,7 @@ let%expect_test _ =
[%expect {| 627 bytes |}] ;
run_ligo_good [ "measure-contract" ; contract "vote.mligo" ; "main" ] ;
[%expect {| 714 bytes |}] ;
[%expect {| 628 bytes |}] ;
()
@ -204,10 +204,9 @@ let%expect_test _ =
NIL operation ;
SWAP ;
CONS ;
DUP ;
DIP { DIP 8 { DUP } ; DIG 8 } ;
DIP { DIP 7 { DUP } ; DIG 7 } ;
PAIR ;
DIP { DROP 12 } } ;
DIP { DROP 11 } } ;
DIP { DROP } }
{ DUP ;
DIP { DIP { DUP } ; SWAP } ;
@ -482,7 +481,10 @@ let%expect_test _ =
CAR ;
IF_LEFT
{ DUP ;
PUSH int 0 ;
DUP ;
CAR ;
CAR ;
DIP { PUSH int 0 ;
SOME ;
DIP { PUSH int 0 ;
SOME ;
@ -491,26 +493,16 @@ let%expect_test _ =
PUSH string "Yes" ;
UPDATE } ;
PUSH string "No" ;
UPDATE ;
DIP { DUP } ;
SWAP ;
CAR ;
CAR ;
DIP { DUP } ;
UPDATE } ;
PAIR ;
DIP { DIP { DUP } ;
SWAP ;
CAR ;
CDR ;
DIP { DIP { DUP } ; SWAP ; CDR } ;
PAIR } ;
DIP { DUP ; CAR ; CDR ; DIP { DUP ; CDR } ; PAIR } ;
PAIR ;
EMPTY_SET address ;
SWAP ;
PAIR ;
NIL operation ;
PAIR ;
DIP { DROP 3 } }
DIP { DROP 2 } }
{ DUP ;
DIP { DIP { DUP } ; SWAP ; CDR } ;
PAIR ;
@ -519,41 +511,36 @@ let%expect_test _ =
DIP { DUP } ;
SWAP ;
CDR ;
NOW ;
SOURCE ;
DIP 3 { DUP } ;
DIG 3 ;
DIP { DIP 2 { DUP } ; DIG 2 ; CAR ; CAR ; CDR } ;
DIP { DUP } ;
SWAP ;
DIP { DUP ; CAR ; CAR ; CDR } ;
GET ;
IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ;
DIP 3 { DUP } ;
DIG 3 ;
DIP { DUP } ;
SWAP ;
CAR ;
CAR ;
CAR ;
DIP { DIP 4 { DUP } ;
DIG 4 ;
DIP { DIP 2 { DUP } ;
DIG 2 ;
DIP { DUP ;
PUSH int 1 ;
ADD ;
SOME ;
DIP { DIP 3 { DUP } ; DIG 3 ; CAR ; CAR ; CDR } } ;
DIP { DIP { DUP } ; SWAP ; CAR ; CAR ; CDR } } ;
UPDATE } ;
PAIR ;
DIP { DIP 3 { DUP } ;
DIG 3 ;
CAR ;
CDR ;
CAR ;
DIP { DIP 3 { DUP } ; DIG 3 ; CAR ; CDR ; CDR } ;
PAIR } ;
PAIR ;
DIP { DIP { DUP } ;
SWAP ;
DIP { DIP 3 { DUP } ; DIG 3 ; CDR ; PUSH bool True } ;
UPDATE } ;
CAR ;
CDR ;
CAR ;
DIP { DIP { DUP } ; SWAP ; CAR ; CDR ; CDR } ;
PAIR } ;
PAIR ;
DIP { DIP { DUP } ; SWAP ; CDR ; PUSH bool True ; SOURCE ; UPDATE } ;
PAIR ;
NIL operation ;
PAIR ;
DIP { DROP 7 } } ;
DIP { DROP 5 } } ;
DIP { DROP } } } |}]

View File

@ -17,12 +17,29 @@ let map_expression :
assuming arguments are pure *)
let is_pure_constant : string -> bool =
function
| "CAR"
| "CDR"
| "PAIR"
| "UNIT"
| "CAR" | "CDR" | "PAIR"
| "NIL" | "CONS"
| "NEG" | "OR" | "AND" | "XOR" | "NOT"
| "EQ" | "NEQ" | "LT" | "LE" | "GT" | "GE"
| "SOME"
| "UPDATE" | "MAP_GET" | "MAP_FIND_OPT" | "MAP_ADD" | "MAP_UPDATE"
| "INT" | "ABS" | "ISNAT"
| "BALANCE" | "AMOUNT" | "ADDRESS" | "NOW" | "SOURCE" | "SENDER" | "CHAIN_ID"
| "SET_MEM" | "SET_ADD" | "SET_REMOVE" | "SLICE"
| "SHA256" | "SHA512" | "BLAKE2B" | "CHECK_SIGNATURE"
| "HASH_KEY" | "PACK" | "CONCAT"
-> true
(* unfortunately impure: *)
| "ADD"|"SUB"|"TIMES"|"DIV"|"MOD"
(* impure: *)
| "ASSERT" | "ASSERT_INFERRED"
| "MAP_GET_FORCE" | "MAP_FIND"
| "FOLD_WHILE"
| "CALL"
(* TODO... *)
| _ -> false
| _
-> false
let rec is_pure : expression -> bool = fun e ->
match e.content with