Skip to content

Commit b24a873

Browse files
committed
Correctly set canSuspend when compiling
1 parent 807661a commit b24a873

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/compile.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ Sk.gensymcount = 0;
88
* @param {string} filename
99
* @param {SymbolTable} st
1010
* @param {number} flags
11+
* @param {boolean=} canSuspend whether compiled code can suspend
1112
* @param {string=} sourceCodeForAnnotation used to add original source to listing if desired
1213
*/
13-
function Compiler (filename, st, flags, sourceCodeForAnnotation) {
14+
function Compiler (filename, st, flags, canSuspend, sourceCodeForAnnotation) {
1415
this.filename = filename;
1516
this.st = st;
1617
this.flags = flags;
18+
this.canSuspend = canSuspend;
1719
this.interactive = false;
1820
this.nestlevel = 0;
1921

@@ -1430,7 +1432,7 @@ Compiler.prototype.buildcodeobj = function (n, coname, decorator_list, args, cal
14301432
//
14311433
// enter the new scope, and create the first block
14321434
//
1433-
scopename = this.enterScope(coname, n, n.lineno, true);
1435+
scopename = this.enterScope(coname, n, n.lineno, this.canSuspend);
14341436

14351437
isGenerator = this.u.ste.generator;
14361438
hasFree = this.u.ste.hasFree;
@@ -2213,7 +2215,7 @@ Compiler.prototype.cprint = function (s) {
22132215
Compiler.prototype.cmod = function (mod) {
22142216
//print("-----");
22152217
//print(Sk.astDump(mod));
2216-
var modf = this.enterScope(new Sk.builtin.str("<module>"), mod, 0, true);
2218+
var modf = this.enterScope(new Sk.builtin.str("<module>"), mod, 0, this.canSuspend);
22172219

22182220
var entryBlock = this.newBlock("module entry");
22192221
this.u.prefixCode = "var " + modf + "=(function($modname){";
@@ -2279,13 +2281,14 @@ Compiler.prototype.cmod = function (mod) {
22792281
* @param {string} source the code
22802282
* @param {string} filename where it came from
22812283
* @param {string} mode one of 'exec', 'eval', or 'single'
2284+
* @param {boolean=} canSuspend if the generated code supports suspension
22822285
*/
2283-
Sk.compile = function (source, filename, mode) {
2286+
Sk.compile = function (source, filename, mode, canSuspend) {
22842287
//print("FILE:", filename);
22852288
var cst = Sk.parse(filename, source);
22862289
var ast = Sk.astFromParse(cst, filename);
22872290
var st = Sk.symboltable(ast, filename);
2288-
var c = new Compiler(filename, st, 0, source); // todo; CO_xxx
2291+
var c = new Compiler(filename, st, 0, canSuspend, source); // todo; CO_xxx
22892292
var funcname = c.cmod(ast);
22902293
var ret = c.result.join("");
22912294
return {

src/import.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Sk.loadExternalLibrary = function (name) {
9696
co = { funcname: "$builtinmodule", code: module };
9797
}
9898
else {
99-
co = Sk.compile(module, path, "exec");
99+
co = Sk.compile(module, path, "exec", true);
100100
}
101101

102102
Sk.externalLibraryCache[name] = co;
@@ -294,7 +294,7 @@ Sk.importModuleInternal_ = function (name, dumpJS, modname, suppliedPyBody, canS
294294

295295
if (suppliedPyBody) {
296296
filename = name + ".py";
297-
co = Sk.compile(suppliedPyBody, filename, "exec");
297+
co = Sk.compile(suppliedPyBody, filename, "exec", canSuspend);
298298
}
299299
else {
300300
// If an onBeforeImport method is supplied, call it and if
@@ -327,7 +327,7 @@ Sk.importModuleInternal_ = function (name, dumpJS, modname, suppliedPyBody, canS
327327
isPy = true;
328328
return compileReadCode(Sk.importSearchPathForName(name, ".py", false, canSuspend));
329329
} else {
330-
return isPy ? Sk.compile(codeAndPath.code, codeAndPath.filename, "exec")
330+
return isPy ? Sk.compile(codeAndPath.code, codeAndPath.filename, "exec", canSuspend)
331331
: { funcname: "$builtinmodule", code: codeAndPath.code };
332332
}
333333
})(codeAndPath);

0 commit comments

Comments
 (0)