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.
@@ -0,0 +1,91 @@
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
+
30
+ #include "v8.h"
31
+
32
+ #include "platform.h"
33
+
34
+ #include "sys/stat.h"
35
+
36
+ namespace v8 {
37
+ namespace internal {
38
+
39
+ void StringBuilder::AddString(const char* s) {
40
+ AddSubstring(s, StrLength(s));
41
+ }
42
+
43
+
44
+ void StringBuilder::AddSubstring(const char* s, int n) {
45
+ ASSERT(!is_finalized() && position_ + n < buffer_.length());
46
+ ASSERT(static_cast<size_t>(n) <= strlen(s));
47
+ memcpy(&buffer_[position_], s, n * kCharSize);
48
+ position_ += n;
49
+ }
50
+
51
+
52
+ // MOZ: This is not from V8. See DoubleToCString() for details.
53
+ void StringBuilder::AddInteger(int n) {
54
+ ASSERT(!is_finalized() && position_ < buffer_.length());
55
+ // Get the number of digits.
56
+ int ndigits = 0;
57
+ int n2 = n;
58
+ do {
59
+ ndigits++;
60
+ n2 /= 10;
61
+ } while (n2);
62
+
63
+ // Add the integer string backwards.
64
+ position_ += ndigits;
65
+ int i = position_;
66
+ do {
67
+ buffer_[--i] = '0' + (n % 10);
68
+ n /= 10;
69
+ } while (n);
70
+ }
71
+
72
+
73
+ void StringBuilder::AddPadding(char c, int count) {
74
+ for (int i = 0; i < count; i++) {
75
+ AddCharacter(c);
76
+ }
77
+ }
78
+
79
+
80
+ char* StringBuilder::Finalize() {
81
+ ASSERT(!is_finalized() && position_ < buffer_.length());
82
+ buffer_[position_] = '\0';
83
+ // Make sure nobody managed to add a 0-character to the
84
+ // buffer while building the string.
85
+ ASSERT(strlen(buffer_.start()) == static_cast<size_t>(position_));
86
+ position_ = -1;
87
+ ASSERT(is_finalized());
88
+ return buffer_.start();
89
+ }
90
+
91
+ } } // namespace v8::internal
@@ -0,0 +1,165 @@
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_UTILS_H_
29
+ #define V8_UTILS_H_
30
+
31
+ #include <stdlib.h>
32
+ #include <string.h>
33
+
34
+ namespace v8 {
35
+ namespace internal {
36
+
37
+ // ----------------------------------------------------------------------------
38
+ // General helper functions
39
+
40
+ inline int StrLength(const char* string) {
41
+ size_t length = strlen(string);
42
+ ASSERT(length == static_cast<size_t>(static_cast<int>(length)));
43
+ return static_cast<int>(length);
44
+ }
45
+
46
+ // ----------------------------------------------------------------------------
47
+ // Miscellaneous
48
+
49
+ template <typename T>
50
+ class Vector {
51
+ public:
52
+ Vector() : start_(NULL), length_(0) {}
53
+ Vector(T* data, int length) : start_(data), length_(length) {
54
+ ASSERT(length == 0 || (length > 0 && data != NULL));
55
+ }
56
+
57
+ // Returns the length of the vector.
58
+ int length() const { return length_; }
59
+
60
+ // Returns the pointer to the start of the data in the vector.
61
+ T* start() const { return start_; }
62
+
63
+ // Access individual vector elements - checks bounds in debug mode.
64
+ T& operator[](int index) const {
65
+ ASSERT(0 <= index && index < length_);
66
+ return start_[index];
67
+ }
68
+
69
+ inline Vector<T> operator+(int offset) {
70
+ ASSERT(offset < length_);
71
+ return Vector<T>(start_ + offset, length_ - offset);
72
+ }
73
+
74
+ private:
75
+ T* start_;
76
+ int length_;
77
+ };
78
+
79
+
80
+ // Helper class for building result strings in a character buffer. The
81
+ // purpose of the class is to use safe operations that checks the
82
+ // buffer bounds on all operations in debug mode.
83
+ class StringBuilder {
84
+ public:
85
+
86
+ StringBuilder(char* buffer, int size)
87
+ : buffer_(buffer, size), position_(0) { }
88
+
89
+ ~StringBuilder() { if (!is_finalized()) Finalize(); }
90
+
91
+ // Add a single character to the builder. It is not allowed to add
92
+ // 0-characters; use the Finalize() method to terminate the string
93
+ // instead.
94
+ void AddCharacter(char c) {
95
+ ASSERT(c != '\0');
96
+ ASSERT(!is_finalized() && position_ < buffer_.length());
97
+ buffer_[position_++] = c;
98
+ }
99
+
100
+ // Add an entire string to the builder. Uses strlen() internally to
101
+ // compute the length of the input string.
102
+ void AddString(const char* s);
103
+
104
+ // Add the first 'n' characters of the given string 's' to the
105
+ // builder. The input string must have enough characters.
106
+ void AddSubstring(const char* s, int n);
107
+
108
+ // Add an integer to the builder.
109
+ void AddInteger(int n);
110
+
111
+ // Add character padding to the builder. If count is non-positive,
112
+ // nothing is added to the builder.
113
+ void AddPadding(char c, int count);
114
+
115
+ // Finalize the string by 0-terminating it and returning the buffer.
116
+ char* Finalize();
117
+
118
+ private:
119
+ Vector<char> buffer_;
120
+ int position_;
121
+
122
+ bool is_finalized() const { return position_ < 0; }
123
+
124
+ DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder);
125
+ };
126
+
127
+
128
+ // The type-based aliasing rule allows the compiler to assume that pointers of
129
+ // different types (for some definition of different) never alias each other.
130
+ // Thus the following code does not work:
131
+ //
132
+ // float f = foo();
133
+ // int fbits = *(int*)(&f);
134
+ //
135
+ // The compiler 'knows' that the int pointer can't refer to f since the types
136
+ // don't match, so the compiler may cache f in a register, leaving random data
137
+ // in fbits. Using C++ style casts makes no difference, however a pointer to
138
+ // char data is assumed to alias any other pointer. This is the 'memcpy
139
+ // exception'.
140
+ //
141
+ // Bit_cast uses the memcpy exception to move the bits from a variable of one
142
+ // type of a variable of another type. Of course the end result is likely to
143
+ // be implementation dependent. Most compilers (gcc-4.2 and MSVC 2005)
144
+ // will completely optimize BitCast away.
145
+ //
146
+ // There is an additional use for BitCast.
147
+ // Recent gccs will warn when they see casts that may result in breakage due to
148
+ // the type-based aliasing rule. If you have checked that there is no breakage
149
+ // you can use BitCast to cast one pointer type to another. This confuses gcc
150
+ // enough that it can no longer see that you have cast one pointer type to
151
+ // another thus avoiding the warning.
152
+ template <class Dest, class Source>
153
+ inline Dest BitCast(const Source& source) {
154
+ // Compile time assertion: sizeof(Dest) == sizeof(Source)
155
+ // A compile error here means your Dest and Source have different sizes.
156
+ typedef char VerifySizesAreEqual[sizeof(Dest) == sizeof(Source) ? 1 : -1];
157
+
158
+ Dest dest;
159
+ memcpy(&dest, &source, sizeof(dest));
160
+ return dest;
161
+ }
162
+
163
+ } } // namespace v8::internal
164
+
165
+ #endif // V8_UTILS_H_
@@ -0,0 +1,79 @@
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
+ // MOZ: this file was called dtoa.cc, but that clashed in the build with
29
+ // the file dtoa.c in SpiderMonkey, so this file was renamed v8-dtoa.cc.
30
+
31
+ #include <math.h>
32
+
33
+ #include "v8.h"
34
+ #include "dtoa.h"
35
+ #include "double.h"
36
+ #include "fast-dtoa.h"
37
+
38
+ namespace v8 {
39
+ namespace internal {
40
+
41
+ bool DoubleToAscii(double v, DtoaMode mode, int requested_digits,
42
+ Vector<char> buffer, int* sign, int* length, int* point) {
43
+ ASSERT(!Double(v).IsSpecial());
44
+ ASSERT(mode == DTOA_SHORTEST || requested_digits >= 0);
45
+
46
+ if (Double(v).Sign() < 0) {
47
+ *sign = 1;
48
+ v = -v;
49
+ } else {
50
+ *sign = 0;
51
+ }
52
+
53
+ if (v == 0) {
54
+ buffer[0] = '0';
55
+ buffer[1] = '\0';
56
+ *length = 1;
57
+ *point = 1;
58
+ return true;
59
+ }
60
+
61
+ if (mode == DTOA_PRECISION && requested_digits == 0) {
62
+ buffer[0] = '\0';
63
+ *length = 0;
64
+ return true;
65
+ }
66
+
67
+ switch (mode) {
68
+ case DTOA_SHORTEST:
69
+ return FastDtoa(v, buffer, length, point);
70
+ case DTOA_FIXED:
71
+ // MOZ: should never happen.
72
+ //return FastFixedDtoa(v, requested_digits, buffer, length, point);
73
+ default:
74
+ break;
75
+ }
76
+ return false;
77
+ }
78
+
79
+ } } // namespace v8::internal
@@ -0,0 +1,51 @@
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
+ //
29
+ // Top include for all V8 .cc files.
30
+ //
31
+
32
+ #ifndef V8_V8_H_
33
+ #define V8_V8_H_
34
+
35
+ // V8 only uses DEBUG, but included external files
36
+ // may use NDEBUG - make sure they are consistent.
37
+ #if defined(DEBUG) && defined(NDEBUG)
38
+ #error both DEBUG and NDEBUG are set
39
+ #endif
40
+
41
+ // Basic includes
42
+ #include "include-v8.h"
43
+ #include "globals.h"
44
+ #include "checks.h"
45
+ #include "utils.h"
46
+
47
+ #include "platform.h"
48
+
49
+ namespace i = v8::internal;
50
+
51
+ #endif // V8_V8_H_
@@ -28,7 +28,7 @@ class TestPhonic < Test::Unit::TestCase
28
28
  assert_nothing_raised {
29
29
  IV::Phonic::parse("var test = /test/;")
30
30
  }
