1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-27 00:40:26 +00:00

Merge branch 'preload'

This commit is contained in:
Calvin Rose 2020-12-06 21:06:59 -06:00
commit 711ee5a36d
2 changed files with 11 additions and 4 deletions

View File

@ -2,6 +2,7 @@
All notable changes to this project will be documented in this file.
## Unreleased - ???
- Adds a :preload loader which allows one to manually put things into `module/cache`.
- Add `buffer/push` function.
- 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

View File

@ -2560,6 +2560,10 @@
(setdyn :syspath (boot/opts "JANET_PATH"))
(setdyn :headerpath (boot/opts "JANET_HEADERPATH"))
(def module/cache
"Table mapping loaded module identifiers to their environments."
@{})
(defn module/add-paths
```
Add paths to module/paths for a given loader such that
@ -2584,6 +2588,7 @@
(module/add-paths "/init.janet" :source)
(module/add-paths ".janet" :source)
(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
(defn fexists
@ -2638,10 +2643,6 @@
(undef check-.)
(undef not-check-.)
(def module/cache
"Table mapping loaded module identifiers to their environments."
@{})
(def module/loading
`Table mapping currently loading modules to true. Used to prevent
circular dependencies.`
@ -2706,6 +2707,11 @@
(def newenv (dofile path ;args))
(put module/loading path nil)
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)))})
(defn require-1