-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
capability, directory, voting improvements, foreach
- Loading branch information
1 parent
1298084
commit 4fce67a
Showing
13 changed files
with
245 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#define $directory "testdir" | ||
#define $ballot "color" | ||
new lockerCh, ret, ret1, loop, $stdout, $lookup in { | ||
lookup!($locker_%%$myusername, *lockerCh) | for(locker <- lockerCh) { | ||
locker!("get", $myprivkey.hexToBytes(), $locker_nonce_%%$myusername, *stdout, *ret) | | ||
for (@items <- ret) { | ||
@{items.get("peek")}!("directory", $directory, *ret) | | ||
@{items.get("peek")}!("ballot", $ballot, *ret1) | | ||
for ( @[{"read": *read, ..._}, ..._] <- ret; | ||
@[{"chair": *chair, ..._}, ..._] <- ret1 ) { | ||
contract loop ( @map ) = { | ||
match map { | ||
{} => Nil | ||
{ username: *inbox, ...tail } => { | ||
chair!("giveRightToVote", *ret) | | ||
for (@vote <- ret) { | ||
inbox!(["vote", $ballot, vote]) | ||
} | | ||
loop!(tail) | ||
} | ||
} | ||
} | | ||
read!(*ret) | | ||
for ( @members <- ret ) { | ||
loop!(members) | ||
} | ||
} | | ||
stdout!(["#define $locker_nonce_" ++ $myusername, {$locker_nonce_%%$myusername + 1}]) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,11 @@ | ||
#define $user "dummyuser" | ||
#define $ballot "flavors" | ||
new inboxCh, lockerCh, itemsCh, voteCh, | ||
lookup(`rho:registry:lookup`), stdout(`rho:io:stdout`) in { | ||
lookup!($locker_%%$myusername, *lockerCh) | | ||
for(locker <- lockerCh) { | ||
locker!("get", $myprivkey.hexToBytes(), $locker_nonce_%%$myusername, *stdout, *itemsCh) | | ||
stdout!(["#define $locker_nonce_" ++ $myusername, {$locker_nonce_%%$myusername + 1}]) | | ||
for (@{$ballot: ballot, ..._} <- itemsCh) { | ||
@{ballot.get("chair")}!("giveRightToVote", *voteCh) | | ||
for (vote <- voteCh) { | ||
lookup!($inbox_%%$user, *inboxCh) | | ||
for(inbox <- inboxCh) { | ||
inbox!(["vote",$ballot,*vote],*stdout) | | ||
stdout!({"sending right to vote to": $user}) | ||
} } } } } | ||
#define $ballot "color" | ||
new ret in { | ||
$peek("ballot",$ballot,*ret) | | ||
for ( @[{"chair": chair, ..._}, ..._] <- ret ) { | ||
@chair!("giveRightToVote", *ret) | | ||
for (@vote <- ret) { | ||
$send($user,"vote", $ballot, vote) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
new ret, x, y, z, xCh, condCh, _if, _while, _until, stdout(`rho:io:stdout`) in { | ||
contract _while(condCh,body) = { | ||
for (cond <- condCh ) { | ||
if (*cond) { | ||
condCh!(*body ) | | ||
_while!(*condCh,*body) | ||
} | ||
} | ||
} | | ||
|
||
contract _if(condCh,_then,_else) = { | ||
for (cond <- condCh) { | ||
stdout!(*cond) | | ||
stdout!(*@{*cond}) | | ||
*cond | | ||
if ( *cond ) *_then | ||
else *_else | ||
} | ||
} | | ||
contract _if(cond,_then,_else, ret) = { | ||
stdout!(*cond) | | ||
if ( *cond ) ret!(*_then) | ||
else ret!(*_else) | ||
} | | ||
|
||
condCh!(for (x <- xCh) {*x == 0}) | | ||
//condCh!(3==3) | | ||
_if!(*condCh, {xCh!(0)|stdout!("truly")}, xCh!(3+2)) | | ||
for ( val <- xCh ) { | ||
stdout!({"x1": *val}) | ||
} | | ||
/* | ||
_if!(3==5, 1+1, 2+2, *stdout) | | ||
_if!(3==3, x!(10+1), x!(02+2), *y) | | ||
for (rho <- y) { | ||
stdout!(*rho) | | ||
*rho | | ||
for ( val <- x ) { | ||
stdout!({"x2": *val}) | ||
} | ||
} | ||
*/ Nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#define $collection {"a": "b", "c": "d", "e": "f", "g": "h"} | ||
#define $code stdout!({_key: _value}) | ||
new $stdout, _loop in { | ||
contract _loop ( @_map ) = { | ||
match _map { | ||
{} => Nil | ||
{ _key: _value, ..._tail } => { | ||
$code | | ||
_loop!(_tail) | ||
} | ||
[] => Nil | ||
[_value, ..._tail] /\ _key => { | ||
$code | | ||
_loop!(_tail) | ||
} | ||
Set() => Nil | ||
Set(_value, ..._tail) /\ _key => { | ||
$code | | ||
_loop!(_tail) | ||
} | ||
/* _ /\ _name => {for ( @collection <- @_name ) { _loop!(collection) } } */ | ||
} | ||
} | _loop!( $collection ) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#define $collection {"a": "b", "c": "d", "e": "f", "g": "h"} | ||
#define $code stdout!({_key: _value}) | ||
new $stdout, _loop in { | ||
contract _loop ( @_map ) = { | ||
match _map { | ||
{} => Nil | ||
{ _key: _value, ..._tail } => { | ||
$code | | ||
_loop!(_tail) | ||
} | ||
[] => Nil | ||
[_value, ..._tail] /\ _key => { | ||
$code | | ||
_loop!(_tail) | ||
} | ||
Set() => Nil | ||
Set(_value, ..._tail) /\ _key => { | ||
$code | | ||
_loop!(_tail) | ||
} | ||
} | ||
} | _loop!( $collection ) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,11 @@ | ||
#define $name color | ||
#define $name "color" | ||
#define $choiceSet Set("red","green","blue") | ||
new lookupCh, bCh, Ballot, lookup(`rho:registry:lookup`), stdout(`rho:io:stdout`), lockerCh, ackCh | ||
in { | ||
new lookupCh, bCh, $lookup, $stdout in { | ||
lookup!($Ballot, *lookupCh) | | ||
for(Ballot <- lookupCh) { | ||
Ballot!($choiceSet, *bCh) | | ||
for (chair, getWinner <- bCh) { | ||
lookup!($locker_%%$myusername, *lockerCh) | | ||
for(locker <- lockerCh) { | ||
locker!("update", $myprivkey.hexToBytes(), $locker_nonce_%%$myusername, {$name: {"chair": *chair, "getWinner": *getWinner}}, *stdout, *ackCh) | | ||
stdout!(["#define $locker_nonce_" ++ $myusername, {$locker_nonce_%%$myusername + 1}]) | ||
} | ||
$send($myusername, "ballot", $name, {"chair": *chair, "getWinner": *getWinner}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#define $ballot "color" | ||
new ret, $stdout in { | ||
$peek("ballot",$ballot,*ret) | | ||
for ( @[{"getWinner": results, ..._}, ..._] <- ret ) { | ||
@results!(*stdout) | ||
} | ||
} |