Skip to content

Commit

Permalink
Initial implementation of NaN-boxing
Browse files Browse the repository at this point in the history
Co-authored-by: HalidOdat <[email protected]>
  • Loading branch information
HalidOdat authored and jedel1043 committed Sep 8, 2022
1 parent ba91449 commit f6bf8f4
Show file tree
Hide file tree
Showing 82 changed files with 2,391 additions and 1,110 deletions.
49 changes: 49 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion boa_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct Opt {
#[clap(long, short = 'a', value_name = "FORMAT", ignore_case = true, arg_enum)]
dump_ast: Option<Option<DumpFormat>>,

/// Dump the AST to stdout with the given format.
/// Dump the compiled bytecode and trace the execution stack
#[clap(long = "trace", short = 't')]
trace: bool,

Expand Down
4 changes: 4 additions & 0 deletions boa_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ intl = [
"dep:icu_testdata",
"dep:sys-locale"
]
nan_boxing = ["dep:sptr", "dep:num_enum"]

# Enable Boa's WHATWG console object implementation.
console = []
Expand Down Expand Up @@ -50,6 +51,9 @@ unicode-normalization = "0.1.21"
dyn-clone = "1.0.9"
once_cell = "1.14.0"
tap = "1.0.1"
cfg-if = "1.0.0"
sptr = { version = "0.3.1", optional = true }
num_enum = { version = "0.5.7", optional = true }
icu_locale_canonicalizer = { version = "0.6.0", features = ["serde"], optional = true }
icu_locid = { version = "0.6.0", features = ["serde"], optional = true }
icu_datetime = { version = "0.6.0", features = ["serde"], optional = true }
Expand Down
13 changes: 12 additions & 1 deletion boa_engine/src/bigint.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! This module implements the JavaScript bigint primitive rust type.

use crate::{builtins::Number, Context, JsValue};
use crate::{builtins::Number, value::PointerType, Context, JsValue};
use num_integer::Integer;
use num_traits::{pow::Pow, FromPrimitive, One, ToPrimitive, Zero};
use std::{
fmt::{self, Display},
mem::{self, ManuallyDrop},
ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Rem, Shl, Shr, Sub},
rc::Rc,
};
Expand All @@ -22,6 +23,16 @@ pub struct JsBigInt {
inner: Rc<RawBigInt>,
}

unsafe impl PointerType for JsBigInt {
unsafe fn from_void_ptr(ptr: *mut ()) -> ManuallyDrop<Self> {
ManuallyDrop::new(mem::transmute(ptr))
}

unsafe fn into_void_ptr(bigint: ManuallyDrop<Self>) -> *mut () {
mem::transmute(bigint)
}
}

impl JsBigInt {
/// Create a new [`JsBigInt`].
#[inline]
Expand Down
3 changes: 2 additions & 1 deletion boa_engine/src/builtins/array/array_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ impl ArrayIterator {
///
/// [spec]: https://tc39.es/ecma262/#sec-%arrayiteratorprototype%.next
pub(crate) fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let mut array_iterator = this.as_object().map(JsObject::borrow_mut);
let array_iterator = this.as_object();
let mut array_iterator = array_iterator.as_deref().map(JsObject::borrow_mut);
let array_iterator = array_iterator
.as_mut()
.and_then(|obj| obj.as_array_iterator_mut())
Expand Down
Loading

0 comments on commit f6bf8f4

Please sign in to comment.