Skip to content

Commit

Permalink
stepper: add the comment to link the specification (#1680)
Browse files Browse the repository at this point in the history
* add the comment to link the specification

* delete the deprecated code, modify the comments

---------

Co-authored-by: Martin Henz <[email protected]>
  • Loading branch information
FYL2003 and martin-henz authored Sep 10, 2024
1 parent f443ccc commit d3c1191
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/stepper/stepper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,9 @@ function reduceMain(
]
}
},

/**
* Please refer to reduction of Program in stepper specification
*/
Program(
node: es.Program,
context: Context,
Expand Down Expand Up @@ -1974,7 +1976,9 @@ function reduceMain(
]
}
},

/**
* Please refer to reduction of BlockStatement in stepper specification
*/
BlockStatement(
node: es.BlockStatement,
context: Context,
Expand Down Expand Up @@ -2195,7 +2199,10 @@ function reduceMain(
]
}
},

/**
* Please refer to reduction of BlockExpression in stepper specification
* This is related to function application
*/
BlockExpression(
node: BlockExpression,
context: Context,
Expand Down Expand Up @@ -3346,6 +3353,7 @@ export function getEvaluationSteps(
const steps: [es.Program, string[][], string][] = []
try {
checkProgramForUndefinedVariables(program, context)
//reading the step limit
const limit = stepLimit === undefined ? 1000 : stepLimit % 2 === 0 ? stepLimit : stepLimit + 1
evaluateImports(program, context)
// starts with substituting predefined constants
Expand All @@ -3362,6 +3370,9 @@ export function getEvaluationSteps(
[],
'Start of evaluation'
]
/**
* push the content into frontend for showing contents in the webpage
*/
steps.push([
reducedWithPath[0] as es.Program,
reducedWithPath[2].length > 1 ? reducedWithPath[2].slice(1) : reducedWithPath[2],
Expand All @@ -3373,13 +3384,18 @@ export function getEvaluationSteps(
// odd steps: program after reduction
let i = 1
let limitExceeded = false
/**
* This is the start of actual reduction, calling reduceMain function in each iteration
* cause the program get reduced by one step at one iteration
*/
while (isStatementsReducible(reducedWithPath[0] as es.Program, context)) {
//Should work on isReducibleStatement instead of checking body.length
if (steps.length === limit) {
steps[steps.length - 1] = [ast.program([]), [], 'Maximum number of steps exceeded']
limitExceeded = true
break
}
//the program reduce by one step here
reducedWithPath = reduceMain(reducedWithPath[0], context)
steps.push([
reducedWithPath[0] as es.Program,
Expand All @@ -3406,9 +3422,6 @@ export function getEvaluationSteps(
])
}
}
if (steps.length === 0) {
steps.push([reducedWithPath[0] as es.Program, [], 'Nothing to evaluate'])
}
return steps
} catch (error) {
if (error instanceof RuntimeSourceError) {
Expand Down

0 comments on commit d3c1191

Please sign in to comment.