prolog: cross-validate compiler vs interpreter (+17)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-25 18:32:36 +00:00
parent 8fd55d6aa0
commit 1819156d1e
3 changed files with 106 additions and 0 deletions

View File

@@ -155,3 +155,22 @@
(keys src-table))
(dict-set! db :compiled compiled-table)
db)))
;; Cross-validate: load src into both a plain and a compiled DB,
;; run goal-str through each, return true iff solution counts match.
;; Use this to keep the interpreter as the reference implementation.
(define
pl-compiled-matches-interp?
(fn
(src goal-str)
(let
((db-interp (pl-mk-db)) (db-comp (pl-mk-db)))
(pl-db-load! db-interp (pl-parse src))
(pl-db-load! db-comp (pl-parse src))
(pl-compile-db! db-comp)
(let
((gi (pl-instantiate (pl-parse-goal goal-str) {}))
(gc (pl-instantiate (pl-parse-goal goal-str) {})))
(=
(pl-solve-count! db-interp gi (pl-mk-trail))
(pl-solve-count! db-comp gc (pl-mk-trail)))))))