31
- pp IV::Phonic::parse("var i = 20;")
31
+ pp IV::Phonic::parse("var i = {1e1: 'OK'};")
32
32
  # assert_nothing_raised {
33
33
  # IV::Phonic::parse(File.read('tmp/jquery.js'))
34
34
  # }
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: iv-phonic
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Constellation
@@ -58,6 +58,8 @@ files:
58
58
  - ext/include/iv/conversions.h
59
59
  - ext/include/iv/dtoa.h
60
60
  - ext/include/iv/mt19937.h
61
+ - ext/include/iv/byteorder.h
62
+ - ext/include/iv/about.h
61
63
  - ext/include/iv/ast.h
62
64
  - ext/include/iv/noncopyable.h
63
65
  - ext/include/iv/stringpiece.h
@@ -77,6 +79,7 @@ files:
77
79
  - ext/include/iv/none.h
78
80
  - ext/include/iv/ustring.h
79
81
  - ext/include/iv/ast_serializer.h
82
+ - ext/include/iv/netlib-dtoa.h
80
83
  - ext/include/iv/utils.h
81
84
  - ext/include/iv/ast_visitor.h
82
85
  - ext/include/iv/alloc.h
@@ -85,6 +88,28 @@ files:
85
88
  - ext/include/iv/ustringpiece.h
