CompCode.st
author claus
Mon, 10 Oct 1994 01:29:28 +0100
changeset 159 514c749165c3
parent 131 39599c151f30
child 225 7c8e57cc5b13
permissions -rw-r--r--
*** empty log message ***

"
 COPYRIGHT (c) 1994 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

ExecutableFunction subclass:#ExecutableCodeObject
       instanceVariableNames:'byteCode literals'
       classVariableNames:'NoByteCodeSignal InvalidByteCodeSignal
			   InvalidInstructionSignal BadLiteralsSignal
			   NonBooleanReceiverSignal ArgumentSignal'
       poolDictionaries:''
       category:'Kernel-Methods'
!

ExecutableCodeObject comment:'
COPYRIGHT (c) 1994 by Claus Gittinger
	      All Rights Reserved

$Header: /cvs/stx/stx/libbasic/Attic/CompCode.st,v 1.6 1994-10-10 00:25:41 claus Exp $
'!

!ExecutableCodeObject class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1994 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

version
"
$Header: /cvs/stx/stx/libbasic/Attic/CompCode.st,v 1.6 1994-10-10 00:25:41 claus Exp $
"
!

documentation
"
    This is an abstract class, to merge common attributes of Blocks and
    Methods i.e. describe all objects consisting of compiled or interpreted code.

    Instance variables:

    byteCode    <ByteArray>       bytecode if its an interpreted codeobject
    literals    <Array>           the block/methods literal array

    NOTICE: layout known by runtime system and compiler - do not change
"
! !

!ExecutableCodeObject class methodsFor:'initialization'!

initialize
    NoByteCodeSignal isNil ifTrue:[
	ExecutableFunction initialize.

	NoByteCodeSignal := ExecutionErrorSignal newSignalMayProceed:true.
	NoByteCodeSignal nameClass:self message:#noByteCodeSignal.
	NoByteCodeSignal notifierString:'nil byteCode in code-object - not executable'.

	InvalidByteCodeSignal := ExecutionErrorSignal newSignalMayProceed:true.
	InvalidByteCodeSignal nameClass:self message:#invalidByteCodeSignal.
	InvalidByteCodeSignal notifierString:'invalid byteCode in code-object - not executable'.

	InvalidInstructionSignal := ExecutionErrorSignal newSignalMayProceed:true.
	InvalidInstructionSignal nameClass:self message:#invalidInstructionSignal.
	InvalidInstructionSignal notifierString:'invalid instruction in code-object - not executable'.

	BadLiteralsSignal := ExecutionErrorSignal newSignalMayProceed:true.
	BadLiteralsSignal nameClass:self message:#badLiteralsSignal.
	BadLiteralsSignal notifierString:'bad literal table in code-object - should not happen'.

	NonBooleanReceiverSignal := ExecutionErrorSignal newSignalMayProceed:true.
	NonBooleanReceiverSignal nameClass:self message:#nonBooleanReceiverSignal.
	NonBooleanReceiverSignal notifierString:'if/while on non-boolean receiver'.

	ArgumentSignal := ExecutionErrorSignal newSignalMayProceed:true.
	ArgumentSignal nameClass:self message:#argumentSignal.
	ArgumentSignal notifierString:'bad argument(s)'.
    ]
! !

!ExecutableCodeObject class methodsFor:'signal access'!

executionErrorSignal
    "return the parent-signal of all execution errors"

    ^ ExecutionErrorSignal
!

argumentSignal
    "return the signal raised when something's wrong with the
     arguments"

    ^ ArgumentSignal
! !

!ExecutableCodeObject class methodsFor:'queries'!

isBuiltInClass
    "this class is known by the run-time-system"

    ^ true
! !

!ExecutableCodeObject methodsFor:'accessing'!

byteCode
    "return the bytecode (a ByteArray)"

    ^ byteCode
!

literals
    "return the literal array"

    ^ literals
! !

!ExecutableCodeObject methodsFor:'private accessing'!

byteCode:aByteArray
    "set the bytecode field - DANGER ALERT"

    byteCode := aByteArray
!

literals:aLiteralArray 
    "set the literal array for evaluation - DANGER ALERT"

    literals := aLiteralArray
! !

!ExecutableCodeObject methodsFor:'error handling'!

noByteCode
    "this error is triggered when the interpreter tries to execute a
     code object, where the byteCode is nil.
     Can only happen when Compiler/runtime system is broken or
     someone played around with a block/method."

    ^ NoByteCodeSignal raise.
!

invalidByteCode
    "this error is triggered when the interpreter tries to execute a
     code object, where the byteCode is nonNil, but not a ByteArray.
     Can only happen when Compiler/runtime system is broken or
     someone played around with a block/method."

    ^ InvalidByteCodeSignal raise.
!

invalidInstruction
    "this error is triggered when the bytecode-interpreter tries to
     execute an invalid bytecode instruction.
     Can only happen when Compiler/runtime system is broken or
     someone played around with the block/methods code."

    ^ InvalidInstructionSignal raise.
!

badLiteralTable
    "this error is triggered, when a block/method is called with a bad literal
     array (i.e. non-array) - this can only happen, if the
     compiler is broken or someone played around with a block/methods
     literal table or the GC is broken and corrupted it."

    ^ BadLiteralsSignal raise.
!

receiverNotBoolean:anObject
    "this error is triggered when the bytecode-interpreter tries to
     execute ifTrue:/ifFalse or whileTrue: type of expressions where the
     receiver is neither true nor false."

    ^ NonBooleanReceiverSignal raise.
!

tooManyArguments
    "this error is triggered, when a method/block tries to perform a send with
     more arguments than supported by the interpreter. This can only happen,
     if the compiler has been changed without updating the VM."

    ^ ArgumentSignal
	raiseRequestWith:self
	errorString:'too many args in send'
!

badArgumentArray
    "this error is triggered, if a non array is passed to #perform:with:
     or #value:with:."

    ^ ArgumentSignal
	raiseRequestWith:self
	errorString:'argumentArray must be an Array'
! !