musictheory / NilScript

Objective-C-style language superset of JavaScript with a tiny, simple runtime
Other
50 stars 5 forks source link

Incremental Builds / Compiler API #73

Closed iccir closed 8 years ago

iccir commented 8 years ago

oj should provide a Compiler API in addition to compile. In addition to the constructor, this would have two methods:

Compiler#parent(parentCompiler)
Compiler#compile(options, callback)

The parent method replaces the need for the input-state and output-state options. Rather than serializing/deserializing, input state is read directly from the parent compiler.

The first call to compile is effectively the same as the compile() API. Subsequent calls to compile should reuse pieces from previous compiles, including the typechecker, to allow for faster incremental builds.

From my prototype in the 2.0 branch, running the type checker goes from ~5.2 seconds per save to ~1.5 seconds per save (assuming there isn't a global change, like a class rename). Non-typechecker passes are about the same speed.

IngwiePhoenix commented 8 years ago

So currently, OJ runs one-off:

ojc.compile(options, cb(err, res))

But with this, we'd construct a compiler?

// Something like...
var cc = new ojc.compiler(options);
cc.compile(cb(err, res))

Or how is this to be understood?

iccir commented 8 years ago

Yep, that's exactly it. You would keep cc around, and then call cc.compile on it again in response to a file change.

IngwiePhoenix commented 8 years ago

Oh! Now that’s pretty cool. :) Looking forward to seeing that in action.

iccir commented 8 years ago

On branch and documented. Note that Compiler#parent is now Compiler#uses.