From b6c679afa6b9446829b94b527fbb8de3042889dd Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sat, 16 Jul 2016 15:40:20 -0400 Subject: [PATCH] Support `module+` in Syndicate #langs. Closes #2. Adding `#'module+` explicitly to the stop-list for local-expand stops the infinite recursion (problem 1 in the issue description). The code goes on to treat it like `#'module` and `#'module+`, namely as a non-action-producing form. Problem 2 in the issue description is interesting. I haven't done anything in particular to address the production of unbounded `X` -> `(begin X)` expansions, but it seems not currently to be a problem; and, weirdly (?), submodules in a `#lang syndicate` or `#lang syndicate/actor` module do not seem to inherit the `#%module-begin` of their container! That is, `(module+ main)`, `(module+ test)` etc. all seem to have a `racket/base` `#%module-begin`, though I've not looked very far into this. Most peculiar on this front is that if the `#,@(reverse final-forms)` precedes the `(module+ syndicate-main ...)`, and the module being processed includes, say, a `(module+ main)`, then for some reason the resulting `main` submodule *is* treated as having a `syndicate/lang` `#%module-begin` (thus causing problems as suggested in the issue description)! I *really* don't understand why that might be, and haven't spent very much time investigating after I noticed that so long as the `main`-required `syndicate-main` submodule preceded all other submodule declarations, things seemed to work out. This whole approach is still a bit dicey: for example, the following will erroneously treat `(foo quux)` as an expression yielding actions, rather than a struct declaration: #lang syndicate (define-syntax-rule (foo x) (struct x ())) (foo quux) --- racket/syndicate/lang.rkt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/racket/syndicate/lang.rkt b/racket/syndicate/lang.rkt index d6451e2..d40f02d 100644 --- a/racket/syndicate/lang.rkt +++ b/racket/syndicate/lang.rkt @@ -39,8 +39,7 @@ (define (accumulate-actions action-ids final-forms forms) (if (null? forms) (let ((final-stx - #`(#%module-begin #,@(reverse final-forms) - (module+ syndicate-main + #`(#%module-begin (module+ syndicate-main (provide boot-actions activate!) (define activated? #f) (define boot-actions (list #,@(reverse action-ids))) @@ -48,6 +47,7 @@ (when (not activated?) (set! activated? #t) boot-actions))) + #,@(reverse final-forms) (module+ main (require (submod ".." syndicate-main)) (run-ground (activate!)))))) @@ -55,7 +55,7 @@ final-stx) (syntax-case (local-expand (car forms) 'module - (kernel-form-identifier-list)) () + (cons #'module+ (kernel-form-identifier-list))) () [(head rest ...) (if (free-identifier=? #'head #'begin) (accumulate-actions action-ids @@ -63,7 +63,7 @@ (append (syntax->list #'(rest ...)) (cdr forms))) (if (ormap (lambda (i) (free-identifier=? #'head i)) (syntax->list #'(define-values define-syntaxes begin-for-syntax - module module* + module module* module+ #%module-begin #%require #%provide))) (accumulate-actions action-ids