mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 19:19:53 +00:00
Deprecate process/args and add use macro.
Use is a shorthand for (import module :prefix ""). process/args has been replaced by (dyn :args) at the top level.
This commit is contained in:
parent
0d3986abbb
commit
a0e98b9aa8
@ -79,7 +79,7 @@ Keys are:
|
||||
"clear-cache" cook/clear-cache
|
||||
"uninstall" uninstall})
|
||||
|
||||
(def args (tuple/slice process/args 2))
|
||||
(def args (tuple/slice (dyn :args) 2))
|
||||
(def len (length args))
|
||||
(var i 0)
|
||||
|
||||
|
@ -50,7 +50,7 @@ int main(int argc, const char **argv) {
|
||||
JanetArray *args = janet_array(argc);
|
||||
for (int i = 0; i < argc; i++)
|
||||
janet_array_push(args, janet_cstringv(argv[i]));
|
||||
janet_def(env, "process/args", janet_wrap_array(args), "Command line arguments.");
|
||||
janet_def(env, "boot/args", janet_wrap_array(args), "Command line arguments.");
|
||||
|
||||
/* Add in options from janetconf.h so boot.janet can configure the image as needed. */
|
||||
JanetTable *opts = janet_table(0);
|
||||
@ -60,7 +60,7 @@ int main(int argc, const char **argv) {
|
||||
#ifdef JANET_NO_SOURCEMAPS
|
||||
janet_table_put(opts, janet_ckeywordv("no-sourcemaps"), janet_wrap_true());
|
||||
#endif
|
||||
janet_def(env, "process/config", janet_wrap_table(opts), "Boot options");
|
||||
janet_def(env, "boot/config", janet_wrap_table(opts), "Boot options");
|
||||
|
||||
/* Run bootstrap script to generate core image */
|
||||
const char *boot_file;
|
||||
|
@ -1433,10 +1433,10 @@
|
||||
###
|
||||
###
|
||||
|
||||
# Get process options
|
||||
(def- process/opts @{})
|
||||
(each [k v] (partition 2 (tuple/slice process/args 2))
|
||||
(put process/opts k v))
|
||||
# Get boot options
|
||||
(def- boot/opts @{})
|
||||
(each [k v] (partition 2 (tuple/slice boot/args 2))
|
||||
(put boot/opts k v))
|
||||
|
||||
(defn make-env
|
||||
"Create a new environment table. The new environment
|
||||
@ -1624,8 +1624,8 @@
|
||||
[":sys:/:all:/init.janet" :source not-check-.]
|
||||
[(string ":sys:/:all:" nati) :native not-check-.]])
|
||||
|
||||
(setdyn :syspath (process/opts "JANET_PATH"))
|
||||
(setdyn :headerpath (process/opts "JANET_HEADERPATH"))
|
||||
(setdyn :syspath (boot/opts "JANET_PATH"))
|
||||
(setdyn :headerpath (boot/opts "JANET_HEADERPATH"))
|
||||
|
||||
# Version of fexists that works even with a reduced OS
|
||||
(if-let [has-stat (_env 'os/stat)]
|
||||
@ -1853,7 +1853,7 @@ _fiber is bound to the suspended fiber
|
||||
(env-walk keyword? env))
|
||||
|
||||
# Clean up some extra defs
|
||||
(put _env 'process/opts nil)
|
||||
(put _env 'boot/opts nil)
|
||||
(put _env 'env-walk nil)
|
||||
(put _env '_env nil)
|
||||
|
||||
@ -1880,13 +1880,14 @@ _fiber is bound to the suspended fiber
|
||||
(loop [[k v] :pairs env
|
||||
:when (symbol? k)]
|
||||
(def flat (proto-flatten @{} v))
|
||||
(when (process/config :no-docstrings)
|
||||
(when (boot/config :no-docstrings)
|
||||
(put flat :doc nil))
|
||||
(when (process/config :no-sourcemaps)
|
||||
(when (boot/config :no-sourcemaps)
|
||||
(put flat :source-map nil))
|
||||
(put env k flat))
|
||||
|
||||
(put env 'process/config nil)
|
||||
(put env 'boot/config nil)
|
||||
(put env 'boot/args nil)
|
||||
(def image (let [env-pairs (pairs (env-lookup env))
|
||||
essential-pairs (filter (fn [[k v]] (or (cfunction? v) (abstract? v))) env-pairs)
|
||||
lookup (table ;(mapcat identity essential-pairs))
|
||||
@ -1897,7 +1898,7 @@ _fiber is bound to the suspended fiber
|
||||
# can be compiled and linked statically into the main janet library
|
||||
# and example client.
|
||||
(def chunks (string/bytes image))
|
||||
(def image-file (file/open (process/args 1) :wb))
|
||||
(def image-file (file/open (boot/args 1) :wb))
|
||||
(file/write image-file
|
||||
"#ifndef JANET_AMALG\n"
|
||||
"#include <janet.h>\n"
|
||||
|
@ -1,5 +1,7 @@
|
||||
# Copyright 2017-2019 (C) Calvin Rose
|
||||
|
||||
(def process/args "Deprecated. use '(dyn :args)' at script entry instead for process argument array."
|
||||
(dyn :args))
|
||||
(do
|
||||
|
||||
(var *should-repl* false)
|
||||
@ -13,11 +15,12 @@
|
||||
|
||||
(if-let [jp (os/getenv "JANET_PATH")] (setdyn :syspath jp))
|
||||
(if-let [jp (os/getenv "JANET_HEADERPATH")] (setdyn :headerpath jp))
|
||||
(def args (dyn :args))
|
||||
|
||||
# Flag handlers
|
||||
(def handlers :private
|
||||
{"h" (fn [&]
|
||||
(print "usage: " (get process/args 0) " [options] script args...")
|
||||
(print "usage: " (get args 0) " [options] script args...")
|
||||
(print
|
||||
`Options are:
|
||||
-h : Show this help
|
||||
@ -42,20 +45,20 @@
|
||||
"q" (fn [&] (set *quiet* true) 1)
|
||||
"k" (fn [&] (set *compile-only* true) (set *exit-on-error* false) 1)
|
||||
"n" (fn [&] (set *colorize* false) 1)
|
||||
"m" (fn [i &] (setdyn :syspath (get process/args (+ i 1))) 2)
|
||||
"m" (fn [i &] (setdyn :syspath (get args (+ i 1))) 2)
|
||||
"c" (fn [i &]
|
||||
(def e (dofile (get process/args (+ i 1))))
|
||||
(spit (get process/args (+ i 2)) (make-image e))
|
||||
(def e (dofile (get args (+ i 1))))
|
||||
(spit (get args (+ i 2)) (make-image e))
|
||||
(set *no-file* false)
|
||||
3)
|
||||
"-" (fn [&] (set *handleopts* false) 1)
|
||||
"l" (fn [i &]
|
||||
(import* (get process/args (+ i 1))
|
||||
(import* (get args (+ i 1))
|
||||
:prefix "" :exit *exit-on-error*)
|
||||
2)
|
||||
"e" (fn [i &]
|
||||
(set *no-file* false)
|
||||
(eval-string (get process/args (+ i 1)))
|
||||
(eval-string (get args (+ i 1)))
|
||||
2)})
|
||||
|
||||
(defn- dohandler [n i &]
|
||||
@ -64,9 +67,9 @@
|
||||
|
||||
# Process arguments
|
||||
(var i 1)
|
||||
(def lenargs (length process/args))
|
||||
(def lenargs (length args))
|
||||
(while (< i lenargs)
|
||||
(def arg (get process/args i))
|
||||
(def arg (get args i))
|
||||
(if (and *handleopts* (= "-" (string/slice arg 0 1)))
|
||||
(+= i (dohandler (string/slice arg 1 2) i))
|
||||
(do
|
||||
|
@ -63,7 +63,7 @@ int main(int argc, char **argv) {
|
||||
args = janet_array(argc);
|
||||
for (i = 0; i < argc; i++)
|
||||
janet_array_push(args, janet_cstringv(argv[i]));
|
||||
janet_def(env, "process/args", janet_wrap_array(args), "Command line arguments.");
|
||||
janet_table_put(env, janet_ckeywordv("args"), janet_wrap_array(args));
|
||||
|
||||
/* Run startup script */
|
||||
status = janet_dobytes(env, janet_gen_init, janet_gen_init_size, "init.janet", NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user