artichoke_backend/extn/
mod.rs

1#![expect(
2    clippy::needless_pass_by_value,
3    reason = "permit passing `Value` by value in all mruby and Rust trampolines"
4)]
5
6use crate::release_metadata::ReleaseMetadata;
7
8pub mod core;
9pub mod prelude;
10pub mod stdlib;
11
12use prelude::*;
13
14pub const INPUT_RECORD_SEPARATOR: &str = "\n";
15
16pub fn init(interp: &mut Artichoke, config: ReleaseMetadata<'_>) -> InitializeResult<()> {
17    let mut copyright = interp.try_convert_mut(config.ruby_copyright())?;
18    copyright.freeze(interp)?;
19    interp.define_global_constant("RUBY_COPYRIGHT", copyright)?;
20
21    let mut description = interp.try_convert_mut(config.ruby_description())?;
22    description.freeze(interp)?;
23    interp.define_global_constant("RUBY_DESCRIPTION", description)?;
24
25    let mut engine = interp.try_convert_mut(config.ruby_engine())?;
26    engine.freeze(interp)?;
27    interp.define_global_constant("RUBY_ENGINE", engine)?;
28
29    let mut engine_version = interp.try_convert_mut(config.ruby_engine_version())?;
30    engine_version.freeze(interp)?;
31    interp.define_global_constant("RUBY_ENGINE_VERSION", engine_version)?;
32
33    let patchlevel = config
34        .ruby_patchlevel()
35        .parse::<i64>()
36        .map_err(|_| NotDefinedError::global_constant("RUBY_PATCHLEVEL"))?;
37    let patchlevel = interp.convert(patchlevel);
38    interp.define_global_constant("RUBY_PATCHLEVEL", patchlevel)?;
39
40    let mut platform = interp.try_convert_mut(config.ruby_platform())?;
41    platform.freeze(interp)?;
42    interp.define_global_constant("RUBY_PLATFORM", platform)?;
43
44    let mut release_date = interp.try_convert_mut(config.ruby_release_date())?;
45    release_date.freeze(interp)?;
46    interp.define_global_constant("RUBY_RELEASE_DATE", release_date)?;
47
48    let revision = config.ruby_revision();
49    let revision = interp.try_convert_mut(revision)?;
50    interp.define_global_constant("RUBY_REVISION", revision)?;
51
52    let mut version = interp.try_convert_mut(config.ruby_version())?;
53    version.freeze(interp)?;
54    interp.define_global_constant("RUBY_VERSION", version)?;
55
56    let mut compiler_version = interp.try_convert_mut(config.artichoke_compiler_version())?;
57    compiler_version.freeze(interp)?;
58    interp.define_global_constant("ARTICHOKE_COMPILER_VERSION", compiler_version)?;
59
60    core::init(interp)?;
61    stdlib::init(interp)?;
62    Ok(())
63}