The Trunk: Compiler-nice.111.mcz

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

The Trunk: Compiler-nice.111.mcz

commits-2
Nicolas Cellier uploaded a new version of Compiler to project The Trunk:
http://source.squeak.org/trunk/Compiler-nice.111.mcz

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

Name: Compiler-nice.111
Author: nice
Time: 27 December 2009, 5:01:29 am
UUID: 46325f49-4b22-499c-aa2d-9cc5f16ebd65
Ancestors: Compiler-nice.110

Cosmetic: move or remove a few temps inside closures

=============== Diff against Compiler-nice.110 ===============

Item was changed:
  ----- Method: MessageNode>>sizeForValue: (in category 'code generation') -----
  sizeForValue: encoder
+ | total |
- | total argSize |
  special > 0
  ifTrue: [^self perform: (MacroSizers at: special) with: encoder with: true].
  receiver == NodeSuper
  ifTrue: [selector := selector copy "only necess for splOops"].
  total := selector size: encoder args: arguments size super: receiver == NodeSuper.
  receiver == nil
  ifFalse: [total := total + (receiver sizeForValue: encoder)].
  sizes := arguments collect:
+ [:arg | | argSize |
- [:arg |
  argSize := arg sizeForValue: encoder.
  total := total + argSize.
  argSize].
  ^total!

Item was changed:
  ----- Method: MessageNode>>sizeCodeForValue: (in category 'code generation (new scheme)') -----
  sizeCodeForValue: encoder
+ | total |
- | total argSize |
  special > 0
  ifTrue: [^self perform: (NewStyleMacroSizers at: special) with: encoder with: true].
  receiver == NodeSuper
  ifTrue: [selector := selector copy "only necess for splOops"].
  total := selector sizeCode: encoder args: arguments size super: receiver == NodeSuper.
  receiver == nil
  ifFalse: [total := total + (receiver sizeCodeForValue: encoder)].
  sizes := arguments collect:
+ [:arg | | argSize |
- [:arg |
  argSize := arg sizeCodeForValue: encoder.
  total := total + argSize.
  argSize].
  ^total!

Item was changed:
  ----- Method: MessageNode>>sizeCodeForCase:value: (in category 'code generation (new scheme)') -----
  sizeCodeForCase: encoder value: forValue
 
+ | braceNode sizeIndex elseSize allReturn |
- | braceNode sizeIndex thenSize elseSize allReturn |
  forValue not ifTrue:
  [^super sizeCodeForEffect: encoder].
  equalNode := encoder encodeSelector: #=.
  braceNode := arguments first.
  sizes := Array new: 2 * braceNode numElements.
  sizeIndex := sizes size.
  elseSize := arguments size = 2
  ifTrue:
  [arguments last sizeCodeForEvaluatedValue: encoder] "otherwise: [...]"
  ifFalse:
  [caseErrorNode := encoder encodeSelector: #caseError.
  (NodeSelf sizeCodeForValue: encoder)
  + (caseErrorNode sizeCode: encoder args: 0 super: false)]. "self caseError"
  "There must be at least one branch around the otherwise/caseError
   so the decompiler can identify the end of the otherwise/caseError."
  allReturn := true. "assume every case ends with a return"
  braceNode casesForwardDo:
  [:keyNode :valueNode :last |
  valueNode returns ifFalse: [allReturn := false]].
  braceNode casesReverseDo:
+ [:keyNode :valueNode :last | | thenSize |
- [:keyNode :valueNode :last |
  sizes at: sizeIndex put: elseSize.
  thenSize := valueNode sizeCodeForEvaluatedValue: encoder.
  last ifFalse: [thenSize := thenSize + encoder sizePop].
  valueNode returns ifFalse: [thenSize := thenSize + (self sizeCode: encoder forJump: elseSize)].
  (last and: [allReturn]) ifTrue: [thenSize := thenSize + (self sizeCode: encoder forJump: elseSize)].
  sizes at: sizeIndex-1 put: thenSize.
  last ifFalse: [elseSize := elseSize + encoder sizeDup].
  elseSize := elseSize
  + (keyNode sizeCodeForEvaluatedValue: encoder)
  + (equalNode sizeCode: encoder args: 1 super: false)
  + (self sizeCode: encoder forBranchOn: false dist: thenSize)
  + thenSize.
  sizeIndex := sizeIndex - 2].
  ^(receiver sizeCodeForValue: encoder) + elseSize!

Item was changed:
  ----- Method: MessageNode>>sizeCase:value: (in category 'code generation') -----
  sizeCase: encoder value: forValue
 
+ | braceNode sizeIndex elseSize |
- | braceNode sizeIndex thenSize elseSize |
  forValue not
  ifTrue: [^super sizeForEffect: encoder].
  equalNode := encoder encodeSelector: #=.
  braceNode := arguments first.
  sizes := Array new: 2 * braceNode numElements.
  sizeIndex := sizes size.
  elseSize := arguments size = 2
  ifTrue:
  [arguments last sizeForEvaluatedValue: encoder] "otherwise: [...]"
  ifFalse:
  [caseErrorNode := encoder encodeSelector: #caseError.
  1 + (caseErrorNode size: encoder args: 0 super: false)]. "self caseError"
  braceNode casesReverseDo:
+ [:keyNode :valueNode :last | | thenSize |
- [:keyNode :valueNode :last |
  sizes at: sizeIndex put: elseSize.
  thenSize := valueNode sizeForEvaluatedValue: encoder.
  last ifFalse: [thenSize := thenSize + 1]. "Pop"
  valueNode returns ifFalse: [thenSize := thenSize + (self sizeJump: elseSize)].
  sizes at: sizeIndex-1 put: thenSize.
  last ifFalse: [elseSize := elseSize + 1]. "Dup"
  elseSize := elseSize + (keyNode sizeForEvaluatedValue: encoder) +
  (equalNode size: encoder args: 1 super: false) +
  (self sizeBranchOn: false dist: thenSize) + thenSize.
  sizeIndex := sizeIndex - 2].
  ^(receiver sizeForValue: encoder) + elseSize
  !

Item was changed:
  ----- Method: MethodHighlightingTests>>asXML (in category 'tests') -----
  asXML
  "self new asXML"
  "Convert the master index into external XML representation"
+
+ ^String streamContents:[:s| | writer |
- | writer |
- ^String streamContents:[:s|
  writer := XMLWriter on: s.
  writer xmlDeclaration: '1.0'.
  writer startTag: 'recording'; endTag.
  writer tag: 'creator' pcData: creator.
  writer tag: 'timestamp' pcData: timeStamp.
  writer tag: 'duration' pcData: duration.
  writer startTag: 'tracks'; endTag.
  tracks do:[:tdata|
  writer startTag: 'track'; attribute: 'type' value: tdata value; endTag.
  writer pcData: tdata key.
  writer endTag: 'track'.
  ].
  writer endTag: 'tracks'.
  writer endTag: 'recording'.
  ].
  !

Item was changed:
  ----- Method: Parser>>externalFunctionDeclaration (in category 'primitives') -----
  externalFunctionDeclaration
  "Parse the function declaration for a call to an external library."
+ | descriptorClass callType retType externalName args argType module |
- | descriptorClass callType retType externalName args argType module fn |
  descriptorClass := Smalltalk at: #ExternalFunction ifAbsent:[nil].
  descriptorClass == nil ifTrue:[^false].
  callType := descriptorClass callingConventionFor: here.
  callType == nil ifTrue:[^false].
  "Parse return type"
  self advance.
  retType := self externalType: descriptorClass.
  retType == nil ifTrue:[^self expected:'return type'].
  "Parse function name or index"
  externalName := here.
  (self match: #string)
  ifTrue:[externalName := externalName asSymbol]
  ifFalse:[(self match:#number) ifFalse:[^self expected:'function name or index']].
  (self matchToken: #'(') ifFalse:[^self expected:'argument list'].
  args := WriteStream on: Array new.
  [here == #')'] whileFalse:[
  argType := self externalType: descriptorClass.
  argType == nil ifTrue:[^self expected:'argument'].
  argType isVoid & argType isPointerType not ifFalse:[args nextPut: argType].
  ].
  (self matchToken:#')') ifFalse:[^self expected:')'].
  (self matchToken: 'module:') ifTrue:[
  module := here.
  (self match: #string) ifFalse:[^self expected: 'String'].
  module := module asSymbol].
+ Smalltalk at: #ExternalLibraryFunction ifPresent:[:xfn| | fn |
- Smalltalk at: #ExternalLibraryFunction ifPresent:[:xfn|
  fn := xfn name: externalName
  module: module
  callType: callType
  returnType: retType
  argumentTypes: args contents.
  self allocateLiteral: fn.
  ].
  self addPragma: (Pragma keyword: #primitive: arguments: #(120)).
  ^true!

Item was changed:
  ----- Method: Parser>>removeUnusedTemps (in category 'error correction') -----
  removeUnusedTemps
  "Scan for unused temp names, and prompt the user about the prospect of removing each one found"
 
+ | str madeChanges |
- | str end start madeChanges |
  madeChanges := false.
  str := requestor text asString.
  ((tempsMark between: 1 and: str size)
  and: [(str at: tempsMark) = $|]) ifFalse: [^ self].
  encoder unusedTempNames do:
+ [:temp | | start end |
- [:temp |
  (UnusedVariable name: temp) ifTrue:
  [(encoder encodeVariable: temp) isUndefTemp
  ifTrue:
  [end := tempsMark.
  ["Beginning at right temp marker..."
  start := end - temp size + 1.
  end < temp size or: [temp = (str copyFrom: start to: end)
  and: [(str at: start-1) isSeparator & (str at: end+1) isSeparator]]]
  whileFalse:
  ["Search left for the unused temp"
  end := requestor nextTokenFrom: end direction: -1].
  end < temp size ifFalse:
  [(str at: start-1) = $  ifTrue: [start := start-1].
  requestor correctFrom: start to: end with: ''.
  str := str copyReplaceFrom: start to: end with: ''.
  madeChanges := true.
  tempsMark := tempsMark - (end-start+1)]]
  ifFalse:
  [self inform:
  'You''ll first have to remove the\statement where it''s stored into' withCRs]]].
  madeChanges ifTrue: [ReparseAfterSourceEditing signal]!

Item was changed:
  ----- Method: MessageNode>>emitCase:on:value: (in category 'code generation') -----
  emitCase: stack on: strm value: forValue
 
+ | braceNode sizeStream |
- | braceNode sizeStream thenSize elseSize |
  forValue not
  ifTrue: [^super emitForEffect: stack on: strm].
  braceNode := arguments first.
  sizeStream := ReadStream on: sizes.
  receiver emitForValue: stack on: strm.
  braceNode casesForwardDo:
+ [:keyNode :valueNode :last | | thenSize elseSize |
- [:keyNode :valueNode :last |
  thenSize := sizeStream next.
  elseSize := sizeStream next.
  last ifFalse: [strm nextPut: Dup. stack push: 1].
  keyNode emitForEvaluatedValue: stack on: strm.
  equalNode emit: stack args: 1 on: strm.
  self emitBranchOn: false dist: thenSize pop: stack on: strm.
  last ifFalse: [strm nextPut: Pop. stack pop: 1].
  valueNode emitForEvaluatedValue: stack on: strm.
  last ifTrue: [stack pop: 1].
  valueNode returns ifFalse: [self emitJump: elseSize on: strm]].
  arguments size = 2
  ifTrue:
  [arguments last emitForEvaluatedValue: stack on: strm] "otherwise: [...]"
  ifFalse:
  [NodeSelf emitForValue: stack on: strm.
  caseErrorNode emit: stack args: 0 on: strm]!