Omnigia

December 23, 2006

CPSCM passes R5RS pitfalls

Filed under: scheme, cpscm — Dan Muresan @ 2:53 am

After several fixes and tweaks, the CPSCM Javascript backend passes the R5RS Pitfalls test with a full score. The Lisp backend almost does, but since I decided to stick with Lisp’s convention of representing both false booleans and empty lists with NIL, it fails cases 5.1 - 5.3.

Additionally, I have tested the bubble sort example and the JS backend in general under IE 6, Firefox and Opera (the browsers I can access easily). I haven’t encountered any issues. If you are using IE 7 or Safari and run into problems, please report. The online compiler now lets you execute compiled code directly in your browser, so it’s much easier to test than before.

On the negative side, some of you have noticed that the CPS code is more bloated than before. This is because I had to back out η-reduction for some cases, in the interest of correctness: (lambda (x) (f x)) does not reduce to f automaticaly if f is mutable (and, of course, Scheme is not Erlang). The analysis module will catch up eventually…

December 14, 2006

CPSCM translates Scheme to Javascript

Filed under: scheme, cpscm — Dan Muresan @ 7:21 am

I have added a Javascript backend for CPSCM. The compiled code runs either inside a browser or in Rhino. The Bubble sort example demonstrates compiled Scheme code running “in a web page” and interfacing with native Javascript code (the latter provides DHTML functionality). You can call Scheme functions from Javascript and Javascript functions from Scheme with no restrictions (even continuations will work correctly). The explanations on the bubblesort page should get you started, in case you want to roll your own Scheme programs.

I have made updates and fixes to all backends. There are still missing pieces, but at least now they are summarized on the conformance page, so you know what to expect. Among the improvements, there is an error function which interacts correctly with dynamic-wind. I have borrowed the concept of failure continuations from SISC; you can access them via with-failure-continuation.

Finally, since Javascript console I/O is not standardized, I have implemented SRFI-6 output strings. By default, (display) and its family assume you are using Rhino and try to print to standard output. You can switch to a string using (current-output-port (open-output-string)), and at any point retrieve the accumulated output using (get-output-string (current-output-port)).

December 3, 2006

CPSCM improvements

Filed under: scheme, cpscm — Dan Muresan @ 10:44 am

Alessandro Colomba (of SISCweb fame) played with CPSCM and noted that he had trouble compiling the SRFI-1 reference implementation (you need a self-contained SRFI-1 to check). After investigating the problem, I found out that the culprit was the η-reduction code in simplify-sexp, which wasn’t designed carefully and exhibited exponential behavior on certain inputs (in practice, I’ve only seen that happen on CPS-ed code). After refactoring simplify-sexp, SRFI-1 compiles in just a few seconds.

The fixes are up in SVN (I’ve tagged the current version as rel-0.9.2). Other improvements:

  • Most of the code can be compiled under Chicken, with remarkable speed gains. Just type make in the scm directory. csi (which is still needed for the REPL) uses the compiled libraries automatically.
  • By popular demand I have added a file->lisp procedure for compiling a Scheme source file.
  • Programs are no longer wrapped in a giant letrec, but generate a sequence of top-level definitions and evaluation calls. This means you can compile libraries (such as SRFI-1 above) to separate files, and then load those compiled files independently in the back-end.

[ Powered by WordPress ]