mt-lang 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -214,548 +214,6 @@ module MilkTea
214
214
  ]
215
215
  end
216
216
 
217
- def emit_format_helpers
218
- helpers = used_format_helpers
219
- lines = []
220
-
221
- if helpers['mt_format_str_make']
222
- lines.concat([
223
- "static mt_str mt_format_str_make(uintptr_t len) {",
224
- "#{INDENT}char* data = (char*)malloc((size_t)(len + 1));",
225
- "#{INDENT}if (data == NULL) mt_fatal(\"format string allocation failed\");",
226
- "#{INDENT}data[len] = '\\0';",
227
- "#{INDENT}return (mt_str){ .data = data, .len = len };",
228
- "}",
229
- ])
230
- end
231
-
232
- if helpers['mt_format_str_release']
233
- lines << "" unless lines.empty?
234
- lines.concat([
235
- "static void mt_format_str_release(mt_str value) {",
236
- "#{INDENT}free(value.data);",
237
- "}",
238
- ])
239
- end
240
-
241
- if helpers['mt_format_check_capacity']
242
- lines << "" unless lines.empty?
243
- lines.concat([
244
- "static void mt_format_check_capacity(mt_str target, uintptr_t offset, uintptr_t len) {",
245
- "#{INDENT}if (offset > target.len || len > target.len - offset) mt_fatal(\"format string append exceeds capacity\");",
246
- "}",
247
- ])
248
- end
249
-
250
- if helpers['mt_format_append_bytes']
251
- lines << "" unless lines.empty?
252
- lines.concat([
253
- "static uintptr_t mt_format_append_bytes(mt_str target, uintptr_t offset, const char* data, uintptr_t len) {",
254
- "#{INDENT}mt_format_check_capacity(target, offset, len);",
255
- "#{INDENT}if (len > 0) memcpy(target.data + offset, data, (size_t)len);",
256
- "#{INDENT}offset += len;",
257
- "#{INDENT}target.data[offset] = '\\0';",
258
- "#{INDENT}return offset;",
259
- "}",
260
- ])
261
- end
262
-
263
- if helpers['mt_format_cstr_len']
264
- lines << "" unless lines.empty?
265
- lines.concat([
266
- "static uintptr_t mt_format_cstr_len(const char* value) {",
267
- "#{INDENT}return (uintptr_t)strlen(value);",
268
- "}",
269
- ])
270
- end
271
-
272
- if helpers['mt_format_bool_len']
273
- lines << "" unless lines.empty?
274
- lines.concat([
275
- "static uintptr_t mt_format_bool_len(bool value) {",
276
- "#{INDENT}return value ? 4 : 5;",
277
- "}",
278
- ])
279
- end
280
-
281
- if helpers['mt_format_ptr_uint_len']
282
- lines << "" unless lines.empty?
283
- lines.concat([
284
- "static uintptr_t mt_format_ptr_uint_len(uintptr_t value) {",
285
- "#{INDENT}uintptr_t len = 1;",
286
- "#{INDENT}while (value >= 10) {",
287
- "#{INDENT * 2}value /= 10;",
288
- "#{INDENT * 2}len += 1;",
289
- "#{INDENT}}",
290
- "#{INDENT}return len;",
291
- "}",
292
- ])
293
- end
294
-
295
- if helpers['mt_format_ulong_len']
296
- lines << "" unless lines.empty?
297
- lines.concat([
298
- "static uintptr_t mt_format_ulong_len(uint64_t value) {",
299
- "#{INDENT}uintptr_t len = 1;",
300
- "#{INDENT}while (value >= 10) {",
301
- "#{INDENT * 2}value /= 10;",
302
- "#{INDENT * 2}len += 1;",
303
- "#{INDENT}}",
304
- "#{INDENT}return len;",
305
- "}",
306
- ])
307
- end
308
-
309
- if helpers['mt_format_ulong_hex_len']
310
- lines << "" unless lines.empty?
311
- lines.concat([
312
- "static uintptr_t mt_format_ulong_hex_len(uint64_t value) {",
313
- "#{INDENT}int written = snprintf(NULL, 0, \"%llx\", (unsigned long long)value);",
314
- "#{INDENT}if (written < 0) mt_fatal(\"format string could not measure unsigned hex\");",
315
- "#{INDENT}return (uintptr_t)written;",
316
- "}",
317
- ])
318
- end
319
-
320
- if helpers['mt_format_uint_len']
321
- lines << "" unless lines.empty?
322
- lines.concat([
323
- "static uintptr_t mt_format_uint_len(uint32_t value) {",
324
- "#{INDENT}return mt_format_ptr_uint_len((uintptr_t)value);",
325
- "}",
326
- ])
327
- end
328
-
329
- if helpers['mt_format_long_len']
330
- lines << "" unless lines.empty?
331
- lines.concat([
332
- "static uintptr_t mt_format_long_len(int64_t value) {",
333
- "#{INDENT}if (value < 0) return 1 + mt_format_ulong_len(((uint64_t)(-(value + 1))) + 1);",
334
- "#{INDENT}return mt_format_ulong_len((uint64_t)value);",
335
- "}",
336
- ])
337
- end
338
-
339
- if helpers['mt_format_long_hex_len']
340
- lines << "" unless lines.empty?
341
- lines.concat([
342
- "static uintptr_t mt_format_long_hex_len(int64_t value) {",
343
- "#{INDENT}if (value < 0) return 1 + mt_format_ulong_hex_len(((uint64_t)(-(value + 1))) + 1);",
344
- "#{INDENT}return mt_format_ulong_hex_len((uint64_t)value);",
345
- "}",
346
- ])
347
- end
348
-
349
- if helpers['mt_format_ulong_oct_len']
350
- lines << "" unless lines.empty?
351
- lines.concat([
352
- "static uintptr_t mt_format_ulong_oct_len(uint64_t value) {",
353
- "#{INDENT}int written = snprintf(NULL, 0, \"%llo\", (unsigned long long)value);",
354
- "#{INDENT}if (written < 0) mt_fatal(\"format string could not measure unsigned octal\");",
355
- "#{INDENT}return (uintptr_t)written;",
356
- "}",
357
- ])
358
- end
359
-
360
- if helpers['mt_format_long_oct_len']
361
- lines << "" unless lines.empty?
362
- lines.concat([
363
- "static uintptr_t mt_format_long_oct_len(int64_t value) {",
364
- "#{INDENT}if (value < 0) return 1 + mt_format_ulong_oct_len(((uint64_t)(-(value + 1))) + 1);",
365
- "#{INDENT}return mt_format_ulong_oct_len((uint64_t)value);",
366
- "}",
367
- ])
368
- end
369
-
370
- if helpers['mt_format_ulong_bin_len']
371
- lines << "" unless lines.empty?
372
- lines.concat([
373
- "static uintptr_t mt_format_ulong_bin_len(uint64_t value) {",
374
- "#{INDENT}uintptr_t len = 1;",
375
- "#{INDENT}while (value >= 2) {",
376
- "#{INDENT * 2}value >>= 1;",
377
- "#{INDENT * 2}len += 1;",
378
- "#{INDENT}}",
379
- "#{INDENT}return len;",
380
- "}",
381
- ])
382
- end
383
-
384
- if helpers['mt_format_long_bin_len']
385
- lines << "" unless lines.empty?
386
- lines.concat([
387
- "static uintptr_t mt_format_long_bin_len(int64_t value) {",
388
- "#{INDENT}if (value < 0) return 1 + mt_format_ulong_bin_len(((uint64_t)(-(value + 1))) + 1);",
389
- "#{INDENT}return mt_format_ulong_bin_len((uint64_t)value);",
390
- "}",
391
- ])
392
- end
393
-
394
- if helpers['mt_format_int_len']
395
- lines << "" unless lines.empty?
396
- lines.concat([
397
- "static uintptr_t mt_format_int_len(int32_t value) {",
398
- "#{INDENT}if (value < 0) return 1 + mt_format_ptr_uint_len((uintptr_t)(-((int64_t)value)));",
399
- "#{INDENT}return mt_format_ptr_uint_len((uintptr_t)value);",
400
- "}",
401
- ])
402
- end
403
-
404
- if helpers['mt_format_float_len']
405
- lines << "" unless lines.empty?
406
- lines.concat([
407
- "static uintptr_t mt_format_float_len(float value) {",
408
- "#{INDENT}int written = snprintf(NULL, 0, \"%g\", (double)value);",
409
- "#{INDENT}if (written < 0) mt_fatal(\"format string could not measure float\");",
410
- "#{INDENT}return (uintptr_t)written;",
411
- "}",
412
- ])
413
- end
414
-
415
- if helpers['mt_format_double_len']
416
- lines << "" unless lines.empty?
417
- lines.concat([
418
- "static uintptr_t mt_format_double_len(double value) {",
419
- "#{INDENT}int written = snprintf(NULL, 0, \"%g\", value);",
420
- "#{INDENT}if (written < 0) mt_fatal(\"format string could not measure double\");",
421
- "#{INDENT}return (uintptr_t)written;",
422
- "}",
423
- ])
424
- end
425
-
426
- if helpers['mt_format_double_precision_len']
427
- lines << "" unless lines.empty?
428
- lines.concat([
429
- "static uintptr_t mt_format_double_precision_len(double value, int32_t precision) {",
430
- "#{INDENT}int written = snprintf(NULL, 0, \"%.*f\", precision, value);",
431
- "#{INDENT}if (written < 0) mt_fatal(\"format string could not measure double precision\");",
432
- "#{INDENT}return (uintptr_t)written;",
433
- "}",
434
- ])
435
- end
436
-
437
- if helpers['mt_format_append_str']
438
- lines << "" unless lines.empty?
439
- lines.concat([
440
- "static uintptr_t mt_format_append_str(mt_str target, uintptr_t offset, mt_str value) {",
441
- "#{INDENT}return mt_format_append_bytes(target, offset, value.data, value.len);",
442
- "}",
443
- ])
444
- end
445
-
446
- if helpers['mt_format_append_cstr']
447
- lines << "" unless lines.empty?
448
- lines.concat([
449
- "static uintptr_t mt_format_append_cstr(mt_str target, uintptr_t offset, const char* value) {",
450
- "#{INDENT}uintptr_t len = mt_format_cstr_len(value);",
451
- "#{INDENT}return mt_format_append_bytes(target, offset, value, len);",
452
- "}",
453
- ])
454
- end
455
-
456
- if helpers['mt_format_append_bool']
457
- lines << "" unless lines.empty?
458
- lines.concat([
459
- "static uintptr_t mt_format_append_bool(mt_str target, uintptr_t offset, bool value) {",
460
- "#{INDENT}return value ? mt_format_append_bytes(target, offset, \"true\", 4) : mt_format_append_bytes(target, offset, \"false\", 5);",
461
- "}",
462
- ])
463
- end
464
-
465
- if helpers['mt_format_append_ptr_uint']
466
- lines << "" unless lines.empty?
467
- lines.concat([
468
- "static uintptr_t mt_format_append_ptr_uint(mt_str target, uintptr_t offset, uintptr_t value) {",
469
- "#{INDENT}uintptr_t len = mt_format_ptr_uint_len(value);",
470
- "#{INDENT}uintptr_t index = offset + len;",
471
- "#{INDENT}mt_format_check_capacity(target, offset, len);",
472
- "#{INDENT}target.data[index] = '\\0';",
473
- "#{INDENT}do {",
474
- "#{INDENT * 2}index -= 1;",
475
- "#{INDENT * 2}target.data[index] = (char)('0' + (value % 10));",
476
- "#{INDENT * 2}value /= 10;",
477
- "#{INDENT}} while (index > offset);",
478
- "#{INDENT}return offset + len;",
479
- "}",
480
- ])
481
- end
482
-
483
- if helpers['mt_format_append_ulong']
484
- lines << "" unless lines.empty?
485
- lines.concat([
486
- "static uintptr_t mt_format_append_ulong(mt_str target, uintptr_t offset, uint64_t value) {",
487
- "#{INDENT}uintptr_t len = mt_format_ulong_len(value);",
488
- "#{INDENT}uintptr_t index = offset + len;",
489
- "#{INDENT}mt_format_check_capacity(target, offset, len);",
490
- "#{INDENT}target.data[index] = '\\0';",
491
- "#{INDENT}do {",
492
- "#{INDENT * 2}index -= 1;",
493
- "#{INDENT * 2}target.data[index] = (char)('0' + (value % 10));",
494
- "#{INDENT * 2}value /= 10;",
495
- "#{INDENT}} while (index > offset);",
496
- "#{INDENT}return offset + len;",
497
- "}",
498
- ])
499
- end
500
-
501
- if helpers['mt_format_append_uint']
502
- lines << "" unless lines.empty?
503
- lines.concat([
504
- "static uintptr_t mt_format_append_uint(mt_str target, uintptr_t offset, uint32_t value) {",
505
- "#{INDENT}return mt_format_append_ptr_uint(target, offset, (uintptr_t)value);",
506
- "}",
507
- ])
508
- end
509
-
510
- if helpers['mt_format_append_long']
511
- lines << "" unless lines.empty?
512
- lines.concat([
513
- "static uintptr_t mt_format_append_long(mt_str target, uintptr_t offset, int64_t value) {",
514
- "#{INDENT}if (value < 0) {",
515
- "#{INDENT * 2}offset = mt_format_append_bytes(target, offset, \"-\", 1);",
516
- "#{INDENT * 2}return mt_format_append_ulong(target, offset, ((uint64_t)(-(value + 1))) + 1);",
517
- "#{INDENT}}",
518
- "#{INDENT}return mt_format_append_ulong(target, offset, (uint64_t)value);",
519
- "}",
520
- ])
521
- end
522
-
523
- if helpers['mt_format_append_ulong_hex']
524
- lines << "" unless lines.empty?
525
- lines.concat([
526
- "static uintptr_t mt_format_append_ulong_hex(mt_str target, uintptr_t offset, uint64_t value) {",
527
- "#{INDENT}uintptr_t len = mt_format_ulong_hex_len(value);",
528
- "#{INDENT}mt_format_check_capacity(target, offset, len);",
529
- "#{INDENT}int written = snprintf(target.data + offset, (size_t)(target.len - offset + 1), \"%llx\", (unsigned long long)value);",
530
- "#{INDENT}if (written < 0 || (uintptr_t)written != len) mt_fatal(\"format string could not format unsigned hex\");",
531
- "#{INDENT}return offset + len;",
532
- "}",
533
- ])
534
- end
535
-
536
- if helpers['mt_format_append_ulong_hex_upper']
537
- lines << "" unless lines.empty?
538
- lines.concat([
539
- "static uintptr_t mt_format_append_ulong_hex_upper(mt_str target, uintptr_t offset, uint64_t value) {",
540
- "#{INDENT}uintptr_t len = mt_format_ulong_hex_len(value);",
541
- "#{INDENT}mt_format_check_capacity(target, offset, len);",
542
- "#{INDENT}int written = snprintf(target.data + offset, (size_t)(target.len - offset + 1), \"%llX\", (unsigned long long)value);",
543
- "#{INDENT}if (written < 0 || (uintptr_t)written != len) mt_fatal(\"format string could not format unsigned hex\");",
544
- "#{INDENT}return offset + len;",
545
- "}",
546
- ])
547
- end
548
-
549
- if helpers['mt_format_append_long_hex']
550
- lines << "" unless lines.empty?
551
- lines.concat([
552
- "static uintptr_t mt_format_append_long_hex(mt_str target, uintptr_t offset, int64_t value) {",
553
- "#{INDENT}if (value < 0) {",
554
- "#{INDENT * 2}offset = mt_format_append_bytes(target, offset, \"-\", 1);",
555
- "#{INDENT * 2}return mt_format_append_ulong_hex(target, offset, ((uint64_t)(-(value + 1))) + 1);",
556
- "#{INDENT}}",
557
- "#{INDENT}return mt_format_append_ulong_hex(target, offset, (uint64_t)value);",
558
- "}",
559
- ])
560
- end
561
-
562
- if helpers['mt_format_append_long_hex_upper']
563
- lines << "" unless lines.empty?
564
- lines.concat([
565
- "static uintptr_t mt_format_append_long_hex_upper(mt_str target, uintptr_t offset, int64_t value) {",
566
- "#{INDENT}if (value < 0) {",
567
- "#{INDENT * 2}offset = mt_format_append_bytes(target, offset, \"-\", 1);",
568
- "#{INDENT * 2}return mt_format_append_ulong_hex_upper(target, offset, ((uint64_t)(-(value + 1))) + 1);",
569
- "#{INDENT}}",
570
- "#{INDENT}return mt_format_append_ulong_hex_upper(target, offset, (uint64_t)value);",
571
- "}",
572
- ])
573
- end
574
-
575
- if helpers['mt_format_append_ulong_oct']
576
- lines << "" unless lines.empty?
577
- lines.concat([
578
- "static uintptr_t mt_format_append_ulong_oct(mt_str target, uintptr_t offset, uint64_t value) {",
579
- "#{INDENT}uintptr_t len = mt_format_ulong_oct_len(value);",
580
- "#{INDENT}mt_format_check_capacity(target, offset, len);",
581
- "#{INDENT}int written = snprintf(target.data + offset, (size_t)(target.len - offset + 1), \"%llo\", (unsigned long long)value);",
582
- "#{INDENT}if (written < 0 || (uintptr_t)written != len) mt_fatal(\"format string could not format unsigned octal\");",
583
- "#{INDENT}return offset + len;",
584
- "}",
585
- ])
586
- end
587
-
588
- if helpers['mt_format_append_long_oct']
589
- lines << "" unless lines.empty?
590
- lines.concat([
591
- "static uintptr_t mt_format_append_long_oct(mt_str target, uintptr_t offset, int64_t value) {",
592
- "#{INDENT}if (value < 0) {",
593
- "#{INDENT * 2}offset = mt_format_append_bytes(target, offset, \"-\", 1);",
594
- "#{INDENT * 2}return mt_format_append_ulong_oct(target, offset, ((uint64_t)(-(value + 1))) + 1);",
595
- "#{INDENT}}",
596
- "#{INDENT}return mt_format_append_ulong_oct(target, offset, (uint64_t)value);",
597
- "}",
598
- ])
599
- end
600
-
601
- if helpers['mt_format_append_ulong_bin']
602
- lines << "" unless lines.empty?
603
- lines.concat([
604
- "static uintptr_t mt_format_append_ulong_bin(mt_str target, uintptr_t offset, uint64_t value) {",
605
- "#{INDENT}uintptr_t len = mt_format_ulong_bin_len(value);",
606
- "#{INDENT}uintptr_t index = offset + len;",
607
- "#{INDENT}mt_format_check_capacity(target, offset, len);",
608
- "#{INDENT}target.data[index] = '\\0';",
609
- "#{INDENT}do {",
610
- "#{INDENT * 2}index -= 1;",
611
- "#{INDENT * 2}target.data[index] = (char)('0' + (value & 1));",
612
- "#{INDENT * 2}value >>= 1;",
613
- "#{INDENT}} while (index > offset);",
614
- "#{INDENT}return offset + len;",
615
- "}",
616
- ])
617
- end
618
-
619
- if helpers['mt_format_append_long_bin']
620
- lines << "" unless lines.empty?
621
- lines.concat([
622
- "static uintptr_t mt_format_append_long_bin(mt_str target, uintptr_t offset, int64_t value) {",
623
- "#{INDENT}if (value < 0) {",
624
- "#{INDENT * 2}offset = mt_format_append_bytes(target, offset, \"-\", 1);",
625
- "#{INDENT * 2}return mt_format_append_ulong_bin(target, offset, ((uint64_t)(-(value + 1))) + 1);",
626
- "#{INDENT}}",
627
- "#{INDENT}return mt_format_append_ulong_bin(target, offset, (uint64_t)value);",
628
- "}",
629
- ])
630
- end
631
-
632
- if helpers['mt_format_append_int']
633
- lines << "" unless lines.empty?
634
- lines.concat([
635
- "static uintptr_t mt_format_append_int(mt_str target, uintptr_t offset, int32_t value) {",
636
- "#{INDENT}if (value < 0) {",
637
- "#{INDENT * 2}offset = mt_format_append_bytes(target, offset, \"-\", 1);",
638
- "#{INDENT * 2}return mt_format_append_ptr_uint(target, offset, (uintptr_t)(-((int64_t)value)));",
639
- "#{INDENT}}",
640
- "#{INDENT}return mt_format_append_ptr_uint(target, offset, (uintptr_t)value);",
641
- "}",
642
- ])
643
- end
644
-
645
- if helpers['mt_format_append_float']
646
- lines << "" unless lines.empty?
647
- lines.concat([
648
- "static uintptr_t mt_format_append_float(mt_str target, uintptr_t offset, float value) {",
649
- "#{INDENT}uintptr_t len = mt_format_float_len(value);",
650
- "#{INDENT}mt_format_check_capacity(target, offset, len);",
651
- "#{INDENT}int written = snprintf(target.data + offset, (size_t)(target.len - offset + 1), \"%g\", (double)value);",
652
- "#{INDENT}if (written < 0 || (uintptr_t)written != len) mt_fatal(\"format string could not format float\");",
653
- "#{INDENT}return offset + len;",
654
- "}",
655
- ])
656
- end
657
-
658
- if helpers['mt_format_append_double']
659
- lines << "" unless lines.empty?
660
- lines.concat([
661
- "static uintptr_t mt_format_append_double(mt_str target, uintptr_t offset, double value) {",
662
- "#{INDENT}uintptr_t len = mt_format_double_len(value);",
663
- "#{INDENT}mt_format_check_capacity(target, offset, len);",
664
- "#{INDENT}int written = snprintf(target.data + offset, (size_t)(target.len - offset + 1), \"%g\", value);",
665
- "#{INDENT}if (written < 0 || (uintptr_t)written != len) mt_fatal(\"format string could not format double\");",
666
- "#{INDENT}return offset + len;",
667
- "}",
668
- ])
669
- end
670
-
671
- if helpers['mt_format_append_double_precision']
672
- lines << "" unless lines.empty?
673
- lines.concat([
674
- "static uintptr_t mt_format_append_double_precision(mt_str target, uintptr_t offset, double value, int32_t precision) {",
675
- "#{INDENT}uintptr_t len = mt_format_double_precision_len(value, precision);",
676
- "#{INDENT}mt_format_check_capacity(target, offset, len);",
677
- "#{INDENT}int written = snprintf(target.data + offset, (size_t)(target.len - offset + 1), \"%.*f\", precision, value);",
678
- "#{INDENT}if (written < 0 || (uintptr_t)written != len) mt_fatal(\"format string could not format double precision\");",
679
- "#{INDENT}return offset + len;",
680
- "}",
681
- ])
682
- end
683
-
684
- lines
685
- end
686
-
687
- def emit_fmt_builder_helpers
688
- return [] unless uses_fmt_builder?
689
-
690
- [
691
- "typedef struct {",
692
- "#{INDENT}char* data;",
693
- "#{INDENT}uintptr_t capacity;",
694
- "#{INDENT}uintptr_t offset;",
695
- "} mt_fmt_builder;",
696
- "",
697
- "static inline mt_fmt_builder mt_fmt_begin(uintptr_t capacity) {",
698
- "#{INDENT}mt_fmt_builder b;",
699
- "#{INDENT}b.data = (char*)malloc((size_t)capacity);",
700
- "#{INDENT}b.capacity = capacity;",
701
- "#{INDENT}b.offset = 0;",
702
- "#{INDENT}return b;",
703
- "}",
704
- "",
705
- "static inline void mt_fmt_cleanup(mt_fmt_builder b) {",
706
- "#{INDENT}free(b.data);",
707
- "}",
708
- "",
709
- "static inline mt_str mt_fmt_finish(mt_fmt_builder* b) {",
710
- "#{INDENT}return (mt_str){ .data = b->data, .len = b->offset };",
711
- "}",
712
- "",
713
- "static inline void mt_fmt_write_bytes(mt_fmt_builder* b, const char* data, uintptr_t len) {",
714
- "#{INDENT}mt_fmt_builder buf = *b;",
715
- "#{INDENT}b->offset = mt_format_append_bytes((mt_str){ .data = buf.data, .len = buf.capacity }, buf.offset, data, len);",
716
- "}",
717
- "",
718
- "static inline void mt_fmt_write_str(mt_fmt_builder* b, mt_str value) {",
719
- "#{INDENT}mt_fmt_write_bytes(b, value.data, value.len);",
720
- "}",
721
- "",
722
- "static inline void mt_fmt_write_int(mt_fmt_builder* b, int32_t value) {",
723
- "#{INDENT}mt_fmt_builder buf = *b;",
724
- "#{INDENT}b->offset = mt_format_append_int((mt_str){ .data = buf.data, .len = buf.capacity }, buf.offset, value);",
725
- "}",
726
- "",
727
- "static inline void mt_fmt_write_ptr_uint(mt_fmt_builder* b, uintptr_t value) {",
728
- "#{INDENT}mt_fmt_builder buf = *b;",
729
- "#{INDENT}b->offset = mt_format_append_ptr_uint((mt_str){ .data = buf.data, .len = buf.capacity }, buf.offset, value);",
730
- "}",
731
- "",
732
- "static inline void mt_fmt_write_long_hex(mt_fmt_builder* b, int64_t value) {",
733
- "#{INDENT}mt_fmt_builder buf = *b;",
734
- "#{INDENT}b->offset = mt_format_append_long_hex((mt_str){ .data = buf.data, .len = buf.capacity }, buf.offset, value);",
735
- "}",
736
- "",
737
- "static inline void mt_fmt_write_long_hex_upper(mt_fmt_builder* b, int64_t value) {",
738
- "#{INDENT}mt_fmt_builder buf = *b;",
739
- "#{INDENT}b->offset = mt_format_append_long_hex_upper((mt_str){ .data = buf.data, .len = buf.capacity }, buf.offset, value);",
740
- "}",
741
- "",
742
- "static inline void mt_fmt_write_long_oct(mt_fmt_builder* b, int64_t value) {",
743
- "#{INDENT}mt_fmt_builder buf = *b;",
744
- "#{INDENT}b->offset = mt_format_append_long_oct((mt_str){ .data = buf.data, .len = buf.capacity }, buf.offset, value);",
745
- "}",
746
- "",
747
- "static inline void mt_fmt_write_long_bin(mt_fmt_builder* b, int64_t value) {",
748
- "#{INDENT}mt_fmt_builder buf = *b;",
749
- "#{INDENT}b->offset = mt_format_append_long_bin((mt_str){ .data = buf.data, .len = buf.capacity }, buf.offset, value);",
750
- "}",
751
- "",
752
- "static inline void mt_fmt_write_double_precision(mt_fmt_builder* b, double value, int32_t precision) {",
753
- "#{INDENT}mt_fmt_builder buf = *b;",
754
- "#{INDENT}b->offset = mt_format_append_double_precision((mt_str){ .data = buf.data, .len = buf.capacity }, buf.offset, value, precision);",
755
- "}",
756
- ]
757
- end
758
-
759
217
  def emit_foreign_temp_cstr_helpers
760
218
  lines = []
761
219