commit 9973e1c705fc71cd57044ed978a2bb6917f68e37
parent 8d6eaf227e55331afea6823dd36e0e4a0fa9f9a8
Author: Stephen Chang <stchang@ccs.neu.edu>
Date: Wed, 29 Jul 2015 14:27:24 -0400
start require "extends" macro in typecheck.rkt
Diffstat:
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/tapl/typecheck.rkt b/tapl/typecheck.rkt
@@ -1,7 +1,10 @@
#lang racket/base
(require
- (for-syntax racket syntax/parse racket/syntax syntax/stx "stx-utils.rkt")
- (for-meta 2 racket/base syntax/parse))
+ (for-syntax (except-in racket extends)
+ syntax/parse racket/syntax syntax/stx
+ "stx-utils.rkt")
+ (for-meta 2 racket/base syntax/parse)
+ racket/provide)
(provide
(for-syntax (all-defined-out)) (all-defined-out)
(for-syntax
@@ -25,6 +28,30 @@
(struct exn:fail:type:runtime exn:fail:user ())
+;; need options for
+;; - pass through
+;; - use (generated) prefix to avoid conflicts
+;; - exceptions - dont pass through
+;; - either because id from another lang, or extending
+;; - use in impl
+;; - either as is
+;; - or prefixed
+(define-syntax extends
+ (syntax-parser
+ [(_ base-lang
+ (~optional (~seq #:use (x ...)) #:defaults ([(x 1) null])))
+ #:with pre (generate-temporary)
+ #:with pre: (format-id #'pre "~a:" #'pre)
+ #'(begin
+ (require (prefix-in pre: base-lang))
+ (require (only-in base-lang x ...))
+ (provide (filtered-out
+ (let ([pre-pat (regexp (format "^~a" (syntax->datum #'pre:)))])
+ (λ (name)
+ (and (regexp-match? pre-pat name)
+ (regexp-replace pre-pat name ""))))
+ (all-from-out base-lang))))]))
+
;; when combining #%type's with #%plain-type's, eg when inferring type for λ
;; (call this mixed type) we create a type that still needs expansion, ie eval
;; With the #%type and #%plain-type distinction, mixed types can be evaled