import { RuntimeConstruct } from "../core/constructs/CPPConstruct"; import { Project } from "../core/Project"; import { Simulation } from "../core/runtime/Simulation"; import { AsynchronousSimulationRunner } from "../core/runtime/simulationRunners"; import { MessageResponses, listenTo, stopListeningTo, messageResponse, Message } from "../util/observe"; import { assert, Mutable } from "../util/util"; import { CheckpointsOutlet } from "./CheckpointOutlets"; import { ProjectEditor, CompilationOutlet, CompilationStatusOutlet } from "./editors"; import { SimulationOutlet } from "./simOutlets"; import { MemoryOutlet } from "./memory/MemoryOutlet"; export class InstantMemoryDiagramOutlet { public readonly project: Project; public readonly isActive: boolean; private readonly memoryOutlet: MemoryOutlet; private readonly element: JQuery; public _act!: MessageResponses; public constructor(element: JQuery, project: Project, isActive: boolean) { this.element = element; this.isActive = isActive; this.memoryOutlet = new MemoryOutlet(element); this.project = project; listenTo(this, project); } public setActive(isActive: boolean) { (>this).isActive = isActive; this.updateMemory(); } public setProject(project: Project) { if (this.project) { stopListeningTo(this, this.project); } (>this).project = project; listenTo(this, this.project); this.updateMemory(); } private async updateMemory() { let program = this.project.program; if (!this.isActive){ this.memoryOutlet.clearMemory(); return; } if (!program.isRunnable()) { return; } let sim = new Simulation(program); this.memoryOutlet.setMemory(sim.memory); let simRunner = new AsynchronousSimulationRunner(sim); await simRunner.stepToEndOfMain(0, 1000); this.element.find(".code-memoryObject .set").removeClass("set"); } @messageResponse("compilationFinished") public onCompilationFinished() { this.updateMemory(); } }