diff --git a/evildoer/random.rkt b/evildoer/random.rkt index b6443e5..88b002c 100644 --- a/evildoer/random.rkt +++ b/evildoer/random.rkt @@ -1,5 +1,5 @@ #lang racket -(provide random-expr random-well-defined-expr) +(provide random-expr random-well-defined-expr random-input) (require "parse.rkt") ;; Randomly generate an expression @@ -10,6 +10,9 @@ (define (random-well-defined-expr) (parse (contract-random-generate expr-good/c))) +(define (random-input) + (contract-random-generate string?)) + (define op0/c (one-of/c 'read-byte 'peek-byte 'void)) diff --git a/extort/random.rkt b/extort/random.rkt index b6443e5..88b002c 100644 --- a/extort/random.rkt +++ b/extort/random.rkt @@ -1,5 +1,5 @@ #lang racket -(provide random-expr random-well-defined-expr) +(provide random-expr random-well-defined-expr random-input) (require "parse.rkt") ;; Randomly generate an expression @@ -10,6 +10,9 @@ (define (random-well-defined-expr) (parse (contract-random-generate expr-good/c))) +(define (random-input) + (contract-random-generate string?)) + (define op0/c (one-of/c 'read-byte 'peek-byte 'void)) diff --git a/hustle/heap.rkt b/hustle/heap.rkt index 0f7eb34..4d477a3 100644 --- a/hustle/heap.rkt +++ b/hustle/heap.rkt @@ -1,15 +1,18 @@ #lang racket -(provide alloc-box alloc-cons heap-ref heap-set) +(provide alloc-box alloc-cons heap-ref heap-set box-ptr cons-ptr) + +(struct box-ptr (i)) +(struct cons-ptr (i)) ;; Value* Heap -> Answer* (define (alloc-box v h) (cons (cons v h) - (list 'box (length h)))) + (box-ptr (length h)))) ;; Value* Value* Heap -> Answer* (define (alloc-cons v1 v2 h) (cons (cons v2 (cons v1 h)) - (list 'cons (length h)))) + (cons-ptr (length h)))) ;; Heap Address -> Value* (define (heap-ref h a) diff --git a/hustle/interp-heap.rkt b/hustle/interp-heap.rkt index 0256171..6909013 100644 --- a/hustle/interp-heap.rkt +++ b/hustle/interp-heap.rkt @@ -16,14 +16,16 @@ ;; | Eof ;; | Void ;; | '() -;; | (list 'box Address) -;; | (list 'cons Address) +;; | (box-ptr Address) +;; | (cons-ptr Address) + +;; type Address = Natural ;; type Heap = (Listof Value*) ;; type REnv = (Listof (List Id Value*)) ;; Expr -> Answer -(define (interp e) +(define (interp e) (unload (interp-env-heap e '() '()))) ;; Expr REnv Heap -> Answer* @@ -55,7 +57,7 @@ (if v (interp-env-heap e1 r h) (interp-env-heap e2 r h))])] - [(Begin e1 e2) + [(Begin e1 e2) (match (interp-env-heap e1 r h) ['err 'err] [(cons h _) (interp-env-heap e2 r h)])] diff --git a/hustle/interp-prims-heap.rkt b/hustle/interp-prims-heap.rkt index 53cbd4f..9ceaaa1 100644 --- a/hustle/interp-prims-heap.rkt +++ b/hustle/interp-prims-heap.rkt @@ -14,9 +14,9 @@ [(list 'eof-object? v) (cons h (eof-object? v))] [(list 'write-byte (? byte?)) (cons h (write-byte v))] [(list 'box v) (alloc-box v h)] - [(list 'unbox (list 'box i)) (cons h (heap-ref h i))] - [(list 'car (list 'cons i)) (cons h (heap-ref h i))] - [(list 'cdr (list 'cons i)) (cons h (heap-ref h (add1 i)))] + [(list 'unbox (box-ptr i)) (cons h (heap-ref h i))] + [(list 'car (cons-ptr i)) (cons h (heap-ref h i))] + [(list 'cdr (cons-ptr i)) (cons h (heap-ref h (add1 i)))] [(list 'empty? v) (cons h (empty? v))] [_ 'err])) @@ -26,7 +26,7 @@ [(list '+ (? integer? i1) (? integer? i2)) (cons h (+ i1 i2))] [(list '- (? integer? i1) (? integer? i2)) (cons h (- i1 i2))] [(list '< (? integer? i1) (? integer? i2)) (cons h (< i1 i2))] - [(list '= (? integer? i1) (? integer? i2)) (cons h (= i1 i2))] + [(list '= (? integer? i1) (? integer? i2)) (cons h (= i1 i2))] [(list 'eq? v1 v2) (match (list v1 v2) [(list (list t1 a1) (list t2 a2)) (cons h (and (eq? t1 t2) (= a1 a2)))] diff --git a/hustle/unload.rkt b/hustle/unload.rkt index 9092ca3..3429e45 100644 --- a/hustle/unload.rkt +++ b/hustle/unload.rkt @@ -13,12 +13,12 @@ (match v [(? integer?) v] [(? boolean?) v] - [(? char?) v] + [(? char?) v] [(? eof-object?) v] - [(? void?) v] - ['() '()] - [(list 'box a) + [(? void?) v] + ['() '()] + [(box-ptr a) (box (unload-value (heap-ref h a) h))] - [(list 'cons a) + [(cons-ptr a) (cons (unload-value (heap-ref h a) h) (unload-value (heap-ref h (add1 a)) h))]))