correcting a soundness bug: I need to explicitly mark the lambdas so we can properly annotate the functions.

This commit is contained in:
Danny Yoo 2013-03-01 16:42:21 -07:00
parent 9e66a61c3c
commit 6642cdcff7
6 changed files with 33 additions and 1 deletions

View File

@ -844,6 +844,7 @@
(append-instruction-sequences (append-instruction-sequences
(Lam-entry-label exp) (Lam-entry-label exp)
(make-MarkEntryPoint (Lam-entry-label exp))
(Comment (format "lambda body for ~a" (Lam-name exp))) (Comment (format "lambda body for ~a" (Lam-name exp)))
maybe-unsplice-rest-argument maybe-unsplice-rest-argument
maybe-install-closure-values maybe-install-closure-values

View File

@ -167,6 +167,7 @@
(define-type StraightLineStatement (U (define-type StraightLineStatement (U
DebugPrint DebugPrint
Comment Comment
MarkEntryPoint
AssignImmediate AssignImmediate
AssignPrimOp AssignPrimOp
@ -293,6 +294,11 @@
#:transparent) #:transparent)
;; Marks the head of every lambda.
(define-struct: MarkEntryPoint ([label : Symbol])
#:transparent)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Primitive Operators ;; Primitive Operators

View File

@ -196,6 +196,9 @@
;(loop (rest stmts)) ;(loop (rest stmts))
(cons a-stmt (loop (rest stmts))) (cons a-stmt (loop (rest stmts)))
] ]
[(MarkEntryPoint? a-stmt)
(cons a-stmt (loop (rest stmts)))]
[(AssignImmediate? a-stmt) [(AssignImmediate? a-stmt)
(cons (make-AssignImmediate (rewrite-target (AssignImmediate-target a-stmt)) (cons (make-AssignImmediate (rewrite-target (AssignImmediate-target a-stmt))
@ -347,6 +350,9 @@
#f #f
#;#t] #;#t]
[(MarkEntryPoint? stmt)
#f]
[(AssignImmediate? stmt) [(AssignImmediate? stmt)
(equal? (AssignImmediate-target stmt) (equal? (AssignImmediate-target stmt)
(AssignImmediate-value stmt))] (AssignImmediate-value stmt))]

View File

@ -170,6 +170,8 @@ EOF
(next)] (next)]
[(DebugPrint? stmt) [(DebugPrint? stmt)
(next)] (next)]
[(MarkEntryPoint? stmt)
(next)]
[(AssignImmediate? stmt) [(AssignImmediate? stmt)
(next)] (next)]
[(AssignPrimOp? stmt) [(AssignPrimOp? stmt)
@ -293,6 +295,9 @@ EOF
[else [else
(define stmt (first stmts)) (define stmt (first stmts))
(cond (cond
[(MarkEntryPoint? stmt)
(default stmt)]
[(DebugPrint? stmt) [(DebugPrint? stmt)
(default stmt)] (default stmt)]
@ -430,6 +435,9 @@ EOF
[else [else
(define stmt (first stmts)) (define stmt (first stmts))
(cond (cond
[(MarkEntryPoint? stmt)
(default)]
[(DebugPrint? stmt) [(DebugPrint? stmt)
(default)] (default)]
@ -496,6 +504,10 @@ EOF
(define (assemble-statement stmt blockht) (define (assemble-statement stmt blockht)
(define assembled (define assembled
(cond (cond
[(MarkEntryPoint? stmt)
;; Marking the entry point to the lambda should have no other effect.
""]
[(DebugPrint? stmt) [(DebugPrint? stmt)
(format "M.params.currentOutputPort.writeDomNode(M, $('<span/>').text(~a));" (format "M.params.currentOutputPort.writeDomNode(M, $('<span/>').text(~a));"
(assemble-oparg (DebugPrint-value stmt) (assemble-oparg (DebugPrint-value stmt)
@ -667,6 +679,9 @@ EOF
[else [else
(define first-stmt (first stmts)) (define first-stmt (first stmts))
(cond (cond
[(MarkEntryPoint? first-stmt)
(cons (MarkEntryPoint-label first-stmt)
(get-function-entry-and-exit-names (rest stmts)))]
[(LinkedLabel? first-stmt) [(LinkedLabel? first-stmt)
(cons (LinkedLabel-label first-stmt) (cons (LinkedLabel-label first-stmt)
(cons (LinkedLabel-linked-to first-stmt) (cons (LinkedLabel-linked-to first-stmt)

View File

@ -25,6 +25,8 @@
(LinkedLabel-linked-to stmt))] (LinkedLabel-linked-to stmt))]
[(DebugPrint? stmt) [(DebugPrint? stmt)
empty] empty]
[(MarkEntryPoint? stmt)
(list (MarkEntryPoint-label stmt))]
[(AssignImmediate? stmt) [(AssignImmediate? stmt)
(let: ([v : OpArg (AssignImmediate-value stmt)]) (let: ([v : OpArg (AssignImmediate-value stmt)])
(collect-input v))] (collect-input v))]
@ -172,6 +174,8 @@
[(LinkedLabel? stmt) [(LinkedLabel? stmt)
(list (LinkedLabel-label stmt) (list (LinkedLabel-label stmt)
(LinkedLabel-linked-to stmt))] (LinkedLabel-linked-to stmt))]
[(MarkEntryPoint? stmt)
(list (MarkEntryPoint-label stmt))]
[(DebugPrint? stmt) [(DebugPrint? stmt)
empty] empty]
[(AssignImmediate? stmt) [(AssignImmediate? stmt)

View File

@ -78,7 +78,7 @@
(define assembled-op (open-output-string)) (define assembled-op (open-output-string))
(define assembled (assemble/write-invoke compiled-bytecode #f assembled-op)) (define assembled (assemble/write-invoke compiled-bytecode #f assembled-op))
(cons (get-output-string assembled-op) (loop))]))) (cons (get-output-string assembled-op) (loop))])))
#;(printf "assembled codes ~a\n" assembled-codes) (printf "assembled codes ~a\n" assembled-codes)
(write-json (hash 'compiledCodes assembled-codes) (write-json (hash 'compiledCodes assembled-codes)
op)] op)]
[else [else