forth: JIT cooperation hooks (vm-eligible flag + call-count + forth-hot-words)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 11s

This commit is contained in:
2026-04-25 04:57:49 +00:00
parent 0d6d0bf439
commit 55f3024743
5 changed files with 56 additions and 4 deletions

View File

@@ -5,7 +5,39 @@
(define
forth-execute-word
(fn (state word) (let ((body (get word "body"))) (body state))))
(fn
(state word)
(dict-set! word "call-count" (+ 1 (or (get word "call-count") 0)))
(let ((body (get word "body"))) (body state))))
(define
forth-hot-words
(fn
(state threshold)
(forth-hot-walk
(keys (get state "dict"))
(get state "dict")
threshold
(list))))
(define
forth-hot-walk
(fn
(names dict threshold acc)
(if
(= (len names) 0)
acc
(let
((n (first names)))
(let
((w (get dict n)))
(let
((c (or (get w "call-count") 0)))
(forth-hot-walk
(rest names)
dict
threshold
(if (>= c threshold) (cons (list n c) acc) acc))))))))
(define
forth-interpret-token