From 407a6b267e9503b8eed00d7a01c59c69f246bc13 Mon Sep 17 00:00:00 2001 From: Olivier Date: Wed, 1 May 2024 22:31:26 +0100 Subject: [PATCH] Where possible, unreflect u64s to Value::Ints --- hornbeam_interpreter/src/engine.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hornbeam_interpreter/src/engine.rs b/hornbeam_interpreter/src/engine.rs index ffe8b15..e64f640 100644 --- a/hornbeam_interpreter/src/engine.rs +++ b/hornbeam_interpreter/src/engine.rs @@ -59,6 +59,7 @@ lazy_static! { static ref U8_TYPEID: TypeId = TypeId::of::(); static ref U16_TYPEID: TypeId = TypeId::of::(); static ref U32_TYPEID: TypeId = TypeId::of::(); + static ref U64_TYPEID: TypeId = TypeId::of::(); static ref I8_TYPEID: TypeId = TypeId::of::(); static ref I16_TYPEID: TypeId = TypeId::of::(); static ref I32_TYPEID: TypeId = TypeId::of::(); @@ -80,6 +81,16 @@ impl Value { Value::Int(u16::from_reflect(reflect.deref()).unwrap() as i64) } else if ti == *U32_TYPEID { Value::Int(u32::from_reflect(reflect.deref()).unwrap() as i64) + } else if ti == *U64_TYPEID { + // If we can, convert it to a native i64 value + // If we can't (because it's bigger than i64::MAX), + // then we have no choice but to leave it as a reflective value... :/ + // TODO I really don't like this but my hands are tied... + let value_u64 = u64::from_reflect(reflect.deref()).unwrap(); + match i64::try_from(value_u64) { + Ok(value_i64) => Value::Int(value_i64), + Err(_cant) => Value::Reflective(reflect), + } } else if ti == *I8_TYPEID { Value::Int(i8::from_reflect(reflect.deref()).unwrap() as i64) } else if ti == *I16_TYPEID {