P_MarkGuardVariable

Primitive: Mark a primitive failure variable from a nearby invocation of P_CatchException. The three states are (1) unmarked and running the body, (2) handling an exception, and (3) running the final ensure clause. If the current state is 1, it can be marked as either 2 or 3. If the state is 2, it can be marked as 3. No other transitions are allowed.

Author

Todd L Smith

Mark van Gulik

Properties

Link copied to clipboard

The number of arguments the primitive expects. The value -1 is used by the special primitive P_PushConstant to indicate it may have any number of arguments. However, note that that primitive cannot be used explicitly in Avail code.

Link copied to clipboard

A type to constrain the A_Type.writeType of the variable declaration within the primitive declaration of a block. The actual variable's inner type must be this or a supertype.

Link copied to clipboard

Capture the name of the primitive class once for performance.

Link copied to clipboard

The Statistic for abandoning the stack due to a primitive attempt answering Result.CONTINUATION_CHANGED.

Link copied to clipboard

The Statistic for reification prior to invoking a primitive that does not have Flag.CanInline set.

Link copied to clipboard

Capture the simpleName of the primitive class once for performance.

Functions

Link copied to clipboard
fun addNanosecondsCheckingResultType(deltaNanoseconds: Long, interpreterIndex: Int)

Record that some number of nanoseconds were just expended checking the type of the value returned by this primitive.

Link copied to clipboard
fun addNanosecondsRunning(deltaNanoseconds: Long, interpreterIndex: Int)

Record that some number of nanoseconds were just expended running this primitive.

Link copied to clipboard
open override fun attempt(interpreter: Interpreter): Primitive.Result

Attempt this primitive with the given Interpreter. The interpreter's argument list must be set up prior to this call. If the primitive fails, it should set the primitive failure code by calling Interpreter.primitiveFailure and returning its result from the primitive. Otherwise it should set the interpreter's primitive result by calling Interpreter.primitiveSuccess and then return its result from the primitive. For unusual primitives that replace the current continuation, Result.CONTINUATION_CHANGED is more appropriate, and the latestResult need not be set. For primitives that need to cause a context switch, Result.FIBER_SUSPENDED should be returned.

Link copied to clipboard
open fun attemptToGenerateSimpleInvocation(simpleTranslator: L2SimpleTranslator, functionIfKnown: A_Function?, rawFunction: A_RawFunction, argRestrictions: List<TypeRestriction>, expectedType: A_Type): TypeRestriction?

Attempt to generate a simplified, faster invocation of the given constant function, with the given argument restrictions. The arguments will be on the stack, the last-pushed one at stackp. If this code generation attempt is successful, code will be generated to invoke the given function, and if it completes without reification, to check the return result if it's not already guaranteed correct. Note that the call and the return type check can't be in separate instructions, since there's nowhere to store the unchecked return value to compare it against the expected type. We can't just clobber the expected type (that was pushed at the start of the call), since that would

Link copied to clipboard

Return a function type that restricts actual primitive blocks defined using that primitive. The actual block's argument types must be at least as specific as this function type's argument types, and the actual block's return type must be at least as general as this function type's return type. That's equivalent to the condition that the actual block's type is a subtype of this function type.

Link copied to clipboard

To simplify styling during bootstrapping, a method defined by the pragma mechanism can have its primitive declare a styler primitive to plug in as that method definition's styler.

Link copied to clipboard

Answer whether a raw function using this primitive can/should have nybblecode instructions.

Link copied to clipboard

Answer the fallibility of the primitive for a call site with the given argument types.

Link copied to clipboard
fun generateJvmCode(translator: JVMTranslator, method: MethodVisitor, arguments: L2ReadBoxedVectorOperand, result: L2WriteBoxedOperand)

Write a JVM invocation of this primitive. This sets up the interpreter, calls Interpreter.beforeAttemptPrimitive, calls Primitive.attempt, calls Interpreter.afterAttemptPrimitive, and records statistics as needed. It also deals with primitive failures, suspensions, and reifications.

Link copied to clipboard

Test whether the specified Flag is set for this primitive.

Link copied to clipboard
open fun returnTypeGuaranteedByVM(rawFunction: A_RawFunction, argumentTypes: List<A_Type>): A_Type

Answer the type of the result that will be produced by a call site with the given argument types. Don't include semantic restrictions defined in the Avail code, but if convenient answer something stronger than the return type in the primitive's basic function type.

Link copied to clipboard
fun tryToGenerateGeneralPrimitiveInvocation(rawFunction: A_RawFunction, arguments: List<L2ReadBoxedOperand>, argumentTypes: List<A_Type>, translator: L1Translator, callSiteHelper: L1Translator.CallSiteHelper): Boolean

The primitive couldn't be folded out, and the primitive failed to produce specialized L2 instructions for itself. If the primitive is still known to be infallible (and does not affect the continuation stack) at this site, generate an L2_RUN_INFALLIBLE_PRIMITIVE for it and answer true, ensuring control flow will go to the appropriate CallSiteHelper exit point, and leave the translator NOT at a currentReachable() point.

Link copied to clipboard
open fun tryToGenerateSpecialPrimitiveInvocation(functionToCallReg: L2ReadBoxedOperand, rawFunction: A_RawFunction, arguments: List<L2ReadBoxedOperand>, argumentTypes: List<A_Type>, translator: L1Translator, callSiteHelper: L1Translator.CallSiteHelper): Boolean

The primitive couldn't be folded out, so see if alternative instructions can be generated for its invocation. If so, answer true, ensure control flow will go to the appropriate CallSiteHelper exit point, and leave the translator NOT at a currentReachable() point. If the alternative instructions could not be generated for this primitive, answer false, and generate nothing.

Link copied to clipboard
open fun writeDefaultFailureCode(lineNumber: Int, writer: L1InstructionWriter, numArgs: Int)

Generate suitable primitive failure code on the given L1InstructionWriter. Some primitives may have special requirements, but most (fallible) primitives follow the same pattern.