diff --git a/sources/interpreter_two/src/bytecode/mod.rs b/sources/interpreter_two/src/bytecode/mod.rs index 53ce2cba..fc23be93 100644 --- a/sources/interpreter_two/src/bytecode/mod.rs +++ b/sources/interpreter_two/src/bytecode/mod.rs @@ -34,7 +34,7 @@ pub fn decode_instruction(_vm: &VM, bytes: &mut BytesMut) -> Result b(ops::Nop), - // Constants Loads Stores + // Constants / Loads / Stores 0x01 => b(ops::PushConst { value: RuntimeValue::Null, }), diff --git a/sources/interpreter_two/src/object/mod.rs b/sources/interpreter_two/src/object/mod.rs index c83ec1f9..42ac0535 100644 --- a/sources/interpreter_two/src/object/mod.rs +++ b/sources/interpreter_two/src/object/mod.rs @@ -38,7 +38,6 @@ pub trait Object: fmt::Debug { } } - #[derive(Debug)] pub struct RuntimeObject { pub class_object: WrappedClassObject, @@ -49,9 +48,9 @@ impl RuntimeObject { pub fn new(class_object: WrappedClassObject) -> Self { Self { class_object, - instance_fields: HashMap::new() + instance_fields: HashMap::new(), } - } + } } impl Object for RuntimeObject { @@ -227,8 +226,10 @@ impl StringObject { }))); s.set_instance_field(("value".to_string(), "[B".to_string()), arr)?; - s.set_instance_field(("coder".to_string(), "B".to_string()), RuntimeValue::Integral((1_i32).into()))?; - + s.set_instance_field( + ("coder".to_string(), "B".to_string()), + RuntimeValue::Integral((1_i32).into()), + )?; Ok(s) } @@ -255,6 +256,24 @@ pub enum RuntimeValue { Null, } +impl RuntimeValue { + pub fn hash_code(&self) -> i32 { + match self { + RuntimeValue::Object(data) => { + let pt = Rc::as_ptr(data); + pt as *const () as i32 + }, + RuntimeValue::Array(data) => { + let pt = Rc::as_ptr(data); + pt as *const () as i32 + }, + RuntimeValue::Integral(data) => data.value as i32, + RuntimeValue::Floating(data) => data.value as i32, + RuntimeValue::Null => 0, + } + } +} + const UPPER_SCIENCE_BOUND: f64 = 1_000_000.0; const LOWER_SCIENCE_BOUND: f64 = 0.000_000_1;