home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mitsch75.zip / scheme-7_5_17-src.zip / scheme-7.5.17 / src / compiler / back / asmmac.scm next >
Encoding:
Text File  |  1999-01-02  |  2.9 KB  |  93 lines

  1. #| -*-Scheme-*-
  2.  
  3. $Id: asmmac.scm,v 1.8 1999/01/02 06:06:43 cph Exp $
  4.  
  5. Copyright (c) 1988, 1990, 1999 Massachusetts Institute of Technology
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful, but
  13. WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. |#
  21.  
  22. ;;;; Assembler Syntax Macros
  23.  
  24. (declare (usual-integrations))
  25.  
  26. (syntax-table-define assembler-syntax-table 'DEFINE-INSTRUCTION
  27.   (macro (keyword . rules)
  28.     `(ADD-INSTRUCTION!
  29.       ',keyword
  30.       ,(compile-database rules
  31.      (lambda (pattern actions)
  32.        pattern
  33.        (if (null? actions)
  34.            (error "DEFINE-INSTRUCTION: Too few forms")
  35.            (parse-instruction (car actions) (cdr actions) false)))))))
  36.  
  37. (define (compile-database cases procedure)
  38.   `(LIST
  39.     ,@(map (lambda (rule)
  40.          (parse-rule (car rule) (cdr rule)
  41.            (lambda (pattern variables qualifier actions)
  42.          `(CONS ',pattern
  43.             ,(rule-result-expression variables
  44.                          qualifier
  45.                          (procedure pattern
  46.                                 actions))))))
  47.        cases)))
  48.  
  49. (define optimize-group-syntax
  50.   (let ()
  51.     (define (find-constant components)
  52.       (cond ((null? components)
  53.          '())
  54.         ((car-constant? components)
  55.          (compact (car-constant-value components)
  56.               (cdr components)))
  57.         (else
  58.          (cons (car components)
  59.            (find-constant (cdr components))))))
  60.  
  61.     (define (compact bit-string components)
  62.       (cond ((null? components)
  63.          (cons (make-constant bit-string) '()))
  64.         ((car-constant? components)
  65.          (compact (instruction-append bit-string
  66.                       (car-constant-value components))
  67.               (cdr components)))
  68.         (else
  69.          (cons (make-constant bit-string)
  70.            (cons (car components)
  71.              (find-constant (cdr components)))))))
  72.  
  73.     (define-integrable (car-constant? expression)
  74.       (and (eq? (caar expression) 'QUOTE)
  75.        (bit-string? (cadar expression))))
  76.  
  77.     (define-integrable (car-constant-value constant)
  78.       (cadar constant))
  79.  
  80.     (define-integrable (make-constant bit-string)
  81.       `',bit-string)
  82.  
  83.     (lambda (components early?)
  84.       (let ((components (find-constant components)))
  85.     (cond ((null? components)
  86.            (error "OPTIMIZE-GROUP-SYNTAX: No components in group!"))
  87.           ((null? (cdr components))
  88.            (car components))
  89.           (else
  90.            `(,(if early?
  91.               'OPTIMIZE-GROUP-EARLY
  92.               'OPTIMIZE-GROUP)
  93.          ,@components)))))))