Skip to content

Commit d3c1191

Browse files
FYL2003martin-henz
andauthoredSep 10, 2024··
stepper: add the comment to link the specification (#1680)
* add the comment to link the specification * delete the deprecated code, modify the comments --------- Co-authored-by: Martin Henz <[email protected]>
1 parent f443ccc commit d3c1191

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed
 

‎src/stepper/stepper.ts

+19-6
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,9 @@ function reduceMain(
17511751
]
17521752
}
17531753
},
1754-
1754+
/**
1755+
* Please refer to reduction of Program in stepper specification
1756+
*/
17551757
Program(
17561758
node: es.Program,
17571759
context: Context,
@@ -1974,7 +1976,9 @@ function reduceMain(
19741976
]
19751977
}
19761978
},
1977-
1979+
/**
1980+
* Please refer to reduction of BlockStatement in stepper specification
1981+
*/
19781982
BlockStatement(
19791983
node: es.BlockStatement,
19801984
context: Context,
@@ -2195,7 +2199,10 @@ function reduceMain(
21952199
]
21962200
}
21972201
},
2198-
2202+
/**
2203+
* Please refer to reduction of BlockExpression in stepper specification
2204+
* This is related to function application
2205+
*/
21992206
BlockExpression(
22002207
node: BlockExpression,
22012208
context: Context,
@@ -3346,6 +3353,7 @@ export function getEvaluationSteps(
33463353
const steps: [es.Program, string[][], string][] = []
33473354
try {
33483355
checkProgramForUndefinedVariables(program, context)
3356+
//reading the step limit
33493357
const limit = stepLimit === undefined ? 1000 : stepLimit % 2 === 0 ? stepLimit : stepLimit + 1
33503358
evaluateImports(program, context)
33513359
// starts with substituting predefined constants
@@ -3362,6 +3370,9 @@ export function getEvaluationSteps(
33623370
[],
33633371
'Start of evaluation'
33643372
]
3373+
/**
3374+
* push the content into frontend for showing contents in the webpage
3375+
*/
33653376
steps.push([
33663377
reducedWithPath[0] as es.Program,
33673378
reducedWithPath[2].length > 1 ? reducedWithPath[2].slice(1) : reducedWithPath[2],
@@ -3373,13 +3384,18 @@ export function getEvaluationSteps(
33733384
// odd steps: program after reduction
33743385
let i = 1
33753386
let limitExceeded = false
3387+
/**
3388+
* This is the start of actual reduction, calling reduceMain function in each iteration
3389+
* cause the program get reduced by one step at one iteration
3390+
*/
33763391
while (isStatementsReducible(reducedWithPath[0] as es.Program, context)) {
33773392
//Should work on isReducibleStatement instead of checking body.length
33783393
if (steps.length === limit) {
33793394
steps[steps.length - 1] = [ast.program([]), [], 'Maximum number of steps exceeded']
33803395
limitExceeded = true
33813396
break
33823397
}
3398+
//the program reduce by one step here
33833399
reducedWithPath = reduceMain(reducedWithPath[0], context)
33843400
steps.push([
33853401
reducedWithPath[0] as es.Program,
@@ -3406,9 +3422,6 @@ export function getEvaluationSteps(
34063422
])
34073423
}
34083424
}
3409-
if (steps.length === 0) {
3410-
steps.push([reducedWithPath[0] as es.Program, [], 'Nothing to evaluate'])
3411-
}
34123425
return steps
34133426
} catch (error) {
34143427
if (error instanceof RuntimeSourceError) {

0 commit comments

Comments
 (0)
Please sign in to comment.