-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathrepl.pxi
More file actions
30 lines (27 loc) · 998 Bytes
/
repl.pxi
File metadata and controls
30 lines (27 loc) · 998 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(ns pixie.repl
(:require [pixie.stacklets :as st]
[pixie.io :as io]
[pixie.ffi-infer :as f]))
(f/with-config {:library "edit"
:includes ["editline/readline.h"]}
(f/defcfn readline))
(defn repl []
(let [rdr (reader-fn (fn []
(let [prompt (if (= 0 pixie.stdlib/*reading-form*)
(str (name pixie.stdlib/*ns*) " => ")
"")
line (st/apply-blocking readline prompt)]
(if line
(str line "\n")
""))))]
(loop []
(try (let [form (read rdr false)]
(if (= form eof)
(exit 0)
(let [x (eval form)]
(pixie.stdlib/-push-history x)
(prn x))))
(catch ex
(pixie.stdlib/-set-*e ex)
(println "ERROR: \n" ex)))
(recur))))