Skip to content

Commit 8155879

Browse files
committed
resolve all issues with scheme CSE machine
1 parent 9506b82 commit 8155879

File tree

6 files changed

+32
-5
lines changed

6 files changed

+32
-5
lines changed

src/commons/application/ApplicationTypes.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,23 @@ const schemeSubLanguages: Array<Pick<SALanguage, 'chapter' | 'variant' | 'displa
194194
];
195195

196196
export const schemeLanguages: SALanguage[] = schemeSubLanguages.map(sublang => {
197-
return { ...sublang, mainLanguage: SupportedLanguage.SCHEME, supports: { repl: true } };
197+
return {
198+
...sublang,
199+
mainLanguage: SupportedLanguage.SCHEME,
200+
supports: { repl: true, cseMachine: true }
201+
};
198202
});
199203

204+
export function isSchemeLanguage(chapter: Chapter): boolean {
205+
return [
206+
Chapter.SCHEME_1,
207+
Chapter.SCHEME_2,
208+
Chapter.SCHEME_3,
209+
Chapter.SCHEME_4,
210+
Chapter.FULL_SCHEME
211+
].includes(chapter);
212+
}
213+
200214
const pySubLanguages: Array<Pick<SALanguage, 'chapter' | 'variant' | 'displayName'>> = [
201215
{ chapter: Chapter.PYTHON_1, variant: Variant.DEFAULT, displayName: 'Python \xa71' }
202216
//{ chapter: Chapter.PYTHON_2, variant: Variant.DEFAULT, displayName: 'Python \xa72' },

src/commons/mocks/ContextMocks.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ export function mockRuntimeContext(): Context {
3737
control: null,
3838
stash: null,
3939
envStepsTotal: 0,
40-
breakpointSteps: []
40+
breakpointSteps: [],
41+
objectCount: 0,
42+
changepointSteps: []
4143
};
4244
return context;
4345
}

src/commons/sagas/PlaygroundSaga.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
updateShortURL
1313
} from '../../features/playground/PlaygroundActions';
1414
import { GENERATE_LZ_STRING, SHORTEN_URL } from '../../features/playground/PlaygroundTypes';
15-
import { isSourceLanguage, OverallState } from '../application/ApplicationTypes';
15+
import { isSchemeLanguage, isSourceLanguage, OverallState } from '../application/ApplicationTypes';
1616
import { ExternalLibraryName } from '../application/types/ExternalTypes';
1717
import { retrieveFilesInWorkspaceAsRecord } from '../fileSystem/utils';
1818
import { visitSideContent } from '../sideContent/SideContentActions';
@@ -116,6 +116,10 @@ export default function* PlaygroundSaga(): SagaIterator {
116116
yield put(toggleUsingCse(true, workspaceLocation));
117117
}
118118
}
119+
120+
if (isSchemeLanguage(playgroundSourceChapter) && newId === SideContentType.cseMachine) {
121+
yield put(toggleUsingCse(true, workspaceLocation));
122+
}
119123
}
120124
);
121125
}

src/commons/sagas/WorkspaceSaga.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { DeviceSession } from '../../features/remoteExecution/RemoteExecutionTyp
3131
import { WORKSPACE_BASE_PATHS } from '../../pages/fileSystem/createInBrowserFileSystem';
3232
import {
3333
defaultEditorValue,
34+
isSchemeLanguage,
3435
isSourceLanguage,
3536
OverallState,
3637
styliseSublanguage
@@ -1089,7 +1090,11 @@ export function* evalCode(
10891090
.currentStep
10901091
)
10911092
: -1;
1092-
const cseActiveAndCorrectChapter = context.chapter >= 3 && cseIsActive;
1093+
1094+
// TODO: we need to make a function that generalises all languages that depend on using the CSE machine
1095+
const cseActiveAndCorrectChapter =
1096+
(isSchemeLanguage(context.chapter) || context.chapter >= 3) && cseIsActive;
1097+
10931098
if (cseActiveAndCorrectChapter) {
10941099
context.executionMethod = 'cse-machine';
10951100
}

src/features/cseMachine/CseMachineLayout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ export class Layout {
185185
/** remove program environment containing predefined functions */
186186
private static removeProgramEnv() {
187187
if (!Layout.globalEnvNode.children) return;
188+
if (Layout.globalEnvNode.children.length === 0) return;
188189

189190
const programEnvNode = Layout.globalEnvNode.children[0];
190191
const globalEnvNode = Layout.globalEnvNode;

src/features/cseMachine/components/ControlStack.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as es from 'estree';
22
import { Control } from 'js-slang/dist/cse-machine/interpreter';
33
import { ControlItem, Instr } from 'js-slang/dist/cse-machine/types';
4+
import { StatementSequence } from 'js-slang/dist/types';
45
import { KonvaEventObject } from 'konva/lib/Node';
56
import React from 'react';
67
import { Group, Label, Tag, Text } from 'react-konva';
@@ -142,6 +143,6 @@ export const isInstr = (command: ControlItem): command is Instr => {
142143
* @param command A ControlItem
143144
* @returns true if the ControlItem is an esNode and false if it is an instruction.
144145
*/
145-
export const isNode = (command: ControlItem): command is es.Node => {
146+
export const isNode = (command: ControlItem): command is es.Node | StatementSequence => {
146147
return (command as es.Node).type !== undefined;
147148
};

0 commit comments

Comments
 (0)