Updating contracts.
This commit is contained in:
parent
4d61c2285c
commit
93682629b4
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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,29 +1,16 @@
|
|||||||
// 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
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -12,12 +12,10 @@ 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
|
||||||
|
@ -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
|
||||||
|
@ -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
|
|
||||||
|
@ -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
|
|
||||||
|
@ -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)
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
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
|
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
|
type integer is int
|
||||||
|
|
||||||
let main (i : int) =
|
let main (i : int) =
|
||||||
if (i=2 : bool) then (42: int) else (0: int)
|
if (i = 2 : bool) then (42 : int) else (0 : integer)
|
||||||
|
@ -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
|
||||||
|
@ -4,6 +4,6 @@ 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 =
|
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
|
@ -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"
|
||||||
|
@ -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 (f : int * int -> int) (x : int) (y : int) -> f (y,x))
|
||||||
(fun (x : int) (y : int) -> x + y)
|
(fun (x : int) (y : int) -> x + y)
|
||||||
0
|
0
|
||||||
1
|
1
|
||||||
|
in ([] : operation list), store
|
||||||
|
@ -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 (f : int -> int) (z : int) (y : int) -> f y)
|
||||||
(fun (x : int) -> x)
|
(fun (x : int) -> x)
|
||||||
0
|
0
|
||||||
1
|
1
|
||||||
|
in ([] : operation list), store
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
type storage = unit
|
type storage = unit
|
||||||
|
|
||||||
let main (p: unit) storage =
|
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 (f : int -> int -> int) (x : int) (y : int) -> f y (x+y))
|
||||||
(fun (x : int) (y : int) -> x + y)
|
(fun (x : int) (y : int) -> x + y)
|
||||||
0
|
0
|
||||||
1
|
1
|
||||||
|
in ([] : operation list), store
|
||||||
|
@ -4,4 +4,4 @@ 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 = {
|
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
|
|
||||||
|
@ -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
|
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)
|
|
||||||
|
@ -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)
|
|
||||||
|
@ -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
|
||||||
|
@ -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
|
@ -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
|
@ -1,14 +1,14 @@
|
|||||||
// 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
|
block {
|
||||||
var r : int := 0;
|
var r : int := 0;
|
||||||
function aggregate (const i : int) : unit is
|
function aggregate (const i : int) : unit is
|
||||||
begin
|
block {
|
||||||
r := r + i ;
|
r := r + i
|
||||||
end with unit ;
|
} with unit;
|
||||||
set_iter(aggregate, s) ;
|
set_iter (aggregate, s)
|
||||||
end with r
|
} with r // ALWAYS RETURNS 0
|
||||||
|
|
||||||
function fold_op (const s : set (int)) : int is
|
function fold_op (const s : set (int)) : int is
|
||||||
block {
|
block {
|
||||||
|
@ -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)
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
@ -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
|
||||||
|
@ -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)
|
||||||
|
@ -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)),
|
|
||||||
|
type return is list (operation) * storage
|
||||||
|
|
||||||
|
function main (const p : action; const s : int) : return is
|
||||||
|
((nil : list (operation)),
|
||||||
case p of
|
case p of
|
||||||
| Increment (n) -> s + n
|
Increment (n) -> s + n
|
||||||
| Decrement (n) -> s - n
|
| Decrement (n) -> s - n
|
||||||
end)
|
end)
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
block {
|
||||||
if s >= now then failwith ("Contract is still time locked") else skip;
|
if s >= now then failwith ("Contract is still time locked") else skip;
|
||||||
const message : message_t = p;
|
const message : message_t = p;
|
||||||
const ret_ops : list(operation) = message(unit) ;
|
const ret_ops : list (operation) = message (unit)
|
||||||
} with (ret_ops, s)
|
} 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) :
|
||||||
|
contract_return_t is
|
||||||
((nil : list (operation)), s)
|
((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
|
@ -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)
|
||||||
|
@ -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
|
||||||
|
@ -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)
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
type return is list (operation) * int
|
||||||
|
|
||||||
function add (const a : int; const b : int) : int is a + b
|
function add (const a : int; const b : int) : int is a + b
|
||||||
|
|
||||||
function subtract (const a : int; const b : int) : int is a - b
|
function subtract (const a : int; const b : int) : int is a - b
|
||||||
|
|
||||||
// real entrypoint that re-routes the flow based on the action provided
|
// main function routing the flow based on the action provided
|
||||||
function main (const p : action ; const s : int) : (list(operation) * int) is
|
|
||||||
|
function main (const p : action; const s : int) : return is
|
||||||
((nil : list (operation)),
|
((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)
|
||||||
|
Loading…
Reference in New Issue
Block a user