---
title: "Primitives Reference"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Primitives Reference}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r, echo = FALSE}
library(anvl)

ns <- asNamespace("anvl")
prim_names <- grep("^prim_", ls(ns), value = TRUE)
prims <- mget(prim_names, envir = ns)
prims <- Filter(function(x) inherits(x, "JitPrimitive"), prims)

# Extract primitive info
primitives_list <- lapply(prims, function(p) {
  p_meta <- attr(p, "primitive")
  has_stablehlo <- !is.null(p_meta$rules[["stablehlo"]])
  has_quickr <- !is.null(p_meta$rules[["quickr"]])
  has_reverse <- !is.null(p_meta$rules[["reverse"]])

  data.frame(
    Name = p_meta$name,
    StableHLO = if (has_stablehlo) "\u2713" else "\u2717",
    Quickr = if (has_quickr) "\u2713" else "\u2717",
    Reverse = if (has_reverse) "\u2713" else "\u2717"
  )
})

primitives_df <- do.call(rbind, Filter(Negate(is.null), primitives_list))
primitives_df <- primitives_df[order(primitives_df$Name), ]
rownames(primitives_df) <- NULL
```

The table below shows all `r nrow(primitives_df)` primitives and which rules they implement.
Note that a rule might be missing because it was just not added yet, or because it does not apply for a specific primitive.


```{r, echo = FALSE}
knitr::kable(primitives_df, align = c("l", "c", "c", "c"))
```
