Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions static/js/languages/microscript/v2/runner.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ class @Thread
@paused = false
@terminated = false
@next_calls = []
@call_cache = new Map()
@interface =
pause: ()=>@pause()
resume: ()=>@resume()
Expand All @@ -272,11 +273,16 @@ class @Thread
if f instanceof Routine
@processor.load f
else
parser = new Parser(f,"")
parser.parse()
program = parser.program
compiler = new Compiler(program)
@processor.load compiler.routine
cached = @call_cache.get(f)
if cached?
@processor.load cached
else
parser = new Parser(f,"")
parser.parse()
program = parser.program
compiler = new Compiler(program)
@call_cache.set f, compiler.routine
@processor.load compiler.routine
if (f == "update()" or f == "serverUpdate()") and @runner.updateControls?
@runner.updateControls()
true
Expand Down
19 changes: 13 additions & 6 deletions static/js/languages/microscript/v2/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ this.Thread = class Thread {
this.paused = false;
this.terminated = false;
this.next_calls = [];
this.call_cache = new Map();
this.interface = {
pause: () => {
return this.pause();
Expand All @@ -335,17 +336,23 @@ this.Thread = class Thread {
}

loadNext() {
var compiler, f, parser, program;
var cached, compiler, f, parser, program;
if (this.next_calls.length > 0) {
f = this.next_calls.splice(0, 1)[0];
if (f instanceof Routine) {
this.processor.load(f);
} else {
parser = new Parser(f, "");
parser.parse();
program = parser.program;
compiler = new Compiler(program);
this.processor.load(compiler.routine);
cached = this.call_cache.get(f);
if (cached != null) {
this.processor.load(cached);
} else {
parser = new Parser(f, "");
parser.parse();
program = parser.program;
compiler = new Compiler(program);
this.call_cache.set(f, compiler.routine);
this.processor.load(compiler.routine);
}
if ((f === "update()" || f === "serverUpdate()") && (this.runner.updateControls != null)) {
this.runner.updateControls();
}
Expand Down