-
Notifications
You must be signed in to change notification settings - Fork 8
Implicit CPS
I've been wondering for a little while wether to have PogoScript generate fully CPS code for situations that would benefit from it. The situations I was thinking of were highly IO bound code, or code that would benefit from a distributed parallelism.
For example, we can make IO calls without having to worry about callbacks or funny async operators. Our code is back as it was in regular languages like C# or Ruby.
locations = read file "locations.xml"
http: post (locations) to "http://example.com/locations"
But this would break one of Node's best features for concurrent programming: cooperative multi-threading. With cooperative multi-threading, the thread chooses when to yield, meaning that it has a chance to get its state consistent before another thread is scheduled. In preemptive multi-threading, when the scheduler chooses to yield a thread, the thread has to use locks to protect inconsistent state.
By allowing implicit CPS (like Scheme) for the purposes of running IO and distributed parallelism, we destroy this property: effectively any call could invoke a yield that may lead to another "thread" accessing inconsistent state.
So we're back to the original proposal for CPS calls in PogoScript: use an operator to mark those calls that should be called CPS.
locations = ~ read file "locations.xml"
http: ~ post (locations) to "http://example.com/locations"
At the time that operator was ~
, which is the JavaScript bit-wise not operator, we should find a different one.
Perhaps a leading <-
would do?
locations = <- read file "locations.xml"
http: <- post (locations) to "http://example.com/locations"
According to the documentation, you can have Closure Compiler add the sourceMappingURL to the bottom of the script with something like this:
--output_wrapper "%output%
//# sourceMappingURL=output.js.map"
being added to your call. Not that you cannot use "\n" here, and you need a newline literal. On a Linux shell this works just fine (if you're inside of quotes when you press enter, the command doesn't get executed).