From 066d89d9934e8c2b2fea2aa03ce5492b2fc5195e Mon Sep 17 00:00:00 2001 From: Ben Greenman Date: Mon, 6 Jun 2016 17:38:01 -0400 Subject: [PATCH] ** add/expose parameter for logging 'hits' --- trivial/parameters.rkt | 7 ++++++ trivial/private/common.rkt | 41 +++++++++++++++++++++------------- trivial/private/parameters.rkt | 11 +++++++++ 3 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 trivial/parameters.rkt create mode 100644 trivial/private/parameters.rkt diff --git a/trivial/parameters.rkt b/trivial/parameters.rkt new file mode 100644 index 0000000..e4165e9 --- /dev/null +++ b/trivial/parameters.rkt @@ -0,0 +1,7 @@ +#lang typed/racket/base + +(provide + (all-from-out trivial/private/parameters)) + +(require + trivial/private/parameters) diff --git a/trivial/private/common.rkt b/trivial/private/common.rkt index 908df34..8a7427c 100644 --- a/trivial/private/common.rkt +++ b/trivial/private/common.rkt @@ -27,6 +27,7 @@ ) (require + trivial/private/parameters racket/syntax syntax/parse syntax/id-table @@ -121,21 +122,31 @@ f-let)) (define ((make-alias id-stx parser) stx) - (or (parser stx) - (syntax-parse stx - [_:id - id-stx] - [(_ e* ...) - #:with app-stx (format-id stx "#%app") - #`(app-stx #,id-stx e* ...)]))) + (cond + [(parser stx) + => (lambda (r) + (when (*TRIVIAL-LOG*) (printf "[LOG] alias ~a\n" (syntax->datum id-stx))) + r)] + [else + (syntax-parse stx + [_:id + id-stx] + [(_ e* ...) + #:with app-stx (format-id stx "#%app") + #`(app-stx #,id-stx e* ...)])])) (define ((make-keyword-alias id-sym parser) stx) - (or (parser stx) + (cond + [(parser stx) + => (lambda (r) + (when (*TRIVIAL-LOG*) (printf "[LOG] keyword ~a\n" id-sym)) + r)] + [else (syntax-parse stx - [(_ e* ...) - #:with id-stx (case id-sym - [(define) #'tr:define] - [(let) #'tr:let] - [(set!) #'tr:set!] - [else (error 'trivial "Unknown keyword '~a'" id-sym)]) - (syntax/loc stx (id-stx e* ...))]))) + [(_ e* ...) + #:with id-stx (case id-sym + [(define) #'tr:define] + [(let) #'tr:let] + [(set!) #'tr:set!] + [else (error 'trivial "Unknown keyword '~a'" id-sym)]) + (syntax/loc stx (id-stx e* ...))])])) diff --git a/trivial/private/parameters.rkt b/trivial/private/parameters.rkt new file mode 100644 index 0000000..4ce496c --- /dev/null +++ b/trivial/private/parameters.rkt @@ -0,0 +1,11 @@ +#lang typed/racket/base + +(provide + *TRIVIAL-LOG* +) + +;; ============================================================================= + +(: *TRIVIAL-LOG* (Parameterof Boolean)) +(define *TRIVIAL-LOG* (make-parameter #f)) +