new_primitive() creates a new primitive: an AnvlPrimitive, the function
the primitive is called through (e.g. prim_add()).
For details on how to do this, see the Adding a Primitive article.
Like every jitted function it runs on the active backend when called.
Arguments
- name
(
character(1))
Primitive name, without theprim_prefix ("add"forprim_add()).- fn
(
function)
Body of the primitive. Its formals become the formals of the returned JIT-compiled callable. Insidefn, the primitive is accessible via the lexically-bound symbolself(anAnvlPrimitiveDef); pass it as the first argument tograph_desc_add().- subgraphs
(
character())
Names of parameters that are subgraphs (for higher-order primitives).- static
(
character()|integer())
Passed tojit().- register
(
logical(1))
Whether to add the primitive to anvl's internal registry of primitives, undername, replacing one registered under the same name. The quickr backend reads that registry to know which primitives it can lower, so a primitive created withregister = FALSEis rejected on quickr even if it has aquickrrule. The other backends only read the rules of the primitive itself. This does not bind the result to aprim_<name>variable; assign it yourself.
Value
(AnvlPrimitive)
The function the primitive is called through, of class
c("AnvlPrimitive", "JitFunction"). Its AnvlPrimitiveDef is
attr(<fn>, "definition"), and [[ / [[<- on it access the rules of
that definition.