ExternalAddress.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 12 Jun 2019 15:02:01 +0100
branchjv
changeset 24334 e82c3f5bc1f1
parent 23217 5811aa416119
child 25391 cad52f81f60c
permissions -rw-r--r--
Issue #259: fix `ProjectDefinition >> classesForPlatform` and use it `#testSuite` THis allows packages to specify testcases valid for some platform only. This is normally not needed but sometimes the testcase uses a class that is platform specific and this will cause package validation error upon commit.
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
23217
5811aa416119 Fixed `ExternalAddress >> setAddress:` to allow for parameter to be `0` or `nil`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 21024
diff changeset
     3
 COPYRIGHT (c) 2018 Jan Vrany
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
	      All Rights Reserved
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 This software is furnished under a license and may be used
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 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
     8
 inclusion of the above copyright notice.   This software may not
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 be provided or otherwise made available to, or used by, any
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 other person.  No title to or ownership of the software is
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
 hereby transferred.
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
"
6491
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
    13
"{ Package: 'stx:libbasic' }"
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
    14
18828
919987dab72c #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 14648
diff changeset
    15
"{ NameSpace: Smalltalk }"
919987dab72c #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 14648
diff changeset
    16
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
Object subclass:#ExternalAddress
1267
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    18
	instanceVariableNames:'address*'
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    19
	classVariableNames:''
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    20
	poolDictionaries:''
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    21
	category:'System-Support'
847
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
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
!ExternalAddress class methodsFor:'documentation'!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
copyright
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
"
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
 COPYRIGHT (c) 1995 by Claus Gittinger
23217
5811aa416119 Fixed `ExternalAddress >> setAddress:` to allow for parameter to be `0` or `nil`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 21024
diff changeset
    29
 COPYRIGHT (c) 2017 Jan Vrany
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
	      All Rights Reserved
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 This software is furnished under a license and may be used
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 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
    34
 inclusion of the above copyright notice.   This software may not
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 be provided or otherwise made available to, or used by, any
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 other person.  No title to or ownership of the software is
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 hereby transferred.
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
!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
documentation
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
"
19513
0423b94b4789 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19485
diff changeset
    43
    Instances of this class represent external (non-Smalltalk) memory addresses.
0423b94b4789 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19485
diff changeset
    44
    They are only useful to represent handles as returned by C functions,
0423b94b4789 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19485
diff changeset
    45
    or to pass them to C functions. 
0423b94b4789 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19485
diff changeset
    46
    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
    47
    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
    48
    (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
    49
     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
    50
     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
    51
     around makes things pretty clear in inspectors etc.).
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
19513
0423b94b4789 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19485
diff changeset
    53
    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
    54
    creation/use should be done in primitive C-code via 
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
    55
       __MKEXTERNALADDRESS(voidPtr) and __ExternalAddressVal(obj).
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
19513
0423b94b4789 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19485
diff changeset
    57
    ExternalAddresses are much like ExternalBytes - however, ExternalAddresses do not know
0423b94b4789 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19485
diff changeset
    58
    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
    59
    (which ExternalBytes do).
0423b94b4789 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19485
diff changeset
    60
    ExternalAddresses are meant to remain anonymous, opaque handles.
8463
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
    61
    Also, memory blocks which are freeable should be represented as ExternalBytes.
1286
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1267
diff changeset
    62
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1267
diff changeset
    63
    [author:]
8463
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
    64
        Claus Gittinger
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
    65
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
    66
    [see also:]
8463
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
    67
        ByteArray
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
    68
        ExternalBytes ExternalFunction
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
    69
        ( how to write primitive code :html: programming/primitive.html )
