code-ruby 0.5.5 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -4
- data/Gemfile.lock +10 -22
- data/code-ruby.gemspec +4 -3
- data/lib/code/error.rb +16 -5
- data/lib/code/node/base_10.rb +4 -2
- data/lib/code/node/base_16.rb +3 -1
- data/lib/code/node/base_2.rb +3 -1
- data/lib/code/node/base_8.rb +3 -1
- data/lib/code/node/boolean.rb +4 -2
- data/lib/code/node/call.rb +35 -12
- data/lib/code/node/call_argument.rb +16 -5
- data/lib/code/node/code.rb +5 -4
- data/lib/code/node/decimal.rb +2 -0
- data/lib/code/node/{dictionnary.rb → dictionary.rb} +14 -5
- data/lib/code/node/function.rb +7 -4
- data/lib/code/node/function_parameter.rb +3 -1
- data/lib/code/node/if.rb +5 -3
- data/lib/code/node/left_operation.rb +63 -0
- data/lib/code/node/list.rb +2 -0
- data/lib/code/node/negation.rb +2 -0
- data/lib/code/node/not.rb +2 -0
- data/lib/code/node/nothing.rb +3 -1
- data/lib/code/node/number.rb +2 -0
- data/lib/code/node/right_operation.rb +70 -0
- data/lib/code/node/splat.rb +2 -0
- data/lib/code/node/square_bracket.rb +37 -0
- data/lib/code/node/statement.rb +13 -5
- data/lib/code/node/string.rb +3 -1
- data/lib/code/node/ternary.rb +5 -3
- data/lib/code/node/unary_minus.rb +2 -0
- data/lib/code/node/while.rb +6 -4
- data/lib/code/node.rb +11 -5
- data/lib/code/object/argument.rb +13 -7
- data/lib/code/object/boolean.rb +43 -5
- data/lib/code/object/class.rb +17 -0
- data/lib/code/object/context.rb +36 -0
- data/lib/code/object/decimal.rb +252 -100
- data/lib/code/object/dictionary.rb +641 -0
- data/lib/code/object/function.rb +54 -27
- data/lib/code/object/global.rb +65 -19
- data/lib/code/object/identifier_list.rb +47 -0
- data/lib/code/object/integer.rb +320 -137
- data/lib/code/object/list.rb +140 -138
- data/lib/code/object/nothing.rb +10 -4
- data/lib/code/object/number.rb +6 -1
- data/lib/code/object/range.rb +85 -88
- data/lib/code/object/ruby_function.rb +11 -6
- data/lib/code/object/string.rb +51 -48
- data/lib/code/object.rb +117 -139
- data/lib/code/parser/addition.rb +4 -2
- data/lib/code/parser/and_operator.rb +4 -2
- data/lib/code/parser/bitwise_and.rb +4 -2
- data/lib/code/parser/bitwise_or.rb +4 -2
- data/lib/code/parser/boolean.rb +3 -1
- data/lib/code/parser/call.rb +17 -11
- data/lib/code/parser/chained_call.rb +10 -22
- data/lib/code/parser/class.rb +9 -6
- data/lib/code/parser/code.rb +6 -4
- data/lib/code/parser/{dictionnary.rb → dictionary.rb} +16 -13
- data/lib/code/parser/equal.rb +9 -36
- data/lib/code/parser/equality.rb +4 -2
- data/lib/code/parser/function.rb +24 -9
- data/lib/code/parser/greater.rb +6 -3
- data/lib/code/parser/group.rb +4 -2
- data/lib/code/parser/if.rb +6 -4
- data/lib/code/parser/if_modifier.rb +5 -25
- data/lib/code/parser/left_operation.rb +40 -0
- data/lib/code/parser/list.rb +6 -5
- data/lib/code/parser/multiplication.rb +4 -2
- data/lib/code/parser/name.rb +19 -4
- data/lib/code/parser/negation.rb +4 -2
- data/lib/code/parser/not_keyword.rb +5 -3
- data/lib/code/parser/nothing.rb +3 -10
- data/lib/code/parser/number.rb +4 -2
- data/lib/code/parser/or_keyword.rb +4 -2
- data/lib/code/parser/or_operator.rb +4 -2
- data/lib/code/parser/power.rb +4 -28
- data/lib/code/parser/range.rb +4 -2
- data/lib/code/parser/rescue.rb +6 -26
- data/lib/code/parser/right_operation.rb +40 -0
- data/lib/code/parser/shift.rb +4 -2
- data/lib/code/parser/splat.rb +5 -3
- data/lib/code/parser/square_bracket.rb +48 -0
- data/lib/code/parser/statement.rb +3 -1
- data/lib/code/parser/string.rb +12 -10
- data/lib/code/parser/ternary.rb +10 -11
- data/lib/code/parser/unary_minus.rb +5 -3
- data/lib/code/parser/while.rb +5 -3
- data/lib/code/parser/whitespace.rb +2 -0
- data/lib/code/parser.rb +10 -3
- data/lib/code/ruby.rb +4 -2
- data/lib/code/type/hash.rb +38 -0
- data/lib/code/type/maybe.rb +29 -0
- data/lib/code/type/or.rb +38 -0
- data/lib/code/type/repeat.rb +38 -0
- data/lib/code/type/sig.rb +130 -0
- data/lib/code/type.rb +25 -0
- data/lib/code/version.rb +3 -0
- data/lib/code-ruby.rb +1 -2
- data/lib/code.rb +15 -16
- data/spec/code/node/call_spec.rb +39 -0
- data/spec/code/object/boolean_spec.rb +18 -0
- data/spec/code/object/decimal_spec.rb +51 -0
- data/spec/code/object/dictionary_spec.rb +98 -0
- data/spec/code/object/function_spec.rb +42 -0
- data/spec/code/object/integer_spec.rb +43 -0
- data/spec/code/object/nothing_spec.rb +14 -0
- data/spec/code/object/range_spec.rb +23 -0
- data/spec/code/parser/boolean_spec.rb +5 -10
- data/spec/code/parser/chained_call.rb +4 -5
- data/spec/code/parser/{dictionnary_spec.rb → dictionary_spec.rb} +5 -6
- data/spec/code/parser/function_spec.rb +4 -5
- data/spec/code/parser/group_spec.rb +5 -12
- data/spec/code/parser/if_modifier_spec.rb +18 -0
- data/spec/code/parser/list_spec.rb +4 -5
- data/spec/code/parser/number_spec.rb +4 -5
- data/spec/code/parser/string_spec.rb +4 -5
- data/spec/code/parser_spec.rb +22 -16
- data/spec/code/type_spec.rb +21 -0
- data/spec/code_spec.rb +171 -0
- data/spec/spec_helper.rb +1 -6
- metadata +61 -137
- data/.cherry.js +0 -21
- data/.editorconfig +0 -9
- data/.github/workflows/rspec.yml +0 -14
- data/.gitignore +0 -2
- data/.prettierrc +0 -3
- data/.tool-versions +0 -1
- data/CHANGELOG.md +0 -55
- data/LICENSE +0 -7
- data/README.md +0 -103
- data/TODO +0 -17
- data/bin/code +0 -76
- data/bin/format +0 -3
- data/bin/publish +0 -19
- data/bin/template +0 -85
- data/bin/test +0 -17
- data/docs/class.code +0 -9
- data/docs/euler/1.template +0 -10
- data/docs/euler/2.template +0 -16
- data/docs/euler/3.template +0 -16
- data/docs/euler/4.template +0 -10
- data/docs/euler/5.template +0 -13
- data/docs/fibonnaci.template +0 -14
- data/docs/meetup.code +0 -12
- data/docs/precedence.template +0 -36
- data/docs/rain.code +0 -22
- data/docs/slack.code +0 -17
- data/docs/stripe.code +0 -7
- data/docs/twitter.code +0 -9
- data/language-ruby.gemspec +0 -17
- data/lib/code/node/chained_call.rb +0 -23
- data/lib/code/node/equal.rb +0 -34
- data/lib/code/node/if_modifier.rb +0 -47
- data/lib/code/node/operation.rb +0 -38
- data/lib/code/node/power.rb +0 -20
- data/lib/code/node/rescue.rb +0 -17
- data/lib/code/object/dictionnary.rb +0 -96
- data/lib/code/parser/equality_lower.rb +0 -9
- data/lib/code/parser/operation.rb +0 -35
- data/lib/language/atom.rb +0 -342
- data/lib/language/output.rb +0 -130
- data/lib/language/parser/absent/present.rb +0 -8
- data/lib/language/parser/absent.rb +0 -6
- data/lib/language/parser/end_of_input.rb +0 -6
- data/lib/language/parser/interuption.rb +0 -38
- data/lib/language/parser/not_end_of_input.rb +0 -6
- data/lib/language/parser/str/not_found.rb +0 -16
- data/lib/language/parser/str.rb +0 -6
- data/lib/language/parser.rb +0 -53
- data/lib/language-ruby.rb +0 -10
- data/lib/language.rb +0 -80
- data/lib/template/node/code_part.rb +0 -13
- data/lib/template/node/part.rb +0 -19
- data/lib/template/node/template.rb +0 -15
- data/lib/template/node/text_part.rb +0 -13
- data/lib/template/node.rb +0 -4
- data/lib/template/parser/template.rb +0 -39
- data/lib/template/parser.rb +0 -19
- data/lib/template/version.rb +0 -3
- data/lib/template-ruby.rb +0 -10
- data/lib/template.rb +0 -50
- data/spec/code/addition_spec.rb +0 -13
- data/spec/code/and_operator_spec.rb +0 -13
- data/spec/code/bitwise_and_spec.rb +0 -13
- data/spec/code/bitwise_or_spec.rb +0 -13
- data/spec/code/boolean_spec.rb +0 -13
- data/spec/code/call_spec.rb +0 -21
- data/spec/code/chained_call_spec.rb +0 -16
- data/spec/code/code_spec.rb +0 -11
- data/spec/code/dictionnary_spec.rb +0 -17
- data/spec/code/equal_spec.rb +0 -26
- data/spec/code/equality_spec.rb +0 -13
- data/spec/code/function_spec.rb +0 -18
- data/spec/code/greater_spec.rb +0 -18
- data/spec/code/group_spec.rb +0 -12
- data/spec/code/if_modifier_spec.rb +0 -20
- data/spec/code/if_spec.rb +0 -25
- data/spec/code/list_spec.rb +0 -19
- data/spec/code/multiplication_spec.rb +0 -18
- data/spec/code/negation_spec.rb +0 -20
- data/spec/code/not_keyword_spec.rb +0 -13
- data/spec/code/nothing_spec.rb +0 -17
- data/spec/code/number_spec.rb +0 -22
- data/spec/code/or_keyword_spec.rb +0 -17
- data/spec/code/or_operator_spec.rb +0 -16
- data/spec/code/parser/call_spec.rb +0 -26
- data/spec/code/power_spec.rb +0 -13
- data/spec/code/range_spec.rb +0 -16
- data/spec/code/rescue_spec.rb +0 -13
- data/spec/code/shift_spec.rb +0 -13
- data/spec/code/splat_spec.rb +0 -13
- data/spec/code/string_spec.rb +0 -27
- data/spec/code/ternary_spec.rb +0 -18
- data/spec/code/unary_minus_spec.rb +0 -13
- data/spec/code/while_spec.rb +0 -18
- data/template-ruby.gemspec +0 -19
data/lib/code/object/integer.rb
CHANGED
@@ -1,221 +1,404 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Code
|
2
4
|
class Object
|
3
|
-
class Integer <
|
5
|
+
class Integer < Number
|
4
6
|
attr_reader :raw
|
5
7
|
|
6
8
|
def initialize(whole, exponent: nil)
|
7
9
|
@raw = whole.to_i
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
raise ::Code::Error::TypeError.new("exponent is not a number")
|
14
|
-
end
|
11
|
+
return unless exponent
|
12
|
+
|
13
|
+
unless exponent.is_a?(Number)
|
14
|
+
raise Code::Error::TypeError, "exponent is not a number"
|
15
15
|
end
|
16
|
+
|
17
|
+
@raw *= 10**exponent.raw
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.name
|
21
|
+
"Integer"
|
16
22
|
end
|
17
23
|
|
18
24
|
def call(**args)
|
19
25
|
operator = args.fetch(:operator, nil)
|
20
26
|
arguments = args.fetch(:arguments, [])
|
21
|
-
globals = multi_fetch(args,
|
27
|
+
globals = multi_fetch(args, *GLOBALS)
|
22
28
|
value = arguments.first&.value
|
23
29
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
sig(
|
60
|
-
|
61
|
-
|
62
|
-
sig(
|
63
|
-
|
64
|
-
|
65
|
-
sig(
|
66
|
-
|
67
|
-
|
68
|
-
sig(
|
69
|
-
|
70
|
-
|
71
|
-
sig(
|
72
|
-
|
73
|
-
|
74
|
-
sig(
|
75
|
-
|
76
|
-
|
77
|
-
sig(
|
78
|
-
|
79
|
-
|
80
|
-
sig(
|
81
|
-
|
82
|
-
|
83
|
-
sig(
|
84
|
-
|
85
|
-
|
86
|
-
sig(
|
87
|
-
|
30
|
+
case operator.to_s
|
31
|
+
when "%", "modulo"
|
32
|
+
sig(args) { Number }
|
33
|
+
code_modulo(value)
|
34
|
+
when "&", "bitwise_and"
|
35
|
+
sig(args) { Number }
|
36
|
+
code_bitwise_and(value)
|
37
|
+
when "*", "multiplication"
|
38
|
+
sig(args) { Number | String }
|
39
|
+
code_multiplication(value)
|
40
|
+
when "**", "power"
|
41
|
+
sig(args) { Number }
|
42
|
+
code_power(value)
|
43
|
+
when "+", "plus"
|
44
|
+
sig(args) { Object.maybe }
|
45
|
+
value ? code_plus(value) : self
|
46
|
+
when "+", "plus", "self"
|
47
|
+
sig(args) { Object.maybe }
|
48
|
+
value ? code_plus(value) : code_self
|
49
|
+
when "-", "minus"
|
50
|
+
sig(args) { Number.maybe }
|
51
|
+
value ? code_minus(value) : code_unary_minus
|
52
|
+
when "-", "minus", "unary_minus"
|
53
|
+
sig(args) { Number.maybe }
|
54
|
+
value ? code_minus(value) : code_unary_minus
|
55
|
+
when "/", "division"
|
56
|
+
sig(args) { Number }
|
57
|
+
code_division(value)
|
58
|
+
when "<", "inferior"
|
59
|
+
sig(args) { Number }
|
60
|
+
code_inferior(value)
|
61
|
+
when "<<", "left_shift"
|
62
|
+
sig(args) { Number }
|
63
|
+
code_left_shift(value)
|
64
|
+
when "<=", "inferior_or_equal"
|
65
|
+
sig(args) { Number }
|
66
|
+
code_inferior_or_equal(value)
|
67
|
+
when "<=>", "compare"
|
68
|
+
sig(args) { Number }
|
69
|
+
code_compare(value)
|
70
|
+
when ">", "superior"
|
71
|
+
sig(args) { Number }
|
72
|
+
code_superior(value)
|
73
|
+
when ">=", "superior_or_equal"
|
74
|
+
sig(args) { Number }
|
75
|
+
code_superior_or_equal(value)
|
76
|
+
when ">>", "right_shift"
|
77
|
+
sig(args) { Number }
|
78
|
+
code_right_shift(value)
|
79
|
+
when "^", "bitwise_xor"
|
80
|
+
sig(args) { Number }
|
81
|
+
code_bitwise_xor(value)
|
82
|
+
when "abs"
|
83
|
+
sig(args)
|
84
|
+
code_abs
|
85
|
+
when "ceil"
|
86
|
+
sig(args) { Integer.maybe }
|
87
|
+
code_ceil(value)
|
88
|
+
when "clone"
|
89
|
+
sig(args)
|
90
|
+
code_clone
|
91
|
+
when "decrement!"
|
92
|
+
sig(args) { Integer.maybe }
|
93
|
+
code_decrement!(value)
|
94
|
+
when "decrement"
|
95
|
+
sig(args) { Integer.maybe }
|
96
|
+
code_decrement(value)
|
97
|
+
when "eight?"
|
98
|
+
sig(args)
|
99
|
+
code_eight?
|
100
|
+
when "even?"
|
101
|
+
sig(args)
|
102
|
+
code_even?
|
103
|
+
when "five?"
|
104
|
+
sig(args)
|
105
|
+
code_five?
|
106
|
+
when "floor"
|
107
|
+
sig(args) { Integer.maybe }
|
108
|
+
code_floor(value)
|
109
|
+
when "four?"
|
110
|
+
sig(args)
|
111
|
+
code_four?
|
112
|
+
when "increment!"
|
113
|
+
sig(args) { Integer.maybe }
|
114
|
+
code_increment!(value)
|
115
|
+
when "increment"
|
116
|
+
sig(args) { Integer.maybe }
|
117
|
+
code_increment(value)
|
118
|
+
when "nine?"
|
119
|
+
sig(args)
|
120
|
+
code_nine?
|
121
|
+
when "odd?"
|
122
|
+
sig(args)
|
123
|
+
code_odd?
|
124
|
+
when "one?"
|
125
|
+
sig(args)
|
126
|
+
code_one?
|
127
|
+
when "round"
|
128
|
+
sig(args) { Integer.maybe }
|
129
|
+
code_round(value)
|
130
|
+
when "seven?"
|
131
|
+
sig(args)
|
132
|
+
code_seven?
|
133
|
+
when "six?"
|
134
|
+
sig(args)
|
135
|
+
code_six?
|
136
|
+
when "sqrt"
|
137
|
+
sig(args)
|
138
|
+
code_sqrt
|
139
|
+
when "ten?"
|
140
|
+
sig(args)
|
141
|
+
code_ten?
|
142
|
+
when "three?"
|
143
|
+
sig(args)
|
144
|
+
code_three?
|
145
|
+
when "times"
|
146
|
+
sig(args) { Function }
|
147
|
+
code_times(value, **globals)
|
148
|
+
when "to_decimal"
|
149
|
+
sig(args)
|
150
|
+
code_to_decimal
|
151
|
+
when "to_integer"
|
152
|
+
sig(args)
|
153
|
+
code_to_integer
|
154
|
+
when "to_string"
|
155
|
+
sig(args)
|
156
|
+
code_to_string
|
157
|
+
when "truncate"
|
158
|
+
sig(args) { Integer.maybe }
|
159
|
+
code_truncate(value)
|
160
|
+
when "two?"
|
161
|
+
sig(args)
|
162
|
+
code_two?
|
163
|
+
when "zero?"
|
164
|
+
sig(args)
|
165
|
+
code_zero?
|
166
|
+
when "|", "bitwise_or"
|
167
|
+
sig(args) { Number }
|
168
|
+
code_bitwise_or(value)
|
88
169
|
else
|
89
170
|
super
|
90
171
|
end
|
91
172
|
end
|
92
173
|
|
93
|
-
def
|
94
|
-
|
174
|
+
def code_abs
|
175
|
+
Decimal.new(raw.abs)
|
95
176
|
end
|
96
177
|
|
97
|
-
def
|
98
|
-
|
178
|
+
def code_bitwise_and(other)
|
179
|
+
Integer.new(raw & other.raw.to_i)
|
99
180
|
end
|
100
181
|
|
101
|
-
def
|
102
|
-
raw.
|
182
|
+
def code_bitwise_or(other)
|
183
|
+
Integer.new(raw | other.raw.to_i)
|
103
184
|
end
|
104
185
|
|
105
|
-
def
|
106
|
-
|
186
|
+
def code_bitwise_xor(other)
|
187
|
+
Integer.new(raw ^ other.raw.to_i)
|
188
|
+
end
|
189
|
+
|
190
|
+
def code_ceil(n = nil)
|
191
|
+
n ||= Integer.new(0)
|
192
|
+
Integer.new(raw.ceil(n.raw))
|
193
|
+
end
|
194
|
+
|
195
|
+
def code_clone
|
196
|
+
Integer.new(raw)
|
197
|
+
end
|
198
|
+
|
199
|
+
def code_compare(other)
|
200
|
+
Integer.new(raw <=> other.raw)
|
201
|
+
end
|
202
|
+
|
203
|
+
def code_decrement!(n = nil)
|
204
|
+
n ||= Integer.new(1)
|
205
|
+
@raw -= n.raw
|
206
|
+
self
|
207
|
+
end
|
208
|
+
|
209
|
+
def code_decrement(n = nil)
|
210
|
+
n ||= Integer.new(1)
|
211
|
+
Integer.new(raw - n.raw)
|
212
|
+
end
|
213
|
+
|
214
|
+
def code_division(other)
|
215
|
+
Decimal.new(BigDecimal(raw) / other.raw)
|
216
|
+
end
|
217
|
+
|
218
|
+
def code_eight?
|
219
|
+
Boolean.new(raw == 8)
|
220
|
+
end
|
221
|
+
|
222
|
+
def code_even?
|
223
|
+
Boolean.new(raw.even?)
|
224
|
+
end
|
225
|
+
|
226
|
+
def code_five?
|
227
|
+
Boolean.new(raw == 5)
|
228
|
+
end
|
229
|
+
|
230
|
+
def code_floor(n = nil)
|
231
|
+
n ||= Integer.new(0)
|
232
|
+
Integer.new(raw.floor(n.raw))
|
233
|
+
end
|
234
|
+
|
235
|
+
def code_four?
|
236
|
+
Boolean.new(raw == 4)
|
237
|
+
end
|
238
|
+
|
239
|
+
def code_increment!(n = nil)
|
240
|
+
n ||= Integer.new(1)
|
241
|
+
@raw += n.raw
|
242
|
+
self
|
107
243
|
end
|
108
244
|
|
109
|
-
|
245
|
+
def code_increment(n = nil)
|
246
|
+
n ||= Integer.new(1)
|
247
|
+
Integer.new(raw + n.raw)
|
248
|
+
end
|
249
|
+
|
250
|
+
def code_inferior(other)
|
251
|
+
Boolean.new(raw < other.raw)
|
252
|
+
end
|
110
253
|
|
111
|
-
def
|
112
|
-
|
254
|
+
def code_inferior_or_equal(other)
|
255
|
+
Boolean.new(raw <= other.raw)
|
113
256
|
end
|
114
257
|
|
115
|
-
def
|
116
|
-
|
258
|
+
def code_left_shift(other)
|
259
|
+
Integer.new(raw << other.raw.to_i)
|
260
|
+
end
|
261
|
+
|
262
|
+
def code_minus(other)
|
263
|
+
if other.is_a?(Integer)
|
264
|
+
Integer.new(raw - other.raw)
|
265
|
+
else
|
266
|
+
Decimal.new(raw - other.raw)
|
267
|
+
end
|
117
268
|
end
|
118
269
|
|
119
|
-
def
|
120
|
-
if other.is_a?(
|
121
|
-
|
122
|
-
elsif other.is_a?(::Code::Object::Decimal)
|
123
|
-
::Code::Object::Decimal.new(raw * other.raw)
|
270
|
+
def code_modulo(other)
|
271
|
+
if other.is_a?(Integer)
|
272
|
+
Integer.new(raw % other.raw)
|
124
273
|
else
|
125
|
-
|
274
|
+
Decimal.new(raw % other.raw)
|
126
275
|
end
|
127
276
|
end
|
128
277
|
|
129
|
-
def
|
130
|
-
if other.is_a?(
|
131
|
-
|
132
|
-
elsif other.is_a?(
|
133
|
-
|
278
|
+
def code_multiplication(other)
|
279
|
+
if other.is_a?(Integer)
|
280
|
+
Integer.new(raw * other.raw)
|
281
|
+
elsif other.is_a?(Decimal)
|
282
|
+
Decimal.new(raw * other.raw)
|
134
283
|
else
|
135
|
-
|
284
|
+
String.new(other.raw * raw)
|
136
285
|
end
|
137
286
|
end
|
138
287
|
|
139
|
-
def
|
140
|
-
|
288
|
+
def code_nine?
|
289
|
+
Boolean.new(raw == 9)
|
141
290
|
end
|
142
291
|
|
143
|
-
def
|
144
|
-
|
145
|
-
|
292
|
+
def code_odd?
|
293
|
+
Boolean.new(raw.odd?)
|
294
|
+
end
|
295
|
+
|
296
|
+
def code_one?
|
297
|
+
Boolean.new(raw == 1)
|
298
|
+
end
|
299
|
+
|
300
|
+
def code_plus(other)
|
301
|
+
if other.is_a?(Integer)
|
302
|
+
Integer.new(raw + other.raw)
|
303
|
+
elsif other.is_a?(Decimal)
|
304
|
+
Decimal.new(raw + other.raw)
|
146
305
|
else
|
147
|
-
|
306
|
+
String.new(to_s + other.to_s)
|
148
307
|
end
|
149
308
|
end
|
150
309
|
|
151
|
-
def
|
152
|
-
if other.is_a?(
|
153
|
-
|
310
|
+
def code_power(other)
|
311
|
+
if other.is_a?(Integer)
|
312
|
+
Integer.new(raw**other.raw)
|
154
313
|
else
|
155
|
-
|
314
|
+
Decimal.new(raw**other.raw)
|
156
315
|
end
|
157
316
|
end
|
158
317
|
|
159
|
-
def
|
160
|
-
|
318
|
+
def code_right_shift(other)
|
319
|
+
Integer.new(raw >> other.raw.to_i)
|
161
320
|
end
|
162
321
|
|
163
|
-
def
|
164
|
-
|
165
|
-
|
166
|
-
else
|
167
|
-
::Code::Object::Decimal.new(raw**other.raw)
|
168
|
-
end
|
322
|
+
def code_round(n = nil)
|
323
|
+
n ||= Integer.new(0)
|
324
|
+
Integer.new(raw.round(n.raw))
|
169
325
|
end
|
170
326
|
|
171
|
-
def
|
172
|
-
|
327
|
+
def code_seven?
|
328
|
+
Boolean.new(raw == 7)
|
173
329
|
end
|
174
330
|
|
175
|
-
def
|
176
|
-
|
331
|
+
def code_six?
|
332
|
+
Boolean.new(raw == 6)
|
177
333
|
end
|
178
334
|
|
179
|
-
def
|
180
|
-
|
335
|
+
def code_sqrt
|
336
|
+
Decimal.new(Math.sqrt(raw).to_s)
|
181
337
|
end
|
182
338
|
|
183
|
-
def
|
184
|
-
|
339
|
+
def code_superior(other)
|
340
|
+
Boolean.new(raw > other.raw)
|
185
341
|
end
|
186
342
|
|
187
|
-
def
|
188
|
-
|
343
|
+
def code_superior_or_equal(other)
|
344
|
+
Boolean.new(raw >= other.raw)
|
189
345
|
end
|
190
346
|
|
191
|
-
def
|
192
|
-
|
347
|
+
def code_ten?
|
348
|
+
Boolean.new(raw == 10)
|
193
349
|
end
|
194
350
|
|
195
|
-
def
|
196
|
-
|
351
|
+
def code_three?
|
352
|
+
Boolean.new(raw == 3)
|
197
353
|
end
|
198
354
|
|
199
|
-
def
|
200
|
-
|
355
|
+
def code_to_decimal
|
356
|
+
Decimal.new(raw)
|
201
357
|
end
|
202
358
|
|
203
|
-
def
|
204
|
-
|
359
|
+
def code_to_integer
|
360
|
+
Integer.new(raw)
|
205
361
|
end
|
206
362
|
|
207
|
-
def
|
363
|
+
def code_times(argument, **globals)
|
208
364
|
raw.times do |element|
|
209
365
|
argument.call(
|
210
|
-
arguments: [
|
211
|
-
::Code::Object::Argument.new(::Code::Object::Integer.new(element))
|
212
|
-
],
|
366
|
+
arguments: [Argument.new(Integer.new(element))],
|
213
367
|
**globals
|
214
368
|
)
|
215
369
|
end
|
216
370
|
|
217
371
|
self
|
218
372
|
end
|
373
|
+
|
374
|
+
def code_truncate(n = nil)
|
375
|
+
n ||= Integer.new(0)
|
376
|
+
Integer.new(raw.truncate(n.raw))
|
377
|
+
end
|
378
|
+
|
379
|
+
def code_two?
|
380
|
+
Boolean.new(raw == 2)
|
381
|
+
end
|
382
|
+
|
383
|
+
def code_unary_minus
|
384
|
+
Integer.new(-raw)
|
385
|
+
end
|
386
|
+
|
387
|
+
def code_zero?
|
388
|
+
Boolean.new(raw.zero?)
|
389
|
+
end
|
390
|
+
|
391
|
+
def inspect
|
392
|
+
to_s
|
393
|
+
end
|
394
|
+
|
395
|
+
def succ
|
396
|
+
Integer.new(raw + 1)
|
397
|
+
end
|
398
|
+
|
399
|
+
def to_s
|
400
|
+
raw.to_s
|
401
|
+
end
|
219
402
|
end
|
220
403
|
end
|
221
404
|
end
|