cs: small interpreter clean-ups

This commit is contained in:
Matthew Flatt 2020-02-10 20:11:18 -07:00
parent 5e45dd2e1c
commit 56fe13e6f7
4 changed files with 20 additions and 3 deletions

View File

@ -147,6 +147,11 @@
(list-of-keywords? (cadr v))
(extflonum? (cadr v))))
10]
[(and (pair? v)
(pair? (cdr v))
(eq? 'quote (car v))
(void? (cadr v)))
6]
[(bytes? v) (* 3 (bytes-length v))]
[(and (symbol? v) (regexp-match? #rx"#" (symbol->string v)))
(+ 2 (string-length (symbol->string v)))]
@ -175,6 +180,11 @@
(list-of-keywords? (cadr v))
(extflonum? (cadr v))))
(write (hash-ref lifts (cadr v)) out)]
[(and (pair? v)
(pair? (cdr v))
(eq? 'quote (car v))
(void? (cadr v)))
(write '(void) out)]
[(bytes? v)
(display "#vu8")
(write (bytes->list v) out)]

View File

@ -302,7 +302,7 @@
(compile-expr `(call-with-values (lambda () ,rhs)
(lambda ,gen-ids
,@(if (null? ids)
'((void))
(list (void))
(for/list ([id (in-list ids)]
[gen-id (in-list gen-ids)])
`(set! ,id ,gen-id)))))
@ -548,7 +548,11 @@
(define pos (stack->pos (if (boxed? var) (boxed-pos var) var) stk-i)) ; box result means unused
(cond
[(box? pos)
(vector 'clear (list (unbox pos)) e)]
(cond
[(and (vector? e) (eq? 'clear (vector-ref e 0)))
(vector 'clear (cons (unbox pos) (vector-ref e 1)) (vector-ref e 2))]
[else
(vector 'clear (list (unbox pos)) e)])]
[(not (hash-ref mutated u #f))
e]
[else

View File

@ -43,7 +43,7 @@
(cond
[(or (string? x) (bytes? x) (boolean? x) (number? x))
x]
[(void? x) '(void)]
[(void? x) `(quote ,(void))]
[(eof-object? x) 'eof]
[else
`(quote ,x)]))

View File

@ -396,6 +396,9 @@
[`,_ (finish-definition ids)])]
[else
(finish-wrapped-definition ids rhs)])]
[`(quote ,_) ; useful to drop #<void>s for the interpreter
#:guard (or (pair? (cdr l)) (pair? accum-ids))
(loop (cdr l) mut-l accum-exprs accum-ids knowns)]
[`,_
(match form
[`(define-values ,ids ,_)