-
Notifications
You must be signed in to change notification settings - Fork 1
/
interp-Cvar.rkt
38 lines (33 loc) · 920 Bytes
/
interp-Cvar.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
#lang racket
(require racket/fixnum)
(require racket/dict)
(require "utilities.rkt")
(require "interp-Rvar.rkt")
(provide interp-Cvar interp-Cvar-mixin)
(define (interp-Cvar-mixin super-class)
(class super-class
(super-new)
(inherit interp-exp)
(define/public (interp-stmt env)
(lambda (s)
(match s
[(Assign (Var x) e)
(dict-set env x ((interp-exp env) e))]
)))
(define/public (interp-tail env)
(lambda (t)
(match t
[(Return e)
((interp-exp env) e)]
[(Seq s t2)
(define new-env ((interp-stmt env) s))
((interp-tail new-env) t2)]
)))
(define/override (interp-program p)
(match p
[(CProgram _ `((start . ,t)))
((interp-tail '()) t)]
))
))
(define (interp-Cvar p)
(send (new (interp-Cvar-mixin interp-Rvar-class)) interp-program p))