Skip to content
Browse files

fixup tameRequire docs and usage

  • Loading branch information...
1 parent bb7a588 commit 2e232668c7abb9064c22f55cacf6bf41d97f3f94 @maxtaco committed Dec 11, 2011
Showing with 33 additions and 15 deletions.
  1. +16 −2 TAME.md
  2. +5 −6 lib/coffee-script/nodes.js
  3. +11 −6 src/nodes.coffee
  4. +1 −1 test/tame_advanced.coffee
View
18 TAME.md
@@ -108,7 +108,7 @@ program to continue as soon as the first deferral is fulfilled (rather than
the last):
```coffeescript
-tameRequire(external) # need full library via require() for rendezvous
+tameRequire(node) # need full library via require() for rendezvous
do_all = (lst, windowsz) ->
rv = new tame.Rendezvous
@@ -209,8 +209,22 @@ rand_wait = (autocb) ->
```
Implicitly, `return 0;` is mapped by the CoffeeScript compiler to `autocb(0); return`.
-
+New Keywords
+------------
+
+In sum, the tame additions to CoffeeScript consist of three new keywords:
+
+* **await***, marking off a block or a single statement.
+* **defer**, which is quite similar to a normal function call, but is compiled specially
+to accommodate argument passing.
+* **tameRequire**, which is used to control the "require"ing of the tame runtime. By
+default, the runtime is pasted inline, but with `tameRequire(node)`, it is loaded
+via node's `require`, and with `tameRequire(none)`, it is skipped altogether.
+
+Finally, `autocb` isn't a bonafide keyword, but the compiler searches for it in paramaters
+to CoffeeScript functions, and updates the behavior of the `Code` block accordingly.
+
Translation Technique
---------------------
View
11 lib/coffee-script/nodes.js
@@ -2450,9 +2450,8 @@
function TameRequire(args) {
this.typ = null;
- if (args && args.length > 2) {
- throw SyntaxError("args to tameRequire are either 'inline' or 'ext'");
- }
+ this.usage = "tameRequire takes either 'inline', 'node' or 'none'";
+ if (args && args.length > 2) throw SyntaxError(this.usage);
if (args && args.length === 1) this.typ = args[0];
}
@@ -2462,7 +2461,7 @@
this.body = null;
if (v === "inline") {
this.body = InlineDeferral.generate();
- } else if (v === "ext") {
+ } else if (v === "node") {
file = new Literal("'coffee-script'");
access = new Access(new Literal(tame["const"].ns));
req = new Value(new Literal("require"));
@@ -2471,8 +2470,8 @@
callv.add(access);
ns = new Value(new Literal(tame["const"].ns));
this.body = new Assign(ns, callv);
- } else if (v !== "skip") {
- throw SyntaxError("tameRequire takes either 'inline', 'ext' or 'skip'");
+ } else if (v !== "none") {
+ throw SyntaxError(this.usage);
}
if (this.body) {
return this.body.compile(o);
View
17 src/nodes.coffee
@@ -1995,14 +1995,19 @@ exports.Await = class Await extends Base
#### tameRequire
#
# By default, the tame libraries are inlined. But if you preface your file
-# with 'tameRequire(ext)', you can have it require external libraries
-# of your choosing.
+# with 'tameRequire(node)', it will assume a node runtime, emitting:
+#
+# tame = require('coffee-script').tame
+#
+# With 'tameRequire(none)', you can supply a runtime of
+# your choosing.
#
exports.TameRequire = class TameRequire extends Base
constructor: (args) ->
@typ = null
+ @usage = "tameRequire takes either 'inline', 'node' or 'none'"
if args and args.length > 2
- throw SyntaxError "args to tameRequire are either 'inline' or 'ext'"
+ throw SyntaxError @usage
if args and args.length == 1
@typ = args[0]
@@ -2011,7 +2016,7 @@ exports.TameRequire = class TameRequire extends Base
@body = null
if v == "inline"
@body = InlineDeferral.generate()
- else if v == "ext"
+ else if v == "node"
file = new Literal "'coffee-script'"
access = new Access new Literal tame.const.ns
req = new Value new Literal "require"
@@ -2020,8 +2025,8 @@ exports.TameRequire = class TameRequire extends Base
callv.add access
ns = new Value new Literal tame.const.ns
@body = new Assign ns, callv
- else if v != "skip"
- throw SyntaxError "tameRequire takes either 'inline', 'ext' or 'skip'"
+ else if v != "none"
+ throw SyntaxError @usage
if @body then @body.compile o else ''
children = [ 'typ']
View
2 test/tame_advanced.coffee
@@ -1,5 +1,5 @@
-tameRequire(skip)
+tameRequire(none)
tame = require('../lib/coffee-script/coffee-script').tame;
atest "rendezvous & windowing example", (cb) ->

0 comments on commit 2e23266

Please sign in to comment.
Something went wrong with that request. Please try again.