The Trunk: Kernel-eem.1360.mcz

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

The Trunk: Kernel-eem.1360.mcz

commits-2
Eliot Miranda uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-eem.1360.mcz

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

Name: Kernel-eem.1360
Author: eem
Time: 2 November 2020, 10:10:50.874417 am
UUID: 2041d4e1-746a-49f9-9098-8fbd6ba2f787
Ancestors: Kernel-eem.1359, Kernel-ct.1359

Merge Kernel-ct.1359 from inbox
Author: ct
Time: 1 November 2020, 7:50:24.183428 pm
UUID: 3b12b316-79f3-de41-8765-8296d964b821
Ancestors: Kernel-mt.1353

Revise and extend Context #runSimulated: implementation. Remove restriction to blocks that do not have a method return. Add support for exception signaling during the execution, which caused unterminated simulation of the calling process in the past. Support argless contextAtEachStep blocks.

Benchmarks:
        code:
                [Context runSimulated: [100@100 corner: 200@200]] bench
        before:
                16.7 ms/run
        after:
                19.8 ms/run
I think this should be okay, given the fact that the primary purpose of simulation is providing explorability but not efficiency ...

eem: Fix a bug in the use of runSimulated:contextAtEachStep:.  Presumably because of the pre-closure block model existing senders were of the form
        thisContext sender
                runSimulated: aBlock
                contextAtEachStep: [....]
but this caused the jump at the end of runSimulated:contextAtEachStep: to short-cut any processing done after runSimulated:contextAtEachStep:.  So rewrite all users of runSimulated:contextAtEachStep: in this form:
        thisContext
                runSimulated: aBlock
                contextAtEachStep: [....]
                and consequently have tallyInstruction: rallyMethods: et al answer their intended results.

=============== Diff against Kernel-eem.1359 ===============

Item was changed:
  ----- Method: Context class>>runSimulated: (in category 'simulation') -----
  runSimulated: aBlock
+ "Simulate the execution of aBlock, until it ends or is curtailed. Answer the result it returns."
- "Simulate the execution of the argument, current. Answer the result it
- returns."
 
+ ^thisContext
- ^ thisContext sender
  runSimulated: aBlock
+ contextAtEachStep: []
- contextAtEachStep: [:ignored]
 
  "Context runSimulated: [Pen new defaultNib: 5; go: 100]"!

Item was changed:
  ----- Method: Context class>>tallyInstructions: (in category 'examples') -----
  tallyInstructions: aBlock
  "This method uses the simulator to count the number of occurrences of
  each of the Smalltalk instructions executed during evaluation of aBlock.
  Results appear in order of the byteCode set."
  | tallies |
  tallies := Bag new.
+ thisContext
- thisContext sender
  runSimulated: aBlock
  contextAtEachStep:
  [:current | tallies add: current nextByte].
  ^tallies sortedElements
 
  "Context tallyInstructions: [3.14159 printString]"!

Item was changed:
  ----- Method: Context class>>tallyMethods: (in category 'examples') -----
  tallyMethods: aBlock
  "This method uses the simulator to count the number of calls on each method
  invoked in evaluating aBlock. Results are given in order of decreasing counts."
  | prev tallies |
  tallies := Bag new.
  prev := aBlock.
+ thisContext
- thisContext sender
  runSimulated: aBlock
  contextAtEachStep:
  [:current |
  current == prev ifFalse: "call or return"
  [prev sender == nil ifFalse: "call only"
  [tallies add: current printString].
  prev := current]].
  ^tallies sortedCounts
 
  "Context tallyMethods: [3.14159 printString]"!

Item was changed:
  ----- Method: Context class>>trace:on: (in category 'examples') -----
  trace: aBlock on: aStream "Context trace: [3 factorial]"
  "This method uses the simulator to print calls to a file."
  | prev |
  prev := aBlock.
+ ^thisContext
- ^ thisContext sender
  runSimulated: aBlock
  contextAtEachStep:
  [:current |
+ Sensor anyButtonPressed ifTrue: [^nil].
+ current == prev ifFalse:
+ [prev sender ifNil:
+ [aStream space; nextPut: $^.
+ self carefullyPrint: current top on: aStream].
+ aStream cr.
+ (current depthBelow: aBlock) timesRepeat: [aStream space].
+ self carefullyPrint: current receiver on: aStream.
+ aStream space; nextPutAll: current selector; flush.
+ prev := current]]!
- Sensor anyButtonPressed ifTrue: [^ nil].
- current == prev
- ifFalse:
- [prev sender ifNil:
- [aStream space; nextPut: $^.
- self carefullyPrint: current top on: aStream].
- aStream cr.
- (current depthBelow: aBlock) timesRepeat: [aStream space].
- self carefullyPrint: current receiver on: aStream.
- aStream space; nextPutAll: current selector; flush.
- prev := current]]!

Item was changed:
  ----- Method: Context>>runSimulated:contextAtEachStep: (in category 'system simulation') -----
+ runSimulated: aBlock contextAtEachStep: anotherBlock
+ "Simulate the execution of the argument, aBlock, until it ends or is curtailed. If any exception is signaled during the execution, simulate it being handled on the present caller stack. Evaluate anotherBlock with the current context prior to each instruction executed. Answer the simulated value of aBlock."
+
+ | current resume ensure |
+ resume := false.
- runSimulated: aBlock contextAtEachStep: block2
- "Simulate the execution of the argument, aBlock, until it ends. aBlock
- MUST NOT contain an '^'. Evaluate block2 with the current context
- prior to each instruction executed. Answer the simulated value of aBlock."
- | current |
- aBlock hasMethodReturn
- ifTrue: [self error: 'simulation of blocks with ^ can run loose'].
  current := aBlock asContext.
+ ensure := current insertSender: (Context contextEnsure: [resume := true]).
+ ensure sender ifNil: [ensure privSender: self]. "For backward compatibility, do not fail if aBlock is dead."
+
+ (anotherBlock numArgs = 0
+ ifTrue: ["optimized" [resume]]
+ ifFalse: ["stop execution on time, don't expose simulation details to caller"
+ [current == ensure or:
+ ["Context >> #resume:"
+ current size >= 2 and:
+ [(current at: 2) == ensure]]] ])
- current pushArgs: Array new from: self.
- [current == self]
  whileFalse:
+ [anotherBlock cull: current.
- [block2 value: current.
  current := current step].
+
+ ^ current jump!
- ^self pop!