gogyou 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.ja.md +51 -0
- data/{LICENSE.markdown → LICENSE} +0 -0
- data/{README.markdown → README.md} +166 -90
- data/Rakefile +101 -58
- data/gemstub.rb +15 -18
- data/lib/gogyou.rb +88 -40
- data/lib/gogyou/accessor.rb +113 -58
- data/lib/gogyou/mixin.rb +8 -8
- data/lib/gogyou/model.rb +93 -53
- data/lib/gogyou/primitives.rb +6 -109
- data/lib/gogyou/typespec.rb +4 -4
- data/lib/gogyou/version.rb +3 -0
- data/mkprims.rb +7 -50
- data/spec/gogyou_spec.rb +6 -2
- metadata +19 -15
data/lib/gogyou/mixin.rb
CHANGED
@@ -320,15 +320,15 @@ module Gogyou
|
|
320
320
|
end
|
321
321
|
|
322
322
|
def loadu8(index)
|
323
|
-
getbyte(index
|
323
|
+
getbyte(index)
|
324
324
|
end
|
325
325
|
|
326
326
|
def loadi8(index)
|
327
|
-
|
327
|
+
getbyte(index).extendsign(8)
|
328
328
|
end
|
329
329
|
|
330
330
|
def loadu16be(index)
|
331
|
-
(
|
331
|
+
(getbyte(index) << 8) | getbyte(index + 1)
|
332
332
|
end
|
333
333
|
|
334
334
|
def loadi16be(index)
|
@@ -336,7 +336,7 @@ module Gogyou
|
|
336
336
|
end
|
337
337
|
|
338
338
|
def loadu16le(index)
|
339
|
-
|
339
|
+
getbyte(index) | (getbyte(index + 1) << 8)
|
340
340
|
end
|
341
341
|
|
342
342
|
def loadi16le(index)
|
@@ -344,7 +344,7 @@ module Gogyou
|
|
344
344
|
end
|
345
345
|
|
346
346
|
def loadu24be(index)
|
347
|
-
(
|
347
|
+
(getbyte(index) << 16) | (getbyte(index + 1) << 8) | getbyte(index + 2)
|
348
348
|
end
|
349
349
|
|
350
350
|
def loadi24be(index)
|
@@ -352,7 +352,7 @@ module Gogyou
|
|
352
352
|
end
|
353
353
|
|
354
354
|
def loadu24le(index)
|
355
|
-
|
355
|
+
getbyte(index) | (getbyte(index + 1) << 8) | (getbyte(index + 2) << 16)
|
356
356
|
end
|
357
357
|
|
358
358
|
def loadi24le(index)
|
@@ -360,7 +360,7 @@ module Gogyou
|
|
360
360
|
end
|
361
361
|
|
362
362
|
def loadu32be(index)
|
363
|
-
(
|
363
|
+
(getbyte(index) << 24) | (getbyte(index + 1) << 16) | (getbyte(index + 2) << 8) | getbyte(index + 3)
|
364
364
|
end
|
365
365
|
|
366
366
|
def loadi32be(index)
|
@@ -368,7 +368,7 @@ module Gogyou
|
|
368
368
|
end
|
369
369
|
|
370
370
|
def loadu32le(index)
|
371
|
-
|
371
|
+
getbyte(index) | (getbyte(index + 1) << 8) | (getbyte(index + 2) << 16) | (getbyte(index + 3) << 24)
|
372
372
|
end
|
373
373
|
|
374
374
|
def loadi32le(index)
|
data/lib/gogyou/model.rb
CHANGED
@@ -13,14 +13,24 @@ module Gogyou
|
|
13
13
|
|
14
14
|
undef :bytesize=, :bytealign=, :fields=
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
#
|
17
|
+
# call-seq:
|
18
|
+
# initialize(bytesize, bytealign, fields, ...)
|
19
|
+
#
|
20
|
+
# [bytesize]
|
21
|
+
# This is total model size in bytes.
|
22
|
+
#
|
23
|
+
# [bytealign]
|
24
|
+
# This is model alignment size in bytes.
|
25
|
+
#
|
26
|
+
# [fields ...]
|
27
|
+
# These are one or more field instance.
|
28
|
+
#
|
29
|
+
def initialize(bytesize, bytealign, field1, *fields)
|
30
|
+
if fields.empty? && field1.kind_of?(::Array)
|
21
31
|
super
|
22
32
|
else
|
23
|
-
super
|
33
|
+
super bytesize.to_i, bytealign.to_i, [field1, *fields]
|
24
34
|
end
|
25
35
|
end
|
26
36
|
|
@@ -85,6 +95,11 @@ module Gogyou
|
|
85
95
|
end
|
86
96
|
end
|
87
97
|
|
98
|
+
def bytesize
|
99
|
+
s = type.bytesize
|
100
|
+
vector ? vector.inject(&:*) * s : s
|
101
|
+
end
|
102
|
+
|
88
103
|
def const?
|
89
104
|
((flags & CONST_BITMASK) == CONST_BITMASK) ? true : false
|
90
105
|
end
|
@@ -215,7 +230,7 @@ module Gogyou
|
|
215
230
|
end
|
216
231
|
|
217
232
|
def maxsize(fields = self.fields)
|
218
|
-
fields.map { |f|
|
233
|
+
fields.map { |f| f.bytesize }.max
|
219
234
|
end
|
220
235
|
|
221
236
|
def flatten_field(fields = self.fields)
|
@@ -236,59 +251,15 @@ module Gogyou
|
|
236
251
|
fields2
|
237
252
|
end
|
238
253
|
|
239
|
-
# :nodoc: all
|
240
|
-
class Proxy < Object
|
241
|
-
#class Proxy < BasicObject
|
242
|
-
def initialize(creator, packexp = Field::PACKSIZE_NOTDEFINE)
|
243
|
-
#singleton_class = (class << proxy; self; end)
|
244
|
-
singleton_class.class_eval do
|
245
|
-
latest_fields = nil
|
246
|
-
#define_method(:method_missing, ->(type, *args) { latest_fields = creator.addfield(type, args); nil })
|
247
|
-
creator.typemap.each_key do |t|
|
248
|
-
define_method(t, ->(*args) { latest_fields = creator.addfield(t, packexp, args); nil })
|
249
|
-
end
|
250
|
-
define_method(:struct, ->(*args, &block) { latest_fields = creator.struct(args, packexp, &block); nil })
|
251
|
-
define_method(:union, ->(*args, &block) { latest_fields = creator.union(args, packexp, &block); nil })
|
252
|
-
define_method(:const, ->(dummy_fields) { creator.const(latest_fields); latest_fields = nil; nil })
|
253
|
-
define_method(:typedef, ->(*args, &block) { creator.typedef(args, &block) })
|
254
|
-
packexp0 = nil
|
255
|
-
define_method(:packed, ->(bytealign = 1, &block) {
|
256
|
-
raise "wrong nested ``packed''" if packexp0
|
257
|
-
exp = Math.log(bytealign, 2)
|
258
|
-
# exp が Nan Infinity -Infinity の場合は例外が発生するので、それに対する処置も行う
|
259
|
-
unless ((exp = exp.to_i) rescue nil) && (1 << exp) == bytealign
|
260
|
-
raise ArgumentError, "shall be given power of two (but #{bytealign})"
|
261
|
-
end
|
262
|
-
|
263
|
-
begin
|
264
|
-
packexp0 = packexp
|
265
|
-
packexp = exp
|
266
|
-
self.instance_exec(&block)
|
267
|
-
ensure
|
268
|
-
(packexp, packexp0) = packexp0, nil
|
269
|
-
end
|
270
|
-
|
271
|
-
nil
|
272
|
-
})
|
273
|
-
if creator.respond_to?(:bytealign)
|
274
|
-
define_method(:bytealign, ->(bytesize, &block) { creator.bytealign(bytesize, &block); nil })
|
275
|
-
end
|
276
|
-
if creator.respond_to?(:padding)
|
277
|
-
define_method(:padding, ->(bytesize, &block) { creator.padding(bytesize, &block); nil })
|
278
|
-
end
|
279
|
-
end
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
254
|
#
|
284
255
|
# call-seq:
|
285
256
|
# struct type, name, *vector
|
286
257
|
# struct proc, name, *vector
|
287
258
|
# struct { ... }
|
288
259
|
#
|
289
|
-
#
|
260
|
+
# 最初と二番目の呼び出し方法は、既存の (typedef していない) 型情報を用いる、または構造体をその場で定義するために利用できます。
|
290
261
|
#
|
291
|
-
#
|
262
|
+
# 三番目の呼び出し方法は、無名構造体を定義するために利用できます。
|
292
263
|
#
|
293
264
|
# === example (型情報を用いる)
|
294
265
|
#
|
@@ -360,6 +331,28 @@ module Gogyou
|
|
360
331
|
fields.each { |f| f.set_const }
|
361
332
|
end
|
362
333
|
|
334
|
+
#
|
335
|
+
# call-seq:
|
336
|
+
# packed { ... } -> nil
|
337
|
+
# packed(bytealign) { ... } -> nil
|
338
|
+
#
|
339
|
+
# ブロック内部のフィールドのバイトアライメントを調節します。
|
340
|
+
#
|
341
|
+
# packed を直接の入れ子にして呼び出すことは出来ません。struct や union を挟んで呼び出すことは出来ます。
|
342
|
+
#
|
343
|
+
# 引数無しで呼び出した場合は、bytealign に 1 を与えて呼び出すものと同義となります。
|
344
|
+
#
|
345
|
+
# [bytealign]
|
346
|
+
# 1 以上で2の冪乗となる整数値を指定します。
|
347
|
+
#
|
348
|
+
# nil を与えた場合、上位階層で指定したパックサイズを無効化して本来のバイトアライメントに配置するようにします。
|
349
|
+
#
|
350
|
+
def packed(bytealign = 1)
|
351
|
+
raise "This method is defined for documentaion. Real implemented is in Gogyou::Model::BasicCreator::Proxy#initialize"
|
352
|
+
yield
|
353
|
+
nil
|
354
|
+
end
|
355
|
+
|
363
356
|
#
|
364
357
|
# フィールド名の解析
|
365
358
|
#
|
@@ -429,6 +422,53 @@ module Gogyou
|
|
429
422
|
|
430
423
|
tmpfields
|
431
424
|
end
|
425
|
+
|
426
|
+
class Proxy < Object # :nodoc: all
|
427
|
+
#class Proxy < BasicObject
|
428
|
+
def initialize(creator, packexp = Field::PACKSIZE_NOTDEFINE)
|
429
|
+
#singleton_class = (class << proxy; self; end)
|
430
|
+
singleton_class.class_eval do
|
431
|
+
latest_fields = nil
|
432
|
+
#define_method(:method_missing, ->(type, *args) { latest_fields = creator.addfield(type, args); nil })
|
433
|
+
creator.typemap.each_key do |t|
|
434
|
+
define_method(t, ->(*args) { latest_fields = creator.addfield(t, packexp, args); nil })
|
435
|
+
end
|
436
|
+
define_method(:struct, ->(*args, &block) { latest_fields = creator.struct(args, packexp, &block); nil })
|
437
|
+
define_method(:union, ->(*args, &block) { latest_fields = creator.union(args, packexp, &block); nil })
|
438
|
+
define_method(:const, ->(dummy_fields) { creator.const(latest_fields); latest_fields = nil; nil })
|
439
|
+
define_method(:typedef, ->(*args, &block) { creator.typedef(args, &block) })
|
440
|
+
packexp0 = nil
|
441
|
+
define_method(:packed, ->(bytealign = 1, &block) {
|
442
|
+
raise "wrong nested ``packed''" if packexp0
|
443
|
+
if bytealign.nil?
|
444
|
+
exp = Field::PACKSIZE_NOTDEFINE
|
445
|
+
else
|
446
|
+
exp = Math.log(bytealign, 2)
|
447
|
+
# exp が Nan Infinity -Infinity の場合は例外が発生するので、それに対する処置も行う
|
448
|
+
unless ((exp = exp.to_i) rescue nil) && (1 << exp) == bytealign
|
449
|
+
raise ArgumentError, "shall be given power of two (but #{bytealign})"
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
453
|
+
begin
|
454
|
+
packexp0 = packexp
|
455
|
+
packexp = exp
|
456
|
+
self.instance_exec(&block)
|
457
|
+
ensure
|
458
|
+
(packexp, packexp0) = packexp0, nil
|
459
|
+
end
|
460
|
+
|
461
|
+
nil
|
462
|
+
})
|
463
|
+
if creator.respond_to?(:bytealign)
|
464
|
+
define_method(:bytealign, ->(bytesize, &block) { creator.bytealign(bytesize, &block); nil })
|
465
|
+
end
|
466
|
+
if creator.respond_to?(:padding)
|
467
|
+
define_method(:padding, ->(bytesize, &block) { creator.padding(bytesize, &block); nil })
|
468
|
+
end
|
469
|
+
end
|
470
|
+
end
|
471
|
+
end
|
432
472
|
end
|
433
473
|
|
434
474
|
class Struct < Model
|
data/lib/gogyou/primitives.rb
CHANGED
@@ -22,26 +22,23 @@ module Gogyou
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def to_s
|
25
|
-
"
|
25
|
+
"\#<#{self.class}:#{name} bytesize=#{bytesize.inspect}, bytealign=#{bytealign.inspect}>"
|
26
26
|
end
|
27
27
|
|
28
28
|
alias inspect to_s
|
29
29
|
|
30
30
|
def pretty_print(q)
|
31
31
|
#name, bytesize, bytealign
|
32
|
-
q.group(1, "
|
33
|
-
q.
|
34
|
-
q.pp name
|
35
|
-
q.text ", "
|
36
|
-
#q.breakable
|
32
|
+
q.group(1, "\#<#{self.class}:#{name}") do
|
33
|
+
q.breakable " "
|
37
34
|
q.text "bytesize="
|
38
35
|
q.pp bytesize
|
39
|
-
q.text ",
|
40
|
-
|
36
|
+
q.text ","
|
37
|
+
q.breakable " "
|
41
38
|
q.text "bytealign="
|
42
39
|
q.pp bytealign
|
43
40
|
end
|
44
|
-
q.text "
|
41
|
+
q.text ">"
|
45
42
|
end
|
46
43
|
end
|
47
44
|
|
@@ -69,24 +66,12 @@ module Gogyou
|
|
69
66
|
UINT16_T = Primitive[:uint16_t, 2, 2,
|
70
67
|
->(buf, offset, num) { buf.store16(offset, num) },
|
71
68
|
->(buf, offset) { buf.loadu16(offset) }].freeze
|
72
|
-
INT24_T = Primitive[:int24_t, 3, 1,
|
73
|
-
->(buf, offset, num) { buf.store24(offset, num) },
|
74
|
-
->(buf, offset) { buf.loadi24(offset) }].freeze
|
75
|
-
UINT24_T = Primitive[:uint24_t, 3, 1,
|
76
|
-
->(buf, offset, num) { buf.store24(offset, num) },
|
77
|
-
->(buf, offset) { buf.loadu24(offset) }].freeze
|
78
69
|
INT32_T = Primitive[:int32_t, 4, 4,
|
79
70
|
->(buf, offset, num) { buf.store32(offset, num) },
|
80
71
|
->(buf, offset) { buf.loadi32(offset) }].freeze
|
81
72
|
UINT32_T = Primitive[:uint32_t, 4, 4,
|
82
73
|
->(buf, offset, num) { buf.store32(offset, num) },
|
83
74
|
->(buf, offset) { buf.loadu32(offset) }].freeze
|
84
|
-
INT48_T = Primitive[:int48_t, 6, 2,
|
85
|
-
->(buf, offset, num) { buf.store48(offset, num) },
|
86
|
-
->(buf, offset) { buf.loadi48(offset) }].freeze
|
87
|
-
UINT48_T = Primitive[:uint48_t, 6, 2,
|
88
|
-
->(buf, offset, num) { buf.store48(offset, num) },
|
89
|
-
->(buf, offset) { buf.loadu48(offset) }].freeze
|
90
75
|
INT64_T = Primitive[:int64_t, 8, 8,
|
91
76
|
->(buf, offset, num) { buf.store64(offset, num) },
|
92
77
|
->(buf, offset) { buf.loadi64(offset) }].freeze
|
@@ -159,24 +144,12 @@ module Gogyou
|
|
159
144
|
UINT16_SWAP = Primitive[:uint16_swap, 2, 2,
|
160
145
|
->(buf, offset, num) { buf.store16swap(offset, num) },
|
161
146
|
->(buf, offset) { buf.loadu16swap(offset) }].freeze
|
162
|
-
INT24_SWAP = Primitive[:int24_swap, 3, 1,
|
163
|
-
->(buf, offset, num) { buf.store24swap(offset, num) },
|
164
|
-
->(buf, offset) { buf.loadi24swap(offset) }].freeze
|
165
|
-
UINT24_SWAP = Primitive[:uint24_swap, 3, 1,
|
166
|
-
->(buf, offset, num) { buf.store24swap(offset, num) },
|
167
|
-
->(buf, offset) { buf.loadu24swap(offset) }].freeze
|
168
147
|
INT32_SWAP = Primitive[:int32_swap, 4, 4,
|
169
148
|
->(buf, offset, num) { buf.store32swap(offset, num) },
|
170
149
|
->(buf, offset) { buf.loadi32swap(offset) }].freeze
|
171
150
|
UINT32_SWAP = Primitive[:uint32_swap, 4, 4,
|
172
151
|
->(buf, offset, num) { buf.store32swap(offset, num) },
|
173
152
|
->(buf, offset) { buf.loadu32swap(offset) }].freeze
|
174
|
-
INT48_SWAP = Primitive[:int48_swap, 6, 2,
|
175
|
-
->(buf, offset, num) { buf.store48swap(offset, num) },
|
176
|
-
->(buf, offset) { buf.loadi48swap(offset) }].freeze
|
177
|
-
UINT48_SWAP = Primitive[:uint48_swap, 6, 2,
|
178
|
-
->(buf, offset, num) { buf.store48swap(offset, num) },
|
179
|
-
->(buf, offset) { buf.loadu48swap(offset) }].freeze
|
180
153
|
INT64_SWAP = Primitive[:int64_swap, 8, 8,
|
181
154
|
->(buf, offset, num) { buf.store64swap(offset, num) },
|
182
155
|
->(buf, offset) { buf.loadi64swap(offset) }].freeze
|
@@ -238,80 +211,4 @@ module Gogyou
|
|
238
211
|
->(buf, offset, num) { buf.storef64swap(offset, num) },
|
239
212
|
->(buf, offset) { buf.loadf64swap(offset) }].freeze
|
240
213
|
end
|
241
|
-
|
242
|
-
class Model
|
243
|
-
TYPEMAP = {
|
244
|
-
size_t: Primitives::SIZE_T,
|
245
|
-
ssize_t: Primitives::SSIZE_T,
|
246
|
-
intptr_t: Primitives::INTPTR_T,
|
247
|
-
uintptr_t: Primitives::UINTPTR_T,
|
248
|
-
int8_t: Primitives::INT8_T,
|
249
|
-
uint8_t: Primitives::UINT8_T,
|
250
|
-
int16_t: Primitives::INT16_T,
|
251
|
-
uint16_t: Primitives::UINT16_T,
|
252
|
-
int24_t: Primitives::INT24_T,
|
253
|
-
uint24_t: Primitives::UINT24_T,
|
254
|
-
int32_t: Primitives::INT32_T,
|
255
|
-
uint32_t: Primitives::UINT32_T,
|
256
|
-
int48_t: Primitives::INT48_T,
|
257
|
-
uint48_t: Primitives::UINT48_T,
|
258
|
-
int64_t: Primitives::INT64_T,
|
259
|
-
uint64_t: Primitives::UINT64_T,
|
260
|
-
int16_be: Primitives::INT16_BE,
|
261
|
-
uint16_be: Primitives::UINT16_BE,
|
262
|
-
int24_be: Primitives::INT24_BE,
|
263
|
-
uint24_be: Primitives::UINT24_BE,
|
264
|
-
int32_be: Primitives::INT32_BE,
|
265
|
-
uint32_be: Primitives::UINT32_BE,
|
266
|
-
int48_be: Primitives::INT48_BE,
|
267
|
-
uint48_be: Primitives::UINT48_BE,
|
268
|
-
int64_be: Primitives::INT64_BE,
|
269
|
-
uint64_be: Primitives::UINT64_BE,
|
270
|
-
int16_le: Primitives::INT16_LE,
|
271
|
-
uint16_le: Primitives::UINT16_LE,
|
272
|
-
int24_le: Primitives::INT24_LE,
|
273
|
-
uint24_le: Primitives::UINT24_LE,
|
274
|
-
int32_le: Primitives::INT32_LE,
|
275
|
-
uint32_le: Primitives::UINT32_LE,
|
276
|
-
int48_le: Primitives::INT48_LE,
|
277
|
-
uint48_le: Primitives::UINT48_LE,
|
278
|
-
int64_le: Primitives::INT64_LE,
|
279
|
-
uint64_le: Primitives::UINT64_LE,
|
280
|
-
int16_swap: Primitives::INT16_SWAP,
|
281
|
-
uint16_swap: Primitives::UINT16_SWAP,
|
282
|
-
int24_swap: Primitives::INT24_SWAP,
|
283
|
-
uint24_swap: Primitives::UINT24_SWAP,
|
284
|
-
int32_swap: Primitives::INT32_SWAP,
|
285
|
-
uint32_swap: Primitives::UINT32_SWAP,
|
286
|
-
int48_swap: Primitives::INT48_SWAP,
|
287
|
-
uint48_swap: Primitives::UINT48_SWAP,
|
288
|
-
int64_swap: Primitives::INT64_SWAP,
|
289
|
-
uint64_swap: Primitives::UINT64_SWAP,
|
290
|
-
char: Primitives::CHAR,
|
291
|
-
uchar: Primitives::UCHAR,
|
292
|
-
short: Primitives::SHORT,
|
293
|
-
ushort: Primitives::USHORT,
|
294
|
-
int: Primitives::INT,
|
295
|
-
uint: Primitives::UINT,
|
296
|
-
long: Primitives::LONG,
|
297
|
-
ulong: Primitives::ULONG,
|
298
|
-
longlong: Primitives::LONGLONG,
|
299
|
-
ulonglong: Primitives::ULONGLONG,
|
300
|
-
float: Primitives::FLOAT,
|
301
|
-
double: Primitives::DOUBLE,
|
302
|
-
float_be: Primitives::FLOAT_BE,
|
303
|
-
double_be: Primitives::DOUBLE_BE,
|
304
|
-
float_le: Primitives::FLOAT_LE,
|
305
|
-
double_le: Primitives::DOUBLE_LE,
|
306
|
-
float_swap: Primitives::FLOAT_SWAP,
|
307
|
-
double_swap: Primitives::DOUBLE_SWAP,
|
308
|
-
}
|
309
|
-
|
310
|
-
TYPEMAP[:unsigned_char] = TYPEMAP[:uchar]
|
311
|
-
TYPEMAP[:unsigned_short] = TYPEMAP[:ushort]
|
312
|
-
TYPEMAP[:unsigned_int] = TYPEMAP[:uint]
|
313
|
-
TYPEMAP[:unsigned_long] = TYPEMAP[:ulong]
|
314
|
-
TYPEMAP[:unsigned_long_long] = TYPEMAP[:ulonglong]
|
315
|
-
TYPEMAP[:long_long] = TYPEMAP[:longlong]
|
316
|
-
end
|
317
214
|
end
|
data/lib/gogyou/typespec.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Gogyou
|
2
2
|
module TypeSpec
|
3
3
|
SIZEOF_CHAR = [0].pack("C").bytesize
|
4
|
-
SIZEOF_SHORT = [0].pack("S").bytesize
|
5
|
-
SIZEOF_INT = [0].pack("I").bytesize
|
6
|
-
SIZEOF_LONG = [0].pack("L").bytesize
|
7
|
-
SIZEOF_LONGLONG = [0].pack("Q").bytesize
|
4
|
+
SIZEOF_SHORT = [0].pack("S!").bytesize
|
5
|
+
SIZEOF_INT = [0].pack("I!").bytesize
|
6
|
+
SIZEOF_LONG = [0].pack("L!").bytesize
|
7
|
+
SIZEOF_LONGLONG = [0].pack("Q!").bytesize
|
8
8
|
SIZEOF_SIZE_T = [nil].pack("P").bytesize
|
9
9
|
SIZEOF_FLOAT = [0].pack("F").bytesize
|
10
10
|
SIZEOF_DOUBLE = [0].pack("D").bytesize
|
data/mkprims.rb
CHANGED
@@ -12,12 +12,8 @@ int8_t 1 1 store8 loadi8
|
|
12
12
|
uint8_t 1 1 store8 loadu8
|
13
13
|
int16_t 2 2 store16 loadi16
|
14
14
|
uint16_t 2 2 store16 loadu16
|
15
|
-
int24_t 3 1 store24 loadi24
|
16
|
-
uint24_t 3 1 store24 loadu24
|
17
15
|
int32_t 4 4 store32 loadi32
|
18
16
|
uint32_t 4 4 store32 loadu32
|
19
|
-
int48_t 6 2 store48 loadi48
|
20
|
-
uint48_t 6 2 store48 loadu48
|
21
17
|
int64_t 8 8 store64 loadi64
|
22
18
|
uint64_t 8 8 store64 loadu64
|
23
19
|
int16_be 2 2 store16be loadi16be
|
@@ -42,12 +38,8 @@ int64_le 8 8 store64le loadi64le
|
|
42
38
|
uint64_le 8 8 store64le loadu64le
|
43
39
|
int16_swap 2 2 store16swap loadi16swap
|
44
40
|
uint16_swap 2 2 store16swap loadu16swap
|
45
|
-
int24_swap 3 1 store24swap loadi24swap
|
46
|
-
uint24_swap 3 1 store24swap loadu24swap
|
47
41
|
int32_swap 4 4 store32swap loadi32swap
|
48
42
|
uint32_swap 4 4 store32swap loadu32swap
|
49
|
-
int48_swap 6 2 store48swap loadi48swap
|
50
|
-
uint48_swap 6 2 store48swap loadu48swap
|
51
43
|
int64_swap 8 8 store64swap loadi64swap
|
52
44
|
uint64_swap 8 8 store64swap loadu64swap
|
53
45
|
char 1 1 store8 loadi8
|
@@ -96,26 +88,23 @@ module Gogyou
|
|
96
88
|
end
|
97
89
|
|
98
90
|
def to_s
|
99
|
-
"
|
91
|
+
"\\\#<\#{self.class}:\#{name} bytesize=\#{bytesize.inspect}, bytealign=\#{bytealign.inspect}>"
|
100
92
|
end
|
101
93
|
|
102
94
|
alias inspect to_s
|
103
95
|
|
104
96
|
def pretty_print(q)
|
105
97
|
#name, bytesize, bytealign
|
106
|
-
q.group(1, "
|
107
|
-
q.
|
108
|
-
q.pp name
|
109
|
-
q.text ", "
|
110
|
-
#q.breakable
|
98
|
+
q.group(1, "\\\#<\#{self.class}:\#{name}") do
|
99
|
+
q.breakable " "
|
111
100
|
q.text "bytesize="
|
112
101
|
q.pp bytesize
|
113
|
-
q.text ",
|
114
|
-
|
102
|
+
q.text ","
|
103
|
+
q.breakable " "
|
115
104
|
q.text "bytealign="
|
116
105
|
q.pp bytealign
|
117
106
|
end
|
118
|
-
q.text "
|
107
|
+
q.text ">"
|
119
108
|
end
|
120
109
|
end
|
121
110
|
|
@@ -123,7 +112,7 @@ module Gogyou
|
|
123
112
|
|
124
113
|
records = records.split(/\n/)
|
125
114
|
records.map! { |r| r.split(/\s+/) }
|
126
|
-
|
115
|
+
|
127
116
|
records.each do |typename, bytesize, bytealign, aset, aref|
|
128
117
|
name = typename.upcase
|
129
118
|
f.puts <<-EOS
|
@@ -135,38 +124,6 @@ module Gogyou
|
|
135
124
|
|
136
125
|
f.puts <<-EOS
|
137
126
|
end
|
138
|
-
|
139
|
-
class Model
|
140
|
-
TYPEMAP = {
|
141
|
-
EOS
|
142
|
-
|
143
|
-
records.each do |typename, bytesize, bytealign, aset, aref|
|
144
|
-
sym = typename.to_sym.inspect
|
145
|
-
f.puts <<-EOS % ["#{typename}:".ljust(17, " "), typename.upcase]
|
146
|
-
%s Primitives::%s,
|
147
|
-
EOS
|
148
|
-
end
|
149
|
-
|
150
|
-
f.puts <<-EOS
|
151
|
-
}
|
152
|
-
|
153
|
-
EOS
|
154
|
-
|
155
|
-
[
|
156
|
-
%w(unsigned_char uchar),
|
157
|
-
%w(unsigned_short ushort),
|
158
|
-
%w(unsigned_int uint),
|
159
|
-
%w(unsigned_long ulong),
|
160
|
-
%w(unsigned_long_long ulonglong),
|
161
|
-
%w(long_long longlong),
|
162
|
-
].each do |link, name|
|
163
|
-
f.puts <<-EOS
|
164
|
-
TYPEMAP[:#{link}] = TYPEMAP[:#{name}]
|
165
|
-
EOS
|
166
|
-
end
|
167
|
-
|
168
|
-
f.puts <<-EOS
|
169
|
-
end
|
170
127
|
end
|
171
128
|
EOS
|
172
129
|
end
|