From d1eca1cf528d37132f972693c3d1428c056acc3d Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Wed, 17 Apr 2019 09:47:33 -0400 Subject: [PATCH] Add all-dynamics to list current dynamic bindings. --- src/boot/boot.janet | 24 +++++++++++++++++------- src/core/fiber.c | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index d756b0d3..1b834cf8 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -1735,21 +1735,31 @@ :on-status onsignal :source "repl"})) -(defn all-bindings - "Get all symbols available in the current environment." - [] +(defn- env-walk + [pred] (def env (fiber/getenv (fiber/current))) (def envs @[]) (do (var e env) (while e (array/push envs e) (set e (table/getproto e)))) - (def symbol-set @{}) + (def ret-set @{}) (loop [envi :in envs k :keys envi - :when (symbol? k)] - (put symbol-set k true)) - (sort (keys symbol-set))) + :when (pred k)] + (put ret-set k true)) + (sort (keys ret-set))) + +(defn all-bindings + "Get all symbols available in the current environment." + [] + (env-walk symbol?)) + +(defn all-dynamics + "Get all dynamic bindings in the current fiber." + [] + (env-walk keyword?)) # Clean up some extra defs (put _env 'process/opts nil) +(put _env 'env-walk nil) (put _env '_env nil) ### diff --git a/src/core/fiber.c b/src/core/fiber.c index 5a5047dc..ab317a35 100644 --- a/src/core/fiber.c +++ b/src/core/fiber.c @@ -415,7 +415,7 @@ static const JanetReg fiber_cfuns[] = { "\tu - block user signals\n" "\ty - block yield signals\n" "\t0-9 - block a specific user signal\n" - "\ti - inherit the environment from the current fiber") + "\ti - inherit the environment from the current fiber (not related to signals)") }, { "fiber/status", cfun_fiber_status,