Skip to content

Commit

Permalink
chore(heap): Move NumberHeapData to ecmascript/types/language/number
Browse files Browse the repository at this point in the history
  • Loading branch information
aapoalas committed Oct 29, 2023
1 parent d98ec8f commit cb35c79
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion nova_vm/src/ecmascript/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod language;
mod spec;

pub(crate) use language::{BigIntHeapData, ObjectHeapData, StringHeapData};
pub(crate) use language::{BigIntHeapData, NumberHeapData, ObjectHeapData, StringHeapData};
pub use language::{Function, InternalMethods, Number, Object, PropertyKey, String, Value};
pub use spec::{Base, PropertyDescriptor, Reference, ReferencedName};

Expand Down
2 changes: 1 addition & 1 deletion nova_vm/src/ecmascript/types/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod value;

pub use bigint::{BigInt, BigIntHeapData};
pub use function::Function;
pub use number::Number;
pub use number::{Number, NumberHeapData};
pub use object::{InternalMethods, Object, ObjectHeapData, PropertyKey, PropertyStorage};
pub use string::{String, StringHeapData};
pub use value::Value;
4 changes: 4 additions & 0 deletions nova_vm/src/ecmascript/types/language/number.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod data;

use super::{
value::{FLOAT_DISCRIMINANT, INTEGER_DISCRIMINANT, NUMBER_DISCRIMINANT},
Value,
Expand All @@ -8,6 +10,8 @@ use crate::{
SmallInteger,
};

pub use data::NumberHeapData;

/// 6.1.6.1 The Number Type
/// https://tc39.es/ecma262/#sec-ecmascript-language-types-number-type
#[derive(Clone, Copy)]
Expand Down
17 changes: 17 additions & 0 deletions nova_vm/src/ecmascript/types/language/number/data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#[derive(Debug, Clone, Copy)]
pub struct NumberHeapData {
pub(crate) data: f64,
}

impl From<f64> for NumberHeapData {
#[inline(always)]
fn from(data: f64) -> Self {
Self { data }
}
}

impl From<NumberHeapData> for f64 {
fn from(value: NumberHeapData) -> Self {
value.data
}
}
8 changes: 4 additions & 4 deletions nova_vm/src/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use self::{
},
indexes::{BaseIndex, FunctionIndex, NumberIndex, ObjectIndex, StringIndex},
math::initialize_math_object,
number::{initialize_number_heap, NumberHeapData},
number::initialize_number_heap,
object::{initialize_object_heap, ObjectEntry, PropertyDescriptor},
regexp::{initialize_regexp_heap, RegExpHeapData},
string::initialize_string_heap,
Expand All @@ -46,8 +46,8 @@ use crate::ecmascript::{
builtins::ArrayHeapData,
execution::{Environments, Realm, RealmIdentifier},
types::{
BigIntHeapData, Function, Number, Object, ObjectHeapData, PropertyKey, String,
StringHeapData, Value,
BigIntHeapData, Function, Number, NumberHeapData, Object, ObjectHeapData, PropertyKey,
String, StringHeapData, Value,
},
};
use wtf8::{Wtf8, Wtf8Buf};
Expand Down Expand Up @@ -269,7 +269,7 @@ impl<'ctx, 'host> Heap<'ctx, 'host> {
}

pub fn alloc_number(&mut self, number: f64) -> NumberIndex {
self.numbers.push(Some(NumberHeapData::new(number)));
self.numbers.push(Some(number.into()));
NumberIndex::last(&self.numbers)
}

Expand Down
8 changes: 5 additions & 3 deletions nova_vm/src/heap/indexes.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use super::array_buffer::ArrayBufferHeapData;
use super::{
date::DateHeapData, error::ErrorHeapData, function::FunctionHeapData, number::NumberHeapData,
regexp::RegExpHeapData, symbol::SymbolHeapData,
date::DateHeapData, error::ErrorHeapData, function::FunctionHeapData, regexp::RegExpHeapData,
symbol::SymbolHeapData,
};
use crate::ecmascript::builtins::ArrayHeapData;
use crate::ecmascript::types::{BigIntHeapData, ObjectHeapData, StringHeapData, Value};
use crate::ecmascript::types::{
BigIntHeapData, NumberHeapData, ObjectHeapData, StringHeapData, Value,
};
use crate::Heap;
use core::fmt::Debug;
use std::hash::{Hash, Hasher};
Expand Down
15 changes: 0 additions & 15 deletions nova_vm/src/heap/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,6 @@ use crate::{
},
};

#[derive(Debug, Clone, Copy)]
pub struct NumberHeapData {
pub(super) data: f64,
}

impl NumberHeapData {
pub(super) fn new(data: f64) -> NumberHeapData {
NumberHeapData { data }
}

pub fn value(&self) -> f64 {
self.data
}
}

pub fn initialize_number_heap(heap: &mut Heap) {
let entries = vec![
ObjectEntry::new(
Expand Down

0 comments on commit cb35c79

Please sign in to comment.