Skip to main content

execute_reg_jit

Function execute_reg_jit 

Source
pub fn execute_reg_jit(
    chunk: &RegChunk,
    ctx: EvalContext,
) -> Result<(JsValue, EvalContext), JErrorType>
Expand description

Execute register bytecode with Cranelift JIT compilation.

Uses the Cranelift code generator to compile numeric-heavy code paths to native machine code for maximum performance.

ยงExamples

use just::parser::JsParser;
use just::runner::plugin::types::EvalContext;
use just::runner::jit::reg_compiler::RegCompiler;
use just::runner::jit;

let code = "var sum = 0; for (var i = 0; i < 100; i++) { sum = sum + i; }";
let ast = JsParser::parse_to_ast_from_str(code).unwrap();
let compiler = RegCompiler::new();
let chunk = compiler.compile_program(&ast);

let ctx = EvalContext::new();
let (result, ctx) = jit::execute_reg_jit(&chunk, ctx).unwrap();