blob: bc6fa854d8f3d0023e25fd902055c1d4976eeeb8 (
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
|
;; 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 [|let |do return* return fail fail*]])
(lux.compiler [base :as &&])
[lux.lib.loader :as &lib]))
;; [Utils]
(def ^:private !libs (atom nil))
(defn ^:private libs-imported? []
(not (nil? @!libs)))
(defn ^:private init-libs! []
(reset! !libs (&lib/load)))
;; [Resources]
(defn read-file [^String file-name]
(let [file (new java.io.File (str &&/input-dir "/" file-name))]
(if (.exists file)
(return (slurp file))
(do (when (not (libs-imported?))
(init-libs!))
(if-let [code (get @!libs file-name)]
(return code)
(fail (str "[I/O Error] File doesn't exist: " file-name)))))))
|