* Added (module <lang>) as a specification for using

`make-module-evaluator' accepting only modules with the specified
  language.
* Fix a bug with deciding on how to convert values for printing.
* Improved code in checker.ss.

svn: r11955
This commit is contained in:
Eli Barzilay 2008-10-06 21:44:23 +00:00
parent 433819df52
commit d2bd4c050e
3 changed files with 37 additions and 26 deletions

View File

@ -488,6 +488,14 @@
submission->bytes) submission->bytes)
submission maxwidth textualize? untabify? submission maxwidth textualize? untabify?
markup-prefix prefix-re)))) markup-prefix prefix-re))))
(define (uem-handler e)
(let ([m (if (exn? e) (exn-message e) (format "~a" e))])
(cond
[(procedure? uem) (uem m)]
[(not (string? uem))
(error* "badly configured user-error-message")]
[(regexp-match? #rx"~[aesvAESV]" uem) (error* uem m)]
[else (error* "~a" uem)])))
(when create-text? (make-directory "grading") (write-text)) (when create-text? (make-directory "grading") (write-text))
(when value-printer (current-value-printer value-printer)) (when value-printer (current-value-printer value-printer))
(when coverage? (sandbox-coverage-enabled #t)) (when coverage? (sandbox-coverage-enabled #t))
@ -495,24 +503,10 @@
(cond (cond
[(not eval?) (let () body ...)] [(not eval?) (let () body ...)]
[language [language
(let ([eval (let ([eval (with-handlers ([void uem-handler])
(with-handlers (call-with-evaluator/submission
([void language (append requires teachpacks)
(lambda (e) submission values))])
(let ([m (if (exn? e)
(exn-message e)
(format "~a" e))])
(cond
[(procedure? uem) (uem m)]
[(not (string? uem))
(error* "badly configured ~a"
"user-error-message")]
[(regexp-match? #rx"~[aesvAESV]" uem)
(error* uem m)]
[else (error* "~a" uem)])))])
(call-with-evaluator/submission
language (append requires teachpacks)
submission values))])
(set-run-status "running tests") (set-run-status "running tests")
(parameterize ([submission-eval (wrap-evaluator eval)]) (parameterize ([submission-eval (wrap-evaluator eval)])
(let-syntax ([with-submission-bindings (let-syntax ([with-submission-bindings

View File

@ -21,6 +21,7 @@
@defproc[(make-evaluator/submission @defproc[(make-evaluator/submission
[language (or/c module-path? [language (or/c module-path?
(list/c (one-of/c 'special) symbol?) (list/c (one-of/c 'special) symbol?)
(list/c (one-of/c 'module) module-path?)
(cons/c (one-of/c 'begin) list?))] (cons/c (one-of/c 'begin) list?))]
[require-paths (listof path-string?)] [require-paths (listof path-string?)]
[content bytes?]) [content bytes?])
@ -28,11 +29,19 @@
Like @scheme[make-evaluator], but the definitions content is Like @scheme[make-evaluator], but the definitions content is
supplied as a submission byte string. The byte string is opened for supplied as a submission byte string. The byte string is opened for
reading, with line-counting enabled.} reading, with line-counting enabled.
In addition to the language specification for
@scheme[make-evaluator], the @scheme[language] argument can be a
list that begins with @scheme['module]. In this case,
@scheme[make-module-language] is used to create an evaluator, and
the module code must be using the the specified language in its
language position.}
@defproc[(call-with-evaluator @defproc[(call-with-evaluator
[language (or/c module-path? [language (or/c module-path?
(list/c (one-of/c 'special) symbol?) (list/c (one-of/c 'special) symbol?)
(list/c (one-of/c 'module) module-path?)
(cons/c (one-of/c 'begin) list?))] (cons/c (one-of/c 'begin) list?))]
[require-paths (listof path-string?)] [require-paths (listof path-string?)]
[input-program any/c] [input-program any/c]
@ -46,11 +55,13 @@
suitable for @scheme[language], it initializes suitable for @scheme[language], it initializes
@scheme[set-run-status] with @scheme["executing your code"], and it @scheme[set-run-status] with @scheme["executing your code"], and it
catches all exceptions to re-raise them in a form suitable as a catches all exceptions to re-raise them in a form suitable as a
submission error.} submission error. See @scheme[make-evaluator/submission] for
further details.}
@defproc[(call-with-evaluator/submission [language @defproc[(call-with-evaluator/submission [language
(or/c module-path? (or/c module-path?
(list/c (one-of/c 'special) symbol?) (list/c (one-of/c 'special) symbol?)
(list/c (one-of/c 'module) module-path?)
(cons/c (one-of/c 'begin) list?))] (cons/c (one-of/c 'begin) list?))]
[require-paths (listof path-string?)] [require-paths (listof path-string?)]
[submission bytes?] [submission bytes?]
@ -59,7 +70,8 @@
Like @scheme[call-with-evaluator], but the definitions content is Like @scheme[call-with-evaluator], but the definitions content is
supplied as a byte string. The byte string is opened for reading, supplied as a byte string. The byte string is opened for reading,
with line-counting enabled.} with line-counting enabled. See @scheme[call-with-evaluator] and
@scheme[make-evaluator/submission] for further details.}
@; JBC: this contract is probably wrong @; JBC: this contract is probably wrong
@; JBC: does this eval accept an optional namespace? @; JBC: does this eval accept an optional namespace?

View File

@ -48,14 +48,18 @@
;; Execution ---------------------------------------- ;; Execution ----------------------------------------
(define (make-evaluator* lang reqs inp)
(if (and (list? lang) (= 2 (length lang)) (eq? 'module (car lang)))
(make-module-evaluator inp #:language (cadr lang) #:allow-read reqs)
(make-evaluator lang inp #:requires reqs)))
(define (open-input-text-editor/lines str) (define (open-input-text-editor/lines str)
(let ([inp (open-input-text-editor str)]) (let ([inp (open-input-text-editor str)])
(port-count-lines! inp) inp)) (port-count-lines! inp) inp))
(define (make-evaluator/submission language requires str) (define (make-evaluator/submission language requires str)
(let-values ([(defs interacts) (unpack-submission str)]) (let-values ([(defs interacts) (unpack-submission str)])
(make-evaluator language #:requires requires (make-evaluator* language requires (open-input-text-editor defs))))
(open-input-text-editor defs))))
(define (evaluate-all source port eval) (define (evaluate-all source port eval)
(let loop () (let loop ()
@ -164,11 +168,12 @@
(define (call-with-evaluator lang requires program-port go) (define (call-with-evaluator lang requires program-port go)
(parameterize ([error-value->string-handler (lambda (v s) (parameterize ([error-value->string-handler (lambda (v s)
((current-value-printer) v))] ((current-value-printer) v))]
[list-abbreviation-enabled (not (or (eq? lang 'beginner) [list-abbreviation-enabled
(eq? lang 'beginner-abbr)))]) (not (or (equal? lang '(special beginner))
(equal? lang '(special beginner-abbr))))])
(reraise-exn-as-submission-problem (reraise-exn-as-submission-problem
(lambda () (lambda ()
(let ([e (make-evaluator lang #:requires requires program-port)]) (let ([e (make-evaluator* lang requires program-port)])
(set-run-status "executing your code") (set-run-status "executing your code")
(go e)))))) (go e))))))