Nicolas Cellier uploaded a new version of Compiler to project The Trunk:
http://source.squeak.org/trunk/Compiler-nice.224.mcz ==================== Summary ==================== Name: Compiler-nice.224 Author: nice Time: 20 February 2012, 10:56:20.223 pm UUID: 15070f34-9c69-4407-a041-7659522fc95a Ancestors: Compiler-nice.223 Just for fun, fix http://code.google.com/p/pharo/issues/detail?id=4915 The inlined and non inlined versions of to:do: should answer the same result. Implementation notes: This happens to be the receiver of to:do:, and thus the initial value of the loop index. So we can trivially - push the value of init statement on the stack, - remove the final nil that was pushed forValue, - and leave the rest of code generation unchanged =============== Diff against Compiler-nice.223 =============== Item was changed: ----- Method: MessageNode>>emitCodeForToDo:encoder:value: (in category 'code generation') ----- emitCodeForToDo: stack encoder: encoder value: forValue " var := rcvr. L1: [var <= arg1] Bfp(L2) [block body. var := var + inc] Jmp(L1) L2: " | loopSize initStmt limitInit test block incStmt blockSize | initStmt := arguments at: 4. limitInit := arguments at: 7. test := arguments at: 5. block := arguments at: 3. incStmt := arguments at: 6. blockSize := sizes at: 1. loopSize := sizes at: 2. limitInit == nil ifFalse: [limitInit emitCodeForEffect: stack encoder: encoder]. + + "This will return the receiver of to:do: which is the initial value of the loop" + forValue + ifTrue: [initStmt emitCodeForValue: stack encoder: encoder.] + ifFalse: [initStmt emitCodeForEffect: stack encoder: encoder]. - initStmt emitCodeForEffect: stack encoder: encoder. test emitCodeForValue: stack encoder: encoder. self emitCodeForBranchOn: false dist: blockSize pop: stack encoder: encoder. pc := encoder methodStreamPosition. block emitCodeForEvaluatedEffect: stack encoder: encoder. incStmt emitCodeForEffect: stack encoder: encoder. + self emitCodeForJump: 0 - loopSize encoder: encoder.! - self emitCodeForJump: 0 - loopSize encoder: encoder. - forValue ifTrue: [encoder genPushSpecialLiteral: nil. stack push: 1]! Item was changed: ----- Method: MessageNode>>sizeCodeForToDo:value: (in category 'code generation') ----- sizeCodeForToDo: encoder value: forValue " var := rcvr. L1: [var <= arg1] Bfp(L2) [block body. var := var + inc] Jmp(L1) L2: " | loopSize initStmt test block incStmt blockSize initSize limitInit | block := arguments at: 3. initStmt := arguments at: 4. test := arguments at: 5. incStmt := arguments at: 6. limitInit := arguments at: 7. + initSize := forValue + ifTrue: [initStmt sizeCodeForValue: encoder.] + ifFalse: [initStmt sizeCodeForEffect: encoder]. - initSize := initStmt sizeCodeForEffect: encoder. limitInit == nil ifFalse: [initSize := initSize + (limitInit sizeCodeForEffect: encoder)]. blockSize := (block sizeCodeForEvaluatedEffect: encoder) + (incStmt sizeCodeForEffect: encoder) + (encoder sizeJumpLong: -1). loopSize := (test sizeCodeForValue: encoder) + (self sizeCode: encoder forBranchOn: false dist: blockSize) + blockSize. sizes := Array with: blockSize with: loopSize. ^initSize + + loopSize! - + loopSize - + (forValue ifTrue: [encoder sizePushSpecialLiteral: nil] ifFalse: [0])! |
On Mon, Feb 20, 2012 at 09:56:33PM +0000, [hidden email] wrote:
> Nicolas Cellier uploaded a new version of Compiler to project The Trunk: > http://source.squeak.org/trunk/Compiler-nice.224.mcz > > ==================== Summary ==================== > > Name: Compiler-nice.224 > Author: nice > Time: 20 February 2012, 10:56:20.223 pm > UUID: 15070f34-9c69-4407-a041-7659522fc95a > Ancestors: Compiler-nice.223 > > Just for fun, fix http://code.google.com/p/pharo/issues/detail?id=4915 > The inlined and non inlined versions of to:do: should answer the same result. > It is good to see these ongoing improvements :) Dave > Implementation notes: > This happens to be the receiver of to:do:, and thus the initial value of the loop index. > So we can trivially > - push the value of init statement on the stack, > - remove the final nil that was pushed forValue, > - and leave the rest of code generation unchanged > > =============== Diff against Compiler-nice.223 =============== |
Free forum by Nabble | Edit this page |