mirror of
https://github.com/janet-lang/janet
synced 2024-11-29 03:19:54 +00:00
parent
bb5c478704
commit
081d132538
@ -32,7 +32,7 @@
|
|||||||
(def buf (buffer "(" name))
|
(def buf (buffer "(" name))
|
||||||
(while (< index arglen)
|
(while (< index arglen)
|
||||||
(buffer/push-string buf " ")
|
(buffer/push-string buf " ")
|
||||||
(buffer/format buf "%p" (in args index))
|
(buffer/format buf "%j" (in args index))
|
||||||
(set index (+ index 1)))
|
(set index (+ index 1)))
|
||||||
(array/push modifiers (string buf ")\n\n" docstr))
|
(array/push modifiers (string buf ")\n\n" docstr))
|
||||||
# Build return value
|
# Build return value
|
||||||
@ -1892,6 +1892,7 @@
|
|||||||
(defn run-context
|
(defn run-context
|
||||||
"Run a context. This evaluates expressions of janet in an environment,
|
"Run a context. This evaluates expressions of janet in an environment,
|
||||||
and is encapsulates the parsing, compilation, and evaluation.
|
and is encapsulates the parsing, compilation, and evaluation.
|
||||||
|
Returns (in environment :exit-value environment) when complete.
|
||||||
opts is a table or struct of options. The options are as follows:\n\n\t
|
opts is a table or struct of options. The options are as follows:\n\n\t
|
||||||
:chunks - callback to read into a buffer - default is getline\n\t
|
:chunks - callback to read into a buffer - default is getline\n\t
|
||||||
:on-parse-error - callback when parsing fails - default is bad-parse\n\t
|
:on-parse-error - callback when parsing fails - default is bad-parse\n\t
|
||||||
@ -2149,13 +2150,15 @@
|
|||||||
@{})
|
@{})
|
||||||
|
|
||||||
(defn dofile
|
(defn dofile
|
||||||
"Evaluate a file and return the resulting environment."
|
"Evaluate a file and return the resulting environment. :env, :expander, and
|
||||||
[path & args]
|
:evaluator are passed through to the underlying run-context call.
|
||||||
(def {:exit exit-on-error
|
If exit is true, any top level errors will trigger a call to (os/exit 1)
|
||||||
:source source
|
after printing the error."
|
||||||
:env env
|
[path &keys
|
||||||
:expander expander
|
{:exit exit
|
||||||
:evaluator evaluator} (table ;args))
|
:env env
|
||||||
|
:expander expander
|
||||||
|
:evaluator evaluator}]
|
||||||
(def f (if (= (type path) :core/file)
|
(def f (if (= (type path) :core/file)
|
||||||
path
|
path
|
||||||
(file/open path :rb)))
|
(file/open path :rb)))
|
||||||
@ -2167,11 +2170,11 @@
|
|||||||
(defn chunks [buf _] (file/read f 2048 buf))
|
(defn chunks [buf _] (file/read f 2048 buf))
|
||||||
(defn bp [&opt x y]
|
(defn bp [&opt x y]
|
||||||
(def ret (bad-parse x y))
|
(def ret (bad-parse x y))
|
||||||
(if exit-on-error (os/exit 1))
|
(if exit (os/exit 1))
|
||||||
ret)
|
ret)
|
||||||
(defn bc [&opt x y z]
|
(defn bc [&opt x y z]
|
||||||
(def ret (bad-compile x y z))
|
(def ret (bad-compile x y z))
|
||||||
(if exit-on-error (os/exit 1))
|
(if exit (os/exit 1))
|
||||||
ret)
|
ret)
|
||||||
(unless f
|
(unless f
|
||||||
(error (string "could not find file " path)))
|
(error (string "could not find file " path)))
|
||||||
@ -2183,7 +2186,7 @@
|
|||||||
:on-status (fn [f x]
|
:on-status (fn [f x]
|
||||||
(when (not= (fiber/status f) :dead)
|
(when (not= (fiber/status f) :dead)
|
||||||
(debug/stacktrace f x)
|
(debug/stacktrace f x)
|
||||||
(if exit-on-error (os/exit 1) (eflush))))
|
(if exit (os/exit 1) (eflush))))
|
||||||
:evaluator evaluator
|
:evaluator evaluator
|
||||||
:expander expander
|
:expander expander
|
||||||
:source (if path-is-file "<anonymous>" spath)}))
|
:source (if path-is-file "<anonymous>" spath)}))
|
||||||
@ -2244,18 +2247,14 @@
|
|||||||
any errors encountered at the top level in the module will cause (os/exit 1)
|
any errors encountered at the top level in the module will cause (os/exit 1)
|
||||||
to be called. Dynamic bindings will NOT be imported."
|
to be called. Dynamic bindings will NOT be imported."
|
||||||
[path & args]
|
[path & args]
|
||||||
(def argm (map (fn [x]
|
(def argm (map |(if (keyword? $) $ (string $)) args))
|
||||||
(if (keyword? x)
|
|
||||||
x
|
|
||||||
(string x)))
|
|
||||||
args))
|
|
||||||
(tuple import* (string path) ;argm))
|
(tuple import* (string path) ;argm))
|
||||||
|
|
||||||
(defmacro use
|
(defmacro use
|
||||||
"Similar to import, but imported bindings are not prefixed with a namespace
|
"Similar to import, but imported bindings are not prefixed with a namespace
|
||||||
identifier. Can also import multiple modules in one shot."
|
identifier. Can also import multiple modules in one shot."
|
||||||
[& modules]
|
[& modules]
|
||||||
~(do ,;(map (fn [x] ~(,import* ,(string x) :prefix "")) modules)))
|
~(do ,;(map |~(,import* ,(string $) :prefix "") modules)))
|
||||||
|
|
||||||
###
|
###
|
||||||
###
|
###
|
||||||
@ -2271,11 +2270,15 @@
|
|||||||
the repl in."
|
the repl in."
|
||||||
[&opt chunks onsignal env]
|
[&opt chunks onsignal env]
|
||||||
(default env (make-env))
|
(default env (make-env))
|
||||||
(default chunks (fn [buf p] (getline (string "repl:"
|
(default chunks
|
||||||
((parser/where p) 0)
|
(fn [buf p]
|
||||||
":"
|
(getline
|
||||||
(parser/state p :delimiters) "> ")
|
(string
|
||||||
buf env)))
|
"repl:"
|
||||||
|
((parser/where p) 0)
|
||||||
|
":"
|
||||||
|
(parser/state p :delimiters) "> ")
|
||||||
|
buf env)))
|
||||||
(defn make-onsignal
|
(defn make-onsignal
|
||||||
[e level]
|
[e level]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user