ExternalAddress.st
author Stefan Vogel <sv@exept.de>
Fri, 20 Jan 2017 19:59:28 +0100
changeset 21267 4c1185a27941
parent 20967 ba69e999a1d6
child 21024 8734987eb5c7
child 21413 e578b0899450
permissions -rw-r--r--
#BUGFIX by stefan class: Collection comment/format in: #union: #xor: changed: # #difference: #intersect: #select: (send #speciesForAdding instead of #species) make set operations work with Dictionaries
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
	      All Rights Reserved
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
6491
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
    12
"{ Package: 'stx:libbasic' }"
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
    13
18828
919987dab72c #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 14648
diff changeset
    14
"{ NameSpace: Smalltalk }"
919987dab72c #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 14648
diff changeset
    15
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
Object subclass:#ExternalAddress
1267
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    17
	instanceVariableNames:'address*'
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    18
	classVariableNames:''
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    19
	poolDictionaries:''
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    20
	category:'System-Support'
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!ExternalAddress class methodsFor:'documentation'!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
copyright
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
 COPYRIGHT (c) 1995 by Claus Gittinger
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
	      All Rights Reserved
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 This software is furnished under a license and may be used
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 hereby transferred.
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
"
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
documentation
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
"
19513
0423b94b4789 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19485
diff changeset
    41
    Instances of this class represent external (non-Smalltalk) memory addresses.
0423b94b4789 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19485
diff changeset
    42
    They are only useful to represent handles as returned by C functions,
0423b94b4789 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19485
diff changeset
    43
    or to pass them to C functions. 
0423b94b4789 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19485
diff changeset
    44
    For example, Window- or WidgetIDs (which are actually 32 bit pointers) can be represented this way,
0423b94b4789 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19485
diff changeset
    45
    but better create a handle-subclass for it, to care for proper finalization.
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    (you should not use SmallIntegers for this, since they can only represent 31
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
     bits; LargeIntegers could be used in theory, but it is not a very good style
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
     to do so, since it makes things a bit cryptic - having ExternalAddresses
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
     around makes things pretty clear in inspectors etc.).
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
19513
0423b94b4789 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19485
diff changeset
    51
    There is not much you can do with ExternalAddresses on the Smalltalk level;
8463
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
    52
    creation/use should be done in primitive C-code via 
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
    53
       __MKEXTERNALADDRESS(voidPtr) and __ExternalAddressVal(obj).
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
19513
0423b94b4789 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19485
diff changeset
    55
    ExternalAddresses are much like ExternalBytes - however, ExternalAddresses do not know
0423b94b4789 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19485
diff changeset
    56
    the size of the memory block and therefore do not allow you to access bytes via indexed at:/at:put: messages
0423b94b4789 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19485
diff changeset
    57
    (which ExternalBytes do).
0423b94b4789 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19485
diff changeset
    58
    ExternalAddresses are meant to remain anonymous, opaque handles.
8463
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
    59
    Also, memory blocks which are freeable should be represented as ExternalBytes.
1286
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1267
diff changeset
    60
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1267
diff changeset
    61
    [author:]
8463
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
    62
        Claus Gittinger
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
    63
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
    64
    [see also:]
