Bug fix

Luciano Notarfrancesco luciano at core-sdi.com
Mon Feb 15 13:36:22 UTC 1999


This change set fixes two problems in the CCodeGenerator:

o. now the translator does not fail any more in the division by a
constant float;
o. and #to:by:do: will be translated correctly, at least for constant
steps.

Luciano.-
'From Squeak 2.3 of January 14, 1999 on 15 February 1999 at 8:20:52 am'!
"Change Set:		CCGFixes
Date:			15 February 1999
Author:			Luciano Notarfrancesco

This change set fixes two problems in the CCodeGenerator:

o. now the translator does not fail any more in the division by a constant float;
o. and #to:by:do: will be translated correctly, at least for constant steps (i.e., when in the parse tree the step is a LiteralNode with a constant number)."!


!CCodeGenerator methodsFor: 'C translation' stamp: 'len 2/13/1999 06:33'!
generateDivide: msgNode on: aStream indent: level
	"Generate the C code for this message onto the given stream."

	| rcvr arg divisor |
	rcvr _ msgNode receiver.
	arg _ msgNode args first.
	(arg isConstant and:
	 [UseRightShiftForDivide and:
	 [(divisor _ arg value) isInteger and:
	 [divisor isPowerOfTwo and:
	 [divisor > 0 and:
	 [divisor <= (1 bitShift: 31)]]]]])
	ifTrue: [
		"use signed (arithmetic) right shift instead of divide"
		aStream nextPutAll: '((int) '.
		self emitCExpression: rcvr on: aStream.
		aStream nextPutAll: ' >> ', (divisor log: 2) asInteger printString.
		aStream nextPutAll: ')'.
	] ifFalse: [
		self emitCExpression: rcvr on: aStream.
		aStream nextPutAll: ' / '.
		self emitCExpression: arg on: aStream].
! !

!CCodeGenerator methodsFor: 'C translation' stamp: 'len 2/13/1999 07:36'!
generateToByDo: msgNode on: aStream indent: level
	"Generate the C code for this message onto the given stream."

	| iterationVar step |
	(msgNode args last args size = 1) ifFalse: [
		self error: 'wrong number of block arguments'.
	].
	iterationVar _ msgNode args last args first.
	aStream nextPutAll: 'for (', iterationVar, ' = '.
	self emitCExpression: msgNode receiver on: aStream.
	aStream nextPutAll: '; ', iterationVar,
		(((step _ msgNode args at: 2) isConstant and: [step value > 0])
			ifTrue: [' <= '] ifFalse: [' >= ']).
	self emitCExpression: msgNode args first on: aStream.
	aStream nextPutAll: '; ', iterationVar, ' += '.
	self emitCExpression: step on: aStream.
	aStream nextPutAll: ') {'; cr.
	msgNode args last emitCCodeOn: aStream level: level + 1 generator: self.
	level timesRepeat: [ aStream tab ].
	aStream nextPutAll: '}'.! !





More information about the Squeak-dev mailing list