86
89
  - ext/include/iv/character.h
87
90
  - ext/include/iv/ucdata.h
91
+ - ext/iv/phonic/fast-dtoa.cc
92
+ - ext/iv/phonic/conversions.h
93
+ - ext/iv/phonic/dtoa.h
94
+ - ext/iv/phonic/globals.h
95
+ - ext/iv/phonic/checks.cc
96
+ - ext/iv/phonic/platform.h
97
+ - ext/iv/phonic/README
98
+ - ext/iv/phonic/v8-dtoa.cc
99
+ - ext/iv/phonic/SConscript
100
+ - ext/iv/phonic/double.h
101
+ - ext/iv/phonic/include-v8.h
102
+ - ext/iv/phonic/cached-powers.h
103
+ - ext/iv/phonic/checks.h
104
+ - ext/iv/phonic/conversions.cc
105
+ - ext/iv/phonic/utils.cc
106
+ - ext/iv/phonic/diy-fp.h
107
+ - ext/iv/phonic/utils.h
108
+ - ext/iv/phonic/powers-ten.h
109
+ - ext/iv/phonic/platform.cc
110
+ - ext/iv/phonic/v8.h
111
+ - ext/iv/phonic/diy-fp.cc
112
+ - ext/iv/phonic/fast-dtoa.h
88
113
  - ext/iv/phonic/factory.h
89
114
  - ext/iv/phonic/ast_fwd.h
90
115
  - ext/iv/phonic/parser.h