From 721f280966baec6c56f6ddd1a6a31038b416e99d Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Thu, 16 May 2024 21:42:34 -0500 Subject: [PATCH 1/3] Add `with-env`. --- CHANGELOG.md | 1 + src/boot/boot.janet | 5 +++++ test/suite-boot.janet | 3 +++ 3 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6613d4c2..98204705 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ All notable changes to this project will be documented in this file. ## Unreleased - ??? +- Add `with-env` - Add *module-make-env* dynamic binding - Add buffer/format-at - Add long form command line options for readable CLI usage diff --git a/src/boot/boot.janet b/src/boot/boot.janet index c465dfcb..71672fa1 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -1423,6 +1423,11 @@ ~(setdyn ,(bindings i) ,(bindings (+ i 1))))) ~(,resume (,fiber/new (fn [] ,;dyn-forms ,;body) :p))) +(defmacro with-env + `Run a block of code with a given environment table` + [env & body] + ~(,resume (,fiber/new (fn [] ,;body) : ,env))) + (defmacro with-vars ``Evaluates `body` with each var in `vars` temporarily bound. Similar signature to `let`, but each binding must be a var.`` diff --git a/test/suite-boot.janet b/test/suite-boot.janet index 89fb0076..b412c52d 100644 --- a/test/suite-boot.janet +++ b/test/suite-boot.janet @@ -976,4 +976,7 @@ (assert (= () '() (macex '())) "macex ()") (assert (= '[] (macex '[])) "macex []") +(assert (= :a (with-env @{:b :a} (dyn :b))) "with-env dyn") +(assert-error "unknown symbol +" (with-env @{} (eval '(+ 1 2)))) + (end-suite) From c1647a74c5a6055fd901c771a929ad0c8308f370 Mon Sep 17 00:00:00 2001 From: znley Date: Sat, 18 May 2024 07:18:59 +0000 Subject: [PATCH 2/3] Add LoongArch64 support --- src/include/janet.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/include/janet.h b/src/include/janet.h index 195c1c47..49430e55 100644 --- a/src/include/janet.h +++ b/src/include/janet.h @@ -112,7 +112,8 @@ extern "C" { || defined(__s390x__) /* S390 64-bit (BE) */ \ || (defined(__ppc64__) || defined(__PPC64__)) \ || defined(__aarch64__) /* ARM 64-bit */ \ - || (defined(__riscv) && (__riscv_xlen == 64)) /* RISC-V 64-bit */ + || (defined(__riscv) && (__riscv_xlen == 64)) /* RISC-V 64-bit */ \ + || defined(__loongarch64) /* LoongArch64 64-bit */ #define JANET_64 1 #else #define JANET_32 1 From ace60e18989632abd37c054239bd9b507630770b Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sat, 18 May 2024 17:55:47 -0500 Subject: [PATCH 3/3] Add ev/with-*lock macros. --- CHANGELOG.md | 1 + src/boot/boot.janet | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98204705..7e43aee4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ All notable changes to this project will be documented in this file. ## Unreleased - ??? +- Add macros `ev/with-lock`, `ev/with-rlock`, and `ev/with-wlock` for using mutexes and rwlocks. - Add `with-env` - Add *module-make-env* dynamic binding - Add buffer/format-at diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 71672fa1..a8c02ce3 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -3748,6 +3748,30 @@ [& body] ~(,ev/thread (fn _do-thread [&] ,;body))) + (defn- acquire-release + [acq rel lock body] + (def l (gensym)) + ~(do + (def ,l ,lock) + (,acq ,l) + (defer (,rel ,l) + ,;body))) + + (defmacro ev/with-lock + ``Run a body of code after acquiring a lock. Will automatically release the lock when done.`` + [lock & body] + (acquire-release ev/acquire-lock ev/release-lock lock body)) + + (defmacro ev/with-rlock + ``Run a body of code after acquiring read access to an rwlock. Will automatically release the lock when done.`` + [lock & body] + (acquire-release ev/acquire-rlock ev/release-rlock lock body)) + + (defmacro ev/with-wlock + ``Run a body of code after acquiring read access to an rwlock. Will automatically release the lock when done.`` + [lock & body] + (acquire-release ev/acquire-wlock ev/release-wlock lock body)) + (defmacro ev/spawn-thread ``Run some code in a new thread. Like `ev/do-thread`, but returns nil immediately.`` [& body]