Skip to content

Instantly share code, notes, and snippets.

@jackfirth
Created September 1, 2019 01:26
Show Gist options
  • Save jackfirth/260173a7f7af6cabcdeb960bd8e44483 to your computer and use it in GitHub Desktop.
Save jackfirth/260173a7f7af6cabcdeb960bd8e44483 to your computer and use it in GitHub Desktop.
#lang racket
(require racket/stxparam
syntax/parse/define)
(define mode #f)
(define lens-view #f)
(define lens-set #f)
(define Processor-A-Lens #f)
(define Processor-C-Lens #f)
(define-syntax-parameter the-processor #f)
(begin-for-syntax
(define (raise-undefined-location-alias-error id stx)
(raise-syntax-error (syntax-e id) "undefined" stx)))
(define-simple-macro
(define-location-alias id:id (~optional (~seq #:default lens:id)))
(~?
(define-syntax-parameter id (λ (_) #'(lens-view lens the-processor)))
(define-syntax-parameter id
(λ (stx) (raise-undefined-location-alias-error #'id stx)))))
(define-simple-macro (let-location-alias ([id:id lens:id] ...) body ...)
(syntax-parameterize ([id (λ (_) #'(lens-view lens the-processor))] ...)
body ...))
(define-location-alias A #:default Processor-A-Lens)
(define-location-alias M)
(define-location-alias X)
(define-location-alias Y)
(define-location-alias C #:default Processor-C-Lens)
(define-location-alias Z)
(define-location-alias I)
(define-location-alias D)
(define-location-alias B)
(define-location-alias V)
(define-location-alias N)
(define-simple-macro (:= dst src)
(λ (processor)
(define local-M (mode processor))
(let-location-alias
([M local-M])
(syntax-parameterize
([the-processor (make-rename-transformer #'processor)])
(lens-set dst processor src)))))
(:= A (+ A M C))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment