The Inbox: Compiler-ct.452.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-ct.452.mcz

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

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

Name: Compiler-ct.452
Author: ct
Time: 13 November 2020, 7:07:30.464415 pm
UUID: a40e8327-95c2-f448-8edd-0aa087a5c930
Ancestors: Compiler-eem.451

Reworks public Compiler interface and documentation:

- Parser: Do not use #fail in the event of an internal error unless compilation is interactive. This was a single precedent case.
- Correct description of compilation error handling: failBlock is *not* evaluated any longer if the requestor is nil since I eliminated the above precedent (I validated that twice). Mention SyntaxErrorNotification explicitly instead of referring to the ToolSet-specific SyntaxError tool.
- Provide new convenience selectors #compileNoPattern: and #compileNoPattern:in: on Compiler instance side.
- Unify method comment format and phrases.
- Ban ST80-specific term "controller" from the argument names.

=============== Diff against Compiler-eem.451 ===============

Item was changed:
  ----- Method: Compiler class>>evaluate: (in category 'evaluating') -----
  evaluate: textOrString
+ "See Compiler|evaluate:for:notifying:logged:. If a compilation error occurs, a SyntaxErrorNotification is signaled rather than notifying any requestor.
+ Compilation is carried out with respect to nil, i.e., no object, and the invocation is not logged."
- "See Compiler|evaluate:for:notifying:logged:. If a compilation error occurs,
- a Syntax Error view is created rather than notifying any requestor.
- Compilation is carried out with respect to nil, i.e., no object, and the
- invocation is not logged."
 
  ^self evaluate: textOrString for: nil!

Item was changed:
  ----- Method: Compiler class>>evaluate:for: (in category 'evaluating') -----
  evaluate: textOrString for: anObject  
+ "See Compiler|evaluate:for:notifying:. If a compilation error occurs, a SyntaxErrorNotification is signaled rather than notifying any requestor."
- "See Compiler|evaluate:for:notifying:. If a compilation error occurs,
- a Syntax Error view is created rather than notifying any requestor."
 
  ^self evaluate: textOrString for: anObject notifying: nil!

Item was changed:
  ----- Method: Compiler class>>evaluate:for:logged: (in category 'evaluating logged') -----
  evaluate: textOrString for: anObject logged: logFlag
+ "See Compiler|evaluate:for:notifying:logged:. If a compilation error occurs, a SyntaxErrorNotification is signaled rather than notifying any requestor."
- "See Compiler|evaluate:for:notifying:logged:. If a compilation error occurs,
- a Syntax Error view is created rather than notifying any requestor."
 
  ^self evaluate: textOrString for: anObject notifying: nil logged: logFlag!

Item was changed:
  ----- Method: Compiler class>>evaluate:for:notifying: (in category 'evaluating') -----
+ evaluate: textOrString for: anObject notifying: requestor
+ "Compile and execute the argument, textOrString with respect to the class of anObject. If a compilation error occurs, use requestor for interactive error correction."
- evaluate: textOrString for: anObject notifying: aController
- "Compile and execute the argument, textOrString with respect to the class
- of anObject. If a compilation error occurs, notify aController."
 
  ^ self new
  evaluate: textOrString
  in: nil
  to: anObject
+ notifying: requestor
- notifying: aController
  ifFail: [^nil]!

Item was changed:
  ----- Method: Compiler class>>evaluate:for:notifying:logged: (in category 'evaluating logged') -----
+ evaluate: textOrString for: anObject notifying: requestor logged: logFlag
+ "Compile and execute the argument, textOrString with respect to the class of anObject.
+ If a compilation error occurs, use requestor for interactive error correction.
+ If both compilation and execution are successful then, if logFlag is true, log (write) the text onto a system changes file so that it can be replayed if necessary."
- evaluate: textOrString for: anObject notifying: aController logged: logFlag
- "Compile and execute the argument, textOrString with respect to the class
- of anObject. If a compilation error occurs, notify aController. If both
- compilation and execution are successful then, if logFlag is true, log
- (write) the text onto a system changes file so that it can be replayed if
- necessary."
 
  ^ self new
  evaluate: textOrString
  in: nil
  to: anObject
+ notifying: requestor
- notifying: aController
  ifFail: [^nil]
  logged: logFlag.!

Item was changed:
  ----- Method: Compiler class>>evaluate:in:notifying:logged: (in category 'evaluating logged') -----
