Created
February 7, 2018 07:49
-
-
Save lenary/0b56fe4bde5aa509a3282499a4207c98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang rosette | |
(require rosette/lib/synthax | |
(only-in rosette/base/util/array reshape)) | |
(provide generate-symbolic define-synthax-rule | |
(all-from-out rosette/lib/synthax)) | |
;; Fundamental. If you want bitvectors, use the bv explicit types | |
(current-bitwidth #f) | |
;; Instead of (define (get-sym) (define-symbolic* x <type>) x) | |
;; Use (generate-symbolic <type>) | |
;; | |
;; also works with (generate-symbolic <type> [dim ...]) for multidimensional lists | |
;; just like define-symbolic. Yes that's a thing you can do. Undocumented of course. | |
;; | |
(define-syntax (generate-symbolic stx) | |
(syntax-case stx () | |
[(_ type) | |
(syntax/loc stx | |
(with-syntax ([(var) (generate-temporaries #'(gen))]) | |
(constant (list #'var ((current-oracle) #'var)) type)))] | |
[(_ type [ k ... ]) | |
(syntax/loc stx | |
(with-syntax ([(var) (generate-temporaries #'(gen))]) | |
(reshape (list k ...) (for/list ([i (in-range (* k ...))]) | |
(generate-symbolic type)))))])) | |
;; (define-synthax ...) has a confusing number of parens. | |
;; This allows you to not need nearly as many when your rule only has one pattern. | |
(define-syntax-rule (define-synthax-rule (id pats ...) expr) | |
(define-synthax id | |
([(_ pats ...) expr]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment