#-- # this code is generated by mkprims.rb #++ require_relative "typespec" module Gogyou module Primitives class Primitive < ::Struct.new(:name, :bytesize, :bytealign) BasicStruct = superclass 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 extensible? false end def to_s "#{self.class}[name=#{name.inspect}, bytesize=#{bytesize.inspect}, bytealign=#{bytealign.inspect}]" end alias inspect to_s def pretty_print(q) #name, bytesize, bytealign q.group(1, "#{self.class}[") do q.text "name=" q.pp name q.text ", " #q.breakable q.text "bytesize=" q.pp bytesize q.text ", " #q.breakable q.text "bytealign=" q.pp bytealign end q.text "]" end end 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) }, ->(buf, offset) { buf.load_ssizet(offset) }].freeze INTPTR_T = Primitive[:intptr_t, TypeSpec::SIZEOF_SIZE_T, TypeSpec::SIZEOF_SIZE_T, ->(buf, offset, num) { buf.store_sizet(offset, num) }, ->(buf, offset) { buf.load_ssizet(offset) }].freeze UINTPTR_T = Primitive[:uintptr_t, TypeSpec::SIZEOF_SIZE_T, TypeSpec::SIZEOF_SIZE_T, ->(buf, offset, num) { buf.store_sizet(offset, num) }, ->(buf, offset) { buf.load_sizet(offset) }].freeze INT8_T = Primitive[:int8_t, 1, 1, ->(buf, offset, num) { buf.store8(offset, num) }, ->(buf, offset) { buf.loadi8(offset) }].freeze UINT8_T = Primitive[:uint8_t, 1, 1, ->(buf, offset, num) { buf.store8(offset, num) }, ->(buf, offset) { buf.loadu8(offset) }].freeze INT16_T = Primitive[:int16_t, 2, 2, ->(buf, offset, num) { buf.store16(offset, num) }, ->(buf, offset) { buf.loadi16(offset) }].freeze UINT16_T = Primitive[:uint16_t, 2, 2, ->(buf, offset, num) { buf.store16(offset, num) }, ->(buf, offset) { buf.loadu16(offset) }].freeze INT24_T = Primitive[:int24_t, 3, 1, ->(buf, offset, num) { buf.store24(offset, num) }, ->(buf, offset) { buf.loadi24(offset) }].freeze UINT24_T = Primitive[:uint24_t, 3, 1, ->(buf, offset, num) { buf.store24(offset, num) }, ->(buf, offset) { buf.loadu24(offset) }].freeze INT32_T = Primitive[:int32_t, 4, 4, ->(buf, offset, num) { buf.store32(offset, num) }, ->(buf, offset) { buf.loadi32(offset) }].freeze UINT32_T = Primitive[:uint32_t, 4, 4, ->(buf, offset, num) { buf.store32(offset, num) }, ->(buf, offset) { buf.loadu32(offset) }].freeze INT48_T = Primitive[:int48_t, 6, 2, ->(buf, offset, num) { buf.store48(offset, num) }, ->(buf, offset) { buf.loadi48(offset) }].freeze UINT48_T = Primitive[:uint48_t, 6, 2, ->(buf, offset, num) { buf.store48(offset, num) }, ->(buf, offset) { buf.loadu48(offset) }].freeze INT64_T = Primitive[:int64_t, 8, 8, ->(buf, offset, num) { buf.store64(offset, num) }, ->(buf, offset) { buf.loadi64(offset) }].freeze UINT64_T = Primitive[:uint64_t, 8, 8, ->(buf, offset, num) { buf.store64(offset, num) }, ->(buf, offset) { buf.loadu64(offset) }].freeze INT16_BE = Primitive[:int16_be, 2, 2, ->(buf, offset, num) { buf.store16be(offset, num) }, ->(buf, offset) { buf.loadi16be(offset) }].freeze UINT16_BE = Primitive[:uint16_be, 2, 2, ->(buf, offset, num) { buf.store16be(offset, num) }, ->(buf, offset) { buf.loadu16be(offset) }].freeze INT24_BE = Primitive[:int24_be, 3, 1, ->(buf, offset, num) { buf.store24be(offset, num) }, ->(buf, offset) { buf.loadi24be(offset) }].freeze UINT24_BE = Primitive[:uint24_be, 3, 1, ->(buf, offset, num) { buf.store24be(offset, num) }, ->(buf, offset) { buf.loadu24be(offset) }].freeze INT32_BE = Primitive[:int32_be, 4, 4, ->(buf, offset, num) { buf.store32be(offset, num) }, ->(buf, offset) { buf.loadi32be(offset) }].freeze UINT32_BE = Primitive[:uint32_be, 4, 4, ->(buf, offset, num) { buf.store32be(offset, num) }, ->(buf, offset) { buf.loadu32be(offset) }].freeze INT48_BE = Primitive[:int48_be, 6, 2, ->(buf, offset, num) { buf.store48be(offset, num) }, ->(buf, offset) { buf.loadi48be(offset) }].freeze UINT48_BE = Primitive[:uint48_be, 6, 2, ->(buf, offset, num) { buf.store48be(offset, num) }, ->(buf, offset) { buf.loadu48be(offset) }].freeze INT64_BE = Primitive[:int64_be, 8, 8, ->(buf, offset, num) { buf.store64be(offset, num) }, ->(buf, offset) { buf.loadi64be(offset) }].freeze UINT64_BE = Primitive[:uint64_be, 8, 8, ->(buf, offset, num) { buf.store64be(offset, num) }, ->(buf, offset) { buf.loadu64be(offset) }].freeze INT16_LE = Primitive[:int16_le, 2, 2, ->(buf, offset, num) { buf.store16le(offset, num) }, ->(buf, offset) { buf.loadi16le(offset) }].freeze UINT16_LE = Primitive[:uint16_le, 2, 2, ->(buf, offset, num) { buf.store16le(offset, num) }, ->(buf, offset) { buf.loadu16le(offset) }].freeze INT24_LE = Primitive[:int24_le, 3, 1, ->(buf, offset, num) { buf.store24le(offset, num) }, ->(buf, offset) { buf.loadi24le(offset) }].freeze UINT24_LE = Primitive[:uint24_le, 3, 1, ->(buf, offset, num) { buf.store24le(offset, num) }, ->(buf, offset) { buf.loadu24le(offset) }].freeze INT32_LE = Primitive[:int32_le, 4, 4, ->(buf, offset, num) { buf.store32le(offset, num) }, ->(buf, offset) { buf.loadi32le(offset) }].freeze UINT32_LE = Primitive[:uint32_le, 4, 4, ->(buf, offset, num) { buf.store32le(offset, num) }, ->(buf, offset) { buf.loadu32le(offset) }].freeze INT48_LE = Primitive[:int48_le, 6, 2, ->(buf, offset, num) { buf.store48le(offset, num) }, ->(buf, offset) { buf.loadi48le(offset) }].freeze UINT48_LE = Primitive[:uint48_le, 6, 2, ->(buf, offset, num) { buf.store48le(offset, num) }, ->(buf, offset) { buf.loadu48le(offset) }].freeze INT64_LE = Primitive[:int64_le, 8, 8, ->(buf, offset, num) { buf.store64le(offset, num) }, ->(buf, offset) { buf.loadi64le(offset) }].freeze UINT64_LE = Primitive[:uint64_le, 8, 8, ->(buf, offset, num) { buf.store64le(offset, num) }, ->(buf, offset) { buf.loadu64le(offset) }].freeze INT16_SWAP = Primitive[:int16_swap, 2, 2, ->(buf, offset, num) { buf.store16swap(offset, num) }, ->(buf, offset) { buf.loadi16swap(offset) }].freeze UINT16_SWAP = Primitive[:uint16_swap, 2, 2, ->(buf, offset, num) { buf.store16swap(offset, num) }, ->(buf, offset) { buf.loadu16swap(offset) }].freeze INT24_SWAP = Primitive[:int24_swap, 3, 1, ->(buf, offset, num) { buf.store24swap(offset, num) }, ->(buf, offset) { buf.loadi24swap(offset) }].freeze UINT24_SWAP = Primitive[:uint24_swap, 3, 1, ->(buf, offset, num) { buf.store24swap(offset, num) }, ->(buf, offset) { buf.loadu24swap(offset) }].freeze INT32_SWAP = Primitive[:int32_swap, 4, 4, ->(buf, offset, num) { buf.store32swap(offset, num) }, ->(buf, offset) { buf.loadi32swap(offset) }].freeze UINT32_SWAP = Primitive[:uint32_swap, 4, 4, ->(buf, offset, num) { buf.store32swap(offset, num) }, ->(buf, offset) { buf.loadu32swap(offset) }].freeze INT48_SWAP = Primitive[:int48_swap, 6, 2, ->(buf, offset, num) { buf.store48swap(offset, num) }, ->(buf, offset) { buf.loadi48swap(offset) }].freeze UINT48_SWAP = Primitive[:uint48_swap, 6, 2, ->(buf, offset, num) { buf.store48swap(offset, num) }, ->(buf, offset) { buf.loadu48swap(offset) }].freeze INT64_SWAP = Primitive[:int64_swap, 8, 8, ->(buf, offset, num) { buf.store64swap(offset, num) }, ->(buf, offset) { buf.loadi64swap(offset) }].freeze UINT64_SWAP = Primitive[:uint64_swap, 8, 8, ->(buf, offset, num) { buf.store64swap(offset, num) }, ->(buf, offset) { buf.loadu64swap(offset) }].freeze CHAR = Primitive[:char, 1, 1, ->(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 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 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) }, ->(buf, offset) { buf.loadf64be(offset) }].freeze FLOAT_LE = Primitive[:float_le, 4, 4, ->(buf, offset, num) { buf.storef32le(offset, num) }, ->(buf, offset) { buf.loadf32le(offset) }].freeze DOUBLE_LE = Primitive[:double_le, 8, 8, ->(buf, offset, num) { buf.storef64le(offset, num) }, ->(buf, offset) { buf.loadf64le(offset) }].freeze FLOAT_SWAP = Primitive[:float_swap, 4, 4, ->(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 end class Model TYPEMAP = { size_t: Primitives::SIZE_T, ssize_t: Primitives::SSIZE_T, intptr_t: Primitives::INTPTR_T, uintptr_t: Primitives::UINTPTR_T, int8_t: Primitives::INT8_T, uint8_t: Primitives::UINT8_T, int16_t: Primitives::INT16_T, uint16_t: Primitives::UINT16_T, int24_t: Primitives::INT24_T, uint24_t: Primitives::UINT24_T, int32_t: Primitives::INT32_T, uint32_t: Primitives::UINT32_T, int48_t: Primitives::INT48_T, uint48_t: Primitives::UINT48_T, int64_t: Primitives::INT64_T, uint64_t: Primitives::UINT64_T, int16_be: Primitives::INT16_BE, uint16_be: Primitives::UINT16_BE, int24_be: Primitives::INT24_BE, uint24_be: Primitives::UINT24_BE, int32_be: Primitives::INT32_BE, uint32_be: Primitives::UINT32_BE, int48_be: Primitives::INT48_BE, uint48_be: Primitives::UINT48_BE, int64_be: Primitives::INT64_BE, uint64_be: Primitives::UINT64_BE, int16_le: Primitives::INT16_LE, uint16_le: Primitives::UINT16_LE, int24_le: Primitives::INT24_LE, uint24_le: Primitives::UINT24_LE, int32_le: Primitives::INT32_LE, uint32_le: Primitives::UINT32_LE, int48_le: Primitives::INT48_LE, uint48_le: Primitives::UINT48_LE, int64_le: Primitives::INT64_LE, uint64_le: Primitives::UINT64_LE, int16_swap: Primitives::INT16_SWAP, uint16_swap: Primitives::UINT16_SWAP, int24_swap: Primitives::INT24_SWAP, uint24_swap: Primitives::UINT24_SWAP, int32_swap: Primitives::INT32_SWAP, uint32_swap: Primitives::UINT32_SWAP, int48_swap: Primitives::INT48_SWAP, uint48_swap: Primitives::UINT48_SWAP, int64_swap: Primitives::INT64_SWAP, uint64_swap: Primitives::UINT64_SWAP, char: Primitives::CHAR, uchar: Primitives::UCHAR, short: Primitives::SHORT, ushort: Primitives::USHORT, int: Primitives::INT, uint: Primitives::UINT, long: Primitives::LONG, ulong: Primitives::ULONG, longlong: Primitives::LONGLONG, ulonglong: Primitives::ULONGLONG, float: Primitives::FLOAT, double: Primitives::DOUBLE, float_be: Primitives::FLOAT_BE, double_be: Primitives::DOUBLE_BE, float_le: Primitives::FLOAT_LE, double_le: Primitives::DOUBLE_LE, float_swap: Primitives::FLOAT_SWAP, double_swap: Primitives::DOUBLE_SWAP, } TYPEMAP[:unsigned_char] = TYPEMAP[:uchar] TYPEMAP[:unsigned_short] = TYPEMAP[:ushort] TYPEMAP[:unsigned_int] = TYPEMAP[:uint] TYPEMAP[:unsigned_long] = TYPEMAP[:ulong] TYPEMAP[:unsigned_long_long] = TYPEMAP[:ulonglong] TYPEMAP[:long_long] = TYPEMAP[:longlong] end end