-
Notifications
You must be signed in to change notification settings - Fork 0
/
interp-Cvar.rkt
40 lines (35 loc) · 986 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
39
40
#lang racket
(require racket/fixnum)
(require racket/dict)
(require "utilities.rkt")
(require "interp-Lvar.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))]
[else
(error 'interp-stmt "unmatched ~a" s)]
)))
(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-Lvar-class)) interp-program p))