Skip to content
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

Multi-entries may cause more storage consumptions. #131

Open
catsigma opened this issue Oct 9, 2018 · 0 comments
Open

Multi-entries may cause more storage consumptions. #131

catsigma opened this issue Oct 9, 2018 · 0 comments

Comments

@catsigma
Copy link

catsigma commented Oct 9, 2018

type storage = unit

contract type X = sig
  type storage
  val%entry entry_a : nat -> storage -> operation list * storage
  val%entry entry_b : int -> storage -> operation list * storage
end

contract type Y = sig
  type storage
  type pt = 
  | A of nat
  | B of int

  val%entry main : pt -> storage -> operation list * storage
end

(* 1 : Using entry syntax *)
let%entry main (parameter : nat * X.instance) s =
  let num, c = parameter in
  let op = 
    if num < 50p then
      Contract.call c 0tz entry_a 1p
    else
      Contract.call c 0tz entry_b 1
  in
  ([op], s)

(* 2 : Using entry manually *)
(* let%entry main (parameter : nat * Y.instance) s =
  let num, c = parameter in
  let arg = 
    if num < 50p then
      Y.A 1p
    else
      Y.B 1
  in
  let op = Contract.call c 0tz arg in
  ([op], s) *)

For code block 1, it will compile to

parameter
  (pair nat
        (contract :X (or :_entries (nat %_Liq_entry_entry_a) (int %_Liq_entry_entry_b))));
storage unit;
code { DUP ;
       DIP { CDR } ;
       CAR ;
       DUP @parameter ;
       DUP ;
       CDR @c ;
       DUUUUP @s ;
       NIL operation ;
       PUSH nat 50 ;
       DUUUUUP ;
       CAR @num ;
       COMPARE ;
       LT ;
       IF { DUUUP @c ;
            PUSH mutez 0 ;
            PUSH nat 1 ;
            LEFT %_Liq_entry_entry_a % (int %_Liq_entry_entry_b) ;
            TRANSFER_TOKENS }
          { DUUUP @c ;
            PUSH mutez 0 ;
            PUSH int 1 ;
            RIGHT % %_Liq_entry_entry_b nat ;
            TRANSFER_TOKENS } ;
       DIIIP { DROP ; DROP ; DROP ; DROP } ;
       RENAME @op ;
       CONS ;
       PAIR };

For code block 2, it will compile to

parameter (pair nat (contract :Y (or :Y.pt (nat %Y.A) (int %Y.B))));
storage unit;
code { DUP ;
       DIP { CDR } ;
       CAR ;
       DUP @parameter ;
       DUP ;
       CDR @c ;
       PUSH mutez 0 ;
       PUSH nat 50 ;
       DUUUUP ;
       CAR @num ;
       COMPARE ;
       LT ;
       IF { PUSH (or :Y.pt (nat %Y.A) (int %Y.B)) (Left 1) }
          { PUSH (or :Y.pt (nat %Y.A) (int %Y.B)) (Right 1) } ;
       DIIIP { DROP ; DROP } ;
       RENAME @arg ;
       TRANSFER_TOKENS @op ;
       SWAP ;
       NIL operation ;
       DUUUP ;
       DIIIP { DROP } ;
       CONS ;
       PAIR };

Using multiple entries will generate larger size of code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant