Website Summary Files Commits Branches @commit @diff @stats
path: root / JSImpl / test / empty.cpp
diff options
context:
space:
mode:
Commit43b6cf4a91e0222d9840ae4474df38f93dd13ac5 (patch)
Author
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-11-26 21:47:02 +0200
Committer
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-11-26 21:47:02 +0200
Filesbbb343f6198ada4d413169f853d8a301ecbdce66 /JSImpl/test/empty.cpp
IPL-43b6cf4a91e0222d9840ae4474df38f93dd13ac5.tar
IPL-43b6cf4a91e0222d9840ae4474df38f93dd13ac5.tar.gz
IPL-43b6cf4a91e0222d9840ae4474df38f93dd13ac5.zip
Parentf6cdfe77480452f152b916e129fa7ae06ed1a37b (diff)
Made spasm to work with nan-boxed values
1 files changed, 6 insertions, 72 deletions
-rw-r--r--JSImpl/test/empty.cpp78
diff --git a/JSImpl/test/empty.cpp b/JSImpl/test/empty.cpp
index 2725467..8bf7d13 100644
--- a/JSImpl/test/empty.cpp
+++ b/JSImpl/test/empty.cpp
@@ -1,6 +1,7 @@
#include <gtest/gtest.h>
#include <memory>
#include <cmath>
+#include <spasm.hpp>
TEST(Empty, Empty)
{
@@ -60,73 +61,6 @@ TEST(Pointer, int64)
ASSERT_EQ(data + 9, PC);
}
-/*
- * Value will be either a double, undefined, null, string, array, object,
- * function, boolean.
- *
- * Pointer values (like string, array, object, function) can be shared pointers
- * via intrusive pointer implementation. This way we can get a reference
- * counting garbage collection.
- *
- */
-struct Value
-{
- Value(double v)
- {
- m_value.as_double = v;
- }
-
- Value(int tag, void* pointer)
- {
- assert(tag && "Zero tag is plain double");
- assert(!((size_t)pointer >> 48) && "Use only pointers to the heap.");
- m_value.as_pointer.pointer = (size_t)pointer;
- m_value.as_pointer.tag = tag;
- m_value.as_pointer.nan = 0x1fff;
- }
- struct NanPointer
- {
- size_t pointer:48;
- size_t tag:3;
- size_t nan:13;
- };
-
- struct CheckType
- {
- size_t payload: 48;
- size_t check:16;
- };
- union {
- double as_double;
- NanPointer as_pointer;
- CheckType to_check;
-
- } m_value;
-
- static_assert(sizeof(size_t) == 8, "unsupported arch");
- static_assert(sizeof(double) == 8, "unsupported arch");
-
- bool is_double() const
- {
- return m_value.to_check.check <= 0xFFF8;
- }
-
- double get_double() const
- {
- assert(is_double());
- return m_value.as_double;
- }
-
- int get_tag() {
- assert(!is_double());
- return m_value.as_pointer.tag;
- }
-
- void* get_pointer() const {
- return (void*)(size_t) m_value.as_pointer.pointer;
- }
-};
-
TEST(NaNBox, PlainDoubles)
{
@@ -136,11 +70,11 @@ TEST(NaNBox, PlainDoubles)
};
for (auto value: values)
{
- Value box(value);
+ Spasm::Value box(value);
ASSERT_TRUE(box.is_double());
ASSERT_EQ(value, box.get_double());
- Value box2(-value);
+ Spasm::Value box2(-value);
ASSERT_TRUE(box2.is_double());
ASSERT_EQ(-value, box2.get_double());
}
@@ -148,14 +82,14 @@ TEST(NaNBox, PlainDoubles)
TEST(NaNBox, Border)
{
- Value v(2, nullptr);
+ Spasm::Value v(Spasm::ValueType::Object, nullptr);
ASSERT_TRUE(std::isnan(v.m_value.as_double));
ASSERT_FALSE(std::isinf(v.m_value.as_double));
}
TEST(NaNBox, IsNaN)
{
- Value v2(std::sqrt(-1.0));
+ Spasm::Value v2(std::sqrt(-1.0));
ASSERT_TRUE(v2.is_double());
}
@@ -171,7 +105,7 @@ TEST(NaNBox, Pointers)
for (auto& value: pointers)
{
- Value box(1, value.get());
+ Spasm::Value box(Spasm::ValueType::Object, value.get());
ASSERT_FALSE(box.is_double());
ASSERT_EQ(value.get(), box.get_pointer());
}