The Inbox: Compiler-cmm.179.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: Compiler-cmm.179.mcz

commits-2
Chris Muller uploaded a new version of Compiler to project The Inbox:
http://source.squeak.org/inbox/Compiler-cmm.179.mcz

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

Name: Compiler-cmm.179
Author: cmm
Time: 7 November 2010, 8:37:59.582 pm
UUID: 083197fc-650d-46da-9d1c-50a51630023c
Ancestors: Compiler-ul.178, Compiler-cmm.174

- Merged improved pretty-print formatting.

=============== Diff against Compiler-ul.178 ===============

Item was added:
+ ----- Method: AssignmentNode>>isComplex (in category 'testing') -----
+ isComplex
+ ^ value isComplex!

Item was changed:
  ----- Method: AssignmentNode>>printOn:indent: (in category 'printing') -----
  printOn: aStream indent: level
  variable printOn: aStream indent: level.
  aStream nextPutAll: ' := '.
+ value printOn: aStream indent: level!
- value printOn: aStream indent: level + 2!

Item was changed:
  ----- Method: BlockNode>>isComplex (in category 'testing') -----
  isComplex
+ ^ statements size > 1 or:
+ [ (statements size = 1 and: [ statements first isComplex ]) or:
+ [ arguments size > 0 or: [ temporaries size > 0 ] ] ]!
-
- ^statements size > 1 or: [statements size = 1 and: [statements first isComplex]]!

Item was changed:
  ----- Method: BlockNode>>printArgumentsOn:indent: (in category 'printing') -----
+ printArgumentsOn: aStream indent: level
- printArgumentsOn: aStream indent: level
  arguments size = 0 ifTrue: [^ self].
+ arguments do:
+ [ : arg |
+ aStream nextPut: $: ;
+ space;
+ nextPutAll: arg key;
+ space ].
+ aStream
+ nextPut: $|;
+ space!
- arguments do:
- [:arg | aStream nextPut: $:;  nextPutAll: arg key;  space].
- aStream nextPut: $|; space.
- "If >0 args and >1 statement, put all statements on separate lines"
- statements size > 1 ifTrue:
- [aStream crtab: level]!

Item was changed:
  ----- Method: BlockNode>>printOn:indent: (in category 'printing') -----
+ printOn: aStream indent: level
+ aStream
+ nextPut:  $[ ;
+ space.
+ self
+ printArgumentsOn:  aStream
+ indent:  level.
+ (self
+ printTemporaries:  temporaries
+ on:  aStream
+ doPrior:  [ ] ) ifTrue:
+ [ "If >0 temps and >1 statement, put all statements on separate lines"
+ statements size >  1
+ ifTrue:  [ aStream crtab:  level ]
+ ifFalse:  [ aStream space] ] .
+ self
+ printStatementsOn:  aStream
+ indent:  level.
+ aStream
+ space ;
+ nextPut:  $]!
- printOn: aStream indent: level
-
- "statements size <= 1 ifFalse: [aStream crtab: level]."
- aStream nextPut: $[.
- self printArgumentsOn: aStream indent: level.
- (self printTemporaries: temporaries on: aStream doPrior: []) ifTrue:
- ["If >0 temps and >1 statement, put all statements on separate lines"
- statements size > 1
- ifTrue: [aStream crtab: level]
- ifFalse: [aStream space]].
- self printStatementsOn: aStream indent: level.
- aStream nextPut: $]!

Item was changed:
  ----- Method: BlockNode>>printWithClosureAnalysisOn:indent: (in category 'printing') -----
  printWithClosureAnalysisOn: aStream indent: level
+ aStream nextPut: $[; space.
- aStream nextPut: $[.
  blockExtent ifNotNil: [aStream print: blockExtent].
  self printWithClosureAnalysisArgumentsOn: aStream indent: level.
  self printWithClosureAnalysisTemporariesOn: aStream indent: level.
  self printWithClosureAnalysisStatementsOn: aStream indent: level.
+ aStream space; nextPut: $]!
- aStream nextPut: $]!

Item was changed:
  ----- Method: BraceNode>>printOn:indent: (in category 'printing') -----
+ printOn: aStream indent: level
- printOn: aStream indent: level
-
  aStream nextPut: ${.
+ 1
+ to: elements size
+ do:
+ [ : i |
+ (elements at: i)
+ printOn: aStream
+ indent: level.
+ i < elements size ifTrue:
+ [ aStream
+ nextPutAll: '. ' ;
+ crtab: level ] ].
- 1 to: elements size do:
- [:i | (elements at: i) printOn: aStream indent: level.
- i < elements size ifTrue: [aStream nextPutAll: '. ']].
  aStream nextPut: $}!

Item was added:
+ ----- Method: CascadeNode>>isComplex (in category 'testing') -----
+ isComplex
+ ^ true!

