;;; mat.ss ;;; Copyright 1984-2017 Cisco Systems, Inc. ;;; ;;; Licensed under the Apache License, Version 2.0 (the "License"); ;;; you may not use this file except in compliance with the License. ;;; You may obtain a copy of the License at ;;; ;;; http://www.apache.org/licenses/LICENSE-2.0 ;;; ;;; Unless required by applicable law or agreed to in writing, software ;;; distributed under the License is distributed on an "AS IS" BASIS, ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ;;; See the License for the specific language governing permissions and ;;; limitations under the License. ;(eval-when (compile load eval) (current-expand sc-expand)) (eval-when (compile) (optimize-level 2)) (eval-when (load eval) (define-syntax mat (lambda (x) (syntax-case x (parameters) [(_ x (parameters [param val ...] ...) e ...) #'(let f ([p* (list param ...)] [v** (list (list val ...) ...)]) (if (null? p*) (mat x e ...) (let ([p (car p*)]) (for-each (lambda (v) (parameterize ([p v]) (f (cdr p*) (cdr v**)))) (car v**)))))] [(_ x e ...) (with-syntax ([(source ...) (map (lambda (clause) (let ([a (syntax->annotation clause)]) (and (annotation? a) (annotation-source a)))) #'(e ...))]) #'(mat-run 'x '(e source) ...))])))) (define enable-cp0 (make-parameter #f)) (define-syntax mat/cf (syntax-rules (testfile) [(_ (testfile ?path) expr ...) (let* ([path ?path] [testfile.ss (format "~a.ss" path)] [testfile.so (format "~a.so" path)]) (with-output-to-file testfile.ss (lambda () (begin (write 'expr) (newline)) ...) 'replace) (parameterize ([generate-inspector-information #t]) (compile-file testfile.ss)) (load testfile.so) #t)] [(_ expr ...) (mat/cf (testfile "testfile") expr ...)])) (define mat-output (make-parameter (current-output-port))) (let () (define mat-load (lambda (in) (call/cc (lambda (k) (parameterize ([reset-handler (lambda () (k #f))] [current-expand (current-expand)] [run-cp0 (let ([default (run-cp0)]) (lambda (cp0 x) (if (enable-cp0) (default cp0 x) x)))]) (with-exception-handler (lambda (c) (if (warning? c) (raise-continuable c) (begin (fprintf (mat-output) "Error reading mat input: ") (display-condition c (mat-output)) (reset)))) (lambda () (load in)))))))) (define mat-one-exp (lambda (expect th sanitize-all?) (define (sanitize-condition c) (define sanitize (lambda (arg) (if sanitize-all? (cond [(port? arg) 'sanitized-port] [else 'sanitized-unhandled-type]) ; go one level only to avoid getting bit by cyclic structures (if (list? arg) (map sanitize1 arg) (sanitize1 arg))))) (define sanitize1 (lambda (arg) ; attempt to gloss over fixnum-size differences between ; 32- and 64-bit versions (cond [(ftype-pointer? arg) '] [(time? arg) '