Updating contracts.

This commit is contained in:
Christian Rinderknecht 2020-02-27 17:51:29 +01:00
parent 4d61c2285c
commit 93682629b4
53 changed files with 288 additions and 366 deletions

View File

@ -1,3 +1,3 @@
let main (p : key_hash) = let main (p : key_hash) =
let c : unit contract = Current.implicit_account p in let c : unit contract = Current.implicit_account p
Current.address c in Current.address c

View File

@ -1,8 +1,8 @@
function check (const p: unit) : int is function check (const p : unit) : int is
begin block {
var result : int := 0; var result : int := 0;
if amount = 100tz then if Tezos.amount = 100tz then
result := 42 result := 42
else else
result := 0 result := 0
end with result } with result

View File

@ -1 +1 @@
let check_ (p: unit) : int = if Current.amount = 100tz then 42 else 0 let check = if Tezos.amount > 100tez then 42 else 0

View File

@ -1,30 +1,17 @@
// Test CameLIGO arithmetic operators // Test CameLIGO arithmetic operators
let mod_op (n : int) : nat = let mod_op (n : int) : nat = n mod 42
n mod 42
let plus_op (n : int) : int = let plus_op (n : int) : int = n + 42
n + 42
let minus_op (n : int) : int = let minus_op (n : int) : int = n - 42
n - 42
let times_op (n : int) : int = let times_op (n : int) : int = n * 42
n * 42
let div_op (n : int) : int = let div_op (n : int) : int = n / 2
n / 2
(* TODO (?): Support conversion from nat to int and back let neg_op (n : int) : int = -n
let int_op (n : nat) : int =
Int n
*)
let neg_op (n : int) : int =
-n
let foo (n : int) : int = n + 10 let foo (n : int) : int = n + 10
let neg_op_2 (b: int) : int = -(foo b) let neg_op_2 (b : int) : int = -(foo b)

View File

@ -1,3 +1,3 @@
let main (p, s: bool * unit) = let main (p, s : bool * unit) =
let u : unit = assert p let u : unit = assert p
in ([] : operation list), s in ([] : operation list), s

View File

@ -1,10 +1,10 @@
let x = 1 [@@inline] let x = 1 [@@inline]
let foo (a: int): int = let foo (a : int): int =
(let test = 2 + a [@@inline] in test) [@@inline] (let test = 2 + a [@@inline] in test) [@@inline]
let y = 1 [@@inline][@@other] let y = 1 [@@inline][@@other]
let bar (b: int): int = let bar (b : int): int =
let test = fun (z: int) -> 2 + b + z [@@inline][@@foo][@@bar] let test = fun (z : int) -> 2 + b + z [@@inline][@@foo][@@bar]
in test b in test b

View File

@ -1,17 +1,16 @@
(** (*
This test makes sure that the balance is accessible in CameLIGO. This test makes sure that the balance is accessible in CameLIGO.
It's there to detect a regression of: https://gitlab.com/ligolang/ligo/issues/61
Which results in this error when you attempt to compile this contract: It is there to detect a regression of:
https://gitlab.com/ligolang/ligo/issues/61
which results in this error when you attempt to compile this contract:
generated. unrecognized constant: {"constant":"BALANCE","location":"generated"} generated. unrecognized constant: {"constant":"BALANCE","location":"generated"}
*) *)
type storage = tez type storage = tez
let main (p, s : unit * storage) = let main (p, s : unit * storage) =
([] : operation list), balance ([] : operation list), balance

View File

