Skip to content

Commit

Permalink
chore(heap): Move BigIntHeapData to ecmascript/types/language/bigint
Browse files Browse the repository at this point in the history
  • Loading branch information
aapoalas committed Oct 29, 2023
1 parent 7e01c84 commit b982dcc
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 18 deletions.
1 change: 1 addition & 0 deletions nova_vm/src/ecmascript/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod language;
mod spec;

pub(crate) use language::BigIntHeapData;
pub(crate) use language::ObjectHeapData;
pub(crate) use language::StringHeapData;
pub use language::{Function, InternalMethods, Number, Object, PropertyKey, String, Value};
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 @@ -5,7 +5,7 @@ mod object;
mod string;
mod value;

pub use bigint::BigInt;
pub use bigint::{BigInt, BigIntHeapData};
pub use function::Function;
pub use number::Number;
pub use object::{InternalMethods, Object, ObjectHeapData, PropertyKey, PropertyStorage};
Expand Down
4 changes: 4 additions & 0 deletions nova_vm/src/ecmascript/types/language/bigint.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
pub(crate) mod data;

use super::value::{BIGINT_DISCRIMINANT, SMALL_BIGINT_DISCRIMINANT};
use crate::{heap::indexes::BigIntIndex, SmallInteger};

pub use data::BigIntHeapData;

#[derive(Clone, Copy)]
#[repr(u8)]
pub enum BigInt {
Expand Down
17 changes: 17 additions & 0 deletions nova_vm/src/ecmascript/types/language/bigint/data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use crate::ecmascript::execution::agent::JsError;
use num_bigint_dig::BigInt;
// use num_traits::cast::ToPrimitive;

#[derive(Debug, Clone)]
pub struct BigIntHeapData {
pub(super) data: BigInt,
}

impl TryInto<f64> for BigIntHeapData {
type Error = JsError;

fn try_into(self) -> Result<f64, Self::Error> {
// self.data.to_f64()
Err(JsError {})
}
}
7 changes: 5 additions & 2 deletions nova_vm/src/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub use self::heap_constants::BuiltinObjectIndexes;
use self::{
array::initialize_array_heap,
array_buffer::{initialize_array_buffer_heap, ArrayBufferHeapData},
bigint::{initialize_bigint_heap, BigIntHeapData},
bigint::initialize_bigint_heap,
boolean::initialize_boolean_heap,
date::{initialize_date_heap, DateHeapData},
element_array::{
Expand All @@ -45,7 +45,10 @@ use self::{
use crate::ecmascript::{
builtins::ArrayHeapData,
execution::{Environments, Realm, RealmIdentifier},
types::{Function, Number, Object, ObjectHeapData, PropertyKey, String, StringHeapData, Value},
types::{
BigIntHeapData, Function, Number, Object, ObjectHeapData, PropertyKey, String,
StringHeapData, Value,
},
};
use wtf8::{Wtf8, Wtf8Buf};

Expand Down
12 changes: 0 additions & 12 deletions nova_vm/src/heap/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@ use crate::{
FunctionHeapData, Heap, ObjectEntry, PropertyDescriptor,
},
};
use num_bigint_dig::BigInt;

#[derive(Debug, Clone)]
pub struct BigIntHeapData {
pub(super) data: BigInt,
}

impl BigIntHeapData {
pub fn try_into_f64(&self) -> Option<f64> {
None
}
}

pub fn initialize_bigint_heap(heap: &mut Heap) {
let entries = vec![
Expand Down
6 changes: 3 additions & 3 deletions nova_vm/src/heap/indexes.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::array_buffer::ArrayBufferHeapData;
use super::{
bigint::BigIntHeapData, date::DateHeapData, error::ErrorHeapData, function::FunctionHeapData,
number::NumberHeapData, regexp::RegExpHeapData, symbol::SymbolHeapData,
date::DateHeapData, error::ErrorHeapData, function::FunctionHeapData, number::NumberHeapData,
regexp::RegExpHeapData, symbol::SymbolHeapData,
};
use crate::ecmascript::builtins::ArrayHeapData;
use crate::ecmascript::types::{ObjectHeapData, StringHeapData, Value};
use crate::ecmascript::types::{BigIntHeapData, ObjectHeapData, StringHeapData, Value};
use crate::Heap;
use core::fmt::Debug;
use std::hash::{Hash, Hasher};
Expand Down

0 comments on commit b982dcc

Please sign in to comment.