WaitAnalysis
Package: Libraries.Language.Compile.Translate · Inherits from: Libraries.Language.Object
Works out which of a program's actions can wait (Action:CanWait), and reports the places that can't wait. Waiting comes from multitasking (Libraries.Multitasking): a task's actions and the lines that run them. An action that waits needs every caller to wait for it too, all the way up. How depends on the target: in JavaScript, and in Python mode, such actions are written async and every call to them is awaited; on Java the calling thread blocks, so nothing changes. The code writers read what it works out (Libraries.Language.Compile.Translate.ActionOpcode and Libraries.Language.Compile.Translate.ChainedActionCallOpcode read Action:CanWait). It works in three steps. 1. It marks the multitasking library's actions (MarkLibraryActions): - The actions that wait: Libraries.Multitasking.Task's Wait and Pause; Libraries.Multitasking.Lines' Wait, WaitForAny and Pause; Libraries.Multitasking.Line's Wait; and Libraries.Multitasking.Key's ReturnAndWait. Wait, WaitForAny and ReturnAndWait come with and without a time limit; Pause always has one. - Libraries.Multitasking.Task's Run and Then. The multitasking library calls a task's Run, waits for it, then calls Then and waits for that, so a task's overrides of them may wait (Action:OverrideMayWait), and a call to either is awaited. 2. It marks the program's actions that can wait: an action that calls one that can wait, an action that a subclass overrides with one that can wait (a call through the parent's type may reach the override), and an action that overrides one that can wait (in Python every call to the parent's action is awaited, so the override must be async too). This needs every action's calls, so it runs after the listener has gone through the whole program, and before any code is written. It walks outward from the actions that wait, so each action and each call is handled once. 3. It reports the places that can't wait: - making an object: on create, and fields' starting values (a JavaScript constructor can't be async); - an override of a library action that the library calls without waiting (Action:OverrideMayWait is false), such as Compare. The standard library's own actions can wait too, when they call one that can wait: for example, Libraries.Robots.Spike.Motor's RunForTime waits for a task (Task:Wait) while the motor turns. MarkLibrary marks them once, when the library is scanned (Libraries.Language.Compile.Library's Scan), before the library or any program is written, with steps 1 and 2 over the whole library. A library action can only call library actions, so what it marks doesn't depend on any program; the flags stay set on the library's Action objects, which every compile shares, and Mark reads them like any other. All of this is kept on the actions themselves, set in this one sweep before any code is written, so the writers only read it.
Actions
Mark(Libraries.Containers.Array<Libraries.Language.Compile.Translate.ClassOpcode> classOpcodes, Libraries.Language.Compile.Symbol.SymbolTable table, Libraries.Language.Compile.CompilerErrorManager errors)
This action marks which of a program's actions can wait, then reports the places that wait where they can't, in the three steps the class describes. It runs once per compile, after the listener has gone through every class and before any code is written. A program's flags are cleared first, because symbols can outlive a compile: Quorum Studio starts each build from the last one's symbol table, so an action that waited before an edit might not now.
Parameters
classOpcodesLibraries.Containers.Array<Libraries.Language.Compile.Translate.ClassOpcode>: The program's classes.tableLibraries.Language.Compile.Symbol.SymbolTable: The compile's symbol table, which also holds the standard library's classes.errorsLibraries.Language.Compile.CompilerErrorManager: Where errors are reported.
Returns
boolean: false if it reported an error, so no code should be written, and true otherwise.
MarkLibrary(Libraries.Language.Compile.Symbol.SymbolTable table)
This action marks which of the standard library's actions can wait, with steps 1 and 2 over the whole library (see the class's description). It runs once, when the library is scanned (Libraries.Language.Compile.Library's Scan), after the listener has gone through every library class and before anything is written. Nothing is reported: the library's code is written to wait only where it can.
Parameters
tableLibraries.Language.Compile.Symbol.SymbolTable: The library's symbol table.