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/numeric.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'corelib/comparable'
|
2
2
|
|
3
|
-
class Numeric
|
4
|
-
include Comparable
|
3
|
+
class ::Numeric
|
4
|
+
include ::Comparable
|
5
5
|
|
6
6
|
def coerce(other)
|
7
7
|
if other.instance_of? self.class
|
8
8
|
return [other, self]
|
9
9
|
end
|
10
10
|
|
11
|
-
[Float(other), Float(self)]
|
11
|
+
[::Kernel.Float(other), ::Kernel.Float(self)]
|
12
12
|
end
|
13
13
|
|
14
14
|
def __coerced__(method, other)
|
@@ -18,9 +18,9 @@ class Numeric
|
|
18
18
|
else
|
19
19
|
case method
|
20
20
|
when :+, :-, :*, :/, :%, :&, :|, :^, :**
|
21
|
-
raise TypeError, "#{other.class} can't be coerced into Numeric"
|
21
|
+
::Kernel.raise ::TypeError, "#{other.class} can't be coerced into Numeric"
|
22
22
|
when :>, :>=, :<, :<=, :<=>
|
23
|
-
raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
|
23
|
+
::Kernel.raise ::ArgumentError, "comparison of #{self.class} with #{other.class} failed"
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -54,11 +54,9 @@ class Numeric
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def angle
|
57
|
-
self < 0 ? Math::PI : 0
|
57
|
+
self < 0 ? ::Math::PI : 0
|
58
58
|
end
|
59
59
|
|
60
|
-
alias arg angle
|
61
|
-
|
62
60
|
def ceil(ndigits = 0)
|
63
61
|
to_f.ceil(ndigits)
|
64
62
|
end
|
@@ -67,14 +65,12 @@ class Numeric
|
|
67
65
|
self
|
68
66
|
end
|
69
67
|
|
70
|
-
alias conjugate conj
|
71
|
-
|
72
68
|
def denominator
|
73
69
|
to_r.denominator
|
74
70
|
end
|
75
71
|
|
76
72
|
def div(other)
|
77
|
-
raise ZeroDivisionError, 'divided by o' if other == 0
|
73
|
+
::Kernel.raise ::ZeroDivisionError, 'divided by o' if other == 0
|
78
74
|
|
79
75
|
(self / other).floor
|
80
76
|
end
|
@@ -92,23 +88,17 @@ class Numeric
|
|
92
88
|
end
|
93
89
|
|
94
90
|
def i
|
95
|
-
Complex(0, self)
|
91
|
+
::Kernel.Complex(0, self)
|
96
92
|
end
|
97
93
|
|
98
94
|
def imag
|
99
95
|
0
|
100
96
|
end
|
101
97
|
|
102
|
-
alias imaginary imag
|
103
|
-
|
104
98
|
def integer?
|
105
99
|
false
|
106
100
|
end
|
107
101
|
|
108
|
-
alias magnitude abs
|
109
|
-
|
110
|
-
alias modulo %
|
111
|
-
|
112
102
|
def nonzero?
|
113
103
|
zero? ? nil : self
|
114
104
|
end
|
@@ -117,14 +107,12 @@ class Numeric
|
|
117
107
|
to_r.numerator
|
118
108
|
end
|
119
109
|
|
120
|
-
alias phase arg
|
121
|
-
|
122
110
|
def polar
|
123
111
|
[abs, arg]
|
124
112
|
end
|
125
113
|
|
126
114
|
def quo(other)
|
127
|
-
Opal.coerce_to!(self, Rational, :to_r) / other
|
115
|
+
::Opal.coerce_to!(self, ::Rational, :to_r) / other
|
128
116
|
end
|
129
117
|
|
130
118
|
def real
|
@@ -139,8 +127,6 @@ class Numeric
|
|
139
127
|
[self, 0]
|
140
128
|
end
|
141
129
|
|
142
|
-
alias rectangular rect
|
143
|
-
|
144
130
|
def round(digits = undefined)
|
145
131
|
to_f.round(digits)
|
146
132
|
end
|
@@ -148,11 +134,11 @@ class Numeric
|
|
148
134
|
def step(limit = undefined, step = undefined, to: undefined, by: undefined, &block)
|
149
135
|
%x{
|
150
136
|
if (limit !== undefined && to !== undefined) {
|
151
|
-
#{raise ArgumentError, 'to is given twice'}
|
137
|
+
#{::Kernel.raise ::ArgumentError, 'to is given twice'}
|
152
138
|
}
|
153
139
|
|
154
140
|
if (step !== undefined && by !== undefined) {
|
155
|
-
#{raise ArgumentError, 'step is given twice'}
|
141
|
+
#{::Kernel.raise ::ArgumentError, 'step is given twice'}
|
156
142
|
}
|
157
143
|
|
158
144
|
if (to !== undefined) {
|
@@ -169,11 +155,11 @@ class Numeric
|
|
169
155
|
|
170
156
|
function validateParameters() {
|
171
157
|
if (step === nil) {
|
172
|
-
#{raise TypeError, 'step must be numeric'}
|
158
|
+
#{::Kernel.raise ::TypeError, 'step must be numeric'}
|
173
159
|
}
|
174
160
|
|
175
161
|
if (step != null && #{step == 0}) {
|
176
|
-
#{raise ArgumentError, "step can't be 0"}
|
162
|
+
#{::Kernel.raise ::ArgumentError, "step can't be 0"}
|
177
163
|
}
|
178
164
|
|
179
165
|
if (step === nil || step == null) {
|
@@ -183,14 +169,14 @@ class Numeric
|
|
183
169
|
var sign = #{step <=> 0};
|
184
170
|
|
185
171
|
if (sign === nil) {
|
186
|
-
#{raise ArgumentError, "0 can't be coerced into #{step.class}"}
|
172
|
+
#{::Kernel.raise ::ArgumentError, "0 can't be coerced into #{step.class}"}
|
187
173
|
}
|
188
174
|
|
189
175
|
if (limit === nil || limit == null) {
|
190
|
-
limit = sign > 0 ? #{Float::INFINITY} : #{
|
176
|
+
limit = sign > 0 ? #{::Float::INFINITY} : #{-::Float::INFINITY};
|
191
177
|
}
|
192
178
|
|
193
|
-
#{Opal.compare(self, limit)}
|
179
|
+
#{::Opal.compare(self, limit)}
|
194
180
|
}
|
195
181
|
|
196
182
|
function stepFloatSize() {
|
@@ -200,7 +186,7 @@ class Numeric
|
|
200
186
|
return 1;
|
201
187
|
} else {
|
202
188
|
var abs = Math.abs, floor = Math.floor,
|
203
|
-
err = (abs(self) + abs(limit) + abs(limit - self)) / abs(step) * #{Float::EPSILON};
|
189
|
+
err = (abs(self) + abs(limit) + abs(limit - self)) / abs(step) * #{::Float::EPSILON};
|
204
190
|
|
205
191
|
if (err === Infinity || err === -Infinity) {
|
206
192
|
return 0;
|
@@ -236,7 +222,17 @@ class Numeric
|
|
236
222
|
|
237
223
|
}
|
238
224
|
|
239
|
-
|
225
|
+
unless block_given?
|
226
|
+
if (!limit || limit.is_a?(::Numeric)) &&
|
227
|
+
(!step || step.is_a?(::Numeric))
|
228
|
+
|
229
|
+
return ::Enumerator::ArithmeticSequence.new(
|
230
|
+
[limit, step, ('to: ' if to), ('by: ' if by)], self
|
231
|
+
)
|
232
|
+
else
|
233
|
+
return enum_for(:step, limit, step, &`stepSize`)
|
234
|
+
end
|
235
|
+
end
|
240
236
|
|
241
237
|
%x{
|
242
238
|
validateParameters();
|
@@ -302,7 +298,7 @@ class Numeric
|
|
302
298
|
end
|
303
299
|
|
304
300
|
def to_c
|
305
|
-
Complex(self, 0)
|
301
|
+
::Kernel.Complex(self, 0)
|
306
302
|
end
|
307
303
|
|
308
304
|
def to_int
|
@@ -340,4 +336,12 @@ class Numeric
|
|
340
336
|
def infinite?
|
341
337
|
nil
|
342
338
|
end
|
339
|
+
|
340
|
+
alias arg angle
|
341
|
+
alias conjugate conj
|
342
|
+
alias imaginary imag
|
343
|
+
alias magnitude abs
|
344
|
+
alias modulo %
|
345
|
+
alias phase arg
|
346
|
+
alias rectangular rect
|
343
347
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
# helpers: respond_to,
|
1
|
+
# helpers: respond_to, truthy
|
2
2
|
|
3
|
-
module ObjectSpace
|
3
|
+
module ::ObjectSpace
|
4
4
|
module_function
|
5
5
|
|
6
6
|
%x{
|
@@ -36,9 +36,9 @@ module ObjectSpace
|
|
36
36
|
def define_finalizer(obj, aproc = undefined, &block)
|
37
37
|
%x{
|
38
38
|
if ($truthy(block)) aproc = block;
|
39
|
-
if (
|
39
|
+
if (!$truthy(aproc)) aproc = #{::Kernel.proc};
|
40
40
|
if (!$respond_to(aproc, '$call')) {
|
41
|
-
#{raise ArgumentError, "Wrong type argument #{aproc.class} (should be callable)"};
|
41
|
+
#{::Kernel.raise ::ArgumentError, "Wrong type argument #{aproc.class} (should be callable)"};
|
42
42
|
}
|
43
43
|
var id = #{obj.__id__};
|
44
44
|
add_caller(id, aproc);
|
@@ -47,7 +47,7 @@ module ObjectSpace
|
|
47
47
|
}
|
48
48
|
catch (e) {
|
49
49
|
delete_callers(id);
|
50
|
-
#{raise ArgumentError, "cannot define finalizer for #{obj.class}"};
|
50
|
+
#{::Kernel.raise ::ArgumentError, "cannot define finalizer for #{obj.class}"};
|
51
51
|
}
|
52
52
|
return [0, aproc];
|
53
53
|
}
|
@@ -62,8 +62,8 @@ module ObjectSpace
|
|
62
62
|
}
|
63
63
|
end
|
64
64
|
|
65
|
-
class WeakMap
|
66
|
-
include Enumerable
|
65
|
+
class self::WeakMap
|
66
|
+
include ::Enumerable
|
67
67
|
|
68
68
|
def initialize
|
69
69
|
@weak_map = `new WeakMap()`
|
@@ -90,13 +90,14 @@ module ObjectSpace
|
|
90
90
|
return #{@weak_map}.has(p1);
|
91
91
|
}
|
92
92
|
end
|
93
|
-
alias member? include?
|
94
|
-
alias key? include?
|
95
93
|
|
96
94
|
%i[each each_key each_value each_pair keys values size length].each do |i|
|
97
95
|
define_method i do |*|
|
98
|
-
raise NotImplementedError, "##{i} can't be implemented on top of JS interfaces"
|
96
|
+
::Kernel.raise ::NotImplementedError, "##{i} can't be implemented on top of JS interfaces"
|
99
97
|
end
|
100
98
|
end
|
99
|
+
|
100
|
+
alias member? include?
|
101
|
+
alias key? include?
|
101
102
|
end
|
102
103
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module PackUnpack
|
1
|
+
module ::PackUnpack
|
2
2
|
%x{
|
3
3
|
var directives = [
|
4
4
|
// Integer
|
@@ -84,11 +84,11 @@ module PackUnpack
|
|
84
84
|
var directiveSupportsModifiers = /[sSiIlLqQjJ]/.test(currentDirective);
|
85
85
|
|
86
86
|
if (!directiveSupportsModifiers && currentModifiers.length > 0) {
|
87
|
-
#{raise ArgumentError, "'#{`currentModifiers[0]`}' allowed only after types sSiIlLqQjJ"}
|
87
|
+
#{::Kernel.raise ::ArgumentError, "'#{`currentModifiers[0]`}' allowed only after types sSiIlLqQjJ"}
|
88
88
|
}
|
89
89
|
|
90
90
|
if (currentModifiers.indexOf('<') !== -1 && currentModifiers.indexOf('>') !== -1) {
|
91
|
-
#{raise RangeError, "Can't use both '<' and '>'"}
|
91
|
+
#{::Kernel.raise ::RangeError, "Can't use both '<' and '>'"}
|
92
92
|
}
|
93
93
|
|
94
94
|
if (!countSpecified) {
|
@@ -1,28 +1,28 @@
|
|
1
|
-
class Array
|
1
|
+
class ::Array
|
2
2
|
def deconstruct
|
3
3
|
self
|
4
4
|
end
|
5
5
|
end
|
6
6
|
|
7
|
-
class Hash
|
7
|
+
class ::Hash
|
8
8
|
def deconstruct_keys(_)
|
9
9
|
self
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
class Struct
|
13
|
+
class ::Struct
|
14
14
|
alias deconstruct to_a
|
15
15
|
# This function is specified in a very weird way...
|
16
16
|
def deconstruct_keys(keys)
|
17
17
|
return to_h if keys.nil?
|
18
|
-
raise TypeError, 'expected Array or nil' unless Array === keys
|
18
|
+
::Kernel.raise ::TypeError, 'expected Array or nil' unless ::Array === keys
|
19
19
|
return {} if keys.length > values.length
|
20
20
|
out = {}
|
21
21
|
keys.each do |key|
|
22
22
|
should_break = case key
|
23
|
-
when Integer
|
23
|
+
when ::Integer
|
24
24
|
values.length < key
|
25
|
-
when Symbol # Or String? Doesn't matter, we're in Opal.
|
25
|
+
when ::Symbol # Or String? Doesn't matter, we're in Opal.
|
26
26
|
!members.include?(key)
|
27
27
|
end
|
28
28
|
break if should_break
|
@@ -32,4 +32,4 @@ class Struct
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
class NoMatchingPatternError < StandardError; end
|
35
|
+
class ::NoMatchingPatternError < ::StandardError; end
|
data/opal/corelib/proc.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# helpers: slice
|
2
2
|
|
3
|
-
class Proc < `Function`
|
4
|
-
`Opal.
|
5
|
-
`Opal.
|
3
|
+
class ::Proc < `Function`
|
4
|
+
`Opal.prop(self.$$prototype, '$$is_proc', true)`
|
5
|
+
`Opal.prop(self.$$prototype, '$$is_lambda', false)`
|
6
6
|
|
7
7
|
def self.new(&block)
|
8
8
|
unless block
|
9
|
-
raise ArgumentError, 'tried to create a Proc object without a block'
|
9
|
+
::Kernel.raise ::ArgumentError, 'tried to create a Proc object without a block'
|
10
10
|
end
|
11
11
|
|
12
12
|
block
|
@@ -50,19 +50,15 @@ class Proc < `Function`
|
|
50
50
|
}
|
51
51
|
end
|
52
52
|
|
53
|
-
alias [] call
|
54
|
-
alias === call
|
55
|
-
alias yield call
|
56
|
-
|
57
53
|
def >>(other)
|
58
|
-
proc do |*args, &block|
|
54
|
+
::Kernel.proc do |*args, &block|
|
59
55
|
out = call(*args, &block)
|
60
56
|
other.call(out)
|
61
57
|
end
|
62
58
|
end
|
63
59
|
|
64
60
|
def <<(other)
|
65
|
-
proc do |*args, &block|
|
61
|
+
::Kernel.proc do |*args, &block|
|
66
62
|
out = other.call(*args, &block)
|
67
63
|
call(out)
|
68
64
|
end
|
@@ -94,10 +90,10 @@ class Proc < `Function`
|
|
94
90
|
end
|
95
91
|
|
96
92
|
def binding
|
97
|
-
`if (self.$$is_curried) { #{raise ArgumentError, "Can't create Binding"} }`
|
93
|
+
`if (self.$$is_curried) { #{::Kernel.raise ::ArgumentError, "Can't create Binding"} }`
|
98
94
|
|
99
|
-
if defined? Binding
|
100
|
-
Binding.new(nil, [], `self.$$s`, source_location)
|
95
|
+
if defined? ::Binding
|
96
|
+
::Binding.new(nil, [], `self.$$s`, source_location)
|
101
97
|
end
|
102
98
|
end
|
103
99
|
|
@@ -136,9 +132,9 @@ class Proc < `Function`
|
|
136
132
|
arity = self.length;
|
137
133
|
}
|
138
134
|
else {
|
139
|
-
arity = #{Opal.coerce_to!(arity, Integer, :to_int)};
|
135
|
+
arity = #{::Opal.coerce_to!(arity, ::Integer, :to_int)};
|
140
136
|
if (self.$$is_lambda && arity !== self.length) {
|
141
|
-
#{raise ArgumentError, "wrong number of arguments (#{`arity`} for #{`self.length`})"}
|
137
|
+
#{::Kernel.raise ::ArgumentError, "wrong number of arguments (#{`arity`} for #{`self.length`})"}
|
142
138
|
}
|
143
139
|
}
|
144
140
|
|
@@ -148,7 +144,7 @@ class Proc < `Function`
|
|
148
144
|
result;
|
149
145
|
|
150
146
|
if (length > arity && self.$$is_lambda && !self.$$is_curried) {
|
151
|
-
#{raise ArgumentError, "wrong number of arguments (#{`length`} for #{`arity`})"}
|
147
|
+
#{::Kernel.raise ::ArgumentError, "wrong number of arguments (#{`length`} for #{`arity`})"}
|
152
148
|
}
|
153
149
|
|
154
150
|
if (length >= arity) {
|
@@ -188,5 +184,8 @@ class Proc < `Function`
|
|
188
184
|
}
|
189
185
|
end
|
190
186
|
|
187
|
+
alias === call
|
191
188
|
alias clone dup
|
189
|
+
alias yield call
|
190
|
+
alias [] call
|
192
191
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ::Process
|
2
|
+
class Status
|
3
|
+
def initialize(status, pid)
|
4
|
+
@status, @pid = status, pid
|
5
|
+
end
|
6
|
+
|
7
|
+
def exitstatus
|
8
|
+
@status
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :pid
|
12
|
+
|
13
|
+
def success?
|
14
|
+
@status == 0
|
15
|
+
end
|
16
|
+
|
17
|
+
def inspect
|
18
|
+
"#<Process::Status: pid #{@pid} exit #{@status}>"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/opal/corelib/process.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module Process
|
1
|
+
module ::Process
|
2
2
|
@__clocks__ = []
|
3
3
|
def self.__register_clock__(name, func)
|
4
4
|
const_set name, @__clocks__.size
|
@@ -34,12 +34,12 @@ module Process
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def self.times
|
37
|
-
t = Time.now.to_f
|
38
|
-
Benchmark::Tms.new(t, t, t, t, t)
|
37
|
+
t = ::Time.now.to_f
|
38
|
+
::Benchmark::Tms.new(t, t, t, t, t)
|
39
39
|
end
|
40
40
|
|
41
41
|
def self.clock_gettime(clock_id, unit = :float_second)
|
42
|
-
(clock = @__clocks__[clock_id]) || raise(Errno::EINVAL, "clock_gettime(#{clock_id}) #{@__clocks__[clock_id]}")
|
42
|
+
(clock = @__clocks__[clock_id]) || ::Kernel.raise(::Errno::EINVAL, "clock_gettime(#{clock_id}) #{@__clocks__[clock_id]}")
|
43
43
|
%x{
|
44
44
|
var ms = clock();
|
45
45
|
switch (unit) {
|
@@ -50,7 +50,7 @@ module Process
|
|
50
50
|
case 'millisecond': return ((ms / 1) | 0); // number of milliseconds as an integer
|
51
51
|
case 'microsecond': return ((ms * 1000) | 0); // number of microseconds as an integer
|
52
52
|
case 'nanosecond': return ((ms * 1000000) | 0); // number of nanoseconds as an integer
|
53
|
-
default: #{raise ArgumentError, "unexpected unit: #{unit}"}
|
53
|
+
default: #{::Kernel.raise ::ArgumentError, "unexpected unit: #{unit}"}
|
54
54
|
}
|
55
55
|
}
|
56
56
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
class Random
|
2
|
-
module Formatter
|
1
|
+
class ::Random
|
2
|
+
module self::Formatter
|
3
3
|
def hex(count = nil)
|
4
|
-
count = Random._verify_count(count)
|
4
|
+
count = ::Random._verify_count(count)
|
5
5
|
%x{
|
6
6
|
var bytes = #{bytes(count)};
|
7
7
|
var out = "";
|
@@ -17,11 +17,11 @@ class Random
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def base64(count = nil)
|
20
|
-
Base64.strict_encode64(random_bytes(count)).encode('US-ASCII')
|
20
|
+
::Base64.strict_encode64(random_bytes(count)).encode('US-ASCII')
|
21
21
|
end
|
22
22
|
|
23
23
|
def urlsafe_base64(count = nil, padding = false)
|
24
|
-
Base64.urlsafe_encode64(random_bytes(count), padding).encode('US-ASCII')
|
24
|
+
::Base64.urlsafe_encode64(random_bytes(count), padding).encode('US-ASCII')
|
25
25
|
end
|
26
26
|
|
27
27
|
def uuid
|
@@ -87,7 +87,7 @@ class Random
|
|
87
87
|
return randomRange();
|
88
88
|
} else if (limit.$$is_number) {
|
89
89
|
if (limit <= 0) {
|
90
|
-
#{raise ArgumentError, "invalid argument - #{limit}"}
|
90
|
+
#{::Kernel.raise ::ArgumentError, "invalid argument - #{limit}"}
|
91
91
|
}
|
92
92
|
|
93
93
|
if (limit % 1 === 0) {
|
@@ -97,10 +97,10 @@ class Random
|
|
97
97
|
return randomFloat() * limit;
|
98
98
|
}
|
99
99
|
} else {
|
100
|
-
limit = #{Opal.coerce_to!(limit, Integer, :to_int)};
|
100
|
+
limit = #{::Opal.coerce_to!(limit, ::Integer, :to_int)};
|
101
101
|
|
102
102
|
if (limit <= 0) {
|
103
|
-
#{raise ArgumentError, "invalid argument - #{limit}"}
|
103
|
+
#{::Kernel.raise ::ArgumentError, "invalid argument - #{limit}"}
|
104
104
|
}
|
105
105
|
|
106
106
|
return randomInt(limit);
|
@@ -111,12 +111,12 @@ class Random
|
|
111
111
|
def alphanumeric(count = nil)
|
112
112
|
count = Random._verify_count(count)
|
113
113
|
map = ['0'..'9', 'a'..'z', 'A'..'Z'].map(&:to_a).flatten
|
114
|
-
Array.new(count) do |i|
|
114
|
+
::Array.new(count) do |i|
|
115
115
|
map[random_number(map.length)]
|
116
116
|
end.join
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
include Random::Formatter
|
121
|
-
extend Random::Formatter
|
120
|
+
include ::Random::Formatter
|
121
|
+
extend ::Random::Formatter
|
122
122
|
end
|
@@ -134,14 +134,14 @@ mersenne_twister = %x{(function() {
|
|
134
134
|
return { genrand_real: genrand_real, init: init };
|
135
135
|
})()}
|
136
136
|
|
137
|
-
class Random
|
137
|
+
class ::Random
|
138
138
|
`var MAX_INT = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1`
|
139
139
|
|
140
|
-
MERSENNE_TWISTER_GENERATOR = `{
|
140
|
+
self::MERSENNE_TWISTER_GENERATOR = `{
|
141
141
|
new_seed: function() { return Math.round(Math.random() * MAX_INT); },
|
142
142
|
reseed: function(seed) { return mersenne_twister.init(seed); },
|
143
143
|
rand: function(mt) { return mersenne_twister.genrand_real(mt); }
|
144
144
|
}`
|
145
145
|
|
146
|
-
self.generator = MERSENNE_TWISTER_GENERATOR
|
146
|
+
self.generator = self::MERSENNE_TWISTER_GENERATOR
|
147
147
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Random
|
1
|
+
class ::Random
|
2
2
|
%x{
|
3
3
|
var module = { exports: {} };
|
4
4
|
|
@@ -17,11 +17,11 @@ class Random
|
|
17
17
|
var $seed_generator = new Math.seedrandom('opal', { entropy: true })
|
18
18
|
}
|
19
19
|
|
20
|
-
SEEDRANDOM_GENERATOR = `{
|
20
|
+
self::SEEDRANDOM_GENERATOR = `{
|
21
21
|
new_seed: function() { return Math.abs($seed_generator.int32()); },
|
22
22
|
reseed: function(seed) { return new seedrandom(seed); },
|
23
23
|
rand: function($rng) { return $rng.quick(); }
|
24
24
|
}`
|
25
25
|
|
26
|
-
self.generator = SEEDRANDOM_GENERATOR
|
26
|
+
self.generator = self::SEEDRANDOM_GENERATOR
|
27
27
|
end
|
data/opal/corelib/random.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
# helpers:
|
1
|
+
# helpers: truthy
|
2
2
|
|
3
3
|
require 'corelib/random/formatter'
|
4
4
|
|
5
|
-
class Random
|
5
|
+
class ::Random
|
6
6
|
attr_reader :seed, :state
|
7
7
|
|
8
8
|
def self._verify_count(count)
|
9
9
|
%x{
|
10
|
-
if (
|
10
|
+
if (!$truthy(count)) count = 16;
|
11
11
|
if (typeof count !== "number") count = #{`count`.to_int};
|
12
|
-
if (count < 0) #{raise ArgumentError, 'negative string size (or size too big)'};
|
12
|
+
if (count < 0) #{::Kernel.raise ::ArgumentError, 'negative string size (or size too big)'};
|
13
13
|
count = Math.floor(count);
|
14
14
|
return count;
|
15
15
|
}
|
16
16
|
end
|
17
17
|
|
18
|
-
def initialize(seed = Random.new_seed)
|
19
|
-
seed = Opal.coerce_to!(seed, Integer, :to_int)
|
18
|
+
def initialize(seed = ::Random.new_seed)
|
19
|
+
seed = ::Opal.coerce_to!(seed, ::Integer, :to_int)
|
20
20
|
@state = seed
|
21
21
|
reseed(seed)
|
22
22
|
end
|
@@ -31,14 +31,14 @@ class Random
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def self.rand(limit = undefined)
|
34
|
-
DEFAULT.rand(limit)
|
34
|
+
self::DEFAULT.rand(limit)
|
35
35
|
end
|
36
36
|
|
37
|
-
def self.srand(n = Random.new_seed)
|
38
|
-
n = Opal.coerce_to!(n, Integer, :to_int)
|
37
|
+
def self.srand(n = ::Random.new_seed)
|
38
|
+
n = ::Opal.coerce_to!(n, ::Integer, :to_int)
|
39
39
|
|
40
|
-
previous_seed = DEFAULT.seed
|
41
|
-
DEFAULT.reseed(n)
|
40
|
+
previous_seed = self::DEFAULT.seed
|
41
|
+
self::DEFAULT.reseed(n)
|
42
42
|
previous_seed
|
43
43
|
end
|
44
44
|
|
@@ -47,19 +47,19 @@ class Random
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def ==(other)
|
50
|
-
return false unless Random === other
|
50
|
+
return false unless ::Random === other
|
51
51
|
|
52
52
|
seed == other.seed && state == other.state
|
53
53
|
end
|
54
54
|
|
55
55
|
def bytes(length)
|
56
|
-
length = Random._verify_count(length)
|
56
|
+
length = ::Random._verify_count(length)
|
57
57
|
|
58
|
-
Array.new(length) { rand(255).chr }.join.encode('ASCII-8BIT')
|
58
|
+
::Array.new(length) { rand(255).chr }.join.encode('ASCII-8BIT')
|
59
59
|
end
|
60
60
|
|
61
61
|
def self.bytes(length)
|
62
|
-
DEFAULT.bytes(length)
|
62
|
+
self::DEFAULT.bytes(length)
|
63
63
|
end
|
64
64
|
|
65
65
|
def rand(limit = undefined)
|
@@ -77,14 +77,14 @@ class Random
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def self.random_float
|
80
|
-
DEFAULT.random_float
|
80
|
+
self::DEFAULT.random_float
|
81
81
|
end
|
82
82
|
|
83
83
|
def self.generator=(generator)
|
84
84
|
`Opal.$$rand = #{generator}`
|
85
85
|
|
86
86
|
if const_defined? :DEFAULT
|
87
|
-
DEFAULT.reseed
|
87
|
+
self::DEFAULT.reseed
|
88
88
|
else
|
89
89
|
const_set :DEFAULT, new(new_seed)
|
90
90
|
end
|