ExternalAddress.st
changeset 20967 ba69e999a1d6
parent 20796 3ab5f54fa968
child 21024 8734987eb5c7
child 21413 e578b0899450
equal deleted inserted replaced
20966:283c240f38d1 20967:ba69e999a1d6
   103 ! !
   103 ! !
   104 
   104 
   105 !ExternalAddress class methodsFor:'instance creation'!
   105 !ExternalAddress class methodsFor:'instance creation'!
   106 
   106 
   107 newAddress:addr
   107 newAddress:addr
       
   108     "return a new externalAddress (pointer), pointing to addr."
       
   109 
   108     ^ self new setAddress:addr
   110     ^ self new setAddress:addr
       
   111 
       
   112     "Modified (comment): / 15-11-2016 / 11:57:34 / cg"
       
   113 !
       
   114 
       
   115 newAddressFromBytes:bytesContainingAddress
       
   116     "return a new externalAddress (pointer), pointing to the addr contained in the argument.
       
   117      The argument must be a byteArray-like object, whose first pointerSize bytes are extracted"
       
   118 
       
   119     ^ (bytesContainingAddress pointerAt:1)
       
   120 
       
   121     "
       
   122      |bytes ptr|
       
   123 
       
   124      bytes := ByteArray new:(ExternalAddress pointerSize).
       
   125      bytes pointerAt:1 put:16r12345678.
       
   126      ptr := ExternalAddress newAddressFromBytes:bytes.
       
   127      self assert:(ptr address = 16r12345678).
       
   128     "
       
   129 
       
   130     "Created: / 15-11-2016 / 12:53:21 / cg"
   109 ! !
   131 ! !
   110 
   132 
   111 !ExternalAddress class methodsFor:'Compatibility-V''Age'!
   133 !ExternalAddress class methodsFor:'Compatibility-V''Age'!
   112 
   134 
   113 fromAddress:anInteger
   135 fromAddress:anInteger
   124 
   146 
   125 !ExternalAddress class methodsFor:'queries'!
   147 !ExternalAddress class methodsFor:'queries'!
   126 
   148 
   127 isBuiltInClass
   149 isBuiltInClass
   128     "return true if this class is known by the run-time-system.
   150     "return true if this class is known by the run-time-system.
   129      Here, true is returned."
   151      Here, true is returned (but not for subclasses)."
   130 
   152 
   131     ^ self == ExternalAddress
   153     ^ self == ExternalAddress
   132 
   154 
   133     "Modified: / 11.6.1998 / 17:12:40 / cg"
   155     "Modified: / 11-06-1998 / 17:12:40 / cg"
       
   156     "Modified (comment): / 15-11-2016 / 11:56:55 / cg"
   134 !
   157 !
   135 
   158 
   136 pointerSize
   159 pointerSize
   137     "answer the size in bytes of a pointer.
   160     "answer the size in bytes of a pointer.
   138      Notice: this is inlined by the compiler(s) as a constant,
   161      Notice: this is inlined by the compiler(s) as a constant,
   139      therefore, a query like 'ExternalAddress pointerSize == 8'
   162      therefore, queries like 
   140      costs nothing; it is compiled in as a constant."
   163         'ExternalAddress pointerSize == 8'
       
   164      cost nothing; they are compiled in as a constant 
       
   165      (and even conditionals are eliminated)."
   141 
   166 
   142 %{ /* NOCONTEXT */
   167 %{ /* NOCONTEXT */
   143     RETURN(__mkSmallInteger(sizeof(void *)));
   168     RETURN(__mkSmallInteger(sizeof(void *)));
   144 %}.
   169 %}.
   145 
   170 
   146     "
   171     "
   147      self pointerSize
   172      self pointerSize
   148     "
   173     "
   149 ! !
   174 
       
   175     "Modified (comment): / 15-11-2016 / 11:56:38 / cg"
       
   176 !
       
   177 
       
   178 sizeOfPointer
       
   179     "answer the size in bytes of a pointer.
       
   180      Notice: this is inlined by the compiler(s) as a constant,
       
   181      therefore, queries like 
       
   182         'ExternalAddress pointerSize == 8'
       
   183      cost nothing; they are compiled in as a constant 
       
   184      (and even conditionals are eliminated)."
       
   185 
       
   186 %{ /* NOCONTEXT */
       
   187     RETURN(__mkSmallInteger(sizeof(void *)));
       
   188 %}.
       
   189 
       
   190     "
       
   191      self sizeOfPointer
       
   192     "
       
   193 
       
   194     "Created: / 15-11-2016 / 11:40:52 / cg"
       
   195 ! !
       
   196 
   150 
   197 
   151 !ExternalAddress methodsFor:'Compatibility-Squeak'!
   198 !ExternalAddress methodsFor:'Compatibility-Squeak'!
   152 
   199 
   153 beNull
   200 beNull
   154     self setAddress:0
   201     self setAddress:0
   306 
   353 
   307     if (__isSmallInteger(anInteger)) {
   354     if (__isSmallInteger(anInteger)) {
   308         addr = __intVal(anInteger);
   355         addr = __intVal(anInteger);
   309     } else {
   356     } else {
   310         addr = __unsignedLongIntVal(anInteger);
   357         addr = __unsignedLongIntVal(anInteger);
       
   358         if (addr == 0) {
       
   359             console_printf("invalid address argument in ExternalAddress>>setAddress\n");
       
   360         }
   311     }
   361     }
   312     __INST(address_) = (OBJ)addr;
   362     __INST(address_) = (OBJ)addr;
   313 %}
   363 %}
       
   364 
       
   365     "Modified: / 15-11-2016 / 11:59:24 / cg"
   314 !
   366 !
   315 
   367 
   316 setAddressFromBytes:aByteArray
   368 setAddressFromBytes:aByteArray
   317     "set the address from a pointer to which we have a pointer to"
   369     "set the address from a pointer to which we have a pointer to"
   318 
   370