]> Witch of Git - ivy/blob - rt/src/int.rs
[rt] More misc fixes
[ivy] / rt / src / int.rs
1 use crate::{Obj, ObjTag};
2 use std::sync::atomic::AtomicU32;
3
4 #[repr(C)]
5 pub struct ObjInt {
6 tag: ObjTag,
7 _pad: [u8; 3],
8 rc: AtomicU32,
9 value: i64,
10 }
11
12 #[no_mangle]
13 pub unsafe extern "C" fn ivy_check_int(obj: Obj) {
14 if obj.tag() != Some(ObjTag::Int) {
15 panic!(
16 "ivy_check_int called with non-integer object {:016x}.",
17 obj.int
18 );
19 }
20 }
21
22 // This should probably be a macro rather than a call?
23 // But it might be good to have it for completeness.
24 // Or maybe it's valuable if we want to support big integers.
25 #[no_mangle]
26 pub unsafe extern "C" fn ivy_make_int(value: i64) -> Obj {
27 // @TODO: Handle 64 bit values rather than 63 bit integers
28 Obj { int: value << 1 | 1 }
29 }