@ -2,22 +2,20 @@ type foo = (int, int) big_map
let set_ (n, m: int * foo) : foo = Big_map.update 23 (Some n) m let set_ (n, m: int * foo) : foo = Big_map.update 23 (Some n) m
let add (n,m : int * foo) : foo = Big_map.add 23 n m let add (n, m : int * foo) : foo = Big_map.add 23 n m
let rm (m : foo) : foo = Big_map.remove 42 m let rm (m : foo) : foo = Big_map.remove 42 m
let gf (m : foo) : int = Big_map.find 23 m let gf (m : foo) : int = Big_map.find 23 m
let get (m: foo): int option = Big_map.find_opt 42 m let get (m : foo): int option = Big_map.find_opt 42 m
let empty_map : foo = Big_map.empty let empty_map : foo = Big_map.empty
let map1 : foo = Big_map.literal let map1 : foo = Big_map.literal [(23,0); (42,0)]
[ (23 , 0) ; (42, 0) ]
let map1 : foo = Big_map.literal let map1 : foo = Big_map.literal [(23,0); (42,0)]
[ (23 , 0) ; (42, 0) ]
let mutimaps (m : foo) (n : foo) : foo = let mutimaps (m : foo) (n : foo) : foo =
let bar : foo = Big_map.update 42 (Some 0) m in let bar : foo = Big_map.update 42 (Some 0) m
Big_map.update 42 (get bar) n in Big_map.update 42 (get bar) n

View File

@ -1,7 +1,7 @@
(* Test CameLIGO bitwise operators *) (* Test CameLIGO bitwise operators *)
let or_op (n: nat) : nat = Bitwise.or n 4n let or_op (n : nat) : nat = Bitwise.lor n 4n
let and_op (n: nat) : nat = Bitwise.and n 7n let and_op (n : nat) : nat = Bitwise.land n 7n
let xor_op (n: nat) : nat = Bitwise.xor n 7n let xor_op (n : nat) : nat = Bitwise.lxor n 7n
let lsl_op (n: nat) : nat = Bitwise.shift_left n 7n let lsl_op (n : nat) : nat = Bitwise.shift_left n 7n
let lsr_op (n: nat) : nat = Bitwise.shift_right n 7n let lsr_op (n : nat) : nat = Bitwise.shift_right n 7n

View File

@ -1,16 +1,11 @@
// Test CameLIGO boolean operators // Test CameLIGO boolean operators
let or_true (b : bool) : bool = let or_true (b : bool) : bool = b || true
b || true
let or_false (b : bool) : bool = let or_false (b : bool) : bool = b || false
b || false
let and_true (b : bool) : bool = let and_true (b : bool) : bool = b && true
b && true
let and_false (b : bool) : bool = let and_false (b : bool) : bool = b && false
b && false
let not_bool (b: bool) : bool = let not_bool (b : bool) : bool = not b
not b

View File

@ -1,8 +1,5 @@
let concat_op (s : bytes) : bytes = let concat_op (s : bytes) : bytes = Bytes.concat s 0x7070
Bytes.concat s 0x7070
let slice_op (s : bytes) : bytes = let slice_op (s : bytes) : bytes = Bytes.slice 1n 2n s
Bytes.slice 1n 2n s
let hasherman (s : bytes) : bytes = let hasherman (s : bytes) : bytes = Crypto.sha256 s
Crypto.sha256 s

View File

@ -1,11 +1,11 @@
let id_string (p: string) : string option = let id_string (p : string) : string option =
let packed: bytes = Bytes.pack p in let packed : bytes = Bytes.pack p in
((Bytes.unpack packed): string option) (Bytes.unpack packed : string option)
let id_int (p: int) : int option = let id_int (p : int) : int option =
let packed: bytes = Bytes.pack p in let packed : bytes = Bytes.pack p in
((Bytes.unpack packed): int option) (Bytes.unpack packed : int option)
let id_address (p: address) : address option = let id_address (p : address) : address option =
let packed: bytes = Bytes.pack p in let packed : bytes = Bytes.pack p in
((Bytes.unpack packed): address option) (Bytes.unpack packed : address option)

View File

@ -1,2 +1,2 @@
let check_signature (pk, signed, msg: key * signature * bytes) : bool = let check_signature (pk, signed, msg : key * signature * bytes) : bool =
Crypto.check pk signed msg Crypto.check pk signed msg