+ evaluate: textOrString in: anEnvironment notifying: requestor logged: logFlag
- evaluate: textOrString in: anEnvironment notifying: aController logged: logFlag
  "Compile and execute the argument, textOrString in anEnvironment.
+ If a compilation error occurs, use requestor for interactive error correction.
+ If both compilation and execution are successful then, if logFlag is true, log (write) the text onto a system changes file so that it can be replayed if necessary."
- If a compilation error occurs, notify aController. If both
- compilation and execution are successful then, if logFlag is true, log
- (write) the text onto a system changes file so that it can be replayed if
- necessary."
 
  ^ self new
  evaluate: textOrString
  in: anEnvironment
+ notifying: requestor
- notifying: aController
  logged: logFlag.!

Item was changed:
  ----- Method: Compiler class>>evaluate:logged: (in category 'evaluating logged') -----
  evaluate: textOrString logged: logFlag
+ "See Compiler|evaluate:for:notifying:logged:. If a compilation error occurs, a SyntaxErrorNotification is raised rather than notifying any requestor.
- "See Compiler|evaluate:for:notifying:logged:. If a compilation error occurs,
- a Syntax Error view is created rather than notifying any requestor.
  Compilation is carried out with respect to nil, i.e., no object."
 
  ^self evaluate: textOrString for: nil logged: logFlag!

Item was changed:
  ----- Method: Compiler class>>evaluate:notifying: (in category 'evaluating') -----
+ evaluate: textOrString notifying: requestor
+ "See Compiler|evaluate:for:notifying:logged:. Compilation is carried out with respect to nil, i.e., no object."
- evaluate: textOrString notifying: aController
- "See Compiler|evaluate:for:notifying:logged:. Compilation is carried out
- with respect to nil, i.e., no object."
 
+ ^self evaluate: textOrString for: nil notifying: requestor!
- ^self evaluate: textOrString for: nil notifying: aController!

Item was changed:
  ----- Method: Compiler class>>evaluate:notifying:logged: (in category 'evaluating logged') -----
+ evaluate: textOrString notifying: requestor logged: logFlag
+ "See Compiler|evaluate:for:notifying:logged:. Compilation is carried out with respect to nil, i.e., no object."
- evaluate: textOrString notifying: aController logged: logFlag
- "See Compiler|evaluate:for:notifying:logged:. Compilation is carried out
- with respect to nil, i.e., no object."
 
+ ^self evaluate: textOrString for: nil notifying: requestor logged: logFlag!
- ^self evaluate: textOrString for: nil notifying: aController logged: logFlag!

Item was changed:
  ----- Method: Compiler class>>format:in:notifying: (in category 'evaluating') -----
+ format: textOrStream in: aClass notifying: requestor
+ ^self new format: textOrStream in: aClass notifying: requestor!
- format: textOrStream in: aClass notifying: aRequestor
- ^self new format: textOrStream in: aClass notifying: aRequestor!

Item was changed:
  ----- Method: Compiler class>>format:in:notifying:decorated: (in category 'evaluating') -----
+ format: textOrStream in: aClass notifying: requestor decorated: aBoolean
+ ^self new format: textOrStream in: aClass notifying: requestor decorated: aBoolean!
- format: textOrStream in: aClass notifying: aRequestor decorated: aBoolean
- ^self new format: textOrStream in: aClass notifying: aRequestor decorated: aBoolean!

Item was changed:
  ----- Method: Compiler>>compile:ifFail: (in category 'public access') -----
  compile: aCue ifFail: failBlock
+ "Answer a MethodNode.
+ If the cue requestor is not nil, use it for interactive error correction, and evaluate failBlock after the compilation has been aborted.
+ The MethodNode is the root of a parse tree. It can be told to generate a CompiledMethod to be installed in the method dictionary of the class specified by the context."
- "Answer a MethodNode. If the MethodNode can not be created, notify
- the requestor in the contxt. If the requestor is nil, evaluate failBlock
- instead. The MethodNode is the root  of a parse tree. It can be told
- to generate a CompiledMethod to be installed in the method dictionary
- of the class specified by the context."
 
  ^self
  compileCue: aCue
  noPattern: false
+ ifFail: failBlock!
- ifFail: failBlock !

