mirror of
https://github.com/janet-lang/janet
synced 2024-11-19 07:04:48 +00:00
Merge pull request #107 from ALSchwalm/compile-only
Add a 'compile-only' flag to the command line
This commit is contained in:
commit
8de999c8f7
@ -1458,6 +1458,7 @@
|
||||
:env - the environment to compile against - default is the current env\n\t
|
||||
:source - string path of source for better errors - default is \"<anonymous>\"\n\t
|
||||
:on-compile-error - callback when compilation fails - default is bad-compile\n\t
|
||||
:compile-only - only compile the souce, do not execute it - default is false\n\t
|
||||
:on-status - callback when a value is evaluated - default is debug/stacktrace\n\t
|
||||
:fiber-flags - what flags to wrap the compilation fiber with. Default is :ia."
|
||||
[opts]
|
||||
@ -1468,9 +1469,11 @@
|
||||
:on-compile-error on-compile-error
|
||||
:on-parse-error on-parse-error
|
||||
:fiber-flags guard
|
||||
:compile-only compile-only
|
||||
:source where} opts)
|
||||
(default env (fiber/getenv (fiber/current)))
|
||||
(default chunks getline)
|
||||
(default compile-only false)
|
||||
(default onstatus debug/stacktrace)
|
||||
(default on-compile-error bad-compile)
|
||||
(default on-parse-error bad-parse)
|
||||
@ -1490,7 +1493,7 @@
|
||||
(fn []
|
||||
(def res (compile source env where))
|
||||
(if (= (type res) :function)
|
||||
(res)
|
||||
(unless compile-only (res))
|
||||
(do
|
||||
(set good false)
|
||||
(def {:error err :start start :end end :fiber errf} res)
|
||||
@ -1658,7 +1661,8 @@
|
||||
(defn dofile
|
||||
"Evaluate a file in a new environment and return the new environment."
|
||||
[path & args]
|
||||
(def {:exit exit-on-error} (table ;args))
|
||||
(def {:exit exit-on-error
|
||||
:compile-only compile-only} (table ;args))
|
||||
(def f (file/open path))
|
||||
(def newenv (make-env))
|
||||
(defn chunks [buf _] (file/read f 2048 buf))
|
||||
@ -1678,6 +1682,7 @@
|
||||
(when (not= (fiber/status f) :dead)
|
||||
(debug/stacktrace f x)
|
||||
(if exit-on-error (os/exit 1))))
|
||||
:compile-only compile-only
|
||||
:source path})
|
||||
(file/close f)
|
||||
(table/setproto newenv nil))
|
||||
|
@ -9,6 +9,7 @@
|
||||
(var *handleopts* true)
|
||||
(var *exit-on-error* true)
|
||||
(var *colorize* true)
|
||||
(var *compile-only* false)
|
||||
|
||||
(if-let [jp (os/getenv "JANET_PATH")] (set module/*syspath* jp))
|
||||
|
||||
@ -25,6 +26,7 @@
|
||||
-r : Enter the repl after running all scripts
|
||||
-p : Keep on executing if there is a top level error (persistent)
|
||||
-q : Hide prompt, logo, and repl output (quiet)
|
||||
-k : Compile scripts but do not execute
|
||||
-m syspath : Set system path for loading global modules
|
||||
-c source output : Compile janet source code into an image
|
||||
-n : Disable ANSI color output in the repl
|
||||
@ -37,6 +39,7 @@
|
||||
"r" (fn [&] (set *should-repl* true) 1)
|
||||
"p" (fn [&] (set *exit-on-error* false) 1)
|
||||
"q" (fn [&] (set *quiet* true) 1)
|
||||
"k" (fn [&] (set *compile-only* true) 1)
|
||||
"n" (fn [&] (set *colorize* false) 1)
|
||||
"m" (fn [i &] (set module/*syspath* (get process/args (+ i 1))) 2)
|
||||
"c" (fn [i &]
|
||||
@ -67,10 +70,10 @@
|
||||
(+= i (dohandler (string/slice arg 1 2) i))
|
||||
(do
|
||||
(set *no-file* false)
|
||||
(import* arg :prefix "" :exit *exit-on-error*)
|
||||
(import* arg :prefix "" :exit *exit-on-error* :compile-only *compile-only*)
|
||||
(set i lenargs))))
|
||||
|
||||
(when (or *should-repl* *no-file*)
|
||||
(when (and (not *compile-only*) (or *should-repl* *no-file*))
|
||||
(if-not *quiet*
|
||||
(print "Janet " janet/version "-" janet/build " Copyright (C) 2017-2019 Calvin Rose"))
|
||||
(defn noprompt [_] "")
|
||||
|
Loading…
Reference in New Issue
Block a user