iv-phonic 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Manifest.txt +45 -0
- data/Rakefile +6 -1
- data/ext/include/iv/about.h +7 -0
- data/ext/include/iv/ast_factory.h +2 -1
- data/ext/include/iv/byteorder.h +20 -0
- data/ext/include/iv/dtoa.h +83 -2
- data/ext/include/iv/netlib-dtoa.h +4320 -0
- data/ext/include/iv/parser.h +35 -4
- data/ext/iv/phonic/README +34 -0
- data/ext/iv/phonic/SConscript +8 -0
- data/ext/iv/phonic/ast_fwd.h +16 -2
- data/ext/iv/phonic/cached-powers.h +119 -0
- data/ext/iv/phonic/checks.cc +57 -0
- data/ext/iv/phonic/checks.h +93 -0
- data/ext/iv/phonic/conversions.cc +123 -0
- data/ext/iv/phonic/conversions.h +41 -0
- data/ext/iv/phonic/creator.h +55 -53
- data/ext/iv/phonic/diy-fp.cc +58 -0
- data/ext/iv/phonic/diy-fp.h +117 -0
- data/ext/iv/phonic/double.h +169 -0
- data/ext/iv/phonic/dtoa.h +81 -0
- data/ext/iv/phonic/extconf.rb +1 -0
- data/ext/iv/phonic/factory.h +3 -1
- data/ext/iv/phonic/fast-dtoa.cc +505 -0
- data/ext/iv/phonic/fast-dtoa.h +58 -0
- data/ext/iv/phonic/globals.h +69 -0
- data/ext/iv/phonic/include-v8.h +59 -0
- data/ext/iv/phonic/platform.cc +111 -0
- data/ext/iv/phonic/platform.h +100 -0
- data/ext/iv/phonic/powers-ten.h +2461 -0
- data/ext/iv/phonic/utils.cc +91 -0
- data/ext/iv/phonic/utils.h +165 -0
- data/ext/iv/phonic/v8-dtoa.cc +79 -0
- data/ext/iv/phonic/v8.h +51 -0
- data/test/test_iv_phonic.rb +1 -1
- metadata +26 -1
data/ext/include/iv/parser.h
CHANGED
@@ -10,6 +10,7 @@
|
|
10
10
|
#include "ast.h"
|
11
11
|
#include "ast_factory.h"
|
12
12
|
#include "lexer.h"
|
13
|
+
#include "dtoa.h"
|
13
14
|
#include "noncopyable.h"
|
14
15
|
#include "utils.h"
|
15
16
|
#include "ustring.h"
|
@@ -1887,7 +1888,9 @@ class Parser
|
|
1887
1888
|
token_ == Token::STRING ||
|
1888
1889
|
token_ == Token::NUMBER) {
|
1889
1890
|
if (token_ == Token::NUMBER) {
|
1890
|
-
ident =
|
1891
|
+
ident = ParseIdentifierNumber();
|
1892
|
+
} else if (token_ == Token::STRING) {
|
1893
|
+
ident = ParseIdentifierString(lexer_.Buffer());
|
1891
1894
|
} else {
|
1892
1895
|
ident = ParseIdentifier(lexer_.Buffer());
|
1893
1896
|
}
|
@@ -1920,7 +1923,9 @@ class Parser
|
|
1920
1923
|
token_ == Token::STRING ||
|
1921
1924
|
token_ == Token::NUMBER) {
|
1922
1925
|
if (token_ == Token::NUMBER) {
|
1923
|
-
ident =
|
1926
|
+
ident = ParseIdentifierNumber();
|
1927
|
+
} else if (token_ == Token::STRING) {
|
1928
|
+
ident = ParseIdentifierString(lexer_.Buffer());
|
1924
1929
|
} else {
|
1925
1930
|
ident = ParseIdentifier(lexer_.Buffer());
|
1926
1931
|
}
|
@@ -2141,9 +2146,34 @@ class Parser
|
|
2141
2146
|
end_block_position);
|
2142
2147
|
}
|
2143
2148
|
|
2149
|
+
Identifier* ParseIdentifierNumber() {
|
2150
|
+
const double val = lexer_.Numeric();
|
2151
|
+
std::tr1::array<char, 80> buf;
|
2152
|
+
DoubleToCString(val, buf.data(), buf.size());
|
2153
|
+
Identifier* const ident = factory_->NewIdentifier(
|
2154
|
+
Token::NUMBER,
|
2155
|
+
core::StringPiece(buf.data(), std::strlen(buf.data())),
|
2156
|
+
lexer_.begin_position(),
|
2157
|
+
lexer_.end_position());
|
2158
|
+
Next();
|
2159
|
+
return ident;
|
2160
|
+
}
|
2161
|
+
|
2162
|
+
|
2163
|
+
template<typename Range>
|
2164
|
+
Identifier* ParseIdentifierString(const Range& range) {
|
2165
|
+
Identifier* const ident = factory_->NewIdentifier(Token::STRING,
|
2166
|
+
range,
|
2167
|
+
lexer_.begin_position(),
|
2168
|
+
lexer_.end_position());
|
2169
|
+
Next();
|
2170
|
+
return ident;
|
2171
|
+
}
|
2172
|
+
|
2144
2173
|
template<typename Range>
|
2145
2174
|
Identifier* ParseIdentifier(const Range& range) {
|
2146
|
-
Identifier* const ident = factory_->NewIdentifier(
|
2175
|
+
Identifier* const ident = factory_->NewIdentifier(Token::IDENTIFIER,
|
2176
|
+
range,
|
2147
2177
|
lexer_.begin_position(),
|
2148
2178
|
lexer_.end_position());
|
2149
2179
|
Next();
|
@@ -2154,7 +2184,8 @@ class Parser
|
|
2154
2184
|
Identifier* ParseIdentifierWithPosition(const Range& range,
|
2155
2185
|
std::size_t begin,
|
2156
2186
|
std::size_t end) {
|
2157
|
-
Identifier* const ident = factory_->NewIdentifier(
|
2187
|
+
Identifier* const ident = factory_->NewIdentifier(Token::IDENTIFIER,
|
2188
|
+
range,
|
2158
2189
|
begin,
|
2159
2190
|
end);
|
2160
2191
|
Next();
|
@@ -0,0 +1,34 @@
|
|
1
|
+
This directory contains V8's fast dtoa conversion code. The V8 revision
|
2
|
+
imported was:
|
3
|
+
|
4
|
+
Repository Root: http://v8.googlecode.com/svn
|
5
|
+
Repository UUID: ce2b1a6d-e550-0410-aec6-3dcde31c8c00
|
6
|
+
Revision: 5322
|
7
|
+
|
8
|
+
The function of interest, which is called by SpiderMonkey, is
|
9
|
+
conversions.cc:DoubleToCString(). This is called from jsnum.cpp to provide a
|
10
|
+
fast Number.toString(10) implementation.
|
11
|
+
|
12
|
+
A great deal of code has been removed from the imported files. The
|
13
|
+
remaining code is more or less the bare minimum required to support this
|
14
|
+
function in a straightforward, standalone manner.
|
15
|
+
|
16
|
+
Two related functions in V8 are DoubleToExponentialCString() and
|
17
|
+
DoubleToPrecisionString(), which can be used to implement
|
18
|
+
Number.toExponential() and Number.toPrecision(). They have not been imported;
|
19
|
+
they both call dtoa() and so are unlikely to be noticeably faster than the
|
20
|
+
existing SpiderMonkey equivalents.
|
21
|
+
|
22
|
+
Another related function in V8 is DoubleToRadixCString(), which can be used to
|
23
|
+
implement Number.toString(base), where base != 10. This has not been imported;
|
24
|
+
it may well be faster than SpiderMonkey's implementation, but V8 generates its
|
25
|
+
own definition of the modulo() function on Win64 and importing this would
|
26
|
+
require also importing large chunks of the assembler, which is not worthwhile.
|
27
|
+
|
28
|
+
Yet another related function in V8 is DoubleToFixedCString(), which can be used
|
29
|
+
to implement Number.toFixed(). This has not been imported as it was measured
|
30
|
+
as slower than SpiderMonkey's version.
|
31
|
+
|
32
|
+
Comments preceded by the string "MOZ: " indicate places where the code has
|
33
|
+
been changed significantly from the original code.
|
34
|
+
|
data/ext/iv/phonic/ast_fwd.h
CHANGED
@@ -13,8 +13,8 @@ namespace core {
|
|
13
13
|
namespace ast {
|
14
14
|
|
15
15
|
template<>
|
16
|
-
class AstNodeBase<
|
17
|
-
: public Inherit<
|
16
|
+
class AstNodeBase<phonic::AstFactory>
|
17
|
+
: public Inherit<phonic::AstFactory, kAstNode> {
|
18
18
|
public:
|
19
19
|
void Location(std::size_t begin, std::size_t end) {
|
20
20
|
begin_ = begin;
|
@@ -31,6 +31,20 @@ class AstNodeBase<iv::phonic::AstFactory>
|
|
31
31
|
std::size_t end_;
|
32
32
|
};
|
33
33
|
|
34
|
+
template<>
|
35
|
+
class IdentifierBase<phonic::AstFactory>
|
36
|
+
: public Inherit<phonic::AstFactory, kIdentifier> {
|
37
|
+
public:
|
38
|
+
void set_type(core::Token::Type type) {
|
39
|
+
type_ = type;
|
40
|
+
}
|
41
|
+
core::Token::Type type() const {
|
42
|
+
return type_;
|
43
|
+
}
|
44
|
+
private:
|
45
|
+
core::Token::Type type_;
|
46
|
+
};
|
47
|
+
|
34
48
|
} } // namespace iv::core::ast
|
35
49
|
|
36
50
|
namespace phonic {
|
@@ -0,0 +1,119 @@
|
|
1
|
+
// Copyright 2010 the V8 project authors. All rights reserved.
|
2
|
+
// Redistribution and use in source and binary forms, with or without
|
3
|
+
// modification, are permitted provided that the following conditions are
|
4
|
+
// met:
|
5
|
+
//
|
6
|
+
// * Redistributions of source code must retain the above copyright
|
7
|
+
// notice, this list of conditions and the following disclaimer.
|
8
|
+
// * Redistributions in binary form must reproduce the above
|
9
|
+
// copyright notice, this list of conditions and the following
|
10
|
+
// disclaimer in the documentation and/or other materials provided
|
11
|
+
// with the distribution.
|
12
|
+
// * Neither the name of Google Inc. nor the names of its
|
13
|
+
// contributors may be used to endorse or promote products derived
|
14
|
+
// from this software without specific prior written permission.
|
15
|
+
//
|
16
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
18
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
19
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
20
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
23
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
|
28
|
+
#ifndef V8_CACHED_POWERS_H_
|
29
|
+
#define V8_CACHED_POWERS_H_
|
30
|
+
|
31
|
+
#include "diy-fp.h"
|
32
|
+
|
33
|
+
namespace v8 {
|
34
|
+
namespace internal {
|
35
|
+
|
36
|
+
struct CachedPower {
|
37
|
+
uint64_t significand;
|
38
|
+
int16_t binary_exponent;
|
39
|
+
int16_t decimal_exponent;
|
40
|
+
};
|
41
|
+
|
42
|
+
// The following defines implement the interface between this file and the
|
43
|
+
// generated 'powers_ten.h'.
|
44
|
+
// GRISU_CACHE_NAME(1) contains all possible cached powers.
|
45
|
+
// GRISU_CACHE_NAME(i) contains GRISU_CACHE_NAME(1) where only every 'i'th
|
46
|
+
// element is kept. More formally GRISU_CACHE_NAME(i) contains the elements j*i
|
47
|
+
// with 0 <= j < k with k such that j*k < the size of GRISU_CACHE_NAME(1).
|
48
|
+
// The higher 'i' is the fewer elements we use.
|
49
|
+
// Given that there are less elements, the exponent-distance between two
|
50
|
+
// elements in the cache grows. The variable GRISU_CACHE_MAX_DISTANCE(i) stores
|
51
|
+
// the maximum distance between two elements.
|
52
|
+
#define GRISU_CACHE_STRUCT CachedPower
|
53
|
+
#define GRISU_CACHE_NAME(i) kCachedPowers##i
|
54
|
+
#define GRISU_CACHE_MAX_DISTANCE(i) kCachedPowersMaxDistance##i
|
55
|
+
#define GRISU_CACHE_OFFSET kCachedPowerOffset
|
56
|
+
#define GRISU_UINT64_C V8_2PART_UINT64_C
|
57
|
+
// The following include imports the precompiled cached powers.
|
58
|
+
#include "powers-ten.h" // NOLINT
|
59
|
+
|
60
|
+
static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10)
|
61
|
+
|
62
|
+
// We can't use a function since we reference variables depending on the 'i'.
|
63
|
+
// This way the compiler is able to see at compile time that only one
|
64
|
+
// cache-array variable is used and thus can remove all the others.
|
65
|
+
#define COMPUTE_FOR_CACHE(i) \
|
66
|
+
if (!found && (gamma - alpha + 1 >= GRISU_CACHE_MAX_DISTANCE(i))) { \
|
67
|
+
int kQ = DiyFp::kSignificandSize; \
|
68
|
+
double k = ceiling((alpha - e + kQ - 1) * kD_1_LOG2_10); \
|
69
|
+
int index = (GRISU_CACHE_OFFSET + static_cast<int>(k) - 1) / i + 1; \
|
70
|
+
cached_power = GRISU_CACHE_NAME(i)[index]; \
|
71
|
+
found = true; \
|
72
|
+
} \
|
73
|
+
|
74
|
+
static void GetCachedPower(int e, int alpha, int gamma, int* mk, DiyFp* c_mk) {
|
75
|
+
// The following if statement should be optimized by the compiler so that only
|
76
|
+
// one array is referenced and the others are not included in the object file.
|
77
|
+
bool found = false;
|
78
|
+
CachedPower cached_power;
|
79
|
+
COMPUTE_FOR_CACHE(20);
|
80
|
+
COMPUTE_FOR_CACHE(19);
|
81
|
+
COMPUTE_FOR_CACHE(18);
|
82
|
+
COMPUTE_FOR_CACHE(17);
|
83
|
+
COMPUTE_FOR_CACHE(16);
|
84
|
+
COMPUTE_FOR_CACHE(15);
|
85
|
+
COMPUTE_FOR_CACHE(14);
|
86
|
+
COMPUTE_FOR_CACHE(13);
|
87
|
+
COMPUTE_FOR_CACHE(12);
|
88
|
+
COMPUTE_FOR_CACHE(11);
|
89
|
+
COMPUTE_FOR_CACHE(10);
|
90
|
+
COMPUTE_FOR_CACHE(9);
|
91
|
+
COMPUTE_FOR_CACHE(8);
|
92
|
+
COMPUTE_FOR_CACHE(7);
|
93
|
+
COMPUTE_FOR_CACHE(6);
|
94
|
+
COMPUTE_FOR_CACHE(5);
|
95
|
+
COMPUTE_FOR_CACHE(4);
|
96
|
+
COMPUTE_FOR_CACHE(3);
|
97
|
+
COMPUTE_FOR_CACHE(2);
|
98
|
+
COMPUTE_FOR_CACHE(1);
|
99
|
+
if (!found) {
|
100
|
+
UNIMPLEMENTED();
|
101
|
+
// Silence compiler warnings.
|
102
|
+
cached_power.significand = 0;
|
103
|
+
cached_power.binary_exponent = 0;
|
104
|
+
cached_power.decimal_exponent = 0;
|
105
|
+
}
|
106
|
+
*c_mk = DiyFp(cached_power.significand, cached_power.binary_exponent);
|
107
|
+
*mk = cached_power.decimal_exponent;
|
108
|
+
ASSERT((alpha <= c_mk->e() + e) && (c_mk->e() + e <= gamma));
|
109
|
+
}
|
110
|
+
#undef GRISU_REDUCTION
|
111
|
+
#undef GRISU_CACHE_STRUCT
|
112
|
+
#undef GRISU_CACHE_NAME
|
113
|
+
#undef GRISU_CACHE_MAX_DISTANCE
|
114
|
+
#undef GRISU_CACHE_OFFSET
|
115
|
+
#undef GRISU_UINT64_C
|
116
|
+
|
117
|
+
} } // namespace v8::internal
|
118
|
+
|
119
|
+
#endif // V8_CACHED_POWERS_H_
|
@@ -0,0 +1,57 @@
|
|
1
|
+
// Copyright 2006-2008 the V8 project authors. All rights reserved.
|
2
|
+
// Redistribution and use in source and binary forms, with or without
|
3
|
+
// modification, are permitted provided that the following conditions are
|
4
|
+
// met:
|
5
|
+
//
|
6
|
+
// * Redistributions of source code must retain the above copyright
|
7
|
+
// notice, this list of conditions and the following disclaimer.
|
8
|
+
// * Redistributions in binary form must reproduce the above
|
9
|
+
// copyright notice, this list of conditions and the following
|
10
|
+
// disclaimer in the documentation and/or other materials provided
|
11
|
+
// with the distribution.
|
12
|
+
// * Neither the name of Google Inc. nor the names of its
|
13
|
+
// contributors may be used to endorse or promote products derived
|
14
|
+
// from this software without specific prior written permission.
|
15
|
+
//
|
16
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
18
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
19
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
20
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
23
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
|
28
|
+
#include <stdarg.h>
|
29
|
+
#include <signal.h>
|
30
|
+
|
31
|
+
#include "v8.h"
|
32
|
+
|
33
|
+
static int fatal_error_handler_nesting_depth = 0;
|
34
|
+
|
35
|
+
// Contains protection against recursive calls (faults while handling faults).
|
36
|
+
extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) {
|
37
|
+
fflush(stdout);
|
38
|
+
fflush(stderr);
|
39
|
+
fatal_error_handler_nesting_depth++;
|
40
|
+
// First time we try to print an error message
|
41
|
+
//
|
42
|
+
// MOZ: lots of calls to printing functions within v8::internal::OS were
|
43
|
+
// replaced with simpler standard C calls, to avoid pulling in lots of
|
44
|
+
// platform-specific code. As a result, in some cases the error message may
|
45
|
+
// not be printed as well or at all.
|
46
|
+
if (fatal_error_handler_nesting_depth < 2) {
|
47
|
+
fprintf(stderr, "\n\n#\n# Fatal error in %s, line %d\n# ", file, line);
|
48
|
+
va_list arguments;
|
49
|
+
va_start(arguments, format);
|
50
|
+
vfprintf(stderr, format, arguments);
|
51
|
+
va_end(arguments);
|
52
|
+
fprintf(stderr, "\n#\n\n");
|
53
|
+
}
|
54
|
+
|
55
|
+
i::OS::Abort();
|
56
|
+
}
|
57
|
+
|
@@ -0,0 +1,93 @@
|
|
1
|
+
// Copyright 2006-2008 the V8 project authors. All rights reserved.
|
2
|
+
// Redistribution and use in source and binary forms, with or without
|
3
|
+
// modification, are permitted provided that the following conditions are
|
4
|
+
// met:
|
5
|
+
//
|
6
|
+
// * Redistributions of source code must retain the above copyright
|
7
|
+
// notice, this list of conditions and the following disclaimer.
|
8
|
+
// * Redistributions in binary form must reproduce the above
|
9
|
+
// copyright notice, this list of conditions and the following
|
10
|
+
// disclaimer in the documentation and/or other materials provided
|
11
|
+
// with the distribution.
|
12
|
+
// * Neither the name of Google Inc. nor the names of its
|
13
|
+
// contributors may be used to endorse or promote products derived
|
14
|
+
// from this software without specific prior written permission.
|
15
|
+
//
|
16
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
18
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
19
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
20
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
23
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
|
28
|
+
#ifndef V8_CHECKS_H_
|
29
|
+
#define V8_CHECKS_H_
|
30
|
+
|
31
|
+
#include <string.h>
|
32
|
+
|
33
|
+
extern "C" void V8_Fatal(const char* file, int line, const char* format, ...);
|
34
|
+
|
35
|
+
// The FATAL, UNREACHABLE and UNIMPLEMENTED macros are useful during
|
36
|
+
// development, but they should not be relied on in the final product.
|
37
|
+
|
38
|
+
#ifdef DEBUG
|
39
|
+
#define FATAL(msg) \
|
40
|
+
V8_Fatal(__FILE__, __LINE__, "%s", (msg))
|
41
|
+
#define UNIMPLEMENTED() \
|
42
|
+
V8_Fatal(__FILE__, __LINE__, "unimplemented code")
|
43
|
+
#define UNREACHABLE() \
|
44
|
+
V8_Fatal(__FILE__, __LINE__, "unreachable code")
|
45
|
+
#else
|
46
|
+
#define FATAL(msg) \
|
47
|
+
V8_Fatal("", 0, "%s", (msg))
|
48
|
+
#define UNIMPLEMENTED() \
|
49
|
+
V8_Fatal("", 0, "unimplemented code")
|
50
|
+
#define UNREACHABLE() ((void) 0)
|
51
|
+
#endif
|
52
|
+
|
53
|
+
// Used by the CHECK macro -- should not be called directly.
|
54
|
+
static inline void CheckHelper(const char* file,
|
55
|
+
int line,
|
56
|
+
const char* source,
|
57
|
+
bool condition) {
|
58
|
+
if (!condition)
|
59
|
+
V8_Fatal(file, line, source);
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
// The CHECK macro checks that the given condition is true; if not, it
|
64
|
+
// prints a message to stderr and aborts.
|
65
|
+
#define CHECK(condition) CheckHelper(__FILE__, __LINE__, #condition, condition)
|
66
|
+
|
67
|
+
|
68
|
+
// Helper function used by the CHECK_EQ function when given int
|
69
|
+
// arguments. Should not be called directly.
|
70
|
+
static inline void CheckEqualsHelper(const char* file, int line,
|
71
|
+
const char* expected_source, int expected,
|
72
|
+
const char* value_source, int value) {
|
73
|
+
if (expected != value) {
|
74
|
+
V8_Fatal(file, line,
|
75
|
+
"CHECK_EQ(%s, %s) failed\n# Expected: %i\n# Found: %i",
|
76
|
+
expected_source, value_source, expected, value);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
|
81
|
+
#define CHECK_EQ(expected, value) CheckEqualsHelper(__FILE__, __LINE__, \
|
82
|
+
#expected, expected, #value, value)
|
83
|
+
|
84
|
+
|
85
|
+
// The ASSERT macro is equivalent to CHECK except that it only
|
86
|
+
// generates code in debug builds.
|
87
|
+
#ifdef DEBUG
|
88
|
+
#define ASSERT(condition) CHECK(condition)
|
89
|
+
#else
|
90
|
+
#define ASSERT(condition) ((void) 0)
|
91
|
+
#endif
|
92
|
+
|
93
|
+
#endif // V8_CHECKS_H_
|
@@ -0,0 +1,123 @@
|
|
1
|
+
// Copyright 2006-2008 the V8 project authors. All rights reserved.
|
2
|
+
// Redistribution and use in source and binary forms, with or without
|
3
|
+
// modification, are permitted provided that the following conditions are
|
4
|
+
// met:
|
5
|
+
//
|
6
|
+
// * Redistributions of source code must retain the above copyright
|
7
|
+
// notice, this list of conditions and the following disclaimer.
|
8
|
+
// * Redistributions in binary form must reproduce the above
|
9
|
+
// copyright notice, this list of conditions and the following
|
10
|
+
// disclaimer in the documentation and/or other materials provided
|
11
|
+
// with the distribution.
|
12
|
+
// * Neither the name of Google Inc. nor the names of its
|
13
|
+
// contributors may be used to endorse or promote products derived
|
14
|
+
// from this software without specific prior written permission.
|
15
|
+
//
|
16
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
18
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
19
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
20
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
23
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
|
28
|
+
#include <math.h>
|
29
|
+
|
30
|
+
#include "v8.h"
|
31
|
+
#include "dtoa.h"
|
32
|
+
|
33
|
+
extern "C" char* dtoa(double d, int mode, int ndigits,
|
34
|
+
int *decpt, int *sign, char **rve);
|
35
|
+
extern "C" void freedtoa(char *s);
|
36
|
+
|
37
|
+
namespace v8 {
|
38
|
+
namespace internal {
|
39
|
+
|
40
|
+
char* DoubleToCString(double v, char* buffer, int buflen) {
|
41
|
+
StringBuilder builder(buffer, buflen);
|
42
|
+
|
43
|
+
switch (fpclassify(v)) {
|
44
|
+
case FP_NAN:
|
45
|
+
builder.AddString("NaN");
|
46
|
+
break;
|
47
|
+
|
48
|
+
case FP_INFINITE:
|
49
|
+
if (v < 0.0) {
|
50
|
+
builder.AddString("-Infinity");
|
51
|
+
} else {
|
52
|
+
builder.AddString("Infinity");
|
53
|
+
}
|
54
|
+
break;
|
55
|
+
|
56
|
+
case FP_ZERO:
|
57
|
+
builder.AddCharacter('0');
|
58
|
+
break;
|
59
|
+
|
60
|
+
default: {
|
61
|
+
int decimal_point;
|
62
|
+
int sign;
|
63
|
+
char* decimal_rep;
|
64
|
+
bool used_gay_dtoa = false;
|
65
|
+
const int kV8DtoaBufferCapacity = kBase10MaximalLength + 1;
|
66
|
+
char v8_dtoa_buffer[kV8DtoaBufferCapacity];
|
67
|
+
int length;
|
68
|
+
|
69
|
+
if (DoubleToAscii(v, DTOA_SHORTEST, 0,
|
70
|
+
Vector<char>(v8_dtoa_buffer, kV8DtoaBufferCapacity),
|
71
|
+
&sign, &length, &decimal_point)) {
|
72
|
+
decimal_rep = v8_dtoa_buffer;
|
73
|
+
} else {
|
74
|
+
decimal_rep = dtoa(v, 0, 0, &decimal_point, &sign, NULL);
|
75
|
+
used_gay_dtoa = true;
|
76
|
+
length = StrLength(decimal_rep);
|
77
|
+
}
|
78
|
+
|
79
|
+
if (sign) builder.AddCharacter('-');
|
80
|
+
|
81
|
+
if (length <= decimal_point && decimal_point <= 21) {
|
82
|
+
// ECMA-262 section 9.8.1 step 6.
|
83
|
+
builder.AddString(decimal_rep);
|
84
|
+
builder.AddPadding('0', decimal_point - length);
|
85
|
+
|
86
|
+
} else if (0 < decimal_point && decimal_point <= 21) {
|
87
|
+
// ECMA-262 section 9.8.1 step 7.
|
88
|
+
builder.AddSubstring(decimal_rep, decimal_point);
|
89
|
+
builder.AddCharacter('.');
|
90
|
+
builder.AddString(decimal_rep + decimal_point);
|
91
|
+
|
92
|
+
} else if (decimal_point <= 0 && decimal_point > -6) {
|
93
|
+
// ECMA-262 section 9.8.1 step 8.
|
94
|
+
builder.AddString("0.");
|
95
|
+
builder.AddPadding('0', -decimal_point);
|
96
|
+
builder.AddString(decimal_rep);
|
97
|
+
|
98
|
+
} else {
|
99
|
+
// ECMA-262 section 9.8.1 step 9 and 10 combined.
|
100
|
+
builder.AddCharacter(decimal_rep[0]);
|
101
|
+
if (length != 1) {
|
102
|
+
builder.AddCharacter('.');
|
103
|
+
builder.AddString(decimal_rep + 1);
|
104
|
+
}
|
105
|
+
builder.AddCharacter('e');
|
106
|
+
builder.AddCharacter((decimal_point >= 0) ? '+' : '-');
|
107
|
+
int exponent = decimal_point - 1;
|
108
|
+
if (exponent < 0) exponent = -exponent;
|
109
|
+
// MOZ: This was a call to 'AddFormatted("%d", exponent)', which
|
110
|
+
// called onto vsnprintf(). Because this was the only call to
|
111
|
+
// AddFormatted in the imported code, it was replaced with this call
|
112
|
+
// to AddInteger, which is faster and doesn't require any
|
113
|
+
// platform-specific code.
|
114
|
+
builder.AddInteger(exponent);
|
115
|
+
}
|
116
|
+
|
117
|
+
if (used_gay_dtoa) freedtoa(decimal_rep);
|
118
|
+
}
|
119
|
+
}
|
120
|
+
return builder.Finalize();
|
121
|
+
}
|
122
|
+
|
123
|
+
} } // namespace v8::internal
|