Item was changed:
  ----- Method: Compiler>>compile:in:environment:notifying:ifFail: (in category 'public access') -----
+ compile: textOrStream in: aClass environment: anEnvironment notifying: requestor ifFail: failBlock
+ "Answer a MethodNode for the argument, textOrStream.
+ If requestor is not nil, use it for interactive error correction, and evaluate failBlock after the compilation has been aborted.
+ The MethodNode is the root of a parse tree. It can be told to generate a CompiledMethod to be installed in the method dictionary of the argument, aClass."
- compile: textOrStream in: aClass environment: anEnvironment notifying: aRequestor ifFail: failBlock
- "Answer a MethodNode for the argument, textOrStream. If the
- MethodNode can not be created, notify the argument, aRequestor; if
- aRequestor is nil, evaluate failBlock instead. The MethodNode is the root
- of a parse tree. It can be told to generate a CompiledMethod to be
- installed in the method dictionary of the argument, aClass."
 
  ^self
  compileCue: (CompilationCue
  source: textOrStream
  class: aClass
  environment: anEnvironment
+ requestor: requestor)
- requestor: aRequestor)
  noPattern: false
+ ifFail: failBlock!
- ifFail: failBlock
- !

Item was changed:
  ----- Method: Compiler>>compile:in:notifying:ifFail: (in category 'public access') -----
+ compile: textOrStream in: aClass notifying: requestor ifFail: failBlock
+ "Answer a MethodNode for the argument, textOrStream.
+ If requestor is not nil, use it for interactive error correction, and evaluate failBlock after the compilation has been aborted.
+ The MethodNode is the root of a parse tree. It can be told to generate a CompiledMethod to be installed in the method dictionary of the argument, aClass."
- compile: textOrStream in: aClass notifying: aRequestor ifFail: failBlock
- "Answer a MethodNode for the argument, textOrStream. If the
- MethodNode can not be created, notify the argument, aRequestor; if
- aRequestor is nil, evaluate failBlock instead. The MethodNode is the root
- of a parse tree. It can be told to generate a CompiledMethod to be
- installed in the method dictionary of the argument, aClass."
 
  ^self
  compileCue: (CompilationCue
  source: textOrStream
  class: aClass
+ requestor: requestor)
- requestor: aRequestor)
  noPattern: false
+ ifFail: failBlock!
- ifFail: failBlock
- !

Item was changed:
  ----- Method: Compiler>>compileCue:noPattern:ifFail: (in category 'private') -----
  compileCue: aCue noPattern: aBoolean ifFail: failBlock
  "Answer a MethodNode corresponding to cue source.
+ If the cue requestor is not nil, use it for interactive error correction, and evaluate failBlock after the compilation has been aborted.
+ The MethodNode is the root of a parse tree. It can be told to generate a CompiledMethod:
- If the MethodNode can not be created, notify the cue requestor.
- If the cue requestor is nil, evaluate failBlock instead.
- The MethodNode is the root  of a parse tree.
- It can be told to generate a CompiledMethod
  - either to be evaluated in cue context if aBoolean is true, with cue receiver as method receiver,
  - or to be installed in the method dictionary of the target class specified by the cue if aBoolean is false."
+
-
  self setCue: aCue.
  ^self translateNoPattern: aBoolean ifFail: failBlock!

Item was added:
+ ----- Method: Compiler>>compileNoPattern: (in category 'public access') -----
+ compileNoPattern: textOrStream
+
+ ^ self
+ compileNoPattern: textOrStream
+ in: nil class!

Item was added:
+ ----- Method: Compiler>>compileNoPattern:in: (in category 'public access') -----
+ compileNoPattern: textOrStream in: aClass
+
+ ^ self
+ compileNoPattern: textOrStream
+ in: aClass
+ notifying: nil
+ ifFail: [^ nil]!

Item was changed:
  ----- Method: Compiler>>compileNoPattern:in:context:environment:notifying:ifFail: (in category 'public access') -----
+ compileNoPattern: textOrStream in: aClass context: aContext environment: anEnvironment notifying: requestor ifFail: failBlock
- compileNoPattern: textOrStream in: aClass context: aContext environment: anEnvironment notifying: aRequestor ifFail: failBlock
  "Similar to #compile:in:notifying:ifFail:, but the compiled code is
  expected to be a do-it expression, with no message pattern,
  and it will be in an explicit environment."
 
  ^self
  compileCue: (CompilationCue
  source: textOrStream
  context: aContext
  class: aClass
  environment: anEnvironment
+ requestor: requestor)
- requestor: aRequestor)
  noPattern: true
