File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#lang racket
22(provide interp interp-env-heap)
3- (require "heap.rkt "
4- "env.rkt "
3+ (require "env.rkt "
54 "unload.rkt "
65 "interp-prims-heap.rkt "
76 "ast.rkt " )
Original file line number Diff line number Diff line change 11#lang racket
2- (provide interp-prim1 interp-prim2 interp-prim3 )
2+ (provide interp-prim1 interp-prim2)
33(require "heap.rkt " )
44
55;; Op1 Value* Heap -> Answer*
1818 [(list 'car (list 'cons i)) (cons h (heap-ref h i))]
1919 [(list 'cdr (list 'cons i)) (cons h (heap-ref h (add1 i)))]
2020 [(list 'empty? v) (cons h (empty? v))]
21- [(list 'string? (list 'str s)) (cons h #t )]
22- [(list 'string? v) (cons h #f )]
23- [(list 'string-length (list 'str a)) (cons h (heap-ref h a))]
2421 [_ 'err ]))
2522
2623;; Op2 Value* Value* Heap -> Answer*
3532 [(list (list t1 a1) (list t2 a2)) (cons h (and (eq? t1 t2) (= a1 a2)))]
3633 [_ (cons h (eqv? v1 v2))])]
3734 [(list 'cons v1 v2) (alloc-cons v1 v2 h)]
38- [(list 'make-string (? integer? i) (? char? c))
39- (if (<= 0 i)
40- (alloc-str (make-string i c) h)
41- 'err )]
42- [(list 'string-ref (list 'str a) (? integer? i))
43- (cons h (heap-ref h (+ a i 1 )))]
4435 [_ 'err ]))
4536
46- ;; Op2 Value* Value* Heap -> Answer*
47- (define (interp-prim3 p v1 v2 v3 h)
48- (match (list p v1 v2 v3)
49- [(list 'string-set! (list 'str a) (? integer? i) (? char? c))
50- (if (<= 0 v2 (sub1 (heap-ref h a)))
51- (cons (heap-set h (+ a i 1 ) c)
52- (void))
53- 'err )]
54- [_ 'err ]))
55-
5637;; Any -> Boolean
5738(define (codepoint? v)
5839 (and (integer? v)
You can’t perform that action at this time.
0 commit comments