| Title: | C R Bytecode Compiler |
|---|---|
| Description: | Implements a bytecode compiler for 'R' in 'C', targeting functional parity with the base 'compiler' package, while focusing on better performance. The architecture mostly mirrors the original 'GNU-R' compiler as described in <https://homepage.cs.uiowa.edu/~luke/R/compiler/compiler.pdf>. |
| Authors: | Josef Malý [aut, cre], Filip Křikava [ths] |
| Maintainer: | Josef Malý <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.1.0 |
| Built: | 2026-10-04 10:03:47 UTC |
| Source: | https://github.com/PRL-PRG/crbcc |
Compiles all top-level expressions in an R source file to bytecode and saves the result to an output file.
cmpfile(infile, outfile, ascii = FALSE, env = .GlobalEnv, verbose = FALSE, options = NULL, version = NULL)cmpfile(infile, outfile, ascii = FALSE, env = .GlobalEnv, verbose = FALSE, options = NULL, version = NULL)
infile |
Path to the input R source file. |
outfile |
Path to the output file. If missing, defaults to the input
file name with extension replaced by |
ascii |
Logical; whether to write an ASCII file. |
env |
The top-level environment in which to evaluate expressions. |
verbose |
Logical; Not yet implemented, print compilation progress messages. |
options |
List of compilation options. |
version |
Optional file format version. |
Invisible NULL. Output is written to file as a side effect.
tmp_r <- tempfile(fileext = ".R") tmp_rc <- tempfile(fileext = ".Rc") writeLines("x <- 1; x + 1", tmp_r) cmpfile(tmp_r, tmp_rc)tmp_r <- tempfile(fileext = ".R") tmp_rc <- tempfile(fileext = ".Rc") writeLines("x <- 1; x + 1", tmp_r) cmpfile(tmp_r, tmp_rc)
Compiles an R closure to bytecode using the C-based compiler backend.
cmpfun(fun, options = list())cmpfun(fun, options = list())
fun |
A closure to compile to bytecode. |
options |
A named list of compilation options. |
A bytecode-compiled function.
f <- function(x) x + 1 cf <- cmpfun(f) cf(10)f <- function(x) x + 1 cf <- cmpfun(f) cf(10)
Compiles a generic R language object (such as an expression or function) to bytecode using the C-based compiler backend.
compile(e, env = .GlobalEnv, options = NULL, srcref = NULL)compile(e, env = .GlobalEnv, options = NULL, srcref = NULL)
e |
An R language object to compile. |
env |
The environment in which to evaluate the object. |
options |
A list of compilation options, or |
srcref |
Optional source reference information. |
The compiled object, or invisible NULL if compilation is only for side effect.
expr <- quote({ x <- 1; x + 2 }) compile(expr)expr <- quote({ x <- 1; x + 2 }) compile(expr)
Loads bytecode compiled by cmpfile into an environment.
loadcmp(file, envir)loadcmp(file, envir)
file |
Path to the compiled |
envir |
The environment to load into, use .GlobalEnv to load the code into current global session |
Invisible NULL.
tmp_r <- tempfile(fileext = ".R") tmp_rc <- tempfile(fileext = ".Rc") writeLines("f <- function(x) x * 2", tmp_r) cmpfile(tmp_r, tmp_rc) loadcmp(tmp_rc, .GlobalEnv) f(3)tmp_r <- tempfile(fileext = ".R") tmp_rc <- tempfile(fileext = ".Rc") writeLines("f <- function(x) x * 2", tmp_r) cmpfile(tmp_r, tmp_rc) loadcmp(tmp_rc, .GlobalEnv) f(3)