Skip to content

Commit

Permalink
Make everything public to pass build
Browse files Browse the repository at this point in the history
  • Loading branch information
aapoalas committed Oct 2, 2023
1 parent f5816cf commit 40bcd48
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 108 deletions.
40 changes: 20 additions & 20 deletions nova_vm/src/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod function;
mod heap_bits;
mod heap_constants;
mod heap_gc;
pub(crate) mod indexes;
pub mod indexes;
mod math;
mod number;
mod object;
Expand Down Expand Up @@ -52,19 +52,19 @@ pub struct Heap {
/// ElementsArrays is where all element arrays live;
/// Element arrays are static arrays of Values plus
/// a HashMap of possible property descriptors.
pub(crate) elements: ElementArrays,
pub(crate) arrays: Vec<Option<ArrayHeapData>>,
pub(crate) array_buffers: Vec<Option<ArrayBufferHeapData>>,
pub(crate) bigints: Vec<Option<BigIntHeapData>>,
pub(crate) errors: Vec<Option<ErrorHeapData>>,
pub(crate) functions: Vec<Option<FunctionHeapData>>,
pub(crate) dates: Vec<Option<DateHeapData>>,
pub(crate) globals: Vec<Value>,
pub(crate) numbers: Vec<Option<NumberHeapData>>,
pub(crate) objects: Vec<Option<ObjectHeapData>>,
pub(crate) regexps: Vec<Option<RegExpHeapData>>,
pub(crate) strings: Vec<Option<StringHeapData>>,
pub(crate) symbols: Vec<Option<SymbolHeapData>>,
pub elements: ElementArrays,
pub arrays: Vec<Option<ArrayHeapData>>,
pub array_buffers: Vec<Option<ArrayBufferHeapData>>,
pub bigints: Vec<Option<BigIntHeapData>>,
pub errors: Vec<Option<ErrorHeapData>>,
pub functions: Vec<Option<FunctionHeapData>>,
pub dates: Vec<Option<DateHeapData>>,
pub globals: Vec<Value>,
pub numbers: Vec<Option<NumberHeapData>>,
pub objects: Vec<Option<ObjectHeapData>>,
pub regexps: Vec<Option<RegExpHeapData>>,
pub strings: Vec<Option<StringHeapData>>,
pub symbols: Vec<Option<SymbolHeapData>>,
}

