bfソースをlisp(sbcl)にトランスパイルする。
LGBTの発展形として、bfで書かれたソースををCommon Lisp系であるsbclに変換し、実行させることに成功しました。
マップファイル
map.lisp.json
{
">": " (incf ptr)",
"<": " (decf ptr)",
"+": " (setf (aref tape ptr) (mod (1+ (aref tape ptr)) 256))",
"-": " (setf (aref tape ptr) (mod (1- (aref tape ptr)) 256))",
".": " (write-char (code-char (aref tape ptr)))",
",": " (let ((c (read-char nil nil nil))) (setf (aref tape ptr) (if c (char-code c) 0)))",
"[": " (loop while (/= (aref tape ptr) 0) do",
"]": " )"
}
header file
header.lisp
;; header.lisp -- main とテープ初期化を定義
(defun main ()
(let ((tape (make-array 30000 :initial-element 0))
(ptr 0))
;; ここから Brainfuck 変換コードが挿入されます
tailor file
tailor.lisp
;; 変換コードの末尾に来る補助出力(必要なら)
(finish-output))) ; let の中と defun を閉じる
;; スクリプトとして実行されたとき main を呼ぶ
(main)
Transpilation and execution
lgbt.py map.lisp.json header.lisp hello.bf tailor.lisp >hello.lisp #
sbcl --script hello.lisp
Hello world!