-
Notifications
You must be signed in to change notification settings - Fork 1
/
interp-Rvec.rkt
42 lines (37 loc) · 1.2 KB
/
interp-Rvec.rkt
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
33
34
35
36
37
38
39
40
41
42
#lang racket
(require racket/fixnum)
(require "utilities.rkt")
(require "interp-Rif.rkt")
(provide interp-Rvec interp-Rvec-class)
;; Note to maintainers of this code:
;; A copy of this interpreter is in the book and should be
;; kept in sync with this code.
(define interp-Rvec-class
(class interp-Rif-class
(super-new)
(define/override (interp-op op)
(verbose "Rvec/interp-op" op)
(match op
['eq? (lambda (v1 v2)
(cond [(or (and (fixnum? v1) (fixnum? v2))
(and (boolean? v1) (boolean? v2))
(and (vector? v1) (vector? v2))
(and (void? v1) (void? v2)))
(eq? v1 v2)]))]
['vector vector]
['vector-length vector-length]
['vector-ref vector-ref]
['vector-set! vector-set!]
[else (super interp-op op)]
))
(define/override ((interp-exp env) e)
(define recur (interp-exp env))
(verbose "Rvec/interp-exp" e)
(match e
[(HasType e t) (recur e)]
[(Void) (void)]
[else ((super interp-exp env) e)]
))
))
(define (interp-Rvec p)
(send (new interp-Rvec-class) interp-program p))