+ ifFail: failBlock!
- ifFail: failBlock
- !

Item was changed:
  ----- Method: Compiler>>compileNoPattern:in:context:notifying:ifFail: (in category 'public access') -----
+ compileNoPattern: textOrStream in: aClass context: aContext notifying: requestor ifFail: failBlock
- compileNoPattern: textOrStream in: aClass context: aContext notifying: aRequestor ifFail: failBlock
  "Similar to #compile:in:notifying:ifFail:, but the compiled code is
  expected to be a do-it expression, with no message pattern."
 
  ^self
  compileCue: (CompilationCue
  source: textOrStream
  context: aContext
  class: aClass
+ requestor: requestor)
- requestor: aRequestor)
  noPattern: true
+ ifFail: failBlock!
- ifFail: failBlock
- !

Item was changed:
  ----- Method: Compiler>>compileNoPattern:in:notifying:ifFail: (in category 'public access') -----
+ compileNoPattern: textOrStream in: aClass notifying: requestor ifFail: failBlock
- compileNoPattern: textOrStream in: aClass notifying: aRequestor ifFail: failBlock
  "Similar to #compile:in:notifying:ifFail:, but the compiled code is
  expected to be a do-it expression, with no message pattern."
 
  ^self
  compileCue: (CompilationCue
  source: textOrStream
  class: aClass
+ requestor: requestor)
- requestor: aRequestor)
  noPattern: true
+ ifFail: failBlock!
- ifFail: failBlock
- !

Item was changed:
  ----- Method: Compiler>>compiledMethodFor:in:to:notifying:ifFail: (in category 'public access') -----
+ compiledMethodFor: textOrStream in: aContext to: receiver notifying: requestor ifFail: failBlock
+ "Compiles the sourceStream into a parse tree, then generates code into a method, and answers it.
+ If receiver is not nil, then the text can refer to instance variables of that receiver (the Inspector uses this).
+ If aContext is not nil, the text can refer to temporaries in that context (the Debugger uses this).
+ If requestor is not nil, use it for interactive error correction, and evaluate failBlock after the compilation has been aborted."
- compiledMethodFor: textOrStream in: aContext to: receiver notifying: aRequestor ifFail: failBlock
- "Compiles the sourceStream into a parse tree, then generates code
- into a method, and answers it.  If receiver is not nil, then the text can
- refer to instance variables of that receiver (the Inspector uses this).
- If aContext is not nil, the text can refer to temporaries in that context
- (the Debugger uses this). If aRequestor is not nil, then it will receive a
- notify:at: message before the attempt to evaluate is aborted."
 
  | methodNode method |
  methodNode := self
  compileNoPattern: textOrStream
  in: (self classForReceiver: receiver context: aContext)
  context: aContext
+ notifying: requestor
- notifying: aRequestor
  ifFail: [^failBlock value].
  method := self interactive
  ifTrue: [ methodNode generateWithTempNames ]
  ifFalse: [ methodNode generate ].
  ^method!

Item was changed:
  ----- Method: Compiler>>compiledMethodFor:in:to:notifying:ifFail:logged: (in category 'public access logging') -----
+ compiledMethodFor: textOrStream in: aContext to: receiver notifying: requestor ifFail: failBlock logged: logFlag
+ "Compiles the sourceStream into a parse tree, then generates code into a method, and answers it.
+ If receiver is not nil, then the text can refer to instance variables of that receiver (the Inspector uses this).
+ If aContext is not nil, the text can refer to temporaries in that context (the Debugger uses this).
+ If requestor is not nil, use it for interactive compilation, and evaluate failBlock after the compilation has been aborted."
- compiledMethodFor: textOrStream in: aContext to: receiver notifying: aRequestor ifFail: failBlock logged: logFlag
- "Compiles the sourceStream into a parse tree, then generates code
- into a method, and answers it.  If receiver is not nil, then the text can
- refer to instance variables of that receiver (the Inspector uses this).
- If aContext is not nil, the text can refer to temporaries in that context
- (the Debugger uses this). If aRequestor is not nil, then it will receive a
- notify:at: message before the attempt to evaluate is aborted."
 
  | method |
  method := self
  compiledMethodFor: textOrStream
  in: aContext
  to: receiver
