diff --git a/CHANGELOG.md b/CHANGELOG.md index b6891e27..b9457797 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. ## ??? - Unreleased +- Allow evaluating ev streams with dofile. +- Fix `ev` related bug with operations on already closed file descriptors. +- Add struct and table agnostic `getproto` function. +- Add a number of functions related to structs. +- Add prototypes to structs. Structs can now inherit from other structs, just like tables. +- Create a struct with a prototype with `struct/with-proto`. - Deadlocked channels will no longer exit early - instead they will hang, which is more intuitive. ## 1.18.1 - 2021-10-16 diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 25da7ad8..bd70e710 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -2590,7 +2590,7 @@ @{}) (defn dofile - `Evaluate a file and return the resulting environment. :env, :expander, + `Evaluate a file, file path, or stream and return the resulting environment. :env, :expander, :evaluator, :read, and :parser are passed through to the underlying run-context call. If exit is true, any top level errors will trigger a call to (os/exit 1) after printing the error.` @@ -2602,8 +2602,9 @@ :evaluator evaluator :read read :parser parser}] - (def f (if (= (type path) :core/file) - path + (def f (case (type path) + :core/file path + :core/stream path (file/open path :rb))) (def path-is-file (= f path)) (default env (make-env)) @@ -2612,7 +2613,7 @@ (put env :source (or src (if-not path-is-file spath path))) (var exit-error nil) (var exit-fiber nil) - (defn chunks [buf _] (file/read f 4096 buf)) + (defn chunks [buf _] (:read f 4096 buf)) (defn bp [&opt x y] (when exit (bad-parse x y) @@ -2654,7 +2655,7 @@ :read read :parser parser :source (or src (if path-is-file "" spath))})) - (if-not path-is-file (file/close f)) + (if-not path-is-file (:close f)) (when exit-error (if exit-fiber (propagate exit-error exit-fiber) diff --git a/test/suite0010.janet b/test/suite0010.janet index 8ba64f1c..84913d51 100644 --- a/test/suite0010.janet +++ b/test/suite0010.janet @@ -192,4 +192,11 @@ (assert (= (math/gcd 462 1071) 21) "math/gcd 1") (assert (= (math/lcm 462 1071) 23562) "math/lcm 1") +# Evaluate stream with `dofile` +(def [r w] (os/pipe)) +(:write w "(setdyn :x 10)") +(:close w) +(def stream-env (dofile r)) +(assert (= (stream-env :x) 10) "dofile stream 1") + (end-suite)