Skip to content

Commit

Permalink
buggy cause blocks fail algebra layout, both added watches and the me…
Browse files Browse the repository at this point in the history
…thods with watches in them
  • Loading branch information
JoeAtHPI committed Jan 19, 2024
1 parent dfc3477 commit 79d0863
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 33 deletions.
55 changes: 53 additions & 2 deletions packages/Sandblocks-Babylonian/SBExploriants.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ Class {
#name : #SBExploriants,
#superclass : #SBTabView,
#instVars : [
'objectToPermutation'
'objectToPermutation',
'updateProcess',
'updateProcessRunning'
],
#classInstVars : [
'uniqueInstance'
Expand Down Expand Up @@ -43,6 +45,12 @@ SBExploriants >> = other [
^ self class = other class
]

{ #category : #'as yet unclassified' }
SBExploriants >> artefactSaved: aMethodBlock [

(aMethodBlock isMethod and: [self isInEditor]) ifTrue: [self tryToUpdateInBackgroundAfterChangeIn: aMethodBlock]
]

{ #category : #'ast helpers' }
SBExploriants >> binding: aString for: block class: aClass ifPresent: aBlock [

Expand Down Expand Up @@ -86,6 +94,7 @@ SBExploriants >> initialize [
super initialize.

objectToPermutation := WeakKeyDictionary new.
updateProcessRunning := false.

self
attachDecorator: SBMoveDecorator new;
Expand Down Expand Up @@ -118,13 +127,55 @@ SBExploriants >> selector [
^ nil
]

{ #category : #'as yet unclassified' }
SBExploriants >> tryToUpdateInBackgroundAfterChangeIn: aMethodBlock [

| multiverse |
multiverse := self active multiverse.
"(multiverse allMethodBlocksContainingVariants includes: aMethodBlock)
ifTrue: [
| methodClass methodSelector latestChange |
methodClass := aMethodBlock compiledMethod methodClass.
methodSelector := aMethodBlock compiledMethod selector.
self halt.
latestChange := (ChangeSet
scanVersionsOf: aMethodBlock compiledMethod
class: methodClass
meta: methodClass isMeta
category: (methodClass organization categoryOfElement: methodSelector)
selector: methodSelector) first."

"mostRecentChangeSetWithChangeForClass: methodClass selector: methodSelector."
"aMethodBlock compiledMethod getSource asString allRangesOfRegexMatches: '(?<=activeIndex\: )\d*'."
"multiverse variants select: [:aVariant | aVariant containingArtefact = aMethodBlock]""]."

updateProcessRunning ifTrue: [
updateProcess ifNotNil: #terminate.
updateProcessRunning := false.].

updateProcessRunning := true.
updateProcess := [
| newMultiverse |
newMultiverse := SBMultiverse bigbangInEditorWithoutKaboom: self sandblockEditor.
self namedBlocks do: [:aTab | aTab multiverse: newMultiverse].
[newMultiverse kaboom]
valueWithin: 5 seconds
onTimeout: [
newMultiverse cleanUp. updateProcess := nil. updateProcessRunning := false.].
updateProcess := nil. updateProcessRunning := false.
] forkAt: Processor userBackgroundPriority.



]

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

| tabs |
self width: 0.
"tabs will visualize as soon as multiverse is finished"
tabs := SBExploriantsView getTabsInMultiverse: (SBMultiverse newInEditor: self sandblockEditor).
tabs := SBExploriantsView getTabsInMultiverse: (SBMultiverse bigbangInEditor: self sandblockEditor).

self namedBlocks: tabs activeIndex: 1.

Expand Down
4 changes: 2 additions & 2 deletions packages/Sandblocks-Babylonian/SBExploriantsView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ SBExploriantsView >> initialize [
{ #category : #accessing }
SBExploriantsView >> multiverse [

^ multiverse ifNil: [self multiverse: (SBMultiverse newInEditor: SBEditor current)]
^ multiverse ifNil: [self multiverse: (SBMultiverse bigbangInEditor: SBEditor current)]
]

{ #category : #accessing }
Expand All @@ -121,7 +121,7 @@ SBExploriantsView >> updateButton [
^ SBButton new
icon: SBIcon iconRotateLeft
label: 'Re-Generate Multiverse'
do: [self multiverse initialize];
do: [self multiverse gatherElements; asyncKaboom];
cornerStyle: #squared
]

Expand Down
96 changes: 67 additions & 29 deletions packages/Sandblocks-Babylonian/SBMultiverse.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Class {
#instVars : [
'universes',
'variants',
'watches',
'activeExamples',
'allMethodBlocksContainingVariants',
'allMethodBlocksContainingWatches',
Expand All @@ -16,21 +17,31 @@ Class {
}

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

"Use constructor with editor instead"
self shouldNotImplement
SBMultiverse class >> bigbangInEditor: aSandblockEditor [

^ self basicNew
sandblockEditor: aSandblockEditor;
initialize;
asyncKaboom;
yourself
]

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

^ self basicNew
sandblockEditor: aSandblockEditor;
initialize;
yourself
]

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

"Use constructor with editor instead"
self shouldNotImplement
]

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

Expand Down Expand Up @@ -89,12 +100,24 @@ SBMultiverse >> allMethodBlocksContainingWatches [

]

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

^ [self kaboom] forkAt: Processor userSchedulingPriority.
]

{ #category : #actions }
SBMultiverse >> cleanUp [

self resetWatchesToOriginalPermutationRunning: activeExamples.
(watches select: [:anOpenWatch | anOpenWatch containingArtefact isNil]) copy do: #delete
]

^ SBUniverse
newActive: aSBPermutation
watches: self copyWatches
{ #category : #actions }
SBMultiverse >> cleanUpRemovingCopies: outOfWorldWatches [

self resetWatchesToOriginalPermutationRunning: activeExamples.
outOfWorldWatches copy do: #delete
]

{ #category : #collecting }
Expand All @@ -115,12 +138,14 @@ SBMultiverse >> gatherElements [
have consistency between changes."
allMethodBlocksContainingVariants := self findExistingOrConvertToBlocks: self allCompiledMethodsContainingVariants.

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

variants := (allMethodBlocksContainingVariants collect: #containedVariants) flatten.
variants := variants select: #isActive.

watches := (self allMethodBlocksContainingWatches collect: #containedExampleWatches) flatten.

universes := OrderedCollection new.
activeExamples := self allActiveExamples.


Expand All @@ -129,27 +154,23 @@ SBMultiverse >> gatherElements [
{ #category : #'initialize-release' }
SBMultiverse >> initialize [

| permutations watches outOfWorldWatches |
super initialize.

self gatherElements.

permutations := SBPermutation allPermutationsOf: variants.
universes := OrderedCollection new.
self gatherElements.
]

{ #category : #actions }
SBMultiverse >> kaboom [

watches := (self allMethodBlocksContainingWatches collect: #containedExampleWatches) flatten.
| outOfWorldWatches |
"Only open watches display values when examples are run. We want to show them too"
(outOfWorldWatches := watches reject: #isInEditor) do: [:aWatch | self sandblockEditor openMorph: aWatch].

[permutations do: [:aPermutation |
SBActiveVariantPermutation value: aPermutation.
activeExamples do: #runSynchronouslyIgnoreReturn.
universes add: (SBUniverse newActive: aPermutation watches: (watches collect: #asInactiveCopy))].
outOfWorldWatches copy do: #delete.
self resetWatchesToOriginalPermutationRunning: activeExamples.
self triggerEvent: #updated] forkAt: Processor userSchedulingPriority.


(SBPermutation allPermutationsOf: variants) do: [:aPermutation |
self runPermutation: aPermutation copyingWatches: watches ].
self resetWatchesToOriginalPermutationRunning: activeExamples.
outOfWorldWatches copy do: #delete.
self triggerEvent: #updated.
]

{ #category : #actions }
Expand All @@ -159,13 +180,14 @@ SBMultiverse >> reset [
allMethodBlocksContainingWatches := OrderedCollection new.
variants := OrderedCollection new.
activeExamples := OrderedCollection new.
watches:= OrderedCollection new.
universes := OrderedCollection withAll: ((SBPermutation allPermutationsOf: {})
collect: [:aPermutation | self createUniverseFomPermutation: aPermutation]) .
collect: [:aPermutation | SBUniverse newActive: aPermutation watches: {}]) .

self triggerEvent: #updated.
]

{ #category : #state }
{ #category : #'action-helper' }
SBMultiverse >> resetWatchesToOriginalPermutationRunning: activeExamples [

SBActiveVariantPermutation value: nil.
Expand All @@ -189,6 +211,16 @@ SBMultiverse >> resolve [

]

{ #category : #actions }
SBMultiverse >> runPermutation: aPermutation copyingWatches: allWatches [


SBActiveVariantPermutation value: aPermutation.
activeExamples do: #runSynchronouslyIgnoreReturn.
universes add: (SBUniverse newActive: aPermutation watches: (watches collect: #asInactiveCopy))

]

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

Expand Down Expand Up @@ -220,3 +252,9 @@ SBMultiverse >> variants [

^ variants
]

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

^ watches
]

0 comments on commit 79d0863

Please sign in to comment.