in the middle of changing those compile-time errors to runtime ones.

This commit is contained in:
Danny Yoo 2011-04-17 14:45:15 -04:00
parent 832df0a2be
commit 3c08b75f44
2 changed files with 66 additions and 44 deletions

View File

@ -531,8 +531,10 @@
[(Prefix? op-knowledge) [(Prefix? op-knowledge)
(error 'impossible)] (error 'impossible)]
[(Const? op-knowledge) [(Const? op-knowledge)
;; FIXME: this needs to be a runtime error to preserve Racket's semantics. (make-instruction-sequence `(,(make-AssignImmediateStatement 'proc op-knowledge)
(error 'application "Can't apply constant ~s as a function" (Const-const op-knowledge))])))) ,(make-PerformStatement
(make-RaiseOperatorApplicationError! (make-Reg 'proc)))))]))))
(: compile-general-application (App CompileTimeEnvironment Target Linkage -> InstructionSequence)) (: compile-general-application (App CompileTimeEnvironment Target Linkage -> InstructionSequence))
@ -829,15 +831,16 @@
(StaticallyKnownLam App CompileTimeEnvironment Target Linkage (StaticallyKnownLam App CompileTimeEnvironment Target Linkage
-> InstructionSequence)) -> InstructionSequence))
(define (compile-statically-known-lam-application static-knowledge exp cenv target linkage) (define (compile-statically-known-lam-application static-knowledge exp cenv target linkage)
(unless (arity-matches? (StaticallyKnownLam-arity static-knowledge) (let ([arity-check
(cond [(arity-matches? (StaticallyKnownLam-arity static-knowledge)
(length (App-operands exp))) (length (App-operands exp)))
;; FIXME: this needs to be turned into a runtime error, not a compile-time error, to preserve empty-instruction-sequence]
;; Racket semantics. [else
(error 'arity-mismatch "~s expected ~s arguments, but received ~s" (make-instruction-sequence
(StaticallyKnownLam-name static-knowledge) `(,(make-PerformStatement
(make-RaiseArityMismatchError!
(StaticallyKnownLam-arity static-knowledge) (StaticallyKnownLam-arity static-knowledge)
(length (App-operands exp)))) (make-Const (length (App-operands exp)))))))])])
(let* ([extended-cenv (let* ([extended-cenv
(extend-compile-time-environment/scratch-space (extend-compile-time-environment/scratch-space
cenv cenv
@ -865,12 +868,13 @@
empty-instruction-sequence) empty-instruction-sequence)
proc-code proc-code
(juggle-operands operand-codes) (juggle-operands operand-codes)
arity-check
(compile-procedure-call/statically-known-lam static-knowledge (compile-procedure-call/statically-known-lam static-knowledge
cenv cenv
extended-cenv extended-cenv
(length (App-operands exp)) (length (App-operands exp))
target target
linkage)))) linkage)))))
(: juggle-operands ((Listof InstructionSequence) -> InstructionSequence)) (: juggle-operands ((Listof InstructionSequence) -> InstructionSequence))

View File

@ -325,6 +325,22 @@
(define-struct: RaiseContextExpectedValuesError! ([expected : Natural]) (define-struct: RaiseContextExpectedValuesError! ([expected : Natural])
#:transparent) #:transparent)
;; Raises an exception that says that we're doing a
;; procedure application, but got sent an incorrect number.
(define-struct: RaiseArityMismatchError! ([expected : Arity]
[received : OpArg])
#:transparent)
;; Raises an exception that says that we're doing a
;; procedure application, but got sent an incorrect number.
(define-struct: RaiseOperatorApplicationError! ([operator : OpArg])
#: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)
@ -351,6 +367,8 @@
UnspliceRestFromStack! UnspliceRestFromStack!
RaiseContextExpectedValuesError! RaiseContextExpectedValuesError!
RaiseArityMismatchError!
RaiseOperatorApplicationError!
RestoreEnvironment! RestoreEnvironment!
RestoreControl!)) RestoreControl!))