Skip to content

Commit 8d218e9

Browse files
committed
Fix problems with exit(); replace program references with names
1 parent 07b6281 commit 8d218e9

File tree

11 files changed

+130
-100
lines changed

11 files changed

+130
-100
lines changed

codex/easycoder/plugins/browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ const EasyCoder_Browser = {
393393
if (command.parent === `body`) {
394394
parent = document.body;
395395
} else {
396-
const p = command.imported ? program.parent : program;
396+
const p = command.imported ? EasyCoder.scripts[program.parent] : program;
397397
const parentRecord = p.getSymbolRecord(command.parent);
398398
if (!parentRecord.element[parentRecord.index]) {
399399
program.runtimeError(command.pc, `Element ${parentRecord.name} does not exist.`);

easycoder/easycoder-min.js

Lines changed: 42 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

easycoder/easycoder.js

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ const EasyCoder_Core = {
667667
run: program => {
668668
const command = program[program.pc];
669669
const moduleRecord = program.getSymbolRecord(command.module);
670-
const p = moduleRecord.program;
670+
const p = EasyCoder.scripts[moduleRecord.program];
671671
p.run(p.onClose);
672672
return command.pc + 1;
673673
}
@@ -959,8 +959,6 @@ const EasyCoder_Core = {
959959
},
960960

961961
run: program => {
962-
program.parent.run(program.parent.nextPc);
963-
program.parent.nextPc = 0;
964962
program.exit();
965963
return 0;
966964
}
@@ -1176,7 +1174,7 @@ const EasyCoder_Core = {
11761174
newRecord.extra = symbolRecord.extra;
11771175
newRecord.isValueHolder = symbolRecord.isValueHolder;
11781176
if (symbolRecord.program) {
1179-
newRecord.program = symbolRecord.program;
1177+
newRecord.program = symbolRecord.program.script;
11801178
}
11811179
newRecord.imported = true;
11821180
if (!compiler.tokenIs(`and`)) {
@@ -1289,8 +1287,7 @@ const EasyCoder_Core = {
12891287
},
12901288

12911289
run: program => {
1292-
const command = program[program.pc];
1293-
return command.pc + 1;
1290+
return program[program.pc].pc + 1;
12941291
}
12951292
},
12961293

@@ -1650,13 +1647,11 @@ const EasyCoder_Core = {
16501647
compile: compiler => {
16511648
const lino = compiler.getLino();
16521649
const script = compiler.getNextValue();
1653-
let program = compiler.getProgram();
16541650
const imports = [];
16551651
if (compiler.tokenIs(`with`)) {
16561652
while (true) {
16571653
if (compiler.nextIsSymbol(true)) {
16581654
const symbolRecord = compiler.getSymbolRecord();
1659-
// symbolRecord.exporter = program.script;
16601655
imports.push(symbolRecord.name);
16611656
compiler.next();
16621657
if (!compiler.tokenIs(`and`)) {
@@ -1669,7 +1664,7 @@ const EasyCoder_Core = {
16691664
if (compiler.tokenIs(`as`)) {
16701665
if (compiler.nextIsSymbol(true)) {
16711666
const moduleRecord = compiler.getSymbolRecord();
1672-
moduleRecord.program = program;
1667+
// moduleRecord.program = program.script;
16731668
compiler.next();
16741669
if (moduleRecord.keyword !== `module`) {
16751670
throw new Error(`'${moduleRecord.name}' is not a module`);
@@ -1806,9 +1801,9 @@ const EasyCoder_Core = {
18061801
const command = program[program.pc];
18071802
const message = program.getValue(command.message);
18081803
if (command.recipient === `parent`) {
1809-
const parent = program.parent;
1810-
if (parent) {
1811-
const onMessage = program.parent.onMessage;
1804+
if (program.parent) {
1805+
const parent = EasyCoder.scripts[program.parent];
1806+
const onMessage = parent.onMessage;
18121807
if (onMessage) {
18131808
parent.message = message;
18141809
parent.run(parent.onMessage);
@@ -1817,8 +1812,9 @@ const EasyCoder_Core = {
18171812
} else {
18181813
const recipient = program.getSymbolRecord(command.recipient);
18191814
if (recipient.program) {
1820-
recipient.program.message = message;
1821-
recipient.program.run(recipient.program.onMessage);
1815+
let rprog = EasyCoder.scripts[recipient.program];
1816+
rprog.message = message;
1817+
rprog.run(rprog.onMessage);
18221818
}
18231819
}
18241820
return command.pc + 1;
@@ -2027,8 +2023,11 @@ const EasyCoder_Core = {
20272023
}
20282024
break;
20292025
case `setReady`:
2030-
program.parent.run(program.parent.nextPc);
2031-
program.parent.nextPc = 0;
2026+
let parent = EasyCoder.scripts[program.parent];
2027+
if (parent) {
2028+
parent.run(parent.nextPc);
2029+
parent.nextPc = 0;
2030+
}
20322031
break;
20332032
case `setArray`:
20342033
targetRecord = program.getSymbolRecord(command.target);
@@ -2235,7 +2234,7 @@ const EasyCoder_Core = {
22352234
const command = program[program.pc];
22362235
if (command.name) {
22372236
const symbolRecord = program.getSymbolRecord(command.name);
2238-
symbolRecord.program.exit();
2237+
EasyCoder.scripts[symbolRecord.program].exit();
22392238
} else {
22402239
return 0;
22412240
}
@@ -2435,7 +2434,9 @@ const EasyCoder_Core = {
24352434
const command = program[program.pc];
24362435
const value = program.getValue(command.value);
24372436
setTimeout(function () {
2438-
program.run(command.pc + 1);
2437+
if (program.run) {
2438+
program.run(command.pc + 1);
2439+
}
24392440
}, value * command.multiplier);
24402441
return 0;
24412442
}
@@ -3595,7 +3596,7 @@ const EasyCoder = {
35953596
imports.caller = program.script;
35963597
const moduleRecord = command.module ? program.getSymbolRecord(command.module) : null;
35973598
try {
3598-
EasyCoder.tokeniseAndCompile(script.split(`\n`), imports, moduleRecord, this, command.then);
3599+
EasyCoder.tokeniseAndCompile(script.split(`\n`), imports, moduleRecord, this.script, command.then);
35993600
} catch (err) {
36003601
EasyCoder.reportError(err, program, program.source);
36013602
if (program.onError) {
@@ -3666,7 +3667,7 @@ const EasyCoder = {
36663667
program.module = module;
36673668
program.parent = parent;
36683669
if (module) {
3669-
module.program = program;
3670+
module.program = program.script;
36703671
}
36713672
return program;
36723673
},
@@ -3749,7 +3750,11 @@ const EasyCoder = {
37493750
}
37503751
}
37513752
if (program) {
3752-
program.onExit = then;
3753+
EasyCoder.scripts[program.script] = program;
3754+
if (module) {
3755+
module.program = program.script;
3756+
}
3757+
program.afterExit = then;
37533758
program.running = true;
37543759
EasyCoder_Run.run(program, 0);
37553760
}
@@ -4028,11 +4033,19 @@ const EasyCoder_Run = {
40284033

40294034
exit: (program) => {
40304035
if (program.onExit) {
4031-
delete EasyCoder.scripts[program.script];
4032-
program.parent.run(program.onExit);
4033-
program.module.program = null;
4034-
program.running = false;
4035-
program = null;
4036+
program.run(program.onExit);
4037+
}
4038+
let parent = program.parent;
4039+
let afterExit = program.afterExit;
4040+
delete EasyCoder.scripts[program.script];
4041+
if (program.module) {
4042+
delete program.module.program;
4043+
}
4044+
Object.keys(program).forEach(function(key) {
4045+
delete program[key];
4046+
});
4047+
if (parent && afterExit) {
4048+
EasyCoder.scripts[parent].run(afterExit);
40364049
}
40374050
}
40384051
};
@@ -4235,7 +4248,7 @@ const EasyCoder_Value = {
42354248
return value;
42364249
}
42374250
};
4238-
EasyCoder.version = `2.5.2`;
4251+
EasyCoder.version = `2.5.4`;
42394252
EasyCoder.timestamp = Date.now();
42404253
console.log(`EasyCoder loaded; waiting for page`);
42414254

easycoder/plugins/browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ const EasyCoder_Browser = {
395395
if (command.parent === `body`) {
396396
parent = document.body;
397397
} else {
398-
const p = command.imported ? program.parent : program;
398+
const p = command.imported ? EasyCoder.scripts[program.parent] : program;
399399
const parentRecord = p.getSymbolRecord(command.parent);
400400
if (!parentRecord.element[parentRecord.index]) {
401401
program.runtimeError(command.pc, `Element ${parentRecord.name} does not exist.`);

js/EasyCoder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
EasyCoder.version = `2.5.2`;
1+
EasyCoder.version = `2.5.4`;
22
EasyCoder.timestamp = Date.now();
33
console.log(`EasyCoder loaded; waiting for page`);
44

js/easycoder/Core.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ const EasyCoder_Core = {
283283
run: program => {
284284
const command = program[program.pc];
285285
const moduleRecord = program.getSymbolRecord(command.module);
286-
const p = moduleRecord.program;
286+
const p = EasyCoder.scripts[moduleRecord.program];
287287
p.run(p.onClose);
288288
return command.pc + 1;
289289
}
@@ -575,8 +575,6 @@ const EasyCoder_Core = {
575575
},
576576

577577
run: program => {
578-
program.parent.run(program.parent.nextPc);
579-
program.parent.nextPc = 0;
580578
program.exit();
581579
return 0;
582580
}
@@ -792,7 +790,7 @@ const EasyCoder_Core = {
792790
newRecord.extra = symbolRecord.extra;
793791
newRecord.isValueHolder = symbolRecord.isValueHolder;
794792
if (symbolRecord.program) {
795-
newRecord.program = symbolRecord.program;
793+
newRecord.program = symbolRecord.program.script;
796794
}
797795
newRecord.imported = true;
798796
if (!compiler.tokenIs(`and`)) {
@@ -905,8 +903,7 @@ const EasyCoder_Core = {
905903
},
906904

907905
run: program => {
908-
const command = program[program.pc];
909-
return command.pc + 1;
906+
return program[program.pc].pc + 1;
910907
}
911908
},
912909

@@ -1266,13 +1263,11 @@ const EasyCoder_Core = {
12661263
compile: compiler => {
12671264
const lino = compiler.getLino();
12681265
const script = compiler.getNextValue();
1269-
let program = compiler.getProgram();
12701266
const imports = [];
12711267
if (compiler.tokenIs(`with`)) {
12721268
while (true) {
12731269
if (compiler.nextIsSymbol(true)) {
12741270
const symbolRecord = compiler.getSymbolRecord();
1275-
// symbolRecord.exporter = program.script;
12761271
imports.push(symbolRecord.name);
12771272
compiler.next();
12781273
if (!compiler.tokenIs(`and`)) {
@@ -1285,7 +1280,7 @@ const EasyCoder_Core = {
12851280
if (compiler.tokenIs(`as`)) {
12861281
if (compiler.nextIsSymbol(true)) {
12871282
const moduleRecord = compiler.getSymbolRecord();
1288-
moduleRecord.program = program;
1283+
// moduleRecord.program = program.script;
12891284
compiler.next();
12901285
if (moduleRecord.keyword !== `module`) {
12911286
throw new Error(`'${moduleRecord.name}' is not a module`);
@@ -1422,9 +1417,9 @@ const EasyCoder_Core = {
14221417
const command = program[program.pc];
14231418
const message = program.getValue(command.message);
14241419
if (command.recipient === `parent`) {
1425-
const parent = program.parent;
1426-
if (parent) {
1427-
const onMessage = program.parent.onMessage;
1420+
if (program.parent) {
1421+
const parent = EasyCoder.scripts[program.parent];
1422+
const onMessage = parent.onMessage;
14281423
if (onMessage) {
14291424
parent.message = message;
14301425
parent.run(parent.onMessage);
@@ -1433,8 +1428,9 @@ const EasyCoder_Core = {
14331428
} else {
14341429
const recipient = program.getSymbolRecord(command.recipient);
14351430
if (recipient.program) {
1436-
recipient.program.message = message;
1437-
recipient.program.run(recipient.program.onMessage);
1431+
let rprog = EasyCoder.scripts[recipient.program];
1432+
rprog.message = message;
1433+
rprog.run(rprog.onMessage);
14381434
}
14391435
}
14401436
return command.pc + 1;
@@ -1643,8 +1639,11 @@ const EasyCoder_Core = {
16431639
}
16441640
break;
16451641
case `setReady`:
1646-
program.parent.run(program.parent.nextPc);
1647-
program.parent.nextPc = 0;
1642+
let parent = EasyCoder.scripts[program.parent];
1643+
if (parent) {
1644+
parent.run(parent.nextPc);
1645+
parent.nextPc = 0;
1646+
}
16481647
break;
16491648
case `setArray`:
16501649
targetRecord = program.getSymbolRecord(command.target);
@@ -1851,7 +1850,7 @@ const EasyCoder_Core = {
18511850
const command = program[program.pc];
18521851
if (command.name) {
18531852
const symbolRecord = program.getSymbolRecord(command.name);
1854-
symbolRecord.program.exit();
1853+
EasyCoder.scripts[symbolRecord.program].exit();
18551854
} else {
18561855
return 0;
18571856
}
@@ -2051,7 +2050,9 @@ const EasyCoder_Core = {
20512050
const command = program[program.pc];
20522051
const value = program.getValue(command.value);
20532052
setTimeout(function () {
2054-
program.run(command.pc + 1);
2053+
if (program.run) {
2054+
program.run(command.pc + 1);
2055+
}
20552056
}, value * command.multiplier);
20562057
return 0;
20572058
}

js/easycoder/Main.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ const EasyCoder = {
173173
imports.caller = program.script;
174174
const moduleRecord = command.module ? program.getSymbolRecord(command.module) : null;
175175
try {
176-
EasyCoder.tokeniseAndCompile(script.split(`\n`), imports, moduleRecord, this, command.then);
176+
EasyCoder.tokeniseAndCompile(script.split(`\n`), imports, moduleRecord, this.script, command.then);
177177
} catch (err) {
178178
EasyCoder.reportError(err, program, program.source);
179179
if (program.onError) {
@@ -244,7 +244,7 @@ const EasyCoder = {
244244
program.module = module;
245245
program.parent = parent;
246246
if (module) {
247-
module.program = program;
247+
module.program = program.script;
248248
}
249249
return program;
250250
},
@@ -327,7 +327,11 @@ const EasyCoder = {
327327
}
328328
}
329329
if (program) {
330-
program.onExit = then;
330+
EasyCoder.scripts[program.script] = program;
331+
if (module) {
332+
module.program = program.script;
333+
}
334+
program.afterExit = then;
331335
program.running = true;
332336
EasyCoder_Run.run(program, 0);
333337
}

js/easycoder/Run.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,19 @@ const EasyCoder_Run = {
162162

163163
exit: (program) => {
164164
if (program.onExit) {
165-
delete EasyCoder.scripts[program.script];
166-
program.parent.run(program.onExit);
167-
program.module.program = null;
168-
program.running = false;
169-
program = null;
165+
program.run(program.onExit);
166+
}
167+
let parent = program.parent;
168+
let afterExit = program.afterExit;
169+
delete EasyCoder.scripts[program.script];
170+
if (program.module) {
171+
delete program.module.program;
172+
}
173+
Object.keys(program).forEach(function(key) {
174+
delete program[key];
175+
});
176+
if (parent && afterExit) {
177+
EasyCoder.scripts[parent].run(afterExit);
170178
}
171179
}
172180
};

js/plugins/browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ const EasyCoder_Browser = {
395395
if (command.parent === `body`) {
396396
parent = document.body;
397397
} else {
398-
const p = command.imported ? program.parent : program;
398+
const p = command.imported ? EasyCoder.scripts[program.parent] : program;
399399
const parentRecord = p.getSymbolRecord(command.parent);
400400
if (!parentRecord.element[parentRecord.index]) {
401401
program.runtimeError(command.pc, `Element ${parentRecord.name} does not exist.`);

0 commit comments

Comments
 (0)