#!/usr/bin/env ruby root = File.expand_path('../..', __FILE__) lib_path = File.join(root, 'lib') $LOAD_PATH << lib_path unless $LOAD_PATH.include? lib_path require 'shen_ruby' # Leave gracefully if someone hits Control-C during loading Signal.trap("INT") { puts "\nLeaving..."; exit 1 } # Load the Shen Envinronment print "Loading..." STDOUT.flush start = Time.now.to_f shen = ShenRuby::Shen.new now = Time.now.to_f puts ". Completed in %0.2f seconds.\n" % (now - start) # Now that the Shen environment is loaded, repurpose the SIGINT # handler to interrupt the current execution. Subclass Interrupt # so that the exception is not caught by trap-error. class ReplInterrupt < Interrupt; end Signal.trap("INT") { raise ReplInterrupt } # Launch the REPL command = :"shen.shen" begin shen.__send__ command rescue ReplInterrupt, SystemStackError => e if e.kind_of? ReplInterrupt puts "Execution interrupted. If you are trying to exit the REPL, use (quit)." else puts "Stack overflow" end command = :"shen.loop" retry end