+ notifying: requestor
- notifying: aRequestor
  ifFail: [^failBlock value].
  logFlag ifTrue:
  [SystemChangeNotifier uniqueInstance evaluated: cue stringToLog context: aContext].
  ^method!

Item was changed:
  ----- Method: Compiler>>evaluate: (in category 'public access') -----
  evaluate: textOrString
+ "See evaluate:for:notifying:logged:. If a compilation error occurs, a SyntaxErrorNotification is signaled rather than notifying any requestor.
+ Compilation is carried out with respect to nil, i.e., no object, and the invocation is not logged."
- "See evaluate:for:notifying:logged:. If a compilation error occurs,
- a Syntax Error view is created rather than notifying any requestor.
- Compilation is carried out with respect to nil, i.e., no object, and the
- invocation is not logged."
 
  ^self evaluate: textOrString for: nil!

Item was changed:
  ----- Method: Compiler>>evaluate:for: (in category 'public access') -----
  evaluate: textOrString for: anObject
+ "See evaluate:for:notifying:logged:. If a compilation error occurs, a SyntaxErrorNotification is signaled rather than notifying any requestor."
- "See evaluate:for:notifying:logged:. If a compilation error occurs,
- a Syntax Error view is created rather than notifying any requestor."
 
  ^self evaluate: textOrString for: anObject notifying: nil!

Item was changed:
  ----- Method: Compiler>>evaluate:for:logged: (in category 'public access logging') -----
  evaluate: textOrString for: anObject logged: logFlag
+ "See evaluate:for:notifying:logged:. If a compilation error occurs, a SyntaxError is signaled rather than notifying any requestor."
- "See evaluate:for:notifying:logged:. If a compilation error occurs,
- a Syntax Error view is created rather than notifying any requestor."
 
  ^self evaluate: textOrString for: anObject notifying: nil logged: logFlag!

Item was changed:
  ----- Method: Compiler>>evaluate:for:notifying: (in category 'public access') -----
+ evaluate: textOrString for: anObject notifying: requestor
+ "Compile and execute the argument, textOrString with respect to the class of anObject. If a compilation error occurs, use requestor for interactive compilation."
- evaluate: textOrString for: anObject notifying: aController
- "Compile and execute the argument, textOrString with respect to the class
- of anObject. If a compilation error occurs, notify aController."
 
  ^ self
  evaluate: textOrString
  in: nil
  to: anObject
+ notifying: requestor
- notifying: aController
  ifFail: [^nil]!

Item was changed:
  ----- Method: Compiler>>evaluate:for:notifying:logged: (in category 'public access logging') -----
+ evaluate: textOrString for: anObject notifying: requestor logged: logFlag
+ "Compile and execute the argument, textOrString with respect to the class of anObject.
+ If a compilation error occurs, use requestor for interactive compilation.
+ If both compilation and execution are successful then, if logFlag is true, log (write) the text onto a system changes file so that it can be replayed if necessary."
- evaluate: textOrString for: anObject notifying: aController logged: logFlag
- "Compile and execute the argument, textOrString with respect to the class
- of anObject. If a compilation error occurs, notify aController. If both
- compilation and execution are successful then, if logFlag is true, log
- (write) the text onto a system changes file so that it can be replayed if
- necessary."
 
  ^ self
  evaluate: textOrString
  in: nil
  to: anObject
+ notifying: requestor
- notifying: aController
  ifFail: [^nil]
  logged: logFlag.!

Item was changed:
  ----- Method: Compiler>>evaluate:in:environment:notifying:ifFail:logged: (in category 'public access logging') -----
+ evaluate: textOrStream in: aContext environment: anEnvironment notifying: requestor ifFail: failBlock logged: logFlag
+ "Compiles the sourceStream into a parse tree, then generates code into a method.
+ If aContext is not nil, the text can refer to temporaries in that context (the Debugger uses this).
+ If requestor is not nil, use it for interactive compilation, and evaluate failBlock after the compilation has been aborted.
+ Finally, the compiled method is invoked from here via withArgs:executeMethod:, hence the system no longer creates Doit method litter on errors."
- evaluate: textOrStream in: aContext environment: anEnvironment notifying: aRequestor ifFail: failBlock logged: logFlag
- "Compiles the sourceStream into a parse tree, then generates code into
- a method. If aContext is not nil, the text can refer to temporaries in that
- context (the Debugger uses this). If aRequestor is not nil, then it will receive
- a notify:at: message before the attempt to evaluate is aborted. Finally, the
- compiled method is invoked from here via withArgs:executeMethod:, hence
- the system no longer creates Doit method litter on errors."
  ^self
  evaluateCue: (CompilationCue
  source: textOrStream
  context: aContext
  receiver: nil
  class: UndefinedObject
  environment: anEnvironment
+ requestor: requestor)
- requestor: aRequestor)
  ifFail: failBlock
  logged: logFlag!

