lib/gogyou/primitives.rb in gogyou-0.2.3 vs lib/gogyou/primitives.rb in gogyou-0.2.4
- old
+ new
@@ -3,47 +3,47 @@
#++
require_relative "typespec"
module Gogyou
- module Primitives
- class Primitive < ::Struct.new(:name, :bytesize, :bytealign)
- BasicStruct = superclass
+ class Primitive < ::Struct.new(:name, :bytesize, :bytealign)
+ BasicStruct = superclass
- undef :name=, :bytesize=, :bytealign=
+ undef :name=, :bytesize=, :bytealign=
- def initialize(name, bytesize, bytealign, aset, aref)
- super(name.intern, bytesize.to_i, bytealign.to_i)
- define_singleton_method(:aset, aset)
- define_singleton_method(:aref, aref)
- end
+ def initialize(name, bytesize, bytealign, aset, aref)
+ super(name.intern, bytesize.to_i, bytealign.to_i)
+ define_singleton_method(:aset, aset)
+ define_singleton_method(:aref, aref)
+ end
- def extensible?
- false
- end
+ def extensible?
+ false
+ end
- def to_s
- "\#<#{self.class}:#{name} bytesize=#{bytesize.inspect}, bytealign=#{bytealign.inspect}>"
- end
+ def to_s
+ "\#<#{self.class}:#{name} bytesize=#{bytesize.inspect}, bytealign=#{bytealign.inspect}>"
+ end
- alias inspect to_s
+ alias inspect to_s
- def pretty_print(q)
- #name, bytesize, bytealign
- q.group(1, "\#<#{self.class}:#{name}") do
- q.breakable " "
- q.text "bytesize="
- q.pp bytesize
- q.text ","
- q.breakable " "
- q.text "bytealign="
- q.pp bytealign
- end
- q.text ">"
+ def pretty_print(q)
+ #name, bytesize, bytealign
+ q.group(1, "\#<#{self.class}:#{name}") do
+ q.breakable " "
+ q.text "bytesize="
+ q.pp bytesize
+ q.text ","
+ q.breakable " "
+ q.text "bytealign="
+ q.pp bytealign
end
+ q.text ">"
end
+ end
+ module Primitives
SIZE_T = Primitive[:size_t, TypeSpec::SIZEOF_SIZE_T, TypeSpec::SIZEOF_SIZE_T,
->(buf, offset, num) { buf.store_sizet(offset, num) },
->(buf, offset) { buf.load_sizet(offset) }].freeze
SSIZE_T = Primitive[:ssize_t, TypeSpec::SIZEOF_SIZE_T, TypeSpec::SIZEOF_SIZE_T,
->(buf, offset, num) { buf.store_sizet(offset, num) },
@@ -160,40 +160,40 @@
->(buf, offset, num) { buf.store8(offset, num) },
->(buf, offset) { buf.loadi8(offset) }].freeze
UCHAR = Primitive[:uchar, 1, 1,
->(buf, offset, num) { buf.store8(offset, num) },
->(buf, offset) { buf.loadu8(offset) }].freeze
- SHORT = Primitive[:short, 2, 2,
- ->(buf, offset, num) { buf.store16(offset, num) },
- ->(buf, offset) { buf.loadi16(offset) }].freeze
- USHORT = Primitive[:ushort, 2, 2,
- ->(buf, offset, num) { buf.store16(offset, num) },
- ->(buf, offset) { buf.loadu16(offset) }].freeze
- INT = Primitive[:int, 4, 4,
- ->(buf, offset, num) { buf.store32(offset, num) },
- ->(buf, offset) { buf.loadi32(offset) }].freeze
- UINT = Primitive[:uint, 4, 4,
- ->(buf, offset, num) { buf.store32(offset, num) },
- ->(buf, offset) { buf.loadu32(offset) }].freeze
+ SHORT = Primitive[:short, TypeSpec::SIZEOF_SHORT, TypeSpec::SIZEOF_SHORT,
+ ->(buf, offset, num) { buf.store_short(offset, num) },
+ ->(buf, offset) { buf.load_short(offset) }].freeze
+ USHORT = Primitive[:ushort, TypeSpec::SIZEOF_SHORT, TypeSpec::SIZEOF_SHORT,
+ ->(buf, offset, num) { buf.store_short(offset, num) },
+ ->(buf, offset) { buf.load_ushort(offset) }].freeze
+ INT = Primitive[:int, TypeSpec::SIZEOF_INT, TypeSpec::SIZEOF_INT,
+ ->(buf, offset, num) { buf.store_int(offset, num) },
+ ->(buf, offset) { buf.load_int(offset) }].freeze
+ UINT = Primitive[:uint, TypeSpec::SIZEOF_INT, TypeSpec::SIZEOF_INT,
+ ->(buf, offset, num) { buf.store_int(offset, num) },
+ ->(buf, offset) { buf.load_uint(offset) }].freeze
LONG = Primitive[:long, TypeSpec::SIZEOF_LONG, TypeSpec::SIZEOF_LONG,
->(buf, offset, num) { buf.store_long(offset, num) },
->(buf, offset) { buf.load_long(offset) }].freeze
ULONG = Primitive[:ulong, TypeSpec::SIZEOF_LONG, TypeSpec::SIZEOF_LONG,
->(buf, offset, num) { buf.store_long(offset, num) },
->(buf, offset) { buf.load_ulong(offset) }].freeze
- LONGLONG = Primitive[:longlong, 8, 8,
- ->(buf, offset, num) { buf.store64(offset, num) },
- ->(buf, offset) { buf.loadi64(offset) }].freeze
- ULONGLONG = Primitive[:ulonglong, 8, 8,
- ->(buf, offset, num) { buf.store64(offset, num) },
- ->(buf, offset) { buf.loadu64(offset) }].freeze
- FLOAT = Primitive[:float, 4, 4,
- ->(buf, offset, num) { buf.storef32(offset, num) },
- ->(buf, offset) { buf.loadf32(offset) }].freeze
- DOUBLE = Primitive[:double, 8, 8,
- ->(buf, offset, num) { buf.storef64(offset, num) },
- ->(buf, offset) { buf.loadf64(offset) }].freeze
+ LONGLONG = Primitive[:longlong, TypeSpec::SIZEOF_LONGLONG, TypeSpec::SIZEOF_LONGLONG,
+ ->(buf, offset, num) { buf.store_longlong(offset, num) },
+ ->(buf, offset) { buf.load_longlong(offset) }].freeze
+ ULONGLONG = Primitive[:ulonglong, TypeSpec::SIZEOF_LONGLONG, TypeSpec::SIZEOF_LONGLONG,
+ ->(buf, offset, num) { buf.store_longlong(offset, num) },
+ ->(buf, offset) { buf.load_ulonglong(offset) }].freeze
+ FLOAT = Primitive[:float, TypeSpec::SIZEOF_FLOAT, TypeSpec::SIZEOF_FLOAT,
+ ->(buf, offset, num) { buf.store_float(offset, num) },
+ ->(buf, offset) { buf.load_float(offset) }].freeze
+ DOUBLE = Primitive[:double, TypeSpec::SIZEOF_DOUBLE, TypeSpec::SIZEOF_DOUBLE,
+ ->(buf, offset, num) { buf.store_double(offset, num) },
+ ->(buf, offset) { buf.load_double(offset) }].freeze
FLOAT_BE = Primitive[:float_be, 4, 4,
->(buf, offset, num) { buf.storef32be(offset, num) },
->(buf, offset) { buf.loadf32be(offset) }].freeze
DOUBLE_BE = Primitive[:double_be, 8, 8,
->(buf, offset, num) { buf.storef64be(offset, num) },
@@ -208,7 +208,115 @@
->(buf, offset, num) { buf.storef32swap(offset, num) },
->(buf, offset) { buf.loadf32swap(offset) }].freeze
DOUBLE_SWAP = Primitive[:double_swap, 8, 8,
->(buf, offset, num) { buf.storef64swap(offset, num) },
->(buf, offset) { buf.loadf64swap(offset) }].freeze
+ FLOAT16_T = Primitive[:float16_t, 2, 2,
+ ->(buf, offset, num) { buf.storef16(offset, num) },
+ ->(buf, offset) { buf.loadf16(offset) }].freeze
+ FLOAT16_SWAP = Primitive[:float16_swap, 2, 2,
+ ->(buf, offset, num) { buf.storef16swap(offset, num) },
+ ->(buf, offset) { buf.loadf16swap(offset) }].freeze
+ FLOAT16_BE = Primitive[:float16_be, 2, 2,
+ ->(buf, offset, num) { buf.storef16be(offset, num) },
+ ->(buf, offset) { buf.loadf16be(offset) }].freeze
+ FLOAT16_LE = Primitive[:float16_le, 2, 2,
+ ->(buf, offset, num) { buf.storef16le(offset, num) },
+ ->(buf, offset) { buf.loadf16le(offset) }].freeze
+ FLOAT32_T = Primitive[:float32_t, 4, 4,
+ ->(buf, offset, num) { buf.storef32(offset, num) },
+ ->(buf, offset) { buf.loadf32(offset) }].freeze
+ FLOAT32_SWAP = Primitive[:float32_swap, 4, 4,
+ ->(buf, offset, num) { buf.storef32swap(offset, num) },
+ ->(buf, offset) { buf.loadf32swap(offset) }].freeze
+ FLOAT32_BE = Primitive[:float32_be, 4, 4,
+ ->(buf, offset, num) { buf.storef32be(offset, num) },
+ ->(buf, offset) { buf.loadf32be(offset) }].freeze
+ FLOAT32_LE = Primitive[:float32_le, 4, 4,
+ ->(buf, offset, num) { buf.storef32le(offset, num) },
+ ->(buf, offset) { buf.loadf32le(offset) }].freeze
+ FLOAT64_T = Primitive[:float64_t, 8, 8,
+ ->(buf, offset, num) { buf.storef64(offset, num) },
+ ->(buf, offset) { buf.loadf64(offset) }].freeze
+ FLOAT64_SWAP = Primitive[:float64_swap, 8, 8,
+ ->(buf, offset, num) { buf.storef64swap(offset, num) },
+ ->(buf, offset) { buf.loadf64swap(offset) }].freeze
+ FLOAT64_BE = Primitive[:float64_be, 8, 8,
+ ->(buf, offset, num) { buf.storef64be(offset, num) },
+ ->(buf, offset) { buf.loadf64be(offset) }].freeze
+ FLOAT64_LE = Primitive[:float64_le, 8, 8,
+ ->(buf, offset, num) { buf.storef64le(offset, num) },
+ ->(buf, offset) { buf.loadf64le(offset) }].freeze
+ FIXED16Q8_T = Primitive[:fixed16q8_t, 2, 2,
+ ->(buf, offset, num) { buf.store16q8(offset, num) },
+ ->(buf, offset) { buf.loadi16q8(offset) }].freeze
+ FIXED16Q8_SWAP = Primitive[:fixed16q8_swap, 2, 2,
+ ->(buf, offset, num) { buf.store16q8swap(offset, num) },
+ ->(buf, offset) { buf.loadi16q8swap(offset) }].freeze
+ FIXED16Q8_BE = Primitive[:fixed16q8_be, 2, 2,
+ ->(buf, offset, num) { buf.store16q8be(offset, num) },
+ ->(buf, offset) { buf.loadi16q8be(offset) }].freeze
+ FIXED16Q8_LE = Primitive[:fixed16q8_le, 2, 2,
+ ->(buf, offset, num) { buf.store16q8le(offset, num) },
+ ->(buf, offset) { buf.loadi16q8le(offset) }].freeze
+ FIXED32Q6_T = Primitive[:fixed32q6_t, 4, 4,
+ ->(buf, offset, num) { buf.store32q6(offset, num) },
+ ->(buf, offset) { buf.loadi32q6(offset) }].freeze
+ FIXED32Q6_SWAP = Primitive[:fixed32q6_swap, 4, 4,
+ ->(buf, offset, num) { buf.store32q6swap(offset, num) },
+ ->(buf, offset) { buf.loadi32q6swap(offset) }].freeze
+ FIXED32Q6_BE = Primitive[:fixed32q6_be, 4, 4,
+ ->(buf, offset, num) { buf.store32q6be(offset, num) },
+ ->(buf, offset) { buf.loadi32q6be(offset) }].freeze
+ FIXED32Q6_LE = Primitive[:fixed32q6_le, 4, 4,
+ ->(buf, offset, num) { buf.store32q6le(offset, num) },
+ ->(buf, offset) { buf.loadi32q6le(offset) }].freeze
+ FIXED32Q8_T = Primitive[:fixed32q8_t, 4, 4,
+ ->(buf, offset, num) { buf.store32q8(offset, num) },
+ ->(buf, offset) { buf.loadi32q8(offset) }].freeze
+ FIXED32Q8_SWAP = Primitive[:fixed32q8_swap, 4, 4,
+ ->(buf, offset, num) { buf.store32q8swap(offset, num) },
+ ->(buf, offset) { buf.loadi32q8swap(offset) }].freeze
+ FIXED32Q8_BE = Primitive[:fixed32q8_be, 4, 4,
+ ->(buf, offset, num) { buf.store32q8be(offset, num) },
+ ->(buf, offset) { buf.loadi32q8be(offset) }].freeze
+ FIXED32Q8_LE = Primitive[:fixed32q8_le, 4, 4,
+ ->(buf, offset, num) { buf.store32q8le(offset, num) },
+ ->(buf, offset) { buf.loadi32q8le(offset) }].freeze
+ FIXED32Q12_T = Primitive[:fixed32q12_t, 4, 4,
+ ->(buf, offset, num) { buf.store32q12(offset, num) },
+ ->(buf, offset) { buf.loadi32q12(offset) }].freeze
+ FIXED32Q12_SWAP = Primitive[:fixed32q12_swap, 4, 4,
+ ->(buf, offset, num) { buf.store32q12swap(offset, num) },
+ ->(buf, offset) { buf.loadi32q12swap(offset) }].freeze
+ FIXED32Q12_BE = Primitive[:fixed32q12_be, 4, 4,
+ ->(buf, offset, num) { buf.store32q12be(offset, num) },
+ ->(buf, offset) { buf.loadi32q12be(offset) }].freeze
+ FIXED32Q12_LE = Primitive[:fixed32q12_le, 4, 4,
+ ->(buf, offset, num) { buf.store32q12le(offset, num) },
+ ->(buf, offset) { buf.loadi32q12le(offset) }].freeze
+ FIXED32Q16_T = Primitive[:fixed32q16_t, 4, 4,
+ ->(buf, offset, num) { buf.store32q16(offset, num) },
+ ->(buf, offset) { buf.loadi32q16(offset) }].freeze
+ FIXED32Q16_SWAP = Primitive[:fixed32q16_swap, 4, 4,
+ ->(buf, offset, num) { buf.store32q16swap(offset, num) },
+ ->(buf, offset) { buf.loadi32q16swap(offset) }].freeze
+ FIXED32Q16_BE = Primitive[:fixed32q16_be, 4, 4,
+ ->(buf, offset, num) { buf.store32q16be(offset, num) },
+ ->(buf, offset) { buf.loadi32q16be(offset) }].freeze
+ FIXED32Q16_LE = Primitive[:fixed32q16_le, 4, 4,
+ ->(buf, offset, num) { buf.store32q16le(offset, num) },
+ ->(buf, offset) { buf.loadi32q16le(offset) }].freeze
+ FIXED32Q24_T = Primitive[:fixed32q24_t, 4, 4,
+ ->(buf, offset, num) { buf.store32q24(offset, num) },
+ ->(buf, offset) { buf.loadi32q24(offset) }].freeze
+ FIXED32Q24_SWAP = Primitive[:fixed32q24_swap, 4, 4,
+ ->(buf, offset, num) { buf.store32q24swap(offset, num) },
+ ->(buf, offset) { buf.loadi32q24swap(offset) }].freeze
+ FIXED32Q24_BE = Primitive[:fixed32q24_be, 4, 4,
+ ->(buf, offset, num) { buf.store32q24be(offset, num) },
+ ->(buf, offset) { buf.loadi32q24be(offset) }].freeze
+ FIXED32Q24_LE = Primitive[:fixed32q24_le, 4, 4,
+ ->(buf, offset, num) { buf.store32q24le(offset, num) },
+ ->(buf, offset) { buf.loadi32q24le(offset) }].freeze
end
end