Skip to content

Commit 75e7548

Browse files
committed
Edited runner path from index.ts to Conductor (Refs #51)[5]
* super small commit haha * conductor/runner/types/PyEvaluator.ts - Updated with PyRunInContext, no change to the rest * index.ts - Introduced PyRunInContext that is replacement for runInContext * a small reminder: frigging initialise the PyEvaluator (UNCOMMENT) for local testingssssss
1 parent ed3529c commit 75e7548

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/conductor/runner/types/PyEvaluator.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
// https://github.com/source-academy/conductor
33
// Original author(s): Source Academy Team
44

5-
import { runInContext } from "../../../";
5+
import { PyRunInContext } from "../../../";
66
import { Context } from "../../../cse-machine/context";
77
import { BasicEvaluator } from "../BasicEvaluator";
88
import { IRunnerPlugin } from "./IRunnerPlugin";
99
import { IOptions } from "../../../";
10-
import { Finished } from "../../../types";
1110

1211
const defaultContext = new Context();
1312
const defaultOptions: IOptions = {
@@ -28,12 +27,14 @@ export class PyEvaluator extends BasicEvaluator {
2827

2928
async evaluateChunk(chunk: string): Promise<void> {
3029
try {
31-
const result = await runInContext(
30+
const result = await PyRunInContext(
3231
chunk, // Code
3332
this.context,
3433
this.options
3534
);
36-
this.conductor.sendOutput(`${(result as Finished).representation.toString((result as Finished).value)}`);
35+
if ('status' in result && result.status === 'finished') {
36+
this.conductor.sendOutput(`${result.representation.toString(result.value)}`);
37+
}
3738
} catch (error) {
3839
this.conductor.sendOutput(`Error: ${error instanceof Error ? error.message : error}`);
3940
}

src/index.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,21 +215,28 @@ export async function runPyAST(
215215
code: string,
216216
context: Context,
217217
options: RecursivePartial<IOptions> = {}
218-
): Promise<Result> {
218+
): Promise<Stmt> {
219219
const script = code + "\n";
220220
const tokenizer = new Tokenizer(script);
221221
const tokens = tokenizer.scanEverything();
222222
const pyParser = new Parser(script, tokens);
223223
const ast = pyParser.parse();
224+
return ast;
225+
};
226+
227+
export async function PyRunInContext(
228+
code: string,
229+
context: Context,
230+
options: RecursivePartial<IOptions> = {}
231+
): Promise<Result> {
232+
const ast = await runPyAST(code, context, options);
224233
const result = PyRunCSEMachine(code, ast, context, options);
225234
return result;
226-
};
235+
}
227236

228-
// const {runnerPlugin, conduit} = initialise(PyEvaluator);
229237
export * from "./errors";
230238
import * as fs from "fs";
231239

232-
233240
if (require.main === module) {
234241
(async () => {
235242
if (process.argv.length < 3) {
@@ -258,3 +265,4 @@ if (require.main === module) {
258265

259266
})();
260267
}
268+
// const {runnerPlugin, conduit} = initialise(PyEvaluator);

0 commit comments

Comments
 (0)