Item was changed:
  ----- Method: Compiler>>evaluate:in:notifying:logged: (in category 'public access logging') -----
+ evaluate: textOrString in: anEnvironment notifying: requestor logged: logFlag
- evaluate: textOrString in: anEnvironment notifying: aController logged: logFlag
  "Compile and execute the argument, textOrString in anEnvironment.
+ If a compilation error occurs, use requestor for interactive compilation.
+ If both compilation and execution are successful then, if logFlag is true, log (write) the text onto a system changes file so that it can be replayed if necessary."
- If a compilation error occurs, notify aController. If both
- compilation and execution are successful then, if logFlag is true, log
- (write) the text onto a system changes file so that it can be replayed if
- necessary."
 
  ^self
  evaluate: textOrString
  in: nil
  environment: anEnvironment
+ notifying: requestor
- notifying: aController
  ifFail: [^nil]
  logged: logFlag!

Item was changed:
  ----- Method: Compiler>>evaluate:in:to:environment:notifying:ifFail:logged: (in category 'public access logging') -----
+ evaluate: textOrStream in: aContext to: receiver environment: anEnvironment notifying: requestor ifFail: failBlock logged: logFlag
- evaluate: textOrStream in: aContext to: receiver environment: anEnvironment notifying: aRequestor ifFail: failBlock logged: logFlag
  "Same as #evaluate:in:to:notifying:ifFail:logged: but with an explicit environment"
  ^self
  evaluateCue: (CompilationCue
  source: textOrStream
  context: aContext
  receiver: receiver
  class: (self classForReceiver: receiver context: aContext)
  environment: anEnvironment
+ requestor: requestor)
- requestor: aRequestor)
  ifFail: failBlock
  logged: logFlag!

Item was changed:
  ----- Method: Compiler>>evaluate:in:to:notifying:ifFail: (in category 'public access') -----
+ evaluate: textOrStream in: aContext to: receiver notifying: requestor ifFail: failBlock
+ "Compiles the sourceStream into a parse tree, then generates code into a method.
+ If aContext is not nil, the text can refer to temporaries in that context (the Debugger uses this).
+ If requestor is not nil, use it for interactive error correction, and evaluate failBlock if the compilation fails.
+ Finally, the compiled method is invoked from here via withArgs:executeMethod:, hence the system no longer creates Doit method litter on errors."
+
- evaluate: textOrStream in: aContext to: receiver notifying: aRequestor ifFail: failBlock
- "Compiles the sourceStream into a parse tree, then generates code into
- a method. If aContext is not nil, the text can refer to temporaries in that
- context (the Debugger uses this). If aRequestor is not nil, then it will receive
- a notify:at: message before the attempt to evaluate is aborted. Finally, the
- compiled method is invoked from here via withArgs:executeMethod:, hence
- the system no longer creates Doit method litter on errors."
-
  | theClass |
  theClass := self classForReceiver: receiver context: aContext.
  ^self
  evaluateCue: (CompilationCue
  source: textOrStream
  context: aContext
  receiver: receiver
  class: theClass
  environment: theClass environment
+ requestor: requestor)
- requestor: aRequestor)
  ifFail: failBlock!

Item was changed:
  ----- Method: Compiler>>evaluate:in:to:notifying:ifFail:logged: (in category 'public access logging') -----