Item was changed:
  ----- Method: CascadeNode>>printOn:indent:precedence: (in category 'printing') -----
  printOn: aStream indent: level precedence: p
+ p > 0 ifTrue: [ aStream nextPut: $( ].
+ messages first
+ printReceiver: receiver
+ on: aStream
+ indent: level.
+ 1
+ to: messages size
+ do:
+ [ : i |
+ aStream crtab: level + 1.
+ (messages at: i)
+ printOn: aStream
+ indent: level.
+ i < messages size ifTrue: [ aStream nextPutAll: ' ;' ] ].
+ p > 0 ifTrue: [ aStream nextPut: $) ]!
-
- p > 0 ifTrue: [aStream nextPut: $(].
- messages first printReceiver: receiver on: aStream indent: level.
- 1 to: messages size do:
- [:i | (messages at: i) printOn: aStream indent: level.
- i < messages size ifTrue:
- [aStream nextPut: $;.
- messages first precedence >= 2 ifTrue: [aStream crtab: level + 1]]].
- p > 0 ifTrue: [aStream nextPut: $)]!

Item was changed:
  ----- Method: MessageNode>>isComplex (in category 'testing') -----
  isComplex
+ ^ (special
+ between: 1
+ and: 10)
+ or:
+ [ arguments size > 1
+ or:
+ [ receiver isComplex or: [ arguments anySatisfy: [ : each | each isComplex ] ] ] ]!
-
- ^(special between: 1 and: 10) or: [arguments size > 2 or: [receiver isComplex]]!

Item was changed:
  ----- Method: MessageNode>>printIfOn:indent: (in category 'printing') -----
+ printIfOn: aStream indent: level
+ receiver ifNotNil:
+ [ receiver
+ printOn: aStream
+ indent: level
+ precedence: precedence ].
+ (arguments last isJust: NodeNil) ifTrue: [ ^ self
+ printKeywords: #ifTrue:
+ arguments: (Array with: arguments first)
+ on: aStream
+ indent: level ].
+ (arguments last isJust: NodeFalse) ifTrue: [ ^ self
+ printKeywords: #and:
+ arguments: (Array with: arguments first)
+ on: aStream
+ indent: level ].
+ (arguments first isJust: NodeNil) ifTrue: [ ^ self
+ printKeywords: #ifFalse:
+ arguments: (Array with: arguments last)
+ on: aStream
+ indent: level ].
+ (arguments first isJust: NodeTrue) ifTrue: [ ^ self
+ printKeywords: #or:
+ arguments: (Array with: arguments last)
+ on: aStream
+ indent: level ].
+ self
+ printKeywords: #ifTrue:ifFalse:
+ arguments: arguments
+ on: aStream
+ indent: level!
- printIfOn: aStream indent: level
-
- receiver ifNotNil:
- [receiver printOn: aStream indent: level + 1 precedence: precedence].
- (arguments last isJust: NodeNil) ifTrue:
- [^self printKeywords: #ifTrue: arguments: (Array with: arguments first)
- on: aStream indent: level].
- (arguments last isJust: NodeFalse) ifTrue:
- [^self printKeywords: #and: arguments: (Array with: arguments first)
- on: aStream indent: level].
- (arguments first isJust: NodeNil) ifTrue:
- [^self printKeywords: #ifFalse: arguments: (Array with: arguments last)
- on: aStream indent: level].
- (arguments first isJust: NodeTrue) ifTrue:
- [^self printKeywords: #or: arguments: (Array with: arguments last)
- on: aStream indent: level].
- self printKeywords: #ifTrue:ifFalse: arguments: arguments
- on: aStream indent: level!

Item was changed:
  ----- Method: MessageNode>>printKeywords:arguments:on:indent: (in category 'printing') -----
+ printKeywords: key arguments: args on: aStream indent: level
- printKeywords: key arguments: args on: aStream indent: level
  | keywords indent arg kwd doCrTab |
  args size = 0 ifTrue:
+ [ aStream
+ space ;
+ nextPutAll: key.
+ ^ self ].
- [aStream space; nextPutAll: key.
- ^self].
  keywords := key keywords.
+ doCrTab := args size > 1.
+ 1
+ to: (args size min: keywords size)
+ do:
+ [ : i | arg := args at: i.
+ kwd := keywords at: i.
+ doCrTab
+ ifTrue:
+ [ aStream crtab: level + 1.
+ indent := 1
+ "newline after big args" ]
+ ifFalse:
+ [ aStream space.
+ indent := 0 ].
+ aStream nextPutAll: kwd.
+ arg isComplex
+ ifTrue: [ aStream crtab: level + indent + 1 ]
+ ifFalse: [ aStream space ].
+ arg
+ printOn: aStream
+ indent: level + 1 + indent
+ precedence:
+ (precedence = 2
+ ifTrue: [ 1 ]
+ ifFalse: [ precedence ]) ]!
- doCrTab := args size > 2
- or: [{receiver} , args anySatisfy:
- [:thisArg |
- thisArg notNil
- and: [thisArg isBlockNode
- or: [thisArg isMessageNode and: [thisArg precedence >= 3]]]]].
- 1 to: (args size min: keywords size) do:
- [:i |
- arg := args at: i.
- kwd := keywords at: i.
- doCrTab
- ifTrue: [aStream crtab: level+1. indent := 1] "newline after big args"
- ifFalse: [aStream space. indent := 0].
- aStream nextPutAll: kwd; space.
- arg printOn: aStream
- indent: level + 1 + indent
- precedence: (precedence = 2 ifTrue: [1] ifFalse: [precedence])]!