847
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
!
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
examples
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
    To pass some C-pointer from primitive code to smalltalk:
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
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
	RETURN (__MKEXTERNALADDRESS(foo));
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
    pass it back to C and use it there:
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
	...
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
	if (__isExternalAddress(anExternalAddress)) {
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
	    ptr = __externalAddressVal(anExternalAddress));
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
	...
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
    concrete example:
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
	test1
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
	    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
    93
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
	    RETURN (__MKEXTERNALADDRESS(foo));
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
	%}
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
	test2:anExternalAddress
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
	%{
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
	    if (__isExternalAddress(anExternalAddress)) {
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
		printf(__externalAddressVal(anExternalAddress));
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
		RETURN (self);
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
"
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
! !
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
3957
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   107
!ExternalAddress class methodsFor:'instance creation'!
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   108
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   109
newAddress:addr
20967
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   110
    "return a new externalAddress (pointer), pointing to addr."
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   111
3957
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   112
    ^ self new setAddress:addr
20967
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
    "Modified (comment): / 15-11-2016 / 11:57:34 / cg"
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   115
!
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   116
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   117
newAddressFromBytes:bytesContainingAddress
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   118
    "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
   119
     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
   120
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   121
    ^ (bytesContainingAddress pointerAt:1)
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   122
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 ptr|
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   125
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   126
     bytes := ByteArray new:(ExternalAddress pointerSize).
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   127
     bytes pointerAt:1 put:16r12345678.
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   128
     ptr := ExternalAddress newAddressFromBytes:bytes.
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   129
     self assert:(ptr address = 16r12345678).
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   130
    "
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   131
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   132
    "Created: / 15-11-2016 / 12:53:21 / cg"
3957
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   133
! !
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   134
13183
4d031c796ecc added: #fromAddress:
Claus Gittinger <cg@exept.de>
parents: 13180
diff changeset
   135
!ExternalAddress class methodsFor:'Compatibility-V''Age'!
4d031c796ecc added: #fromAddress:
Claus Gittinger <cg@exept.de>
parents: 13180
diff changeset
   136
4d031c796ecc added: #fromAddress:
Claus Gittinger <cg@exept.de>
parents: 13180
diff changeset
   137
fromAddress:anInteger
4d031c796ecc added: #fromAddress:
Claus Gittinger <cg@exept.de>
parents: 13180
diff changeset
   138
    ^ self newAddress:anInteger
4d031c796ecc added: #fromAddress:
Claus Gittinger <cg@exept.de>
parents: 13180
diff changeset
   139
4d031c796ecc added: #fromAddress:
Claus Gittinger <cg@exept.de>
parents: 13180
diff changeset
   140
    "Created: / 22-12-2010 / 13:48:42 / cg"
4d031c796ecc added: #fromAddress:
Claus Gittinger <cg@exept.de>
parents: 13180
diff changeset
   141
!
13180
206304310ce0 added: #sizeInBytes
Claus Gittinger <cg@exept.de>
parents: 13105
diff changeset
   142
206304310ce0 added: #sizeInBytes
Claus Gittinger <cg@exept.de>
parents: 13105
diff changeset
   143
sizeInBytes
206304310ce0 added: #sizeInBytes
Claus Gittinger <cg@exept.de>
parents: 13105
diff changeset
   144
    ^ self pointerSize
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
    "Created: / 21-12-2010 / 15:18:06 / cg"
206304310ce0 added: #sizeInBytes
Claus Gittinger <cg@exept.de>
parents: 13105
diff changeset
   147
! !
206304310ce0 added: #sizeInBytes
Claus Gittinger <cg@exept.de>
parents: 13105
diff changeset
   148
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
!ExternalAddress class methodsFor:'queries'!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
isBuiltInClass
1267
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   152
    "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
   153
     Here, true is returned (but not for subclasses)."
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
3552
686923fc2096 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3487
diff changeset
   155
    ^ self == ExternalAddress
1267
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   156
20967
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   157
    "Modified: / 11-06-1998 / 17:12:40 / cg"
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   158
    "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
   159
!
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   160
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   161
pointerSize
19485
00717d9f3ba5 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18828
diff changeset
   162
    "answer the size in bytes of a pointer.
00717d9f3ba5 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18828
diff changeset
   163
     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
   164
     therefore, queries like 
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   165
        'ExternalAddress pointerSize == 8'
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   166
     cost nothing; they are compiled in as a constant 
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   167
     (and even conditionals are eliminated)."
6491
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   168
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   169
%{ /* NOCONTEXT */
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   170
    RETURN(__mkSmallInteger(sizeof(void *)));
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
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   173
    "
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   174
     self pointerSize
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   175
    "
20967
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
    "Modified (comment): / 15-11-2016 / 11:56:38 / cg"
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   178
!
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   179
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   180
sizeOfPointer
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   181
    "answer the size in bytes of a pointer.
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   182
     Notice: this is inlined by the compiler(s) as a constant,
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   183
     therefore, queries like 
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   184
        'ExternalAddress pointerSize == 8'
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   185
     cost nothing; they are compiled in as a constant 
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   186
     (and even conditionals are eliminated)."
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   187
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   188
%{ /* NOCONTEXT */
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   189
    RETURN(__mkSmallInteger(sizeof(void *)));
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
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
     self sizeOfPointer
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   194
    "
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   195
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   196
    "Created: / 15-11-2016 / 11:40:52 / cg"
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
! !
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
20967
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   199
8463
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   200
!ExternalAddress methodsFor:'Compatibility-Squeak'!
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   201
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   202
beNull
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   203
    self setAddress:0
13105
8c9757dcd4ea added: #isNull
Claus Gittinger <cg@exept.de>
parents: 12865
diff changeset
   204
!
8c9757dcd4ea added: #isNull
Claus Gittinger <cg@exept.de>
parents: 12865
diff changeset
   205
8c9757dcd4ea added: #isNull
Claus Gittinger <cg@exept.de>
parents: 12865
diff changeset
   206
isNull
8c9757dcd4ea added: #isNull
Claus Gittinger <cg@exept.de>
parents: 12865
diff changeset
   207
    ^ self address = 0
8c9757dcd4ea added: #isNull
Claus Gittinger <cg@exept.de>
parents: 12865
diff changeset
   208
8c9757dcd4ea added: #isNull
Claus Gittinger <cg@exept.de>
parents: 12865
diff changeset
   209
    "Created: / 26-10-2010 / 23:17:57 / cg"
8463
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   210
! !
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   211
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
!ExternalAddress methodsFor:'accessing'!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
address
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
    "return the start address as an integer"
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
%{  /* NOCONTEXT */
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
2869
6fcc9aafb7c4 alpha64 stuff
Claus Gittinger <cg@exept.de>
parents: 2472
diff changeset
   219
    unsigned INT addr;
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
2877
cc3a4903d692 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2872
diff changeset
   221
    addr = (unsigned INT)__INST(address_);
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
    RETURN ( __MKUINT(addr));
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
%}
4673
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   224
!
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   225
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   226
instVarAt:index
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   227
    "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
   228
12865
fcf412fac69d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12595
diff changeset
   229
    index == 1 ifTrue:[^ self address].
4673
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   230
    ^ super instVarAt:index
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
    "Created: / 3.9.1999 / 13:47:03 / ps"
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   233
!
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   234
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   235
instVarAt:index put:newAddress
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   236
    "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
   237
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   238
    index == 1 ifTrue:[
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   239
        self setAddress:newAddress.
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   240
        ^ 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
    ^ super instVarAt:index put:newAddress
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   243
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   244
    "Created: / 3.9.1999 / 14:31:57 / ps"
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
! !
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
!ExternalAddress methodsFor:'comparing'!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
= anExternalAddress
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
    "return true, if two externalAddress instance represent the same
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
     C pointer"
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
%{  /* NOCONTEXT */
14648
7a9bec61d6fe fix equal compare for subclasses
Claus Gittinger <cg@exept.de>
parents: 13192
diff changeset
   254
    if ((__Class(anExternalAddress) == __Class(self))
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
     && (__externalAddressVal(self) == __externalAddressVal(anExternalAddress))) {
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
	RETURN (true);
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
    }
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
    ^ false
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
hash
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
    "return a number useful for hashing"
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
%{  /* NOCONTEXT */
2869
6fcc9aafb7c4 alpha64 stuff
Claus Gittinger <cg@exept.de>
parents: 2472
diff changeset
   266
    unsigned INT addr = (unsigned INT) __externalAddressVal(self);
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
2472
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   268
    if (addr > _MAX_INT) {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   269
	if ((addr & 1) == 0) {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   270
	    addr >>= 1;
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   271
	}
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   272
	if (addr > _MAX_INT) {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   273
	    if ((addr & 1) == 0) {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   274
		addr >>= 1;
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   275
	    }
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   276
	}
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   277
	if (addr > _MAX_INT) {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   278
	    addr &= _MAX_INT;
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   279
	}
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   280
    } else {
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
	    if (addr <= _MAX_INT) {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   285
		addr <<= 1;
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   286
	    }
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   287
	}
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   288
	addr >>= 1;
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   289
    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8595
diff changeset
   290
    RETURN (__mkSmallInteger(addr));
847
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
! !
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   293
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
!ExternalAddress methodsFor:'converting'!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
6491
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   296
asExternalAddress
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   297
    "convert to an ExternalAddress.
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   298
     Useful to convert subclasses"
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
%{ /* NOCONTEXT */
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   301
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   302
    if (__qClass(self) == @global(ExternalAddress)) {
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   303
        RETURN(self)
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
    RETURN(__MKEXTERNALADDRESS(__INST(address_)));
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
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
      (ExternalAddress newAddress:16r12345678) asExternalAddress
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   310
    "
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   311
!
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   312
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   313
asExternalBytes
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   314
    "return an ExternalBytes object pointing to where the receiver points to.
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   315
     Use of this is not recommended; primitives which return externalAddresses
20796
3ab5f54fa968 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19513
diff changeset
   316
     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
   317
     which do think so should return an externalBytes instance right away."
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   318
6491
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   319
%{ /* NOCONTEXT */
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
    RETURN(__MKEXTERNALBYTES(__INST(address_)));
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
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   324
    "
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   325
      (ExternalAddress newAddress:16r12345678) asExternalBytes
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   326
    "
12595
ab229fdd630c added: #copyCStringFromHeap
Claus Gittinger <cg@exept.de>
parents: 12462
diff changeset
   327
!
ab229fdd630c added: #copyCStringFromHeap
Claus Gittinger <cg@exept.de>
parents: 12462
diff changeset
   328
ab229fdd630c added: #copyCStringFromHeap
Claus Gittinger <cg@exept.de>
parents: 12462
diff changeset
   329
copyCStringFromHeap
ab229fdd630c added: #copyCStringFromHeap
Claus Gittinger <cg@exept.de>
parents: 12462
diff changeset
   330
    ^ self asExternalBytes copyCStringFromHeap
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
! !
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
!ExternalAddress methodsFor:'printing & storing'!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
7018
5ceb0daa7b1b Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents: 6491
diff changeset
   335
printOn:aStream
5ceb0daa7b1b Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents: 6491
diff changeset
   336
    "return a printed representation of the receiver"
2957
46015145c398 comments
Claus Gittinger <cg@exept.de>
parents: 2877
diff changeset
   337
7018
5ceb0daa7b1b Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents: 6491
diff changeset
   338
    self class name printOn:aStream.
18828
919987dab72c #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 14648
diff changeset
   339
    aStream nextPutAll:'@'.
7018
5ceb0daa7b1b Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents: 6491
diff changeset
   340
    self address printOn:aStream base:16.
18828
919987dab72c #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 14648
diff changeset
   341
919987dab72c #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 14648
diff changeset
   342
    "
919987dab72c #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 14648
diff changeset
   343
        self new printString
919987dab72c #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 14648
diff changeset
   344
    "
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
! !
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
7258
9ccdbee7d1ad method category rename
Claus Gittinger <cg@exept.de>
parents: 7018
diff changeset
   347
!ExternalAddress methodsFor:'private-accessing'!
3957
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   348
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   349
setAddress:anInteger
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   350
    "set the address"
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
%{  /* NOCONTEXT */
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
    unsigned INT addr;
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   355
23217
5811aa416119 Fixed `ExternalAddress >> setAddress:` to allow for parameter to be `0` or `nil`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 21024
diff changeset
   356
    if (anInteger == nil) {
5811aa416119 Fixed `ExternalAddress >> setAddress:` to allow for parameter to be `0` or `nil`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 21024
diff changeset
   357
    	addr = (unsigned INT)NULL;
5811aa416119 Fixed `ExternalAddress >> setAddress:` to allow for parameter to be `0` or `nil`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 21024
diff changeset
   358
    } else if (__isSmallInteger(anInteger)) {
8595
a756fee49327 #setAddress: use unsignedLongIntVal()
Stefan Vogel <sv@exept.de>
parents: 8463
diff changeset
   359
        addr = __intVal(anInteger);
3957
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   360
    } else {
23217
5811aa416119 Fixed `ExternalAddress >> setAddress:` to allow for parameter to be `0` or `nil`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 21024
diff changeset
   361
        addr = __unsignedLongIntVal(anInteger);    
3957
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   362
    }
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   363
    __INST(address_) = (OBJ)addr;
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   364
%}
20967
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   365
ba69e999a1d6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20796
diff changeset
   366
    "Modified: / 15-11-2016 / 11:59:24 / cg"
9477
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   367
!
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   368
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   369
setAddressFromBytes:aByteArray
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   370
    "set the address from a pointer to which we have a pointer to"
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   371
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   372
%{  /* NOCONTEXT */
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   373
12462
1a3054e5c032 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 9477
diff changeset
   374
    if (__isByteArrayLike(aByteArray)) {
9477
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   375
        if (__byteArraySize(aByteArray) == sizeof(void *)) {
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   376
            __INST(address_) = (OBJ)(((void **)__byteArrayVal(aByteArray))[0]);
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   377
            RETURN (self);
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
%}.
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   381
    self primitiveFailed.
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   382
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   383
    "Created: / 27-07-2006 / 14:37:57 / fm"
ee3efc29a68f *** empty log message ***
fm
parents: 8913
diff changeset
   384
    "Modified: / 07-08-2006 / 15:16:32 / fm"
3957
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   385
! !
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   386
13186
3ba883fe8aa2 added: #isExternalAddress
Claus Gittinger <cg@exept.de>
parents: 13183
diff changeset
   387
!ExternalAddress methodsFor:'testing'!
3ba883fe8aa2 added: #isExternalAddress
Claus Gittinger <cg@exept.de>
parents: 13183
diff changeset
   388
3ba883fe8aa2 added: #isExternalAddress
Claus Gittinger <cg@exept.de>
parents: 13183
diff changeset
   389
isExternalAddress
3ba883fe8aa2 added: #isExternalAddress
Claus Gittinger <cg@exept.de>
parents: 13183
diff changeset
   390
    ^ true
3ba883fe8aa2 added: #isExternalAddress
Claus Gittinger <cg@exept.de>
parents: 13183
diff changeset
   391
3ba883fe8aa2 added: #isExternalAddress
Claus Gittinger <cg@exept.de>
parents: 13183
diff changeset
   392
    "Created: / 22-12-2010 / 17:14:57 / cg"
3ba883fe8aa2 added: #isExternalAddress
Claus Gittinger <cg@exept.de>
parents: 13183
diff changeset
   393
! !
3ba883fe8aa2 added: #isExternalAddress
Claus Gittinger <cg@exept.de>
parents: 13183
diff changeset
   394
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
!ExternalAddress class methodsFor:'documentation'!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   397
version
18828
919987dab72c #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 14648
diff changeset
   398
    ^ '$Header$'
12462
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
1a3054e5c032 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 9477
diff changeset
   401
version_CVS
18828
919987dab72c #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 14648
diff changeset
   402
    ^ '$Header$'
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   403
! !
18828
919987dab72c #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 14648
diff changeset
   404