gregspurrier / shen-ruby

ShenRuby is a port of the Shen programming language to Ruby
Other
76 stars 7 forks source link

srrepl fails to start under cygwin #3

Open gregspurrier opened 11 years ago

gregspurrier commented 11 years ago

Reported on the Qilang Google group:

I just tried it but I am getting an error:

$ srrepl
Loading.../usr/lib/ruby/gems/1.9.1/gems/shen-ruby-0.1.0/lib/kl/cons.rb:32: stack level too deep (SystemStackError)

I am testing under cygwin, is that a problem?
gregspurrier commented 11 years ago

Again from the group:

I was testing in Win7 32bit with CYGWIN_NT-6.1
gregspurrier commented 11 years ago

I have reproduced this under Windows XP Home Edition and ruby 1.9.3p327 installed via cygwin.

According to ulimit -s, the system stack is much smaller on Windows (2026k) than on OS X (8192k), which explains why I'm not running into this issue under OS X.

Based on how quickly the error message is displayed, the failure is occurring quite early in the initialization of the ShenRuby::Shen object. Trying ShenRuby::Shen.new in irb gave then same failure, but no more information. I'll have to add some instrumentation and see whether I can pinpoint where it is failing.

gregspurrier commented 11 years ago

The stack overflow is occurring in Kl::Reader#read_list while attempting to read the definition of shen_alpha? in sys.kl. The fix for this will be to keep a local stack of the nested lists in progress of being read. Hopefully the compiler won't also stack overflow on all the nested conses....

gregspurrier commented 11 years ago

This is going to be more challenging than I thought. I reimplemented Kl::Reader#read_list to not use recursion, but then the compiler caused a stack overflow when parsing the form. So, I tried pre-compiling the K Lambda code and make it part of the ShenRuby::Shen#initialize method. That helped and it got further in loading, but eventually bombed in the declare statement for vector->.

At this point, I'm not confident that ShenRuby can be made to work under cygwin with an implementation that uses the Ruby stack as its stack. I've been thinking about experimenting with the approach described in Efficient Compilation of Tail Calls and Continuations to JavaScript to see whether that improves performance and addresses the stack overflow that is currently seen in the Qi Interpreter test case when running under OS X.

That's longer term though, but perhaps could happen before the 1.0 release.

gregspurrier commented 11 years ago

It turns out that the Ruby environment installed via RubyInstaller will successfully load the Shen REPL. I still hope to be able to reduce the stack requirements for ShenRuby before the 1.0 release. In the mean time, RubyInstaller is the recommended way to run ShenRuby on Windows.