blob: 12073a0a5c9dd78698b5dc17979a0eca76e3d06c (
plain)
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
31
|
;; Copyright (c) Eduardo Julian. All rights reserved.
;; This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
;; If a copy of the MPL was not distributed with this file,
;; You can obtain one at http://mozilla.org/MPL/2.0/.
(ns lux.compiler.io
(:require (lux [base :as & :refer [|case |let |do return* return fail fail*]])
(lux.compiler [base :as &&])
[lux.lib.loader :as &lib]))
;; [Utils]
(def ^:private !libs (atom nil))
;; [Resources]
(defn init-libs! []
(reset! !libs (&lib/load)))
(defn read-file [source-dirs ^String file-name]
(|case (&/|some (fn [source-dir]
(let [file (new java.io.File source-dir file-name)]
(if (.exists file)
(&/$Some file)
&/$None)))
source-dirs)
(&/$Some file)
(return (slurp file))
(&/$None)
(if-let [code (get @!libs file-name)]
(return code)
(fail (str "[I/O Error] File doesn't exist: " file-name)))))
|