ExecutableFunction.st
author Claus Gittinger <cg@exept.de>
Thu, 23 Nov 1995 12:17:00 +0100
changeset 623 6795a71e39d1
parent 530 07d0bce293c9
child 829 fc386319f41c
permissions -rw-r--r--
checkin from browser
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
     1
"
1eba5946aea2 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1994 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 131
diff changeset
     3
	      All Rights Reserved
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
     4
1eba5946aea2 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
1eba5946aea2 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
1eba5946aea2 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
1eba5946aea2 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
1eba5946aea2 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    11
"
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    12
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    13
Object subclass:#ExecutableFunction
623
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    14
	 instanceVariableNames:'code*'
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    15
	 classVariableNames:'ExecutionErrorSignal InvalidCodeSignal'
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    16
	 poolDictionaries:''
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    17
	 category:'Kernel-Methods'
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    18
!
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    19
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    20
!ExecutableFunction class methodsFor:'documentation'!
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    21
88
81dacba7a63a *** empty log message ***
claus
parents: 84
diff changeset
    22
copyright
81dacba7a63a *** empty log message ***
claus
parents: 84
diff changeset
    23
"
81dacba7a63a *** empty log message ***
claus
parents: 84
diff changeset
    24
 COPYRIGHT (c) 1994 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 131
diff changeset
    25
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 84
diff changeset
    26
81dacba7a63a *** empty log message ***
claus
parents: 84
diff changeset
    27
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 84
diff changeset
    28
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 84
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 84
diff changeset
    30
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 84
diff changeset
    31
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 84
diff changeset
    32
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 84
diff changeset
    33
"
81dacba7a63a *** empty log message ***
claus
parents: 84
diff changeset
    34
!
81dacba7a63a *** empty log message ***
claus
parents: 84
diff changeset
    35
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    36
documentation
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    37
"
88
81dacba7a63a *** empty log message ***
claus
parents: 84
diff changeset
    38
    This is an abstract class, to merge common attributes of all kinds of
357
claus
parents: 345
diff changeset
    39
    executable code objects; i.e. non-ST functions, Blocks and Methods
claus
parents: 345
diff changeset
    40
    and whatever there might be in the future.
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    41
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    42
    Instance variables:
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    43
225
7c8e57cc5b13 commenting
claus
parents: 159
diff changeset
    44
      code        <not_an_object>   the function pointer to the machine code.
7c8e57cc5b13 commenting
claus
parents: 159
diff changeset
    45
				    Not accessable from smalltalk code.
328
claus
parents: 326
diff changeset
    46
				    (notice the '*' in the instVarNames definition)
225
7c8e57cc5b13 commenting
claus
parents: 159
diff changeset
    47
7c8e57cc5b13 commenting
claus
parents: 159
diff changeset
    48
107
f3e3e2dad7fd *** empty log message ***
claus
parents: 92
diff changeset
    49
225
7c8e57cc5b13 commenting
claus
parents: 159
diff changeset
    50
    Class variables:
7c8e57cc5b13 commenting
claus
parents: 159
diff changeset
    51
7c8e57cc5b13 commenting
claus
parents: 159
diff changeset
    52
      ExecutionErrorSignal          parent of all execution errors
7c8e57cc5b13 commenting
claus
parents: 159
diff changeset
    53
				    (not raised itself)
7c8e57cc5b13 commenting
claus
parents: 159
diff changeset
    54
7c8e57cc5b13 commenting
claus
parents: 159
diff changeset
    55
      InvalidCodeSignal             codeObject is not executable
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    56
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    57
    NOTICE: layout known by runtime system and compiler - do not change
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    58
"
623
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    59
!
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    60
623
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    61
version
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    62
    ^ '$Header: /cvs/stx/stx/libbasic/ExecutableFunction.st,v 1.18 1995-11-23 11:17:00 cg Exp $'
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    63
! !
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    64
107
f3e3e2dad7fd *** empty log message ***
claus
parents: 92
diff changeset
    65
!ExecutableFunction class methodsFor:'initialization'!
f3e3e2dad7fd *** empty log message ***
claus
parents: 92
diff changeset
    66
f3e3e2dad7fd *** empty log message ***
claus
parents: 92
diff changeset
    67
initialize
f3e3e2dad7fd *** empty log message ***
claus
parents: 92
diff changeset
    68
    InvalidCodeSignal isNil ifTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 131
diff changeset
    69
	ExecutionErrorSignal := ErrorSignal newSignalMayProceed:true.
514c749165c3 *** empty log message ***
claus
parents: 131
diff changeset
    70
	ExecutionErrorSignal nameClass:self message:#executionErrorSignal.
514c749165c3 *** empty log message ***
claus
parents: 131
diff changeset
    71
	ExecutionErrorSignal notifierString:'execution error'.
514c749165c3 *** empty log message ***
claus
parents: 131
diff changeset
    72
514c749165c3 *** empty log message ***
claus
parents: 131
diff changeset
    73
	InvalidCodeSignal := ExecutionErrorSignal newSignalMayProceed:true.
514c749165c3 *** empty log message ***
claus
parents: 131
diff changeset
    74
	InvalidCodeSignal nameClass:self message:#invalidCodeSignal.
514c749165c3 *** empty log message ***
claus
parents: 131
diff changeset
    75
	InvalidCodeSignal notifierString:'invalid code-object - not executable'.
107
f3e3e2dad7fd *** empty log message ***
claus
parents: 92
diff changeset
    76
    ]
f3e3e2dad7fd *** empty log message ***
claus
parents: 92
diff changeset
    77
