removing separate returnlinkage-notail structure
This commit is contained in:
parent
1ad7796fdd
commit
d805bca845
58
NOTES
58
NOTES
|
@ -360,3 +360,61 @@ optimize the efficiency of the runtime. I don't know what the
|
||||||
function is, but we want to optimize the parameters FN and TI such
|
function is, but we want to optimize the parameters FN and TI such
|
||||||
that it maximizes FN and minimizes TI, and yet gives us the browser
|
that it maximizes FN and minimizes TI, and yet gives us the browser
|
||||||
reactivity we want.
|
reactivity we want.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
April 24, 2011
|
||||||
|
|
||||||
|
The variables for linkage and target are doing double duty, which is
|
||||||
|
showing up in the defintion for compilation, since there are cases
|
||||||
|
that shouldn't exist in there.
|
||||||
|
|
||||||
|
They really should be part of the same datatype which describes,
|
||||||
|
essentially, what the code's continuation should be doing next.
|
||||||
|
Target's describing where the value needs to be installed at the end
|
||||||
|
of this, and linkage describes how to jump into the continuation.
|
||||||
|
|
||||||
|
|
||||||
|
Return --- write value to val, pop off and jump according to
|
||||||
|
dynamic value on control context. Return context may be in tail
|
||||||
|
position or not.
|
||||||
|
|
||||||
|
Next --- write value to a particular target and continue on.
|
||||||
|
|
||||||
|
Label --- write value to a particular target and jump
|
||||||
|
unconditionally to labeled location.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
The continuation may or may not be expecting multiple values.
|
||||||
|
|
||||||
|
Ignore: doesn't care how many values come back. Throw away values
|
||||||
|
if multiple values are passed in.
|
||||||
|
|
||||||
|
Any: receives multiple values, and ensures those values are on the
|
||||||
|
stack. If a single value is received, pushes it on the stack and
|
||||||
|
sets up argcount to 1.
|
||||||
|
|
||||||
|
N: must receive exactly N values. If there's a mismatch, raises a
|
||||||
|
runtime error.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Return will allow Any number of values to come back. It doesn't need
|
||||||
|
a separate multiple-value context.
|
||||||
|
|
||||||
|
Next expects either exactly 1 value to come back, or ignores. So it
|
||||||
|
needs an multiple-value context.
|
||||||
|
|
||||||
|
Label, too, expects exactly 1 value to come back, or ignores. So it
|
||||||
|
needs a mulitple-value context.
|
||||||
|
|
||||||
|
|
||||||
|
When we use apply-values, it'll compile the producer expression in an
|
||||||
|
Any context.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
I'm going to simplify values a bit.
|
57
compiler.rkt
57
compiler.rkt
|
@ -205,23 +205,29 @@
|
||||||
(define (compile-linkage cenv linkage)
|
(define (compile-linkage cenv linkage)
|
||||||
(cond
|
(cond
|
||||||
[(ReturnLinkage? linkage)
|
[(ReturnLinkage? linkage)
|
||||||
(make-instruction-sequence `(,(make-AssignImmediateStatement 'proc (make-ControlStackLabel))
|
(cond
|
||||||
|
[(ReturnLinkage-tail? linkage)
|
||||||
|
(make-instruction-sequence
|
||||||
|
`(,(make-AssignImmediateStatement 'proc (make-ControlStackLabel))
|
||||||
,(make-PopEnvironment (make-Const (length cenv))
|
,(make-PopEnvironment (make-Const (length cenv))
|
||||||
(make-Const 0))
|
(make-Const 0))
|
||||||
,(make-PopControlFrame)
|
,(make-PopControlFrame)
|
||||||
,(make-GotoStatement (make-Reg 'proc))))]
|
,(make-GotoStatement (make-Reg 'proc))))]
|
||||||
[(ReturnLinkage/NonTail? linkage)
|
[else
|
||||||
(make-instruction-sequence `(,(make-AssignImmediateStatement 'proc (make-ControlStackLabel))
|
(make-instruction-sequence
|
||||||
|
`(,(make-AssignImmediateStatement 'proc (make-ControlStackLabel))
|
||||||
,(make-PopControlFrame)
|
,(make-PopControlFrame)
|
||||||
,(make-GotoStatement (make-Reg 'proc))))]
|
,(make-GotoStatement (make-Reg 'proc))))])]
|
||||||
[(NextLinkage? linkage)
|
[(NextLinkage? linkage)
|
||||||
empty-instruction-sequence]
|
empty-instruction-sequence]
|
||||||
[(NextLinkage/Expects? linkage)
|
[(NextLinkage/Expects? linkage)
|
||||||
empty-instruction-sequence]
|
empty-instruction-sequence]
|
||||||
[(LabelLinkage? linkage)
|
[(LabelLinkage? linkage)
|
||||||
(make-instruction-sequence `(,(make-GotoStatement (make-Label (LabelLinkage-label linkage)))))]
|
(make-instruction-sequence
|
||||||
|
`(,(make-GotoStatement (make-Label (LabelLinkage-label linkage)))))]
|
||||||
[(LabelLinkage/Expects? linkage)
|
[(LabelLinkage/Expects? linkage)
|
||||||
(make-instruction-sequence `(,(make-GotoStatement (make-Label (LabelLinkage/Expects-label linkage)))))]))
|
(make-instruction-sequence
|
||||||
|
`(,(make-GotoStatement (make-Label (LabelLinkage/Expects-label linkage)))))]))
|
||||||
|
|
||||||
|
|
||||||
(: compile-singular-context-check (Linkage -> InstructionSequence))
|
(: compile-singular-context-check (Linkage -> InstructionSequence))
|
||||||
|
@ -234,8 +240,6 @@
|
||||||
empty-instruction-sequence]
|
empty-instruction-sequence]
|
||||||
[(ReturnLinkage? linkage)
|
[(ReturnLinkage? linkage)
|
||||||
empty-instruction-sequence]
|
empty-instruction-sequence]
|
||||||
[(ReturnLinkage/NonTail? linkage)
|
|
||||||
empty-instruction-sequence]
|
|
||||||
[(NextLinkage/Expects? linkage)
|
[(NextLinkage/Expects? linkage)
|
||||||
(let ([n (NextLinkage/Expects-expects linkage)])
|
(let ([n (NextLinkage/Expects-expects linkage)])
|
||||||
(cond
|
(cond
|
||||||
|
@ -339,8 +343,6 @@
|
||||||
(make-LabelLinkage/Expects after-if (NextLinkage/Expects-expects linkage))]
|
(make-LabelLinkage/Expects after-if (NextLinkage/Expects-expects linkage))]
|
||||||
[(ReturnLinkage? linkage)
|
[(ReturnLinkage? linkage)
|
||||||
linkage]
|
linkage]
|
||||||
[(ReturnLinkage/NonTail? linkage)
|
|
||||||
linkage]
|
|
||||||
[(LabelLinkage? linkage)
|
[(LabelLinkage? linkage)
|
||||||
linkage]
|
linkage]
|
||||||
[(LabelLinkage/Expects? linkage)
|
[(LabelLinkage/Expects? linkage)
|
||||||
|
@ -930,7 +932,8 @@
|
||||||
(let: ([primitive-branch : LabelLinkage (make-LabelLinkage (make-label 'primitiveBranch))]
|
(let: ([primitive-branch : LabelLinkage (make-LabelLinkage (make-label 'primitiveBranch))]
|
||||||
[compiled-branch : LabelLinkage (make-LabelLinkage (make-label 'compiledBranch))]
|
[compiled-branch : LabelLinkage (make-LabelLinkage (make-label 'compiledBranch))]
|
||||||
[after-call : LabelLinkage (make-LabelLinkage (make-label 'afterCall))])
|
[after-call : LabelLinkage (make-LabelLinkage (make-label 'afterCall))])
|
||||||
(let: ([compiled-linkage : Linkage (if (ReturnLinkage? linkage)
|
(let: ([compiled-linkage : Linkage (if (and (ReturnLinkage? linkage)
|
||||||
|
(ReturnLinkage-tail? linkage))
|
||||||
linkage
|
linkage
|
||||||
after-call)])
|
after-call)])
|
||||||
(append-instruction-sequences
|
(append-instruction-sequences
|
||||||
|
@ -970,7 +973,8 @@
|
||||||
(StaticallyKnownLam CompileTimeEnvironment CompileTimeEnvironment Natural Target Linkage -> InstructionSequence))
|
(StaticallyKnownLam CompileTimeEnvironment CompileTimeEnvironment Natural Target Linkage -> InstructionSequence))
|
||||||
(define (compile-procedure-call/statically-known-lam static-knowledge cenv extended-cenv n target linkage)
|
(define (compile-procedure-call/statically-known-lam static-knowledge cenv extended-cenv n target linkage)
|
||||||
(let*: ([after-call : LabelLinkage (make-LabelLinkage (make-label 'afterCall))]
|
(let*: ([after-call : LabelLinkage (make-LabelLinkage (make-label 'afterCall))]
|
||||||
[compiled-linkage : Linkage (if (ReturnLinkage? linkage)
|
[compiled-linkage : Linkage (if (and (ReturnLinkage? linkage)
|
||||||
|
(ReturnLinkage-tail? linkage))
|
||||||
linkage
|
linkage
|
||||||
after-call)])
|
after-call)])
|
||||||
(append-instruction-sequences
|
(append-instruction-sequences
|
||||||
|
@ -1009,7 +1013,8 @@
|
||||||
;; 2. Non-tail calls (next/label linkage) that write to val
|
;; 2. Non-tail calls (next/label linkage) that write to val
|
||||||
;; 3. Calls in argument position (next/label linkage) that write to the stack.
|
;; 3. Calls in argument position (next/label linkage) that write to the stack.
|
||||||
(define (compile-compiled-procedure-application cenv-length-with-args entry-point target linkage)
|
(define (compile-compiled-procedure-application cenv-length-with-args entry-point target linkage)
|
||||||
(let*-values ([(maybe-install-jump-address entry-point-target)
|
(let*-values
|
||||||
|
([(maybe-install-jump-address entry-point-target)
|
||||||
;; Optimization: if the entry-point is supposed to be val, then it needs to hold
|
;; Optimization: if the entry-point is supposed to be val, then it needs to hold
|
||||||
;; the procedure entry here. Otherwise, it doesn't.
|
;; the procedure entry here. Otherwise, it doesn't.
|
||||||
(cond [(Label? entry-point)
|
(cond [(Label? entry-point)
|
||||||
|
@ -1024,6 +1029,8 @@
|
||||||
[(proc-return) (make-LinkedLabel (make-label 'procReturn)
|
[(proc-return) (make-LinkedLabel (make-label 'procReturn)
|
||||||
proc-return-multiple)])
|
proc-return-multiple)])
|
||||||
(cond [(ReturnLinkage? linkage)
|
(cond [(ReturnLinkage? linkage)
|
||||||
|
(cond
|
||||||
|
[(ReturnLinkage-tail? linkage)
|
||||||
(cond
|
(cond
|
||||||
[(eq? target 'val)
|
[(eq? target 'val)
|
||||||
;; This case happens when we're in tail position.
|
;; This case happens when we're in tail position.
|
||||||
|
@ -1051,9 +1058,8 @@
|
||||||
;; occur when we're in tail position, and we should be in tail position
|
;; occur when we're in tail position, and we should be in tail position
|
||||||
;; only when the target is the val register.
|
;; only when the target is the val register.
|
||||||
(error 'compile "return linkage, target not val: ~s" target)])]
|
(error 'compile "return linkage, target not val: ~s" target)])]
|
||||||
|
[else
|
||||||
|
|
||||||
|
|
||||||
[(ReturnLinkage/NonTail? linkage)
|
|
||||||
(cond [(eq? target 'val)
|
(cond [(eq? target 'val)
|
||||||
;; This case happens for a function call that isn't in
|
;; This case happens for a function call that isn't in
|
||||||
;; tail position.
|
;; tail position.
|
||||||
|
@ -1084,7 +1090,7 @@
|
||||||
(make-Const 0))))
|
(make-Const 0))))
|
||||||
proc-return
|
proc-return
|
||||||
(make-instruction-sequence
|
(make-instruction-sequence
|
||||||
`(,(make-AssignImmediateStatement target (make-Reg 'val)))))])]
|
`(,(make-AssignImmediateStatement target (make-Reg 'val)))))])])]
|
||||||
|
|
||||||
[(NextLinkage? linkage)
|
[(NextLinkage? linkage)
|
||||||
(cond [(eq? target 'val)
|
(cond [(eq? target 'val)
|
||||||
|
@ -1321,9 +1327,10 @@
|
||||||
[(NextLinkage/Expects? linkage)
|
[(NextLinkage/Expects? linkage)
|
||||||
linkage]
|
linkage]
|
||||||
[(ReturnLinkage? linkage)
|
[(ReturnLinkage? linkage)
|
||||||
|
(cond [(ReturnLinkage-tail? linkage)
|
||||||
linkage]
|
linkage]
|
||||||
[(ReturnLinkage/NonTail? linkage)
|
[else
|
||||||
(make-LabelLinkage after-body-code)]
|
(make-LabelLinkage after-body-code)])]
|
||||||
[(LabelLinkage? linkage)
|
[(LabelLinkage? linkage)
|
||||||
(make-LabelLinkage after-body-code)]
|
(make-LabelLinkage after-body-code)]
|
||||||
[(LabelLinkage/Expects? linkage)
|
[(LabelLinkage/Expects? linkage)
|
||||||
|
@ -1360,9 +1367,11 @@
|
||||||
[(NextLinkage/Expects? linkage)
|
[(NextLinkage/Expects? linkage)
|
||||||
linkage]
|
linkage]
|
||||||
[(ReturnLinkage? linkage)
|
[(ReturnLinkage? linkage)
|
||||||
|
(cond
|
||||||
|
[(ReturnLinkage-tail? linkage)
|
||||||
linkage]
|
linkage]
|
||||||
[(ReturnLinkage/NonTail? linkage)
|
[else
|
||||||
(make-LabelLinkage after-body-code)]
|
(make-LabelLinkage after-body-code)])]
|
||||||
[(LabelLinkage? linkage)
|
[(LabelLinkage? linkage)
|
||||||
(make-LabelLinkage after-body-code)]
|
(make-LabelLinkage after-body-code)]
|
||||||
[(LabelLinkage/Expects? linkage)
|
[(LabelLinkage/Expects? linkage)
|
||||||
|
@ -1407,9 +1416,11 @@
|
||||||
[(NextLinkage/Expects? linkage)
|
[(NextLinkage/Expects? linkage)
|
||||||
linkage]
|
linkage]
|
||||||
[(ReturnLinkage? linkage)
|
[(ReturnLinkage? linkage)
|
||||||
|
(cond
|
||||||
|
[(ReturnLinkage-tail? linkage)
|
||||||
linkage]
|
linkage]
|
||||||
[(ReturnLinkage/NonTail? linkage)
|
[else
|
||||||
(make-LabelLinkage after-body-code)]
|
(make-LabelLinkage after-body-code)])]
|
||||||
[(LabelLinkage? linkage)
|
[(LabelLinkage? linkage)
|
||||||
(make-LabelLinkage after-body-code)]
|
(make-LabelLinkage after-body-code)]
|
||||||
[(LabelLinkage/Expects? linkage)
|
[(LabelLinkage/Expects? linkage)
|
||||||
|
@ -1522,8 +1533,6 @@
|
||||||
`(,(make-PopControlFrame)))))))
|
`(,(make-PopControlFrame)))))))
|
||||||
|
|
||||||
(cond
|
(cond
|
||||||
[(ReturnLinkage/NonTail? linkage)
|
|
||||||
(in-return-context)]
|
|
||||||
[(ReturnLinkage? linkage)
|
[(ReturnLinkage? linkage)
|
||||||
(in-return-context)]
|
(in-return-context)]
|
||||||
[(NextLinkage? linkage)
|
[(NextLinkage? linkage)
|
||||||
|
|
|
@ -425,12 +425,9 @@
|
||||||
;; Both ReturnLinkage and ReturnLinkage/NonTail deal with multiple
|
;; Both ReturnLinkage and ReturnLinkage/NonTail deal with multiple
|
||||||
;; values indirectly, through the alternative multiple-value-return
|
;; values indirectly, through the alternative multiple-value-return
|
||||||
;; address in the LinkedLabel of their call frame.
|
;; address in the LinkedLabel of their call frame.
|
||||||
(define-struct: ReturnLinkage ())
|
(define-struct: ReturnLinkage ([tail? : Boolean]))
|
||||||
(define return-linkage (make-ReturnLinkage))
|
(define return-linkage (make-ReturnLinkage #t))
|
||||||
|
(define return-linkage/nontail (make-ReturnLinkage #f))
|
||||||
(define-struct: ReturnLinkage/NonTail ())
|
|
||||||
(define return-linkage/nontail (make-ReturnLinkage/NonTail))
|
|
||||||
|
|
||||||
|
|
||||||
(define-type Linkage (U NextLinkage
|
(define-type Linkage (U NextLinkage
|
||||||
NextLinkage/Expects
|
NextLinkage/Expects
|
||||||
|
@ -438,8 +435,7 @@
|
||||||
LabelLinkage
|
LabelLinkage
|
||||||
LabelLinkage/Expects
|
LabelLinkage/Expects
|
||||||
|
|
||||||
ReturnLinkage
|
ReturnLinkage))
|
||||||
ReturnLinkage/NonTail))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user