Skip to content

Instantly share code, notes, and snippets.

@aturon
Created May 7, 2012 20:08
Show Gist options
  • Save aturon/2630073 to your computer and use it in GitHub Desktop.
Save aturon/2630073 to your computer and use it in GitHub Desktop.
early reagent code generation
(define-reagent (push s x)
(read-match s
[xs (update-to! (cons x xs))]))
; --generates->
(define (push s x)
(let retry40 ()
(let ([b41 (atomic-ref-box s)]
[ov42 (unsafe-unbox* b41)])
(match
ov42
[xs
(let ([nv43 (cons x xs)])
(if (static-kcas! (b41 ov42 nv43)) #<void> (retry40))))))))
(define-reagent (pop s)
(read-match s
[(cons x xs) (update-to! xs) x]
[_ #f]))
; --generates->
(define (pop s)
(let retry44 ()
(let ([b45 (atomic-ref-box s)]
[ov46 (unsafe-unbox* b45)])
(match
ov46
[(cons x xs)
(let ([nv47 xs])
(let ([result48 x])
(if (static-kcas! (b45 ov46 nv47)) result48 (retry44))))]
[_
(let ((result49 #f))
(if (static-kcas! (b45 ov46 ov46)) result49 (retry44)))]))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment