Skip to content

Commit

Permalink
Adds SBUniverse / SBMultiverse to save objects in a permutation (make…
Browse files Browse the repository at this point in the history
…s things faster)
  • Loading branch information
JoeAtHPI committed Nov 16, 2023
1 parent b374de3 commit fedbf57
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 99 deletions.
8 changes: 3 additions & 5 deletions packages/Sandblocks-Babylonian/SBExploriants.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ SBExploriants >> saveTryFixing: aFixBoolean quick: aQuickBoolean [
^ true
]

{ #category : #'as yet unclassified' }
{ #category : #accessing }
SBExploriants >> selector [
" if this node represents any selector, return it here "

Expand All @@ -85,11 +85,9 @@ SBExploriants >> selector [
{ #category : #actions }
SBExploriants >> visualize [

"The Views need a parent to visualize themselves. We also want to avoid double-calculations"
| tabs |
tabs := SBExploriantsView getTabs.
tabs do: [:aTab | self addMorph: aTab block. aTab visualize.].
self removeAllMorphs.
tabs := SBExploriantsView getTabsInMultiverse: (SBMultiverse newInEditor: self sandblockEditor).
tabs do: #visualize.

self namedBlocks: tabs activeIndex: 1.

Expand Down
51 changes: 23 additions & 28 deletions packages/Sandblocks-Babylonian/SBExploriantsView.class.st
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"
Caution:
The Views need a parent who in in the editor to visualize themselves
"
Class {
#name : #SBExploriantsView,
#superclass : #SBNamedBlock,
#instVars : [
'multiverse'
],
#category : #'Sandblocks-Babylonian'
}

Expand All @@ -22,34 +21,18 @@ SBExploriantsView class >> deepSubclasses: aClass [
]

{ #category : #'instance creation' }
SBExploriantsView class >> getTabs [
SBExploriantsView class >> getTabsInMultiverse: aSBMultiverse [

^ (self subclasses collect: [:mySubClass | self deepSubclasses: mySubClass]) flatten collect: #new
^ (self subclasses collect: [:mySubClass | self deepSubclasses: mySubClass]) flatten
collect: [:mySubclass | mySubclass newMultiverse: aSBMultiverse]
]

{ #category : #accessing }
SBExploriantsView >> allCompiledMethodsContainingClass: aClass [

"aClass should have #matchingSelectors implemented"
^ (((aClass matchingSelectors collect: [:aSelector | self systemNavigation allCallsOn: aSelector]) flatten)
reject: [:aMethodReference | aMethodReference actualClass = aClass class])
collect: #compiledMethod
]

{ #category : #accessing }
SBExploriantsView >> allCompiledMethodsContainingVariants [

^ self allCompiledMethodsContainingClass: SBVariant
]

{ #category : #accessing }
SBExploriantsView >> allMethodBlocksContainingVariants [

"We are looking for already opened methods so that we can assign the
variant there as the original in SBVariantProxy. That way, we immediately
have consistency between changes."
^ self findExistingOrConvertToBlocks: self allCompiledMethodsContainingVariants
{ #category : #'instance creation' }
SBExploriantsView class >> newMultiverse: aSBMultiverse [

^ self new
multiverse: aSBMultiverse;
yourself
]

{ #category : #actions }
Expand Down Expand Up @@ -100,6 +83,18 @@ SBExploriantsView >> initialize [
vResizing: #shrinkWrap)
]

{ #category : #accessing }
SBExploriantsView >> multiverse [

^ multiverse ifNil: [multiverse := SBMultiverse newInEditor: SBEditor current]
]

{ #category : #accessing }
SBExploriantsView >> multiverse: aSBMultiverse [

multiverse := aSBMultiverse
]

{ #category : #actions }
SBExploriantsView >> visualize [

Expand Down
8 changes: 4 additions & 4 deletions packages/Sandblocks-Babylonian/SBGridResultsView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Class {
}

{ #category : #building }
SBGridResultsView >> buildPermutationFor: aPermutation collectingWatchesFrom: aCollectionOfMethodBlocks [
SBGridResultsView >> buildPermutationFor: aSBUniverse [

self block addAllMorphsBack: { SBOwnTextMorph new contents: aPermutation asString.
self applyButtonFor: aPermutation.
self block addAllMorphsBack: { SBOwnTextMorph new contents: aSBUniverse activePermutation asString.
self applyButtonFor: aSBUniverse activePermutation.
(self containerRow listDirection: #leftToRight)
addMorph: ((
SBPermutationCluster
newFromWatches: (self allWatchesIn: aCollectionOfMethodBlocks)
newFromWatches: aSBUniverse watches
havingSize: (SBMorphResizer newMedium))).
LineMorph from: 0@0 to: 50@0 color: Color black width: 2}
]
Expand Down
159 changes: 159 additions & 0 deletions packages/Sandblocks-Babylonian/SBMultiverse.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
Class {
#name : #SBMultiverse,
#superclass : #Object,
#instVars : [
'universes',
'variants',
'watches',
'activeExamples',
'allMethodBlocksContainingVariants',
'allMethodBlocksContainingWatches',
'sandblockEditor'
],
#category : #'Sandblocks-Babylonian'
}

{ #category : #'instance creation' }
SBMultiverse class >> new [

"Use constructor with editor instead"
self shouldNotImplement
]

{ #category : #'instance creation' }
SBMultiverse class >> newInEditor: aSandblockEditor [

^ self basicNew
sandblockEditor: aSandblockEditor;
initialize;
yourself
]

{ #category : #accessing }
SBMultiverse >> activeExamples [

^ activeExamples
]

{ #category : #collecting }
SBMultiverse >> allActiveExamples [

^ (self allCompiledMethodsContainingExamples
collect: [:aCompiledMethod |
"Only examples which are open in the editor can actually be active."
self sandblockEditor blockFor: aCompiledMethod withInterfaces: #(#isMethod)
ifOpen: [:existingMethodBlock | existingMethodBlock containedExamples select: #active]
ifClosed: [#()]]) flatten
]

{ #category : #collecting }
SBMultiverse >> allCompiledMethodsContainingClass: aClass [

"aClass should have #matchingSelectors implemented"
^ (((aClass matchingSelectors collect: [:aSelector | self systemNavigation allCallsOn: aSelector]) flatten)
reject: [:aMethodReference | aMethodReference actualClass = aClass class])
collect: #compiledMethod
]

{ #category : #collecting }
SBMultiverse >> allCompiledMethodsContainingExampleWatches [

^ self allCompiledMethodsContainingClass: SBExampleWatch
]

{ #category : #collecting }
SBMultiverse >> allCompiledMethodsContainingExamples [

^ self allCompiledMethodsContainingClass: SBExample
]

{ #category : #collecting }
SBMultiverse >> allCompiledMethodsContainingVariants [

^ self allCompiledMethodsContainingClass: SBVariant
]

{ #category : #accessing }
SBMultiverse >> allMethodBlocksContainingVariants [

^ allMethodBlocksContainingVariants

]

{ #category : #accessing }
SBMultiverse >> allMethodBlocksContainingWatches [

^ allMethodBlocksContainingWatches

]

{ #category : #collecting }
SBMultiverse >> copyWatchesIn: aCollectionOfMethodBlocks [

^ (aCollectionOfMethodBlocks collect: [:aMethodBlock |
aMethodBlock containedExampleWatches collect: #asInactiveCopy]) flatten
]

{ #category : #converting }
SBMultiverse >> createUniverseFomPermutation: aSBPermutation [

^ SBUniverse
newActive: aSBPermutation
watches: (self copyWatchesIn: self allMethodBlocksContainingWatches)
]

{ #category : #collecting }
SBMultiverse >> findExistingOrConvertToBlocks: aCollectionOfCompiledMethods [

^ aCollectionOfCompiledMethods
collect: [:aCompiledMethod |
self sandblockEditor blockFor: aCompiledMethod withInterfaces: #(#isMethod)
ifOpen: [:existingMethodBlock | existingMethodBlock]
ifClosed: [aCompiledMethod asSandblock]]
]

{ #category : #'initialize-release' }
SBMultiverse >> initialize [

super initialize.

"We are looking for already opened methods so that we can assign the
variant there as the original in SBVariantProxy. That way, we immediately
have consistency between changes."
allMethodBlocksContainingVariants := self findExistingOrConvertToBlocks: self allCompiledMethodsContainingVariants.

"We need existing originals to be noticed of changes."
allMethodBlocksContainingWatches := self findExistingOrConvertToBlocks: self allCompiledMethodsContainingExampleWatches.

variants := (allMethodBlocksContainingVariants collect: #containedVariants) flatten.
activeExamples := self allActiveExamples.

universes := (SBPermutation allPermutationsOf: variants) collect: [:aPermutation |
self createUniverseFomPermutation: aPermutation].


]

{ #category : #accessing }
SBMultiverse >> sandblockEditor [

^ sandblockEditor
]

{ #category : #accessing }
SBMultiverse >> sandblockEditor: aSandblockEditor [

sandblockEditor := aSandblockEditor
]

{ #category : #accessing }
SBMultiverse >> universes [

^ universes
]

{ #category : #accessing }
SBMultiverse >> variants [

^ variants
]
71 changes: 10 additions & 61 deletions packages/Sandblocks-Babylonian/SBResultsView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,6 @@ Class {
#category : #'Sandblocks-Babylonian'
}

{ #category : #building }
SBResultsView >> addAllWatchesFrom: aCollectionOfMethodBlocks [

self block addAllMorphsBack: (self allWatchesIn: aCollectionOfMethodBlocks)
]

{ #category : #accessing }
SBResultsView >> allActiveExamples [

^ (self allCompiledMethodsContainingExamples
collect: [:aCompiledMethod |
"Only examples which are open in the editor can actually be active."
self block sandblockEditor blockFor: aCompiledMethod withInterfaces: #(#isMethod)
ifOpen: [:existingMethodBlock | existingMethodBlock containedExamples select: #active]
ifClosed: [#()]]) flatten
]

{ #category : #accessing }
SBResultsView >> allCompiledMethodsContainingExampleWatches [

^ self allCompiledMethodsContainingClass: SBExampleWatch
]

{ #category : #accessing }
SBResultsView >> allCompiledMethodsContainingExamples [

^ self allCompiledMethodsContainingClass: SBExample
]

{ #category : #accessing }
SBResultsView >> allMethodBlocksContainingWatches [

"We need existing originals to be noticed of changes."
^ self findExistingOrConvertToBlocks: self allCompiledMethodsContainingExampleWatches

]

{ #category : #accessing }
SBResultsView >> allWatchesIn: aCollectionOfMethodBlocks [

^ (aCollectionOfMethodBlocks collect: [:aMethodBlock |
aMethodBlock containedExampleWatches collect: #asInactiveCopy]) flatten
]

{ #category : #building }
SBResultsView >> applyButtonFor: aPermutation [

Expand All @@ -63,30 +19,23 @@ SBResultsView >> applyButtonFor: aPermutation [

{ #category : #building }
SBResultsView >> buildAllPossibleResults [

| permutations activeExamples watchMethodBlocks variants |
self flag: #todo. "don't calculate all variants a second time (first time being the variants view) -jb"
variants := (self allMethodBlocksContainingVariants collect: #containedVariants) flatten.
watchMethodBlocks := self allMethodBlocksContainingWatches.
activeExamples := self allActiveExamples.
permutations := SBPermutation allPermutationsOf: variants.

permutations ifEmpty: [self addAllWatchesFrom: watchMethodBlocks].
self multiverse universes ifEmpty: [self block addAllMorphsBack: self mutliverse watches].

[ permutations do: [:aPermutation |
SBActiveVariantPermutation value: aPermutation.
activeExamples do: #runSynchronouslyIgnoreReturn.
self buildPermutationFor: aPermutation collectingWatchesFrom: watchMethodBlocks].
self resetWatchesToOriginalPermutationRunning: activeExamples] forkAt: Processor userSchedulingPriority
[ self multiverse universes do: [:aUniverse |
SBActiveVariantPermutation value: aUniverse activePermutation.
self multiverse activeExamples do: #runSynchronouslyIgnoreReturn.
self buildPermutationFor: aUniverse].
self resetWatchesToOriginalPermutationRunning: self multiverse activeExamples] forkAt: Processor userSchedulingPriority
]

{ #category : #building }
SBResultsView >> buildPermutationFor: aPermutation collectingWatchesFrom: aCollectionOfMethodBlocks [
SBResultsView >> buildPermutationFor: aSBUniverse [

self block addAllMorphsBack: { SBOwnTextMorph new contents: aPermutation asString.
self applyButtonFor: aPermutation.
self block addAllMorphsBack: { SBOwnTextMorph new contents: aSBUniverse activePermutation asString.
self applyButtonFor: aSBUniverse activePermutation.
(self containerRow listDirection: #leftToRight)
addAllMorphsBack: (self allWatchesIn: aCollectionOfMethodBlocks).
addAllMorphsBack: aSBUniverse watches.
LineMorph from: 0@0 to: 50@0 color: Color black width: 2}
]

Expand Down
Loading

0 comments on commit fedbf57

Please sign in to comment.