+ evaluate: textOrStream in: aContext to: receiver notifying: requestor ifFail: failBlock logged: logFlag
+ "Compiles the sourceStream into a parse tree, then generates code into a method.
+ If aContext is not nil, the text can refer to temporaries in that context (the Debugger uses this).
+ If requestor is not nil, use it for interactive compilation, and evaluate failBlock if the compilation fails.
+ Finally, the compiled method is invoked from here via withArgs:executeMethod:, hence the system no longer creates Doit method litter on errors."
+
- evaluate: textOrStream in: aContext to: receiver notifying: aRequestor ifFail: failBlock logged: logFlag
- "Compiles the sourceStream into a parse tree, then generates code into
- a method. If aContext is not nil, the text can refer to temporaries in that
- context (the Debugger uses this). If aRequestor is not nil, then it will receive
- a notify:at: message before the attempt to evaluate is aborted. Finally, the
- compiled method is invoked from here via withArgs:executeMethod:, hence
- the system no longer creates Doit method litter on errors."
  | theClass |
  theClass := self classForReceiver: receiver context: aContext.
  ^self
  evaluateCue: (CompilationCue
  source: textOrStream
  context: aContext
  receiver: receiver
  class: theClass
  environment: theClass environment
+ requestor: requestor)
- requestor: aRequestor)
  ifFail: failBlock
  logged: logFlag!

Item was changed:
  ----- Method: Compiler>>evaluate:logged: (in category 'public access logging') -----
  evaluate: textOrString logged: logFlag
+ "See evaluate:for:notifying:logged:. If a compilation error occurs, a SyntaxErrorNotification is signaled rather than notifying any requestor.
- "See evaluate:for:notifying:logged:. If a compilation error occurs,
- a Syntax Error view is created rather than notifying any requestor.
  Compilation is carried out with respect to nil, i.e., no object."
 
  ^self evaluate: textOrString for: nil logged: logFlag!

Item was changed:
  ----- Method: Compiler>>evaluate:notifying: (in category 'public access') -----
+ evaluate: textOrString notifying: requestor
+ "See evaluate:for:notifying:. Compilation is carried out with respect to nil, i.e., no object."
- evaluate: textOrString notifying: aController
- "See evaluate:for:notifying:. Compilation is carried out
- with respect to nil, i.e., no object."
 
+ ^self evaluate: textOrString for: nil notifying: requestor!
- ^self evaluate: textOrString for: nil notifying: aController!

Item was changed:
  ----- Method: Compiler>>evaluate:notifying:logged: (in category 'public access logging') -----
+ evaluate: textOrString notifying: requestor logged: logFlag
+ "See evaluate:for:notifying:logged:. Compilation is carried out with respect to nil, i.e., no object."
- evaluate: textOrString notifying: aController logged: logFlag
- "See evaluate:for:notifying:logged:. Compilation is carried out
- with respect to nil, i.e., no object."
 
+ ^self evaluate: textOrString for: nil notifying: requestor logged: logFlag!
- ^self evaluate: textOrString for: nil notifying: aController logged: logFlag!

Item was changed:
  ----- Method: Compiler>>format:in:notifying: (in category 'public access') -----
+ format: textOrStream in: aClass notifying: requestor
+ "Compile a parse tree from the argument, textOrStream. Answer a string containing the original code, formatted nicely. If aBoolean is true, then decorate the resulting text with color and hypertext actions."
- format: textOrStream in: aClass notifying: aRequestor
- "Compile a parse tree from the argument, textOrStream. Answer a string containing the original code, formatted nicely.  If aBoolean is true, then decorate the resulting text with color and hypertext actions"
 
  | aNode |
  self from: textOrStream
  class: aClass
+ notifying: requestor.
- notifying: aRequestor.
  aNode := self formatNoPattern: false ifFail: [^ nil].
-
- "aSymbol == #colorPrint ifTrue:
- [^aNode asColorizedSmalltalk80Text]." "deprecating #colorPrint in favor of Shout --Ron Spengler"
-
  ^aNode decompileString!

Item was changed:
  ----- Method: Compiler>>format:in:notifying:decorated: (in category 'public access') -----
+ format: textOrStream in: aClass notifying: requestor decorated: aBoolean
+ "Compile a parse tree from the argument, textOrStream. Answer a string containing the original code, formatted nicely. If aBoolean is true, then decorate the resulting text with color and hypertext actions."
+
- format: textOrStream in: aClass notifying: aRequestor decorated: aBoolean
- "Compile a parse tree from the argument, textOrStream. Answer a string containing the original code, formatted nicely.  If aBoolean is true, then decorate the resulting text with color and hypertext actions"
  | aNode |
  self from: textOrStream
  class: aClass