! !
f3e3e2dad7fd *** empty log message ***
claus
parents: 92
diff changeset
    78
345
claus
parents: 328
diff changeset
    79
!ExecutableFunction class methodsFor:'Signal constants'!
159
514c749165c3 *** empty log message ***
claus
parents: 131
diff changeset
    80
514c749165c3 *** empty log message ***
claus
parents: 131
diff changeset
    81
executionErrorSignal
514c749165c3 *** empty log message ***
claus
parents: 131
diff changeset
    82
    "return the parent-signal of all execution errors"
514c749165c3 *** empty log message ***
claus
parents: 131
diff changeset
    83
514c749165c3 *** empty log message ***
claus
parents: 131
diff changeset
    84
    ^ ExecutionErrorSignal
514c749165c3 *** empty log message ***
claus
parents: 131
diff changeset
    85
! !
514c749165c3 *** empty log message ***
claus
parents: 131
diff changeset
    86
623
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    87
!ExecutableFunction class methodsFor:'queries'!
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    88
623
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    89
isBuiltInClass
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    90
    "this class is known by the run-time-system"
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    91
623
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    92
    ^ true
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    93
! !
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    94
623
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    95
!ExecutableFunction methodsFor:'accessing'!
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    96
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    97
code
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    98
    "return the code field. This is not an object but the address of the machine instructions. 
1eba5946aea2 Initial revision
claus
parents:
diff changeset
    99
     Therefore an integer representing the code-address is returned"
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   100
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   101
%{  /* NOCONTEXT */
357
claus
parents: 345
diff changeset
   102
    extern OBJ __MKUINT();
claus
parents: 345
diff changeset
   103
    unsigned addr;
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   104
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   105
    if (_INST(code_) != nil) {
357
claus
parents: 345
diff changeset
   106
	addr = (int)_INST(code_);
claus
parents: 345
diff changeset
   107
	if (addr <= _MAX_INT) {
claus
parents: 345
diff changeset
   108
	    RETURN ( __MKSMALLINT(addr) );
claus
parents: 345
diff changeset
   109
	}
claus
parents: 345
diff changeset
   110
	RETURN ( __MKUINT(addr));
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   111
    }
328
claus
parents: 326
diff changeset
   112
%}.
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   113
    ^ nil
623
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   114
!
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   115
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   116
instVarAt:index
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   117
    "have to catch instVar access to code - since its no object"
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   118
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   119
    (index == 1) ifTrue:[^ self code].
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   120
    ^ super instVarAt:index
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   121
!
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   122
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   123
instVarAt:index put:value
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   124
    "have to catch instVar access to code - since its no object"
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   125
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   126
    (index == 1) ifTrue:[^ self code:value].
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   127
    ^ super instVarAt:index put:value
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   128
! !
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   129
623
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   130
!ExecutableFunction methodsFor:'binary storage'!
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   131
623
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   132
readBinaryContentsFrom: stream manager: manager
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   133
    "make certain, that no invalid function addresses are created."
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   134
623
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   135
    super readBinaryContentsFrom: stream manager: manager.
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   136
    self code:nil.
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   137
! !
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   138
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   139
!ExecutableFunction methodsFor:'error handling'!
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   140
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   141
invalidCode
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   142
    "this error is triggered by the interpreter when something is wrong
107
f3e3e2dad7fd *** empty log message ***
claus
parents: 92
diff changeset
   143
     with the code object (any error not handled by Method-signals).
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   144
     In this case, the VM sends this to the bad method/block (the receiver).
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   145
     Can only happen when the Compiler/runtime system is broken or
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   146
     someone played around."
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   147
131
39599c151f30 return value of signal raise
claus
parents: 107
diff changeset
   148
    ^ InvalidCodeSignal raise.
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   149
! !
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   150
357
claus
parents: 345
diff changeset
   151
!ExecutableFunction methodsFor:'printing & storing'!
claus
parents: 345
diff changeset
   152
claus
parents: 345
diff changeset
   153
printOn:aStream
claus
parents: 345
diff changeset
   154
    |addr|
claus
parents: 345
diff changeset
   155
claus
parents: 345
diff changeset
   156
    addr := self code.
claus
parents: 345
diff changeset
   157
    addr isNil ifTrue:[^ super printOn:aStream].
claus
parents: 345
diff changeset
   158
claus
parents: 345
diff changeset
   159
    aStream nextPutAll:self class name; nextPutAll:'(address: 0x';
claus
parents: 345
diff changeset
   160
	    nextPutAll:(addr printStringRadix:16); nextPutAll:')'
claus
parents: 345
diff changeset
   161
! !
claus
parents: 345
diff changeset
   162
623
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   163
!ExecutableFunction methodsFor:'private accessing'!
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   164
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   165
code:anAddress
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   166
    "set the code field - DANGER ALERT. 
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   167
     This is not an object but the address of the machine instructions.
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   168
     Therefore the argument must be an integer representing this address.
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   169
     You can crash Smalltalk very badly when playing around here ...
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   170
     This method is for compiler support and very special cases (debugging) only
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   171
     - do not use"
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   172
623
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   173
%{  /* NOCONTEXT */
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   174
623
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   175
    if (__isSmallInteger(anAddress))
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   176
	_INST(code_) = (OBJ)(_intVal(anAddress));
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   177
    else {
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   178
	_INST(code_) = (OBJ)(__longIntVal(anAddress));
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   179
    }
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   180
%}
84
1eba5946aea2 Initial revision
claus
parents:
diff changeset
   181
! !
623
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   182
6795a71e39d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   183
ExecutableFunction initialize!