-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodegen.rkt
More file actions
32 lines (24 loc) · 881 Bytes
/
codegen.rkt
File metadata and controls
32 lines (24 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#lang rosette
(provide code-gen)
(define (type-string x)
(cond [(integer? x) "int"]
[(real? x) "float"]))
(define (print-variable x)
(format "~a ~a" (type-string (eval x)) (symbol->string x)))
(define (get-precond cond)
(match cond
[(list 'assert (list op x y)) (format "~a ~a ~a" x op y)]))
(define (get-match lhs)
(match lhs
[(list op x y) (format "match(~a.withop(~a,~a)" op x y)]))
(define (get-replace rhs)
(match rhs
[(list op x y) (format "replaceIns(~a,~a,~a)" op x y)]))
(define (code-gen rule)
(match rule
[(list 'define name asserts ... (list '= lhs rhs))
(define precond-string (for/list ([assert asserts])
(get-precond assert)))
(define match-string (get-match lhs))
(define replace-string (get-replace rhs))
(print (cons (cons precond-string match-string) replace-string))]))