Using immutable hash vs alist
svn: r11425
This commit is contained in:
parent
ee42d18e6b
commit
9cb82aebf3
|
@ -1,8 +1,5 @@
|
||||||
#lang scheme/base
|
#lang scheme
|
||||||
(require mzlib/serialize
|
(require scheme/serialize
|
||||||
mzlib/list
|
|
||||||
mzlib/plt-match
|
|
||||||
mzlib/contract
|
|
||||||
"../private/closure.ss")
|
"../private/closure.ss")
|
||||||
;; Implementation: Have a distinguished frame variable that is read and captured by send/suspend,
|
;; Implementation: Have a distinguished frame variable that is read and captured by send/suspend,
|
||||||
;; installed on invocations of continuations by the server (and NOT from other continuation invocations)
|
;; installed on invocations of continuations by the server (and NOT from other continuation invocations)
|
||||||
|
@ -11,28 +8,8 @@
|
||||||
(define-serializable-struct primitive-wc (id))
|
(define-serializable-struct primitive-wc (id))
|
||||||
(define-serializable-struct frame (env))
|
(define-serializable-struct frame (env))
|
||||||
|
|
||||||
;; Environment
|
|
||||||
(define empty-env empty)
|
|
||||||
(define env-lookup
|
|
||||||
(match-lambda*
|
|
||||||
[(list id (list))
|
|
||||||
(error 'web-cell "Undefined web-cell: ~e" id)]
|
|
||||||
[(list id (list-rest (list-rest a-id a-val) env))
|
|
||||||
(if (eq? id a-id)
|
|
||||||
a-val
|
|
||||||
(env-lookup id env))]))
|
|
||||||
(define env-replace
|
|
||||||
(match-lambda*
|
|
||||||
[(list id val (list))
|
|
||||||
(list (cons id val))]
|
|
||||||
[(list id val (list-rest (list-rest a-id a-val) env))
|
|
||||||
(if (eq? id a-id)
|
|
||||||
(list* (cons id val) env)
|
|
||||||
(list* (cons a-id a-val)
|
|
||||||
(env-replace id val env)))]))
|
|
||||||
|
|
||||||
;; Frames
|
;; Frames
|
||||||
(define *wc-frame* (make-thread-cell (make-frame empty-env) #t))
|
(define *wc-frame* (make-thread-cell (make-frame (make-immutable-hasheq empty)) #t))
|
||||||
(define (current-frame) (thread-cell-ref *wc-frame*))
|
(define (current-frame) (thread-cell-ref *wc-frame*))
|
||||||
(define (update-frame! nf) (thread-cell-set! *wc-frame* nf))
|
(define (update-frame! nf) (thread-cell-set! *wc-frame* nf))
|
||||||
|
|
||||||
|
@ -68,14 +45,17 @@
|
||||||
wc)
|
wc)
|
||||||
|
|
||||||
(define (web-cell-ref pwc)
|
(define (web-cell-ref pwc)
|
||||||
(env-lookup (primitive-wc-id pwc)
|
(define i (primitive-wc-id pwc))
|
||||||
(frame-env (current-frame))))
|
(hash-ref
|
||||||
|
(frame-env (current-frame)) i
|
||||||
|
(lambda ()
|
||||||
|
(error 'web-cell "Undefined web-cell: ~e" i))))
|
||||||
|
|
||||||
(define (web-cell-shadow wc nv)
|
(define (web-cell-shadow wc nv)
|
||||||
(update-frame!
|
(update-frame!
|
||||||
(make-frame
|
(make-frame
|
||||||
(env-replace (primitive-wc-id wc) nv
|
(hash-set (frame-env (current-frame))
|
||||||
(frame-env (current-frame))))))
|
(primitive-wc-id wc) nv))))
|
||||||
|
|
||||||
(provide make-web-cell)
|
(provide make-web-cell)
|
||||||
(provide/contract
|
(provide/contract
|
||||||
|
|
Loading…
Reference in New Issue
Block a user