mirror of
https://github.com/janet-lang/janet
synced 2024-12-25 16:00:27 +00:00
Simplify eval-string implementation.
This commit is contained in:
parent
a3a42eebea
commit
8d1cfe0c56
@ -2542,31 +2542,6 @@
|
||||
(setdyn :exit-value value)
|
||||
nil)
|
||||
|
||||
(defn eval-string
|
||||
``Evaluates a string in the current environment. If more control over the
|
||||
environment is needed, use `run-context`.``
|
||||
[str]
|
||||
(var state (string str))
|
||||
(defn chunks [buf _]
|
||||
(def ret state)
|
||||
(set state nil)
|
||||
(when ret
|
||||
(buffer/push-string buf str)
|
||||
(buffer/push-string buf "\n")))
|
||||
(var returnval nil)
|
||||
(run-context {:chunks chunks
|
||||
:on-compile-error (fn compile-error [msg errf &]
|
||||
(error (string "compile error: " msg)))
|
||||
:on-parse-error (fn parse-error [p x]
|
||||
(error (string "parse error: " (:error p))))
|
||||
:fiber-flags :i
|
||||
:on-status (fn on-status [f val]
|
||||
(if-not (= (fiber/status f) :dead)
|
||||
(error val))
|
||||
(set returnval val))
|
||||
:source :eval-string})
|
||||
returnval)
|
||||
|
||||
(defn eval
|
||||
``Evaluates a form in the current environment. If more control over the
|
||||
environment is needed, use `run-context`.``
|
||||
@ -2582,6 +2557,8 @@
|
||||
[str]
|
||||
(let [p (parser/new)]
|
||||
(parser/consume p str)
|
||||
(if (= :error (parser/status p))
|
||||
(error (parser/error p)))
|
||||
(parser/eof p)
|
||||
(if (parser/has-more p)
|
||||
(parser/produce p)
|
||||
@ -2596,6 +2573,8 @@
|
||||
(let [p (parser/new)
|
||||
ret @[]]
|
||||
(parser/consume p str)
|
||||
(if (= :error (parser/status p))
|
||||
(error (parser/error p)))
|
||||
(parser/eof p)
|
||||
(while (parser/has-more p)
|
||||
(array/push ret (parser/produce p)))
|
||||
@ -2603,6 +2582,14 @@
|
||||
(error (parser/error p))
|
||||
ret)))
|
||||
|
||||
(defn eval-string
|
||||
``Evaluates a string in the current environment. If more control over the
|
||||
environment is needed, use `run-context`.``
|
||||
[str]
|
||||
(var ret nil)
|
||||
(each x (parse-all str) (set ret (eval x)))
|
||||
ret)
|
||||
|
||||
(def load-image-dict
|
||||
``A table used in combination with `unmarshal` to unmarshal byte sequences created
|
||||
by `make-image`, such that `(load-image bytes)` is the same as `(unmarshal bytes load-image-dict)`.``
|
||||
|
Loading…
Reference in New Issue
Block a user