Reworking non-schemeunit tests and abstract running process

svn: r6295
This commit is contained in:
Jay McCarthy 2007-05-25 15:49:54 +00:00
parent ec228f9092
commit f7ca8895b6
5 changed files with 61 additions and 48 deletions

View File

@ -20,6 +20,7 @@
send/suspend send/suspend
;; "CLIENT" INTERFACE ;; "CLIENT" INTERFACE
run-start
dispatch-start dispatch-start
dispatch dispatch
) )
@ -150,6 +151,13 @@
;; ********************************************************************** ;; **********************************************************************
;; "CLIENT" INTERFACE ;; "CLIENT" INTERFACE
(define (run-start harness start)
(abort/cc
(with-continuation-mark safe-call? '(#t start)
(start
(with-continuation-mark the-cont-key start
(harness))))))
;; dispatch-start: request -> reponse ;; dispatch-start: request -> reponse
;; pass the initial request to the starting interaction point ;; pass the initial request to the starting interaction point
(define (dispatch-start req0) (define (dispatch-start req0)

View File

@ -196,11 +196,7 @@
(lambda _ (lambda _
(dynamic-require module-name #f))]) (dynamic-require module-name #f))])
(let ([start (dynamic-require module-name 'start)]) (let ([start (dynamic-require module-name 'start)])
(abort/cc (run-start start-servlet start)))))
(with-continuation-mark safe-call? '(#t start)
(start
(with-continuation-mark the-cont-key start
(start-servlet)))))))))
(myprint "resume-session~n") (myprint "resume-session~n")
(resume-session (session-id ses) host-info))) (resume-session (session-id ses) host-info)))
(output-response/method (output-response/method

View File

@ -1,29 +1,38 @@
(require "../client.ss") (require "../abort-resume.ss")
(define (id x) x)
;; **************************************** ;; ****************************************
;; **************************************** ;; ****************************************
;; BASIC TESTS ;; BASIC TESTS
(module m00 "../interaction.ss" (module m00 "../lang.ss"
(define (id x) x) (define (id x) x)
(id (start-interaction id))) (provide start)
(define (start i)
(id i)))
(require m00) (require (prefix m00: m00))
(run-start (lambda () (start-interaction id)) m00:start)
(= 7 (dispatch-start 7)) (= 7 (dispatch-start 7))
(= 8 (dispatch-start 8)) (= 8 (dispatch-start 8))
(module m01 "../interaction.ss" (module m01 "../lang.ss"
(define (id x) x) (provide start)
(+ (* 1 2) (* 3 4) (start-interaction id))) (define (start i)
(+ (* 1 2) (* 3 4) i)))
(require m01) (require (prefix m01: m01))
(run-start (lambda () (start-interaction id)) m01:start)
(= 14 (dispatch-start 0)) (= 14 (dispatch-start 0))
(= 20 (dispatch-start 6)) (= 20 (dispatch-start 6))
;; start-interaction may be called mutitple times ;; start-interaction may be called mutitple times
;; each call overwrites the previous interaction ;; each call overwrites the previous interaction
;; continuation with the latest one. ;; continuation with the latest one.
(module m02 "../interaction.ss" ; XXX Can't do this anymore
#|
(module m02 "../lang.ss"
(define (id x) x) (define (id x) x)
(+ (start-interaction id) (+ (start-interaction id)
(start-interaction id))) (start-interaction id)))
@ -32,37 +41,39 @@
(void? (dispatch-start 1)) (void? (dispatch-start 1))
(= 3 (dispatch-start 2)) (= 3 (dispatch-start 2))
(= 0 (dispatch-start -1)) (= 0 (dispatch-start -1))
|#
;; **************************************** ;; ****************************************
;; **************************************** ;; ****************************************
;; TESTS INVOLVING CALL/CC ;; TESTS INVOLVING CALL/CC
(module m03 "../interaction.ss" (module m03 "../lang.ss"
(define (f x) (provide start)
(define (start x)
(let/cc k (let/cc k
(+ 2 4 (k 3) 6 8))) (+ 2 4 (k 3) 6 8))))
(f (start-interaction (lambda (x) x))))
(require m03) (require (prefix m03: m03))
(run-start (lambda () (start-interaction id)) m03:start)
(= 3 (dispatch-start 'foo)) (= 3 (dispatch-start 'foo))
(= 3 (dispatch-start 7)) (= 3 (dispatch-start 7))
;; in the following test, if you modify ;; in the following test, if you modify
;; resume to print the "stack" you will ;; resume to print the "stack" you will
;; see that this is not tail recursive ;; see that this is not tail recursive
(module m04 "../interaction.ss" (module m04 "../lang.ss"
(define (mult ln) (provide start)
(define (start ln)
(let/cc k (let/cc k
(cond (cond
[(null? ln) 1] [(null? ln) 1]
[(zero? (car ln)) (k 0)] [(zero? (car ln)) (k 0)]
[else [else
(* (car ln) (* (car ln)
(mult (cdr ln)))]))) (start (cdr ln)))]))))
(mult (start-interaction (lambda (x) x))))
(require m04) (require (prefix m04: m04))
(run-start (lambda () (start-interaction id)) m04:start)
(= 0 (dispatch-start (list 1 2 3 4 5 6 7 0 8 9))) (= 0 (dispatch-start (list 1 2 3 4 5 6 7 0 8 9)))
(= 120 (dispatch-start (list 1 2 3 4 5))) (= 120 (dispatch-start (list 1 2 3 4 5)))
@ -70,10 +81,10 @@
;; outside the recursion and should be tail ;; outside the recursion and should be tail
;; recursive. A "stack trace" reveals this ;; recursive. A "stack trace" reveals this
;; as expected. ;; as expected.
(module m05 "../interaction.ss" (module m05 "../lang.ss"
(provide mult) (provide start)
(define (mult ln) (define (start ln)
(let/cc escape (let/cc escape
(mult/escape escape ln))) (mult/escape escape ln)))
@ -83,19 +94,18 @@
[(zero? (car ln)) (escape 0)] [(zero? (car ln)) (escape 0)]
[else [else
(* (car ln) (* (car ln)
(mult/escape escape (cdr ln)))])) (mult/escape escape (cdr ln)))])))
(mult (start-interaction (lambda (x) x))))
(require m05) (require (prefix m05: m05))
(run-start (lambda () (start-interaction id)) m05:start)
(= 0 (dispatch-start (list 1 2 3 0 4 5 6))) (= 0 (dispatch-start (list 1 2 3 0 4 5 6)))
(= 120 (dispatch-start (list 1 2 3 4 5))) (= 120 (dispatch-start (list 1 2 3 4 5)))
;; **************************************** ;; ****************************************
;; **************************************** ;; ****************************************
;; TESTS INVOLVING send/suspend ;; TESTS INVOLVING send/suspend
; XXX Doesn't work
#|
(module table01 mzscheme (module table01 mzscheme
(provide store-k (provide store-k
lookup-k) lookup-k)
@ -136,4 +146,5 @@
(= 4 (dispatch `(,second-key 3))) (= 4 (dispatch `(,second-key 3)))
(zero? (dispatch `(,second-key -1))) (zero? (dispatch `(,second-key -1)))
(= -7 (dispatch `(,third-key 0))) (= -7 (dispatch `(,third-key 0)))
(zero? (dispatch `(,third-key 7))))) (zero? (dispatch `(,third-key 7)))))
|#

