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
204 205 206 |
# File 'lib/wardite/value.rb', line 204 def value @value end |
Class Method Details
.from_bytes(str, size: nil, signed: false) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/wardite/value.rb', line 210 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
292 293 294 295 296 297 298 299 300 301 |
# File 'lib/wardite/value.rb', line 292 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
305 306 307 308 309 310 311 312 313 314 |
# File 'lib/wardite/value.rb', line 305 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
318 319 320 |
# File 'lib/wardite/value.rb', line 318 def demote(to:) raise EvalError, "unsupported operation" end |
#extend_s(to:) ⇒ Object
268 269 270 |
# File 'lib/wardite/value.rb', line 268 def extend_s(to:) raise EvalError, "unsupported operation" end |
#extend_u(to:) ⇒ Object
274 275 276 |
# File 'lib/wardite/value.rb', line 274 def extend_u(to:) raise EvalError, "unsupported operation" end |
#inspect ⇒ Object
I64#inspect shows signed value
338 339 340 |
# File 'lib/wardite/value.rb', line 338 def inspect "I64(#{@value})" end |
#memsize ⇒ Object
228 229 230 |
# File 'lib/wardite/value.rb', line 228 def memsize 64 end |
#packed(size: nil) ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/wardite/value.rb', line 242 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
324 325 326 |
# File 'lib/wardite/value.rb', line 324 def promote(to:) raise EvalError, "unsupported operation" end |
#reinterpret(to:) ⇒ Object
330 331 332 333 334 335 |
# File 'lib/wardite/value.rb', line 330 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
280 281 282 |
# File 'lib/wardite/value.rb', line 280 def trunc_s(to:) raise EvalError, "unsupported operation" end |
#trunc_u(to:) ⇒ Object
286 287 288 |
# File 'lib/wardite/value.rb', line 286 def trunc_u(to:) raise EvalError, "unsupported operation" end |
#value_s ⇒ Object
returns a value interpreted as signed integer
234 235 236 237 238 |
# File 'lib/wardite/value.rb', line 234 def value_s (@value >> 63).zero? ? @value : ((-@value) ^ I64_MAX) + 1 end |