AvailRuntime

class AvailRuntime(val moduleNameResolver: ModuleNameResolver, fileManager: FileManager)

An AvailRuntime comprises the modules, methods, and special objects that define an Avail system. It also manages global resources, such as file connections.

Author

Todd L Smith

Parameters

moduleNameResolver

The module name resolver that this AvailRuntime should use to resolve unqualified module names.

fileManager

The FileManager of the running Avail.

Constructors

Link copied to clipboard
fun AvailRuntime(moduleNameResolver: ModuleNameResolver, fileManager: FileManager)

Construct a new AvailRuntime.

Types

Link copied to clipboard
object Companion
Link copied to clipboard
data class DiversionQueue(    val interpreterSurplus: Int,     val postponedSafeTasks: ImmutableList<AvailTask>?,     val postponedInterpreterTasks: ImmutableList<AvailTask>?)

An immutable state object that can atomically replace the current state in activeDiversionQueue via a compare-and-set (with retries).

Link copied to clipboard
enum HookType : Enum<AvailRuntime.HookType>

A HookType describes an abstract missing behavior in the virtual machine, where an actual hook will have to be constructed to hold an A_Function within each separate AvailRuntime.

Functions

Link copied to clipboard
fun addModule(module: A_Module)

Add the specified module to the runtime.

Link copied to clipboard
fun addSeal(methodName: A_Atom, sealSignature: A_Tuple)

Add a seal to the method associated with the given method name.

Link copied to clipboard
fun addSemanticRestriction(restriction: A_SemanticRestriction)

Add a semantic restriction to the method associated with the given method name.

Link copied to clipboard
fun allFibers(): Set<A_Fiber>

Answer a Set of all A_Fibers that have not yet retired. Retired fibers will be garbage collected when there are no remaining references.

Link copied to clipboard
fun allocateInterpreterIndex(): Int

Allocate the next interpreter index in [0..maxInterpreters) thread-safely.

Link copied to clipboard
fun assertInSafePoint()

Assert that we're currently inside a safe point. This should only be checked while running a safe point task (good) or an interpreter task (should fail).

Link copied to clipboard
fun awaitNoFibers()

Block the current Thread until there are no fibers that can run. If nothing outside the VM is actively creating and running new fibers, this is a permanent state. After this method returns, there will be no more AvailTasks added to the executor.

Link copied to clipboard
fun callbackSystem(): CallbackSystem

Answer this runtime's CallbackSystem.

Link copied to clipboard
fun compareAndSetFiberCaptureFunction(oldValue: (A_Fiber) -> Unit?, newValue: (A_Fiber) -> Unit?): Boolean

Attempt to write the newValue into the newFiberHandler, but only if it currently contains oldValue. Answer whether it wos successful. If it was not successful due to the oldValue not being the current value, make no change and answer false.

Link copied to clipboard
fun destroy()

Destroy all data structures used by this AvailRuntime. Also disassociate it from the current Thread's local storage.

Link copied to clipboard
fun execute(task: AvailTask)

Schedule the specified task for eventual execution. The implementation is free to run the task immediately or delay its execution arbitrarily. The task is guaranteed to execute on an AvailThread.

fun execute(priority: Int, body: () -> Unit)

Schedule the specified task for eventual execution. The implementation is free to run the task immediately or delay its execution arbitrarily. The task is guaranteed to execute on an Avail thread.

Link copied to clipboard
operator fun get(hookType: AvailRuntime.HookType): A_Function

Extract the current A_Function for the given hook from this runtime.

Link copied to clipboard
fun implicitObserveFunction(): A_Function

Answer the function to invoke whenever a variable with write reactors is written when write tracing is not enabled.

Link copied to clipboard
fun includesModuleNamed(moduleName: A_String): Boolean

Does the runtime define a module with the specified name?

Link copied to clipboard
fun integrityCheck()

Perform an integrity check on the parser data structures. Report the findings to System.out.

Link copied to clipboard
fun invalidMessageSendFunction(): A_Function

Answer the function to invoke whenever a method send fails for a definitional reason.

Link copied to clipboard
fun loadedModules(): A_Map

Answer my current A_Map of A_Modules. It's always Mutability.SHARED for safety.

Link copied to clipboard
fun lookupJavaType(className: A_String, classParameters: A_Tuple): A_Type

Look up the given Java class name, and create a suitable Java POJO A_Type. Capture the classParameters, since the Avail POJO mechanism doesn't erase generics.

Link copied to clipboard
fun lookupRawJavaClass(className: A_String): Class<*>

Look up the given Java class name, and create a suitable Java raw POJO for this raw Java class. The raw class does not capture type parameters.

Link copied to clipboard
fun moduleAt(moduleName: A_String): AvailObject

Answer the module with the specified name.

Link copied to clipboard
fun moduleRoots(): ModuleRoots

Answer the Avail module roots.

Link copied to clipboard
fun registerFiber(fiber: A_Fiber)

Add the specified fiber to this runtime.

Link copied to clipboard
fun removeDefinition(definition: A_Definition)

Unbind the specified definition from the runtime system.

Link copied to clipboard
fun removeGrammaticalRestriction(restriction: A_GrammaticalRestriction)

Remove a grammatical restriction from the method associated with the given method name.

Link copied to clipboard
fun removeMacro(macro: A_Macro)

Unbind the specified macro from the runtime system.

Link copied to clipboard
fun removeSeal(methodName: A_Atom, sealSignature: A_Tuple)

Remove a seal from the method associated with the given method name.

Link copied to clipboard
fun removeTypeRestriction(restriction: A_SemanticRestriction)