View File

@ -5,14 +5,13 @@
(define (go ns) (define (go ns)
(lambda () (lambda ()
(parameterize ([current-namespace ns]) (parameterize ([current-namespace ns])
(eval '(abort/cc (eval '(run-start
(with-continuation-mark safe-call? '(#t start) (lambda ()
(start (start-interaction
(with-continuation-mark the-cont-key start
(start-interaction
(lambda (k*v) (lambda (k*v)
(lambda (k*v) (lambda (k*v)
((car k*v) k*v)))))))))))) ((car k*v) k*v)))))
start)))))
(define-syntax (make-module-eval m-expr) (define-syntax (make-module-eval m-expr)
(syntax-case m-expr (module) (syntax-case m-expr (module)

View File

@ -1,17 +1,15 @@
(require "../client.ss" (require "../abort-resume.ss"
(lib "serialize.ss")) (lib "serialize.ss"))
(module m08 "../persistent-interaction.ss" (module m08 "../lang.ss"
(define (id x) x) (provide start)
(define (gn which) (define (gn which)
(cadr (cadr
(send/suspend (send/suspend
(lambda (k) (lambda (k)
(let ([ignore (printf "Please send the ~a number.~n" which)]) (let ([ignore (printf "Please send the ~a number.~n" which)])
k))))) k)))))
(define (start ignore)
(let ([ignore (start-interaction car)])
(letrec ([f (let ([n (gn "first")]) (letrec ([f (let ([n (gn "first")])
(lambda (m) (+ n m)))] (lambda (m) (+ n m)))]
[g (let ([n (gn "second")]) [g (let ([n (gn "second")])
@ -20,7 +18,8 @@
(let ([ignore (printf "The answer is: ~s~n" result)]) (let ([ignore (printf "The answer is: ~s~n" result)])
result))))) result)))))
(require m08) (require (prefix m08: m08))
(run-start (lambda () (start-interaction car)) m08:start)
;; trace *without* serialization ;; trace *without* serialization
(define k0 (dispatch-start 'foo)) (define k0 (dispatch-start 'foo))