1
0
mirror of https://github.com/janet-lang/janet synced 2025-12-11 19:18:07 +00:00

Improve flychecking.

Flychecking will now work correctly with arity checking, and
will better handle imports. Well structured modules should interact
cleanly with the flychecker in a mostly safe manner, but maliciously
crafted modules can execute arbitrary code. As such, the flychecker is
not a good way to validate completely untrusted modules.

We also extend run-context with an :evaluator option to replace
:compile-only. This is more flexible and allows users to create their
own flychecker like functionality.
This commit is contained in:
Calvin Rose
2019-10-27 16:15:41 -05:00
parent d28925fdab
commit 45c2819068
3 changed files with 24 additions and 8 deletions

View File

@@ -63,6 +63,21 @@
(def h (get handlers n))
(if h (h i) (do (print "unknown flag -" n) ((get handlers "h")))))
(def- safe-forms {'defn true 'defn- true 'defmacro true 'defmacro- true})
(def- importers {'import true 'import* true 'use true 'dofile true 'require true})
(defn- evaluator
[thunk source env where]
(if *compile-only*
(when (tuple? source)
(cond
(safe-forms (source 0)) (thunk)
(importers (source 0))
(do
(let [[l c] (tuple/sourcemap source)
newtup (tuple/setmap (tuple ;source :evaluator evaluator) l c)]
((compile newtup env where))))))
(thunk)))
# Process arguments
(var i 0)
(def lenargs (length args))
@@ -72,7 +87,7 @@
(+= i (dohandler (string/slice arg 1 2) i))
(do
(set *no-file* false)
(dofile arg :prefix "" :exit *exit-on-error* :compile-only *compile-only*)
(dofile arg :prefix "" :exit *exit-on-error* :evaluator evaluator)
(set i lenargs))))
(when (and (not *compile-only*) (or *should-repl* *no-file*))