8463
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
    65
        ByteArray
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
    66
        ExternalBytes ExternalFunction
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
    67
        ( how to write primitive code :html: programming/primitive.html )
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
"
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
examples
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
"
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    To pass some C-pointer from primitive code to smalltalk:
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
	...
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
	RETURN (__MKEXTERNALADDRESS(foo));
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
    pass it back to C and use it there:
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
	...
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
	if (__isExternalAddress(anExternalAddress)) {
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
	    ptr = __externalAddressVal(anExternalAddress));
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
	}
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
	...
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
    concrete example:
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
	test1
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
	%{
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
	    static char foo[] = {'h', 'e' ,'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '\n'};
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
	    RETURN (__MKEXTERNALADDRESS(foo));
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
	%}
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
	test2:anExternalAddress
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
	%{
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
	    if (__isExternalAddress(anExternalAddress)) {
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
		printf(__externalAddressVal(anExternalAddress));
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
		RETURN (self);
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
	    }
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
	%}
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
"
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
! !
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
3957
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   105
!ExternalAddress class methodsFor:'instance creation'!
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   106
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   107
newAddress:addr
20967
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   108
    "return a new externalAddress (pointer), pointing to addr."
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   109
3957
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   110
    ^ self new setAddress:addr
20967
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   111
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   112
    "Modified (comment): / 15-11-2016 / 11:57:34 / cg"
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   113
!
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   114
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   115
newAddressFromBytes:bytesContainingAddress
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   116
    "return a new externalAddress (pointer), pointing to the addr contained in the argument.
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   117
     The argument must be a byteArray-like object, whose first pointerSize bytes are extracted"
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   118
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   119
    ^ (bytesContainingAddress pointerAt:1)
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   120
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   121
    "
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   122
     |bytes ptr|
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   123
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   124
     bytes := ByteArray new:(ExternalAddress pointerSize).
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   125
     bytes pointerAt:1 put:16r12345678.
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   126
     ptr := ExternalAddress newAddressFromBytes:bytes.
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   127
     self assert:(ptr address = 16r12345678).
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   128
    "
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   129
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   130
    "Created: / 15-11-2016 / 12:53:21 / cg"
3957
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   131
! !
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   132
13183
4d031c796ecc added: #fromAddress:
Claus Gittinger <cg@exept.de>
parents: 13180
diff changeset
   133
!ExternalAddress class methodsFor:'Compatibility-V''Age'!
4d031c796ecc added: #fromAddress:
Claus Gittinger <cg@exept.de>
parents: 13180
diff changeset
   134
4d031c796ecc added: #fromAddress:
Claus Gittinger <cg@exept.de>
parents: 13180
diff changeset
   135
fromAddress:anInteger
4d031c796ecc added: #fromAddress:
Claus Gittinger <cg@exept.de>
parents: 13180
diff changeset
   136
    ^ self newAddress:anInteger
4d031c796ecc added: #fromAddress:
Claus Gittinger <cg@exept.de>
parents: 13180
diff changeset
   137
4d031c796ecc added: #fromAddress:
Claus Gittinger <cg@exept.de>
parents: 13180
diff changeset
   138
    "Created: / 22-12-2010 / 13:48:42 / cg"
4d031c796ecc added: #fromAddress:
Claus Gittinger <cg@exept.de>
parents: 13180
diff changeset
   139
!
13180
206304310ce0 added: #sizeInBytes
Claus Gittinger <cg@exept.de>
parents: 13105
diff changeset
   140
206304310ce0 added: #sizeInBytes
Claus Gittinger <cg@exept.de>
parents: 13105
diff changeset
   141
sizeInBytes
206304310ce0 added: #sizeInBytes
Claus Gittinger <cg@exept.de>
parents: 13105
diff changeset
   142
    ^ self pointerSize
206304310ce0 added: #sizeInBytes
Claus Gittinger <cg@exept.de>
parents: 13105
diff changeset
   143
206304310ce0 added: #sizeInBytes
Claus Gittinger <cg@exept.de>
parents: 13105
diff changeset
   144
    "Created: / 21-12-2010 / 15:18:06 / cg"
206304310ce0 added: #sizeInBytes
Claus Gittinger <cg@exept.de>
parents: 13105
diff changeset
   145
! !
206304310ce0 added: #sizeInBytes
Claus Gittinger <cg@exept.de>
parents: 13105
diff changeset
   146
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
!ExternalAddress class methodsFor:'queries'!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
isBuiltInClass
1267
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   150
    "return true if this class is known by the run-time-system.
20967
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   151
     Here, true is returned (but not for subclasses)."
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
3552
686923fc2096 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3487
diff changeset
   153
    ^ self == ExternalAddress
1267
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   154
20967
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   155
    "Modified: / 11-06-1998 / 17:12:40 / cg"
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   156
    "Modified (comment): / 15-11-2016 / 11:56:55 / cg"
6491
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   157
!
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   158
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   159
pointerSize
19485
00717d9f3ba5 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18828
diff changeset
   160
    "answer the size in bytes of a pointer.
00717d9f3ba5 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18828
diff changeset
   161
     Notice: this is inlined by the compiler(s) as a constant,
20967
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   162
     therefore, queries like 
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   163
        'ExternalAddress pointerSize == 8'
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   164
     cost nothing; they are compiled in as a constant 
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   165
     (and even conditionals are eliminated)."
6491
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   166
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   167
%{ /* NOCONTEXT */
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   168
    RETURN(__mkSmallInteger(sizeof(void *)));
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   169
%}.
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   170
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   171
    "
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   172
     self pointerSize
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   173
    "
20967
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   174
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   175
    "Modified (comment): / 15-11-2016 / 11:56:38 / cg"
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   176
!
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   177
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   178
sizeOfPointer
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   179
    "answer the size in bytes of a pointer.
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   180
     Notice: this is inlined by the compiler(s) as a constant,
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   181
     therefore, queries like 
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   182
        'ExternalAddress pointerSize == 8'
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   183
     cost nothing; they are compiled in as a constant 
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   184
     (and even conditionals are eliminated)."
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   185
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   186
%{ /* NOCONTEXT */
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   187
    RETURN(__mkSmallInteger(sizeof(void *)));
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   188
%}.
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   189
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   190
    "
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   191
     self sizeOfPointer
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   192
    "
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   193
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   194
    "Created: / 15-11-2016 / 11:40:52 / cg"
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
! !
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
20967
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   197
8463
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   198
!ExternalAddress methodsFor:'Compatibility-Squeak'!
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   199
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   200
beNull
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   201
    self setAddress:0
13105
8c9757dcd4ea added: #isNull
Claus Gittinger <cg@exept.de>
parents: 12865
diff changeset
   202
!
8c9757dcd4ea added: #isNull
Claus Gittinger <cg@exept.de>
parents: 12865
diff changeset
   203
8c9757dcd4ea added: #isNull
Claus Gittinger <cg@exept.de>
parents: 12865
diff changeset
   204
isNull
8c9757dcd4ea added: #isNull
Claus Gittinger <cg@exept.de>
parents: 12865
diff changeset
   205
    ^ self address = 0
8c9757dcd4ea added: #isNull
Claus Gittinger <cg@exept.de>
parents: 12865
diff changeset
   206
8c9757dcd4ea added: #isNull
Claus Gittinger <cg@exept.de>
parents: 12865
diff changeset
   207
    "Created: / 26-10-2010 / 23:17:57 / cg"
8463
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   208
! !
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   209
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
!ExternalAddress methodsFor:'accessing'!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
address
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
    "return the start address as an integer"
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
%{  /* NOCONTEXT */
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
2869
6fcc9aafb7c4 alpha64 stuff
Claus Gittinger <cg@exept.de>
parents: 2472
diff changeset
   217
    unsigned INT addr;
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
2877
cc3a4903d692 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2872
diff changeset
   219
    addr = (unsigned INT)__INST(address_);
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
    RETURN ( __MKUINT(addr));
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
%}
4673
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   222
!
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   223
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   224
instVarAt:index
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   225
    "redefined to suppress direct access to my address, which is a non-object"
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   226
12865
fcf412fac69d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12595
diff changeset
   227
    index == 1 ifTrue:[^ self address].
4673
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   228
    ^ super instVarAt:index
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   229
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   230
    "Created: / 3.9.1999 / 13:47:03 / ps"
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   231
!
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   232
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   233
instVarAt:index put:newAddress
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   234
    "redefined to suppress direct access to my address, which is a non-object"
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   235
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   236
    index == 1 ifTrue:[
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   237
        self setAddress:newAddress.
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   238
        ^ newAddress
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   239
    ].
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   240
    ^ super instVarAt:index put:newAddress
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   241
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   242
    "Created: / 3.9.1999 / 14:31:57 / ps"
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
! !
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
!ExternalAddress methodsFor:'comparing'!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
= anExternalAddress
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
    "return true, if two externalAddress instance represent the same
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
     C pointer"
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
%{  /* NOCONTEXT */
14648
7a9bec61d6fe fix equal compare for subclasses
Claus Gittinger <cg@exept.de>
parents: 13192
diff changeset
   252
    if ((__Class(anExternalAddress) == __Class(self))
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
     && (__externalAddressVal(self) == __externalAddressVal(anExternalAddress))) {
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
	RETURN (true);
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
    }
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
%}.
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
    ^ false
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
hash
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
    "return a number useful for hashing"
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
%{  /* NOCONTEXT */
2869
6fcc9aafb7c4 alpha64 stuff
Claus Gittinger <cg@exept.de>
parents: 2472
diff changeset
   264
    unsigned INT addr = (unsigned INT) __externalAddressVal(self);
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
2472
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   266
    if (addr > _MAX_INT) {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   267
	if ((addr & 1) == 0) {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   268
	    addr >>= 1;
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   269
	}
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   270
	if (addr > _MAX_INT) {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   271
	    if ((addr & 1) == 0) {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   272
		addr >>= 1;
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   273
	    }
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   274
	}
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   275
	if (addr > _MAX_INT) {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   276
	    addr &= _MAX_INT;
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   277
	}
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   278
    } else {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   279
	addr <<= 1;
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   280
	if (addr <= _MAX_INT) {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   281
	    addr <<= 1;
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   282
	    if (addr <= _MAX_INT) {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   283
		addr <<= 1;
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   284
	    }
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   285
	}
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   286
	addr >>= 1;
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   287
    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8595
diff changeset
   288
    RETURN (__mkSmallInteger(addr));
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   289
%}
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   290
! !
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   291
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   292
!ExternalAddress methodsFor:'converting'!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   293
6491
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   294
asExternalAddress
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   295
    "convert to an ExternalAddress.
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   296
     Useful to convert subclasses"
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   297
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   298
%{ /* NOCONTEXT */
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   299
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   300
    if (__qClass(self) == @global(ExternalAddress)) {
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   301
        RETURN(self)
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   302
    }
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   303
    RETURN(__MKEXTERNALADDRESS(__INST(address_)));
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   304
%}.
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   305
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   306
    "
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   307
      (ExternalAddress newAddress:16r12345678) asExternalAddress
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   308
    "
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   309
!
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   310
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   311
asExternalBytes
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   312
    "return an ExternalBytes object pointing to where the receiver points to.
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   313
     Use of this is not recommended; primitives which return externalAddresses
20796
3ab5f54fa968 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19513
diff changeset
   314
     don't think that access to the memory is required/useful, while primitives
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   315
     which do think so should return an externalBytes instance right away."
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   316
6491
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   317
%{ /* NOCONTEXT */
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   318
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   319
    RETURN(__MKEXTERNALBYTES(__INST(address_)));
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   320
%}
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   321
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   322
    "
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   323
      (ExternalAddress newAddress:16r12345678) asExternalBytes
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   324
    "
12595
ab229fdd630c added: #copyCStringFromHeap
Claus Gittinger <cg@exept.de>
parents: 12462
diff changeset
   325
!
ab229fdd630c added: #copyCStringFromHeap
Claus Gittinger <cg@exept.de>
parents: 12462
diff changeset
   326
ab229fdd630c added: #copyCStringFromHeap
Claus Gittinger <cg@exept.de>
parents: 12462
diff changeset
   327
copyCStringFromHeap
ab229fdd630c added: #copyCStringFromHeap
Claus Gittinger <cg@exept.de>
parents: 12462
diff changeset
   328
    ^ self asExternalBytes copyCStringFromHeap
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
! !
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
!ExternalAddress methodsFor:'printing & storing'!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
7018
5ceb0daa7b1b Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents: 6491
diff changeset
   333
printOn:aStream
5ceb0daa7b1b Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents: 6491
diff changeset
   334
    "return a printed representation of the receiver"
2957
46015145c398 comments
Claus Gittinger <cg@exept.de>
parents: 2877
diff changeset
   335
7018
5ceb0daa7b1b Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents: 6491
diff changeset
   336
    self class name printOn:aStream.
18828
919987dab72c #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 14648
diff changeset
   337
    aStream nextPutAll:'@'.
7018
5ceb0daa7b1b Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents: 6491
diff changeset
   338
    self address printOn:aStream base:16.
18828
919987dab72c #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 14648
diff changeset
   339
919987dab72c #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 14648
diff changeset
   340
    "
919987dab72c #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 14648
diff changeset
   341
        self new printString
919987dab72c #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 14648
diff changeset
   342
    "
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
! !
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
7258
9ccdbee7d1ad method category rename
Claus Gittinger <cg@exept.de>
parents: 7018
diff changeset
   345
!ExternalAddress methodsFor:'private-accessing'!
3957
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   346
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   347
setAddress:anInteger
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   348
    "set the address"
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   349
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   350
%{  /* NOCONTEXT */
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   351
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   352
    unsigned INT addr;
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   353
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   354
    if (__isSmallInteger(anInteger)) {
8595
a756fee49327 #setAddress: use unsignedLongIntVal()
Stefan Vogel <sv@exept.de>
parents: 8463
diff changeset
   355
        addr = __intVal(anInteger);
3957
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   356
    } else {
8595
a756fee49327 #setAddress: use unsignedLongIntVal()
Stefan Vogel <sv@exept.de>
parents: 8463
diff changeset
   357
        addr = __unsignedLongIntVal(anInteger);
20967
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   358
        if (addr == 0) {
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   359
            console_printf("invalid address argument in ExternalAddress>>setAddress\n");
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   360
        }
3957
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   361
    }
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   362
    __INST(address_) = (OBJ)addr;
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   363
%}
20967
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   364
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   365
    "Modified: / 15-11-2016 / 11:59:24 / cg"
9477
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   366
!
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   367
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   368
setAddressFromBytes:aByteArray
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   369
    "set the address from a pointer to which we have a pointer to"
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   370
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   371
%{  /* NOCONTEXT */
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   372
12462
1a3054e5c032 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 9477
diff changeset
   373
    if (__isByteArrayLike(aByteArray)) {
9477
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   374
        if (__byteArraySize(aByteArray) == sizeof(void *)) {
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   375
            __INST(address_) = (OBJ)(((void **)__byteArrayVal(aByteArray))[0]);
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   376
            RETURN (self);
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   377
        }
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   378
    }
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   379
%}.
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   380
    self primitiveFailed.
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   381
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   382
    "Created: / 27-07-2006 / 14:37:57 / fm"
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   383
    "Modified: / 07-08-2006 / 15:16:32 / fm"
3957
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   384
! !
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   385
13186
3ba883fe8aa2 added: #isExternalAddress
Claus Gittinger <cg@exept.de>
parents: 13183
diff changeset
   386
!ExternalAddress methodsFor:'testing'!
3ba883fe8aa2 added: #isExternalAddress
Claus Gittinger <cg@exept.de>
parents: 13183
diff changeset
   387
3ba883fe8aa2 added: #isExternalAddress
Claus Gittinger <cg@exept.de>
parents: 13183
diff changeset
   388
isExternalAddress
3ba883fe8aa2 added: #isExternalAddress
Claus Gittinger <cg@exept.de>
parents: 13183
diff changeset
   389
    ^ true
3ba883fe8aa2 added: #isExternalAddress
Claus Gittinger <cg@exept.de>
parents: 13183
diff changeset
   390
3ba883fe8aa2 added: #isExternalAddress
Claus Gittinger <cg@exept.de>
parents: 13183
diff changeset
   391
    "Created: / 22-12-2010 / 17:14:57 / cg"
3ba883fe8aa2 added: #isExternalAddress
Claus Gittinger <cg@exept.de>
parents: 13183
diff changeset
   392
! !
3ba883fe8aa2 added: #isExternalAddress
Claus Gittinger <cg@exept.de>
parents: 13183
diff changeset
   393
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   394
!ExternalAddress class methodsFor:'documentation'!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
version
18828
919987dab72c #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 14648
diff changeset
   397
    ^ '$Header$'
12462
1a3054e5c032 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 9477
diff changeset
   398
!
1a3054e5c032 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 9477
diff changeset
   399
1a3054e5c032 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 9477
diff changeset
   400
version_CVS
18828
919987dab72c #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 14648
diff changeset
   401
    ^ '$Header$'
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   402
! !
18828
919987dab72c #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 14648
diff changeset
   403