Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions samples/bank.as
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ actor class Issuer() {
};
};

actor class Account(initialBalance : Int) {
actor class Account(initialBalance : Int) = this {
private var balance : Int = initialBalance;

getBalance() : async Int {
Expand All @@ -25,15 +25,15 @@ actor class Account(initialBalance : Int) {
return Account(amount);
};

join(account : Account) { // this implicitly asserts that account is Account
join(account : like Account) {
assert(account is Account);
let amount = balance;
balance := 0;
account.credit(amount);
account.credit(amount, Account);
};

private credit(amount : Int) {
// private implicitly asserts that caller is own class
// by implicitly passing the modref as an extra argument
credit(amount : Int, caller : Class) {
assert(this is caller);
balance += amount;
};

Expand Down
60 changes: 31 additions & 29 deletions samples/bank.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Checking bank.as:
type Account <: actor {getBalance : shared () -> async Int; isCompatible : shared (like Account) -> async Bool; join : shared Account -> (); split : shared Int -> async Account}
type Account <: actor {credit : shared (Int, Class) -> (); getBalance : shared () -> async Int; isCompatible : shared (like Account) -> async Bool; join : shared (like Account) -> (); split : shared Int -> async Account}
type Bank <: actor {getIssuer : shared () -> async Issuer; getReserve : shared () -> async Account}
type Issuer <: actor {hasIssued : shared (like Account) -> async Bool}
let Account : class Int -> Account
Expand All @@ -15,8 +15,8 @@ Bank(100)
Issuer()
<= {hasIssued = func}
Account(100)
<= {balance = 100; credit = func; getBalance = func; isCompatible = func; join = func; split = func}
<= {getIssuer = func; getReserve = func; issuer = {hasIssued = func}; reserve = {balance = 100; credit = func; getBalance = func; isCompatible = func; join = func; split = func}}
<= {credit = func; getBalance = func; isCompatible = func; join = func; split = func}
<= {getIssuer = func; getReserve = func}
test()
-> async bank.as:56.40-68.2
<= async _
Expand All @@ -28,8 +28,8 @@ test()
-> async bank.as:7.32-7.51
<= async _
<- async bank.as:7.32-7.51
<= {balance = 100; credit = func; getBalance = func; isCompatible = func; join = func; split = func}
<- await bank.as:57.17-57.40({balance = 100; credit = func; getBalance = func; isCompatible = func; join = func; split = func})
<= {credit = func; getBalance = func; isCompatible = func; join = func; split = func}
<- await bank.as:57.17-57.40({credit = func; getBalance = func; isCompatible = func; join = func; split = func})
-> message split(10)
=> await bank.as:58.12-58.35
<- message split(10)
Expand All @@ -38,9 +38,9 @@ test()
<= async _
<- async bank.as:23.39-26.4
Account(10)
<= {balance = 10; credit = func; getBalance = func; isCompatible = func; join = func; split = func}
<= {balance = 10; credit = func; getBalance = func; isCompatible = func; join = func; split = func}
<- await bank.as:58.12-58.35({balance = 10; credit = func; getBalance = func; isCompatible = func; join = func; split = func})
<= {credit = func; getBalance = func; isCompatible = func; join = func; split = func}
<= {credit = func; getBalance = func; isCompatible = func; join = func; split = func}
<- await bank.as:58.12-58.35({credit = func; getBalance = func; isCompatible = func; join = func; split = func})
-> message split(10)
=> await bank.as:59.12-59.35
<- message split(10)
Expand All @@ -49,16 +49,16 @@ test()
<= async _
<- async bank.as:23.39-26.4
Account(10)
<= {balance = 10; credit = func; getBalance = func; isCompatible = func; join = func; split = func}
<= {balance = 10; credit = func; getBalance = func; isCompatible = func; join = func; split = func}
<- await bank.as:59.12-59.35({balance = 10; credit = func; getBalance = func; isCompatible = func; join = func; split = func})
show("reserve", {balance = 80; credit = func; getBalance = func; isCompatible = func; join = func; split = func})
<= {credit = func; getBalance = func; isCompatible = func; join = func; split = func}
<= {credit = func; getBalance = func; isCompatible = func; join = func; split = func}
<- await bank.as:59.12-59.35({credit = func; getBalance = func; isCompatible = func; join = func; split = func})
show("reserve", {credit = func; getBalance = func; isCompatible = func; join = func; split = func})
<= ()
show("a1", {balance = 10; credit = func; getBalance = func; isCompatible = func; join = func; split = func})
show("a1", {credit = func; getBalance = func; isCompatible = func; join = func; split = func})
<= ()
show("a2", {balance = 10; credit = func; getBalance = func; isCompatible = func; join = func; split = func})
show("a2", {credit = func; getBalance = func; isCompatible = func; join = func; split = func})
<= ()
transfer({balance = 10; credit = func; getBalance = func; isCompatible = func; join = func; split = func}, {balance = 10; credit = func; getBalance = func; isCompatible = func; join = func; split = func}, 5)
transfer({credit = func; getBalance = func; isCompatible = func; join = func; split = func}, {credit = func; getBalance = func; isCompatible = func; join = func; split = func}, 5)
-> async bank.as:46.79-49.2
<= async _
=> await bank.as:63.3-63.28
Expand All @@ -71,30 +71,32 @@ test()
<= async _
<- async bank.as:23.39-26.4
Account(5)
<= {balance = 5; credit = func; getBalance = func; isCompatible = func; join = func; split = func}
<= {balance = 5; credit = func; getBalance = func; isCompatible = func; join = func; split = func}
<- await bank.as:47.13-47.39({balance = 5; credit = func; getBalance = func; isCompatible = func; join = func; split = func})
-> message join({balance = 10; credit = func; getBalance = func; isCompatible = func; join = func; split = func})
<= {credit = func; getBalance = func; isCompatible = func; join = func; split = func}
<= {credit = func; getBalance = func; isCompatible = func; join = func; split = func}
<- await bank.as:47.13-47.39({credit = func; getBalance = func; isCompatible = func; join = func; split = func})
-> message join({credit = func; getBalance = func; isCompatible = func; join = func; split = func})
<= ()
<- message join({balance = 10; credit = func; getBalance = func; isCompatible = func; join = func; split = func})
join({balance = 10; credit = func; getBalance = func; isCompatible = func; join = func; split = func})
credit(5)
<= ()
<- message join({credit = func; getBalance = func; isCompatible = func; join = func; split = func})
join({credit = func; getBalance = func; isCompatible = func; join = func; split = func})
-> message credit(5, class)
<= ()
<- message credit(5, class)
credit(5, class)
<= ()
<- await bank.as:63.3-63.28()
show("reserve", {balance = 80; credit = func; getBalance = func; isCompatible = func; join = func; split = func})
show("reserve", {credit = func; getBalance = func; isCompatible = func; join = func; split = func})
<= ()
show("a1", {balance = 5; credit = func; getBalance = func; isCompatible = func; join = func; split = func})
show("a1", {credit = func; getBalance = func; isCompatible = func; join = func; split = func})
<= ()
show("a2", {balance = 15; credit = func; getBalance = func; isCompatible = func; join = func; split = func})
show("a2", {credit = func; getBalance = func; isCompatible = func; join = func; split = func})
<= ()
<= ({balance = 5; credit = func; getBalance = func; isCompatible = func; join = func; split = func}, {balance = 15; credit = func; getBalance = func; isCompatible = func; join = func; split = func})
<= ({credit = func; getBalance = func; isCompatible = func; join = func; split = func}, {credit = func; getBalance = func; isCompatible = func; join = func; split = func})
-- Finished bank.as:
let Account : class Int -> Account = class
let Bank : class Int -> Bank = class
let Issuer : class () -> Issuer = class
let bank : Bank = {getIssuer = func; getReserve = func; issuer = {hasIssued = func}; reserve = {balance = 80; credit = func; getBalance = func; isCompatible = func; join = func; split = func}}
let main : async (Account, Account) = async ({balance = 5; credit = func; getBalance = func; isCompatible = func; join = func; split = func}, {balance = 15; credit = func; getBalance = func; isCompatible = func; join = func; split = func})
let bank : Bank = {getIssuer = func; getReserve = func}
let main : async (Account, Account) = async ({credit = func; getBalance = func; isCompatible = func; join = func; split = func}, {credit = func; getBalance = func; isCompatible = func; join = func; split = func})
let show : (Text, Account) -> () = func
let test : () -> async (Account, Account) = func
let transfer : (Account, Account, Int) -> async () = func
Expand Down
56 changes: 28 additions & 28 deletions samples/cheque.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Bank(100)
Issuer()
<= {hasIssued = func}
Account(100)
<= {balance = 100; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}
<= {getIssuer = func; getReserve = func; issuer = {hasIssued = func}; reserve = {balance = 100; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}}
<= {credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}
<= {getIssuer = func; getReserve = func}
test()
-> async cheque.as:76.39-88.2
<= async _
Expand All @@ -31,8 +31,8 @@ test()
-> async cheque.as:7.32-7.51
<= async _
<- async cheque.as:7.32-7.51
<= {balance = 100; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}
<- await cheque.as:77.17-77.40({balance = 100; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
<= {credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}
<- await cheque.as:77.17-77.40({credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
-> message split(10)
=> await cheque.as:78.12-78.35
<- message split(10)
Expand All @@ -41,9 +41,9 @@ test()
<= async _
<- async cheque.as:32.39-35.4
Account(10)
<= {balance = 10; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}
<= {balance = 10; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}
<- await cheque.as:78.12-78.35({balance = 10; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
<= {credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}
<= {credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}
<- await cheque.as:78.12-78.35({credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
-> message split(10)
=> await cheque.as:79.12-79.35
<- message split(10)
Expand All @@ -52,35 +52,35 @@ test()
<= async _
<- async cheque.as:32.39-35.4
Account(10)
<= {balance = 10; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}
<= {balance = 10; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}
<- await cheque.as:79.12-79.35({balance = 10; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
show("reserve", {balance = 80; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
<= {credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}
<= {credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}
<- await cheque.as:79.12-79.35({credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
show("reserve", {credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
<= ()
show("a1", {balance = 10; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
show("a1", {credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
<= ()
show("a2", {balance = 10; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
show("a2", {credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
<= ()
transfer({balance = 10; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}, {balance = 10; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}, 5)
transfer({credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}, {credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}, 5)
-> async cheque.as:64.79-67.2
<= async _
=> await cheque.as:83.3-83.28
<- async cheque.as:64.79-67.2
-> message invoice(5, {balance = 10; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
-> message invoice(5, {credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
=> await cheque.as:65.16-65.53
<- message invoice(5, {balance = 10; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
invoice(5, {balance = 10; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
<- message invoice(5, {credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
invoice(5, {credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
-> async cheque.as:41.59-44.4
<= async _
<- async cheque.as:41.59-44.4
Cheque(5, {balance = 10; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
<= {current = 5; deposit = func}
<= {current = 5; deposit = func}
<- await cheque.as:65.16-65.53({current = 5; deposit = func})
-> message deposit({current = 5; deposit = func})
Cheque(5, {credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
<= {deposit = func}
<= {deposit = func}
<- await cheque.as:65.16-65.53({deposit = func})
-> message deposit({deposit = func})
<= ()
<- message deposit({current = 5; deposit = func})
deposit({current = 5; deposit = func})
<- message deposit({deposit = func})
deposit({deposit = func})
-> message deposit()
<= ()
<- message deposit()
Expand All @@ -91,7 +91,7 @@ test()
credit(5)
<= ()
<- await cheque.as:83.3-83.28()
show("reserve", {balance = 80; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
show("reserve", {credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
<= ()
-> message getBalance()
=> await cheque.as:85.21-85.42
Expand All @@ -115,14 +115,14 @@ test()
<- await cheque.as:86.21-86.42(15)
showBalance("b2", 15)
<= ()
<= ({balance = 5; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}, {balance = 15; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
<= ({credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}, {credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
-- Finished cheque.as:
let Account : class Int -> Account = class
let Bank : class Int -> Bank = class
let Cheque : class (Int, Account) -> Cheque = class
let Issuer : class () -> Issuer = class
let bank : Bank = {getIssuer = func; getReserve = func; issuer = {hasIssued = func}; reserve = {balance = 80; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}}
let main : async (Account, Account) = async ({balance = 5; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}, {balance = 15; credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
let bank : Bank = {getIssuer = func; getReserve = func}
let main : async (Account, Account) = async ({credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func}, {credit = func; deposit = func; getBalance = func; invoice = func; isCompatible = func; join = func; split = func})
let show : (Text, Account) -> () = func
let showBalance : (Text, Int) -> () = func
let test : () -> async (Account, Account) = func
Expand Down
4 changes: 2 additions & 2 deletions samples/counter.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let testDec : () -> ()
let testRead : () -> ()
-- Interpreting counter.as:
Counter(10)
<= {c = 10; dec = func; read = func}
<= {dec = func; read = func}
testDec()
-> message dec()
-> message dec()
Expand Down Expand Up @@ -288,7 +288,7 @@ testRead()
<= ()
-- Finished counter.as:
let Counter : class Int -> Counter = class
let c : Counter = {c = -10; dec = func; read = func}
let c : Counter = {dec = func; read = func}
let show : (Text, Int) -> () = func
let showAsync : (Text, async Int) -> () = func
let testDec : () -> () = func
Expand Down
4 changes: 2 additions & 2 deletions samples/quicksort.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let cmpi : (Int, Int) -> Int
let qs : QS<Int>
-- Interpreting quicksort.as:
QS(func)
<= {partition = func; quicksort = func; swap = func; trace = func}
<= {quicksort = func}
quicksort([8, 3, 9, 5, 2], 0, 4)
partition([8, 3, 9, 5, 2], 0, 4)
trace([8, 3, 9, 5, 2])
Expand Down Expand Up @@ -100,5 +100,5 @@ quicksort([8, 3, 9, 5, 2], 0, 4)
let QS : class <T>((T, T) -> Int) -> QS<T> = class
let a : Array<Int> = [2, 3, 5, 8, 9]
let cmpi : (Int, Int) -> Int = func
let qs : QS<Int> = {partition = func; quicksort = func; swap = func; trace = func}
let qs : QS<Int> = {quicksort = func}

4 changes: 2 additions & 2 deletions src/arrange.ml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ and dec d = match d.it with
"FuncD" $$ [Atom (sharing s.it); id i] @ List.map typ_bind tp @ [pat p; typ t; exp e]
| TypD (i, tp, t) ->
"TypD" $$ [id i] @ List.map typ_bind tp @ [typ t]
| ClassD (i, j, tp, s, p, efs) ->
"ClassD" $$ id i :: id j :: List.map typ_bind tp @ [obj_sort s; pat p] @ List.map exp_field efs
| ClassD (i, j, tp, s, p, i', efs) ->
"ClassD" $$ id i :: id j :: List.map typ_bind tp @ [obj_sort s; pat p; id i'] @ List.map exp_field efs

and prog prog = "BlockE" $$ List.map dec prog.it
4 changes: 2 additions & 2 deletions src/async.ml
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,9 @@ and t_dec' dec' =
| _ -> failwith "async.ml t_dec': funcD3"
end
end
| ClassD (id, lab, typbinds, sort, pat, fields) ->
| ClassD (id, lab, typbinds, sort, pat, id', fields) ->
let fields' = t_fields fields in
ClassD (id, lab, t_typbinds typbinds, sort, t_pat pat, fields')
ClassD (id, lab, t_typbinds typbinds, sort, t_pat pat, id', fields')

and t_decs decs = List.map t_dec decs

Expand Down
Loading