The Trunk: Kernel-eem.1031.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.1031.mcz

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

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

Name: Kernel-eem.1031
Author: eem
Time: 5 July 2016, 6:16:17.071766 pm
UUID: 04b233a5-6540-4c4b-8a79-64e8e4c12e65
Ancestors: Kernel-eem.1030

Provide support for saving blocks on DataStreams.  The old code only allowed saving contewxts in image segments.  This code allows only the contexts of blocks being saved to be saved, an saves them with nilled senders, and is careful to manage fields beyond the top of stack, storing and reading nils.

With this code the following works, and one can e.g. save a MessageNames as a morph on file and read it in again.

[:a :b| a > b] saveOnFileNamed: 'block.bin'.
(MultiByteBinaryOrTextStream with: ((FileStream readOnlyFileNamed: 'block.bin') binary contentsOfEntireFile)) binary reset fileInObjectAndCode value: 2 value: 1

=============== Diff against Kernel-eem.1030 ===============

Item was added:
+ ----- Method: BlockClosure>>outerContextsDo: (in category 'private') -----
+ outerContextsDo: aBlock
+ "Evaluate aBlock with all the outer contexts along the receiver's static chain."
+ | outer |
+ outer := outerContext.
+ [outer notNil] whileTrue:
+ [aBlock value: outer.
+ outer := outer closure ifNotNil: [:outerClosure| outerClosure outerContext]]!

Item was added:
+ ----- Method: BlockClosure>>storeDataOn: (in category 'objects from disk') -----
+ storeDataOn: aDataStream
+ "Blocks are allowed go to out in DataStreams, but only without home senders."
+
+ | contexts |
+ contexts := IdentitySet new.
+ aDataStream insideASegment ifFalse:
+ [self outerContextsDo:
+ [:ctxt|
+ contexts add: ctxt.
+ aDataStream replace: ctxt sender with: nil]].
+ ^[super storeDataOn: aDataStream]
+ on: Notification
+ do: [:ex|
+ (contexts includes: ex tag)
+ ifTrue: [ex resume: ex tag]
+ ifFalse: [ex pass]]!

Item was added:
+ ----- Method: ContextPart>>readDataFrom:size: (in category 'objects from disk') -----
+ readDataFrom: aDataStream size: varsOnDisk
+ "Fill in the fields of self based on the contents of aDataStream.  Answer self.
+ Read in the instance-variables written by Object>>storeDataOn:.
+ NOTE: This method must send beginReference: before reading any objects from aDataStream that might reference it.
+ Allow aDataStream to have fewer inst vars.  See SmartRefStream.
+ Override to not store nil stack contents beyond stack pointer."
+ | cntInstVars cntIndexedVars |
+
+ cntInstVars := self class instSize.
+ cntIndexedVars := varsOnDisk - cntInstVars.
+ cntIndexedVars < 0 ifTrue:
+ [self error: 'Class has changed too much.  Define a convertxxx method'].
+
+ aDataStream beginReference: self.
+ 1 to: cntInstVars do:
+ [:i | self instVarAt: i put: aDataStream next].
+ 1 to: stackp do:
+ [:i | self basicAt: i put: aDataStream next].
+ stackp + 1 to: cntIndexedVars do:
+ [:i | aDataStream next ~~ nil ifTrue:
+ [self error: 'Reading a Context''s contents expects only nil beyond top of stack']].
+ "Total number read MUST be equal to varsOnDisk!!"
+ ^self "If we ever answer something other than self, fix calls
+ on (super readDataFrom: aDataStream size: anInteger)"!

Item was changed:
  ----- Method: ContextPart>>storeDataOn: (in category 'objects from disk') -----
  storeDataOn: aDataStream
+ "Contexts are not always allowed go to out in DataStreams.  They must be included inside an ImageSegment,
+ or be being saved for a closure."
+ | cntInstVars cntIndexedVars |
- "Contexts are not allowed go to out in DataStreams.  They must be included inside an ImageSegment."
 
+ (aDataStream insideASegment
+ or: [(Notification new tag: self; signal) == self]) ifFalse: "or perhaps ImageSegments were not used at all"
+ [self error: 'This Context was not included in the ImageSegment'].
- aDataStream insideASegment ifTrue: [^ super storeDataOn: aDataStream].
 
+ cntInstVars := self class instSize.
+ cntIndexedVars := self method frameSize.
+ aDataStream
+ beginInstance: self class
+ size: cntInstVars + cntIndexedVars.
+ 1 to: cntInstVars do:
+ [:i | aDataStream nextPut: (self instVarAt: i)].
+ 1 to: stackp do:
+ [:i | aDataStream nextPut: (self basicAt: i)].
+ stackp + 1 to: cntIndexedVars do:
+ [:i | aDataStream nextPut: nil]!
- self error: 'This Context was not included in the ImageSegment'.
- "or perhaps ImageSegments were not used at all"
- ^ nil!