impl Heap {
Expand Down Expand Up @@ -143,7 +143,7 @@ impl Heap {
heap
}

pub(crate) fn alloc_string(&mut self, message: &str) -> StringIndex {
pub fn alloc_string(&mut self, message: &str) -> StringIndex {
let found = self.strings.iter().position(|opt| {
opt.as_ref()
.map_or(false, |data| data.data == Wtf8::from_str(message))
Expand All @@ -162,12 +162,12 @@ impl Heap {
}
}

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

pub(crate) fn create_function(
pub fn create_function(
&mut self,
name: Value,
length: u8,
Expand Down Expand Up @@ -206,7 +206,7 @@ impl Heap {
index
}

pub(crate) fn create_object(&mut self, entries: Vec<ObjectEntry>) -> ObjectIndex {
pub fn create_object(&mut self, entries: Vec<ObjectEntry>) -> ObjectIndex {
let (keys, values) = self.elements.create_object_entries(entries);
let object_data = ObjectHeapData {
_extensible: true,
Expand All @@ -218,7 +218,7 @@ impl Heap {
ObjectIndex::last(&self.objects)
}

pub(crate) fn create_null_object(&mut self, entries: Vec<ObjectEntry>) -> ObjectIndex {
pub fn create_null_object(&mut self, entries: Vec<ObjectEntry>) -> ObjectIndex {
let (keys, values) = self.elements.create_object_entries(entries);
let object_data = ObjectHeapData {
_extensible: true,
Expand All @@ -230,7 +230,7 @@ impl Heap {
ObjectIndex::last(&self.objects)
}

pub(crate) fn insert_builtin_object(
pub fn insert_builtin_object(
&mut self,
index: BuiltinObjectIndexes,
extensible: bool,
Expand Down
4 changes: 2 additions & 2 deletions nova_vm/src/heap/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use super::{
};

#[derive(Debug, Clone, Copy)]
pub(crate) struct ArrayHeapData {
pub(super) object_index: ObjectIndex,
pub struct ArrayHeapData {
pub(super) object_index: Option<ObjectIndex>,
// TODO: Use SmallVec<[Value; 4]>
pub(super) elements: ElementsVector,
}
Expand Down
6 changes: 3 additions & 3 deletions nova_vm/src/heap/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ use crate::{
use super::indexes::{ErrorIndex, ObjectIndex};

#[derive(Debug, Clone)]
pub(crate) struct BigIntHeapData {
pub struct BigIntHeapData {
pub(super) sign: bool,
pub(super) len: u32,
pub(super) parts: Box<[u64]>,
}

impl BigIntHeapData {
pub(crate) fn len(&self) -> u32 {
pub fn len(&self) -> u32 {
self.len
}

pub(crate) fn try_into_f64(&self) -> Option<f64> {
pub fn try_into_f64(&self) -> Option<f64> {
if self.len == 1 {
Some(self.parts[0] as f64)
} else {
Expand Down
2 changes: 1 addition & 1 deletion nova_vm/src/heap/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::{
};

#[derive(Debug, Clone, Copy)]
pub(crate) struct DateHeapData {
pub struct DateHeapData {
pub(super) object_index: ObjectIndex,
pub(super) _date: SystemTime,
}
Expand Down
78 changes: 39 additions & 39 deletions nova_vm/src/heap/element_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use core::panic;
use std::{collections::HashMap, mem::MaybeUninit, num::NonZeroU16};

#[derive(Debug, Clone, Copy)]
pub(crate) enum ElementArrayKey {
pub enum ElementArrayKey {
/// up to 16 elements
E4,
/// up to 64 elements
Expand Down Expand Up @@ -51,10 +51,10 @@ impl From<usize> for ElementArrayKey {
}

#[derive(Debug, Clone, Copy)]
pub(crate) struct ElementsVector {
pub(crate) elements_index: ElementIndex,
pub(crate) cap: ElementArrayKey,
pub(crate) len: u32,
pub struct ElementsVector {
pub elements_index: ElementIndex,
pub cap: ElementArrayKey,
pub len: u32,
}

#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -386,9 +386,9 @@ impl ElementDescriptor {

/// Element arrays of up to 16 elements
#[derive(Debug)]
pub(crate) struct ElementArray2Pow4 {
pub(crate) values: Vec<Option<[Option<Value>; usize::pow(2, 4)]>>,
pub(crate) descriptors: HashMap<ElementIndex, HashMap<u32, ElementDescriptor>>,
pub struct ElementArray2Pow4 {
pub values: Vec<Option<[Option<Value>; usize::pow(2, 4)]>>,
pub descriptors: HashMap<ElementIndex, HashMap<u32, ElementDescriptor>>,
}

impl Default for ElementArray2Pow4 {
Expand All @@ -411,9 +411,9 @@ impl ElementArray2Pow4 {

/// Element arrays of up to 64 elements
#[derive(Debug)]
pub(crate) struct ElementArray2Pow6 {
pub(crate) values: Vec<Option<[Option<Value>; usize::pow(2, 6)]>>,
pub(crate) descriptors: HashMap<ElementIndex, HashMap<u32, ElementDescriptor>>,
pub struct ElementArray2Pow6 {
pub values: Vec<Option<[Option<Value>; usize::pow(2, 6)]>>,
pub descriptors: HashMap<ElementIndex, HashMap<u32, ElementDescriptor>>,
}

impl Default for ElementArray2Pow6 {
Expand All @@ -436,9 +436,9 @@ impl ElementArray2Pow6 {

/// Element arrays of up to 256 elements
#[derive(Debug)]
pub(crate) struct ElementArray2Pow8 {
pub(crate) values: Vec<Option<[Option<Value>; usize::pow(2, 8)]>>,
pub(crate) descriptors: HashMap<ElementIndex, HashMap<u32, ElementDescriptor>>,
pub struct ElementArray2Pow8 {
pub values: Vec<Option<[Option<Value>; usize::pow(2, 8)]>>,
pub descriptors: HashMap<ElementIndex, HashMap<u32, ElementDescriptor>>,
}

impl Default for ElementArray2Pow8 {
Expand All @@ -461,9 +461,9 @@ impl ElementArray2Pow8 {

/// Element arrays of up to 1024 elements
#[derive(Debug)]
pub(crate) struct ElementArray2Pow10 {
pub(crate) values: Vec<Option<[Option<Value>; usize::pow(2, 10)]>>,
pub(crate) descriptors: HashMap<ElementIndex, HashMap<u32, ElementDescriptor>>,
pub struct ElementArray2Pow10 {
pub values: Vec<Option<[Option<Value>; usize::pow(2, 10)]>>,
pub descriptors: HashMap<ElementIndex, HashMap<u32, ElementDescriptor>>,
}

impl Default for ElementArray2Pow10 {
Expand All @@ -486,9 +486,9 @@ impl ElementArray2Pow10 {

/// Element arrays of up to 4096 elements
#[derive(Debug)]
pub(crate) struct ElementArray2Pow12 {
pub(crate) values: Vec<Option<[Option<Value>; usize::pow(2, 12)]>>,
pub(crate) descriptors: HashMap<ElementIndex, HashMap<u32, ElementDescriptor>>,
pub struct ElementArray2Pow12 {
pub values: Vec<Option<[Option<Value>; usize::pow(2, 12)]>>,
pub descriptors: HashMap<ElementIndex, HashMap<u32, ElementDescriptor>>,
}

impl Default for ElementArray2Pow12 {
Expand All @@ -511,9 +511,9 @@ impl ElementArray2Pow12 {

/// Element arrays of up to 65536 elements
#[derive(Debug)]
pub(crate) struct ElementArray2Pow16 {
pub(crate) values: Vec<Option<[Option<Value>; usize::pow(2, 16)]>>,
pub(crate) descriptors: HashMap<ElementIndex, HashMap<u32, ElementDescriptor>>,
pub struct ElementArray2Pow16 {
pub values: Vec<Option<[Option<Value>; usize::pow(2, 16)]>>,
pub descriptors: HashMap<ElementIndex, HashMap<u32, ElementDescriptor>>,
}

impl Default for ElementArray2Pow16 {
Expand All @@ -536,9 +536,9 @@ impl ElementArray2Pow16 {

/// Element arrays of up to 16777216 elements
#[derive(Debug)]
pub(crate) struct ElementArray2Pow24 {
pub(crate) values: Vec<Option<[Option<Value>; usize::pow(2, 24)]>>,
pub(crate) descriptors: HashMap<ElementIndex, HashMap<u32, ElementDescriptor>>,
pub struct ElementArray2Pow24 {
pub values: Vec<Option<[Option<Value>; usize::pow(2, 24)]>>,
pub descriptors: HashMap<ElementIndex, HashMap<u32, ElementDescriptor>>,
}

impl Default for ElementArray2Pow24 {
Expand All @@ -561,9 +561,9 @@ impl ElementArray2Pow24 {

/// Element arrays of up to 4294967296 elements
#[derive(Debug)]
pub(crate) struct ElementArray2Pow32 {
pub(crate) values: Vec<Option<[Option<Value>; usize::pow(2, 32)]>>,
pub(crate) descriptors: HashMap<ElementIndex, HashMap<u32, ElementDescriptor>>,
pub struct ElementArray2Pow32 {
pub values: Vec<Option<[Option<Value>; usize::pow(2, 32)]>>,
pub descriptors: HashMap<ElementIndex, HashMap<u32, ElementDescriptor>>,
}

impl Default for ElementArray2Pow32 {
Expand All @@ -585,23 +585,23 @@ impl ElementArray2Pow32 {
}

#[derive(Debug)]
pub(crate) struct ElementArrays {
pub struct ElementArrays {
/// up to 16 elements
pub(crate) e2pow4: ElementArray2Pow4,
pub e2pow4: ElementArray2Pow4,
/// up to 64 elements
pub(crate) e2pow6: ElementArray2Pow6,
pub e2pow6: ElementArray2Pow6,
/// up to 256 elements
pub(crate) e2pow8: ElementArray2Pow8,
pub e2pow8: ElementArray2Pow8,
/// up to 1024 elements
pub(crate) e2pow10: ElementArray2Pow10,
pub e2pow10: ElementArray2Pow10,
/// up to 4096 elements
pub(crate) e2pow12: ElementArray2Pow12,
pub e2pow12: ElementArray2Pow12,
/// up to 65536 elements
pub(crate) e2pow16: ElementArray2Pow16,
pub e2pow16: ElementArray2Pow16,
/// up to 16777216 elements
pub(crate) e2pow24: ElementArray2Pow24,
pub e2pow24: ElementArray2Pow24,
/// up to 4294967296 elements
pub(crate) e2pow32: ElementArray2Pow32,
pub e2pow32: ElementArray2Pow32,
}

impl ElementArrays {
Expand Down Expand Up @@ -775,7 +775,7 @@ impl ElementArrays {
}
}

pub(crate) fn create_object_entries(
pub fn create_object_entries(
&mut self,
mut entries: Vec<ObjectEntry>,
) -> (ElementsVector, ElementsVector) {
Expand Down
2 changes: 1 addition & 1 deletion nova_vm/src/heap/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::{
};

#[derive(Debug, Clone, Copy)]
pub(crate) struct ErrorHeapData {
pub struct ErrorHeapData {
pub(super) object_index: ObjectIndex,
// TODO: stack? name?
}
Expand Down
2 changes: 1 addition & 1 deletion nova_vm/src/heap/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use super::{
pub type JsBindingFunction = fn(heap: &mut Heap, this: Value, args: &[Value]) -> JsResult<Value>;

#[derive(Debug, Clone)]
pub(crate) struct FunctionHeapData {
pub struct FunctionHeapData {
pub(super) object_index: ObjectIndex,
pub(super) length: u8,
pub(super) uses_arguments: bool,
Expand Down
12 changes: 6 additions & 6 deletions nova_vm/src/heap/heap_bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use super::{
Heap,
};

pub(crate) struct HeapBits {
pub struct HeapBits {
pub e_2_4: Box<[AtomicBool]>,
pub e_2_6: Box<[AtomicBool]>,
pub e_2_8: Box<[AtomicBool]>,
Expand All @@ -32,7 +32,7 @@ pub(crate) struct HeapBits {
pub symbols: Box<[AtomicBool]>,
}

pub(crate) struct WorkQueues {
pub struct WorkQueues {
pub e_2_4: Vec<ElementIndex>,
pub e_2_6: Vec<ElementIndex>,
pub e_2_8: Vec<ElementIndex>,
Expand All @@ -55,7 +55,7 @@ pub(crate) struct WorkQueues {
}

impl HeapBits {
pub(crate) fn new(heap: &Heap) -> Self {
pub fn new(heap: &Heap) -> Self {
Self {
e_2_4: Vec::with_capacity(heap.elements.e2pow4.values.len()).into_boxed_slice(),
e_2_6: Vec::with_capacity(heap.elements.e2pow6.values.len()).into_boxed_slice(),
Expand All @@ -81,7 +81,7 @@ impl HeapBits {
}

impl WorkQueues {
pub(crate) fn new(heap: &Heap) -> Self {
pub fn new(heap: &Heap) -> Self {
Self {
e_2_4: Vec::with_capacity(heap.elements.e2pow4.values.len() / 4),
e_2_6: Vec::with_capacity(heap.elements.e2pow6.values.len() / 4),
Expand All @@ -105,7 +105,7 @@ impl WorkQueues {
}
}

pub(crate) fn push_value(&mut self, value: Value) {
pub fn push_value(&mut self, value: Value) {
match value {
Value::Array(idx) => self.arrays.push(idx),
Value::ArrayBuffer(idx) => self.array_buffers.push(idx),
Expand Down Expand Up @@ -139,7 +139,7 @@ impl WorkQueues {
}
}

pub(crate) fn is_empty(&self) -> bool {
pub fn is_empty(&self) -> bool {
self.e_2_4.is_empty()
&& self.e_2_6.is_empty()
&& self.e_2_8.is_empty()
Expand Down
6 changes: 4 additions & 2 deletions nova_vm/src/heap/heap_gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::{
ElementsVector, Heap,
};

pub(crate) fn heap_gc(heap: &mut Heap) {
pub fn heap_gc(heap: &mut Heap) {
let bits = HeapBits::new(heap);
let mut queues = WorkQueues::new(heap);

Expand All @@ -32,7 +32,9 @@ pub(crate) fn heap_gc(heap: &mut Heap) {
}
marked.store(true, Ordering::Relaxed);
let heap_data = heap.arrays.get(index).unwrap().as_ref().unwrap();
queues.push_value(Value::Object(heap_data.object_index));
if let Some(data) = heap_data.object_index {
queues.push_value(Value::Object(data));
}
let ElementsVector {
elements_index,
cap,
Expand Down
Loading

0 comments on commit 40bcd48

Please sign in to comment.