Updating contracts.
This commit is contained in:
parent
4d61c2285c
commit
93682629b4
@ -1,3 +1,3 @@
|
||||
let main (p : key_hash) =
|
||||
let c : unit contract = Current.implicit_account p in
|
||||
Current.address c
|
||||
let c : unit contract = Current.implicit_account p
|
||||
in Current.address c
|
||||
|
@ -1,8 +1,8 @@
|
||||
function check (const p: unit) : int is
|
||||
begin
|
||||
function check (const p : unit) : int is
|
||||
block {
|
||||
var result : int := 0;
|
||||
if amount = 100tz then
|
||||
if Tezos.amount = 100tz then
|
||||
result := 42
|
||||
else
|
||||
result := 0
|
||||
end with result
|
||||
} with result
|
||||
|
@ -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
|
||||
|
@ -1,30 +1,17 @@
|
||||
// Test CameLIGO arithmetic operators
|
||||
|
||||
let mod_op (n : int) : nat =
|
||||
n mod 42
|
||||
let mod_op (n : int) : nat = n mod 42
|
||||
|
||||
let plus_op (n : int) : int =
|
||||
n + 42
|
||||
let plus_op (n : int) : int = n + 42
|
||||
|
||||
let minus_op (n : int) : int =
|
||||
n - 42
|
||||
let minus_op (n : int) : int = n - 42
|
||||
|
||||
let times_op (n : int) : int =
|
||||
n * 42
|
||||
let times_op (n : int) : int = n * 42
|
||||
|
||||
let div_op (n : int) : int =
|
||||
n / 2
|
||||
let div_op (n : int) : int = n / 2
|
||||
|
||||
(* TODO (?): Support conversion from nat to int and back
|
||||
|
||||
let int_op (n : nat) : int =
|
||||
Int n
|
||||
|
||||
*)
|
||||
|
||||
let neg_op (n : int) : int =
|
||||
-n
|
||||
let neg_op (n : int) : int = -n
|
||||
|
||||
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)
|
||||
|
@ -1,3 +1,3 @@
|
||||
let main (p, s: bool * unit) =
|
||||
let main (p, s : bool * unit) =
|
||||
let u : unit = assert p
|
||||
in ([] : operation list), s
|
||||
|
@ -1,10 +1,10 @@
|
||||
let x = 1 [@@inline]
|
||||
|
||||
let foo (a: int): int =
|
||||
let foo (a : int): int =
|
||||
(let test = 2 + a [@@inline] in test) [@@inline]
|
||||
|
||||
let y = 1 [@@inline][@@other]
|
||||
|
||||
let bar (b: int): int =
|
||||
let test = fun (z: int) -> 2 + b + z [@@inline][@@foo][@@bar]
|
||||
let bar (b : int): int =
|
||||
let test = fun (z : int) -> 2 + b + z [@@inline][@@foo][@@bar]
|
||||
in test b
|
||||
|
@ -1,17 +1,16 @@
|
||||
(**
|
||||
|
||||
(*
|
||||
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"}
|
||||
|
||||
|
||||
*)
|
||||
|
||||
type storage = tez
|
||||
|
||||
let main (p, s : unit * storage) =
|
||||
([] : operation list), balance
|
||||
|
||||
|
@ -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 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 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 map1 : foo = Big_map.literal
|
||||
[ (23 , 0) ; (42, 0) ]
|
||||
let map1 : foo = Big_map.literal [(23,0); (42,0)]
|
||||
|
||||
let map1 : foo = Big_map.literal
|
||||
[ (23 , 0) ; (42, 0) ]
|
||||
let map1 : foo = Big_map.literal [(23,0); (42,0)]
|
||||
|
||||
let mutimaps (m : foo) (n : foo) : foo =
|
||||
let bar : foo = Big_map.update 42 (Some 0) m in
|
||||
Big_map.update 42 (get bar) n
|
||||
let bar : foo = Big_map.update 42 (Some 0) m
|
||||
in Big_map.update 42 (get bar) n
|
||||
|
@ -1,7 +1,7 @@
|
||||
(* Test CameLIGO bitwise operators *)
|
||||
|
||||
let or_op (n: nat) : nat = Bitwise.or n 4n
|
||||
let and_op (n: nat) : nat = Bitwise.and n 7n
|
||||
let xor_op (n: nat) : nat = Bitwise.xor 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 or_op (n : nat) : nat = Bitwise.lor n 4n
|
||||
let and_op (n : nat) : nat = Bitwise.land n 7n
|
||||
let xor_op (n : nat) : nat = Bitwise.lxor n 7n
|
||||
let lsl_op (n : nat) : nat = Bitwise.shift_left n 7n
|
||||
let lsr_op (n : nat) : nat = Bitwise.shift_right n 7n
|
||||
|
@ -1,16 +1,11 @@
|
||||
// Test CameLIGO boolean operators
|
||||
|
||||
let or_true (b : bool) : bool =
|
||||
b || true
|
||||
let or_true (b : bool) : bool = b || true
|
||||
|
||||
let or_false (b : bool) : bool =
|
||||
b || false
|
||||
let or_false (b : bool) : bool = b || false
|
||||
|
||||
let and_true (b : bool) : bool =
|
||||
b && true
|
||||
let and_true (b : bool) : bool = b && true
|
||||
|
||||
let and_false (b : bool) : bool =
|
||||
b && false
|
||||
let and_false (b : bool) : bool = b && false
|
||||
|
||||
let not_bool (b: bool) : bool =
|
||||
not b
|
||||
let not_bool (b : bool) : bool = not b
|
||||
|
@ -1,8 +1,5 @@
|
||||
let concat_op (s : bytes) : bytes =
|
||||
Bytes.concat s 0x7070
|
||||
let concat_op (s : bytes) : bytes = Bytes.concat s 0x7070
|
||||
|
||||
let slice_op (s : bytes) : bytes =
|
||||
Bytes.slice 1n 2n s
|
||||
let slice_op (s : bytes) : bytes = Bytes.slice 1n 2n s
|
||||
|
||||
let hasherman (s : bytes) : bytes =
|
||||
Crypto.sha256 s
|
||||
let hasherman (s : bytes) : bytes = Crypto.sha256 s
|
||||
|
@ -1,11 +1,11 @@
|
||||
let id_string (p: string) : string option =
|
||||
let packed: bytes = Bytes.pack p in
|
||||
((Bytes.unpack packed): string option)
|
||||
let id_string (p : string) : string option =
|
||||
let packed : bytes = Bytes.pack p in
|
||||
(Bytes.unpack packed : string option)
|
||||
|
||||
let id_int (p: int) : int option =
|
||||
let packed: bytes = Bytes.pack p in
|
||||
((Bytes.unpack packed): int option)
|
||||
let id_int (p : int) : int option =
|
||||
let packed : bytes = Bytes.pack p in
|
||||
(Bytes.unpack packed : int option)
|
||||
|
||||
let id_address (p: address) : address option =
|
||||
let packed: bytes = Bytes.pack p in
|
||||
((Bytes.unpack packed): address option)
|
||||
let id_address (p : address) : address option =
|
||||
let packed : bytes = Bytes.pack p in
|
||||
(Bytes.unpack packed : address option)
|
||||
|
@ -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
|
||||
|
@ -1,9 +1,7 @@
|
||||
(* Test whether closures retain values in CameLIGO *)
|
||||
|
||||
let test (k: int) : int =
|
||||
let j: int = k + 5 in
|
||||
let close: (int -> int) =
|
||||
fun (i: int) -> i + j
|
||||
in
|
||||
let j: int = 20 in (* Shadow original variable to see if value close'd *)
|
||||
close 20
|
||||
let test (k : int) : int =
|
||||
let j : int = k + 5 in
|
||||
let close : int -> int = fun (i : int) -> i + j in
|
||||
let j : int = 20 (* Shadow original variable *)
|
||||
in close 20
|
||||
|
@ -1,2 +1,4 @@
|
||||
let main (i: int) =
|
||||
if (i=2 : bool) then (42: int) else (0: int)
|
||||
type integer is int
|
||||
|
||||
let main (i : int) =
|
||||
if (i = 2 : bool) then (42 : int) else (0 : integer)
|
||||
|
@ -1,6 +1,6 @@
|
||||
(* TODO : make a test using mutation, not shadowing *)
|
||||
|
||||
let main (i: int) =
|
||||
let main (i : int) =
|
||||
let result = 0 in
|
||||
if i = 2 then
|
||||
let result = 42 in result
|
||||
|
@ -1,4 +1,4 @@
|
||||
type storage = int
|
||||
|
||||
let main (ps: int * storage) =
|
||||
(([] : operation list) , ps.0 + ps.1)
|
||||
let main (ps : int * storage) =
|
||||
([] : operation list), ps.0 + ps.1
|
||||
|
@ -1,2 +1,2 @@
|
||||
let hasherman512 (s: bytes) : bytes = Crypto.sha512 s
|
||||
let hasherman_blake (s: bytes) : bytes = Crypto.blake2b s
|
||||
let hasherman512 (s : bytes) : bytes = Crypto.sha512 s
|
||||
let hasherman_blake (s : bytes) : bytes = Crypto.blake2b s
|
||||
|
@ -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
|
||||
|
@ -1,8 +1,8 @@
|
||||
type foo =
|
||||
| Bar of int
|
||||
| Baz
|
||||
Bar of int
|
||||
| Baz
|
||||
|
||||
let main (f: foo): int =
|
||||
let main (f : foo) : int =
|
||||
match f with
|
||||
| Bar i -> i
|
||||
Bar i -> i
|
||||
| Baz -> -1
|
@ -1,3 +1,3 @@
|
||||
// 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
|
||||
|
@ -1,4 +1,4 @@
|
||||
type storage = unit
|
||||
|
||||
let main (p: unit) storage =
|
||||
if true then failwith "This contract always fails" else ()
|
||||
let main (p : unit; store : storage) : operation list * storage =
|
||||
if true then failwith "This contract always fails"
|
||||
|
@ -1,7 +1,9 @@
|
||||
type storage = unit
|
||||
|
||||
let main (p: unit) storage =
|
||||
(fun (f: (int * int) -> int) (x: int) (y: int) -> f (y,x))
|
||||
(fun (x: int) (y: int) -> x + y)
|
||||
0
|
||||
1
|
||||
let main (p : unit; store : storage) : operation list * storage =
|
||||
let n =
|
||||
(fun (f : int * int -> int) (x : int) (y : int) -> f (y,x))
|
||||
(fun (x : int) (y : int) -> x + y)
|
||||
0
|
||||
1
|
||||
in ([] : operation list), store
|
||||
|
@ -1,7 +1,9 @@
|
||||
type storage = unit
|
||||
|
||||
let main (p: unit) storage =
|
||||
(fun (f: int -> int) (_: int) (y: int) -> f y)
|
||||
(fun (x: int) -> x)
|
||||
0
|
||||
1
|
||||
let main (p : unit; store : storage) : operation list * storage =
|
||||
let n =
|
||||
(fun (f : int -> int) (z : int) (y : int) -> f y)
|
||||
(fun (x : int) -> x)
|
||||
0
|
||||
1
|
||||
in ([] : operation list), store
|
||||
|
@ -1,7 +1,9 @@
|
||||
type storage = unit
|
||||
|
||||
let main (p: unit) storage =
|
||||
(fun (f: int -> int -> int) (x: int) (y: int) -> f y (x+y))
|
||||
(fun (x: int) (y: int) -> x + y)
|
||||
0
|
||||
1
|
||||
let main (p : unit; store : storage) : operation list * storage =
|
||||
let n =
|
||||
(fun (f : int -> int -> int) (x : int) (y : int) -> f y (x+y))
|
||||
(fun (x : int) (y : int) -> x + y)
|
||||
0
|
||||
1
|
||||
in ([] : operation list), store
|
||||
|
@ -1,7 +1,7 @@
|
||||
(* 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
|
||||
|
@ -1,20 +1,18 @@
|
||||
type storage = {
|
||||
challenge : string;
|
||||
challenge : string
|
||||
}
|
||||
|
||||
type param = {
|
||||
new_challenge : string;
|
||||
attempt : string;
|
||||
attempt : string
|
||||
}
|
||||
|
||||
let attempt (p: param) storage =
|
||||
(* if p.attempt <> storage.challenge then failwith "Failed challenge" else *)
|
||||
let contract : unit contract =
|
||||
Operation.get_contract sender in
|
||||
type return = operation list * storage
|
||||
|
||||
let attempt (p: param; store : storage) : return =
|
||||
(* if p.attempt <> store.challenge then failwith "Failed challenge" else *)
|
||||
let contract : unit contract = Operation.get_contract sender in
|
||||
let transfer : operation =
|
||||
Operation.transaction (unit , contract , 10.00tz) in
|
||||
(* TODO: no syntax for functional updates yet *)
|
||||
(* let storage : storage = { storage with challenge = p.new_challenge } in *)
|
||||
(* for now, rebuild the record by hand. *)
|
||||
let storage : storage = { challenge = p.new_challenge }
|
||||
in ([] : operation list), storage
|
||||
Operation.transaction (unit, contract, 10.00tez) in
|
||||
let store : storage = {challenge = p.new_challenge}
|
||||
in ([] : operation list), store
|
||||
|
@ -1,13 +1,13 @@
|
||||
// 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
|
||||
|
||||
function assign (var m : int) : foobar is
|
||||
block {
|
||||
var coco : foobar := None;
|
||||
coco := Some(m);
|
||||
coco := Some (m);
|
||||
coco := (None : foobar); //temporary annotation added until type inference
|
||||
} with coco
|
||||
|
@ -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".
|
@ -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
|
@ -1,8 +1,3 @@
|
||||
function foo (const input : int) : int is begin
|
||||
skip
|
||||
end with (input + 42)
|
||||
function foo (const input : int) : int is input + 42
|
||||
|
||||
function main (const i : int) : int is
|
||||
begin
|
||||
skip
|
||||
end with i + foo (i)
|
||||
function main (const i : int) : int is i + foo (i)
|
||||
|
@ -1,13 +1,5 @@
|
||||
function foo (const input : int) : int is begin
|
||||
skip
|
||||
end with (input + 23)
|
||||
function foo (const input : int) : int is input + 23
|
||||
|
||||
function bar (const input : int) : int is begin
|
||||
skip
|
||||
end with (input + 51)
|
||||
function bar (const input : int) : int is input + 51
|
||||
|
||||
|
||||
function main (const i : int) : int is
|
||||
begin
|
||||
skip
|
||||
end with foo (i) + bar (i)
|
||||
function main (const i : int) : int is foo (i) + bar (i)
|
||||
|
@ -1,68 +1,38 @@
|
||||
// Test record type in PascaLIGO
|
||||
|
||||
type foobar is record
|
||||
foo : int ;
|
||||
bar : int ;
|
||||
end
|
||||
type foobar is record [foo : int; bar : int]
|
||||
|
||||
const fb : foobar = record
|
||||
foo = 0 ;
|
||||
bar = 0 ;
|
||||
end
|
||||
const fb : foobar = record [foo = 0; bar = 0]
|
||||
|
||||
type abc is record
|
||||
a : int ;
|
||||
b : int ;
|
||||
c : int ;
|
||||
end
|
||||
type abc is record [a : int; b : int; c : int]
|
||||
|
||||
const abc : abc = record
|
||||
a = 42 ;
|
||||
b = 142 ;
|
||||
c = 242 ;
|
||||
end
|
||||
const abc : abc = record [a = 42; b = 142; c = 242]
|
||||
|
||||
const a : int = abc.a ;
|
||||
const b : int = abc.b ;
|
||||
const c : int = abc.c ;
|
||||
const a : int = abc.a
|
||||
const b : int = abc.b
|
||||
const c : int = abc.c
|
||||
|
||||
function projection (const r : foobar) : int is
|
||||
begin
|
||||
skip
|
||||
end with r.foo + r.bar
|
||||
function projection (const r : foobar) : int is r.foo + r.bar
|
||||
|
||||
function modify (const r : foobar) : foobar is
|
||||
function modify (var r : foobar) : foobar is
|
||||
block {
|
||||
r.foo := 256 ;
|
||||
r.foo := 256
|
||||
} with r
|
||||
|
||||
function modify_abc (const r : abc) : abc is
|
||||
block {
|
||||
const c : int = 42;
|
||||
r := r with record b = 2048; c = c; end;
|
||||
r := r with record [b=2048; c=c]
|
||||
} with r
|
||||
|
||||
type big_record is record
|
||||
a : int ;
|
||||
b : int ;
|
||||
c : int ;
|
||||
d : int ;
|
||||
e : int ;
|
||||
end
|
||||
type big_record is record [a : int; b : int; c : int; d : int; e : int]
|
||||
|
||||
const br : big_record = record
|
||||
a = 23 ;
|
||||
b = 23 ;
|
||||
c = 23 ;
|
||||
d = 23 ;
|
||||
e = 23 ;
|
||||
end
|
||||
const br : big_record =
|
||||
record [a = 23; b = 23; c = 23; d = 23; e = 23]
|
||||
|
||||
type double_record is record
|
||||
inner : abc;
|
||||
end
|
||||
type double_record is record [inner : abc]
|
||||
|
||||
function modify_inner (const r : double_record) : double_record is
|
||||
block {
|
||||
r := r with record inner.b = 2048; end;
|
||||
r := r with record [inner.b = 2048]
|
||||
} with r
|
||||
|
@ -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
|
||||
((list end : list(operation)), foo(unit))
|
||||
function main (const p : unit; const s : int) : list (operation) * int is
|
||||
((nil : list (operation)), foo (unit))
|
||||
|
||||
function foo(const p : unit) : int is 1
|
||||
function foo (const p : unit) : int is 1
|
||||
|
@ -1,35 +1,35 @@
|
||||
// storage type
|
||||
type storage_t is address;
|
||||
type storage_t is address
|
||||
|
||||
// entry points parameter types
|
||||
type change_addr_pt is address
|
||||
|
||||
type message_t is list (operation) ;
|
||||
type pass_message_pt is (unit -> message_t)
|
||||
type message_t is list (operation)
|
||||
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
|
||||
| Change_address of change_addr_pt
|
||||
| Pass_message of pass_message_pt
|
||||
Change_address of change_addr_pt
|
||||
| Pass_message of pass_message_pt
|
||||
|
||||
function change_address (const param : change_addr_pt;
|
||||
const s : storage_t) : contract_return_t is
|
||||
begin
|
||||
if sender =/= s then failwith("Unauthorized sender")
|
||||
block {
|
||||
if sender =/= s then failwith ("Unauthorized sender")
|
||||
else skip
|
||||
end with ((nil : list(operation)), param)
|
||||
} with ((nil : list (operation)), param)
|
||||
|
||||
function pass_message ( const param: pass_message_pt;
|
||||
const s : storage_t ) : contract_return_t is
|
||||
begin
|
||||
if sender =/= s then failwith("Unauthorized sender") else skip ;
|
||||
var message : pass_message_pt := param ;
|
||||
end with (param(unit),s)
|
||||
function pass_message (const param: pass_message_pt;
|
||||
const s : storage_t ) : contract_return_t is
|
||||
block {
|
||||
if sender =/= s then failwith("Unauthorized sender") else skip;
|
||||
var message : pass_message_pt := param
|
||||
} with (param (unit), s)
|
||||
|
||||
function main(const param : entry_point_t; const s : storage_t) : contract_return_t is
|
||||
block {skip} with
|
||||
function main (const param : entry_point_t; const s : storage_t) :
|
||||
contract_return_t is
|
||||
case param of
|
||||
| Change_address (p) -> change_address(p,s)
|
||||
| Pass_message (p) -> pass_message(p,s)
|
||||
end
|
||||
Change_address (p) -> change_address (p,s)
|
||||
| Pass_message (p) -> pass_message (p,s)
|
||||
end
|
||||
|
@ -1 +1 @@
|
||||
function main (const p: unit) : address is self_address
|
||||
function main (const p : unit) : address is self_address
|
||||
|
@ -1,17 +1,17 @@
|
||||
// Test set iteration in PascaLIGO
|
||||
|
||||
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
|
||||
function iter_op (const s : set (int)) : int is
|
||||
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
|
||||
} with set_fold(aggregate, s , 15)
|
||||
} with set_fold (aggregate, s, 15)
|
||||
|
@ -1,30 +1,27 @@
|
||||
// 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 [
|
||||
"foo" ;
|
||||
"bar" ;
|
||||
]
|
||||
const s_fb : set (string) = set ["foo"; "bar"]
|
||||
|
||||
function add_op (const s : set(string)) : set(string) is
|
||||
begin skip end with set_add("foobar" , s)
|
||||
function add_op (const s : set (string)) : set (string) is
|
||||
set_add ("foobar", s)
|
||||
|
||||
function remove_op (const s : set(string)) : set(string) is
|
||||
begin skip end with set_remove("foobar" , s)
|
||||
function remove_op (const s : set (string)) : set (string) is
|
||||
set_remove ("foobar", s)
|
||||
|
||||
// Test the PascaLIGO syntactic sugar for set removal vs. the function call
|
||||
function remove_syntax (var s : set(string)) : set(string) is
|
||||
begin remove "foobar" from set s; end with s
|
||||
function remove_syntax (var s : set (string)) : set (string) is
|
||||
block {remove "foobar" from set s} with s
|
||||
|
||||
function remove_deep (var s : set(string) * nat) : set(string) * nat is
|
||||
begin remove "foobar" from set s.0; end with s
|
||||
function remove_deep (var s : set (string) * nat) : set (string) * nat is
|
||||
block {remove "foobar" from set s.0} with s
|
||||
|
||||
function patch_op (var s: set(string)) : set(string) is
|
||||
begin patch s with set ["foobar"]; end with s
|
||||
function patch_op (var s : set (string)) : set (string) is
|
||||
block {patch s with set ["foobar"]} with s
|
||||
|
||||
function patch_op_deep (var s: set(string)*nat) : set(string)*nat is
|
||||
begin patch s.0 with set ["foobar"]; end with s
|
||||
function patch_op_deep (var s : set (string) * nat) : set (string) * nat is
|
||||
block {patch s.0 with set ["foobar"]} with s
|
||||
|
||||
function mem_op (const s : set(string)) : bool is
|
||||
begin skip end with set_mem("foobar" , s)
|
||||
function mem_op (const s : set (string)) : bool is
|
||||
set_mem ("foobar", s)
|
||||
|
@ -1,6 +1,5 @@
|
||||
function main (const p: key_hash) : list(operation) is
|
||||
begin
|
||||
const unused: operation = set_delegate(Some(p)) ;
|
||||
const dummy: list(operation) = nil;
|
||||
end with dummy
|
||||
|
||||
function main (const p : key_hash) : list (operation) is
|
||||
block {
|
||||
const unused : operation = set_delegate (Some (p));
|
||||
const dummy : list (operation) = nil
|
||||
} with dummy
|
||||
|
@ -1,5 +1,4 @@
|
||||
function foo (const i : int) : int is
|
||||
block {
|
||||
function bar (const i : int) : int is
|
||||
i ;
|
||||
function bar (const i : int) : int is i
|
||||
} with bar (0)
|
||||
|
@ -1,21 +1,21 @@
|
||||
//Test simple_access in PascalLigo
|
||||
type tpi is (int*int)
|
||||
type rpi is record
|
||||
x : int;
|
||||
y : int;
|
||||
end
|
||||
type mpi is map(string,int)
|
||||
//Test simple_access in PascaLIGO
|
||||
|
||||
type tpi is int * int
|
||||
|
||||
type rpi is record [x : int; y : int]
|
||||
|
||||
type mpi is map (string, int)
|
||||
|
||||
function main (const toto : tpi) : int is
|
||||
begin
|
||||
block {
|
||||
var a : tpi := toto;
|
||||
var b : rpi := record x = 0; y=1 ; end;
|
||||
var m : mpi := map "y" -> 1; end;
|
||||
var b : rpi := record [x=0; y=1];
|
||||
var m : mpi := map ["y" -> 1];
|
||||
a.0 := 2;
|
||||
b.x := a.0;
|
||||
m["x"] := b.x;
|
||||
end with
|
||||
case m["x"] of
|
||||
| Some (s) -> s
|
||||
| None -> 42
|
||||
end
|
||||
m["x"] := b.x
|
||||
} with
|
||||
case m["x"] of
|
||||
Some (s) -> s
|
||||
| None -> 42
|
||||
end
|
||||
|
@ -1,3 +1,3 @@
|
||||
const s : string = "toto"
|
||||
const x : string = s^"bar"
|
||||
const y : string = "foo"^x
|
||||
const x : string = s ^ "bar"
|
||||
const y : string = "foo" ^ x
|
||||
|
@ -1,5 +1,5 @@
|
||||
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
|
||||
begin skip end with string_slice(1n , 2n , s)
|
||||
string_slice (1n, 2n, s)
|
||||
|
@ -1,10 +1,14 @@
|
||||
type action is
|
||||
| Increment of int
|
||||
Increment of int
|
||||
| Decrement of int
|
||||
|
||||
function main (const p : action ; const s : int) : (list(operation) * int) is
|
||||
block {skip} with ((nil : list(operation)),
|
||||
case p of
|
||||
| Increment (n) -> s + n
|
||||
| Decrement (n) -> s - n
|
||||
end)
|
||||
type storage is int
|
||||
|
||||
type return is list (operation) * storage
|
||||
|
||||
function main (const p : action; const s : int) : return is
|
||||
((nil : list (operation)),
|
||||
case p of
|
||||
Increment (n) -> s + n
|
||||
| Decrement (n) -> s - n
|
||||
end)
|
||||
|
@ -1,16 +1,18 @@
|
||||
const add_tez : tez = 21mutez + 0.000021tz;
|
||||
const sub_tez : tez = 21mutez - 20mutez;
|
||||
const add_tez : tez = 21mutez + 0.000_021tez
|
||||
|
||||
const sub_tez : tez = 21mutez - 20mutez
|
||||
|
||||
(* 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 tez_mul_nat : tez = 100mutez * 10n;
|
||||
const nat_mul_tez : tez = 1n * 100mutez
|
||||
const tez_mul_nat : tez = 100mutez * 10n
|
||||
|
||||
const tez_div_tez1 : nat = 100mutez / 1mutez;
|
||||
const tez_div_tez2 : nat = 100mutez / 90mutez;
|
||||
const tez_div_tez3 : nat = 100mutez / 110mutez;
|
||||
const tez_div_tez1 : nat = 100mutez / 1mutez
|
||||
const tez_div_tez2 : nat = 100mutez / 90mutez
|
||||
const tez_div_tez3 : nat = 100mutez / 110mutez
|
||||
|
||||
const tez_mod_tez1 : tez = 100mutez mod 1mutez;
|
||||
const tez_mod_tez2 : tez = 100mutez mod 90mutez;
|
||||
const tez_mod_tez3 : tez = 100mutez mod 110mutez;
|
||||
const tez_mod_tez1 : tez = 100mutez mod 1mutez
|
||||
const tez_mod_tez2 : tez = 100mutez mod 90mutez
|
||||
const tez_mod_tez3 : tez = 100mutez mod 110mutez
|
||||
|
@ -1,25 +1,28 @@
|
||||
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 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
|
||||
| Call of call_pt
|
||||
| Default of default_pt
|
||||
|
||||
function call (const p : call_pt; const s : storage_t) : contract_return_t is block {
|
||||
if s >= now then failwith("Contract is still time locked") else skip ;
|
||||
const message : message_t = p ;
|
||||
const ret_ops : list(operation) = message(unit) ;
|
||||
} with (ret_ops,s)
|
||||
function call (const p : call_pt; const s : storage_t) : contract_return_t is
|
||||
block {
|
||||
if s >= now then failwith ("Contract is still time locked") else skip;
|
||||
const message : message_t = p;
|
||||
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
|
||||
((nil: list(operation)) , s)
|
||||
function default (const p : default_pt; const s : storage_t) :
|
||||
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
|
||||
| Call (p) -> call(p,s)
|
||||
| Default (p) -> default(p,s)
|
||||
end
|
||||
Call (p) -> call (p,s)
|
||||
| Default (p) -> default (p,s)
|
||||
end
|
||||
|
@ -1,3 +1,4 @@
|
||||
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)
|
||||
|
@ -1,6 +1,3 @@
|
||||
type toto is record
|
||||
a : nat ;
|
||||
b : nat
|
||||
end
|
||||
type toto is record [a : nat; b : nat]
|
||||
|
||||
const foo : int = 3
|
||||
|
@ -1,22 +1,18 @@
|
||||
type abc is (int * int * int)
|
||||
type abc is int * int * int
|
||||
|
||||
function projection_abc (const tpl : abc) : int is
|
||||
block { skip } with tpl.1
|
||||
function projection_abc (const tpl : abc) : int is tpl.1
|
||||
|
||||
function modify_abc (const tpl : abc) : abc is
|
||||
block {
|
||||
tpl.1 := 2048 ;
|
||||
tpl.1 := 2048
|
||||
} 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
|
||||
begin
|
||||
skip
|
||||
end with tpl.0 + tpl.1
|
||||
function projection (const tpl : foobar) : int is 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)
|
||||
|
@ -1,11 +1,11 @@
|
||||
type foobar is
|
||||
| Foo of int
|
||||
Foo of int
|
||||
| Bar of bool
|
||||
| Kee of nat
|
||||
|
||||
function fb(const p : foobar) : int is
|
||||
block { skip } with (case p of
|
||||
| Foo (n) -> n
|
||||
function fb (const p : foobar) : int is
|
||||
case p of
|
||||
Foo (n) -> n
|
||||
| Bar (t) -> 42
|
||||
| Kee (n) -> 23
|
||||
end)
|
||||
end
|
||||
|
@ -1,5 +1,5 @@
|
||||
type foobar is
|
||||
| Foo of int
|
||||
Foo of int
|
||||
| Bar of bool
|
||||
| Kee of nat
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
function main (const p : int ; const s : int) : (list(operation) * int) is
|
||||
block {skip} with ((nil : list(operation)), s + 1)
|
||||
function main (const p : int; const s : int) : list (operation) * int is
|
||||
((nil : list (operation)), s + 1)
|
||||
|
@ -1,16 +1,20 @@
|
||||
// variant defining pseudo multi-entrypoint actions
|
||||
// variant defining entrypoints
|
||||
|
||||
type action is
|
||||
| Increment of int
|
||||
Increment 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 main (const p : action ; const s : int) : (list(operation) * int) is
|
||||
((nil : list(operation)),
|
||||
function subtract (const a : int; const b : int) : int is a - b
|
||||
|
||||
// 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
|
||||
| Increment (n) -> add (s, n)
|
||||
Increment (n) -> add (s, n)
|
||||
| Decrement (n) -> subtract (s, n)
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user