mirror of
https://github.com/janet-lang/janet
synced 2024-12-28 09:20:26 +00:00
Merge branch 'preload'
This commit is contained in:
commit
711ee5a36d
@ -2,6 +2,7 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
## Unreleased - ???
|
## Unreleased - ???
|
||||||
|
- Adds a :preload loader which allows one to manually put things into `module/cache`.
|
||||||
- Add `buffer/push` function.
|
- Add `buffer/push` function.
|
||||||
- Backtick delimited strings and buffers are now reindented based on the column of the
|
- Backtick delimited strings and buffers are now reindented based on the column of the
|
||||||
opening delimiter. WHitespace in columns to the left of the starting column is ignored unless
|
opening delimiter. WHitespace in columns to the left of the starting column is ignored unless
|
||||||
|
@ -2560,6 +2560,10 @@
|
|||||||
(setdyn :syspath (boot/opts "JANET_PATH"))
|
(setdyn :syspath (boot/opts "JANET_PATH"))
|
||||||
(setdyn :headerpath (boot/opts "JANET_HEADERPATH"))
|
(setdyn :headerpath (boot/opts "JANET_HEADERPATH"))
|
||||||
|
|
||||||
|
(def module/cache
|
||||||
|
"Table mapping loaded module identifiers to their environments."
|
||||||
|
@{})
|
||||||
|
|
||||||
(defn module/add-paths
|
(defn module/add-paths
|
||||||
```
|
```
|
||||||
Add paths to module/paths for a given loader such that
|
Add paths to module/paths for a given loader such that
|
||||||
@ -2584,6 +2588,7 @@
|
|||||||
(module/add-paths "/init.janet" :source)
|
(module/add-paths "/init.janet" :source)
|
||||||
(module/add-paths ".janet" :source)
|
(module/add-paths ".janet" :source)
|
||||||
(module/add-paths ".jimage" :image)
|
(module/add-paths ".jimage" :image)
|
||||||
|
(array/insert module/paths 0 [(fn is-cached [path] (if (in module/cache path) path)) :preload])
|
||||||
|
|
||||||
# Version of fexists that works even with a reduced OS
|
# Version of fexists that works even with a reduced OS
|
||||||
(defn fexists
|
(defn fexists
|
||||||
@ -2638,10 +2643,6 @@
|
|||||||
(undef check-.)
|
(undef check-.)
|
||||||
(undef not-check-.)
|
(undef not-check-.)
|
||||||
|
|
||||||
(def module/cache
|
|
||||||
"Table mapping loaded module identifiers to their environments."
|
|
||||||
@{})
|
|
||||||
|
|
||||||
(def module/loading
|
(def module/loading
|
||||||
`Table mapping currently loading modules to true. Used to prevent
|
`Table mapping currently loading modules to true. Used to prevent
|
||||||
circular dependencies.`
|
circular dependencies.`
|
||||||
@ -2706,6 +2707,11 @@
|
|||||||
(def newenv (dofile path ;args))
|
(def newenv (dofile path ;args))
|
||||||
(put module/loading path nil)
|
(put module/loading path nil)
|
||||||
newenv)
|
newenv)
|
||||||
|
:preload (fn [path & args]
|
||||||
|
(when-let [m (in module/cache path)]
|
||||||
|
(if (function? m)
|
||||||
|
(set (module/cache path) (m path ;args))
|
||||||
|
m)))
|
||||||
:image (fn [path &] (load-image (slurp path)))})
|
:image (fn [path &] (load-image (slurp path)))})
|
||||||
|
|
||||||
(defn require-1
|
(defn require-1
|
||||||
|
Loading…
Reference in New Issue
Block a user