Item was changed:
  ----- Method: ParseNode>>printSingleComment:on:indent: (in category 'private') -----
  printSingleComment: aString on: aStream indent: indent
+ "Print the comment string, assuming it has been indented indent tabs.  Break the string at word breaks, given the widths in the default font, at 450 points."
+ aStream nextPutAll: aString!
- "Print the comment string, assuming it has been indented indent tabs.
- Break the string at word breaks, given the widths in the default
- font, at 450 points."
-
- | readStream word position lineBreak font wordWidth tabWidth spaceWidth lastChar |
- readStream := ReadStream on: aString.
- font := TextStyle default defaultFont.
- tabWidth := TextConstants at: #DefaultTab.
- spaceWidth := font widthOf: Character space.
- position := indent * tabWidth.
- lineBreak := 450.
- [readStream atEnd]
- whileFalse:
- [word := self nextWordFrom: readStream setCharacter: [:lc | lastChar := lc].
- wordWidth := word inject: 0 into: [:width :char | width + (font widthOf: char)].
- position := position + wordWidth.
- position > lineBreak
- ifTrue:
- [aStream skip: -1; crtab: indent.
- position := indent * tabWidth + wordWidth + spaceWidth.
- lastChar = Character cr
- ifTrue: [[readStream peekFor: Character tab] whileTrue].
- word isEmpty ifFalse: [aStream nextPutAll: word; space]]
- ifFalse:
- [aStream nextPutAll: word.
- readStream atEnd
- ifFalse:
- [position := position + spaceWidth.
- aStream space].
- lastChar = Character cr
- ifTrue:
- [aStream skip: -1; crtab: indent.
- position := indent * tabWidth.
- [readStream peekFor: Character tab] whileTrue]]]!


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Compiler-cmm.179.mcz

marcel.taeumel
Hi Chris,

I would call this rather "different" than "improved". I think that we would benefit from a configurable pretty printer. There are a bunch of acceptable Smalltalk code styles out there. There is no such thing as the one best formatting.

For example, I do prefer this style

somePredicate
   ifTrue: [
      something.
      something]
   ifFalse: [
      something.
      something].

... over this style:

somePredicate
   ifTrue:
      [ something.
      something ]
   ifFalse:
      [ something.
      something ].

Or something like that. Too much spaces. Complicated position of parentheses. I can come up a number of reasons. Hence, I think that there are many Smalltalkers out there, that also have their own style.

Sometimes this seems even more readable:

somePredicate
   ifTrue: [something. something]
   ifFalse: [something. something].

Sure, we have some official books that suggest some code formatting. Personally, I would prefer a configure system where I can read and write the code in the way I feel most productive. :-)

Just my two cents.

Best,
Marcel
Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Compiler-cmm.179.mcz

Chris Muller-3
Agree.  :)

On Wed, Jun 1, 2016 at 10:21 AM, marcel.taeumel <[hidden email]> wrote:

> Hi Chris,
>
> I would call this rather "different" than "improved". I think that we would
> benefit from a configurable pretty printer. There are a bunch of acceptable
> Smalltalk code styles out there. There is no such thing as the one best
> formatting.
>
> For example, I do prefer this style
>
> somePredicate
>    ifTrue: [
>       something.
>       something]
>    ifFalse: [
>       something.
>       something].
>
> ... over this style:
>
> somePredicate
>    ifTrue:
>       [ something.
>       something ]
>    ifFalse:
>       [ something.
>       something ].
>
> Or something like that. Too much spaces. Complicated position of
> parentheses. I can come up a number of reasons. Hence, I think that there
> are many Smalltalkers out there, that also have their own style.
>
> Sometimes this seems even more readable:
>
> somePredicate
>    ifTrue: [something. something]
>    ifFalse: [something. something].
>
> Sure, we have some official books that suggest some code formatting.
> Personally, I would prefer a configure system where I can read and write the
> code in the way I feel most productive. :-)
>
> Just my two cents.
>
> Best,
> Marcel
>
>
>
> --
> View this message in context: http://forum.world.st/The-Inbox-Compiler-cmm-179-mcz-tp4898674p4898688.html
> Sent from the Squeak - Dev mailing list archive at Nabble.com.
>