;;; -*-Scheme-*-
;;;
-;;; $Id: matcher.scm,v 1.23 2001/11/14 18:15:16 cph Exp $
+;;; $Id: matcher.scm,v 1.24 2001/11/14 20:18:35 cph Exp $
;;;
;;; Copyright (c) 2001 Massachusetts Institute of Technology
;;;
,(delay-call ks kf)))
(define-matcher (with-pointer identifier expression)
- pointer
- ;; Ignore the POINTER context. This is a kludge that prevents the
- ;; binding of IDENTIFIER from being discarded by the optimizer.
`((LAMBDA (,identifier)
- ,(compile-matcher-expression expression identifier ks kf))
- ,(fetch-pointer)))
+ ,(compile-matcher-expression expression (or pointer identifier) ks kf))
+ ,(or pointer (fetch-pointer))))
\f
(define-matcher (seq . expressions)
(if (pair? expressions)
;;; -*-Scheme-*-
;;;
-;;; $Id: parser.scm,v 1.26 2001/11/14 18:15:31 cph Exp $
+;;; $Id: parser.scm,v 1.27 2001/11/14 20:19:13 cph Exp $
;;;
;;; Copyright (c) 2001 Massachusetts Institute of Technology
;;;
(procedure ks v kf)))))
(define-parser (with-pointer identifier expression)
- pointer
- ;; Ignore the POINTER context. This is a kludge that prevents the
- ;; binding of IDENTIFIER from being discarded by the optimizer.
`((LAMBDA (,identifier)
- ,(compile-parser-expression expression identifier ks kf))
- ,(fetch-pointer)))
+ ,(compile-parser-expression expression (or pointer identifier) ks kf))
+ ,(or pointer (fetch-pointer))))
(define-parser (discard-matched)
pointer
;;; -*-Scheme-*-
;;;
-;;; $Id: shared.scm,v 1.18 2001/11/14 18:27:17 cph Exp $
+;;; $Id: shared.scm,v 1.19 2001/11/14 20:16:45 cph Exp $
;;;
;;; Copyright (c) 2001 Massachusetts Institute of Technology
;;;
(make-delayed-lambda make-ks-identifier
(list make-value-identifier make-kf-identifier)
generator))
-
+\f
(define (make-kf-identifier)
(generate-identifier 'KF))
(define (generate-identifier prefix)
(string->uninterned-symbol
(string-append
+ internal-identifier-prefix
(symbol-name prefix)
(number->string
(let ((entry (assq prefix *id-counters*)))
n)
(begin
(set! *id-counters* (cons (cons prefix 2) *id-counters*))
- 1)))))))
+ 1))))
+ internal-identifier-suffix)))
+
+(define (internal-identifier? identifier)
+ (let ((string (symbol-name identifier)))
+ (and (string-prefix? internal-identifier-prefix string)
+ (string-suffix? internal-identifier-suffix string))))
+
+(define internal-identifier-prefix "#[")
+(define internal-identifier-suffix "]")
(define *id-counters*)
\f
(operand (car operands))
(count (car counts)))
(cond ((and (= 0 count)
+ (internal-identifier? identifier)
(operand-discardable? operand))
(loop (cdr identifiers)
(cdr operands)
(define (operand-discardable? operand)
;; Returns true iff OPERAND can be removed from the program,
- ;; provided that its value is unused. Basically this tests for the
- ;; potential presence of side effects in OPERAND.
+ ;; provided that its value is unused.
(not (expression-may-have-side-effects? operand)))
(define (expression-may-have-side-effects? expression)
((eq? (car expression) 'LAMBDA)
(let ((parameters (cadr expression)))
`(LAMBDA ,parameters
- ,(optimize-pointer-usage (caddr expression)
- (if (memq pointer parameters)
- #f
- pointer)))))
+ ,(optimize-pointer-usage (caddr expression) #f))))
((eq? (car expression) 'LET)
(let ((name (cadr expression))
(bindings
expression)
(let ((operator (car expression))
(operand (cadr expression)))
- (let ((parameter (car (cadr operator))))
- (let ((body (optimize-pointer-usage (caddr operator) parameter)))
- (if (> (car (count-references (list parameter) body)) 0)
- `((LAMBDA (,parameter) ,body) ,operand)
- body)))))
+ (let ((identifier (car (cadr operator))))
+ (let ((body (optimize-pointer-usage (caddr operator) identifier)))
+ (if (and (internal-identifier? identifier)
+ (= (car (count-references (list identifier) body)) 0))
+ body
+ `((LAMBDA (,identifier) ,body) ,operand))))))
+ ((syntax-match? '(('LAMBDA (* IDENTIFIER) EXPRESSION)
+ . (* EXPRESSION))
+ expression)
+ (let ((operator (car expression))
+ (operands (cdr expression)))
+ (let ((parameters (cadr operator)))
+ `((LAMBDA ,parameters
+ ,(optimize-pointer-usage (caddr operator)
+ (if (memq pointer parameters)
+ #f
+ pointer)))
+ ,@operands))))
((syntax-match?
'('BEGIN
('SET-PARSER-BUFFER-POINTER! EXPRESSION IDENTIFIER)