Skip to content

Commit

Permalink
CSE Machine: Give prelude environments a separate name (#1596)
Browse files Browse the repository at this point in the history
* fix prog env creation p2

* Update src/cse-machine/utils.ts

Shorten code

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

* fix-format

---------

Co-authored-by: Richard Dominick <[email protected]>
  • Loading branch information
NhatMinh0208 and RichDom2185 authored Mar 22, 2024
1 parent c4fc20d commit 650f30d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/cse-machine/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
checkStackOverFlow,
createBlockEnvironment,
createEnvironment,
createProgramEnvironment,
currentEnvironment,
declareFunctionsAndVariables,
declareIdentifier,
Expand Down Expand Up @@ -389,7 +390,7 @@ const cmdEvaluators: { [type: string]: CmdEvaluator } = {
) {
// Create and push the environment only if it is non empty.
if (hasDeclarations(command) || hasImportDeclarations(command)) {
const environment = createBlockEnvironment(context, 'programEnvironment')
const environment = createProgramEnvironment(context, isPrelude)
pushEnvironment(context, environment)
evaluateImports(command as unknown as es.Program, context, {
wrapSourceModules: true,
Expand Down
13 changes: 13 additions & 0 deletions src/cse-machine/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,19 @@ export const createBlockEnvironment = (
}
}

export const createProgramEnvironment = (
context: Context,
isPrelude: boolean,
head: Frame = {}
): Environment => {
return {
name: isPrelude ? 'prelude' : 'programEnvironment',
tail: currentEnvironment(context),
head,
id: uniqueId()
}
}

/**
* Variables
*/
Expand Down

0 comments on commit 650f30d

Please sign in to comment.