Merge pull request #17 from aeternity/PT-163478903-builtin-bits-type

PT-163478903 builtin bits type
This commit is contained in:
Ulf Norell
2019-01-28 10:05:09 +01:00
committed by GitHub
11 changed files with 73 additions and 45 deletions
-2
View File
@@ -36,8 +36,6 @@ contract AllSyntax =
(x, [y, z]) => bar({x = z, y = -y + - -z * (-1)})
(x, y :: _) => ()
function bitOperations(x, y) = bnot (0xff00 band x bsl 4 bxor 0xa5a5a5 bsr 4 bor y)
function mutual() =
let rec recFun(x : int) = mutFun(x)
and mutFun(x) = if(x =< 0) 1 else x * recFun(x - 1)
+13 -15
View File
@@ -5,7 +5,7 @@
contract MultiSig =
record pending_state = { yetNeeded : uint, ownersDone : uint, index : uint }
record pending_state = { yetNeeded : int, ownersDone : bits, index : int }
datatype event =
Confirmation (address, hash) // of { .owner : Address, .operation : Hash }
@@ -13,18 +13,18 @@ contract MultiSig =
| OwnerChanged (address, address) // of { .oldOwner : Address, .newOwner : Address }
| OwnerAdded (address) // of { .newOwner : Address }
| OwnerRemoved (address) // of { .removedOwner : Address }
| ReqChanged (uint) // of { .newReq : uint }
| ReqChanged (int) // of { .newReq : int }
let maxOwners : uint = 250
let maxOwners : int = 250
record state = { nRequired : uint
, nOwners : uint
, owners : map(uint, address)
, ownerIndex : map(address, uint)
record state = { nRequired : int
, nOwners : int
, owners : map(int, address)
, ownerIndex : map(address, int)
, pending : map(hash, pending_state)
, pendingIndex : list(address) }
function init (owners : list(address), nRequired : uint) : state =
function init (owners : list(address), nRequired : int) : state =
let n = length(owners) + 1
{ nRequired = nRequired,
nOwners = n,
@@ -39,10 +39,9 @@ contract MultiSig =
function revoke(operation : hash) =
let ownerIx = lookup(state.ownerIndex, caller())
let pending = lookup(state.pendingIndex, operation)
let ownerIxBit = 1 bsl (ownerIx - 1)
let _ = require(pending.ownersDone band ownerIxBit > 0)
let _ = require(Bits.test(pending.ownersDone, ownerIx))
let pending' = pending { yetNeeded = pending.yetNeeded + 1
, ownersDone = pending.ownersDone - ownerIxBit }
, ownersDone = Bits.clear(pending.ownersDone, ownerIx - 1) }
put(state{ pendingIndex.operator = pending' })
event(Revoke(caller, operation))
@@ -91,7 +90,7 @@ contract MultiSig =
, pendingIx = [] },
event = [OwnerRemoved(oldOwner)] }
function changeRequirement(newReq : uint) =
function changeRequirement(newReq : int) =
let _ = require(newReq =< state.nOwners)
switch(check_pending(callhash()))
CheckFail(state') => { state = state' }
@@ -102,7 +101,7 @@ contract MultiSig =
event = [ReqChanged(newReq)] }
function getOwner(ownerIx0 : uint) =
function getOwner(ownerIx0 : int) =
lookup(state.owners, ownerIx0 + 1)
function isOwner(owner : address) =
@@ -116,8 +115,7 @@ contract MultiSig =
Some(pending) =>
let _ = require(isOwner(owner))
let ownerIx = lookup(state.ownerIndex, owner)
let ownerIxBit = 1 bsl (ownerIx - 1)
(pending.ownersDone band ownerIxBit) != 0
Bits.test(pending.ownersDone, ownerIx - 1)
/* Leave the rest for now... */
-7
View File
@@ -1,5 +1,4 @@
// - + * / mod arithmetic operators
// bnot band bor bxor bsl bsr bitwise operators
// ! && || logical operators
// == != < > =< >= comparison operators
// :: ++ list operators
@@ -13,12 +12,6 @@ contract Operators =
"/" => a / b
"mod" => a mod b
"^" => a ^ b
"bnot" => bnot a
"band" => a band b
"bor" => a bor b
"bxor" => a bxor b
"bsl" => a bsl b
"bsr" => a bsr b
function bool_op(a : bool, b : bool, op : string) =
switch(op)