1 ;;; Tree-il canonicalizer
3 ;; Copyright (C) 2011, 2012, 2013 Free Software Foundation, Inc.
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.
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.
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 02110-1301 USA
21 (define-module (language tree-il canonicalize)
22 #:use-module (language tree-il)
23 #:use-module (ice-9 match)
24 #:use-module (srfi srfi-1)
25 #:export (canonicalize))
27 (define (tree-il-any proc exp)
28 (tree-il-fold (lambda (exp res)
30 (lambda (exp res) res)
33 (define (canonicalize x)
37 (($ <let> src () () () body)
39 (($ <letrec> src _ () () () body)
41 (($ <fix> src () () () body)
43 (($ <lambda> src meta #f)
44 ;; Give a body to case-lambda with no clauses.
48 #f '() #f #f #f '() '()
52 (list (make-const #f 'wrong-number-of-args)
54 (make-const #f "Wrong number of arguments")
58 (($ <prompt> src escape-only? tag body handler)
59 ;; The prompt handler should be a simple lambda, so that we
63 ($ <lambda-case> _ req #f rest #f () syms body #f))
66 (let ((handler-sym (gensym))
69 #f (list 'handler) (list handler-sym) (list handler)
71 src escape-only? tag body
75 #f '() #f 'args #f '() (list args-sym)
78 (list (make-lexical-ref #f 'handler handler-sym)
79 (make-lexical-ref #f 'args args-sym)))