View File

@ -1,9 +1,7 @@
(* Test whether closures retain values in CameLIGO *) (* Test whether closures retain values in CameLIGO *)
let test (k: int) : int = let test (k : int) : int =
let j: int = k + 5 in let j : int = k + 5 in
let close: (int -> int) = let close : int -> int = fun (i : int) -> i + j in
fun (i: int) -> i + j let j : int = 20 (* Shadow original variable *)
in in close 20
let j: int = 20 in (* Shadow original variable to see if value close'd *)
close 20

View File

@ -1,2 +1,4 @@
let main (i: int) = type integer is int
if (i=2 : bool) then (42: int) else (0: int)
let main (i : int) =
if (i = 2 : bool) then (42 : int) else (0 : integer)

View File

@ -1,6 +1,6 @@
(* TODO : make a test using mutation, not shadowing *) (* TODO : make a test using mutation, not shadowing *)
let main (i: int) = let main (i : int) =
let result = 0 in let result = 0 in
if i = 2 then if i = 2 then
let result = 42 in result let result = 42 in result

View File

@ -1,4 +1,4 @@
type storage = int type storage = int
let main (ps: int * storage) = let main (ps : int * storage) =
(([] : operation list) , ps.0 + ps.1) ([] : operation list), ps.0 + ps.1

View File

@ -1,2 +1,2 @@
let hasherman512 (s: bytes) : bytes = Crypto.sha512 s let hasherman512 (s : bytes) : bytes = Crypto.sha512 s
let hasherman_blake (s: bytes) : bytes = Crypto.blake2b s let hasherman_blake (s : bytes) : bytes = Crypto.blake2b s

View File

@ -1,9 +1,9 @@
let conv_test (j: int) (k: int) = j + k let conv_test (j : int) (k : int) = j + k
let main (i: int) : int = conv_test i 10 let main (i : int) : int = conv_test i 10
let partial (a: int) (b: int) : int = a + b let partial (a : int) (b : int) : int = a + b
let mk_partial (j: int) : (int -> int) = partial j let mk_partial (j : int) : int -> int = partial j
let partial_apply (i: int) : int = (mk_partial 10) i let partial_apply (i : int) : int = mk_partial 10 i

View File

@ -1,8 +1,8 @@
type foo = type foo =
| Bar of int Bar of int
| Baz | Baz
let main (f: foo): int = let main (f : foo) : int =
match f with match f with
| Bar i -> i Bar i -> i
| Baz -> -1 | Baz -> -1

View File

@ -1,3 +1,3 @@
// Test conditional in CameLIGO // Test conditional in CameLIGO
let main (a , b : bool * bool) = if a = b then 999 else 1 let main (a, b : bool * bool) = if a = b then 999 else 1

View File

@ -1,4 +1,4 @@
type storage = unit type storage = unit
let main (p: unit) storage = let main (p : unit; store : storage) : operation list * storage =
if true then failwith "This contract always fails" else () if true then failwith "This contract always fails"

View File

@ -1,7 +1,9 @@
type storage = unit type storage = unit
let main (p: unit) storage = let main (p : unit; store : storage) : operation list * storage =
(fun (f: (int * int) -> int) (x: int) (y: int) -> f (y,x)) let n =
(fun (x: int) (y: int) -> x + y) (fun (f : int * int -> int) (x : int) (y : int) -> f (y,x))
0 (fun (x : int) (y : int) -> x + y)
1 0
1
in ([] : operation list), store

View File

@ -1,7 +1,9 @@
type storage = unit type storage = unit
let main (p: unit) storage = let main (p : unit; store : storage) : operation list * storage =
(fun (f: int -> int) (_: int) (y: int) -> f y) let n =
(fun (x: int) -> x) (fun (f : int -> int) (z : int) (y : int) -> f y)
0 (fun (x : int) -> x)
1 0
1
in ([] : operation list), store

View File

@ -1,7 +1,9 @@
type storage = unit type storage = unit
let main (p: unit) storage = let main (p : unit; store : storage) : operation list * storage =
(fun (f: int -> int -> int) (x: int) (y: int) -> f y (x+y)) let n =
(fun (x: int) (y: int) -> x + y) (fun (f : int -> int -> int) (x : int) (y : int) -> f y (x+y))
0 (fun (x : int) (y : int) -> x + y)
1 0
1
in ([] : operation list), store

View File

@ -1,7 +1,7 @@
(* Test use of multiple subroutines in a CameLIGO function *) (* Test use of multiple subroutines in a CameLIGO function *)
let foo (i: int) : int = i + 20 let foo (i : int) : int = i + 20
let bar (i: int) : int = i + 50 let bar (i : int) : int = i + 50
let foobar (i: int) : int = (foo i) + (bar i) let foobar (i : int) : int = foo i + bar i

View File

@ -1,20 +1,18 @@
type storage = { type storage = {
challenge : string; challenge : string
} }
type param = { type param = {
new_challenge : string; new_challenge : string;
attempt : string; attempt : string
} }
let attempt (p: param) storage = type return = operation list * storage
(* if p.attempt <> storage.challenge then failwith "Failed challenge" else *)
let contract : unit contract = let attempt (p: param; store : storage) : return =
Operation.get_contract sender in (* if p.attempt <> store.challenge then failwith "Failed challenge" else *)
let contract : unit contract = Operation.get_contract sender in
let transfer : operation = let transfer : operation =
Operation.transaction (unit , contract , 10.00tz) in Operation.transaction (unit, contract, 10.00tez) in
(* TODO: no syntax for functional updates yet *) let store : storage = {challenge = p.new_challenge}
(* let storage : storage = { storage with challenge = p.new_challenge } in *) in ([] : operation list), store
(* for now, rebuild the record by hand. *)
let storage : storage = { challenge = p.new_challenge }
in ([] : operation list), storage

View File

@ -1,13 +1,13 @@
// Test the option type in PascaLIGO // Test the option type in PascaLIGO
type foobar is option(int) type foobar is option (int)
const s : foobar = Some(42) const s : foobar = Some (42)
const n : foobar = None const n : foobar = None
function assign (var m : int) : foobar is function assign (var m : int) : foobar is
block { block {
var coco : foobar := None; var coco : foobar := None;
coco := Some(m); coco := Some (m);
coco := (None : foobar); //temporary annotation added until type inference coco := (None : foobar); //temporary annotation added until type inference
} with coco } with coco

View File

@ -1,6 +0,0 @@
function f (const x : unit) : unit is
begin skip end with unit
function main (const p : unit ; const s : unit) : unit is
behin skip end with f unit
// the srcloc is correct but the reported term is "skip" instead of "behin".

View File

@ -1,11 +0,0 @@
// Test a trivial PascaLIGO procedure
procedure sub (const j: int) is
begin
i := i + 1
end
function main (const i: int) : int is
begin
sub(i)
end with i

View File

@ -1,8 +1,3 @@
function foo (const input : int) : int is begin function foo (const input : int) : int is input + 42
skip
end with (input + 42)
function main (const i : int) : int is function main (const i : int) : int is i + foo (i)
begin
skip
end with i + foo (i)

View File

@ -1,13 +1,5 @@
function foo (const input : int) : int is begin function foo (const input : int) : int is input + 23
skip
end with (input + 23)
function bar (const input : int) : int is begin function bar (const input : int) : int is input + 51
skip
end with (input + 51)
function main (const i : int) : int is foo (i) + bar (i)
function main (const i : int) : int is
begin
skip
end with foo (i) + bar (i)

View File

@ -1,68 +1,38 @@
// Test record type in PascaLIGO // Test record type in PascaLIGO
type foobar is record type foobar is record [foo : int; bar : int]
foo : int ;
bar : int ;
end
const fb : foobar = record const fb : foobar = record [foo = 0; bar = 0]
foo = 0 ;
bar = 0 ;
end
type abc is record type abc is record [a : int; b : int; c : int]
a : int ;
b : int ;
c : int ;
end
const abc : abc = record const abc : abc = record [a = 42; b = 142; c = 242]
a = 42 ;
b = 142 ;
c = 242 ;
end
const a : int = abc.a ; const a : int = abc.a
const b : int = abc.b ; const b : int = abc.b
const c : int = abc.c ; const c : int = abc.c
function projection (const r : foobar) : int is function projection (const r : foobar) : int is r.foo + r.bar
begin
skip
end with r.foo + r.bar
function modify (const r : foobar) : foobar is function modify (var r : foobar) : foobar is
block { block {
r.foo := 256 ; r.foo := 256
} with r } with r
function modify_abc (const r : abc) : abc is function modify_abc (const r : abc) : abc is
block { block {
const c : int = 42; const c : int = 42;
r := r with record b = 2048; c = c; end; r := r with record [b=2048; c=c]
} with r } with r
type big_record is record type big_record is record [a : int; b : int; c : int; d : int; e : int]
a : int ;
b : int ;
c : int ;
d : int ;
e : int ;
end
const br : big_record = record const br : big_record =
a = 23 ; record [a = 23; b = 23; c = 23; d = 23; e = 23]
b = 23 ;
c = 23 ;
d = 23 ;
e = 23 ;
end
type double_record is record type double_record is record [inner : abc]
inner : abc;
end
function modify_inner (const r : double_record) : double_record is function modify_inner (const r : double_record) : double_record is
block { block {
r := r with record inner.b = 2048; end; r := r with record [inner.b = 2048]
} with r } with r

View File

@ -1,6 +1,6 @@
function foo(const p : unit) : int is 0 function foo (const p : unit) : int is 0
function main(const p : unit; const s : int) : list(operation) * int is function main (const p : unit; const s : int) : list (operation) * int is
((list end : list(operation)), foo(unit)) ((nil : list (operation)), foo (unit))
function foo(const p : unit) : int is 1 function foo (const p : unit) : int is 1

View File

@ -1,35 +1,35 @@
// storage type // storage type
type storage_t is address; type storage_t is address
// entry points parameter types // entry points parameter types
type change_addr_pt is address type change_addr_pt is address
type message_t is list (operation) ; type message_t is list (operation)
type pass_message_pt is (unit -> message_t) type pass_message_pt is unit -> message_t
type contract_return_t is (list(operation) * storage_t) type contract_return_t is list (operation) * storage_t
type entry_point_t is type entry_point_t is
| Change_address of change_addr_pt Change_address of change_addr_pt
| Pass_message of pass_message_pt | Pass_message of pass_message_pt
function change_address (const param : change_addr_pt; function change_address (const param : change_addr_pt;
const s : storage_t) : contract_return_t is const s : storage_t) : contract_return_t is
begin block {
if sender =/= s then failwith("Unauthorized sender") if sender =/= s then failwith ("Unauthorized sender")
else skip else skip
end with ((nil : list(operation)), param) } with ((nil : list (operation)), param)
function pass_message ( const param: pass_message_pt; function pass_message (const param: pass_message_pt;
const s : storage_t ) : contract_return_t is const s : storage_t ) : contract_return_t is
begin block {
if sender =/= s then failwith("Unauthorized sender") else skip ; if sender =/= s then failwith("Unauthorized sender") else skip;
var message : pass_message_pt := param ; var message : pass_message_pt := param
end with (param(unit),s) } with (param (unit), s)
function main(const param : entry_point_t; const s : storage_t) : contract_return_t is function main (const param : entry_point_t; const s : storage_t) :
block {skip} with contract_return_t is
case param of case param of
| Change_address (p) -> change_address(p,s) Change_address (p) -> change_address (p,s)
| Pass_message (p) -> pass_message(p,s) | Pass_message (p) -> pass_message (p,s)
end end

View File

@ -1 +1 @@
function main (const p: unit) : address is self_address function main (const p : unit) : address is self_address

View File

@ -1,17 +1,17 @@
// Test set iteration in PascaLIGO // Test set iteration in PascaLIGO
function iter_op (const s : set(int)) : int is function iter_op (const s : set (int)) : int is
begin
var r : int := 0 ;
function aggregate (const i : int) : unit is
begin
r := r + i ;
end with unit ;
set_iter(aggregate, s) ;
end with r
function fold_op (const s : set(int)) : int is
block { block {
function aggregate (const i : int ; const j : int) : int is var r : int := 0;
function aggregate (const i : int) : unit is
block {
r := r + i
} with unit;
set_iter (aggregate, s)
} with r // ALWAYS RETURNS 0
function fold_op (const s : set (int)) : int is
block {
function aggregate (const i : int; const j : int) : int is
i + j i + j
} with set_fold(aggregate, s , 15) } with set_fold (aggregate, s, 15)

View File

@ -1,30 +1,27 @@
// Test set type and basic operations in PascaLIGO // Test set type and basic operations in PascaLIGO
const s_e : set(string) = (set_empty : set(string)) const s_e : set (string) = set_empty
const s_fb : set(string) = set [ const s_fb : set (string) = set ["foo"; "bar"]
"foo" ;
"bar" ;
]
function add_op (const s : set(string)) : set(string) is function add_op (const s : set (string)) : set (string) is
begin skip end with set_add("foobar" , s) set_add ("foobar", s)
function remove_op (const s : set(string)) : set(string) is function remove_op (const s : set (string)) : set (string) is
begin skip end with set_remove("foobar" , s) set_remove ("foobar", s)
// Test the PascaLIGO syntactic sugar for set removal vs. the function call // Test the PascaLIGO syntactic sugar for set removal vs. the function call
function remove_syntax (var s : set(string)) : set(string) is function remove_syntax (var s : set (string)) : set (string) is
begin remove "foobar" from set s; end with s block {remove "foobar" from set s} with s
function remove_deep (var s : set(string) * nat) : set(string) * nat is function remove_deep (var s : set (string) * nat) : set (string) * nat is
begin remove "foobar" from set s.0; end with s block {remove "foobar" from set s.0} with s
function patch_op (var s: set(string)) : set(string) is function patch_op (var s : set (string)) : set (string) is
begin patch s with set ["foobar"]; end with s block {patch s with set ["foobar"]} with s
function patch_op_deep (var s: set(string)*nat) : set(string)*nat is function patch_op_deep (var s : set (string) * nat) : set (string) * nat is
begin patch s.0 with set ["foobar"]; end with s block {patch s.0 with set ["foobar"]} with s
function mem_op (const s : set(string)) : bool is function mem_op (const s : set (string)) : bool is
begin skip end with set_mem("foobar" , s) set_mem ("foobar", s)

View File

@ -1,6 +1,5 @@
function main (const p: key_hash) : list(operation) is function main (const p : key_hash) : list (operation) is
begin block {
const unused: operation = set_delegate(Some(p)) ; const unused : operation = set_delegate (Some (p));
const dummy: list(operation) = nil; const dummy : list (operation) = nil
end with dummy } with dummy

View File

@ -1,5 +1,4 @@
function foo (const i : int) : int is function foo (const i : int) : int is
block { block {
function bar (const i : int) : int is function bar (const i : int) : int is i
i ;
} with bar (0) } with bar (0)

View File

@ -1,21 +1,21 @@
//Test simple_access in PascalLigo //Test simple_access in PascaLIGO
type tpi is (int*int)
type rpi is record type tpi is int * int
x : int;
y : int; type rpi is record [x : int; y : int]
end
type mpi is map(string,int) type mpi is map (string, int)
function main (const toto : tpi) : int is function main (const toto : tpi) : int is
begin block {
var a : tpi := toto; var a : tpi := toto;
var b : rpi := record x = 0; y=1 ; end; var b : rpi := record [x=0; y=1];
var m : mpi := map "y" -> 1; end; var m : mpi := map ["y" -> 1];
a.0 := 2; a.0 := 2;
b.x := a.0; b.x := a.0;
m["x"] := b.x; m["x"] := b.x
end with } with
case m["x"] of case m["x"] of
| Some (s) -> s Some (s) -> s
| None -> 42 | None -> 42
end end

View File

@ -1,3 +1,3 @@
const s : string = "toto" const s : string = "toto"
const x : string = s^"bar" const x : string = s ^ "bar"
const y : string = "foo"^x const y : string = "foo" ^ x

View File

@ -1,5 +1,5 @@
function concat_op (const s : string) : string is function concat_op (const s : string) : string is
begin skip end with string_concat(s , "toto") string_concat (s, "toto")
function slice_op (const s : string) : string is function slice_op (const s : string) : string is
begin skip end with string_slice(1n , 2n , s) string_slice (1n, 2n, s)

View File

@ -1,10 +1,14 @@
type action is type action is
| Increment of int Increment of int
| Decrement of int | Decrement of int
function main (const p : action ; const s : int) : (list(operation) * int) is type storage is int
block {skip} with ((nil : list(operation)),
case p of type return is list (operation) * storage
| Increment (n) -> s + n
| Decrement (n) -> s - n function main (const p : action; const s : int) : return is
end) ((nil : list (operation)),
case p of
Increment (n) -> s + n
| Decrement (n) -> s - n
end)

View File

@ -1,16 +1,18 @@
const add_tez : tez = 21mutez + 0.000021tz; const add_tez : tez = 21mutez + 0.000_021tez
const sub_tez : tez = 21mutez - 20mutez;
const sub_tez : tez = 21mutez - 20mutez
(* This is not enough. *) (* This is not enough. *)
const not_enough_tez : tez = 4611686018427387903mutez;
const not_enough_tez : tez = 461_168_601_842_738_7903mutez
const nat_mul_tez : tez = 1n * 100mutez; const nat_mul_tez : tez = 1n * 100mutez
const tez_mul_nat : tez = 100mutez * 10n; const tez_mul_nat : tez = 100mutez * 10n
const tez_div_tez1 : nat = 100mutez / 1mutez; const tez_div_tez1 : nat = 100mutez / 1mutez
const tez_div_tez2 : nat = 100mutez / 90mutez; const tez_div_tez2 : nat = 100mutez / 90mutez
const tez_div_tez3 : nat = 100mutez / 110mutez; const tez_div_tez3 : nat = 100mutez / 110mutez
const tez_mod_tez1 : tez = 100mutez mod 1mutez; const tez_mod_tez1 : tez = 100mutez mod 1mutez
const tez_mod_tez2 : tez = 100mutez mod 90mutez; const tez_mod_tez2 : tez = 100mutez mod 90mutez
const tez_mod_tez3 : tez = 100mutez mod 110mutez; const tez_mod_tez3 : tez = 100mutez mod 110mutez

View File

@ -1,25 +1,28 @@
type storage_t is timestamp type storage_t is timestamp
type message_t is (unit -> list(operation)) type message_t is unit -> list (operation)
type default_pt is unit type default_pt is unit
type call_pt is message_t type call_pt is message_t
type contract_return_t is (list(operation) * storage_t) type contract_return_t is list (operation) * storage_t
type entry_point_t is type entry_point_t is
| Call of call_pt | Call of call_pt
| Default of default_pt | Default of default_pt
function call (const p : call_pt; const s : storage_t) : contract_return_t is block { function call (const p : call_pt; const s : storage_t) : contract_return_t is
if s >= now then failwith("Contract is still time locked") else skip ; block {
const message : message_t = p ; if s >= now then failwith ("Contract is still time locked") else skip;
const ret_ops : list(operation) = message(unit) ; const message : message_t = p;
} with (ret_ops,s) const ret_ops : list (operation) = message (unit)
} with (ret_ops, s)
function default (const p : default_pt; const s : storage_t) : contract_return_t is function default (const p : default_pt; const s : storage_t) :
((nil: list(operation)) , s) contract_return_t is
((nil : list (operation)), s)
function main(const param : entry_point_t; const s : storage_t) : contract_return_t is function main(const param : entry_point_t; const s : storage_t) :
contract_return_t is
case param of case param of
| Call (p) -> call(p,s) Call (p) -> call (p,s)
| Default (p) -> default(p,s) | Default (p) -> default (p,s)
end end

View File

@ -1,3 +1,4 @@
type storage_ is timestamp type storage_ is timestamp
function main(const p : unit; const s : storage_) : list(operation) * storage_ is ((nil: list(operation)), now) function main (const p : unit; const s : storage_) :
list (operation) * storage_ is ((nil: list (operation)), now)

View File

@ -1,6 +1,3 @@
type toto is record type toto is record [a : nat; b : nat]
a : nat ;
b : nat
end
const foo : int = 3 const foo : int = 3

View File

@ -1,22 +1,18 @@
type abc is (int * int * int) type abc is int * int * int
function projection_abc (const tpl : abc) : int is function projection_abc (const tpl : abc) : int is tpl.1
block { skip } with tpl.1
function modify_abc (const tpl : abc) : abc is function modify_abc (const tpl : abc) : abc is
block { block {
tpl.1 := 2048 ; tpl.1 := 2048
} with tpl } with tpl
type foobar is (int * int) type foobar is int * int
const fb : foobar = (0, 0) const fb : foobar = (0,0)
function projection (const tpl : foobar) : int is function projection (const tpl : foobar) : int is tpl.0 + tpl.1
begin
skip
end with tpl.0 + tpl.1
type big_tuple is (int * int * int * int * int) type big_tuple is int * int * int * int * int
const br : big_tuple = (23, 23, 23, 23, 23) const br : big_tuple = (23, 23, 23, 23, 23)

View File

@ -1,11 +1,11 @@
type foobar is type foobar is
| Foo of int Foo of int
| Bar of bool | Bar of bool
| Kee of nat | Kee of nat
function fb(const p : foobar) : int is function fb (const p : foobar) : int is
block { skip } with (case p of case p of
| Foo (n) -> n Foo (n) -> n
| Bar (t) -> 42 | Bar (t) -> 42
| Kee (n) -> 23 | Kee (n) -> 23
end) end

View File

@ -1,5 +1,5 @@
type foobar is type foobar is
| Foo of int Foo of int
| Bar of bool | Bar of bool
| Kee of nat | Kee of nat

View File

@ -1,2 +1,2 @@
function main (const p : int ; const s : int) : (list(operation) * int) is function main (const p : int; const s : int) : list (operation) * int is
block {skip} with ((nil : list(operation)), s + 1) ((nil : list (operation)), s + 1)

View File

@ -1,16 +1,20 @@
// variant defining pseudo multi-entrypoint actions // variant defining entrypoints
type action is type action is
| Increment of int Increment of int
| Decrement of int | Decrement of int
function add (const a : int ; const b : int) : int is a + b type return is list (operation) * int
function subtract (const a : int ; const b : int) : int is a - b function add (const a : int; const b : int) : int is a + b
// real entrypoint that re-routes the flow based on the action provided function subtract (const a : int; const b : int) : int is a - b
function main (const p : action ; const s : int) : (list(operation) * int) is
((nil : list(operation)), // main function routing the flow based on the action provided
function main (const p : action; const s : int) : return is
((nil : list (operation)),
case p of case p of
| Increment (n) -> add (s, n) Increment (n) -> add (s, n)
| Decrement (n) -> subtract (s, n) | Decrement (n) -> subtract (s, n)
end) end)