1;;; Brainfuck for GNU Guile.
2
3;; Copyright (C) 2009-2010,2020 Free Software Foundation, Inc.
4
5;; This library is free software; you can redistribute it and/or
6;; modify it under the terms of the GNU Lesser General Public
7;; License as published by the Free Software Foundation; either
8;; version 3 of the License, or (at your option) any later version.
9;;
10;; This library is distributed in the hope that it will be useful,
11;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13;; Lesser General Public License for more details.
14;;
15;; You should have received a copy of the GNU Lesser General Public
16;; License along with this library; if not, write to the Free Software
17;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18;; 02110-1301 USA
19
20;;; Code:
21
22(define-module (language brainfuck spec)
23  #:use-module (language brainfuck compile-tree-il)
24  #:use-module (language brainfuck compile-scheme)
25  #:use-module (language brainfuck parse)
26  #:use-module (system base language)
27  #:export (brainfuck))
28
29
30; The new language is integrated into Guile via this (define-language)
31; specification in the special module (language [lang] spec).
32; Provided is a parser-routine in #:reader, a output routine in #:printer
33; and one or more compiler routines (as target-language - routine pairs)
34; in #:compilers.  This is the basic set of fields needed to specify a new
35; language.
36
37(define (choose-compiler compilers optimization-level opts)
38  (cons 'tree-il compile-tree-il))
39
40(define-language brainfuck
41  #:title	"Brainfuck"
42  #:reader	(lambda (port env) (read-brainfuck port))
43  #:compilers	`((tree-il . ,compile-tree-il)
44                  (scheme . ,compile-scheme))
45  #:compiler-chooser choose-compiler
46  #:printer	write
47  )
48