Class: Wardite::I64
- Inherits:
-
Object
- Object
- Wardite::I64
- Includes:
- ValueHelper
- Defined in:
- lib/wardite/value.rb
Constant Summary collapse
- I64_MAX =
(1<<64) - 1
Instance Attribute Summary collapse
-
#value ⇒ Object
: Integer.
Class Method Summary collapse
Instance Method Summary collapse
- #convert_s(to:) ⇒ Object
- #convert_u(to:) ⇒ Object
- #demote(to:) ⇒ Object
- #extend_s(to:) ⇒ Object
- #extend_u(to:) ⇒ Object
-
#inspect ⇒ Object
I64#inspect shows signed value.
- #memsize ⇒ Object
- #packed(size: nil) ⇒ Object
- #promote(to:) ⇒ Object
- #reinterpret(to:) ⇒ Object
- #trunc_s(to:) ⇒ Object
- #trunc_u(to:) ⇒ Object
-
#value_s ⇒ Object
returns a value interpreted as signed integer.
- #wrap(to:) ⇒ Object
Methods included from ValueHelper
Instance Attribute Details
#value ⇒ Object
: Integer
201 202 203 |
# File 'lib/wardite/value.rb', line 201 def value @value end |
Class Method Details
.from_bytes(str, size: nil, signed: false) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/wardite/value.rb', line 207 def self.from_bytes(str, size: nil, signed: false) v = case size when nil str.unpack("L!")[0] when 8 signed ? str.unpack("c")[0] : str.unpack("C")[0] when 16 signed ? str.unpack("s!")[0] : str.unpack("S!")[0] when 32 signed ? str.unpack("i!")[0] : str.unpack("I!")[0] end if !v.is_a?(Integer) raise "broken string or unsupported size: #{str.inspect} -> #{size}" end Wardite::I64(v) end |
Instance Method Details
#convert_s(to:) ⇒ Object
289 290 291 292 293 294 295 296 297 298 |
# File 'lib/wardite/value.rb', line 289 def convert_s(to:) case to when :f32 F32(value_s.to_f) when :f64 F64(value_s.to_f) else raise EvalError, "unsupported operation" end end |
#convert_u(to:) ⇒ Object
302 303 304 305 306 307 308 309 310 311 |
# File 'lib/wardite/value.rb', line 302 def convert_u(to:) case to when :f32 F32(value.to_f) when :f64 F64(value.to_f) else raise EvalError, "unsupported operation" end end |
#demote(to:) ⇒ Object
315 316 317 |
# File 'lib/wardite/value.rb', line 315 def demote(to:) raise EvalError, "unsupported operation" end |
#extend_s(to:) ⇒ Object
265 266 267 |
# File 'lib/wardite/value.rb', line 265 def extend_s(to:) raise EvalError, "unsupported operation" end |
#extend_u(to:) ⇒ Object
271 272 273 |
# File 'lib/wardite/value.rb', line 271 def extend_u(to:) raise EvalError, "unsupported operation" end |
#inspect ⇒ Object
I64#inspect shows signed value
335 336 337 |
# File 'lib/wardite/value.rb', line 335 def inspect "I64(#{@value})" end |
#memsize ⇒ Object
225 226 227 |
# File 'lib/wardite/value.rb', line 225 def memsize 64 end |
#packed(size: nil) ⇒ Object
239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/wardite/value.rb', line 239 def packed(size: nil) case size when nil [self.value].pack("L!") when 8 [self.value & 0xff].pack("C") when 16 [self.value & 0xffff].pack("S!") when 32 [self.value & 0xffffffff].pack("I!") else raise EvalError, "unsupported size #{size}" end end |
#promote(to:) ⇒ Object
321 322 323 |
# File 'lib/wardite/value.rb', line 321 def promote(to:) raise EvalError, "unsupported operation" end |
#reinterpret(to:) ⇒ Object
327 328 329 330 331 332 |
# File 'lib/wardite/value.rb', line 327 def reinterpret(to:) raise EvalError, "unsupported operation" if to != :f64 v = [value].pack("L!").unpack("d")[0] raise EvalError, "[BUG] String#unpack is broke, really?" if !v.is_a?(Float) F32(v) end |
#trunc_s(to:) ⇒ Object
277 278 279 |
# File 'lib/wardite/value.rb', line 277 def trunc_s(to:) raise EvalError, "unsupported operation" end |
#trunc_u(to:) ⇒ Object
283 284 285 |
# File 'lib/wardite/value.rb', line 283 def trunc_u(to:) raise EvalError, "unsupported operation" end |
#value_s ⇒ Object
returns a value interpreted as signed integer
231 232 233 234 235 |
# File 'lib/wardite/value.rb', line 231 def value_s (@value >> 63).zero? ? @value : ((-@value) ^ I64_MAX) + 1 end |