Skip to content

Commit df0d436

Browse files
stepanchegfacebook-github-bot
authored andcommitted
AllocValue for more int types
Reviewed By: bobyangyf Differential Revision: D38712858 fbshipit-source-id: 72e823078530ebcdb9cfc97157ebab311c23bff9
1 parent 957be9b commit df0d436

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

starlark/src/values/types/bigint/convert.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,30 @@ use crate::values::FrozenValue;
2424
use crate::values::Heap;
2525
use crate::values::Value;
2626

27+
impl StarlarkTypeRepr for u32 {
28+
fn starlark_type_repr() -> String {
29+
i32::starlark_type_repr()
30+
}
31+
}
32+
33+
impl<'v> AllocValue<'v> for u32 {
34+
fn alloc_value(self, heap: &'v Heap) -> Value<'v> {
35+
match i32::try_from(self) {
36+
Ok(x) => Value::new_int(x),
37+
Err(_) => StarlarkBigInt::alloc_bigint(self.into(), heap),
38+
}
39+
}
40+
}
41+
42+
impl AllocFrozenValue for u32 {
43+
fn alloc_frozen_value(self, heap: &FrozenHeap) -> FrozenValue {
44+
match i32::try_from(self) {
45+
Ok(x) => FrozenValue::new_int(x),
46+
Err(_) => StarlarkBigInt::alloc_bigint_frozen(self.into(), heap),
47+
}
48+
}
49+
}
50+
2751
impl StarlarkTypeRepr for u64 {
2852
fn starlark_type_repr() -> String {
2953
i32::starlark_type_repr()
@@ -71,3 +95,51 @@ impl AllocFrozenValue for i64 {
7195
}
7296
}
7397
}
98+
99+
impl StarlarkTypeRepr for usize {
100+
fn starlark_type_repr() -> String {
101+
i32::starlark_type_repr()
102+
}
103+
}
104+
105+
impl<'v> AllocValue<'v> for usize {
106+
fn alloc_value(self, heap: &'v Heap) -> Value<'v> {
107+
match i32::try_from(self) {
108+
Ok(x) => Value::new_int(x),
109+
Err(_) => StarlarkBigInt::alloc_bigint(self.into(), heap),
110+
}
111+
}
112+
}
113+
114+
impl AllocFrozenValue for usize {
115+
fn alloc_frozen_value(self, heap: &FrozenHeap) -> FrozenValue {
116+
match i32::try_from(self) {
117+
Ok(x) => FrozenValue::new_int(x),
118+
Err(_) => StarlarkBigInt::alloc_bigint_frozen(self.into(), heap),
119+
}
120+
}
121+
}
122+
123+
impl StarlarkTypeRepr for isize {
124+
fn starlark_type_repr() -> String {
125+
i32::starlark_type_repr()
126+
}
127+
}
128+
129+
impl<'v> AllocValue<'v> for isize {
130+
fn alloc_value(self, heap: &'v Heap) -> Value<'v> {
131+
match i32::try_from(self) {
132+
Ok(x) => Value::new_int(x),
133+
Err(_) => StarlarkBigInt::alloc_bigint(self.into(), heap),
134+
}
135+
}
136+
}
137+
138+
impl AllocFrozenValue for isize {
139+
fn alloc_frozen_value(self, heap: &FrozenHeap) -> FrozenValue {
140+
match i32::try_from(self) {
141+
Ok(x) => FrozenValue::new_int(x),
142+
Err(_) => StarlarkBigInt::alloc_bigint_frozen(self.into(), heap),
143+
}
144+
}
145+
}

0 commit comments

Comments
 (0)