ryansuchocki / microscheme

A Scheme subset for Atmel microcontrollers.
http://ryansuchocki.github.io/microscheme/
MIT License
300 stars 20 forks source link

Exception in loop when using for-each #22

Closed rekado closed 8 years ago

rekado commented 8 years ago

When I run this on an ATmega32, after just a few seconds an exception is signaled (different exceptions dependent on what happens in the lambda).

(define (loop)
  (for-each
   (lambda (_) 1) (list 1))
  (pause 1))

(forever loop)

It doesn't matter what value is returned in the lambda. The same behaviour can be observed when I replace the lambda with a procedure that's defined outside of the loop.

Seems that there's something wrong with for-each.

ryansuchocki commented 8 years ago

See http://microscheme.org/documentation#memman

rekado commented 8 years ago

Bummer. Are there any plans to add garbage collection? Or to pin lambdas automatically?

ryansuchocki commented 8 years ago

Either of those would be brilliant, and I have spent a lot of time thinking about them, but they are not easy. It seems garbage collection will require deep changes to the runtime system, and lambda lifting might require equally deep changes to the compiler architecture. Honestly, I don't know if I'll ever have the time to do it myself, but then, that's the point of open-sourcing isn't it! ;-)

ryansuchocki commented 8 years ago

To clarify: it's not just a time issue... I haven't really worked out how to do it :)