Behavior.st
changeset 1133 961f2b095c22
parent 1088 989f0e510a32
child 1179 3e0f32177af4
equal deleted inserted replaced
1132:b09ce8542506 1133:961f2b095c22
   295      checking for behaviors."
   295      checking for behaviors."
   296 
   296 
   297 %{  /* NOCONTEXT */
   297 %{  /* NOCONTEXT */
   298     /* this is defined as a primitive to get defines from stc.h */
   298     /* this is defined as a primitive to get defines from stc.h */
   299 
   299 
   300     RETURN ( _MKSMALLINT(BEHAVIOR_INSTS) );
   300     RETURN ( __MKSMALLINT(BEHAVIOR_INSTS) );
   301 %}
   301 %}
   302 
   302 
   303     "consistency check:
   303     "consistency check:
   304      all class-entries must be behaviors;
   304      all class-entries must be behaviors;
   305      all behaviors must be flagged so (in its class's flags)
   305      all behaviors must be flagged so (in its class's flags)
   336      checking for blocks."
   336      checking for blocks."
   337 
   337 
   338 %{  /* NOCONTEXT */
   338 %{  /* NOCONTEXT */
   339     /* this is defined as a primitive to get defines from stc.h */
   339     /* this is defined as a primitive to get defines from stc.h */
   340 
   340 
   341     RETURN ( _MKSMALLINT(BLOCK_INSTS) );
   341     RETURN ( __MKSMALLINT(BLOCK_INSTS) );
   342 %}
   342 %}
   343 !
   343 !
   344 
   344 
   345 flagBlockContext
   345 flagBlockContext
   346     "return the flag code which marks BlockContext-like instances.
   346     "return the flag code which marks BlockContext-like instances.
   348      checking for blockContexts."
   348      checking for blockContexts."
   349 
   349 
   350 %{  /* NOCONTEXT */
   350 %{  /* NOCONTEXT */
   351     /* this is defined as a primitive to get defines from stc.h */
   351     /* this is defined as a primitive to get defines from stc.h */
   352 
   352 
   353     RETURN ( _MKSMALLINT(BCONTEXT_INSTS) );
   353     RETURN ( __MKSMALLINT(BCONTEXT_INSTS) );
   354 %}
   354 %}
   355 !
   355 !
   356 
   356 
   357 flagBytes
   357 flagBytes
   358     "return the flag code for byte-valued indexed instances.
   358     "return the flag code for byte-valued indexed instances.
   360      it with flagBytes."
   360      it with flagBytes."
   361 
   361 
   362 %{  /* NOCONTEXT */
   362 %{  /* NOCONTEXT */
   363     /* this is defined as a primitive to get defines from stc.h */
   363     /* this is defined as a primitive to get defines from stc.h */
   364 
   364 
   365     RETURN ( _MKSMALLINT(BYTEARRAY) );
   365     RETURN ( __MKSMALLINT(BYTEARRAY) );
   366 %}
   366 %}
   367     "
   367     "
   368      Behavior flagBytes    
   368      Behavior flagBytes    
   369     "
   369     "
   370 !
   370 !
   375      checking for contexts."
   375      checking for contexts."
   376 
   376 
   377 %{  /* NOCONTEXT */
   377 %{  /* NOCONTEXT */
   378     /* this is defined as a primitive to get defines from stc.h */
   378     /* this is defined as a primitive to get defines from stc.h */
   379 
   379 
   380     RETURN ( _MKSMALLINT(CONTEXT_INSTS) );
   380     RETURN ( __MKSMALLINT(CONTEXT_INSTS) );
   381 %}
   381 %}
   382 !
   382 !
   383 
   383 
   384 flagDoubles
   384 flagDoubles
   385     "return the flag code for double-valued indexed instances (i.e. 8-byte reals).
   385     "return the flag code for double-valued indexed instances (i.e. 8-byte reals).
   387      it with flagDoubles."
   387      it with flagDoubles."
   388 
   388 
   389 %{  /* NOCONTEXT */
   389 %{  /* NOCONTEXT */
   390     /* this is defined as a primitive to get defines from stc.h */
   390     /* this is defined as a primitive to get defines from stc.h */
   391 
   391 
   392     RETURN ( _MKSMALLINT(DOUBLEARRAY) );
   392     RETURN ( __MKSMALLINT(DOUBLEARRAY) );
   393 %}
   393 %}
   394     "
   394     "
   395      Behavior flagDoubles    
   395      Behavior flagDoubles    
   396     "
   396     "
   397 !
   397 !
   402      checking for floats."
   402      checking for floats."
   403 
   403 
   404 %{  /* NOCONTEXT */
   404 %{  /* NOCONTEXT */
   405     /* this is defined as a primitive to get defines from stc.h */
   405     /* this is defined as a primitive to get defines from stc.h */
   406 
   406 
   407     RETURN ( _MKSMALLINT(FLOAT_INSTS) );
   407     RETURN ( __MKSMALLINT(FLOAT_INSTS) );
   408 %}
   408 %}
   409 !
   409 !
   410 
   410 
   411 flagFloats
   411 flagFloats
   412     "return the flag code for float-valued indexed instances (i.e. 4-byte reals).
   412     "return the flag code for float-valued indexed instances (i.e. 4-byte reals).
   414      it with flagFloats."
   414      it with flagFloats."
   415 
   415 
   416 %{  /* NOCONTEXT */
   416 %{  /* NOCONTEXT */
   417     /* this is defined as a primitive to get defines from stc.h */
   417     /* this is defined as a primitive to get defines from stc.h */
   418 
   418 
   419     RETURN ( _MKSMALLINT(FLOATARRAY) );
   419     RETURN ( __MKSMALLINT(FLOATARRAY) );
   420 %}
   420 %}
   421     "
   421     "
   422      Behavior flagFloats    
   422      Behavior flagFloats    
   423     "
   423     "
   424 !
   424 !
   429      it with flagLongs."
   429      it with flagLongs."
   430 
   430 
   431 %{  /* NOCONTEXT */
   431 %{  /* NOCONTEXT */
   432     /* this is defined as a primitive to get defines from stc.h */
   432     /* this is defined as a primitive to get defines from stc.h */
   433 
   433 
   434     RETURN ( _MKSMALLINT(LONGARRAY) );
   434     RETURN ( __MKSMALLINT(LONGARRAY) );
   435 %}
   435 %}
   436     "
   436     "
   437      Behavior flagLongs    
   437      Behavior flagLongs    
   438     "
   438     "
   439 !
   439 !
   444      checking for methods."
   444      checking for methods."
   445 
   445 
   446 %{  /* NOCONTEXT */
   446 %{  /* NOCONTEXT */
   447     /* this is defined as a primitive to get defines from stc.h */
   447     /* this is defined as a primitive to get defines from stc.h */
   448 
   448 
   449     RETURN ( _MKSMALLINT(METHOD_INSTS) );
   449     RETURN ( __MKSMALLINT(METHOD_INSTS) );
   450 %}
   450 %}
   451 !
   451 !
   452 
   452 
   453 flagNonObjectInst
   453 flagNonObjectInst
   454     "return the flag code which marks instances which have a
   454     "return the flag code which marks instances which have a
   456      (these are ignored by the garbage collector)"
   456      (these are ignored by the garbage collector)"
   457 
   457 
   458 %{  /* NOCONTEXT */
   458 %{  /* NOCONTEXT */
   459     /* this is defined as a primitive to get defines from stc.h */
   459     /* this is defined as a primitive to get defines from stc.h */
   460 
   460 
   461     RETURN ( _MKSMALLINT(NONOBJECT_INSTS) );
   461     RETURN ( __MKSMALLINT(NONOBJECT_INSTS) );
   462 %}
   462 %}
   463 !
   463 !
   464 
   464 
   465 flagNotIndexed
   465 flagNotIndexed
   466     "return the flag code for non-indexed instances.
   466     "return the flag code for non-indexed instances.
   476      it with flagPointers."
   476      it with flagPointers."
   477 
   477 
   478 %{  /* NOCONTEXT */
   478 %{  /* NOCONTEXT */
   479     /* this is defined as a primitive to get defines from stc.h */
   479     /* this is defined as a primitive to get defines from stc.h */
   480 
   480 
   481     RETURN ( _MKSMALLINT(POINTERARRAY) );
   481     RETURN ( __MKSMALLINT(POINTERARRAY) );
   482 %}
   482 %}
   483     "
   483     "
   484      Behavior flagPointers    
   484      Behavior flagPointers    
   485     "
   485     "
   486 !
   486 !
   491      checking for symbols."
   491      checking for symbols."
   492 
   492 
   493 %{  /* NOCONTEXT */
   493 %{  /* NOCONTEXT */
   494     /* this is defined as a primitive to get defines from stc.h */
   494     /* this is defined as a primitive to get defines from stc.h */
   495 
   495 
   496     RETURN ( _MKSMALLINT(SYMBOL_INSTS) );
   496     RETURN ( __MKSMALLINT(SYMBOL_INSTS) );
   497 %}
   497 %}
   498 !
   498 !
   499 
   499 
   500 flagWeakPointers
   500 flagWeakPointers
   501     "return the flag code for weak pointer indexed instances (i.e. WeakArray).
   501     "return the flag code for weak pointer indexed instances (i.e. WeakArray).
   503      it with flagWeakPointers."
   503      it with flagWeakPointers."
   504 
   504 
   505 %{  /* NOCONTEXT */
   505 %{  /* NOCONTEXT */
   506     /* this is defined as a primitive to get defines from stc.h */
   506     /* this is defined as a primitive to get defines from stc.h */
   507 
   507 
   508     RETURN ( _MKSMALLINT(WKPOINTERARRAY) );
   508     RETURN ( __MKSMALLINT(WKPOINTERARRAY) );
   509 %}
   509 %}
   510 !
   510 !
   511 
   511 
   512 flagWords
   512 flagWords
   513     "return the flag code for word-valued indexed instances (i.e. 2-byte).
   513     "return the flag code for word-valued indexed instances (i.e. 2-byte).
   515      it with flagWords."
   515      it with flagWords."
   516 
   516 
   517 %{  /* NOCONTEXT */
   517 %{  /* NOCONTEXT */
   518     /* this is defined as a primitive to get defines from stc.h */
   518     /* this is defined as a primitive to get defines from stc.h */
   519 
   519 
   520     RETURN ( _MKSMALLINT(WORDARRAY) );
   520     RETURN ( __MKSMALLINT(WORDARRAY) );
   521 %}
   521 %}
   522     "
   522     "
   523      Behavior flagWords    
   523      Behavior flagWords    
   524     "
   524     "
   525 !
   525 !
   528     "return a mask to extract all index-type bits"
   528     "return a mask to extract all index-type bits"
   529 
   529 
   530 %{  /* NOCONTEXT */
   530 %{  /* NOCONTEXT */
   531     /* this is defined as a primitive to get defines from stc.h */
   531     /* this is defined as a primitive to get defines from stc.h */
   532 
   532 
   533     RETURN ( _MKSMALLINT(ARRAYMASK) );
   533     RETURN ( __MKSMALLINT(ARRAYMASK) );
   534 %}
   534 %}
   535 ! !
   535 ! !
   536 
   536 
   537 !Behavior class methodsFor:'private '!
   537 !Behavior class methodsFor:'private '!
   538 
   538 
  1363      * the following ugly code is nothing more than a __new() followed
  1363      * the following ugly code is nothing more than a __new() followed
  1364      * by a nilling of the new instance.
  1364      * by a nilling of the new instance.
  1365      * Unrolled for a bit more speed since this is one of the central object 
  1365      * Unrolled for a bit more speed since this is one of the central object 
  1366      * allocation methods in the system
  1366      * allocation methods in the system
  1367      */
  1367      */
  1368     nInstVars = _intVal(_INST(instSize));
  1368     nInstVars = __intVal(__INST(instSize));
  1369     instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
  1369     instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
  1370 
  1370 
  1371     newobj = (OBJ) __newNextPtr;
  1371     newobj = (OBJ) __newNextPtr;
  1372     nextPtr = ((char *)newobj) + instsize;
  1372     nextPtr = ((char *)newobj) + instsize;
  1373 
  1373 
  1390 	    __newNextPtr = nextPtr;
  1390 	    __newNextPtr = nextPtr;
  1391 	}
  1391 	}
  1392 #endif
  1392 #endif
  1393 
  1393 
  1394 ok:
  1394 ok:
  1395 	_InstPtr(newobj)->o_class = self;
  1395 	__InstPtr(newobj)->o_class = self;
  1396 	__qSTORE(newobj, self);
  1396 	__qSTORE(newobj, self);
  1397 
  1397 
  1398 	if (nInstVars) {
  1398 	if (nInstVars) {
  1399 #if defined(memset4) && defined(FAST_OBJECT_MEMSET4) || defined(FAST_MEMSET4)
  1399 #if defined(memset4) && defined(FAST_OBJECT_MEMSET4) || defined(FAST_MEMSET4)
  1400 	    memset4(_InstPtr(newobj)->i_instvars, nil, nInstVars);
  1400 	    memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars);
  1401 #else
  1401 #else
  1402 	    REGISTER OBJ *op;
  1402 	    REGISTER OBJ *op;
  1403 
  1403 
  1404 	    op = _InstPtr(newobj)->i_instvars;
  1404 	    op = __InstPtr(newobj)->i_instvars;
  1405 
  1405 
  1406 # if !defined(NEGATIVE_ADDRESSES)
  1406 # if !defined(NEGATIVE_ADDRESSES)
  1407 	    /*
  1407 	    /*
  1408 	     * knowing that nil is 0
  1408 	     * knowing that nil is 0
  1409 	     */
  1409 	     */
  1461 		*op++ = nil;
  1461 		*op++ = nil;
  1462 		nInstVars--;
  1462 		nInstVars--;
  1463 	    }
  1463 	    }
  1464 #    else
  1464 #    else
  1465 #     if defined(FAST_MEMSET)
  1465 #     if defined(FAST_MEMSET)
  1466 	    memset(_InstPtr(newobj)->i_instvars, 0, instsize-OHDR_SIZE);
  1466 	    memset(__InstPtr(newobj)->i_instvars, 0, instsize-OHDR_SIZE);
  1467 #     else
  1467 #     else
  1468 	    do {
  1468 	    do {
  1469 		*op++ = nil;
  1469 		*op++ = nil;
  1470 		nInstVars--;
  1470 		nInstVars--;
  1471 	    } while (nInstVars != 0);
  1471 	    } while (nInstVars != 0);
  1536     REGISTER OBJ *op;
  1536     REGISTER OBJ *op;
  1537     float *fp;
  1537     float *fp;
  1538     double *dp;
  1538     double *dp;
  1539 
  1539 
  1540     if (__isSmallInteger(anInteger)) {
  1540     if (__isSmallInteger(anInteger)) {
  1541 	nindexedinstvars = _intVal(anInteger);
  1541 	nindexedinstvars = __intVal(anInteger);
  1542 	if (nindexedinstvars >= 0) {
  1542 	if (nindexedinstvars >= 0) {
  1543 	    nInstVars = _intVal(_INST(instSize));
  1543 	    nInstVars = __intVal(__INST(instSize));
  1544 	    flags = _intVal(_INST(flags)) & ARRAYMASK;
  1544 	    flags = __intVal(__INST(flags)) & ARRAYMASK;
  1545 	    switch (flags) {
  1545 	    switch (flags) {
  1546 		case BYTEARRAY:
  1546 		case BYTEARRAY:
  1547 		    instsize = OHDR_SIZE + nindexedinstvars;
  1547 		    instsize = OHDR_SIZE + nindexedinstvars;
  1548 		    if (nInstVars == 0) {
  1548 		    if (nInstVars == 0) {
  1549 			if (__CanDoQuickNew(instsize)) {
  1549 			if (__CanDoQuickNew(instsize)) {
  1550 			    /*
  1550 			    /*
  1551 			     * the most common case
  1551 			     * the most common case
  1552 			     */
  1552 			     */
  1553 			    __qCheckedNew(newobj, instsize);
  1553 			    __qCheckedNew(newobj, instsize);
  1554 			    _InstPtr(newobj)->o_class = self;
  1554 			    __InstPtr(newobj)->o_class = self;
  1555 #if defined(memset4) && defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4)
  1555 #if defined(memset4) && defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4)
  1556 			    nInstVars = nindexedinstvars >> 2;
  1556 			    nInstVars = nindexedinstvars >> 2;
  1557 			    if (nindexedinstvars & 3) nInstVars++;
  1557 			    if (nindexedinstvars & 3) nInstVars++;
  1558 			    memset4(_InstPtr(newobj)->i_instvars, 0, nInstVars);
  1558 			    memset4(__InstPtr(newobj)->i_instvars, 0, nInstVars);
  1559 #else
  1559 #else
  1560 # if defined(FAST_ARRAY_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
  1560 # if defined(FAST_ARRAY_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
  1561 			    memset(_InstPtr(newobj)->i_instvars, 0, nindexedinstvars);
  1561 			    memset(__InstPtr(newobj)->i_instvars, 0, nindexedinstvars);
  1562 # else
  1562 # else
  1563 			    cp = (char *)_InstPtr(newobj)->i_instvars;
  1563 			    cp = (char *)__InstPtr(newobj)->i_instvars;
  1564 			    while (nindexedinstvars >= sizeof(long)) {
  1564 			    while (nindexedinstvars >= sizeof(long)) {
  1565 				*(long *)cp = 0;
  1565 				*(long *)cp = 0;
  1566 				cp += sizeof(long);
  1566 				cp += sizeof(long);
  1567 				nindexedinstvars -= sizeof(long);
  1567 				nindexedinstvars -= sizeof(long);
  1568 			    }
  1568 			    }
  1579 		    __qNew(newobj, instsize, SENDER);
  1579 		    __qNew(newobj, instsize, SENDER);
  1580 		    __UNPROTECT_CONTEXT__
  1580 		    __UNPROTECT_CONTEXT__
  1581 		    if (newobj == nil) {
  1581 		    if (newobj == nil) {
  1582 			break;
  1582 			break;
  1583 		    }
  1583 		    }
  1584 		    _InstPtr(newobj)->o_class = self;
  1584 		    __InstPtr(newobj)->o_class = self;
  1585 		    __qSTORE(newobj, self);
  1585 		    __qSTORE(newobj, self);
  1586 
  1586 
  1587 #if defined(memset4) && defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4)
  1587 #if defined(memset4) && defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4)
  1588 		    nInstVars = (instsize-OHDR_SIZE) >> 2;
  1588 		    nInstVars = (instsize-OHDR_SIZE) >> 2;
  1589 		    if (instsize & 3) nInstVars++;
  1589 		    if (instsize & 3) nInstVars++;
  1590 		    memset4(_InstPtr(newobj)->i_instvars, 0, nInstVars);
  1590 		    memset4(__InstPtr(newobj)->i_instvars, 0, nInstVars);
  1591 #else
  1591 #else
  1592 # if defined(FAST_ARRAY_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
  1592 # if defined(FAST_ARRAY_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
  1593 		    /*
  1593 		    /*
  1594 		     * knowing that nil is 0
  1594 		     * knowing that nil is 0
  1595 		     */
  1595 		     */
  1596 		    memset(_InstPtr(newobj)->i_instvars, 0, instsize-OHDR_SIZE);
  1596 		    memset(__InstPtr(newobj)->i_instvars, 0, instsize-OHDR_SIZE);
  1597 # else
  1597 # else
  1598 		    op = _InstPtr(newobj)->i_instvars;
  1598 		    op = __InstPtr(newobj)->i_instvars;
  1599 		    while (nInstVars--)
  1599 		    while (nInstVars--)
  1600 			*op++ = nil;
  1600 			*op++ = nil;
  1601 		    cp = (char *)op;
  1601 		    cp = (char *)op;
  1602 		    while (nindexedinstvars >= sizeof(long)) {
  1602 		    while (nindexedinstvars >= sizeof(long)) {
  1603 			*(long *)cp = 0;
  1603 			*(long *)cp = 0;
  1619 		    __qNew(newobj, instsize, SENDER);
  1619 		    __qNew(newobj, instsize, SENDER);
  1620 		    __UNPROTECT_CONTEXT__
  1620 		    __UNPROTECT_CONTEXT__
  1621 		    if (newobj == nil) {
  1621 		    if (newobj == nil) {
  1622 			break;
  1622 			break;
  1623 		    }
  1623 		    }
  1624 		    _InstPtr(newobj)->o_class = self;
  1624 		    __InstPtr(newobj)->o_class = self;
  1625 		    __qSTORE(newobj, self);
  1625 		    __qSTORE(newobj, self);
  1626 
  1626 
  1627 #if defined(FAST_ARRAY_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
  1627 #if defined(FAST_ARRAY_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
  1628 		    /*
  1628 		    /*
  1629 		     * knowing that nil is 0
  1629 		     * knowing that nil is 0
  1630 		     */
  1630 		     */
  1631 		    memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
  1631 		    memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
  1632 #else
  1632 #else
  1633 		    op = _InstPtr(newobj)->i_instvars;
  1633 		    op = __InstPtr(newobj)->i_instvars;
  1634 		    while (nInstVars--)
  1634 		    while (nInstVars--)
  1635 			*op++ = nil;
  1635 			*op++ = nil;
  1636 		    sp = (short *)op;
  1636 		    sp = (short *)op;
  1637 		    while (nindexedinstvars--)
  1637 		    while (nindexedinstvars--)
  1638 			*sp++ = 0;
  1638 			*sp++ = 0;
  1648 		    __qAlignedNew(newobj, instsize, SENDER);
  1648 		    __qAlignedNew(newobj, instsize, SENDER);
  1649 		    __UNPROTECT_CONTEXT__
  1649 		    __UNPROTECT_CONTEXT__
  1650 		    if (newobj == nil) {
  1650 		    if (newobj == nil) {
  1651 			break;
  1651 			break;
  1652 		    }
  1652 		    }
  1653 		    _InstPtr(newobj)->o_class = self;
  1653 		    __InstPtr(newobj)->o_class = self;
  1654 		    __qSTORE(newobj, self);
  1654 		    __qSTORE(newobj, self);
  1655 
  1655 
  1656 #if defined(memset4) && defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4)
  1656 #if defined(memset4) && defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4)
  1657 		    /*
  1657 		    /*
  1658 		     * knowing that nil is 0
  1658 		     * knowing that nil is 0
  1659 		     */
  1659 		     */
  1660 		    memset4(_InstPtr(newobj)->i_instvars, 0, nInstVars + nindexedinstvars);
  1660 		    memset4(__InstPtr(newobj)->i_instvars, 0, nInstVars + nindexedinstvars);
  1661 #else
  1661 #else
  1662 # if defined(FAST_ARRAY_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
  1662 # if defined(FAST_ARRAY_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
  1663 		    /*
  1663 		    /*
  1664 		     * knowing that nil is 0
  1664 		     * knowing that nil is 0
  1665 		     */
  1665 		     */
  1666 		    memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
  1666 		    memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
  1667 # else
  1667 # else
  1668 		    op = _InstPtr(newobj)->i_instvars;
  1668 		    op = __InstPtr(newobj)->i_instvars;
  1669 		    while (nInstVars--)
  1669 		    while (nInstVars--)
  1670 			*op++ = nil;
  1670 			*op++ = nil;
  1671 		    lp = (long *)op;
  1671 		    lp = (long *)op;
  1672 		    while (nindexedinstvars--)
  1672 		    while (nindexedinstvars--)
  1673 			*lp++ = 0;
  1673 			*lp++ = 0;
  1685 		    __qNew(newobj, instsize, SENDER);
  1685 		    __qNew(newobj, instsize, SENDER);
  1686 		    __UNPROTECT_CONTEXT__
  1686 		    __UNPROTECT_CONTEXT__
  1687 		    if (newobj == nil) {
  1687 		    if (newobj == nil) {
  1688 			break;
  1688 			break;
  1689 		    }
  1689 		    }
  1690 		    _InstPtr(newobj)->o_class = self;
  1690 		    __InstPtr(newobj)->o_class = self;
  1691 		    __qSTORE(newobj, self);
  1691 		    __qSTORE(newobj, self);
  1692 
  1692 
  1693 		    op = _InstPtr(newobj)->i_instvars;
  1693 		    op = __InstPtr(newobj)->i_instvars;
  1694 # if defined(mips) /* knowin that float 0.0 is all-zeros */
  1694 # if defined(mips) /* knowin that float 0.0 is all-zeros */
  1695 		    memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
  1695 		    memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
  1696 # else
  1696 # else
  1697 		    while (nInstVars--)
  1697 		    while (nInstVars--)
  1698 			*op++ = nil;
  1698 			*op++ = nil;
  1699 		    fp = (float *)op;
  1699 		    fp = (float *)op;
  1700 		    while (nindexedinstvars--)
  1700 		    while (nindexedinstvars--)
  1712 		    __qAlignedNew(newobj, instsize, SENDER);
  1712 		    __qAlignedNew(newobj, instsize, SENDER);
  1713 		    __UNPROTECT_CONTEXT__
  1713 		    __UNPROTECT_CONTEXT__
  1714 		    if (newobj == nil) {
  1714 		    if (newobj == nil) {
  1715 			break;
  1715 			break;
  1716 		    }
  1716 		    }
  1717 		    _InstPtr(newobj)->o_class = self;
  1717 		    __InstPtr(newobj)->o_class = self;
  1718 		    __qSTORE(newobj, self);
  1718 		    __qSTORE(newobj, self);
  1719 
  1719 
  1720 		    op = _InstPtr(newobj)->i_instvars;
  1720 		    op = __InstPtr(newobj)->i_instvars;
  1721 		    while (nInstVars--)
  1721 		    while (nInstVars--)
  1722 			*op++ = nil;
  1722 			*op++ = nil;
  1723 #ifdef NEED_DOUBLE_ALIGN
  1723 #ifdef NEED_DOUBLE_ALIGN
  1724 		    /*
  1724 		    /*
  1725 		     * care for double alignment
  1725 		     * care for double alignment
  1742 		    __qAlignedNew(newobj, instsize, SENDER);
  1742 		    __qAlignedNew(newobj, instsize, SENDER);
  1743 		    __UNPROTECT_CONTEXT__
  1743 		    __UNPROTECT_CONTEXT__
  1744 		    if (newobj == nil) {
  1744 		    if (newobj == nil) {
  1745 			break;
  1745 			break;
  1746 		    }
  1746 		    }
  1747 		    _InstPtr(newobj)->o_class = self;
  1747 		    __InstPtr(newobj)->o_class = self;
  1748 		    __qSTORE(newobj, self);
  1748 		    __qSTORE(newobj, self);
  1749 
  1749 
  1750 #if defined(memset4) && defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4)
  1750 #if defined(memset4) && defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4)
  1751 		    memset4(_InstPtr(newobj)->i_instvars, nil, nInstVars);
  1751 		    memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars);
  1752 #else
  1752 #else
  1753 # if !defined(NEGATIVE_ADDRESSES)
  1753 # if !defined(NEGATIVE_ADDRESSES)
  1754 		    /*
  1754 		    /*
  1755 		     * knowing that nil is 0
  1755 		     * knowing that nil is 0
  1756 		     */
  1756 		     */
  1763 #ifdef sparc
  1763 #ifdef sparc
  1764 # define FAST_ARRAY_MEMSET_DOUBLES_UNROLLED
  1764 # define FAST_ARRAY_MEMSET_DOUBLES_UNROLLED
  1765 #endif
  1765 #endif
  1766 
  1766 
  1767 #  if defined(FAST_ARRAY_MEMSET_DOUBLES_UNROLLED)
  1767 #  if defined(FAST_ARRAY_MEMSET_DOUBLES_UNROLLED)
  1768 		    op = _InstPtr(newobj)->i_instvars;
  1768 		    op = __InstPtr(newobj)->i_instvars;
  1769 		    if (nInstVars > 8) {
  1769 		    if (nInstVars > 8) {
  1770 			*op++ = nil;    /* for alignment */
  1770 			*op++ = nil;    /* for alignment */
  1771 			nInstVars--;
  1771 			nInstVars--;
  1772 			while (nInstVars >= 8) {
  1772 			while (nInstVars >= 8) {
  1773 			    *(double *)op = 0.0;
  1773 			    *(double *)op = 0.0;
  1782 			*op++ = 0;
  1782 			*op++ = 0;
  1783 			nInstVars--;
  1783 			nInstVars--;
  1784 		    }
  1784 		    }
  1785 #  else
  1785 #  else
  1786 #   if defined(FAST_ARRAY_MEMSET_LONGLONG_UNROLLED)
  1786 #   if defined(FAST_ARRAY_MEMSET_LONGLONG_UNROLLED)
  1787 		    op = _InstPtr(newobj)->i_instvars;
  1787 		    op = __InstPtr(newobj)->i_instvars;
  1788 		    if (nInstVars > 8) {
  1788 		    if (nInstVars > 8) {
  1789 			*op++ = nil;    /* for alignment */
  1789 			*op++ = nil;    /* for alignment */
  1790 			nInstVars--;
  1790 			nInstVars--;
  1791 			while (nInstVars >= 8) {
  1791 			while (nInstVars >= 8) {
  1792 			    *(long long *)op = 0;
  1792 			    *(long long *)op = 0;
  1801 			*op++ = 0;
  1801 			*op++ = 0;
  1802 			nInstVars--;
  1802 			nInstVars--;
  1803 		    }
  1803 		    }
  1804 #   else
  1804 #   else
  1805 #    if defined(FAST_ARRAY_MEMSET)
  1805 #    if defined(FAST_ARRAY_MEMSET)
  1806 		    memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
  1806 		    memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
  1807 #    else
  1807 #    else
  1808 		    op = _InstPtr(newobj)->i_instvars;
  1808 		    op = __InstPtr(newobj)->i_instvars;
  1809 		    while (nInstVars--)
  1809 		    while (nInstVars--)
  1810 			*op++ = nil;
  1810 			*op++ = nil;
  1811 #    endif
  1811 #    endif
  1812 #   endif
  1812 #   endif
  1813 #  endif
  1813 #  endif
  1814 # else
  1814 # else
  1815 		    op = _InstPtr(newobj)->i_instvars;
  1815 		    op = __InstPtr(newobj)->i_instvars;
  1816 		    while (nInstVars--)
  1816 		    while (nInstVars--)
  1817 			*op++ = nil;
  1817 			*op++ = nil;
  1818 # endif
  1818 # endif
  1819 #endif
  1819 #endif
  1820 		    RETURN ( newobj );
  1820 		    RETURN ( newobj );
  1831 			__qAlignedNew(newobj, instsize, SENDER);
  1831 			__qAlignedNew(newobj, instsize, SENDER);
  1832 			__UNPROTECT_CONTEXT__
  1832 			__UNPROTECT_CONTEXT__
  1833 			if (newobj == nil) {
  1833 			if (newobj == nil) {
  1834 			    break;
  1834 			    break;
  1835 			}
  1835 			}
  1836 			_InstPtr(newobj)->o_class = self;
  1836 			__InstPtr(newobj)->o_class = self;
  1837 			__qSTORE(newobj, self);
  1837 			__qSTORE(newobj, self);
  1838 
  1838 
  1839 			if (nInstVars) {
  1839 			if (nInstVars) {
  1840 #if defined(memset4) && defined(FAST_OBJECT_MEMSET4) || defined(FAST_MEMSET4)
  1840 #if defined(memset4) && defined(FAST_OBJECT_MEMSET4) || defined(FAST_MEMSET4)
  1841 			    memset4(_InstPtr(newobj)->i_instvars, nil, nInstVars);
  1841 			    memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars);
  1842 #else
  1842 #else
  1843 # if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
  1843 # if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
  1844 			    /*
  1844 			    /*
  1845 			     * knowing that nil is 0
  1845 			     * knowing that nil is 0
  1846 			     */
  1846 			     */
  1847 			    memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
  1847 			    memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
  1848 # else
  1848 # else
  1849 			    op = _InstPtr(newobj)->i_instvars;
  1849 			    op = __InstPtr(newobj)->i_instvars;
  1850 			    do {
  1850 			    do {
  1851 				*op++ = nil;
  1851 				*op++ = nil;
  1852 			    } while (--nInstVars);
  1852 			    } while (--nInstVars);
  1853 # endif
  1853 # endif
  1854 #endif
  1854 #endif
  2587 
  2587 
  2588 %{  /* NOCONTEXT */
  2588 %{  /* NOCONTEXT */
  2589 
  2589 
  2590     REGISTER int what;
  2590     REGISTER int what;
  2591 
  2591 
  2592     what = (INT)(_INST(flags)) & __MASKSMALLINT(ARRAYMASK);
  2592     what = (INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK);
  2593     RETURN (( (what == __MASKSMALLINT(BYTEARRAY))
  2593     RETURN (( (what == __MASKSMALLINT(BYTEARRAY))
  2594 	     || (what == __MASKSMALLINT(WORDARRAY))) ? true : false ); 
  2594 	     || (what == __MASKSMALLINT(WORDARRAY))) ? true : false ); 
  2595 %}
  2595 %}
  2596 !
  2596 !
  2597 
  2597 
  2601     "this could also be defined as:
  2601     "this could also be defined as:
  2602 	^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagBytes
  2602 	^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagBytes
  2603     "
  2603     "
  2604 %{  /* NOCONTEXT */
  2604 %{  /* NOCONTEXT */
  2605 
  2605 
  2606     RETURN ( (((INT)(_INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(BYTEARRAY)) ? true : false ); 
  2606     RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(BYTEARRAY)) ? true : false ); 
  2607 %}
  2607 %}
  2608 !
  2608 !
  2609 
  2609 
  2610 isDoubles
  2610 isDoubles
  2611     "return true, if instances have indexed double instance variables"
  2611     "return true, if instances have indexed double instance variables"
  2613     "this could also be defined as:
  2613     "this could also be defined as:
  2614 	^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagDoubles
  2614 	^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagDoubles
  2615     "
  2615     "
  2616 %{  /* NOCONTEXT */
  2616 %{  /* NOCONTEXT */
  2617 
  2617 
  2618     RETURN ( (((INT)(_INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(DOUBLEARRAY)) ? true : false ); 
  2618     RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(DOUBLEARRAY)) ? true : false ); 
  2619 %}
  2619 %}
  2620 !
  2620 !
  2621 
  2621 
  2622 isFixed
  2622 isFixed
  2623     "return true, if instances do not have indexed instance variables"
  2623     "return true, if instances do not have indexed instance variables"
  2626 	^ self isVariable not
  2626 	^ self isVariable not
  2627     "
  2627     "
  2628 
  2628 
  2629 %{  /* NOCONTEXT */
  2629 %{  /* NOCONTEXT */
  2630 
  2630 
  2631     RETURN ( ((INT)(_INST(flags)) & __MASKSMALLINT(ARRAYMASK)) ? false : true ); 
  2631     RETURN ( ((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) ? false : true ); 
  2632 %}
  2632 %}
  2633 !
  2633 !
  2634 
  2634 
  2635 isFloats
  2635 isFloats
  2636     "return true, if instances have indexed float instance variables"
  2636     "return true, if instances have indexed float instance variables"
  2638     "this could also be defined as:
  2638     "this could also be defined as:
  2639 	^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagFloats
  2639 	^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagFloats
  2640     "
  2640     "
  2641 %{  /* NOCONTEXT */
  2641 %{  /* NOCONTEXT */
  2642 
  2642 
  2643     RETURN ( (((INT)(_INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(FLOATARRAY)) ? true : false ); 
  2643     RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(FLOATARRAY)) ? true : false ); 
  2644 %}
  2644 %}
  2645 !
  2645 !
  2646 
  2646 
  2647 isFloatsOrDoubles
  2647 isFloatsOrDoubles
  2648     "return true, if instances have indexed float or double instance variables"
  2648     "return true, if instances have indexed float or double instance variables"
  2649 
  2649 
  2650 %{  /* NOCONTEXT */
  2650 %{  /* NOCONTEXT */
  2651 
  2651 
  2652     int what;
  2652     int what;
  2653 
  2653 
  2654     what = (INT)(_INST(flags)) & __MASKSMALLINT(ARRAYMASK);
  2654     what = (INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK);
  2655     RETURN (( (what == __MASKSMALLINT(FLOATARRAY))
  2655     RETURN (( (what == __MASKSMALLINT(FLOATARRAY))
  2656 	     || (what == __MASKSMALLINT(DOUBLEARRAY))) ? true : false ); 
  2656 	     || (what == __MASKSMALLINT(DOUBLEARRAY))) ? true : false ); 
  2657 %}
  2657 %}
  2658     "
  2658     "
  2659      (Object new) class isFloatsOrDoubles 
  2659      (Object new) class isFloatsOrDoubles 
  2671     "this could also be defined as:
  2671     "this could also be defined as:
  2672 	^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagLongs
  2672 	^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagLongs
  2673     "
  2673     "
  2674 %{  /* NOCONTEXT */
  2674 %{  /* NOCONTEXT */
  2675 
  2675 
  2676     RETURN ( (((INT)(_INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(LONGARRAY)) ? true : false ); 
  2676     RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(LONGARRAY)) ? true : false ); 
  2677 %}
  2677 %}
  2678 !
  2678 !
  2679 
  2679 
  2680 isPointers
  2680 isPointers
  2681     "return true, if instances have pointer instance variables 
  2681     "return true, if instances have pointer instance variables 
  2685 
  2685 
  2686 %{  /* NOCONTEXT */
  2686 %{  /* NOCONTEXT */
  2687 
  2687 
  2688     REGISTER int flags;
  2688     REGISTER int flags;
  2689 
  2689 
  2690     flags = _intVal(_INST(flags)) & ARRAYMASK;
  2690     flags = __intVal(__INST(flags)) & ARRAYMASK;
  2691     switch (flags) {
  2691     switch (flags) {
  2692 	default:
  2692 	default:
  2693 	    /* normal objects */
  2693 	    /* normal objects */
  2694 	    RETURN ( true );
  2694 	    RETURN ( true );
  2695 
  2695 
  2740 	^ (flags bitAnd:(Behavior maskIndexType)) ~~ 0
  2740 	^ (flags bitAnd:(Behavior maskIndexType)) ~~ 0
  2741      "
  2741      "
  2742 
  2742 
  2743 %{  /* NOCONTEXT */
  2743 %{  /* NOCONTEXT */
  2744 
  2744 
  2745     RETURN ( ((INT)(_INST(flags)) & __MASKSMALLINT(ARRAYMASK)) ? true : false ); 
  2745     RETURN ( ((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) ? true : false ); 
  2746 %}
  2746 %}
  2747 !
  2747 !
  2748 
  2748 
  2749 isWords
  2749 isWords
  2750     "return true, if instances have indexed short instance variables"
  2750     "return true, if instances have indexed short instance variables"
  2752     "this could also be defined as:
  2752     "this could also be defined as:
  2753 	^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagWords
  2753 	^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagWords
  2754     "
  2754     "
  2755 %{  /* NOCONTEXT */
  2755 %{  /* NOCONTEXT */
  2756 
  2756 
  2757     RETURN ( (((INT)(_INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(WORDARRAY)) ? true : false ); 
  2757     RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(WORDARRAY)) ? true : false ); 
  2758 %}
  2758 %}
  2759 !
  2759 !
  2760 
  2760 
  2761 lookupMethodFor:aSelector
  2761 lookupMethodFor:aSelector
  2762     "return the method, which would be executed if aSelector was sent to
  2762     "return the method, which would be executed if aSelector was sent to
  2843 
  2843 
  2844     nInstvars := self instSize.
  2844     nInstvars := self instSize.
  2845 %{
  2845 %{
  2846     int nBytes;
  2846     int nBytes;
  2847 
  2847 
  2848     nBytes = _intVal(nInstvars) * sizeof(OBJ) + OHDR_SIZE; 
  2848     nBytes = __intVal(nInstvars) * sizeof(OBJ) + OHDR_SIZE; 
  2849     if (__isSmallInteger(n)) {
  2849     if (__isSmallInteger(n)) {
  2850 	int nIndex;
  2850 	int nIndex;
  2851 
  2851 
  2852 	nIndex = _intVal(n);
  2852 	nIndex = __intVal(n);
  2853 	switch (_intVal(_INST(flags)) & ARRAYMASK) {
  2853 	switch (__intVal(__INST(flags)) & ARRAYMASK) {
  2854 	    case BYTEARRAY:
  2854 	    case BYTEARRAY:
  2855 		nBytes += nIndex;
  2855 		nBytes += nIndex;
  2856 		if (nBytes & (ALIGN - 1)) {
  2856 		if (nBytes & (ALIGN - 1)) {
  2857 		    nBytes = (nBytes & ~(ALIGN - 1)) + ALIGN;
  2857 		    nBytes = (nBytes & ~(ALIGN - 1)) + ALIGN;
  2858 		}
  2858 		}
  2880 	    default:
  2880 	    default:
  2881 		nBytes += nIndex * sizeof(OBJ);
  2881 		nBytes += nIndex * sizeof(OBJ);
  2882 		break;
  2882 		break;
  2883 	}
  2883 	}
  2884     }
  2884     }
  2885     RETURN (_MKSMALLINT(nBytes));
  2885     RETURN (__MKSMALLINT(nBytes));
  2886 %}
  2886 %}
  2887 !
  2887 !
  2888 
  2888 
  2889 sourceCodeAt:aSelector
  2889 sourceCodeAt:aSelector
  2890     "return the methods source for given selector aSelector or nil.
  2890     "return the methods source for given selector aSelector or nil.
  3028 ! !
  3028 ! !
  3029 
  3029 
  3030 !Behavior class methodsFor:'documentation'!
  3030 !Behavior class methodsFor:'documentation'!
  3031 
  3031 
  3032 version
  3032 version
  3033     ^ '$Header: /cvs/stx/stx/libbasic/Behavior.st,v 1.65 1996-03-07 18:40:50 cg Exp $'
  3033     ^ '$Header: /cvs/stx/stx/libbasic/Behavior.st,v 1.66 1996-04-02 21:58:42 cg Exp $'
  3034 ! !
  3034 ! !