Skip to content

Commit

Permalink
Remove special cases for environment instruction generator (#1577)
Browse files Browse the repository at this point in the history
* Force all blocks and applications to return to program environment regardless of case

* Narrow down removal of cases to only final statement case

---------

Co-authored-by: Martin Henz <[email protected]>
  • Loading branch information
Kyriel Abad and martin-henz authored Mar 9, 2024
1 parent 733b25d commit c97c2ba
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/cse-machine/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,13 @@ const cmdEvaluators: { [type: string]: CmdEvaluator } = {
}
// Normal block statement: do environment setup
// To restore environment after block ends
// If there is an env instruction on top of the stack, or if there are no declarations, or there is no next control item
// If there is an env instruction on top of the stack, or if there are no declarations
// we do not need to push another one
// The no declarations case is handled by Control :: simplifyBlocksWithoutDeclarations, so no blockStatement node
// without declarations should end up here.
const next = control.peek()
// Push ENVIRONMENT instruction if needed
if (next && !(isInstr(next) && next.instrType === InstrType.ENVIRONMENT)) {
if (!next || !(isInstr(next) && next.instrType === InstrType.ENVIRONMENT)) {
control.push(instr.envInstr(currentEnvironment(context), command))
}

Expand Down Expand Up @@ -941,11 +941,11 @@ const cmdEvaluators: { [type: string]: CmdEvaluator } = {

const next = control.peek()

// Push ENVIRONMENT instruction if needed
// Push ENVIRONMENT instruction if needed - if next instruction
// is empty or not an environment instruction
if (
next &&
!(isInstr(next) && next.instrType === InstrType.ENVIRONMENT) &&
!control.isEmpty()
!next ||
(!(isInstr(next) && next.instrType === InstrType.ENVIRONMENT) && !control.isEmpty())
) {
control.push(instr.envInstr(currentEnvironment(context), command.srcNode))
}
Expand Down

0 comments on commit c97c2ba

Please sign in to comment.