From 3190ee2f60df2296295c97f6503bbd7fb32b1db2 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Fri, 12 Aug 2011 14:57:53 -0400 Subject: [PATCH] giving up with being able to define resources in expression position, and going back to define-resource --- examples/using-resources.rkt | 8 +++++++- lang/kernel.rkt | 16 ++------------- resource/compile-time.rkt | 39 +++++++++++++++++------------------- 3 files changed, 27 insertions(+), 36 deletions(-) diff --git a/examples/using-resources.rkt b/examples/using-resources.rkt index cd9d44b..3c987f6 100644 --- a/examples/using-resources.rkt +++ b/examples/using-resources.rkt @@ -1,4 +1,10 @@ #lang planet dyoo/whalesong (require (planet dyoo/whalesong/resource)) -(file-resource "images/humpback.jpg") \ No newline at end of file +(define-resource whale-resource "images/humpback.jpg") + +#;(define whale-image + (image-url + (resource->url whale-resource))) + +#;whale-image diff --git a/lang/kernel.rkt b/lang/kernel.rkt index 30df770..47482a4 100644 --- a/lang/kernel.rkt +++ b/lang/kernel.rkt @@ -61,7 +61,7 @@ e null #%plain-module-begin - (rename-out [my-module-begin #%module-begin]) + #%module-begin #%datum #%app #%top-interaction @@ -98,6 +98,7 @@ unless require for-syntax + for-template define-for-syntax begin-for-syntax prefix-in @@ -438,17 +439,4 @@ symbol->string - - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - - -(define-syntax (my-module-begin stx) - (syntax-case stx () - [(_ body ...) - (with-syntax ([(expanded-body ...) - (local-expand #'(body ...) - 'module-begin - #f)]) - (syntax/loc stx - (#%module-begin expanded-body ...)))])) \ No newline at end of file diff --git a/resource/compile-time.rkt b/resource/compile-time.rkt index fe3c414..42e7528 100644 --- a/resource/compile-time.rkt +++ b/resource/compile-time.rkt @@ -1,29 +1,26 @@ #lang s-exp "../lang/kernel.rkt" - -(provide file-resource) - +;; Macros for recording the definition of resources in a program. +(require (for-syntax racket/base + racket/path + syntax/parse)) + +(provide define-resource) (require "structs.rkt") -;; Macros for recording the definition of resources in a program. -(require (for-syntax racket/base)) - ;; file-resource: ;; -(define-syntax (file-resource stx) - (syntax-case stx () - [(_ path) - (let ([dontcare - (syntax-local-lift-expression #'(begin - (begin-for-syntax - (printf "Compile time code executing")) - (void)))]) +(define-syntax (define-resource stx) + (syntax-parse stx + [(_ name:id path:str) + (with-syntax ([normal-path + (normalize-path (build-path + (or (current-load-relative-directory) + (current-directory)) + (syntax-e #'path)))]) (syntax/loc stx - (let-syntax ([compile-time-code - (lambda (stx) - (printf "compile time code executing\n") - #'(void))]) - (begin - ;;dontcare - (resource path)))))])) + (begin (begin-for-syntax + (printf "compile time code executing; we need to save ~s\n" + normal-path)) + (define name (resource path)))))]))