;;;; cpp-macros.scm -*- Scheme -*- ;;;; Kon Lovett, Apr '20 (module cpp-macros (;export __date__ __time__ __line__ __file__) (import scheme (chicken base) (chicken syntax)) (import-for-syntax (only (chicken string) string-split)) (import-for-syntax (only (chicken time posix) seconds->local-time time->string)) ;;; Helpers (define-for-syntax (local-time->string #!optional (fmt "%c")) (time->string (seconds->local-time) fmt) ) (define-for-syntax (line-info-values e) (let ((v (get-line-number e))) (if (string? v) (apply values (string-split v ":" #t)) (values v #f) ) ) ) ;;; ;inspired by Kooda on #chicken irc Mar 7 23:39 (define-syntax __date__ (er-macro-transformer (lambda (e r c) (local-time->string "%F") ) ) ) (define-syntax __time__ (er-macro-transformer (lambda (e r c) (local-time->string "%T") ) ) ) (define-syntax __line__ (er-macro-transformer (lambda (e r c) (let-values (((f l) (line-info-values e))) (and l (string->number l)) ) ) ) ) (define-syntax __file__ (er-macro-transformer (lambda (e r c) (let-values (((f l) (line-info-values e))) f ) ) ) ) ) ;module cpp-macros