Subject: bug#78831: [PATCH 1/2] language/bf: rewire compiling to scheme

From: Paul Bolle <[email-masked]>
Date: Wed, 18 Jun 2025 21:30:23 +0200

Trying to compile bf to scheme fails with an impressive backtrace:

"In ice-9/boot-9.scm:
  1752:10 13 (with-exception-handler _ _ #:unwind? _ # _)
In unknown file:
          12 (apply-smob/0 #<thunk 7f2594f5d000>)
In ice-9/boot-9.scm:
    724:2 11 (call-with-prompt _ _ #<procedure default-prompt-handle…>)
In ice-9/eval.scm:
    619:8 10 (_ #(#(#<directory (guile-user) 7f2594f12c80>)))
In ice-9/boot-9.scm:
   2836:4  9 (save-module-excursion _)
  4388:12  8 (_)
In /home/[...]/bf2scheme.scm:
     2:15  7 (_)
In system/base/compile.scm:
   307:16  6 (read-and-compile #<input: string 7f25a2ef57e0> #:from _ …)
   278:13  5 (lp _)
   278:13  4 (lp _)
   278:13  3 (lp _)
   278:13  2 (lp _)
    275:6  1 (lp _)
   244:17  0 (next-pass _ _ _ _ _)

system/base/compile.scm:244:17: In procedure next-pass:
no way to compile #<<language> name: brainfuck title: "Brainfuck" reader: #<procedure 7f2592825650 at language/brainfuck/spec.scm:42:16 (port env)> printer: #<procedure write (_ #:optional _)> parser: #f compilers: ((tree-il . #<procedure compile-tree-il (exp env opts)>) (scheme . #<procedure compile-scheme (exp env opts)>)) decompilers: () evaluator: #f joiner: #f for-humans?: #t make-default-environment: #<procedure make-fresh-user-module ()> lowerer: #f analyzer: #f compiler-chooser: #<procedure choose-compiler (compilers optimization-level opts)>> "to" #<<language> name: scheme title: "Scheme" reader: #<procedure 7f2592780650 at language/scheme/spec.scm:34:16 (port env)> printer: #<procedure write (_ #:optional _)> parser: #f compilers: ((tree-il . #<procedure compile-tree-il (x e opts)>)) decompilers: ((tree-il . #<procedure decompile-tree-il (e env opts)>)) evaluator: #<procedure 7f2592780660 at language/scheme/spec.scm:45:16 (x module)> joiner: #f for-humans?: #t make-default-environment: #<procedure 7f2592780670 at language/scheme/spec.scm:48:16 ()> lowerer: #f analyzer: #f compiler-chooser: #f>"

It turns out the compiler for bf is hardwired to compile-tree-il. Make
it possible to choose compile-scheme too.
---
 module/language/brainfuck/spec.scm | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/module/language/brainfuck/spec.scm b/module/language/brainfuck/spec.scm
index ca488b916..5827c95f4 100644
--- a/module/language/brainfuck/spec.scm
+++ b/module/language/brainfuck/spec.scm
@@ -35,7 +35,9 @@
 ; language.
 
 (define (choose-compiler compilers optimization-level opts)
-  (cons 'tree-il compile-tree-il))
+  (if (eq? (language-name compilers) 'scheme)
+    (cons 'scheme compile-scheme)
+    (cons 'tree-il compile-tree-il)))
 
 (define-language brainfuck
   #:title	"Brainfuck"
-- 
2.49.0