1
1
mirror of https://github.com/wader/fq.git synced 2024-11-30 09:58:13 +03:00

luajit: standardize field names (key/value/type ect.)

This commit is contained in:
Babz 2023-06-21 20:42:15 +02:00
parent 3561c08a8c
commit 441d246de6
3 changed files with 147 additions and 128 deletions

View File

@ -127,7 +127,7 @@ func LuaJITDecodeBCIns(d *decode.D) {
}
func LuaJITDecodeNum(d *decode.D) {
d.FieldAnyFn("num", func(d *decode.D) any {
d.FieldAnyFn("value", func(d *decode.D) any {
lo := d.ULEB128()
hi := d.ULEB128()
return u64tof64((hi << 32) + lo)
@ -135,7 +135,7 @@ func LuaJITDecodeNum(d *decode.D) {
}
func LuaJITDecodeKTabK(d *decode.D) {
ktabtype := d.FieldULEB128("ktabtype", fallbackUintMapSymStr{
ktabtype := d.FieldULEB128("type", fallbackUintMapSymStr{
fallback: "str",
UintMapSymStr: scalar.UintMapSymStr{
0: "nil",
@ -146,17 +146,31 @@ func LuaJITDecodeKTabK(d *decode.D) {
},
})
if ktabtype >= 5 {
sz := ktabtype - 5
d.FieldUTF8("str", int(sz))
} else {
switch ktabtype {
case 3:
d.FieldULEB128("int")
switch ktabtype {
case 0:
// nil
d.FieldValueAny("value", nil)
case 4:
LuaJITDecodeNum(d)
}
case 1:
// false
d.FieldValueBool("value", false)
case 2:
// true
d.FieldValueBool("value", true)
case 3:
// int
d.FieldULEB128("value")
case 4:
LuaJITDecodeNum(d)
// ktabtype >= 5
default:
// str
size := ktabtype - 5
d.FieldUTF8("value", int(size))
}
}
@ -164,36 +178,32 @@ func LuaJITDecodeTab(d *decode.D) {
narray := d.FieldULEB128("narray")
nhash := d.FieldULEB128("nhash")
d.FieldArray("karray", func(d *decode.D) {
d.FieldArray("array", func(d *decode.D) {
for i := uint64(0); i < narray; i++ {
d.FieldStruct("ktab", LuaJITDecodeKTabK)
d.FieldStruct("element", LuaJITDecodeKTabK)
}
})
d.FieldArray("khash", func(d *decode.D) {
d.FieldArray("hash", func(d *decode.D) {
for i := uint64(0); i < nhash; i++ {
d.FieldStruct("khash", func(d *decode.D) {
d.FieldStruct("k", LuaJITDecodeKTabK)
d.FieldStruct("v", LuaJITDecodeKTabK)
d.FieldStruct("pair", func(d *decode.D) {
d.FieldStruct("key", LuaJITDecodeKTabK)
d.FieldStruct("value", LuaJITDecodeKTabK)
})
}
})
}
func LuaJITDecodeI64(d *decode.D) {
d.FieldAnyFn("i64", func(d *decode.D) any {
lo := d.ULEB128()
hi := d.ULEB128()
return int64((hi << 32) + lo)
})
func LuaJITDecodeI64(d *decode.D) int64 {
lo := d.ULEB128()
hi := d.ULEB128()
return int64((hi << 32) + lo)
}
func LuaJITDecodeU64(d *decode.D) {
d.FieldAnyFn("u64", func(d *decode.D) any {
lo := d.ULEB128()
hi := d.ULEB128()
return (hi << 32) + lo
})
func LuaJITDecodeU64(d *decode.D) uint64 {
lo := d.ULEB128()
hi := d.ULEB128()
return (hi << 32) + lo
}
func LuaJITDecodeComplex(d *decode.D) {
@ -224,26 +234,29 @@ func LuaJITDecodeKGC(d *decode.D) {
},
})
if kgctype >= 5 {
sz := kgctype - 5
d.FieldUTF8("str", int(sz))
} else {
switch kgctype {
case 0:
//child
switch kgctype {
case 0:
// child
case 1:
LuaJITDecodeTab(d)
case 1:
LuaJITDecodeTab(d)
case 2:
LuaJITDecodeI64(d)
case 2:
LuaJITDecodeI64(d)
case 3:
LuaJITDecodeU64(d)
case 3:
LuaJITDecodeI64(d)
case 4:
LuaJITDecodeComplex(d)
}
case 4:
// json does not support complex numbers,
// so we use a struct{real: float64, imag: float64}
d.FieldStruct("value", LuaJITDecodeComplex)
// kgctype >= 5
default:
// str
size := kgctype - 5
d.FieldUTF8("value", int(size))
}
}

View File

@ -170,66 +170,69 @@ $ fq dv simple.luac
| | | kgc[0:7]: 0xa9-0x125.7 (125)
| | | [0]{}: kgc 0xa9-0xb6.7 (14)
0x0a0| 12 | . | type: "str" (18) 0xa9-0xa9.7 (1)
0x0a0| 6d 79 66 75 6e 63| myfunc| str: "myfunc_result" 0xaa-0xb6.7 (13)
0x0a0| 6d 79 66 75 6e 63| myfunc| value: "myfunc_result" 0xaa-0xb6.7 (13)
0x0b0|5f 72 65 73 75 6c 74 |_result |
| | | [1]{}: kgc 0xb7-0xbd.7 (7)
0x0b0| 0b | . | type: "str" (11) 0xb7-0xb7.7 (1)
0x0b0| 6d 79 66 75 6e 63 | myfunc | str: "myfunc" 0xb8-0xbd.7 (6)
0x0b0| 6d 79 66 75 6e 63 | myfunc | value: "myfunc" 0xb8-0xbd.7 (6)
| | | [2]{}: kgc 0xbe-0xbe.7 (1)
0x0b0| 00 | . | type: "child" (0) 0xbe-0xbe.7 (1)
| | | [3]{}: kgc 0xbf-0xc4.7 (6)
0x0b0| 0a| .| type: "str" (10) 0xbf-0xbf.7 (1)
0x0c0|6d 79 74 62 6c |mytbl | str: "mytbl" 0xc0-0xc4.7 (5)
0x0c0|6d 79 74 62 6c |mytbl | value: "mytbl" 0xc0-0xc4.7 (5)
| | | [4]{}: kgc 0xc5-0xcb.7 (7)
0x0c0| 0b | . | type: "str" (11) 0xc5-0xc5.7 (1)
0x0c0| 6d 79 63 70 6c 78 | mycplx | str: "mycplx" 0xc6-0xcb.7 (6)
0x0c0| 6d 79 63 70 6c 78 | mycplx | value: "mycplx" 0xc6-0xcb.7 (6)
| | | [5]{}: kgc 0xcc-0xd8.7 (13)
0x0c0| 04 | . | type: "complex" (4) 0xcc-0xcc.7 (1)
0x0c0| 00 00 | .. | real: 0 0xcd-0xce.7 (2)
0x0c0| 9a| .| imag: 3.2 0xcf-0xd8.7 (10)
| | | value{}: 0xcd-0xd8.7 (12)
0x0c0| 00 00 | .. | real: 0 0xcd-0xce.7 (2)
0x0c0| 9a| .| imag: 3.2 0xcf-0xd8.7 (10)
0x0d0|b3 e6 cc 09 99 b3 a6 80 04 |......... |
| | | [6]{}: kgc 0xd9-0x125.7 (77)
0x0d0| 01 | . | type: "tab" (1) 0xd9-0xd9.7 (1)
0x0d0| 00 | . | narray: 0 0xda-0xda.7 (1)
0x0d0| 05 | . | nhash: 5 0xdb-0xdb.7 (1)
| | | karray[0:0]: 0xdc-NA (0)
| | | khash[0:5]: 0xdc-0x125.7 (74)
| | | [0]{}: khash 0xdc-0xe6.7 (11)
| | | k{}: 0xdc-0xe5.7 (10)
0x0d0| 0e | . | ktabtype: "str" (14) 0xdc-0xdc.7 (1)
0x0d0| 73 6f 6d| som| str: "somefalse" 0xdd-0xe5.7 (9)
| | | array[0:0]: 0xdc-NA (0)
| | | hash[0:5]: 0xdc-0x125.7 (74)
| | | [0]{}: pair 0xdc-0xe6.7 (11)
| | | key{}: 0xdc-0xe5.7 (10)
0x0d0| 0e | . | type: "str" (14) 0xdc-0xdc.7 (1)
0x0d0| 73 6f 6d| som| value: "somefalse" 0xdd-0xe5.7 (9)
0x0e0|65 66 61 6c 73 65 |efalse |
| | | v{}: 0xe6-0xe6.7 (1)
0x0e0| 01 | . | ktabtype: "false" (1) 0xe6-0xe6.7 (1)
| | | [1]{}: khash 0xe7-0xf0.7 (10)
| | | k{}: 0xe7-0xef.7 (9)
0x0e0| 0d | . | ktabtype: "str" (13) 0xe7-0xe7.7 (1)
0x0e0| 73 6f 6d 65 74 72 75 65| sometrue| str: "sometrue" 0xe8-0xef.7 (8)
| | | v{}: 0xf0-0xf0.7 (1)
0x0f0|02 |. | ktabtype: "true" (2) 0xf0-0xf0.7 (1)
| | | [2]{}: khash 0xf1-0x104.7 (20)
| | | k{}: 0xf1-0xf8.7 (8)
0x0f0| 0c | . | ktabtype: "str" (12) 0xf1-0xf1.7 (1)
0x0f0| 73 6f 6d 65 73 74 72 | somestr | str: "somestr" 0xf2-0xf8.7 (7)
| | | v{}: 0xf9-0x104.7 (12)
0x0f0| 10 | . | ktabtype: "str" (16) 0xf9-0xf9.7 (1)
0x0f0| 69 74 27 73 20 61| it's a| str: "it's a trap" 0xfa-0x104.7 (11)
| | | value{}: 0xe6-0xe6.7 (1)
0x0e0| 01 | . | type: "false" (1) 0xe6-0xe6.7 (1)
| | | value: false 0xe7-NA (0)
| | | [1]{}: pair 0xe7-0xf0.7 (10)
| | | key{}: 0xe7-0xef.7 (9)
0x0e0| 0d | . | type: "str" (13) 0xe7-0xe7.7 (1)
0x0e0| 73 6f 6d 65 74 72 75 65| sometrue| value: "sometrue" 0xe8-0xef.7 (8)
| | | value{}: 0xf0-0xf0.7 (1)
0x0f0|02 |. | type: "true" (2) 0xf0-0xf0.7 (1)
| | | value: true 0xf1-NA (0)
| | | [2]{}: pair 0xf1-0x104.7 (20)
| | | key{}: 0xf1-0xf8.7 (8)
0x0f0| 0c | . | type: "str" (12) 0xf1-0xf1.7 (1)
0x0f0| 73 6f 6d 65 73 74 72 | somestr | value: "somestr" 0xf2-0xf8.7 (7)
| | | value{}: 0xf9-0x104.7 (12)
0x0f0| 10 | . | type: "str" (16) 0xf9-0xf9.7 (1)
0x0f0| 69 74 27 73 20 61| it's a| value: "it's a trap" 0xfa-0x104.7 (11)
0x100|20 74 72 61 70 | trap |
| | | [3]{}: khash 0x105-0x117.7 (19)
| | | k{}: 0x105-0x10c.7 (8)
0x100| 0c | . | ktabtype: "str" (12) 0x105-0x105.7 (1)
0x100| 73 6f 6d 65 6e 75 6d | somenum | str: "somenum" 0x106-0x10c.7 (7)
| | | v{}: 0x10d-0x117.7 (11)
0x100| 04 | . | ktabtype: "num" (4) 0x10d-0x10d.7 (1)
0x100| 80 80| ..| num: 7.89437298e+11 0x10e-0x117.7 (10)
| | | [3]{}: pair 0x105-0x117.7 (19)
| | | key{}: 0x105-0x10c.7 (8)
0x100| 0c | . | type: "str" (12) 0x105-0x105.7 (1)
0x100| 73 6f 6d 65 6e 75 6d | somenum | value: "somenum" 0x106-0x10c.7 (7)
| | | value{}: 0x10d-0x117.7 (11)
0x100| 04 | . | type: "num" (4) 0x10d-0x10d.7 (1)
0x100| 80 80| ..| value: 7.89437298e+11 0x10e-0x117.7 (10)
0x110|a8 b5 02 c4 f3 9b 93 04 |........ |
| | | [4]{}: khash 0x118-0x125.7 (14)
| | | k{}: 0x118-0x11f.7 (8)
0x110| 0c | . | ktabtype: "str" (12) 0x118-0x118.7 (1)
0x110| 73 6f 6d 65 69 6e 74| someint| str: "someint" 0x119-0x11f.7 (7)
| | | v{}: 0x120-0x125.7 (6)
0x120|03 |. | ktabtype: "int" (3) 0x120-0x120.7 (1)
0x120| fd ff ff ff 0f | ..... | int: 4294967293 0x121-0x125.7 (5)
| | | [4]{}: pair 0x118-0x125.7 (14)
| | | key{}: 0x118-0x11f.7 (8)
0x110| 0c | . | type: "str" (12) 0x118-0x118.7 (1)
0x110| 73 6f 6d 65 69 6e 74| someint| value: "someint" 0x119-0x11f.7 (7)
| | | value{}: 0x120-0x125.7 (6)
0x120|03 |. | type: "int" (3) 0x120-0x120.7 (1)
0x120| fd ff ff ff 0f | ..... | value: 4294967293 0x121-0x125.7 (5)
| | | knum[0:0]: 0x126-NA (0)
| | | debug[0:40]: 0x126-0x14d.7 (40)
0x120| 01 | . | [0]: 1 db 0x126-0x126.7 (1)

View File

@ -137,65 +137,68 @@ $ fq dv simple_stripped.luac
| | | kgc[0:7]: 0x7c-0xf8.7 (125)
| | | [0]{}: kgc 0x7c-0x89.7 (14)
0x70| 12 | . | type: "str" (18) 0x7c-0x7c.7 (1)
0x70| 6d 79 66| myf| str: "myfunc_result" 0x7d-0x89.7 (13)
0x70| 6d 79 66| myf| value: "myfunc_result" 0x7d-0x89.7 (13)
0x80|75 6e 63 5f 72 65 73 75 6c 74 |unc_result |
| | | [1]{}: kgc 0x8a-0x90.7 (7)
0x80| 0b | . | type: "str" (11) 0x8a-0x8a.7 (1)
0x80| 6d 79 66 75 6e| myfun| str: "myfunc" 0x8b-0x90.7 (6)
0x80| 6d 79 66 75 6e| myfun| value: "myfunc" 0x8b-0x90.7 (6)
0x90|63 |c |
| | | [2]{}: kgc 0x91-0x91.7 (1)
0x90| 00 | . | type: "child" (0) 0x91-0x91.7 (1)
| | | [3]{}: kgc 0x92-0x97.7 (6)
0x90| 0a | . | type: "str" (10) 0x92-0x92.7 (1)
0x90| 6d 79 74 62 6c | mytbl | str: "mytbl" 0x93-0x97.7 (5)
0x90| 6d 79 74 62 6c | mytbl | value: "mytbl" 0x93-0x97.7 (5)
| | | [4]{}: kgc 0x98-0x9e.7 (7)
0x90| 0b | . | type: "str" (11) 0x98-0x98.7 (1)
0x90| 6d 79 63 70 6c 78 | mycplx | str: "mycplx" 0x99-0x9e.7 (6)
0x90| 6d 79 63 70 6c 78 | mycplx | value: "mycplx" 0x99-0x9e.7 (6)
| | | [5]{}: kgc 0x9f-0xab.7 (13)
0x90| 04| .| type: "complex" (4) 0x9f-0x9f.7 (1)
0xa0|00 00 |.. | real: 0 0xa0-0xa1.7 (2)
0xa0| 9a b3 e6 cc 09 99 b3 a6 80 04 | .......... | imag: 3.2 0xa2-0xab.7 (10)
| | | value{}: 0xa0-0xab.7 (12)
0xa0|00 00 |.. | real: 0 0xa0-0xa1.7 (2)
0xa0| 9a b3 e6 cc 09 99 b3 a6 80 04 | .......... | imag: 3.2 0xa2-0xab.7 (10)
| | | [6]{}: kgc 0xac-0xf8.7 (77)
0xa0| 01 | . | type: "tab" (1) 0xac-0xac.7 (1)
0xa0| 00 | . | narray: 0 0xad-0xad.7 (1)
0xa0| 05 | . | nhash: 5 0xae-0xae.7 (1)
| | | karray[0:0]: 0xaf-NA (0)
| | | khash[0:5]: 0xaf-0xf8.7 (74)
| | | [0]{}: khash 0xaf-0xc2.7 (20)
| | | k{}: 0xaf-0xb6.7 (8)
0xa0| 0c| .| ktabtype: "str" (12) 0xaf-0xaf.7 (1)
0xb0|73 6f 6d 65 73 74 72 |somestr | str: "somestr" 0xb0-0xb6.7 (7)
| | | v{}: 0xb7-0xc2.7 (12)
0xb0| 10 | . | ktabtype: "str" (16) 0xb7-0xb7.7 (1)
0xb0| 69 74 27 73 20 61 20 74| it's a t| str: "it's a trap" 0xb8-0xc2.7 (11)
| | | array[0:0]: 0xaf-NA (0)
| | | hash[0:5]: 0xaf-0xf8.7 (74)
| | | [0]{}: pair 0xaf-0xc2.7 (20)
| | | key{}: 0xaf-0xb6.7 (8)
0xa0| 0c| .| type: "str" (12) 0xaf-0xaf.7 (1)
0xb0|73 6f 6d 65 73 74 72 |somestr | value: "somestr" 0xb0-0xb6.7 (7)
| | | value{}: 0xb7-0xc2.7 (12)
0xb0| 10 | . | type: "str" (16) 0xb7-0xb7.7 (1)
0xb0| 69 74 27 73 20 61 20 74| it's a t| value: "it's a trap" 0xb8-0xc2.7 (11)
0xc0|72 61 70 |rap |
| | | [1]{}: khash 0xc3-0xd5.7 (19)
| | | k{}: 0xc3-0xca.7 (8)
0xc0| 0c | . | ktabtype: "str" (12) 0xc3-0xc3.7 (1)
0xc0| 73 6f 6d 65 6e 75 6d | somenum | str: "somenum" 0xc4-0xca.7 (7)
| | | v{}: 0xcb-0xd5.7 (11)
0xc0| 04 | . | ktabtype: "num" (4) 0xcb-0xcb.7 (1)
0xc0| 80 80 a8 b5| ....| num: 7.89437298e+11 0xcc-0xd5.7 (10)
| | | [1]{}: pair 0xc3-0xd5.7 (19)
| | | key{}: 0xc3-0xca.7 (8)
0xc0| 0c | . | type: "str" (12) 0xc3-0xc3.7 (1)
0xc0| 73 6f 6d 65 6e 75 6d | somenum | value: "somenum" 0xc4-0xca.7 (7)
| | | value{}: 0xcb-0xd5.7 (11)
0xc0| 04 | . | type: "num" (4) 0xcb-0xcb.7 (1)
0xc0| 80 80 a8 b5| ....| value: 7.89437298e+11 0xcc-0xd5.7 (10)
0xd0|02 c4 f3 9b 93 04 |...... |
| | | [2]{}: khash 0xd6-0xe3.7 (14)
| | | k{}: 0xd6-0xdd.7 (8)
0xd0| 0c | . | ktabtype: "str" (12) 0xd6-0xd6.7 (1)
0xd0| 73 6f 6d 65 69 6e 74 | someint | str: "someint" 0xd7-0xdd.7 (7)
| | | v{}: 0xde-0xe3.7 (6)
0xd0| 03 | . | ktabtype: "int" (3) 0xde-0xde.7 (1)
0xd0| fd| .| int: 4294967293 0xdf-0xe3.7 (5)
| | | [2]{}: pair 0xd6-0xe3.7 (14)
| | | key{}: 0xd6-0xdd.7 (8)
0xd0| 0c | . | type: "str" (12) 0xd6-0xd6.7 (1)
0xd0| 73 6f 6d 65 69 6e 74 | someint | value: "someint" 0xd7-0xdd.7 (7)
| | | value{}: 0xde-0xe3.7 (6)
0xd0| 03 | . | type: "int" (3) 0xde-0xde.7 (1)
0xd0| fd| .| value: 4294967293 0xdf-0xe3.7 (5)
0xe0|ff ff ff 0f |.... |
| | | [3]{}: khash 0xe4-0xee.7 (11)
| | | k{}: 0xe4-0xed.7 (10)
0xe0| 0e | . | ktabtype: "str" (14) 0xe4-0xe4.7 (1)
0xe0| 73 6f 6d 65 66 61 6c 73 65 | somefalse | str: "somefalse" 0xe5-0xed.7 (9)
| | | v{}: 0xee-0xee.7 (1)
0xe0| 01 | . | ktabtype: "false" (1) 0xee-0xee.7 (1)
| | | [4]{}: khash 0xef-0xf8.7 (10)
| | | k{}: 0xef-0xf7.7 (9)
0xe0| 0d| .| ktabtype: "str" (13) 0xef-0xef.7 (1)
0xf0|73 6f 6d 65 74 72 75 65 |sometrue | str: "sometrue" 0xf0-0xf7.7 (8)
| | | v{}: 0xf8-0xf8.7 (1)
0xf0| 02 | . | ktabtype: "true" (2) 0xf8-0xf8.7 (1)
| | | [3]{}: pair 0xe4-0xee.7 (11)
| | | key{}: 0xe4-0xed.7 (10)
0xe0| 0e | . | type: "str" (14) 0xe4-0xe4.7 (1)
0xe0| 73 6f 6d 65 66 61 6c 73 65 | somefalse | value: "somefalse" 0xe5-0xed.7 (9)
| | | value{}: 0xee-0xee.7 (1)
0xe0| 01 | . | type: "false" (1) 0xee-0xee.7 (1)
| | | value: false 0xef-NA (0)
| | | [4]{}: pair 0xef-0xf8.7 (10)
| | | key{}: 0xef-0xf7.7 (9)
0xe0| 0d| .| type: "str" (13) 0xef-0xef.7 (1)
0xf0|73 6f 6d 65 74 72 75 65 |sometrue | value: "sometrue" 0xf0-0xf7.7 (8)
| | | value{}: 0xf8-0xf8.7 (1)
0xf0| 02 | . | type: "true" (2) 0xf8-0xf8.7 (1)
| | | value: true 0xf9-NA (0)
| | | knum[0:0]: 0xf9-NA (0)
0xf0| 00| | .| | end: 0 0xf9-0xf9.7 (1)