views:

102

answers:

1

I'm wondering why nested function calls don't work.

I'm implementing Dybvig's Heap-based model from his paper http://www.cs.indiana.edu/~dyb/pubs/3imp.pdf Chapter 3.
I'm doing it in JavaScript. Source is here: http://github.com/z5h/zb-lisp
Pretty much everything is in parser.js right now.

To run,

  1. load test.html in Firefox with Firebug.
  2. Evaluator.newEvaluator().eval("scheme code goes here");
  3. Leave some whitespace at the end of the code as the parser is a little broken right now and relies on whitespace at the end. (to be fixed). e.g. .eval("12 ") not .eval("12")

Lots of stuff works. But I'm having problems with nested function calls: This works and returns 5:
(set! i (lambda (x) x)) (set! ii (i i)) (ii 5)
This does not work:
(set! i (lambda (x) x)) (i (i 5))
Nor does this:
(set! i (lambda (x) x)) ((i i) 5)

The problem might be around line 577 where a nested call is compiled, or perhaps in the code for frame or apply. Section 3.4.2 of the PDF is where sample implementation is described.

This is a pretty complex question. The code has many rough edges.
Any input is appreciated.

I'm happy to answer any questions my implementation.

A: 

It turns out I was clearing the value rib early.

The improved code is available at my github.

z5h