;;;; cpp-macros.scm -*- Scheme -*- ;;;; Kon Lovett, Apr '20 (module cpp-macros (;export __date__ __time__ __line__ __file__) (import scheme) (import (chicken base)) (import (chicken syntax)) ;;; Helpers (import-for-syntax (only (chicken string) string-split)) (import-for-syntax (only (chicken time posix) seconds->local-time time->string)) ;;; ;inspired by Kooda on #chicken irc Mar 7 23:39 (define-syntax __date__ (er-macro-transformer (lambda (e r c) (time->string (seconds->local-time) "%F") ) ) ) (define-syntax __time__ (er-macro-transformer (lambda (e r c) (time->string (seconds->local-time) "%T") ) ) ) (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) ) ) ) (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