Behavior.st
branchjv
changeset 21024 8734987eb5c7
parent 20580 bb4e5c4f84ef
parent 20823 73e7da80f87c
child 21026 81e280fc1b93
equal deleted inserted replaced
20729:5a09e2a164af 21024:8734987eb5c7
  1330      SmallInteger selectorsWithArgs:4
  1330      SmallInteger selectorsWithArgs:4
  1331     "
  1331     "
  1332 !
  1332 !
  1333 
  1333 
  1334 theNonMetaClass
  1334 theNonMetaClass
       
  1335     <resource: #obsolete>
       
  1336     
  1335     "alias for theNonMetaclass (Squeak) - return the class.
  1337     "alias for theNonMetaclass (Squeak) - return the class.
  1336      sigh; in ST/X, it is called theNonMetaclass; please use that."
  1338      sigh; in ST/X, it is called theNonMetaclass; please use that."
  1337 
  1339 
  1338     ^ self theNonMetaclass
  1340     ^ self theNonMetaclass
  1339 
  1341 
  1420 
  1422 
  1421 shortName
  1423 shortName
  1422     ^ self nameWithoutPrefix
  1424     ^ self nameWithoutPrefix
  1423 ! !
  1425 ! !
  1424 
  1426 
  1425 
       
  1426 !Behavior methodsFor:'RefactoringBrowser'!
  1427 !Behavior methodsFor:'RefactoringBrowser'!
  1427 
  1428 
  1428 realClass
  1429 realClass
  1429     "for compatibility with RBAbstractClass"
  1430     "for compatibility with RBAbstractClass"
  1430 
  1431 
  1438      1st argument to the methodDictionary. Flushes all caches."
  1439      1st argument to the methodDictionary. Flushes all caches."
  1439 
  1440 
  1440     |oldMethod ns nsName selector newLookupObject|
  1441     |oldMethod ns nsName selector newLookupObject|
  1441 
  1442 
  1442     (newSelector isMemberOf:Symbol) ifFalse:[
  1443     (newSelector isMemberOf:Symbol) ifFalse:[
  1443         self error:'invalid selector'.
  1444 	self error:'invalid selector'.
  1444     ].
  1445     ].
  1445 
  1446 
  1446     ns := newMethod nameSpace.
  1447     ns := newMethod nameSpace.
  1447     (ns notNil and:[(nsName := ns name) ~= self programmingLanguage defaultSelectorNameSpacePrefix]) ifTrue:[
  1448     (ns notNil and:[(nsName := ns name) ~= self programmingLanguage defaultSelectorNameSpacePrefix]) ifTrue:[
  1448         selector := (':' , nsName , '::' , newSelector) asSymbol.
  1449 	selector := (':' , nsName , '::' , newSelector) asSymbol.
  1449         newLookupObject := Smalltalk at: #NamespaceAwareLookup. "/ so it can be nilled to disable that feature
  1450 	newLookupObject := Smalltalk at: #NamespaceAwareLookup. "/ so it can be nilled to disable that feature
  1450     ] ifFalse:[
  1451     ] ifFalse:[
  1451         selector := newSelector
  1452 	selector := newSelector
  1452     ].
  1453     ].
  1453 
  1454 
  1454     "/ Q (cg): isn't that something that the caller should decide?
  1455     "/ Q (cg): isn't that something that the caller should decide?
  1455     oldMethod := self compiledMethodAt:selector.
  1456     oldMethod := self compiledMethodAt:selector.
  1456     oldMethod notNil ifTrue:[
  1457     oldMethod notNil ifTrue:[
  1457         newMethod restricted:(oldMethod isRestricted).
  1458 	newMethod restricted:(oldMethod isRestricted).
  1458         newMethod setPrivacy:(oldMethod privacy) flushCaches:false.
  1459 	newMethod setPrivacy:(oldMethod privacy) flushCaches:false.
  1459     ].
  1460     ].
  1460 
  1461 
  1461     (self primAddSelector:selector withMethod:newMethod) ifFalse:[^ false].
  1462     (self primAddSelector:selector withMethod:newMethod) ifFalse:[^ false].
  1462 
  1463 
  1463     newLookupObject notNil ifTrue:[
  1464     newLookupObject notNil ifTrue:[
  1464         lookupObject ~= newLookupObject ifTrue:[
  1465 	lookupObject ~= newLookupObject ifTrue:[
  1465             self lookupObject: newLookupObject
  1466 	    self lookupObject: newLookupObject
  1466         ]
  1467 	]
  1467     ].
  1468     ].
  1468 
  1469 
  1469     "
  1470     "
  1470      if I have no subclasses, all we have to flush is cached
  1471      if I have no subclasses, all we have to flush is cached
  1471      data for myself ... (actually, in any case all that needs
  1472      data for myself ... (actually, in any case all that needs
  1472      to be flushed is info for myself and all of my subclasses)
  1473      to be flushed is info for myself and all of my subclasses)
  1473     "
  1474     "
  1474 "
  1475 "
  1475     problem: this is slower; since looking for all subclasses is (currently)
  1476     problem: this is slower; since looking for all subclasses is (currently)
  1476              a bit slow :-(
  1477 	     a bit slow :-(
  1477              We need the hasSubclasses-info bit in Behavior; now
  1478 	     We need the hasSubclasses-info bit in Behavior; now
  1478 
  1479 
  1479     self withAllSubclassesDo:[:aClass |
  1480     self withAllSubclassesDo:[:aClass |
  1480         ObjectMemory flushInlineCachesFor:aClass withArgs:nargs.
  1481 	ObjectMemory flushInlineCachesFor:aClass withArgs:nargs.
  1481         ObjectMemory flushMethodCacheFor:aClass
  1482 	ObjectMemory flushMethodCacheFor:aClass
  1482     ].
  1483     ].
  1483 "
  1484 "
  1484 
  1485 
  1485     "/
  1486     "/
  1486     "/ pass the selector AND the old method as changeArg
  1487     "/ pass the selector AND the old method as changeArg
  1731 
  1732 
  1732 
  1733 
  1733 !Behavior methodsFor:'cleanup'!
  1734 !Behavior methodsFor:'cleanup'!
  1734 
  1735 
  1735 flushSubclasses
  1736 flushSubclasses
  1736     "I dont keep my subclasses - but if anyone inherits from me,
  1737     "I don't keep my subclasses - but if anyone inherits from me,
  1737      it better knows how to ignore this"
  1738      it better knows how to ignore this"
  1738 !
  1739 !
  1739 
  1740 
  1740 lowSpaceCleanup
  1741 lowSpaceCleanup
  1741     "ignored here - redefined in some classes to
  1742     "ignored here - redefined in some classes to
  2522      a garbage collect.
  2523      a garbage collect.
  2523      This means, that the VM wanted to get some more memory from the
  2524      This means, that the VM wanted to get some more memory from the
  2524      Operatingsystem, which was not kind enough to give it.
  2525      Operatingsystem, which was not kind enough to give it.
  2525      Bad luck - you should increase the swap space on your machine.
  2526      Bad luck - you should increase the swap space on your machine.
  2526     "
  2527     "
  2527     ^ ObjectMemory allocationFailureSignal raise.
  2528     ^ AllocationFailure raise.
  2528 !
  2529 !
  2529 
  2530 
  2530 basicNew:anInteger
  2531 basicNew:anInteger
  2531     "return an instance of myself with anInteger indexed variables.
  2532     "return an instance of myself with anInteger indexed variables.
  2532      If the receiver-class has no indexed instvars, this is only allowed
  2533      If the receiver-class has no indexed instvars, this is only allowed
  2888      a garbage collect.
  2889      a garbage collect.
  2889      This means, that the VM wanted to get some more memory from the
  2890      This means, that the VM wanted to get some more memory from the
  2890      Operatingsystem, which was not kind enough to give it.
  2891      Operatingsystem, which was not kind enough to give it.
  2891      Bad luck - you should increase the swap space on your machine.
  2892      Bad luck - you should increase the swap space on your machine.
  2892     "
  2893     "
  2893     ^ ObjectMemory allocationFailureSignal raise.
  2894     ^ AllocationFailure raise.
  2894 !
  2895 !
  2895 
  2896 
  2896 decodeFromLiteralArray:anArray
  2897 decodeFromLiteralArray:anArray
  2897     "create & return a new instance from information encoded in anArray."
  2898     "create & return a new instance from information encoded in anArray."
  2898 
  2899 
  3615     ^ nil
  3616     ^ nil
  3616 !
  3617 !
  3617 
  3618 
  3618 nameWithArticle
  3619 nameWithArticle
  3619     "return a string consisting of classname preceeded by an article.
  3620     "return a string consisting of classname preceeded by an article.
  3620      (dont expect me to write national variants for this ... :-)
  3621      (don't expect me to write national variants for this ... :-)
  3621      If you have special preferences, redefine it..."
  3622      If you have special preferences, redefine it..."
  3622 
  3623 
  3623     |classname|
  3624     |classname|
  3624 
  3625 
  3625     classname := self name.
  3626     classname := self name.
  4781     "return true, if the receiver implements aSelector.
  4782     "return true, if the receiver implements aSelector.
  4782      (i.e. implemented in THIS class - NOT in a superclass).
  4783      (i.e. implemented in THIS class - NOT in a superclass).
  4783      This is semantically equivalent to includesSelector: (which is ST/80/Squeak compatibility).
  4784      This is semantically equivalent to includesSelector: (which is ST/80/Squeak compatibility).
  4784 
  4785 
  4785      Caveat:
  4786      Caveat:
  4786 	This simply checks for the selector being present in the classes
  4787         This simply checks for the selector being present in the classes
  4787 	selector table - therefore, it does not care for ignoredMethods.
  4788         selector table - therefore, it does not care for ignoredMethods.
  4788 	(but: you should not use this method for protocol-testing, anyway).
  4789         (but: you should not use this method for protocol-testing, anyway).
  4789 
  4790 
  4790      Hint:
  4791      Hint:
  4791 	Dont use this method to check if someone responds to a message -
  4792         Don't use this method to check if someone responds to a message -
  4792 	use #canUnderstand: on the class or #respondsTo: on the instance
  4793         use #canUnderstand: on the class or #respondsTo: on the instance
  4793 	to do this."
  4794         to do this."
  4794 
  4795 
  4795     ^ self includesSelector:aSelector
  4796     ^ self includesSelector:aSelector
  4796 
  4797 
  4797     "
  4798     "
  4798      notice: this is class protocol
  4799      notice: this is class protocol