File tree Expand file tree Collapse file tree 2 files changed +17
-8
lines changed
Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change 22// https://github.com/source-academy/conductor
33// Original author(s): Source Academy Team
44
5- import { runInContext } from "../../../" ;
5+ import { PyRunInContext } from "../../../" ;
66import { Context } from "../../../cse-machine/context" ;
77import { BasicEvaluator } from "../BasicEvaluator" ;
88import { IRunnerPlugin } from "./IRunnerPlugin" ;
99import { IOptions } from "../../../" ;
10- import { Finished } from "../../../types" ;
1110
1211const defaultContext = new Context ( ) ;
1312const 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 }
Original file line number Diff line number Diff 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);
229237export * from "./errors" ;
230238import * as fs from "fs" ;
231239
232-
233240if ( 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);
You can’t perform that action at this time.
0 commit comments