opal 1.3.2 → 1.4.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintrc.js +1 -0
- data/.github/workflows/build.yml +0 -3
- data/.rubocop.yml +5 -1
- data/UNRELEASED.md +66 -2
- data/benchmark-ips/bm_truthy.rb +30 -0
- data/bin/opal-mspec +1 -3
- data/bin/opal-repl +1 -2
- data/bin/remove-filters +1 -4
- data/docs/compiled_ruby.md +10 -6
- data/exe/opal-repl +1 -3
- data/lib/opal/ast/builder.rb +1 -1
- data/lib/opal/cli.rb +2 -2
- data/lib/opal/cli_runners/nodejs.rb +9 -2
- data/lib/opal/cli_runners/source-map-support-browser.js +80 -216
- data/lib/opal/cli_runners/source-map-support-node.js +80 -216
- data/lib/opal/cli_runners/source-map-support.js +5 -1
- data/lib/opal/cli_runners/system_runner.rb +10 -4
- data/lib/opal/compiler.rb +3 -5
- data/lib/opal/fragment.rb +5 -1
- data/lib/opal/nodes/args/extract_block_arg.rb +1 -8
- data/lib/opal/nodes/args/extract_kwoptarg.rb +1 -3
- data/lib/opal/nodes/args/extract_optarg.rb +1 -3
- data/lib/opal/nodes/args/extract_post_arg.rb +2 -5
- data/lib/opal/nodes/args/extract_post_optarg.rb +2 -7
- data/lib/opal/nodes/args/initialize_iterarg.rb +1 -3
- data/lib/opal/nodes/args/prepare_post_args.rb +5 -1
- data/lib/opal/nodes/base.rb +3 -2
- data/lib/opal/nodes/call.rb +20 -9
- data/lib/opal/nodes/call_special.rb +50 -0
- data/lib/opal/nodes/class.rb +24 -15
- data/lib/opal/nodes/constants.rb +23 -5
- data/lib/opal/nodes/def.rb +20 -23
- data/lib/opal/nodes/defined.rb +5 -5
- data/lib/opal/nodes/definitions.rb +2 -2
- data/lib/opal/nodes/defs.rb +2 -5
- data/lib/opal/nodes/helpers.rb +48 -18
- data/lib/opal/nodes/if.rb +109 -8
- data/lib/opal/nodes/iter.rb +23 -16
- data/lib/opal/nodes/literal.rb +18 -4
- data/lib/opal/nodes/logic.rb +2 -1
- data/lib/opal/nodes/masgn.rb +4 -9
- data/lib/opal/nodes/module.rb +29 -19
- data/lib/opal/nodes/node_with_args.rb +1 -7
- data/lib/opal/nodes/scope.rb +54 -15
- data/lib/opal/nodes/singleton_class.rb +5 -3
- data/lib/opal/nodes/super.rb +3 -3
- data/lib/opal/nodes/top.rb +34 -31
- data/lib/opal/nodes/variables.rb +2 -2
- data/lib/opal/nodes/x_string.rb +3 -0
- data/lib/opal/nodes.rb +0 -1
- data/lib/opal/parser/patch.rb +75 -0
- data/lib/opal/parser/with_ruby_lexer.rb +1 -1
- data/lib/opal/regexp_anchors.rb +7 -7
- data/lib/opal/requires.rb +19 -0
- data/lib/opal/rewriters/pattern_matching.rb +1 -1
- data/lib/opal/rewriters/returnable_logic.rb +102 -4
- data/lib/opal/util.rb +2 -2
- data/lib/opal/version.rb +1 -1
- data/lib/opal.rb +1 -17
- data/opal/corelib/array/pack.rb +11 -11
- data/opal/corelib/array.rb +193 -152
- data/opal/corelib/basic_object.rb +14 -14
- data/opal/corelib/binding.rb +7 -7
- data/opal/corelib/boolean.rb +12 -15
- data/opal/corelib/class.rb +23 -1
- data/opal/corelib/comparable.rb +8 -8
- data/opal/corelib/complex/base.rb +2 -2
- data/opal/corelib/complex.rb +79 -88
- data/opal/corelib/constants.rb +9 -9
- data/opal/corelib/dir.rb +4 -3
- data/opal/corelib/enumerable.rb +140 -127
- data/opal/corelib/enumerator/arithmetic_sequence.rb +177 -0
- data/opal/corelib/enumerator/chain.rb +42 -0
- data/opal/corelib/enumerator/generator.rb +35 -0
- data/opal/corelib/enumerator/lazy.rb +243 -0
- data/opal/corelib/enumerator/yielder.rb +36 -0
- data/opal/corelib/enumerator.rb +45 -300
- data/opal/corelib/error/errno.rb +47 -0
- data/opal/corelib/error.rb +62 -60
- data/opal/corelib/file.rb +26 -12
- data/opal/corelib/hash.rb +98 -107
- data/opal/corelib/helpers.rb +62 -13
- data/opal/corelib/io.rb +47 -34
- data/opal/corelib/kernel/format.rb +29 -29
- data/opal/corelib/kernel.rb +86 -83
- data/opal/corelib/main.rb +14 -12
- data/opal/corelib/marshal/read_buffer.rb +15 -15
- data/opal/corelib/marshal/write_buffer.rb +45 -44
- data/opal/corelib/marshal.rb +3 -3
- data/opal/corelib/math.rb +50 -50
- data/opal/corelib/method.rb +12 -8
- data/opal/corelib/module.rb +96 -79
- data/opal/corelib/nil.rb +9 -11
- data/opal/corelib/number.rb +113 -118
- data/opal/corelib/numeric.rb +37 -33
- data/opal/corelib/object_space.rb +11 -10
- data/opal/corelib/pack_unpack/format_string_parser.rb +3 -3
- data/opal/corelib/pattern_matching/base.rb +7 -7
- data/opal/corelib/pattern_matching.rb +1 -1
- data/opal/corelib/proc.rb +15 -16
- data/opal/corelib/process/base.rb +2 -2
- data/opal/corelib/process/status.rb +21 -0
- data/opal/corelib/process.rb +5 -5
- data/opal/corelib/random/formatter.rb +11 -11
- data/opal/corelib/random/math_random.js.rb +1 -1
- data/opal/corelib/random/mersenne_twister.rb +3 -3
- data/opal/corelib/random/seedrandom.js.rb +3 -3
- data/opal/corelib/random.rb +17 -17
- data/opal/corelib/range.rb +51 -35
- data/opal/corelib/rational/base.rb +4 -4
- data/opal/corelib/rational.rb +61 -62
- data/opal/corelib/regexp.rb +47 -38
- data/opal/corelib/runtime.js +245 -139
- data/opal/corelib/string/encoding.rb +21 -21
- data/opal/corelib/string/unpack.rb +19 -14
- data/opal/corelib/string.rb +135 -128
- data/opal/corelib/struct.rb +59 -46
- data/opal/corelib/time.rb +47 -57
- data/opal/corelib/trace_point.rb +2 -2
- data/opal/corelib/unsupported.rb +31 -120
- data/opal/corelib/variables.rb +3 -3
- data/opal/opal/base.rb +9 -8
- data/opal/opal/full.rb +8 -8
- data/opal/opal/mini.rb +17 -17
- data/opal/opal.rb +17 -18
- data/opal.gemspec +1 -1
- data/spec/filters/bugs/array.rb +4 -24
- data/spec/filters/bugs/bigdecimal.rb +0 -23
- data/spec/filters/bugs/binding.rb +0 -1
- data/spec/filters/bugs/boolean.rb +3 -0
- data/spec/filters/bugs/class.rb +2 -0
- data/spec/filters/bugs/date.rb +0 -5
- data/spec/filters/bugs/encoding.rb +8 -50
- data/spec/filters/bugs/enumerable.rb +4 -1
- data/spec/filters/bugs/enumerator.rb +3 -36
- data/spec/filters/bugs/exception.rb +0 -2
- data/spec/filters/bugs/file.rb +0 -2
- data/spec/filters/bugs/float.rb +0 -3
- data/spec/filters/bugs/hash.rb +5 -3
- data/spec/filters/bugs/integer.rb +2 -3
- data/spec/filters/bugs/kernel.rb +2 -31
- data/spec/filters/bugs/language.rb +29 -49
- data/spec/filters/bugs/main.rb +0 -2
- data/spec/filters/bugs/marshal.rb +2 -3
- data/spec/filters/bugs/matrix.rb +0 -36
- data/spec/filters/bugs/module.rb +7 -61
- data/spec/filters/bugs/numeric.rb +0 -7
- data/spec/filters/bugs/objectspace.rb +1 -1
- data/spec/filters/bugs/pack_unpack.rb +0 -4
- data/spec/filters/bugs/proc.rb +0 -9
- data/spec/filters/bugs/random.rb +0 -5
- data/spec/filters/bugs/range.rb +1 -6
- data/spec/filters/bugs/regexp.rb +0 -3
- data/spec/filters/bugs/set.rb +8 -1
- data/spec/filters/bugs/string.rb +9 -34
- data/spec/filters/bugs/stringscanner.rb +8 -7
- data/spec/filters/bugs/struct.rb +2 -3
- data/spec/filters/bugs/symbol.rb +0 -1
- data/spec/filters/bugs/time.rb +0 -8
- data/spec/filters/bugs/unboundmethod.rb +0 -8
- data/spec/filters/bugs/warnings.rb +1 -7
- data/spec/filters/unsupported/freeze.rb +24 -0
- data/spec/filters/unsupported/integer.rb +1 -0
- data/spec/filters/unsupported/kernel.rb +12 -0
- data/spec/filters/unsupported/privacy.rb +3 -0
- data/spec/filters/unsupported/string.rb +2 -0
- data/spec/lib/builder_spec.rb +2 -2
- data/spec/lib/cli_spec.rb +1 -1
- data/spec/lib/compiler_spec.rb +37 -37
- data/spec/lib/simple_server_spec.rb +2 -2
- data/spec/lib/source_map/file_spec.rb +1 -1
- data/spec/opal/compiler/irb_spec.rb +2 -2
- data/spec/opal/core/kernel/puts_spec.rb +90 -0
- data/spec/opal/core/language/super_spec.rb +24 -0
- data/spec/ruby_specs +4 -2
- data/spec/support/rewriters_helper.rb +1 -1
- data/stdlib/bigdecimal.rb +7 -11
- data/stdlib/buffer/view.rb +2 -2
- data/stdlib/buffer.rb +2 -2
- data/stdlib/date.rb +5 -6
- data/stdlib/erb.rb +1 -0
- data/stdlib/js.rb +2 -1
- data/stdlib/native.rb +7 -8
- data/stdlib/nodejs/argf.rb +4 -4
- data/stdlib/nodejs/base.rb +29 -0
- data/stdlib/nodejs/dir.rb +1 -1
- data/stdlib/nodejs/env.rb +6 -9
- data/stdlib/nodejs/file.rb +23 -17
- data/stdlib/nodejs/fileutils.rb +3 -3
- data/stdlib/nodejs/io.rb +2 -20
- data/stdlib/nodejs/irb.rb +0 -0
- data/stdlib/nodejs/kernel.rb +2 -37
- data/stdlib/nodejs.rb +1 -3
- data/stdlib/opal/miniracer.rb +2 -0
- data/stdlib/opal/platform.rb +6 -13
- data/stdlib/opal/replutils.rb +16 -5
- data/stdlib/opal-parser.rb +2 -2
- data/stdlib/optparse/ac.rb +54 -0
- data/stdlib/optparse/date.rb +14 -0
- data/stdlib/optparse/kwargs.rb +22 -0
- data/stdlib/optparse/shellwords.rb +7 -0
- data/stdlib/optparse/time.rb +15 -0
- data/stdlib/optparse/uri.rb +7 -0
- data/stdlib/optparse/version.rb +69 -0
- data/stdlib/optparse.rb +2279 -0
- data/stdlib/pathname.rb +5 -6
- data/stdlib/pp.rb +18 -2
- data/stdlib/promise/v2.rb +18 -22
- data/stdlib/promise.rb +15 -21
- data/stdlib/set.rb +32 -32
- data/stdlib/shellwords.rb +240 -0
- data/stdlib/stringio.rb +3 -6
- data/stdlib/strscan.rb +5 -8
- data/stdlib/template.rb +2 -2
- data/stdlib/thread.rb +7 -9
- data/tasks/performance.rake +5 -2
- data/tasks/testing/mspec_special_calls.rb +0 -12
- data/tasks/testing.rake +55 -37
- data/test/nodejs/test_file.rb +11 -0
- metadata +55 -10
- data/lib/opal/nodes/case.rb +0 -114
data/opal/corelib/number.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'corelib/numeric'
|
2
2
|
|
3
|
-
class Number < Numeric
|
4
|
-
Opal.bridge(`Number`, self)
|
5
|
-
`Opal.
|
3
|
+
class ::Number < ::Numeric
|
4
|
+
::Opal.bridge(`Number`, self)
|
5
|
+
`Opal.prop(self.$$prototype, '$$is_number', true)`
|
6
6
|
`self.$$is_number_class = true`
|
7
7
|
|
8
8
|
class << self
|
9
9
|
def allocate
|
10
|
-
raise TypeError, "allocator undefined for #{name}"
|
10
|
+
::Kernel.raise ::TypeError, "allocator undefined for #{name}"
|
11
11
|
end
|
12
12
|
|
13
13
|
undef :new
|
@@ -16,19 +16,19 @@ class Number < Numeric
|
|
16
16
|
def coerce(other)
|
17
17
|
%x{
|
18
18
|
if (other === nil) {
|
19
|
-
#{raise TypeError, "can't convert #{other.class} into Float"};
|
19
|
+
#{::Kernel.raise ::TypeError, "can't convert #{other.class} into Float"};
|
20
20
|
}
|
21
21
|
else if (other.$$is_string) {
|
22
|
-
return [#{Float(other)}, self];
|
22
|
+
return [#{::Kernel.Float(other)}, self];
|
23
23
|
}
|
24
24
|
else if (#{other.respond_to?(:to_f)}) {
|
25
|
-
return [#{Opal.coerce_to!(other, Float, :to_f)}, self];
|
25
|
+
return [#{::Opal.coerce_to!(other, ::Float, :to_f)}, self];
|
26
26
|
}
|
27
27
|
else if (other.$$is_number) {
|
28
28
|
return [other, self];
|
29
29
|
}
|
30
30
|
else {
|
31
|
-
#{raise TypeError, "can't convert #{other.class} into Float"};
|
31
|
+
#{::Kernel.raise ::TypeError, "can't convert #{other.class} into Float"};
|
32
32
|
}
|
33
33
|
}
|
34
34
|
end
|
@@ -37,8 +37,6 @@ class Number < Numeric
|
|
37
37
|
`(self * 2) + 1`
|
38
38
|
end
|
39
39
|
|
40
|
-
alias object_id __id__
|
41
|
-
|
42
40
|
def +(other)
|
43
41
|
%x{
|
44
42
|
if (other.$$is_number) {
|
@@ -83,8 +81,6 @@ class Number < Numeric
|
|
83
81
|
}
|
84
82
|
end
|
85
83
|
|
86
|
-
alias fdiv /
|
87
|
-
|
88
84
|
def %(other)
|
89
85
|
%x{
|
90
86
|
if (other.$$is_number) {
|
@@ -92,7 +88,7 @@ class Number < Numeric
|
|
92
88
|
return other;
|
93
89
|
}
|
94
90
|
else if (other == 0) {
|
95
|
-
#{raise ZeroDivisionError, 'divided by 0'};
|
91
|
+
#{::Kernel.raise ::ZeroDivisionError, 'divided by 0'};
|
96
92
|
}
|
97
93
|
else if (other < 0 || self < 0) {
|
98
94
|
return (self % other + other) % other;
|
@@ -209,24 +205,24 @@ class Number < Numeric
|
|
209
205
|
|
210
206
|
def <=>(other)
|
211
207
|
`spaceship_operator(self, other)`
|
212
|
-
rescue ArgumentError
|
208
|
+
rescue ::ArgumentError
|
213
209
|
nil
|
214
210
|
end
|
215
211
|
|
216
212
|
def <<(count)
|
217
|
-
count = Opal.coerce_to! count, Integer, :to_int
|
213
|
+
count = ::Opal.coerce_to! count, ::Integer, :to_int
|
218
214
|
|
219
215
|
`#{count} > 0 ? self << #{count} : self >> -#{count}`
|
220
216
|
end
|
221
217
|
|
222
218
|
def >>(count)
|
223
|
-
count = Opal.coerce_to! count, Integer, :to_int
|
219
|
+
count = ::Opal.coerce_to! count, ::Integer, :to_int
|
224
220
|
|
225
221
|
`#{count} > 0 ? self >> #{count} : self << -#{count}`
|
226
222
|
end
|
227
223
|
|
228
224
|
def [](bit)
|
229
|
-
bit = Opal.coerce_to! bit, Integer, :to_int
|
225
|
+
bit = ::Opal.coerce_to! bit, ::Integer, :to_int
|
230
226
|
|
231
227
|
%x{
|
232
228
|
if (#{bit} < 0) {
|
@@ -252,14 +248,14 @@ class Number < Numeric
|
|
252
248
|
end
|
253
249
|
|
254
250
|
def **(other)
|
255
|
-
if Integer === other
|
256
|
-
if !(Integer === self) || other > 0
|
251
|
+
if ::Integer === other
|
252
|
+
if !(::Integer === self) || other > 0
|
257
253
|
`Math.pow(self, other)`
|
258
254
|
else
|
259
|
-
Rational.new(self, 1)**other
|
255
|
+
::Rational.new(self, 1)**other
|
260
256
|
end
|
261
|
-
elsif self < 0 && (Float === other || Rational === other)
|
262
|
-
Complex.new(self, 0)**other.to_f
|
257
|
+
elsif self < 0 && (::Float === other || ::Rational === other)
|
258
|
+
::Complex.new(self, 0)**other.to_f
|
263
259
|
elsif `other.$$is_number != null`
|
264
260
|
`Math.pow(self, other)`
|
265
261
|
else
|
@@ -304,12 +300,12 @@ class Number < Numeric
|
|
304
300
|
end
|
305
301
|
|
306
302
|
def allbits?(mask)
|
307
|
-
mask = Opal.coerce_to! mask, Integer, :to_int
|
303
|
+
mask = ::Opal.coerce_to! mask, ::Integer, :to_int
|
308
304
|
`(self & mask) == mask`
|
309
305
|
end
|
310
306
|
|
311
307
|
def anybits?(mask)
|
312
|
-
mask = Opal.coerce_to! mask, Integer, :to_int
|
308
|
+
mask = ::Opal.coerce_to! mask, ::Integer, :to_int
|
313
309
|
`(self & mask) !== 0`
|
314
310
|
end
|
315
311
|
|
@@ -334,12 +330,9 @@ class Number < Numeric
|
|
334
330
|
}
|
335
331
|
end
|
336
332
|
|
337
|
-
alias arg angle
|
338
|
-
alias phase angle
|
339
|
-
|
340
333
|
def bit_length
|
341
|
-
unless Integer === self
|
342
|
-
raise NoMethodError.new("undefined method `bit_length` for #{self}:Float", 'bit_length')
|
334
|
+
unless ::Integer === self
|
335
|
+
::Kernel.raise ::NoMethodError.new("undefined method `bit_length` for #{self}:Float", 'bit_length')
|
343
336
|
end
|
344
337
|
|
345
338
|
%x{
|
@@ -393,14 +386,14 @@ class Number < Numeric
|
|
393
386
|
def downto(stop, &block)
|
394
387
|
unless block_given?
|
395
388
|
return enum_for(:downto, stop) do
|
396
|
-
raise ArgumentError, "comparison of #{self.class} with #{stop.class} failed" unless Numeric === stop
|
389
|
+
::Kernel.raise ::ArgumentError, "comparison of #{self.class} with #{stop.class} failed" unless ::Numeric === stop
|
397
390
|
stop > self ? 0 : self - stop + 1
|
398
391
|
end
|
399
392
|
end
|
400
393
|
|
401
394
|
%x{
|
402
395
|
if (!stop.$$is_number) {
|
403
|
-
#{raise ArgumentError, "comparison of #{self.class} with #{stop.class} failed"}
|
396
|
+
#{::Kernel.raise ::ArgumentError, "comparison of #{self.class} with #{stop.class} failed"}
|
404
397
|
}
|
405
398
|
for (var i = self; i >= stop; i--) {
|
406
399
|
block(i);
|
@@ -410,8 +403,6 @@ class Number < Numeric
|
|
410
403
|
self
|
411
404
|
end
|
412
405
|
|
413
|
-
alias eql? ==
|
414
|
-
|
415
406
|
def equal?(other)
|
416
407
|
self == other || `isNaN(self) && isNaN(other)`
|
417
408
|
end
|
@@ -440,8 +431,8 @@ class Number < Numeric
|
|
440
431
|
end
|
441
432
|
|
442
433
|
def gcd(other)
|
443
|
-
unless Integer === other
|
444
|
-
raise TypeError, 'not an integer'
|
434
|
+
unless ::Integer === other
|
435
|
+
::Kernel.raise ::TypeError, 'not an integer'
|
445
436
|
end
|
446
437
|
|
447
438
|
%x{
|
@@ -468,26 +459,24 @@ class Number < Numeric
|
|
468
459
|
end
|
469
460
|
|
470
461
|
def is_a?(klass)
|
471
|
-
return true if klass == Integer && Integer === self
|
472
|
-
return true if klass == Integer && Integer === self
|
473
|
-
return true if klass == Float && Float === self
|
462
|
+
return true if klass == ::Integer && ::Integer === self
|
463
|
+
return true if klass == ::Integer && ::Integer === self
|
464
|
+
return true if klass == ::Float && ::Float === self
|
474
465
|
|
475
466
|
super
|
476
467
|
end
|
477
468
|
|
478
|
-
alias kind_of? is_a?
|
479
|
-
|
480
469
|
def instance_of?(klass)
|
481
|
-
return true if klass == Integer && Integer === self
|
482
|
-
return true if klass == Integer && Integer === self
|
483
|
-
return true if klass == Float && Float === self
|
470
|
+
return true if klass == ::Integer && ::Integer === self
|
471
|
+
return true if klass == ::Integer && ::Integer === self
|
472
|
+
return true if klass == ::Float && ::Float === self
|
484
473
|
|
485
474
|
super
|
486
475
|
end
|
487
476
|
|
488
477
|
def lcm(other)
|
489
|
-
unless Integer === other
|
490
|
-
raise TypeError, 'not an integer'
|
478
|
+
unless ::Integer === other
|
479
|
+
::Kernel.raise ::TypeError, 'not an integer'
|
491
480
|
end
|
492
481
|
|
493
482
|
%x{
|
@@ -500,16 +489,12 @@ class Number < Numeric
|
|
500
489
|
}
|
501
490
|
end
|
502
491
|
|
503
|
-
alias magnitude abs
|
504
|
-
|
505
|
-
alias modulo %
|
506
|
-
|
507
492
|
def next
|
508
493
|
`self + 1`
|
509
494
|
end
|
510
495
|
|
511
496
|
def nobits?(mask)
|
512
|
-
mask = Opal.coerce_to! mask, Integer, :to_int
|
497
|
+
mask = ::Opal.coerce_to! mask, ::Integer, :to_int
|
513
498
|
`(self & mask) == 0`
|
514
499
|
end
|
515
500
|
|
@@ -536,26 +521,26 @@ class Number < Numeric
|
|
536
521
|
def pow(b, m = undefined)
|
537
522
|
%x{
|
538
523
|
if (self == 0) {
|
539
|
-
#{raise ZeroDivisionError, 'divided by 0'}
|
524
|
+
#{::Kernel.raise ::ZeroDivisionError, 'divided by 0'}
|
540
525
|
}
|
541
526
|
|
542
527
|
if (m === undefined) {
|
543
528
|
return #{self**b};
|
544
529
|
} else {
|
545
|
-
if (!(#{Integer === b})) {
|
546
|
-
#{raise TypeError, 'Integer#pow() 2nd argument not allowed unless a 1st argument is integer'}
|
530
|
+
if (!(#{::Integer === b})) {
|
531
|
+
#{::Kernel.raise ::TypeError, 'Integer#pow() 2nd argument not allowed unless a 1st argument is integer'}
|
547
532
|
}
|
548
533
|
|
549
534
|
if (b < 0) {
|
550
|
-
#{raise TypeError, 'Integer#pow() 1st argument cannot be negative when 2nd argument specified'}
|
535
|
+
#{::Kernel.raise ::TypeError, 'Integer#pow() 1st argument cannot be negative when 2nd argument specified'}
|
551
536
|
}
|
552
537
|
|
553
|
-
if (!(#{Integer === m})) {
|
554
|
-
#{raise TypeError, 'Integer#pow() 2nd argument not allowed unless all arguments are integers'}
|
538
|
+
if (!(#{::Integer === m})) {
|
539
|
+
#{::Kernel.raise ::TypeError, 'Integer#pow() 2nd argument not allowed unless all arguments are integers'}
|
555
540
|
}
|
556
541
|
|
557
542
|
if (m === 0) {
|
558
|
-
#{raise ZeroDivisionError, 'divided by 0'}
|
543
|
+
#{::Kernel.raise ::ZeroDivisionError, 'divided by 0'}
|
559
544
|
}
|
560
545
|
|
561
546
|
return #{(self**b) % m}
|
@@ -568,7 +553,7 @@ class Number < Numeric
|
|
568
553
|
end
|
569
554
|
|
570
555
|
def quo(other)
|
571
|
-
if Integer === self
|
556
|
+
if ::Integer === self
|
572
557
|
super
|
573
558
|
else
|
574
559
|
self / other
|
@@ -578,22 +563,22 @@ class Number < Numeric
|
|
578
563
|
def rationalize(eps = undefined)
|
579
564
|
%x{
|
580
565
|
if (arguments.length > 1) {
|
581
|
-
#{raise ArgumentError, "wrong number of arguments (#{`arguments.length`} for 0..1)"};
|
566
|
+
#{::Kernel.raise ::ArgumentError, "wrong number of arguments (#{`arguments.length`} for 0..1)"};
|
582
567
|
}
|
583
568
|
}
|
584
569
|
|
585
|
-
if Integer === self
|
586
|
-
Rational.new(self, 1)
|
570
|
+
if ::Integer === self
|
571
|
+
::Rational.new(self, 1)
|
587
572
|
elsif infinite?
|
588
|
-
raise FloatDomainError, 'Infinity'
|
573
|
+
::Kernel.raise ::FloatDomainError, 'Infinity'
|
589
574
|
elsif nan?
|
590
|
-
raise FloatDomainError, 'NaN'
|
575
|
+
::Kernel.raise ::FloatDomainError, 'NaN'
|
591
576
|
elsif `eps == null`
|
592
|
-
f, n = Math.frexp self
|
593
|
-
f = Math.ldexp(f, Float::MANT_DIG).to_i
|
594
|
-
n -= Float::MANT_DIG
|
577
|
+
f, n = ::Math.frexp self
|
578
|
+
f = ::Math.ldexp(f, ::Float::MANT_DIG).to_i
|
579
|
+
n -= ::Float::MANT_DIG
|
595
580
|
|
596
|
-
Rational.new(2 * f, 1 << (1 - n)).rationalize(Rational.new(1, 1 << (1 - n)))
|
581
|
+
::Rational.new(2 * f, 1 << (1 - n)).rationalize(::Rational.new(1, 1 << (1 - n)))
|
597
582
|
else
|
598
583
|
to_r.rationalize(eps)
|
599
584
|
end
|
@@ -604,19 +589,19 @@ class Number < Numeric
|
|
604
589
|
end
|
605
590
|
|
606
591
|
def round(ndigits = undefined)
|
607
|
-
if Integer === self
|
592
|
+
if ::Integer === self
|
608
593
|
if `ndigits == null`
|
609
594
|
return self
|
610
595
|
end
|
611
596
|
|
612
|
-
if Float === ndigits && ndigits.infinite?
|
613
|
-
raise RangeError, 'Infinity'
|
597
|
+
if ::Float === ndigits && ndigits.infinite?
|
598
|
+
::Kernel.raise ::RangeError, 'Infinity'
|
614
599
|
end
|
615
600
|
|
616
|
-
ndigits = Opal.coerce_to!(ndigits, Integer, :to_int)
|
601
|
+
ndigits = ::Opal.coerce_to!(ndigits, ::Integer, :to_int)
|
617
602
|
|
618
|
-
if ndigits < Integer::MIN
|
619
|
-
raise RangeError, 'out of bounds'
|
603
|
+
if ndigits < ::Integer::MIN
|
604
|
+
::Kernel.raise ::RangeError, 'out of bounds'
|
620
605
|
end
|
621
606
|
|
622
607
|
if `ndigits >= 0`
|
@@ -637,16 +622,16 @@ class Number < Numeric
|
|
637
622
|
}
|
638
623
|
else
|
639
624
|
if nan? && `ndigits == null`
|
640
|
-
raise FloatDomainError, 'NaN'
|
625
|
+
::Kernel.raise ::FloatDomainError, 'NaN'
|
641
626
|
end
|
642
627
|
|
643
|
-
ndigits = Opal.coerce_to!(`ndigits || 0`, Integer, :to_int)
|
628
|
+
ndigits = ::Opal.coerce_to!(`ndigits || 0`, ::Integer, :to_int)
|
644
629
|
|
645
630
|
if ndigits <= 0
|
646
631
|
if nan?
|
647
|
-
raise RangeError, 'NaN'
|
632
|
+
::Kernel.raise ::RangeError, 'NaN'
|
648
633
|
elsif infinite?
|
649
|
-
raise FloatDomainError, 'Infinity'
|
634
|
+
::Kernel.raise ::FloatDomainError, 'Infinity'
|
650
635
|
end
|
651
636
|
elsif ndigits == 0
|
652
637
|
return `Math.round(self)`
|
@@ -654,9 +639,9 @@ class Number < Numeric
|
|
654
639
|
return self
|
655
640
|
end
|
656
641
|
|
657
|
-
_, exp = Math.frexp(self)
|
642
|
+
_, exp = ::Math.frexp(self)
|
658
643
|
|
659
|
-
if ndigits >= (Float::DIG + 2) - (exp > 0 ? exp / 4 : exp / 3 - 1)
|
644
|
+
if ndigits >= (::Float::DIG + 2) - (exp > 0 ? exp / 4 : exp / 3 - 1)
|
660
645
|
return self
|
661
646
|
end
|
662
647
|
|
@@ -668,8 +653,6 @@ class Number < Numeric
|
|
668
653
|
end
|
669
654
|
end
|
670
655
|
|
671
|
-
alias succ next
|
672
|
-
|
673
656
|
def times(&block)
|
674
657
|
return enum_for(:times) { self } unless block
|
675
658
|
|
@@ -690,25 +673,23 @@ class Number < Numeric
|
|
690
673
|
`self < 0 ? Math.ceil(self) : Math.floor(self)`
|
691
674
|
end
|
692
675
|
|
693
|
-
alias to_int to_i
|
694
|
-
|
695
676
|
def to_r
|
696
|
-
if Integer === self
|
697
|
-
Rational.new(self, 1)
|
677
|
+
if ::Integer === self
|
678
|
+
::Rational.new(self, 1)
|
698
679
|
else
|
699
|
-
f, e = Math.frexp(self)
|
700
|
-
f = Math.ldexp(f, Float::MANT_DIG).to_i
|
701
|
-
e -= Float::MANT_DIG
|
680
|
+
f, e = ::Math.frexp(self)
|
681
|
+
f = ::Math.ldexp(f, ::Float::MANT_DIG).to_i
|
682
|
+
e -= ::Float::MANT_DIG
|
702
683
|
|
703
|
-
(f * (Float::RADIX**e)).to_r
|
684
|
+
(f * (::Float::RADIX**e)).to_r
|
704
685
|
end
|
705
686
|
end
|
706
687
|
|
707
688
|
def to_s(base = 10)
|
708
|
-
base = Opal.coerce_to! base, Integer, :to_int
|
689
|
+
base = ::Opal.coerce_to! base, ::Integer, :to_int
|
709
690
|
|
710
691
|
if base < 2 || base > 36
|
711
|
-
raise ArgumentError, "invalid radix #{base}"
|
692
|
+
::Kernel.raise ::ArgumentError, "invalid radix #{base}"
|
712
693
|
end
|
713
694
|
|
714
695
|
# Don't lose the negative zero
|
@@ -738,21 +719,19 @@ class Number < Numeric
|
|
738
719
|
}
|
739
720
|
end
|
740
721
|
|
741
|
-
alias inspect to_s
|
742
|
-
|
743
722
|
def digits(base = 10)
|
744
723
|
if self < 0
|
745
|
-
raise Math::DomainError, 'out of domain'
|
724
|
+
::Kernel.raise ::Math::DomainError, 'out of domain'
|
746
725
|
end
|
747
726
|
|
748
|
-
base = Opal.coerce_to! base, Integer, :to_int
|
727
|
+
base = ::Opal.coerce_to! base, ::Integer, :to_int
|
749
728
|
|
750
729
|
if base < 2
|
751
|
-
raise ArgumentError, "invalid radix #{base}"
|
730
|
+
::Kernel.raise ::ArgumentError, "invalid radix #{base}"
|
752
731
|
end
|
753
732
|
|
754
733
|
%x{
|
755
|
-
if (self != parseInt(self)) #{raise NoMethodError, "undefined method `digits' for #{inspect}"}
|
734
|
+
if (self != parseInt(self)) #{::Kernel.raise ::NoMethodError, "undefined method `digits' for #{inspect}"}
|
756
735
|
|
757
736
|
var value = self, result = [];
|
758
737
|
|
@@ -771,9 +750,9 @@ class Number < Numeric
|
|
771
750
|
|
772
751
|
def divmod(other)
|
773
752
|
if nan? || other.nan?
|
774
|
-
raise FloatDomainError, 'NaN'
|
753
|
+
::Kernel.raise ::FloatDomainError, 'NaN'
|
775
754
|
elsif infinite?
|
776
|
-
raise FloatDomainError, 'Infinity'
|
755
|
+
::Kernel.raise ::FloatDomainError, 'Infinity'
|
777
756
|
else
|
778
757
|
super
|
779
758
|
end
|
@@ -782,14 +761,14 @@ class Number < Numeric
|
|
782
761
|
def upto(stop, &block)
|
783
762
|
unless block_given?
|
784
763
|
return enum_for(:upto, stop) do
|
785
|
-
raise ArgumentError, "comparison of #{self.class} with #{stop.class} failed" unless Numeric === stop
|
764
|
+
::Kernel.raise ::ArgumentError, "comparison of #{self.class} with #{stop.class} failed" unless ::Numeric === stop
|
786
765
|
stop < self ? 0 : stop - self + 1
|
787
766
|
end
|
788
767
|
end
|
789
768
|
|
790
769
|
%x{
|
791
770
|
if (!stop.$$is_number) {
|
792
|
-
#{raise ArgumentError, "comparison of #{self.class} with #{stop.class} failed"}
|
771
|
+
#{::Kernel.raise ::ArgumentError, "comparison of #{self.class} with #{stop.class} failed"}
|
793
772
|
}
|
794
773
|
for (var i = self; i <= stop; i++) {
|
795
774
|
block(i);
|
@@ -837,43 +816,59 @@ class Number < Numeric
|
|
837
816
|
def negative?
|
838
817
|
`self == -Infinity || 1 / self < 0`
|
839
818
|
end
|
819
|
+
|
820
|
+
alias arg angle
|
821
|
+
alias eql? ==
|
822
|
+
alias fdiv /
|
823
|
+
alias inspect to_s
|
824
|
+
alias kind_of? is_a?
|
825
|
+
alias magnitude abs
|
826
|
+
alias modulo %
|
827
|
+
alias object_id __id__
|
828
|
+
alias phase angle
|
829
|
+
alias succ next
|
830
|
+
alias to_int to_i
|
840
831
|
end
|
841
832
|
|
842
|
-
Fixnum = Number
|
833
|
+
::Fixnum = ::Number
|
843
834
|
|
844
|
-
class Integer < Numeric
|
835
|
+
class ::Integer < ::Numeric
|
845
836
|
`self.$$is_number_class = true`
|
846
837
|
`self.$$is_integer_class = true`
|
847
838
|
|
848
839
|
class << self
|
849
840
|
def allocate
|
850
|
-
raise TypeError, "allocator undefined for #{name}"
|
841
|
+
::Kernel.raise ::TypeError, "allocator undefined for #{name}"
|
851
842
|
end
|
852
843
|
|
853
844
|
undef :new
|
854
845
|
|
855
846
|
def sqrt(n)
|
856
|
-
n = Opal.coerce_to!(n, Integer, :to_int)
|
847
|
+
n = ::Opal.coerce_to!(n, ::Integer, :to_int)
|
857
848
|
%x{
|
858
849
|
if (n < 0) {
|
859
|
-
#{raise Math::DomainError, 'Numerical argument is out of domain - "isqrt"'}
|
850
|
+
#{::Kernel.raise ::Math::DomainError, 'Numerical argument is out of domain - "isqrt"'}
|
860
851
|
}
|
861
852
|
|
862
853
|
return parseInt(Math.sqrt(n), 10);
|
863
854
|
}
|
864
855
|
end
|
856
|
+
|
857
|
+
def try_convert(object)
|
858
|
+
Opal.coerce_to?(object, self, :to_int)
|
859
|
+
end
|
865
860
|
end
|
866
861
|
|
867
|
-
MAX = `Math.pow(2, 30) - 1`
|
868
|
-
MIN = `-Math.pow(2, 30)`
|
862
|
+
self::MAX = `Math.pow(2, 30) - 1`
|
863
|
+
self::MIN = `-Math.pow(2, 30)`
|
869
864
|
end
|
870
865
|
|
871
|
-
class Float < Numeric
|
866
|
+
class ::Float < ::Numeric
|
872
867
|
`self.$$is_number_class = true`
|
873
868
|
|
874
869
|
class << self
|
875
870
|
def allocate
|
876
|
-
raise TypeError, "allocator undefined for #{name}"
|
871
|
+
::Kernel.raise ::TypeError, "allocator undefined for #{name}"
|
877
872
|
end
|
878
873
|
|
879
874
|
undef :new
|
@@ -883,14 +878,14 @@ class Float < Numeric
|
|
883
878
|
end
|
884
879
|
end
|
885
880
|
|
886
|
-
INFINITY = `Infinity`
|
887
|
-
MAX = `Number.MAX_VALUE`
|
888
|
-
MIN = `Number.MIN_VALUE`
|
889
|
-
NAN = `NaN`
|
881
|
+
self::INFINITY = `Infinity`
|
882
|
+
self::MAX = `Number.MAX_VALUE`
|
883
|
+
self::MIN = `Number.MIN_VALUE`
|
884
|
+
self::NAN = `NaN`
|
890
885
|
|
891
|
-
DIG = 15
|
892
|
-
MANT_DIG = 53
|
893
|
-
RADIX = 2
|
886
|
+
self::DIG = 15
|
887
|
+
self::MANT_DIG = 53
|
888
|
+
self::RADIX = 2
|
894
889
|
|
895
|
-
EPSILON = `Number.EPSILON || 2.2204460492503130808472633361816E-16`
|
890
|
+
self::EPSILON = `Number.EPSILON || 2.2204460492503130808472633361816E-16`
|
896
891
|
end
|