Sha256: 04e16b439e2f110e68a7d63447432fd27f504d6dc9ef37b71354fc4f5c6ea401

Contents?: true

Size: 1.61 KB

Versions: 2

Compression:

Stored size: 1.61 KB

Contents

(import fs "fs")
(import path "path")
(import [Module] "module")

(import [start] "./repl")
(import [str] "./runtime")
(import [transpile] "./engine/node")
(import [compile-program] "./compiler")
(import [read-from-string] "./reader")

(defn- exit
  "Takes care of exiting node and printing erros if encounted"
  [error]
  (if error
    (do
      (.error console error)
      (.exit process 1))
    (.exit process 0)))

(defn- compile
  "Compiles lispy from input and writes it to output"
  [input output uri]
  (def source "")
  (.on input :data
       (fn on-chunck
         "Accumulate text form input until it ends."
         [chunck]
         (set! source (str source chunck))))
  (.on input :end
       (fn on-read
         "Once input ends try to compile & write to output."
         []
         (try (.write output (transpile source))
           (catch error (exit error)))))
  (.on input :error exit)
  (.on output :error exit))


(defn main []
  (if (< process.argv.length 3)
    (do
      (.resume process.stdin)
      (.set-encoding process.stdin :utf8)
      ;; Compile stdin and write it to stdout.
      (compile process.stdin process.stdout (.cwd process))
      ;; If there is nothing is written to stdin within 20ms
      ;; start repl.
      (set-timeout
       (fn []
         (if (identical? process.stdin.bytes-read 0)
           (do
             (.remove-all-listeners process.stdin :data)
             (start))))
       20))
    ;; Loading module as main one, same way as nodejs does it:
    ;; https://github.com/joyent/node/blob/master/lib/module.js#L489-493
    (Module._load (.resolve path (get process.argv 2)) null true)))

Version data entries

2 entries across 1 versions & 1 rubygems

Version Path
ruby-wisp-source-0.7.0 vendor/node_modules/wisp/src/wisp.wisp
ruby-wisp-source-0.7.0 vendor/try/node_modules/~wisp/src/wisp.wisp