ExternalAddress.st
author Claus Gittinger <cg@exept.de>
Fri, 08 Jul 2005 19:15:03 +0200
changeset 8913 b9498d27a554
parent 8595 a756fee49327
child 9477 ee3efc29a68f
permissions -rw-r--r--
64bit; mkSmallInteger
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
"
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
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
Object subclass:#ExternalAddress
1267
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    16
	instanceVariableNames:'address*'
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    17
	classVariableNames:''
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    18
	poolDictionaries:''
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    19
	category:'System-Support'
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
!
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
!ExternalAddress class methodsFor:'documentation'!
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
copyright
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 (c) 1995 by Claus Gittinger
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
	      All Rights Reserved
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 This software is furnished under a license and may be used
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 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
    31
 inclusion of the above copyright notice.   This software may not
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 be provided or otherwise made available to, or used by, any
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 other person.  No title to or ownership of the software is
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 hereby transferred.
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
"
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
documentation
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
    Instances of this class represent external (non-Smalltalk) addresses.
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    They are only useful to represent handles as returned by C functions
8463
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
    42
    as smalltalk objects. 
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
    43
    For example, Window- or WidgetIDs (which are actually 32 bit pointers) could be represented this way
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
    44
    (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
    45
    (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
    46
     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
    47
     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
    48
     around makes things pretty clear in inspectors etc.).
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
    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
    51
    creation/use should be done in primitive C-code via 
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
    52
       __MKEXTERNALADDRESS(voidPtr) and __ExternalAddressVal(obj).
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
    ExternallAddresses are much like ExternalBytes - however, the latter
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
    allow you to access bytes via indexed at:/at:put: messages.
8463
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
    56
    ExternalAddresses do not allow such accesses (they are meant to remain anonymous, opaque handles).
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
    57
    Also, memory blocks which are freeable should be represented as ExternalBytes.
1286
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1267
diff changeset
    58
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1267
diff changeset
    59
    [author:]
8463
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
    60
        Claus Gittinger
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
    61
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
    62
    [see also:]
8463
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
    63
        ByteArray
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
    64
        ExternalBytes ExternalFunction
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
    65
        ( how to write primitive code :html: programming/primitive.html )
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
"
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
!
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
examples
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
    To pass some C-pointer from primitive code to smalltalk:
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
	...
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
	RETURN (__MKEXTERNALADDRESS(foo));
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
    pass it back to C and use it there:
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
	...
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
	if (__isExternalAddress(anExternalAddress)) {
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
	    ptr = __externalAddressVal(anExternalAddress));
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
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
    concrete example:
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
	test1
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
	    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
    89
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
	    RETURN (__MKEXTERNALADDRESS(foo));
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
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
	test2:anExternalAddress
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
	    if (__isExternalAddress(anExternalAddress)) {
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
		printf(__externalAddressVal(anExternalAddress));
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
		RETURN (self);
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
	%}
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
3957
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   103
!ExternalAddress class methodsFor:'instance creation'!
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   104
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   105
newAddress:addr
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   106
    ^ self new setAddress:addr
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   107
! !
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   108
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
!ExternalAddress class methodsFor:'queries'!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
isBuiltInClass
1267
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   112
    "return true if this class is known by the run-time-system.
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   113
     Here, true is returned."
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
3552
686923fc2096 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3487
diff changeset
   115
    ^ self == ExternalAddress
1267
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   116
3552
686923fc2096 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3487
diff changeset
   117
    "Modified: / 11.6.1998 / 17:12:40 / cg"
6491
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   118
!
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   119
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   120
pointerSize
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   121
    "answer the size in bytes of a pointer"
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   122
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   123
%{ /* NOCONTEXT */
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   124
    RETURN(__mkSmallInteger(sizeof(void *)));
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   125
%}.
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   126
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   127
    "
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   128
     self pointerSize
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   129
    "
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
! !
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
8463
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   132
!ExternalAddress methodsFor:'Compatibility-Squeak'!
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   133
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   134
beNull
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   135
    self setAddress:0
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   136
! !
65b467ab6ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   137
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
!ExternalAddress methodsFor:'accessing'!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
address
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
    "return the start address as an integer"
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
%{  /* NOCONTEXT */
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
2869
6fcc9aafb7c4 alpha64 stuff
Claus Gittinger <cg@exept.de>
parents: 2472
diff changeset
   145
    unsigned INT addr;
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
2877
cc3a4903d692 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2872
diff changeset
   147
    addr = (unsigned INT)__INST(address_);
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
    RETURN ( __MKUINT(addr));
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
%}
4673
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   150
!
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   151
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   152
instVarAt:index
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   153
    "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
   154
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   155
    index == 1 ifTrue:[
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   156
        ^ self address
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   157
    ].
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   158
    ^ super instVarAt:index
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   159
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   160
    "Created: / 3.9.1999 / 13:47:03 / ps"
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   161
!
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   162
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   163
instVarAt:index put:newAddress
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   164
    "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
   165
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   166
    index == 1 ifTrue:[
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   167
        self setAddress:newAddress.
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   168
        ^ newAddress
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   169
    ].
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   170
    ^ super instVarAt:index put:newAddress
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   171
39fa7949617b care for access to address (non-object inst)
ps
parents: 3957
diff changeset
   172
    "Created: / 3.9.1999 / 14:31:57 / ps"
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
! !
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
!ExternalAddress methodsFor:'comparing'!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
= anExternalAddress
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
    "return true, if two externalAddress instance represent the same
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
     C pointer"
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
%{  /* NOCONTEXT */
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
    if (__isExternalAddress(anExternalAddress)
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
     && (__externalAddressVal(self) == __externalAddressVal(anExternalAddress))) {
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
	RETURN (true);
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
    }
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
%}.
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
    ^ false
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
hash
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
    "return a number useful for hashing"
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
%{  /* NOCONTEXT */
2869
6fcc9aafb7c4 alpha64 stuff
Claus Gittinger <cg@exept.de>
parents: 2472
diff changeset
   194
    unsigned INT addr = (unsigned INT) __externalAddressVal(self);
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
2472
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   196
    if (addr > _MAX_INT) {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   197
	if ((addr & 1) == 0) {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   198
	    addr >>= 1;
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   199
	}
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   200
	if (addr > _MAX_INT) {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   201
	    if ((addr & 1) == 0) {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   202
		addr >>= 1;
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   203
	    }
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   204
	}
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   205
	if (addr > _MAX_INT) {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   206
	    addr &= _MAX_INT;
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   207
	}
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   208
    } else {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   209
	addr <<= 1;
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   210
	if (addr <= _MAX_INT) {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   211
	    addr <<= 1;
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   212
	    if (addr <= _MAX_INT) {
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   213
		addr <<= 1;
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   214
	    }
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   215
	}
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   216
	addr >>= 1;
00e7a1b3b07f better distribution of the hash-key (look for zero-bits)
Claus Gittinger <cg@exept.de>
parents: 1960
diff changeset
   217
    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8595
diff changeset
   218
    RETURN (__mkSmallInteger(addr));
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
%}
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
! !
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
!ExternalAddress methodsFor:'converting'!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
6491
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   224
asExternalAddress
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   225
    "convert to an ExternalAddress.
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   226
     Useful to convert subclasses"
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   227
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   228
%{ /* NOCONTEXT */
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   229
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   230
    if (__qClass(self) == @global(ExternalAddress)) {
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   231
        RETURN(self)
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   232
    }
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   233
    RETURN(__MKEXTERNALADDRESS(__INST(address_)));
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   234
%}.
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   235
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   236
    "
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   237
      (ExternalAddress newAddress:16r12345678) asExternalAddress
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   238
    "
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   239
!
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   240
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
asExternalBytes
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
    "return an ExternalBytes object pointing to where the receiver points to.
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
     Use of this is not recommended; primitives which return externalAddresses
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
     dont think that access to the memory is required/useful, while primitives
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
     which do think so should return an externalBytes instance right away."
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
6491
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   247
%{ /* NOCONTEXT */
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   248
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   249
    RETURN(__MKEXTERNALBYTES(__INST(address_)));
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   250
%}
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   251
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   252
    "
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   253
      (ExternalAddress newAddress:16r12345678) asExternalBytes
6976d9b69e01 Conversion between ExternalBytes and ExternalAddress
Stefan Vogel <sv@exept.de>
parents: 4673
diff changeset
   254
    "
847
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
!ExternalAddress methodsFor:'printing & storing'!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
7018
5ceb0daa7b1b Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents: 6491
diff changeset
   259
printOn:aStream
5ceb0daa7b1b Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents: 6491
diff changeset
   260
    "return a printed representation of the receiver"
2957
46015145c398 comments
Claus Gittinger <cg@exept.de>
parents: 2877
diff changeset
   261
7018
5ceb0daa7b1b Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents: 6491
diff changeset
   262
    self class name printOn:aStream.
5ceb0daa7b1b Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents: 6491
diff changeset
   263
    aStream nextPutAll:' at:'.
5ceb0daa7b1b Print address when doing #printOn:
Stefan Vogel <sv@exept.de>
parents: 6491
diff changeset
   264
    self address printOn:aStream base:16.
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
! !
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
7258
9ccdbee7d1ad method category rename
Claus Gittinger <cg@exept.de>
parents: 7018
diff changeset
   267
!ExternalAddress methodsFor:'private-accessing'!
3957
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   268
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   269
setAddress:anInteger
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   270
    "set the address"
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   271
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   272
%{  /* NOCONTEXT */
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   273
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   274
    unsigned INT addr;
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   275
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   276
    if (__isSmallInteger(anInteger)) {
8595
a756fee49327 #setAddress: use unsignedLongIntVal()
Stefan Vogel <sv@exept.de>
parents: 8463
diff changeset
   277
        addr = __intVal(anInteger);
3957
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   278
    } else {
8595
a756fee49327 #setAddress: use unsignedLongIntVal()
Stefan Vogel <sv@exept.de>
parents: 8463
diff changeset
   279
        addr = __unsignedLongIntVal(anInteger);
3957
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   280
    }
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   281
    __INST(address_) = (OBJ)addr;
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   282
%}
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   283
! !
925e247ae8df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3552
diff changeset
   284
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
!ExternalAddress class methodsFor:'documentation'!
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   286
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   287
version
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8595
diff changeset
   288
    ^ '$Header: /cvs/stx/stx/libbasic/ExternalAddress.st,v 1.21 2005-07-08 17:15:01 cg Exp $'
847
a79ec4e6670d ExternalAddress moved from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   289
! !