Annotation Interface StructuredSleigh.StructuredUserop
- Enclosing class:
StructuredSleigh
This is applied to methods used to generate Sleigh source code. Take note that the method is
only invoked once (for a given library instance) to generate code. Thus, beware of
non-determinism during code generation. For example, implementing something like
rdrnd
in structured Sleigh is rife with peril. Take the following implementation:
@StructuredUserop public void rdrnd() { r0.set(Random.nextLong()); // BAD: Die rolled once at compile time }
The random number will be generated once at structured Sleigh compilation time, and then that
same number used on every invocation of the p-code userop. Instead, this userop should be
implemented using a Java callback, i.e., AnnotatedPcodeUseropLibrary.PcodeUserop
.
The userop may accept parameters and return a result. To accept parameters, declare them in
the Java method signature and annotate them with StructuredSleigh.Param
. To return a result, name the
appropriate type in the type()
attribute and use
StructuredSleigh._result(RVal)
. The Java return type of the method must still be
void
. Note that parameters are passed by reference, so results can also be
communicated by setting a parameter's value.
-
Optional Element Summary
-
Element Details
-
type
String typeThe data type path for the "return type" of the userop. SeeStructuredSleigh.type(String)
.- Default:
"void"
-