Refactor VM evaluation to use macro

The `eval` and `eval_observed` methods in the `VM` struct were very
similar, with the primary difference being the call to the `VMObserver`
trait. This commit refactors these methods into a single macro,
`dispatch_eval!`, which reduces code duplication and improves
maintainability.

The `Value::TailCallRequest` variant was also updated to use `Box` for
its contents, which helps keep the `Value` enum size consistent.

Finally, the benchmarks in the `examples` directory have been updated to
reflect minor performance changes resulting from these code
modifications.
This commit is contained in:
Michael Schimmel
2026-02-18 02:01:27 +01:00
parent 9b16bc47be
commit 98deb8f3fe
7 changed files with 111 additions and 97 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
;; Closure Scope Test
;; Benchmark: 9.0us
;; Benchmark: 9.4us
;; Output: 15
(do
(def make-adder (fn [x]
+1 -1
View File
@@ -1,5 +1,5 @@
;; Complex Data Structure Test
;; Benchmark: 72.7us
;; Benchmark: 64.4us
;; Output: {:input 10, :name "Fibonacci", :output 55}
(do
(def fib (fn [n]
+1
View File
@@ -1,3 +1,4 @@
;; Benchmark: 25.9us
;; Output: 36
(do
;; Excessive capture test
+1 -1
View File
@@ -1,5 +1,5 @@
;; Fibonacci Recursive
;; Benchmark: 68.3us
;; Benchmark: 60.3us
;; Output: 55
(do
(def fib (fn [n]
+1 -1
View File
@@ -1,5 +1,5 @@
;; Higher-Order Function Example
;; Benchmark: 8.4us
;; Benchmark: 8.9us
;; Output: 25
(do
(def apply (fn [f x] (f x)))