@@ -22,6 +22,9 @@ pub mut:
22
22
is_fmt bool
23
23
used_fns map [string ]bool // filled in by the checker, when pref.skip_unused = true;
24
24
used_consts map [string ]bool // filled in by the checker, when pref.skip_unused = true;
25
+ panic_handler FnPanicHandler = default_table_panic_handler
26
+ panic_userdata voidptr = voidptr (0 ) // can be used to pass arbitrary data to panic_handler;
27
+ panic_npanics int
25
28
}
26
29
27
30
[unsafe ]
@@ -42,6 +45,18 @@ pub fn (t &Table) free() {
42
45
}
43
46
}
44
47
48
+ pub type FnPanicHandler = fn (& Table, string )
49
+
50
+ fn default_table_panic_handler (t & Table, message string ) {
51
+ panic (message)
52
+ }
53
+
54
+ pub fn (t &Table) panic (message string ) {
55
+ mut mt := unsafe { & Table (t) }
56
+ mt.panic_npanics++
57
+ t.panic_handler (t, message)
58
+ }
59
+
45
60
pub struct Fn {
46
61
pub :
47
62
params []Param
@@ -209,7 +224,7 @@ pub fn (mut t TypeSymbol) register_method(new_fn Fn) int {
209
224
210
225
pub fn (t &Table) register_aggregate_method (mut sym TypeSymbol, name string ) ? Fn {
211
226
if sym.kind != .aggregate {
212
- panic ('Unexpected type symbol: $sym.kind ' )
227
+ t. panic ('Unexpected type symbol: $sym.kind ' )
213
228
}
214
229
agg_info := sym.info as Aggregate
215
230
// an aggregate always has at least 2 types
@@ -263,7 +278,7 @@ pub fn (t &Table) type_find_method(s &TypeSymbol, name string) ?Fn {
263
278
264
279
fn (t &Table) register_aggregate_field (mut sym TypeSymbol, name string ) ? StructField {
265
280
if sym.kind != .aggregate {
266
- panic ('Unexpected type symbol: $sym.kind ' )
281
+ t. panic ('Unexpected type symbol: $sym.kind ' )
267
282
}
268
283
mut agg_info := sym.info as Aggregate
269
284
// an aggregate always has at least 2 types
@@ -424,7 +439,7 @@ pub fn (t &Table) get_type_symbol(typ Type) &TypeSymbol {
424
439
return unsafe { & t.type_symbols[idx] }
425
440
}
426
441
// this should never happen
427
- panic ('get_type_symbol: invalid type (typ=$typ idx=$idx ). Compiler bug. This should never happen. Please create a GitHub issue.
442
+ t. panic ('get_type_symbol: invalid type (typ=$typ idx=$idx ). Compiler bug. This should never happen. Please create a GitHub issue.
428
443
' )
429
444
}
430
445
@@ -441,7 +456,7 @@ pub fn (t &Table) get_final_type_symbol(typ Type) &TypeSymbol {
441
456
return unsafe { & t.type_symbols[idx] }
442
457
}
443
458
// this should never happen
444
- panic ('get_final_type_symbol: invalid type (typ=$typ idx=$idx ). Compiler bug. This should never happen. Please create a GitHub issue.' )
459
+ t. panic ('get_final_type_symbol: invalid type (typ=$typ idx=$idx ). Compiler bug. This should never happen. Please create a GitHub issue.' )
445
460
}
446
461
447
462
[inline ]
@@ -956,7 +971,7 @@ pub fn (mut t Table) bitsize_to_type(bit_size int) Type {
956
971
}
957
972
else {
958
973
if bit_size % 8 != 0 { // there is no way to do `i2131(32)` so this should never be reached
959
- panic ('compiler bug: bitsizes must be multiples of 8' )
974
+ t. panic ('compiler bug: bitsizes must be multiples of 8' )
960
975
}
961
976
return new_type (t.find_or_register_array_fixed (byte_type, bit_size / 8 ))
962
977
}
0 commit comments