CompilationContext

class CompilationContext(    val moduleHeader: ModuleHeader?,     val module: A_Module,     source: A_String,     val textInterface: TextInterface,     pollForAbort: () -> Boolean,     val progressReporter: CompilerProgressReporter,     problemHandler: ProblemHandler)

A CompilationContext lasts for a module's entire compilation activity.

Author

Mark van Gulik

Parameters

moduleHeader

The module header of the module to compile. May be null for synthetic modules (for entry points), or when parsing the header.

module

The current module.`

source

The source A_String.

textInterface

The text interface for any fibers started by this compiler.

pollForAbort

How to quickly check if the client wants to abort compilation.

progressReporter

How to report progress to the client who instigated compilation. This continuation that accepts the name of the module undergoing compilation, the line number on which the last complete statement concluded, the position of the ongoing parse (in bytes), and the size of the module (in bytes).

problemHandler

The ProblemHandler used for reporting compilation problems.

Constructors

Link copied to clipboard
fun CompilationContext(    moduleHeader: ModuleHeader?,     module: A_Module,     source: A_String,     textInterface: TextInterface,     pollForAbort: () -> Boolean,     progressReporter: CompilerProgressReporter,     problemHandler: ProblemHandler)

Create a CompilationContext for compiling an A_Module.

Types

Link copied to clipboard
object Companion
Link copied to clipboard
sealed class StylingCompletionState

The abstract class for the styling state machine. A statement can be in the process of being styled while the next statement is being parsed, but before that next statement is allowed to executed, the previous styling action must complete. Otherwise, the execution of the next statement might change the stylers that are in effect while the styling of the previous statement is in progress, which is a race.

Functions

Link copied to clipboard
fun beginningStyling()

A styling activity is starting. Note that styling must always be started causally beforewhenNotStyling may be called.

Link copied to clipboard
fun clearStyleCache()

Clear the cache of method -> style function. This can be done either when a new style is added within scope of this module, or just before styling a top-level statement.

Link copied to clipboard
fun evaluatePhraseThen(    expressionNode: A_Phrase,     lexingState: LexingState,     shouldSerialize: Boolean,     trackTasks: Boolean,     onSuccess: (AvailObject) -> Unit,     onFailure: (Throwable) -> Unit)

Generate a function from the specified phrase and evaluate it in the module's context; lexically enclosing variables are not considered in scope, but module variables and constants are in scope.

Link copied to clipboard
fun eventuallyDo(lexingState: LexingState, continuation: () -> Unit)

Attempt the zero-argument continuation. The implementation is free to execute it now or to put it in a bag of continuations to run later in an arbitrary order. There may be performance and/or scale benefits to processing entries in FIFO, LIFO, or some hybrid order, but the correctness is not affected by a choice of order. The implementation may run the expression in parallel with the invoking thread and other such expressions.

Link copied to clipboard
fun finishedStyling()

The current styling activity has completed. If there was a post-styling action set, run it after transitioning to NotStyling.

Link copied to clipboard
fun flushDelayedSerializedEffects()

Flush the delayedSerializedEarlyEffects and delayedSerializedEffects to top-level functions that perform those actions.

Link copied to clipboard
fun getStylerFunction(method: A_Method): A_Function

Given a method, look up stylers visible by the current module, and choose the most specific one, or the conflict styler if there is more than one that is most specific. Answer nil if none are defined and visible to the module.

Link copied to clipboard
fun recordToken(token: A_Token)

Record the fact that this token was encountered while parsing the current top-level statement.

Link copied to clipboard
fun startWorkUnits(countToBeQueued: Int)

Start N work units, which are about to be queued.

Link copied to clipboard
fun styleSendThen(    originalSendPhrase: A_Phrase?,     transformedPhrase: A_Phrase,     then: () -> Unit)

Apply the style for a single method send phrase, without considering its subphrases.

Link copied to clipboard
fun visitAll(    phrases: Collection<A_Phrase>,     visitedSet: MutableSet<A_Phrase>,     then: () -> Unit)

Process all of the phrase's subphrases recursively, then style the phrase itself, then invoke the given action.

Link copied to clipboard
fun whenNotStyling(action: () -> Unit)

A styling action might still be running. If it is, ensure the action is executed after the styling completes. If it was not styling, run the action immediately.

Link copied to clipboard
fun <ArgType> workUnitCompletion(    lexingState: LexingState,     optionalSafetyCheck: AtomicBoolean?,     continuation: (ArgType) -> Unit): (ArgType) -> Unit

Construct and answer a function that wraps the specified continuation in logic that will increment the count of completed work units and potentially call the unambiguous statement.

Link copied to clipboard
fun <ArgType> workUnitsDo(    lexingState: LexingState,     continuations: List<(ArgType) -> Unit>,     argument: ArgType)

Eventually execute the specified List of functions as compiler work units. Note that the queued work unit count must be increased by the full amount up-front to ensure the completion of the first N tasks before the N+1st can be queued doesn't trigger execution of noMoreWorkUnits. Each continuation will be passed the same given argument.

Properties

Link copied to clipboard
val diagnostics: CompilerDiagnostics

The CompilerDiagnostics that tracks potential errors during compilation.

Link copied to clipboard
val loader: AvailLoader

The loader created and operated by this compiler to facilitate the loading of modules.

Link copied to clipboard
val module: A_Module

The Avail module undergoing compilation.

Link copied to clipboard
val moduleHeader: ModuleHeader?

The header information for the current module being parsed.

Link copied to clipboard
var noMoreWorkUnits: () -> Unit? = null

What to do when there are no more work units.

Link copied to clipboard
val progressReporter: CompilerProgressReporter

The CompilerProgressReporter that reports compilation progress at various checkpoints. It accepts the name of the module undergoing compilation, the line number on which the last complete statement concluded, the position of the ongoing parse (in bytes), and the size of the module (in bytes).

Link copied to clipboard
val runtime: AvailRuntime

The AvailRuntime for the compiler. Since a compiler cannot migrate between two runtime environments, it is safe to cache it for efficient access.

Link copied to clipboard
val serializerOutputStream: IndexedFile.ByteArrayOutputStream

The output stream on which the serializer writes.

Link copied to clipboard

A tool for converting character positions between Avail's Unicode strings and Java/Kotlin's UTF-16 representation.

Link copied to clipboard
val textInterface: TextInterface

The text interface for any fibers started by this compiler.

Link copied to clipboard
val workUnitsCompleted: Long

The current number of work units that have been completed.

Link copied to clipboard
val workUnitsQueued: Long

The current number of work units that have been queued.