ANN: Spoon

210 views
Skip to first unread message

Fedor Indutny

unread,
Oct 1, 2012, 3:11:28 PM10/1/12
to nod...@googlegroups.com
Hey people,

Let me introduce you The Spoon: https://github.com/indutny/spoon

It's a JavaScript to CFG (Control-Flow Graph) transpiler and additionally a CPS (Continuation Passing Style) transpiler too.

Basically, it lets you to rewrite code like this:

var data = 'prefix: ' + fs.read('file')

To this:

var data;
fs.read('file', function(err, result) {
  data = 'prefix: ' + result;
});

Please check the readme, if you're interested.

Cheers,
Fedor.

Marcel Laverdet

unread,
Oct 1, 2012, 5:42:56 PM10/1/12
to nod...@googlegroups.com
You have no idea what you've done.

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Mark Hahn

unread,
Oct 1, 2012, 5:55:20 PM10/1/12
to nod...@googlegroups.com
@Marcel just meant that you have started an infinite discussion thread.  He wasn't insulting your module.

Fedor Indutny

unread,
Oct 2, 2012, 2:28:21 AM10/2/12
to nod...@googlegroups.com
"I'm just doing my job".

Ted Young

unread,
Oct 2, 2012, 2:43:00 PM10/2/12
to nod...@googlegroups.com
Just wondering, what were your use cases when writing spoon? Was it to solve production problems you were facing? Are you using it at nodejitsu?

Cheers,
Ted

Fedor Indutny

unread,
Oct 2, 2012, 2:49:28 PM10/2/12
to nod...@googlegroups.com
No, we ain't using this at nodejitsu.

I'm coauthor of xjst module, which is compiling templates to a highly-recursive javascript code. However some javascript VMs like Spidermonkey doesn't support that recursion well, and here comes spoon! It can translate any recursive calls into fake asynchronous ones. And then using tricky dispatch function I can run those calls one-by-one without any recursion at all: https://github.com/veged/xjst/blob/master/lib/xjst/utils.js#L68

Fedor Indutny

unread,
Oct 2, 2012, 2:56:05 PM10/2/12
to nod...@googlegroups.com
I'll write a blog post about it on http://blog.indutny.com/ soon, describing everything in details.

Rick Waldron

unread,
Oct 2, 2012, 3:03:55 PM10/2/12
to nod...@googlegroups.com
Fedor,

Is xjst meant to run in a browser at all? I ask because I see code where objects with a property named "default" are accessing like...

obj["default"]

which isn't necessary in runtimes that correctly implement ES5.1. "default" is a reserved word, but property names are IdentifierNames, not Identifiers, so "default" is valid when used like...

obj.default;

eg.

$ node
> var o = {default: "hi!"}
undefined
> o.default
'hi!'


Anyway, no big deal, I just happened to notice it and figured I'd mention.

Rick

Fedor Indutny

unread,
Oct 2, 2012, 3:07:03 PM10/2/12
to nod...@googlegroups.com
Well, it supposed to work in all browsers, and it supposed to be optimizable by all optimizers including uglifyjs, closure compiler and yui compressor (that's why I'm using "escaped" property names sometimes).

Rick Waldron

unread,
Oct 2, 2012, 3:10:23 PM10/2/12
to nod...@googlegroups.com
On Tue, Oct 2, 2012 at 3:07 PM, Fedor Indutny <fe...@indutny.com> wrote:
Well, it supposed to work in all browsers, and it supposed to be optimizable by all optimizers including uglifyjs, closure compiler and yui compressor (that's why I'm using "escaped" property names sometimes).

Ah, got it, this makes sense :)

Bruno Jouhier

unread,
Oct 3, 2012, 4:14:03 PM10/3/12
to nod...@googlegroups.com, fe...@indutny.com
Hi Fedor,

This looks really promising.

I tried to integrate it as an alternate transformation engine for streamline (a fourth one) and the first results are encouraging: I got the first diskUsage example running.

I had to make a few changes to align spoon on the node.js callback format (error as first callback parameter + testing for err in callback and propagating it through __$callback).

My unit test suite is not running yet because of some unimplemented features: switch, try/finally, labelled statement. But I like the approach. The CGG intermediate representation is cool and can probably produce more efficent code than my pattern based approach.

My changes are here: https://github.com/bjouhier/spoon/commit/83910ee1a4b4036fa1ca38b4f19736b136ace513

Bruno

Bruno Jouhier

unread,
Oct 3, 2012, 4:16:34 PM10/3/12
to nod...@googlegroups.com, fe...@indutny.com
s/CGG/CFG/

Fedor Indutny

unread,
Oct 3, 2012, 4:43:47 PM10/3/12
to Bruno Jouhier, nod...@googlegroups.com
Very nice, Bruno!

Looking forward for getting this back into main repo!
Reply all
Reply to author
Forward
0 new messages