+ notifying: requestor.
- notifying: aRequestor.
  aNode := self formatNoPattern: false ifFail: [^ nil].
  ^ aBoolean
  ifTrue: [aNode decompileText]
  ifFalse: [aNode decompileString]!

Item was changed:
  ----- Method: Compiler>>parse:in:notifying: (in category 'public access') -----
  parse: textOrStream in: aClass notifying: req
+ "Compile the argument, textOrStream, with respect to the class, aClass, and answer the MethodNode that is the root of the resulting parse tree. If an error occurs, use requestor for interactive error handling."
- "Compile the argument, textOrStream, with respect to the class, aClass, and
- answer the MethodNode that is the root of the resulting parse tree.  Notify the
- argument, req, if an error occurs. The failBlock is defaulted to an empty block."
 
  self from: textOrStream class: aClass notifying: req.
  ^self parser
  parseCue: cue
  noPattern: false
  ifFail: []!

Item was changed:
  ----- Method: Parser>>notify:at: (in category 'error handling') -----
  notify: string at: location
  | messageText |
  messageText := '"' , string , ' ->"'.
  cue requestor isNil
  ifTrue: [
  | notification |
  (encoder == self or: [encoder isNil])
+ ifTrue: [^ self interactive
+ ifTrue: [self fail]
+ ifFalse: [self error: 'failure setting up syntax error']].
- ifTrue: [^ self fail "failure setting up syntax error"].
  (notification := SyntaxErrorNotification
  cue: (cue copy
  source: (source contents asText
  copyReplaceFrom: location
  to: location - 1
  with: messageText);
  yourself)
  doitFlag: doitFlag
  errorMessage: string
  location: location) signal.
  notification tryNewSourceIfAvailable]
  ifFalse: [cue requestor
  notify: messageText
  at: location
  in: source].
  ^ self fail!


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Compiler-ct.452.mcz

Jakob Reschke
> Reworks public Compiler interface and documentation:
>
> - Parser: Do not use #fail in the event of an internal error unless compilation is interactive. This was a single precedent case.
> ...
> - Provide new convenience selectors #compileNoPattern: and #compileNoPattern:in: on Compiler instance side.

Independent of whether these changes are good or bad: what is their
reason or purpose? What was that single precedent case? I like to read
such things in the commit message. :-)

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Compiler-ct.452.mcz

Christoph Thiede

Thank you for the feedback, Jakob! I always try to be as specific as possible in the version message, but this one was apparently not precise enough ...


what is their reason or purpose?


I have been wondering a couple of times when exactly the failBlock passed to a compilation process is evaluated, or rather whether it might be evaluated at all. After analyzing the parser code, I found out that failBlock is evaluated *almost never* provided that the compilation is not interactive, i.e. whenever the specified requestor is nil. I have documented this insight in all relevant public method comments.


What was that single precedent case?


There was one exception to this (until now) undocumented rule: Parser >> #notify:at: sent an unconditional #fail "for failure setting up syntax error" which appears to be an internal and thus very rare error only. I have added an interactive check at the relevant place to make sure that the following invariant now is always valid:


If the requestor is nil, failBlock will not be evaluated under any circumstances.


This invariant should help us to simplify several users of the compiler API (in the Trunk as well as in external packages) to reduce the number of code branches that need to be honored. For one example of many, in ClosureCompilerTest >> #testDecompiledDoitMethodTempNames, we now know that we don't have to care about the failBlock so the [self error: 'compilation error'] there is officially redundant. And yes, in the future we also might want to introduce a simple #compile:in: convenience method for this purpose. :-)


I hope I could answer your questions ... :-)


Best,

Christoph


Von: Squeak-dev <[hidden email]> im Auftrag von Jakob Reschke <[hidden email]>
Gesendet: Samstag, 14. November 2020 16:58:59
An: [hidden email]
Betreff: Re: [squeak-dev] The Inbox: Compiler-ct.452.mcz
 
> Reworks public Compiler interface and documentation:
>
> - Parser: Do not use #fail in the event of an internal error unless compilation is interactive. This was a single precedent case.
> ...
> - Provide new convenience selectors #compileNoPattern: and #compileNoPattern:in: on Compiler instance side.

Independent of whether these changes are good or bad: what is their
reason or purpose? What was that single precedent case? I like to read
such things in the commit message. :-)



Carpe Squeak!