Skip to content

Commit

Permalink
CSE Machine: Fix environment reset instruction insertion (#1542)
Browse files Browse the repository at this point in the history
* fix environment reset instruction insertion

* Update nodejs.yml

* remove unneccesary semiclolon in .github/workflows/nodejs.yml

Co-authored-by: Richard Dominick <[email protected]>

---------

Co-authored-by: Richard Dominick <[email protected]>
  • Loading branch information
NhatMinh0208 and RichDom2185 authored Feb 18, 2024
1 parent 31b262f commit 9f82165
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/cse-machine/__tests__/__snapshots__/cse-machine.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ fact(5);",
}
`;

exports[`Environment reset is inserted when only instructions are in control stack: expectResult 1`] = `
Object {
"alertResult": Array [],
"code": "const a = (v => v)(0);",
"displayResult": Array [],
"numErrors": 0,
"parsedErrors": "",
"result": undefined,
"resultStatus": "finished",
"visualiseListResult": Array [],
}
`;

exports[`Imports are properly handled: expectResult 1`] = `
Object {
"alertResult": Array [],
Expand Down
9 changes: 9 additions & 0 deletions src/cse-machine/__tests__/cse-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,12 @@ test('Breaks, continues and returns are detected properly inside loops', () => {
optionEC3
).toMatchInlineSnapshot(`3`)
})

test('Environment reset is inserted when only instructions are in control stack', () => {
return expectResult(
stripIndent`
const a = (v => v)(0);
`,
optionEC3
).toMatchInlineSnapshot(`undefined`)
})
2 changes: 1 addition & 1 deletion src/cse-machine/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ const cmdEvaluators: { [type: string]: CmdEvaluator } = {
if (
next &&
!(isInstr(next) && next.instrType === InstrType.ENVIRONMENT) &&
control.some(isNode)
!control.isEmpty()
) {
control.push(instr.envInstr(currentEnvironment(context), command.srcNode))
}
Expand Down

0 comments on commit 9f82165

Please sign in to comment.