Remove a semantic restriction from the method associated with the given method name.

Link copied to clipboard
fun resultDisagreedWithExpectedTypeFunction(): A_Function

Answer the function to invoke whenever the value produced by a method send disagrees with the type expected.

Link copied to clipboard
fun resumeFromFailedPrimitive(    aFiber: A_Fiber,     failureValue: A_BasicObject,     failureFunction: A_Function,     args: List<AvailObject>)

Schedule resumption of the specified fiber following suspension by a failedprimitive. This method is an entry point.

Link copied to clipboard
fun resumeFromInterrupt(aFiber: A_Fiber)

Schedule resumption of the specified fiber following suspension due to an interrupt. This method is an entry point.

Link copied to clipboard
fun resumeFromSuccessfulPrimitive(    aFiber: A_Fiber,     resumingPrimitive: Primitive,     result: A_BasicObject)

Schedule resumption of the specified fiber following suspension by a successfulprimitive. This method is an entry point.

Link copied to clipboard
fun resumeIfPausedByDebugger(aFiber: A_Fiber)

If the fiber was PAUSED by a debugger, transition it immediately into the UNPAUSING state, and cause an AvailTask to be queued and eventually executed to resume running it.

Link copied to clipboard
fun runOutermostFunction(    aFiber: A_Fiber,     functionToRun: A_Function,     arguments: List<A_BasicObject>)

Schedule the specified fiber to run the given function. This function is invoked via the HookType.BASE_FRAME hook. The fiber must be in the unstarted state. This Kotlin method is an entry point for driving Avail externally.

Link copied to clipboard
operator fun set(hookType: AvailRuntime.HookType, function: A_Function)

Set the given hook's function for this runtime.

Link copied to clipboard
fun setTextInterface(textInterface: TextInterface)

Set the runtime's default text interface.

Link copied to clipboard
fun stringifyThen(    values: List<A_BasicObject>,     textInterface: TextInterface = this.textInterface,     continuation: (List<String>) -> Unit)

Stringify a list of Avail, using the HookType.STRINGIFICATION hook associated with the specified runtime. Stringification will run in parallel, with each value being processed by its own new fiber. If stringification fails for a value for any reason, then the built-in mechanism, available via AvailObject.toString will be used for that value. Invoke the specified continuation with the resulting list, preserving the original order.

fun stringifyThen(    value: A_BasicObject,     textInterface: TextInterface = this.textInterface,     setup: A_Fiber.() -> Unit = { },     continuation: (String) -> Unit)

Stringify an AvailObject, using the HookType.STRINGIFICATION hook in the specified AvailRuntime. Stringification will run in a new fiber. If stringification fails for any reason, then the built-in mechanism, available via AvailObject.toString will be used. Invoke the specified continuation with the result.

Link copied to clipboard
fun textInterface(): TextInterface

Answer the runtime's default text interface.

Link copied to clipboard
fun unassignedVariableReadFunction(): A_Function

Answer the function to invoke whenever an unassigned variable is read.

Link copied to clipboard
fun unlinkModule(module: A_Module)

Remove the specified module from this runtime. The module's code should already have been removed via A_Module.removeFrom.

Link copied to clipboard
fun unregisterFiber(fiber: A_Fiber)

Remove the specified fiber from this runtime. This should be done explicitly when a fiber retires, although the fact that allFibers wraps a WeakHashMap ensures that fibers that are no longer referenced will still be cleaned up at some point.

Link copied to clipboard
fun whenRunningInterpretersDo(priority: Int, action: () -> Unit)

Request that the specified action be executed when interpreter tasks are allowed to run. If there are any postponed safe-point tasks, that means we're either in or waiting for a safe-point to be reached, so don't start another interpreter task – queue it instead.

Link copied to clipboard
fun whenSafePointDo(priority: Int, safeAction: () -> Unit)

Request that the specified action be executed at the next safe-point. No interpreter tasks are running at a safe-point.

Properties

Link copied to clipboard
var breakpointHandler: (A_Fiber) -> Unit

A call-out to allow tools like debuggers to intercept breakpoints. Only one breakpoint handler can be active for this runtime. The function will be invoked from within a safe point.

Link copied to clipboard
val classLoader: ClassLoader

The class loader that should be used to locate and load Java classes.

Link copied to clipboard
val clock: AvailRuntimeSupport.Clock

The number of clock ticks since this runtime was created.

Link copied to clipboard
val executor: ThreadPoolExecutor

The ThreadPoolExecutor for running tasks and fibers of this AvailRuntime.

Link copied to clipboard
val hooks: EnumMap<AvailRuntime.HookType, AtomicReference<A_Function>>

The collection of hooks for this runtime.

Link copied to clipboard
val ioSystem: IOSystem

The IOSystem for this runtime.

Link copied to clipboard
val moduleNameResolver: ModuleNameResolver

The module name resolver that this runtime should use to resolve unqualified module names.

Link copied to clipboard
val newFiberHandler: AtomicReference<(A_Fiber) -> Unit?>

A call-out invoked when a new fiber is created and scheduled for the first time. This mechanism is used to capture new fibers in a debugger's list of fibers.

Link copied to clipboard
val runtimeLock: ReentrantReadWriteLock

The lock that protects the runtime data structures against dangerous concurrent access.

Link copied to clipboard
val safePointRequested: Boolean

Determine whether any safe-point tasks have been queued for later.

Link copied to clipboard
val timer: Timer

The timer that managed scheduled tasks for this runtime. The timer thread is not an Avail thread, and therefore cannot directly execute fibers. It may, however, schedule fiber-related tasks.