rosy/ruby_bindings/
mod.rs

1#![allow(dead_code, non_upper_case_globals, non_snake_case)]
2
3mod prelude {
4    pub use std::{
5        ffi::c_void,
6        os::raw::{c_char, c_int, c_uint, c_long},
7    };
8    pub use super::{VALUE, ID};
9}
10
11mod array;
12mod data;
13mod exception;
14mod float;
15mod gc;
16mod hash;
17mod int;
18mod mixin;
19mod object;
20mod range;
21mod string;
22mod symbol;
23mod vm;
24
25// `USE_FLONUM` is defined by `SIZEOF_VALUE >= SIZEOF_DOUBLE`
26#[cfg(not(target_pointer_width = "32"))]
27mod USE_FLONUM { // true
28    use super::VALUE;
29
30    #[inline]
31    pub fn rb_flonum_p(x: VALUE) -> bool {
32        (x & special_consts::FLONUM_MASK) == special_consts::FLONUM_FLAG
33    }
34
35    pub mod special_consts {
36        pub const Qfalse: usize = 0x00; // ...0000 0000
37        pub const Qtrue:  usize = 0x14; // ...0001 0100
38        pub const Qnil:   usize = 0x08; // ...0000 1000
39        pub const Qundef: usize = 0x34; // ...0011 0100
40
41        pub const IMMEDIATE_MASK: usize = 0x07;
42        pub const FIXNUM_FLAG:    usize = 0x01; // ...xxxx xxx1
43        pub const FLONUM_MASK:    usize = 0x03;
44        pub const FLONUM_FLAG:    usize = 0x02; // ...xxxx xx10
45        pub const SYMBOL_FLAG:    usize = 0x0c; // ...0000 1100
46
47        pub const SPECIAL_SHIFT: usize = 8;
48    }
49}
50
51#[cfg(target_pointer_width = "32")]
52mod USE_FLONUM { // false
53    use super::VALUE;
54
55    #[inline]
56    pub fn rb_flonum_p(x: VALUE) -> bool {
57        false
58    }
59
60    pub mod special_consts {
61        pub const Qfalse: usize = 0; // ...0000 0000
62        pub const Qtrue:  usize = 2; // ...0000 0010
63        pub const Qnil:   usize = 4; // ...0000 0100
64        pub const Qundef: usize = 6; // ...0000 0110
65
66        pub const IMMEDIATE_MASK: usize = 0x03;
67        pub const FIXNUM_FLAG:    usize = 0x01; // ...xxxx xxx1
68        pub const FLONUM_MASK:    usize = 0x00; // any values ANDed with FLONUM_MASK cannot be FLONUM_FLAG
69        pub const FLONUM_FLAG:    usize = 0x02;
70        pub const SYMBOL_FLAG:    usize = 0x0e; // ...0000 1110
71
72        pub const SPECIAL_SHIFT: usize = 8;
73    }
74}
75
76pub mod fl_type {
77    pub const FL_WB_PROTECTED: usize = 1 << 5;
78    pub const FL_PROMOTED0:    usize = 1 << 5;
79    pub const FL_PROMOTED1:    usize = 1 << 6;
80    pub const FL_PROMOTED:     usize = FL_PROMOTED0 | FL_PROMOTED1;
81    pub const FL_FINALIZE:     usize = 1 << 7;
82    pub const FL_TAINT:        usize = 1 << 8;
83    pub const FL_UNTRUSTED:    usize = FL_TAINT;
84    pub const FL_EXIVAR:       usize = 1 << 10;
85    pub const FL_FREEZE:       usize = 1 << 11;
86
87    pub const FL_USHIFT: usize = 12;
88
89    const fn fl_user(n: usize) -> usize {
90        1 << (FL_USHIFT + n)
91    }
92
93    pub const FL_USER_0:  usize = fl_user(0);
94    pub const FL_USER_1:  usize = fl_user(1);
95    pub const FL_USER_2:  usize = fl_user(2);
96    pub const FL_USER_3:  usize = fl_user(3);
97    pub const FL_USER_4:  usize = fl_user(4);
98    pub const FL_USER_5:  usize = fl_user(5);
99    pub const FL_USER_6:  usize = fl_user(6);
100    pub const FL_USER_7:  usize = fl_user(7);
101    pub const FL_USER_8:  usize = fl_user(8);
102    pub const FL_USER_9:  usize = fl_user(9);
103    pub const FL_USER_10: usize = fl_user(10);
104    pub const FL_USER_11: usize = fl_user(11);
105    pub const FL_USER_12: usize = fl_user(12);
106    pub const FL_USER_13: usize = fl_user(13);
107    pub const FL_USER_14: usize = fl_user(14);
108    pub const FL_USER_15: usize = fl_user(15);
109    pub const FL_USER_16: usize = fl_user(16);
110    pub const FL_USER_17: usize = fl_user(17);
111    pub const FL_USER_18: usize = fl_user(18);
112}
113
114pub use self::{
115    array::*,
116    data::*,
117    exception::*,
118    float::*,
119    gc::*,
120    hash::*,
121    int::*,
122    mixin::*,
123    object::*,
124    range::*,
125    string::*,
126    symbol::*,
127    vm::*,
128    USE_FLONUM::*,
129};
130
131type OpaqueFn = Option<unsafe extern "C" fn ()>;
132
133pub type VALUE = usize;
134
135#[allow(non_camel_case_types)]
136#[repr(C)]
137#[derive(Clone, Copy, PartialEq, Eq)]
138pub enum value_type {
139    NONE   = 0x00,
140
141    OBJECT   = 0x01,
142    CLASS    = 0x02,
143    MODULE   = 0x03,
144    FLOAT    = 0x04,
145    STRING   = 0x05,
146    REGEXP   = 0x06,
147    ARRAY    = 0x07,
148    HASH     = 0x08,
149    STRUCT   = 0x09,
150    BIGNUM   = 0x0a,
151    FILE     = 0x0b,
152    DATA     = 0x0c,
153    MATCH    = 0x0d,
154    COMPLEX  = 0x0e,
155    RATIONAL = 0x0f,
156
157    NIL    = 0x11,
158    TRUE   = 0x12,
159    FALSE  = 0x13,
160    SYMBOL = 0x14,
161    FIXNUM = 0x15,
162    UNDEF  = 0x16,
163
164    IMEMO  = 0x1a,
165    NODE   = 0x1b,
166    ICLASS = 0x1c,
167    ZOMBIE = 0x1d,
168
169    MASK   = 0x1f,
170
171    // Defined here to ensure that no other values conflict
172    _Unknown = !0,
173}
174
175extern "C" {
176    pub static ruby_api_version:  [prelude::c_int;  3];
177    pub static ruby_version:      [prelude::c_char; 0];
178    pub static ruby_release_date: [prelude::c_char; 0];
179    pub static ruby_platform:     [prelude::c_char; 0];
180    pub static ruby_patchlevel:   [prelude::c_char; 0];
181    pub static ruby_description:  [prelude::c_char; 0];
182    pub static ruby_copyright:    [prelude::c_char; 0];
183    pub static ruby_engine:       [prelude::c_char; 0];
184}