Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stepper: add the comment to link the specification #1680

Merged
25 changes: 19 additions & 6 deletions src/stepper/stepper.ts
Original file line number Diff line number Diff line change
@@ -1751,7 +1751,9 @@ function reduceMain(
]
}
},

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

/**
* Please refer to reduction of BlockStatement in stepper specification
*/
BlockStatement(
node: es.BlockStatement,
context: Context,
@@ -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,
@@ -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
@@ -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],
@@ -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,
@@ -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) {

Unchanged files with check annotations Beta

'call_cc(f)',
context.variant === Variant.EXPLICIT_CONTROL
? call_with_current_continuation
: (f: any) => {

Check warning on line 425 in src/createContext.ts

GitHub Actions / build

'f' is defined but never used. Allowed unused args must match /^_/u
throw new Error('call_cc is only available in Explicit-Control variant')
}
)
-1
)
// Run the new CSE Machine fully to obtain the result in the stash
for (const _ of gen) {

Check warning on line 50 in src/cse-machine/closure.ts

GitHub Actions / build

'_' is assigned a value but never used
}
// Also don't forget to update object count in original context
context.runtime.objectCount = newContext.runtime.objectCount
* @returns The corresponding promise.
*/
export function CSEResultPromise(context: Context, value: Value): Promise<Result> {
return new Promise((resolve, reject) => {

Check warning on line 268 in src/cse-machine/interpreter.ts

GitHub Actions / build

'reject' is defined but never used. Allowed unused args must match /^_/u
if (value instanceof CSEBreak) {
resolve({ status: 'suspended-cse-eval', context })
} else if (value instanceof CseError) {
command: es.WhileStatement,
context: Context,
control: Control,
stash: Stash

Check warning on line 495 in src/cse-machine/interpreter.ts

GitHub Actions / build

'stash' is defined but never used. Allowed unused args must match /^_/u
) {
if (hasBreakStatement(command.body as es.BlockStatement)) {
control.push(instr.breakMarkerInstr(command))
command: es.IfStatement,
context: Context,
control: Control,
stash: Stash

Check warning on line 578 in src/cse-machine/interpreter.ts

GitHub Actions / build

'stash' is defined but never used. Allowed unused args must match /^_/u
) {
control.push(...reduceConditional(command))
},
command: es.ContinueStatement,
context: Context,
control: Control,
stash: Stash

Check warning on line 651 in src/cse-machine/interpreter.ts

GitHub Actions / build

'stash' is defined but never used. Allowed unused args must match /^_/u
) {
control.push(instr.contInstr(command))
},
command: es.BreakStatement,
context: Context,
control: Control,
stash: Stash

Check warning on line 660 in src/cse-machine/interpreter.ts

GitHub Actions / build

'stash' is defined but never used. Allowed unused args must match /^_/u
) {
control.push(instr.breakInstr(command))
},
command: es.MemberExpression,
context: Context,
control: Control,
stash: Stash

Check warning on line 707 in src/cse-machine/interpreter.ts

GitHub Actions / build

'stash' is defined but never used. Allowed unused args must match /^_/u
) {
control.push(instr.arrAccInstr(command))
control.push(command.property)
command: es.ConditionalExpression,
context: Context,
control: Control,
stash: Stash

Check warning on line 718 in src/cse-machine/interpreter.ts

GitHub Actions / build

'stash' is defined but never used. Allowed unused args must match /^_/u
) {
control.push(...reduceConditional(command))
},
* Instructions
*/
[InstrType.RESET]: function (command: Instr, context: Context, control: Control, stash: Stash) {

Check warning on line 780 in src/cse-machine/interpreter.ts

GitHub Actions / build

'stash' is defined but never used. Allowed unused args must match /^_/u
// Keep pushing reset instructions until marker is found.
const cmdNext: ControlItem | undefined = control.pop()
if (cmdNext && (isNode(cmdNext) || cmdNext.instrType !== InstrType.MARKER)) {