[squeak-dev] The Trunk: Traits-nice.288.mcz

commits at source.squeak.org commits at source.squeak.org
Wed Mar 30 19:47:43 UTC 2011


Nicolas Cellier uploaded a new version of Traits to project The Trunk:
http://source.squeak.org/trunk/Traits-nice.288.mcz

==================== Summary ====================

Name: Traits-nice.288
Author: nice
Time: 30 March 2011, 9:47:27.896 pm
UUID: 2c2016d2-acf3-448a-b3b9-836089b17a9e
Ancestors: Traits-nice.287

Use #newCompiler #newParser

=============== Diff against Traits-nice.287 ===============

Item was changed:
  ----- Method: ClassDescription>>replaceSelector:withAlias:in: (in category '*Traits-NanoKernel') -----
  replaceSelector: originalSelector withAlias: aliasSelector in: source
  	"replaces originalSelector with aliasSelector in in given source code"
  	| oldKeywords newKeywords args selectorWithArgs s |
  	oldKeywords := originalSelector keywords.
  	newKeywords := aliasSelector keywords.
  	oldKeywords size = newKeywords size ifFalse:[self error: 'Keyword mismatch'].
+ 	args := (self newParser parseArgsAndTemps: source asString notifying: nil) 
- 	args := (self parserClass new parseArgsAndTemps: source asString notifying: nil) 
  				copyFrom: 1 to: originalSelector numArgs.
  	selectorWithArgs := String streamContents: [:stream |
  		newKeywords keysAndValuesDo: [:index :keyword |
  			stream nextPutAll: keyword.
  			stream space.
  			args size >= index ifTrue: [
  				stream nextPutAll: (args at: index); space]]].
  	s := source asString readStream.
  	oldKeywords do: [ :each | s match: each ].
  	args isEmpty ifFalse: [ s match: args last ].
  	^selectorWithArgs withBlanksTrimmed asText , s upToEnd
  !

Item was changed:
  ----- Method: ClassDescription>>traitAddSelector:withMethod: (in category '*Traits-NanoKernel') -----
  traitAddSelector: selector withMethod: traitMethod
  	"Add a method inherited from a trait. 
  	Recompiles to avoid sharing and implement aliasing."
  	| oldMethod source methodNode newMethod originalSelector |
  	oldMethod := self compiledMethodAt: selector ifAbsent:[nil].
  	oldMethod ifNotNil:[
  		"The following is an important optimization as it prevents exponential
  		growth in recompilation. If T1 is used by T2 and T2 by T3 then (without
  		this optimization) any change in T1 would cause all methods in T2 to be
  		recompiled and each recompilation of a method in T2 would cause T3
  		to be fully recompiled. The test eliminates all such situations."
  		(oldMethod sameTraitCodeAs: traitMethod) ifTrue:[^oldMethod].
  	].
  	originalSelector := traitMethod selector.
  	source := traitMethod methodClass sourceCodeAt: originalSelector.
  	originalSelector == selector ifFalse:[
  		"Replace source selectors for aliases"
  		source := self replaceSelector: originalSelector withAlias: selector in: source.
  	].
+ 	methodNode := self newCompiler
- 	methodNode := self compilerClass new 
  		compile: source in: self classified: nil notifying: nil ifFail:[^nil].
  	newMethod := methodNode generate: self defaultMethodTrailer.
  	newMethod putSource: source fromParseNode: methodNode inFile: 2
  		withPreamble: [:f | f cr; nextPut: $!!; nextChunkPut: 'Trait method'; cr].
  	newMethod originalTraitMethod: traitMethod.
  	^super addSelectorSilently: selector withMethod: newMethod.!




More information about the Squeak-dev mailing list