var _ns_ = {
  "id": "wisp.wisp",
  "doc": "Wisp program that reads wisp code from stdin and prints\n  compiled javascript code into stdout"
};
var fs = require("fs");;
var path = require("path");;
var module = require("module");
var Module = module.Module;;
var wisp_repl = require("./repl");
var start = wisp_repl.start;;
var wisp_runtime = require("./runtime");
var str = wisp_runtime.str;;
var wisp_compiler = require("./compiler");
var compile_ = wisp_compiler.compile_;;
var wisp_reader = require("./reader");
var read_ = wisp_reader.read_;;;

var exit = function exit(error) {
  return error ?
    (function() {
      console.error(error);
      return process.exit(1);
    })() :
    process.exit(0);
};

var compile = function compile(input, output, uri) {
  var source = "";
  input.on("data", function onChunck(chunck) {
    return source = "" + source + chunck;
  });
  input.on("end", function onRead() {
    return (function() {
    try {
      return output.write(compile_(read_(source)));
    } catch (error) {
      return exit(error);
    }})();
  });
  input.on("error", exit);
  return output.on("error", exit);
};

var main = function main() {
  return process.argv.length < 3 ?
    (function() {
      process.stdin.resume();
      process.stdin.setEncoding("utf8");
      compile(process.stdin, process.stdout, process.cwd());
      return setTimeout(function() {
        return process.stdin.bytesRead === 0 ?
          (function() {
            process.stdin.removeAllListeners("data");
            return start();
          })() :
          void(0);
      }, 20);
    })() :
    Module._load(path.resolve((process.argv || 0)[2]), null, true);
};
exports.main = main