Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

@michaelficarra suggested all of these bug and style fixes

  • Loading branch information...
commit 58ea9e78a4f5ec08570ce34dcdb2a406810d36dd 1 parent c15f18c
@maxtaco authored
View
32 TAME.md
@@ -67,7 +67,7 @@ do_all = (lst) ->
for h in lst
do_one defer(), h
-do_all process.argv.slice(2)
+do_all process.argv[2...]
```
You can run this on the command line like so:
@@ -114,11 +114,11 @@ do_all = (lst, windowsz) ->
nrecv = 0
while nrecv < lst.length
- if nsent - nrecv < windowsz && nsent < n
- do_one(rv.id(nsent).defer(), lst[nsent])
+ if nsent - nrecv < windowsz and nsent < n
+ do_one rv.id(nsent).defer(), lst[nsent]
nsent++
else
- await rv.wait defer(evid)
+ await rv.wait defer evid
console.log "got back lookup nsent=#{evid}"
nrecv++
```
@@ -152,8 +152,8 @@ f = (n,cb) ->
await
for i in [0..n]
((cb) ->
- await setTimeout defer(), 5*Math.random()
- await setTimeout defer(), 4*Math.random()
+ await setTimeout defer(), 5 * Math.random()
+ await setTimeout defer(), 4 * Math.random()
cb()
)(defer())
cb()
@@ -171,8 +171,8 @@ f = (n,autocb) ->
await
for i in [0..n]
((autocb) ->
- setTimeout defer(), 5*Math.random ()
- setTimeout defer(), 4*Math.random ()
+ setTimeout defer(), 5 * Math.random()
+ setTimeout defer(), 4 * Math.random()
)(defer())
```
In the first example, recall, you call `cb()` explicitly. In this
@@ -186,8 +186,8 @@ then fulfills its callback `cb` with the amount of time it waited:
```coffeescript
rand_wait = (cb) ->
- time = Math.floor (Math.random()*5);
- if time == 0
+ time = Math.floor Math.random() * 5
+ if time is 0
cb(0)
return
await setTimeout defer(), time
@@ -198,8 +198,8 @@ This function can written equivalently with `autocb` as:
```coffeescript
rand_wait = (autocb) ->
- time = Math.floor (Math.random()*5);
- return 0 if time == 0
+ time = Math.floor Math.random() * 5
+ return 0 if time is 0
await setTimeout defer(), time
return time
```
@@ -234,7 +234,7 @@ example that shows off the four different cases required to make this
happen:
```coffeescript
-cb = defer x, obj.field, arr[i], rest..
+cb = defer x, obj.field, arr[i], rest...
```
And here is the output from the tamed `coffee` compiler:
@@ -314,8 +314,8 @@ a standard CoffeeScript-style abstract syntax tree (AST).
* **2.1** Find all `await` nodes in the AST. Mark these nodes and their
ancestors with an **A** flag.
- * **2.2** Find all `for`, `while`, or `loop` nodes marked with **A**.
- Mark them and their descendants with an **L** flag.
+ * **2.2** Find all `for`, `while`, `until`, or `loop` nodes marked with
+ **A**. Mark them and their descendants with an **L** flag.
* **2.3** Find all `continue` or `break` nodes marked with an **L** flag.
Mark them and their descendants with a **P** flag.
@@ -324,7 +324,7 @@ a standard CoffeeScript-style abstract syntax tree (AST).
* **3.1** For each `Block` node _b_ in the `AST` marked **A** or **P**:
- * **3.1.1** Find _b_'s first child _c_ marked with with **A** or **P**.
+ * **3.1.1** Find _b_'s first child _c_ marked with **A** or **P**.
* **3.1.2** Cut _b_'s list of expressions after _c_, and move those
expressions on the right of the cut into a new block, called
View
6 src/nodes.coffee
@@ -1419,7 +1419,7 @@ exports.Code = class Code extends Base
tameMarkAutocbs: (found) ->
found = false
for p in @params
- if p.name instanceof Literal and p.name.value == tame.const.autocb
+ if p.name instanceof Literal and p.name.value is tame.const.autocb
found = true
break
super(found)
@@ -1966,7 +1966,7 @@ exports.Defer = class Defer extends Base
# leftover arguments.
#
makeAssignFn : (o) ->
- return null if @slots.length == 0
+ return null if @slots.length is 0
assignments = []
args = []
i = 0
@@ -2088,7 +2088,7 @@ exports.TameRequire = class TameRequire extends Base
@usage = "tameRequire takes either 'inline', 'node' or 'none'"
if args and args.length > 2
throw SyntaxError @usage
- if args and args.length == 1
+ if args and args.length is 1
@typ = args[0]
compileNode: (o) ->
View
96 test/tame.coffee
@@ -1,13 +1,13 @@
delay = (cb, i) ->
- i = i || 10
+ i = i || 3
setTimeout cb, i
atest "basic tame waiting", (cb) ->
i = 1
await delay defer()
i++
- cb(i == 2, {})
+ cb(i is 2, {})
foo = (i, cb) ->
await delay(defer(), i)
@@ -17,12 +17,12 @@ atest "basic tame waiting", (cb) ->
i = 1
await delay defer()
i++
- cb(i == 2, {})
+ cb(i is 2, {})
atest "basic tame trigger values", (cb) ->
i = 10
await foo(i, defer j)
- cb(i == j, {})
+ cb(i is j, {})
atest "basic tame set structs", (cb) ->
field = "yo"
@@ -31,7 +31,7 @@ atest "basic tame set structs", (cb) ->
await
foo(i, defer obj.cat[field])
field = "bar" # change the field to make sure that we captured "yo"
- cb(obj.cat.yo == i, {})
+ cb(obj.cat.yo is i, {})
multi = (cb, arr) ->
await delay defer()
@@ -51,10 +51,10 @@ atest "continue / break test" , (cb) ->
tot = 0
for i in [0..100]
await delay defer()
- continue if i == 3
+ continue if i is 3
tot += i
- break if i == 10
- cb(tot == 52, {})
+ break if i is 10
+ cb(tot is 52, {})
atest "for k,v of obj testing", (cb) ->
obj = { the : "quick", brown : "fox", jumped : "over" }
@@ -62,7 +62,7 @@ atest "for k,v of obj testing", (cb) ->
for k,v of obj
await delay defer()
s += k + " " + v + " "
- cb( s == "the quick brown fox jumped over ", {} )
+ cb( s is "the quick brown fox jumped over ", {} )
atest "for k,v in arr testing", (cb) ->
obj = [ "the", "quick", "brown" ]
@@ -70,7 +70,7 @@ atest "for k,v in arr testing", (cb) ->
for v,i in obj
await delay defer()
s += v + " " + i + " "
- cb( s == "the 0 quick 1 brown 2 ", {} )
+ cb( s is "the 0 quick 1 brown 2 ", {} )
atest "switch-a-roos", (cb) ->
res = 0
@@ -90,8 +90,8 @@ atest "switch-a-roos", (cb) ->
res += 300
else
res += i*1000
- res += 10000 if i == 2
- cb( res == 17321, {} )
+ res += 10000 if i is 2
+ cb( res is 17321, {} )
atest "parallel awaits with classes", (cb) ->
@@ -112,7 +112,7 @@ atest "parallel awaits with classes", (cb) ->
obj.increment 20, 2, defer()
obj.increment 30, 4, defer()
v = obj.getVal()
- cb(v == 14, {})
+ cb(v is 14, {})
atest "loop construct", (cb) ->
i = 0
@@ -120,9 +120,9 @@ atest "loop construct", (cb) ->
await delay defer()
i += 1
await delay defer()
- break if i == 10
+ break if i is 10
await delay defer()
- cb(i == 10, {})
+ cb(i is 10, {})
atest "simple autocb operations", (cb) ->
b = false
@@ -145,48 +145,48 @@ atest "AT variable works in an await (1)", (cb) ->
o = new MyClass
await o.run defer()
cb(o.getFlag(), {})
-
+
atest "more advanced autocb test", (cb) ->
bar = -> "yoyo"
foo = (val, autocb) ->
await delay defer()
- if val == 0 then [1,2,3]
- else if val == 1 then { a : 10 }
- else if val == 2 then bar()
+ if val is 0 then [1,2,3]
+ else if val is 1 then { a : 10 }
+ else if val is 2 then bar()
else 33
oks = 0
await foo 0, defer x
- oks++ if x[2] == 3
+ oks++ if x[2] is 3
await foo 1, defer x
- oks++ if x.a == 10
+ oks++ if x.a is 10
await foo 2, defer x
- oks++ if x == "yoyo"
+ oks++ if x is "yoyo"
await foo 100, defer x
- oks++ if x == 33
- cb(oks == 4, {})
+ oks++ if x is 33
+ cb(oks is 4, {})
atest "test of autocb in a simple function", (cb) ->
simple = (autocb) ->
await delay defer()
- ok = false
+ ok = false
await simple defer()
ok = true
cb(ok,{})
-
+
atest "test nested serial/parallel", (cb) ->
slots = []
await
for i in [0..10]
( (j, autocb) ->
- await delay defer(), 5*Math.random()
- await delay defer(), 4*Math.random()
+ await delay defer(), 5 * Math.random()
+ await delay defer(), 4 * Math.random()
slots[j] = true
)(i, defer())
ok = true
for i in [0..10]
ok = false unless slots[i]
cb(ok, {})
-
+
atest "loops respect autocbs", (cb) ->
ok = false
bar = (autocb) ->
@@ -226,7 +226,7 @@ atest "test scoping", (cb) ->
getVal : -> @val
o = new MyClass
await o.run defer(v)
- cb(v == 5, {})
+ cb(v is 5, {})
atest "AT variable works in an await (2)", (cb) ->
class MyClass
@@ -241,7 +241,7 @@ atest "AT variable works in an await (2)", (cb) ->
getVal : -> @val
o = new MyClass
await o.run defer()
- cb(o.getVal() == 10, {})
+ cb(o.getVal() is 10, {})
atest "another autocb gotcha", (cb) ->
bar = (autocb) ->
@@ -250,7 +250,7 @@ atest "another autocb gotcha", (cb) ->
await bar defer()
ok = true
cb(ok, {})
-
+
atest "fat arrow versus tame", (cb) ->
class Foo
constructor : ->
@@ -264,7 +264,7 @@ atest "fat arrow versus tame", (cb) ->
delay : (autocb) ->
await delay defer()
-
+
addHandlers : ->
@addHandler "sleep1", (cb) =>
await delay defer()
@@ -289,7 +289,7 @@ atest "fat arrow versus tame", (cb) ->
for j in [0..10]
await delay(defer(),1)
val++
- cb(val == 100, {})
+ cb(val is 100, {})
atest "empty autocb", (cb) ->
bar = (autocb) ->
@@ -300,15 +300,15 @@ atest "more autocb (false)", (cb) ->
bar = (autocb) ->
if false
console.log "not reached"
- await bar defer()
- cb(true, {})
+ await bar defer()
+ cb(true, {})
atest "more autocb (true)", (cb) ->
bar = (autocb) ->
if true
10
- await bar defer()
- cb(true, {})
+ await bar defer()
+ cb(true, {})
atest "more autocb (true & false)", (cb) ->
bar = (autocb) ->
@@ -317,20 +317,28 @@ atest "more autocb (true & false)", (cb) ->
else
if false
11
- await bar defer()
- cb(true, {})
+ await bar defer()
+ cb(true, {})
atest "more autocb (while)", (cb) ->
bar = (autocb) ->
while false
10
- await bar defer()
- cb(true, {})
+ await bar defer()
+ cb(true, {})
atest "more autocb (comments)", (cb) ->
bar = (autocb) ->
###
blah blah blah
###
- await bar defer()
- cb(true, {})
+ await bar defer()
+ cb(true, {})
+
+atest "until", (cb) ->
+ i = 10
+ out = 0
+ until i is 0
+ await delay defer()
+ out += i--
+ cb(out is 55, {})
View
4 test/tame_advanced.coffee
@@ -17,7 +17,7 @@ atest "rendezvous & windowing example", (cb) ->
nsent = 0
nrecv = 0
while nrecv < n
- if nsent - nrecv < window && nsent < n
+ if nsent - nrecv < window and nsent < n
call nsent, rv.id(nsent).defer()
nsent++
else
@@ -54,7 +54,7 @@ atest "pipeliner example", (cb) ->
cb()
await window 100, 10, defer()
-
+
ok = true
for s in slots
ok = false unless s == 7
Please sign in to comment.
Something went wrong with that request. Please try again.