Skip to content

Commit cb5d860

Browse files
Merge pull request #78 from adri09070/55bis-jump-to-caret-does-not-keep-a-correct-stack-when-there-are-vector-arrays-to-store-common-variables-between-methods-and-blocks
Fixing: jump to caret does not keep a correct stack when there are vector arrays to store common variables between methods and blocks
2 parents 3962ffe + f579ce4 commit cb5d860

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

src/Sindarin-Tests/SindarinDebuggerTest.class.st

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ SindarinDebuggerTest >> methodWithNotEvaluatedBlock [
124124
^ a * 42
125125
]
126126

127+
{ #category : #helpers }
128+
SindarinDebuggerTest >> methodWithNotEvaluatedBlockWhoseCreationIsFirstBytecodeInFirstStatement [
129+
130+
| a block |
131+
block := [ a := a + 1 ].
132+
a := 1.
133+
a := a + 2.
134+
^ a * 42
135+
]
136+
127137
{ #category : #helpers }
128138
SindarinDebuggerTest >> methodWithOneAssignment [
129139

@@ -933,6 +943,43 @@ SindarinDebuggerTest >> testMoveToNodeWhenFromNonInlinedEmbeddedBlockToNodeThatI
933943
self assert: sdbg topStack equals: 2
934944
]
935945

946+
{ #category : #helpers }
947+
SindarinDebuggerTest >> testMoveToNodeWhenNodeIsInBlockThatCreatesContextAndBlockCreationIsFirstBytecodeInFirstStatement [
948+
949+
| aimedBlock sdbg aimedNode |
950+
sdbg := SindarinDebugger debug: [
951+
self
952+
methodWithNotEvaluatedBlockWhoseCreationIsFirstBytecodeInFirstStatement ].
953+
"We step until the `a * 42` node"
954+
sdbg step.
955+
6 timesRepeat: [ sdbg stepOver ].
956+
957+
self assert: sdbg method identicalTo: self class
958+
>>
959+
#methodWithNotEvaluatedBlockWhoseCreationIsFirstBytecodeInFirstStatement.
960+
self assert: (sdbg readVariableNamed: #a) identicalTo: 3.
961+
962+
"We jump to the node `a + 1` inside the block"
963+
aimedBlock := sdbg methodNode statements first value.
964+
aimedNode := aimedBlock body statements first value.
965+
sdbg moveToNode: aimedNode.
966+
967+
"We are in the block context"
968+
self assert: sdbg method ast identicalTo: aimedBlock.
969+
"The block context can also read #a"
970+
self assert: (sdbg readVariableNamed: #a) identicalTo: 3.
971+
972+
"We step the entire block"
973+
3 timesRepeat: [ sdbg stepOver ].
974+
975+
"We are back in the context method"
976+
self assert: sdbg method identicalTo: self class
977+
>>
978+
#methodWithNotEvaluatedBlockWhoseCreationIsFirstBytecodeInFirstStatement.
979+
"We can still read #a in the method context"
980+
self assert: (sdbg readVariableNamed: #a) identicalTo: 4
981+
]
982+
936983
{ #category : #tests }
937984
SindarinDebuggerTest >> testMoveToNodeWhenNodeIsInBlockThatCreatesContextAndBlockHasBeenCreated [
938985

src/Sindarin/SindarinDebugger.class.st

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,12 @@ SindarinDebugger >> nextExecutedNodeAfter: aNode [
243243

244244
{ #category : #'API - changes' }
245245
SindarinDebugger >> pc: anInteger [
246-
247246
"Allows to move to the first PC associated to the node to which anInteger is associated. anInteger must be a valid pc in the suspended context"
248247

249248
| nextNode methodNode firstPCOfStatementNode |
250249
"If aimedPC is outside the context PCs range, then an error is signaled"
251-
(anInteger < self method initialPC or: [
252-
anInteger > self method endPC ]) ifTrue: [
250+
(anInteger < self method initialPC or: [
251+
anInteger > self method endPC ]) ifTrue: [
253252
^ NotValidPcError signal ].
254253
methodNode := self methodNode.
255254
nextNode := methodNode sourceNodeForPC: anInteger.
@@ -261,6 +260,12 @@ SindarinDebugger >> pc: anInteger [
261260
methodNode statements first.
262261
self cleanStack ].
263262
self context pc: firstPCOfStatementNode.
263+
264+
"If the first pc of the first statement is mapped to a block creation. That means that it needs the associated temp vector on top of the stack. The bytecode that pushes this vector on the stack precedes the block creation. So, here, this bytecode is mapped to the method node and has been skipped. Thus, we go back to the previous bytecode to execute it."
265+
self instructionStream willCreateBlock ifTrue: [
266+
self context pc: self instructionStream previousPc.
267+
self stepBytecode ].
268+
264269
self debugSession stepToFirstInterestingBytecodeIn:
265270
self debugSession interruptedProcess.
266271
self skipUpToNode: nextNode

0 commit comments

Comments
 (0)