From d95941597f2d1f321dce36ff4037903bdeec4b67 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Wed, 15 Aug 2018 22:48:35 -0400 Subject: [PATCH] Fix help. --- src/core/struct.c | 9 +++------ src/mainclient/init.dst | 20 ++++++++++---------- src/mainclient/main.c | 2 +- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/core/struct.c b/src/core/struct.c index 6f53f859..1bb813da 100644 --- a/src/core/struct.c +++ b/src/core/struct.c @@ -92,7 +92,8 @@ void dst_struct_put(DstKV *st, Dst key, Dst value) { * is closer to their source than current. We use robinhood * hashing to ensure that equivalent structs that are contsructed * with different order have the same internal layout, and therefor - * will compare properly - i.e., {1 2 3 4} should equal {3 4 1 2}. */ + * will compare properly - i.e., {1 2 3 4} should equal {3 4 1 2}. + * Collisions are resolved via an insertion sort insertion. */ otherhash = dst_hash(kv->key); otherindex = dst_struct_maphash(cap, otherhash); otherdist = (i + cap - otherindex) & (cap - 1); @@ -155,11 +156,7 @@ const DstKV *dst_struct_end(DstKV *st) { /* Get an item from a struct */ Dst dst_struct_get(const DstKV *st, Dst key) { const DstKV *kv = dst_struct_find(st, key); - if (NULL == kv) { - return dst_wrap_nil(); - } else { - return kv->value; - } + return kv ? kv->value : dst_wrap_nil(); } /* Get the next key in a struct */ diff --git a/src/mainclient/init.dst b/src/mainclient/init.dst index e8530273..12d7b147 100644 --- a/src/mainclient/init.dst +++ b/src/mainclient/init.dst @@ -9,10 +9,10 @@ (var *exit-on-error* :private true) # Flag handlers - (def handlers :private - {"h" (fn [] - (print "usage: " (get args 0) " [options] scripts...") - (print + (def handlers :private + {"h" (fn @[] + (print "usage: " (get process.args 0) " [options] scripts...") + (print `Options are: -h Show this help -v Print the version string @@ -28,20 +28,20 @@ "r" (fn @[] (:= *should-repl* true) 1) "p" (fn @[] (:= *exit-on-error* false) 1) "-" (fn @[] (:= *handleopts* false) 1) - "e" (fn @[i] + "e" (fn @[i] (:= *no-file* false) - (eval (get args (+ i 1))) + (eval (get process.args (+ i 1))) 2)}) (defn- dohandler @[n i] (def h (get handlers n)) - (if h (h i) (print "unknown flag -" n))) + (if h (h i) (do (print "unknown flag -" n) ((get handlers "h"))))) # Process arguments (var i 1) - (def lenargs (length args)) + (def lenargs (length process.args)) (while (< i lenargs) - (def arg (get args i)) + (def arg (get process.args i)) (if (and *handleopts* (= "-" (string.slice arg 0 1))) (+= i (dohandler (string.slice arg 1 2) i)) (do @@ -49,7 +49,7 @@ (import* _env arg :exit *exit-on-error*) (++ i)))) - (when (or *should-repl* *no-file*) + (when (or *should-repl* *no-file*) (if *raw-stdin* (repl nil identity) (do diff --git a/src/mainclient/main.c b/src/mainclient/main.c index 4fefc1d1..ac32306f 100644 --- a/src/mainclient/main.c +++ b/src/mainclient/main.c @@ -38,7 +38,7 @@ int main(int argc, char **argv) { args = dst_array(argc); for (i = 0; i < argc; i++) dst_array_push(args, dst_cstringv(argv[i])); - dst_env_def(env, "args", dst_wrap_array(args)); + dst_env_def(env, "process.args", dst_wrap_array(args)); /* Expose line getter */ dst_env_def(env, "getline", dst_wrap_cfunction(dst_line_getter));