From f579ce479524d464db1a8865fc4b59722d853446 Mon Sep 17 00:00:00 2001 From: adri09070 <97704417+adri09070@users.noreply.github.com> Date: Wed, 14 Jun 2023 09:43:53 +0200 Subject: [PATCH] making #pc: push the temp vector if the temp vector bytecode is on the method node + test --- .../SindarinDebuggerTest.class.st | 47 +++++++++++++++++++ src/Sindarin/SindarinDebugger.class.st | 11 +++-- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/Sindarin-Tests/SindarinDebuggerTest.class.st b/src/Sindarin-Tests/SindarinDebuggerTest.class.st index 4dd99e5..66b695a 100644 --- a/src/Sindarin-Tests/SindarinDebuggerTest.class.st +++ b/src/Sindarin-Tests/SindarinDebuggerTest.class.st @@ -124,6 +124,16 @@ SindarinDebuggerTest >> methodWithNotEvaluatedBlock [ ^ a * 42 ] +{ #category : #helpers } +SindarinDebuggerTest >> methodWithNotEvaluatedBlockWhoseCreationIsFirstBytecodeInFirstStatement [ + + | a block | + block := [ a := a + 1 ]. + a := 1. + a := a + 2. + ^ a * 42 +] + { #category : #helpers } SindarinDebuggerTest >> methodWithOneAssignment [ @@ -919,6 +929,43 @@ SindarinDebuggerTest >> testMoveToNodeWhenFromNonInlinedEmbeddedBlockToNodeThatI self assert: sdbg topStack equals: 2 ] +{ #category : #helpers } +SindarinDebuggerTest >> testMoveToNodeWhenNodeIsInBlockThatCreatesContextAndBlockCreationIsFirstBytecodeInFirstStatement [ + + | aimedBlock sdbg aimedNode | + sdbg := SindarinDebugger debug: [ + self + methodWithNotEvaluatedBlockWhoseCreationIsFirstBytecodeInFirstStatement ]. + "We step until the `a * 42` node" + sdbg step. + 6 timesRepeat: [ sdbg stepOver ]. + + self assert: sdbg method identicalTo: self class + >> + #methodWithNotEvaluatedBlockWhoseCreationIsFirstBytecodeInFirstStatement. + self assert: (sdbg readVariableNamed: #a) identicalTo: 3. + + "We jump to the node `a + 1` inside the block" + aimedBlock := sdbg methodNode statements first value. + aimedNode := aimedBlock body statements first value. + sdbg moveToNode: aimedNode. + + "We are in the block context" + self assert: sdbg method ast identicalTo: aimedBlock. + "The block context can also read #a" + self assert: (sdbg readVariableNamed: #a) identicalTo: 3. + + "We step the entire block" + 3 timesRepeat: [ sdbg stepOver ]. + + "We are back in the context method" + self assert: sdbg method identicalTo: self class + >> + #methodWithNotEvaluatedBlockWhoseCreationIsFirstBytecodeInFirstStatement. + "We can still read #a in the method context" + self assert: (sdbg readVariableNamed: #a) identicalTo: 4 +] + { #category : #tests } SindarinDebuggerTest >> testMoveToNodeWhenNodeIsInBlockThatCreatesContextAndBlockHasBeenCreated [ diff --git a/src/Sindarin/SindarinDebugger.class.st b/src/Sindarin/SindarinDebugger.class.st index cddd0a4..5ef0baa 100644 --- a/src/Sindarin/SindarinDebugger.class.st +++ b/src/Sindarin/SindarinDebugger.class.st @@ -243,13 +243,12 @@ SindarinDebugger >> nextExecutedNodeAfter: aNode [ { #category : #'API - changes' } SindarinDebugger >> pc: anInteger [ - "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" | nextNode methodNode firstPCOfStatementNode | "If aimedPC is outside the context PCs range, then an error is signaled" - (anInteger < self method initialPC or: [ - anInteger > self method endPC ]) ifTrue: [ + (anInteger < self method initialPC or: [ + anInteger > self method endPC ]) ifTrue: [ ^ NotValidPcError signal ]. methodNode := self methodNode. nextNode := methodNode sourceNodeForPC: anInteger. @@ -261,6 +260,12 @@ SindarinDebugger >> pc: anInteger [ methodNode statements first. self cleanStack ]. self context pc: firstPCOfStatementNode. + + "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." + self instructionStream willCreateBlock ifTrue: [ + self context pc: self instructionStream previousPc. + self stepBytecode ]. + self debugSession stepToFirstInterestingBytecodeIn: self debugSession interruptedProcess. self skipUpToNode: nextNode