continuing to work on multiple value stuff
This commit is contained in:
parent
3cb40ab499
commit
a9b3ee7bb9
|
@ -230,6 +230,8 @@ EOF
|
||||||
[(FixClosureShellMap!? op)
|
[(FixClosureShellMap!? op)
|
||||||
empty]
|
empty]
|
||||||
[(InstallContinuationMarkEntry!? op)
|
[(InstallContinuationMarkEntry!? op)
|
||||||
|
empty]
|
||||||
|
[(RaiseContextExpectedValuesError!? op)
|
||||||
empty]))
|
empty]))
|
||||||
|
|
||||||
(unique/eq?
|
(unique/eq?
|
||||||
|
@ -594,7 +596,10 @@ EOF
|
||||||
[(InstallContinuationMarkEntry!? op)
|
[(InstallContinuationMarkEntry!? op)
|
||||||
(string-append "RUNTIME.installContinuationMarkEntry(MACHINE,"
|
(string-append "RUNTIME.installContinuationMarkEntry(MACHINE,"
|
||||||
"MACHINE.control[MACHINE.control.length-1].pendingContinuationMarkKey,"
|
"MACHINE.control[MACHINE.control.length-1].pendingContinuationMarkKey,"
|
||||||
"MACHINE.val);")]))
|
"MACHINE.val);")]
|
||||||
|
[(RaiseContextExpectedValuesError!? op)
|
||||||
|
(format "RUNTIME.raiseContextExpectedValuesError(MACHINE, ~a);"
|
||||||
|
(RaiseContextExpectedValuesError!-expected op))]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
49
compiler.rkt
49
compiler.rkt
|
@ -216,6 +216,8 @@
|
||||||
,(make-GotoStatement (make-Reg 'proc))))]
|
,(make-GotoStatement (make-Reg 'proc))))]
|
||||||
[(NextLinkage? linkage)
|
[(NextLinkage? linkage)
|
||||||
empty-instruction-sequence]
|
empty-instruction-sequence]
|
||||||
|
[(NextLinkage/Expects? linkage)
|
||||||
|
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)))))]))
|
||||||
|
|
||||||
|
@ -1039,6 +1041,46 @@
|
||||||
(make-instruction-sequence
|
(make-instruction-sequence
|
||||||
`(,(make-AssignImmediateStatement target (make-Reg 'val))))))])]
|
`(,(make-AssignImmediateStatement target (make-Reg 'val))))))])]
|
||||||
|
|
||||||
|
[(NextLinkage/Expects? linkage)
|
||||||
|
(cond [(eq? target 'val)
|
||||||
|
;; This case happens for a function call that isn't in
|
||||||
|
;; tail position.
|
||||||
|
(let* ([proc-return-multiple (make-label 'procReturnMultiple)]
|
||||||
|
[proc-return (make-LinkedLabel (make-label 'procReturn)
|
||||||
|
proc-return-multiple)])
|
||||||
|
(append-instruction-sequences
|
||||||
|
(make-instruction-sequence
|
||||||
|
`(,(make-PushControlFrame/Call proc-return)))
|
||||||
|
maybe-install-jump-address
|
||||||
|
(make-instruction-sequence
|
||||||
|
`(,(make-GotoStatement entry-point-target)))
|
||||||
|
proc-return-multiple
|
||||||
|
(make-instruction-sequence `(,(make-PopEnvironment (make-Reg 'argcount)
|
||||||
|
(make-Const 0))))
|
||||||
|
proc-return))]
|
||||||
|
|
||||||
|
[else
|
||||||
|
;; This case happens for evaluating arguments, since the
|
||||||
|
;; arguments are being installed into the scratch space.
|
||||||
|
(let* ([proc-return-multiple (make-label 'procReturnMultiple)]
|
||||||
|
[proc-return (make-LinkedLabel (make-label 'procReturn)
|
||||||
|
proc-return-multiple)])
|
||||||
|
(append-instruction-sequences
|
||||||
|
(make-instruction-sequence
|
||||||
|
`(,(make-PushControlFrame/Call proc-return)))
|
||||||
|
maybe-install-jump-address
|
||||||
|
(make-instruction-sequence
|
||||||
|
`(,(make-GotoStatement entry-point-target)))
|
||||||
|
proc-return-multiple
|
||||||
|
;; FIMXE: this needs to raise a runtime error!
|
||||||
|
(make-instruction-sequence `(,(make-PopEnvironment (make-Reg 'argcount)
|
||||||
|
(make-Const 0))))
|
||||||
|
proc-return
|
||||||
|
(make-instruction-sequence
|
||||||
|
`(,(make-AssignImmediateStatement target (make-Reg 'val))))))])]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[(LabelLinkage? linkage)
|
[(LabelLinkage? 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
|
||||||
|
@ -1131,6 +1173,8 @@
|
||||||
(cond
|
(cond
|
||||||
[(NextLinkage? linkage)
|
[(NextLinkage? linkage)
|
||||||
linkage]
|
linkage]
|
||||||
|
[(NextLinkage/Expects? linkage)
|
||||||
|
linkage]
|
||||||
[(ReturnLinkage? linkage)
|
[(ReturnLinkage? linkage)
|
||||||
linkage]
|
linkage]
|
||||||
[(ReturnLinkage/NonTail? linkage)
|
[(ReturnLinkage/NonTail? linkage)
|
||||||
|
@ -1165,6 +1209,8 @@
|
||||||
(cond
|
(cond
|
||||||
[(NextLinkage? linkage)
|
[(NextLinkage? linkage)
|
||||||
linkage]
|
linkage]
|
||||||
|
[(NextLinkage/Expects? linkage)
|
||||||
|
linkage]
|
||||||
[(ReturnLinkage? linkage)
|
[(ReturnLinkage? linkage)
|
||||||
linkage]
|
linkage]
|
||||||
[(ReturnLinkage/NonTail? linkage)
|
[(ReturnLinkage/NonTail? linkage)
|
||||||
|
@ -1207,6 +1253,8 @@
|
||||||
[letrec-linkage : Linkage (cond
|
[letrec-linkage : Linkage (cond
|
||||||
[(NextLinkage? linkage)
|
[(NextLinkage? linkage)
|
||||||
linkage]
|
linkage]
|
||||||
|
[(NextLinkage/Expects? linkage)
|
||||||
|
linkage]
|
||||||
[(ReturnLinkage? linkage)
|
[(ReturnLinkage? linkage)
|
||||||
linkage]
|
linkage]
|
||||||
[(ReturnLinkage/NonTail? linkage)
|
[(ReturnLinkage/NonTail? linkage)
|
||||||
|
@ -1287,6 +1335,7 @@
|
||||||
(compile (WithContMark-body exp) cenv target linkage))]
|
(compile (WithContMark-body exp) cenv target linkage))]
|
||||||
|
|
||||||
[(or (NextLinkage? linkage)
|
[(or (NextLinkage? linkage)
|
||||||
|
(NextLinkage/Expects? linkage)
|
||||||
(LabelLinkage? linkage))
|
(LabelLinkage? linkage))
|
||||||
(end-with-linkage
|
(end-with-linkage
|
||||||
linkage cenv
|
linkage cenv
|
||||||
|
|
|
@ -314,6 +314,11 @@
|
||||||
[closed-vals : (Listof Natural)])
|
[closed-vals : (Listof Natural)])
|
||||||
#:transparent)
|
#:transparent)
|
||||||
|
|
||||||
|
;; Raises an exception that says that we expected a number of values.
|
||||||
|
;; Assume that argcount is not equal to expected.
|
||||||
|
(define-struct: RaiseContextExpectedValuesError! ([expected : Natural])
|
||||||
|
#:transparent)
|
||||||
|
|
||||||
;; Changes over the control located at the given argument from the structure in env[1]
|
;; Changes over the control located at the given argument from the structure in env[1]
|
||||||
(define-struct: RestoreControl! ([tag : (U DefaultContinuationPromptTag OpArg)]) #:transparent)
|
(define-struct: RestoreControl! ([tag : (U DefaultContinuationPromptTag OpArg)]) #:transparent)
|
||||||
|
|
||||||
|
@ -339,6 +344,8 @@
|
||||||
SpliceListIntoStack!
|
SpliceListIntoStack!
|
||||||
UnspliceRestFromStack!
|
UnspliceRestFromStack!
|
||||||
|
|
||||||
|
RaiseContextExpectedValuesError!
|
||||||
|
|
||||||
RestoreEnvironment!
|
RestoreEnvironment!
|
||||||
RestoreControl!))
|
RestoreControl!))
|
||||||
|
|
||||||
|
@ -376,6 +383,12 @@
|
||||||
(define-struct: NextLinkage ())
|
(define-struct: NextLinkage ())
|
||||||
(define next-linkage (make-NextLinkage))
|
(define next-linkage (make-NextLinkage))
|
||||||
|
|
||||||
|
;; NextLinkage/Expects works like NextLinkage, but should check that
|
||||||
|
;; it is returning 'expects' values back.
|
||||||
|
(define-struct: NextLinkage/Expects ([expects : Natural]))
|
||||||
|
(define next-linkage-expects-single (make-NextLinkage/Expects 1))
|
||||||
|
|
||||||
|
|
||||||
(define-struct: ReturnLinkage ())
|
(define-struct: ReturnLinkage ())
|
||||||
(define return-linkage (make-ReturnLinkage))
|
(define return-linkage (make-ReturnLinkage))
|
||||||
|
|
||||||
|
@ -385,8 +398,11 @@
|
||||||
(define-struct: LabelLinkage ([label : Symbol]))
|
(define-struct: LabelLinkage ([label : Symbol]))
|
||||||
|
|
||||||
(define-type Linkage (U NextLinkage
|
(define-type Linkage (U NextLinkage
|
||||||
|
NextLinkage/Expects
|
||||||
|
|
||||||
ReturnLinkage
|
ReturnLinkage
|
||||||
ReturnLinkage/NonTail
|
ReturnLinkage/NonTail
|
||||||
|
|
||||||
LabelLinkage))
|
LabelLinkage))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -254,6 +254,12 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var raiseContextExpectedValuesError = function(MACHINE, expected) {
|
||||||
|
raise(MACHINE,
|
||||||
|
new Error("expected " + expected +
|
||||||
|
" values, received " +
|
||||||
|
MACHINE.argcount + " values"));
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// captureControl implements the continuation-capturing part of
|
// captureControl implements the continuation-capturing part of
|
||||||
|
@ -1069,6 +1075,8 @@
|
||||||
exports['testArgument'] = testArgument;
|
exports['testArgument'] = testArgument;
|
||||||
exports['testArity'] = testArity;
|
exports['testArity'] = testArity;
|
||||||
exports['raise'] = raise;
|
exports['raise'] = raise;
|
||||||
|
exports['raiseContextExpectedValuesError'] = raiseContextExpectedValuesError;
|
||||||
|
|
||||||
|
|
||||||
exports['captureControl'] = captureControl;
|
exports['captureControl'] = captureControl;
|
||||||
exports['restoreControl'] = restoreControl;
|
exports['restoreControl'] = restoreControl;
|
||||||
|
|
|
@ -383,6 +383,11 @@
|
||||||
(ensure-primitive-value key)
|
(ensure-primitive-value key)
|
||||||
(ensure-primitive-value val))
|
(ensure-primitive-value val))
|
||||||
'ok)]
|
'ok)]
|
||||||
|
|
||||||
|
[(RaiseContextExpectedValuesError!? op)
|
||||||
|
(error "context expected ~a values, received ~a values."
|
||||||
|
(RaiseContextExpectedValuesError!-expected op)
|
||||||
|
(machine-argcount m))]
|
||||||
)))
|
)))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user