Skip to content

Commit

Permalink
macros for emitting expansion events for the macro stepper
Browse files Browse the repository at this point in the history
(wip from yesterday's meeting)
  • Loading branch information
countvajhula committed Oct 14, 2023
1 parent 60a81e7 commit 31f34bb
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions qi-lib/flow/core/compiler.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@
[(_ [op f] rest ...) (op f (inline-compose1 rest ...))]))

(begin-for-syntax

;; currently does not distinguish substeps of a parent expansion step
(define-syntax-rule (qi-expansion-step name stx0 stx1)
(let ()
(emit-local-step stx0 stx1 #:id #'name)
stx1))

(define-syntax-rule (define-qi-expansion-step (name stx0)
body ...)
(define (name stx0)
(let ([stx1 (let () body ...)])
(qi-expansion-step name stx0 stx1))))

;; note: this does not return compiled code but instead,
;; syntax whose expansion compiles the code
(define (compile-flow stx)
Expand Down Expand Up @@ -96,10 +109,11 @@
list->cstream-next))
lst)))]))

(define (normalize-rewrite stx)
(define-qi-expansion-step (normalize-rewrite stx)
;; TODO: the "active" components of the expansions should be
;; optimized, i.e. they should be wrapped with a recursive
;; call to the optimizer
;; TODO: eliminate outdated rules here
(syntax-parse stx
;; restorative optimization for "all"
[((~datum thread) ((~datum amp) onex) (~datum AND))
Expand Down Expand Up @@ -274,16 +288,12 @@
(with-syntax ([(v ...) ids])
#`(let ([v undefined] ...) #,stx)))

(define (process-bindings stx)
(define-qi-expansion-step (process-bindings stx)
;; TODO: use syntax-parse and match ~> specifically.
;; Since macros are expanded "outside in," presumably
;; it will naturally wrap the outermost ~>
(let ([stx1 (wrap-with-scopes #`(qi0->racket #,(rewrite-all-bindings stx))
(bound-identifiers stx))])
(emit-local-step stx stx1 #:id #'process-bindings)
stx1))

)
(wrap-with-scopes #`(qi0->racket #,(rewrite-all-bindings stx))
(bound-identifiers stx))))

(define-syntax (qi0->racket stx)
;; this is a macro so it receives the entire expression
Expand Down

0 comments on commit 31f34bb

Please sign in to comment.