|
326 | 326 | ;; --------------------------------------------------------------------------------------------------- |
327 | 327 |
|
328 | 328 | (begin-for-syntax |
| 329 | + ; Instances of this struct are created by `:` when declaring the types of bindings |
| 330 | + ; seperately from their definitions. When a binding is defined (with `def` or related |
| 331 | + ; forms), it searches for a `binding-declaration` and fills in `internal-id` with the |
| 332 | + ; actual definition. The `type` field is used as the expected type of the definition. |
329 | 333 | ; fixity : [Maybe Fixity] |
330 | | - (struct val-decl [internal-id |
331 | | - type |
332 | | - type-unexpanded |
333 | | - exact? |
334 | | - fixity] |
| 334 | + (struct binding-declaration [internal-id type delta-syntax residual fixity] |
335 | 335 | #:property prop:procedure |
336 | 336 | (λ (this stx) |
337 | | - (match-define (val-decl x- type _ _ _) this) |
| 337 | + (match-define (binding-declaration x- type _ _ _) this) |
338 | 338 | ((make-typed-var-transformer x- type) stx)) |
339 | 339 | #:property prop:infix-operator |
340 | | - (λ (this) (val-decl-fixity this))) |
341 | | - |
342 | | - (define-syntax-class id/val-decl |
343 | | - #:attributes [internal-id |
344 | | - type-unexpanded |
345 | | - exact? |
346 | | - fixity] |
347 | | - [pattern (~var x (local-value val-decl?)) |
348 | | - #:do [(match-define (val-decl x-* _ type* exact?* fixity*) |
| 340 | + (λ (this) (binding-declaration-fixity this))) |
| 341 | + |
| 342 | + (define-syntax-class id/binding-declaration |
| 343 | + #:attributes [internal-id type scoped-binding-introducer residual fixity] |
| 344 | + [pattern (~var x (local-value binding-declaration?)) |
| 345 | + #:do [(match-define (binding-declaration x-* type* delta* resid* fixity*) |
349 | 346 | (attribute x.local-value))] |
350 | | - #:attr internal-id (syntax-local-introduce x-*) |
351 | | - #:with type-unexpanded (syntax-local-introduce type*) |
352 | | - #:attr exact? exact?* |
353 | | - #:attr fixity fixity*])) |
| 347 | + #:attr internal-id (syntax-local-introduce x-*) |
| 348 | + #:with type (syntax-local-introduce type*) |
| 349 | + #:attr scoped-binding-introducer (make-syntax-delta-introducer delta* #'_) |
| 350 | + #:with residual (syntax-local-introduce resid*) |
| 351 | + #:attr fixity fixity*])) |
| 352 | + |
| 353 | +(define-syntax-parser define/binding-declaration |
| 354 | + [(_ x:id/binding-declaration rhs) |
| 355 | + #:with x- #'x.internal-id |
| 356 | + #'(define- x- rhs)]) |
354 | 357 |
|
355 | 358 | ;; --------------------------------------------------------------------------------------------------- |
356 | 359 |
|
|
412 | 415 | #:with t_reduced (if (attribute exact?) |
413 | 416 | #'t.expansion |
414 | 417 | (type-reduce-context #'t.expansion)) |
415 | | - #'(define-syntax x |
416 | | - (val-decl (quote-syntax x-) |
417 | | - (quote-syntax t_reduced) |
418 | | - (quote-syntax t_unexpanded) |
419 | | - 'exct? |
420 | | - 'fixity))])]))) |
| 418 | + #:with delta (syntax-local-introduce |
| 419 | + ((attribute t.scoped-binding-introducer) #'_)) |
| 420 | + #`(define-syntax x |
| 421 | + (binding-declaration |
| 422 | + (quote-syntax x-) |
| 423 | + (quote-syntax t_reduced) |
| 424 | + (quote-syntax delta) |
| 425 | + (quote-syntax t.residual) |
| 426 | + 'fixity))])]))) |
421 | 427 |
|
422 | 428 | (define-syntax-parser λ1 |
423 | 429 | [(_ x:id e:expr) |
|
444 | 450 |
|
445 | 451 | (define-syntax-parser def |
446 | 452 | #:literals [:] |
447 | | - [(_ x:id/val-decl e:expr) |
| 453 | + [(_ x:id/binding-declaration e:expr) |
448 | 454 | #:with x- #'x.internal-id |
449 | | - #:with {~type t:type} #'x.type-unexpanded |
450 | | - #:with t_reduced (if (attribute x.exact?) |
451 | | - #'t.expansion |
452 | | - (type-reduce-context #'t.expansion)) |
453 | 455 | (syntax-property |
454 | 456 | #`(define- x- |
455 | | - (let-values ([() t.residual]) |
| 457 | + (let-values ([() x.residual]) |
456 | 458 | (#%expression |
457 | | - (: #,((attribute t.scoped-binding-introducer) |
| 459 | + (: #,((attribute x.scoped-binding-introducer) |
458 | 460 | #'e) |
459 | | - t_reduced |
| 461 | + x.type |
460 | 462 | #:exact)))) |
461 | 463 | 'disappeared-use |
462 | 464 | (syntax-local-introduce #'x))] |
|
482 | 484 | #:with id-/gen (attach-type id- #'t_gen) |
483 | 485 | #`(begin- |
484 | 486 | (: id t_gen fixity-stuff ... #:exact) |
485 | | - (define/val-decl id |
| 487 | + (define/binding-declaration id |
486 | 488 | (let-syntax ([id-/gen |
487 | 489 | (make-rename-transformer (quote-syntax id))]) |
488 | 490 | #,e-)))]) |
489 | 491 |
|
490 | | -(define-syntax-parser define/val-decl |
491 | | - [(_ x:id/val-decl rhs) |
492 | | - #:with x- #'x.internal-id |
493 | | - #'(define- x- rhs)]) |
494 | | - |
495 | 492 |
|
496 | 493 | (begin-for-syntax |
497 | 494 | (struct todo-item (full summary) #:prefab)) |
|
0 commit comments