-
Notifications
You must be signed in to change notification settings - Fork 0
/
interp-Cvec.rkt
66 lines (60 loc) · 2.2 KB
/
interp-Cvec.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#lang racket
(require "utilities.rkt")
(require "interp-Lvec-prime.rkt")
(require "interp-Cvar.rkt")
(require "interp-Cif.rkt")
(require "interp-Cwhile.rkt")
(require (prefix-in runtime-config: "runtime-config.rkt"))
(provide interp-Cvec interp-Cvec-mixin)
(define (interp-Cvec-mixin super-class)
(class super-class
(super-new)
(inherit interp-exp initialize!)
(define/override (interp-stmt env)
(lambda (ast)
(copious "interp-stmt" ast)
(match ast
#;[(Prim 'vector-set! (list e-vec i e-arg))
((interp-exp env) ast)
env]
;; TODO: move the following to the interpreter for any
#;[(Prim 'any-vector-set! (list e-vec i e-arg))
((interp-exp env) ast)
env]
;; Determine if a collection is needed.
;; Which it isn't because vectors stored in the environment
;; is the representation of the heap in the C language,
;; but collection is a no-op so we should check to see if
;; everything is well formed anyhow.
;; Collection isn't needed or possible in this representation
[(Collect size)
(unless (exact-nonnegative-integer? size)
(error 'interp-C "invalid argument to collect in ~a" ast))
env]
[else ((super interp-stmt env) ast)]
)))
(define/override (interp-tail env blocks)
(lambda (ast)
(copious "interp-tail" ast)
(match ast
[(Seq s t)
(define new-env ((interp-stmt env) s))
((interp-tail new-env blocks) t)]
[else ((super interp-tail env blocks) ast)]
)))
(define/override (interp-program ast)
(copious "interp-program" ast)
(match ast
[(CProgram info blocks)
((initialize!) runtime-config:rootstack-size
runtime-config:heap-size)
(super interp-program (CProgram info blocks))]
[else (error "interp-program unhandled" ast)]))
))
(define (interp-Cvec p)
(define Cvec-class (interp-Cvec-mixin
(interp-Cwhile-mixin
(interp-Cif-mixin
(interp-Cvar-mixin
interp-Lvec-prime-class)))))
(send (new Cvec-class) interp-program p))