[Vm-dev] VM Maker: VMMaker.oscog-eem.182.mcz

commits at source.squeak.org commits at source.squeak.org
Sat Jun 30 01:11:54 UTC 2012


Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-eem.182.mcz

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

Name: VMMaker.oscog-eem.182
Author: eem
Time: 29 June 2012, 6:09:22.966 pm
UUID: 57f7399d-992c-49ef-8f0d-258d1b70027c
Ancestors: VMMaker.oscog-eem.181

Make arrayInitializerCalled:for:type: create literal string initializers,
not arrays of characters.
Convert embedded carriage returns in string literals into \n's.

=============== Diff against VMMaker.oscog-eem.181 ===============

Item was changed:
  ----- Method: CCodeGenerator>>arrayInitializerCalled:for:type: (in category 'utilities') -----
  arrayInitializerCalled: varName for: array type: cType
  	"array is a literal array or a CArray on some array."
  	| sequence lastLine |
  	sequence := array isCollection ifTrue: [array] ifFalse: [array object].
  	lastLine := 0.
  	^String streamContents:
  		[:s|
  		s	nextPutAll: cType;
  			space;
  			nextPutAll: varName;
+ 			nextPutAll: '[] = '.
+ 		sequence isString
+ 			ifTrue: [s nextPutAll: (self cLiteralFor: sequence)]
+ 			ifFalse:
+ 				[s nextPut: ${; crtab: 2.
+ 				sequence
+ 					do: [:element| s nextPutAll: (self cLiteralFor: element)]
+ 					separatedBy:
+ 						[s nextPut: $,.
+ 						 (s position - lastLine) > 76
+ 							ifTrue: [s crtab: 2. lastLine := s position]
+ 							ifFalse: [s space]].
+ 				s crtab; nextPut: $}].
+ 		s cr]!
- 			nextPutAll: '[] = {'; crtab: 2.
- 		sequence
- 			do: [:element| s nextPutAll: (self cLiteralFor: element)]
- 			separatedBy:
- 				[s nextPut: $,.
- 				 (s position - lastLine) > 76
- 					ifTrue: [s crtab: 2. lastLine := s position]
- 					ifFalse: [s space]].
- 		s crtab; nextPut: $}; cr]!

Item was changed:
  ----- Method: CCodeGenerator>>cLiteralFor: (in category 'C code generator') -----
  cLiteralFor: anObject
  	"Return a string representing the C literal value for the given object."
  	anObject isNumber
  		ifTrue:
  			[anObject isInteger ifTrue:
  				[^(anObject < 16r7FFFFFFF)
  					ifTrue: [anObject printString]
  					ifFalse: [anObject printString , ObjectMemory unsignedIntegerSuffix]].
  			anObject isFloat ifTrue:
  				[^anObject printString]]
  		ifFalse:
  			[anObject isString ifTrue:
+ 				[^'"', (anObject copyReplaceAll: (String with: Character cr) with: '\n') , '"'].
- 				[^'"', anObject, '"'].
  			anObject == nil ifTrue: [^ 'null' ].
  			anObject == true ifTrue: [^ '1' ].
  			anObject == false ifTrue: [^ '0' ].
  			anObject isCharacter ifTrue:
  				[^anObject == $'
  					ifTrue: ['''\'''''] "i.e. '\''"
  					ifFalse: [anObject asString printString]]].
  	self error: 'Warning: A Smalltalk literal could not be translated into a C constant: ', anObject printString.
  	^'"XXX UNTRANSLATABLE CONSTANT XXX"'!

Item was changed:
  ----- Method: CCodeGenerator>>cLiteralFor:name: (in category 'C code generator') -----
  cLiteralFor: anObject name: smalltalkName
  	"Return a string representing the C literal value for the given object."
  	anObject isInteger ifTrue:
  		[| hex dec rep |
  		hex := anObject printStringBase: 16.
  		dec := anObject printStringBase: 10.
  		rep := ((smalltalkName endsWith: 'Mask')
  				or: [anObject digitLength > 1
  					and: [(hex asSet size * 3) <= (dec asSet size * 2)
  					and: [(smalltalkName endsWith: 'Size') not]]])
  					ifTrue: [hex first = $- ifTrue: ['-0x', hex allButFirst] ifFalse: ['0x', hex]]
  					ifFalse: [dec].
  		^(anObject < 16r7FFFFFFF)
  			ifTrue: [rep]
  			ifFalse: [rep, ObjectMemory unsignedIntegerSuffix "ikp"]].
  	anObject isFloat ifTrue:
  		[^anObject printString].
  	anObject isString ifTrue:
+ 		[^'"', (anObject copyReplaceAll: (String with: Character cr) with: '\n') , '"'].
- 		[^'"', anObject, '"'].
  	anObject == nil ifTrue: [^ 'null' ].
  	anObject == true ifTrue: [^ '1' ].			"ikp"
  	anObject == false ifTrue: [^ '0' ].			"ikp"
  	anObject isCharacter ifTrue:[^anObject asString printString]. "ar"
  	self error: 'Warning: A Smalltalk literal could not be translated into a C constant: ', anObject printString.
  	^'"XXX UNTRANSLATABLE CONSTANT XXX"'!

Item was changed:
  ----- Method: TAssignmentNode>>emitLiteralArrayDeclarationOn:level:generator: (in category 'C code generation') -----
  emitLiteralArrayDeclarationOn: aStream level: level generator: aCCodeGen
  	| type |
  	type := expression args last value.
  	self assert: type last = $*.
  	aStream
  		crtab: level;
  		nextPutAll: '{ static ';
+ 		nextPutAll: (aCCodeGen arrayInitializerCalled: 'aLiteralArray' for: expression args first value type: type allButLast) withBlanksTrimmed;
- 		nextPutAll: (aCCodeGen arrayInitializerCalled: 'aLiteralArray' for: expression args first value type: type allButLast);
  		nextPut: $;;
  		crtab: level + 1;
  		nextPutAll: variable name;
  		nextPutAll: ' = aLiteralArray;';
  		crtab: level;
  		nextPut: $};
  		cr!



More information about the Vm-dev mailing list