Skip to content

Commit a7e9cfd

Browse files
committed
Change constant? to not include numbers
1 parent f71d9e5 commit a7e9cfd

File tree

11 files changed

+31
-21
lines changed

11 files changed

+31
-21
lines changed

src/core/localize.rkt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
(hash-ref! cache expr
1717
(λ ()
1818
(match expr
19+
[(? number?)
20+
(cons (repeat (bf expr)) (repeat 1))]
1921
[(? constant?)
20-
(define val
21-
(if (symbol? expr)
22-
((constant-info expr 'bf))
23-
(bf expr)))
22+
(define val ((constant-info expr 'bf)))
2423
(cons (repeat val) (repeat 1))]
2524
[(? variable?)
2625
(cons (map (curryr representation-repr->bf (dict-ref (*var-reprs*) expr))
@@ -82,6 +81,7 @@
8281
(unless (andmap (curry = 1) err)
8382
(sow (cons err (reverse loc))))
8483
(match expr
84+
[(? number?) (void)]
8585
[(? constant?) (void)]
8686
[(? variable?) (void)]
8787
[(list 'if cond ift iff)

src/core/matcher.rkt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
(define (fail . irr) #f)
3131

3232
(match pattern
33+
[(? number?)
34+
(and (equal? pattern expr) '())]
3335
[(? constant?)
3436
(and (equal? pattern expr) '())]
3537
[(? variable?)
@@ -45,6 +47,7 @@
4547
(define (pattern-substitute pattern bindings)
4648
; pattern binding -> expr
4749
(match pattern
50+
[(? number?) pattern]
4851
[(? constant?) pattern]
4952
[(? variable?)
5053
(dict-ref bindings pattern)]
@@ -120,6 +123,9 @@
120123
(match pattern
121124
[(? variable?)
122125
(sow (cons '() (list (cons pattern expr))))]
126+
[(? number?)
127+
(when (equal? expr pattern)
128+
(sow (cons '() '())))]
123129
[(? constant?)
124130
(when (equal? expr pattern)
125131
(sow (cons '() '())))]

src/core/reduce.rkt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
(define (simplify expr*)
2020
(define expr ((get-evaluator) expr*))
2121
(match expr
22+
[(? number?) expr]
2223
[(? constant?) expr]
2324
[(? variable?) expr]
2425
[`(λ ,vars ,body)
@@ -47,6 +48,7 @@
4748

4849
(define (simplify-node expr)
4950
(match expr
51+
[(? number?) expr]
5052
[(? constant?) expr]
5153
[(? variable?) expr]
5254
[(or `(+ ,_ ...) `(- ,_ ...) `(neg ,_))

src/core/simplify.rkt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,9 @@
185185
(define (munge expr)
186186
;; Despite the name, `expr` might be an expression OR a pattern
187187
(match expr
188-
[(? constant?)
189-
(if (symbol? expr)
190-
(list expr)
191-
expr)]
192-
[(? variable?)
193-
expr]
188+
[(? number?) expr]
189+
[(? constant?) (list expr)]
190+
[(? variable?) expr]
194191
[(list head subs ...)
195192
(cons head (map munge subs))]))
196193

src/core/taylor.rkt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@
106106
(match expr
107107
[(? (curry equal? var))
108108
(taylor-exact 0 1)]
109+
[(? number?)
110+
(taylor-exact expr)]
109111
[(? constant?)
110112
(taylor-exact expr)]
111113
[(? variable?)

src/function-definitions.rkt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
(define (all-ops expr good?)
1515
(match expr
16+
[(? number?) #t]
1617
[(? constant?) #t]
1718
[(? variable?) #t]
1819
[(list f args ...)

src/programs.rkt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
;; standards, this will have to have more information passed in
4141
(define (type-of expr repr env)
4242
(match expr
43-
[(? real?) (get-type 'real)]
43+
[(? number?) (get-type 'real)]
4444
[(? (representation-repr? repr)) (representation-type repr)]
4545
[(? constant?)
4646
(representation-type (get-representation (constant-info expr 'type)))]
@@ -53,7 +53,7 @@
5353
;; Fast version does not recurse into functions applications
5454
(define (repr-of expr repr env)
5555
(match expr
56-
[(? real?) repr]
56+
[(? number?) repr]
5757
[(? (representation-repr? repr)) repr]
5858
[(? constant?) (get-representation (constant-info expr 'type))]
5959
[(? variable?) (dict-ref env expr)]
@@ -66,7 +66,8 @@
6666
[(list op args ...)
6767
(and (operator-info op field) (andmap loop args))]
6868
[(? variable?) true]
69-
[(? constant?) (or (not (symbol? expr)) (constant-info expr field))])))
69+
[(? number?) true]
70+
[(? constant?) (constant-info expr field)])))
7071

7172
(define (expr-contains? expr pred)
7273
(let loop ([expr expr])
@@ -78,6 +79,7 @@
7879

7980
(define (free-variables prog)
8081
(match prog
82+
[(? number?) '()]
8183
[(? constant?) '()]
8284
[(? variable?) (list prog)]
8385
[`(,op ,args ...)
@@ -157,7 +159,7 @@
157159
(set! size (+ 1 size))
158160
(define expr
159161
(match prog
160-
[(? real?) (list (const (real->precision prog repr)))]
162+
[(? number?) (list (const (real->precision prog repr)))]
161163
[(? constant?) (list (constant-info prog mode))]
162164
[(? variable?) prog]
163165
[`(if ,c ,t ,f)

src/syntax/sugar.rkt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
;; Match guaranteed to succeed because we ran type-check first
9292
(define op* (apply get-parametric-operator op atypes))
9393
(values (cons op* args*) (operator-info op* 'otype))]
94-
[(? real?)
94+
[(? number?)
9595
(values
9696
(match expr
9797
[(or +inf.0 -inf.0 +nan.0) expr]
@@ -146,7 +146,7 @@
146146
(cons op* args*))]
147147
[(? (conjoin complex? (negate real?)))
148148
`(complex ,(real-part expr) ,(imag-part expr))]
149-
[(? real?)
149+
[(? number?)
150150
(if full?
151151
(match expr
152152
[-inf.0 (if full? '(- INFINITY) '(neg INFINITY))] ; not '(neg INFINITY) because this is post-resugaring

src/syntax/syntax-check.rkt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
(define (check-expression* stx vars error!)
88
(match stx
9+
[#`,(? number?) (void)]
910
[#`,(? constant?) (void)]
1011
[#`,(? variable? var)
1112
(unless (set-member? vars stx)

src/syntax/syntax.rkt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -689,10 +689,9 @@
689689
(dict-has-key? (cdr operator-impls) op))))
690690

691691
(define (constant? var)
692-
(or (real? var)
693-
(and (symbol? var)
694-
(or (hash-has-key? parametric-constants var)
695-
(dict-has-key? (cdr constant-impls) var)))))
692+
(and (symbol? var)
693+
(or (hash-has-key? parametric-constants var)
694+
(dict-has-key? (cdr constant-impls) var))))
696695

697696
(define (variable? var)
698697
(and (symbol? var) (not (constant? var))))

0 commit comments

Comments
 (0)