The Inbox: Compiler-cmm.323.mcz

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

The Inbox: Compiler-cmm.323.mcz

commits-2
A new version of Compiler was added to project The Inbox:
http://source.squeak.org/inbox/Compiler-cmm.323.mcz

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

Name: Compiler-cmm.323
Author: cmm
Time: 1 June 2016, 8:27:43.294651 pm
UUID: 4dce5d55-dae2-416b-bbbc-41b4520dd577
Ancestors: Compiler-eem.322

Kent Beckian style "Rectangular Block" pretty printing.

=============== Diff against Compiler-eem.322 ===============

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
+ space ;
+ 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>>printWithClosureAnalysisArgumentsOn:indent: (in category 'printing') -----
  printWithClosureAnalysisArgumentsOn: aStream indent: level
  arguments size = 0 ifTrue: [^self].
  arguments do:
  [:tempNode |
+ aStream "space;" nextPut: $:.
- aStream space; nextPut: $:.
  tempNode printDefinitionForClosureAnalysisOn: aStream].
+ aStream nextPut: $|"; 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>>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: BlockNode>>printWithClosureAnalysisTemporariesOn:indent: (in category 'printing') -----
+ printWithClosureAnalysisTemporariesOn: aStream indent: level
- printWithClosureAnalysisTemporariesOn: aStream indent: level
-
  (temporaries == nil or: [temporaries size = 0]) ifFalse:
  [aStream nextPut: $|.
+ temporaries
+ do:
+ [: tempNode | tempNode printDefinitionForClosureAnalysisOn: aStream]
+ separatedBy: [aStream space].
+ aStream nextPutAll: '|'.
- temporaries do:
- [:tempNode |
- aStream space.
- tempNode printDefinitionForClosureAnalysisOn: aStream].
- aStream nextPutAll: ' | '.
  "If >0 args and >1 statement, put all statements on separate lines"
  statements size > 1 ifTrue: [aStream crtab: level]]!

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.323.mcz

Levente Uzonyi
If you have a look at the diff here, you'll see why using the pretty
printer is such a bad idea:

> 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: $}!

Levente