Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dundalek committed Mar 8, 2020
1 parent f498c1f commit 5e8a726
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
14 changes: 5 additions & 9 deletions src/closh-sci/closh/zero/platform/clojure_compiler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,19 @@
(:require [closh.zero.reader :as reader]
[closh.zero.parser]
[closh.zero.compiler]
[closh.zero.platform.eval :as eval]
#_[closh.zero.platform.eval :as eval]
[clojure.tools.reader.reader-types :as r])
(:import (clojure.lang Compiler RT LineNumberingPushbackReader LispReader$ReaderException Compiler$CompilerException)
(java.io File FileInputStream InputStreamReader StringReader PipedWriter PipedReader PushbackReader BufferedReader)))

(defn eval [form]
(eval/eval
(closh.zero.compiler/compile-interactive
(closh.zero.parser/parse form))))

(defn reader-opts [source-name]
#_(when (str/ends-with source-name ".cljc")
RT.mapUniqueKeys (LispReader.OPT_READ_COND, LispReader.COND_ALLOW)))

;; Reimplementation of Compiler.load
(defn load
([rdr] (load rdr nil "NO_SOURCE_FILE"))
([rdr source-path source-name]
([rdr source-path source-name eval]
(let [eof (Object.)
rdr (r/indexing-push-back-reader rdr)
;;rdr ^LineNumberingPushbackReader (if (instance? LineNumberingPushbackReader rdr) rdr (LineNumberingPushbackReader. rdr))]
Expand Down Expand Up @@ -63,14 +58,15 @@
; Var.popThreadBindings())));

;; Reimplementation of Compiler.loadFile
(defn load-file [^String file]
(defn load-file [^String file eval]
(let [f ^FileInputStream (FileInputStream. file)
rdr ^InputStreamReader (InputStreamReader. f "UTF-8")]
;; rdr (make-custom-reader (PushbackReader. (InputStreamReader. f RT/UTF8)))]
(try
(load
rdr
(.getAbsolutePath (File. file))
(.getName (File. file)))
(.getName (File. file))
eval)
(finally
(.close f)))))
4 changes: 2 additions & 2 deletions src/closh-sci/closh/zero/utils/clojure_main_sci.clj
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
(closh.zero.parser/parse form))))

(defn load-reader [rdr]
(compiler/load rdr))
(compiler/load rdr eval))

(defn rt-load-resource-script [path]
(println "rt-load-resource-script stubbed:" path))

(defn compiler-load-file [path]
(compiler/load-file path))
(compiler/load-file path eval))

;; Copied from clojure/core
(defn read+string
Expand Down
19 changes: 14 additions & 5 deletions src/closh-sci/closh/zero/utils/sci.clj
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
(ns closh.zero.utils.sci
(:refer-clojure :exclude [eval load-file])
(:require [sci.core :as sci]
[sci.impl.interpreter :as interpreter]
[sci.impl.opts :as opts]
[closh.zero.pipeline :as pipeline]
[closh.zero.core :as closh-core]
[closh.zero.compiler]
[closh.zero.parser]
[closh.zero.platform.process :as process]
[closh.zero.builtin :as builtin]
[closh.zero.env :as env]
[closh.zero.util :refer [thread-stop]]
[closh.zero.macros-fns :as macros-fns]
[clojure.repl :as repl]))
[clojure.repl :as repl]
[closh.zero.platform.clojure-compiler :as clojure-compiler]))

(set! *warn-on-reflection* true)

Expand Down Expand Up @@ -76,10 +80,10 @@


(declare ctx)
(declare eval)

(defn load-file* [file]
(let [s (slurp file)]
(sci/eval-string s ctx)))
(defn load-file [file]
(clojure-compiler/load-file file eval))

(def sci-env (atom {}))

Expand All @@ -103,7 +107,7 @@
'clojure.core/swap! swap!
'print print
'println println
'load-file load-file*
'load-file load-file
'Math/sqrt #(Math/sqrt %)
'java.lang.Thread/currentThread #(Thread/currentThread)
'thread-stop thread-stop
Expand Down Expand Up @@ -146,3 +150,8 @@
;; (sci/eval-string (pr-str form) ctx)
(let [ctx (opts/init ctx)]
(interpreter/eval-form ctx form)))

(defn eval [form]
(sci-eval
(closh.zero.compiler/compile-interactive
(closh.zero.parser/parse form))))

0 comments on commit 5e8a726

Please sign in to comment.