Skip to content

Commit c7598db

Browse files
committed
feat: add description for layout arguments with derialization and deserialization logic
1 parent 3cee21a commit c7598db

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

gen/schema.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@
462462
},
463463
"UintArg": {
464464
"type": "object",
465+
"description": "Represents an unsigned integer argument with a specified length and a range of valid values.",
465466
"properties": {
466467
"$": {
467468
"type": "string",
@@ -485,6 +486,7 @@
485486
},
486487
"IntArg": {
487488
"type": "object",
489+
"description": "Represents a signed integer argument with a specified length and a range of valid values.",
488490
"properties": {
489491
"$": {
490492
"type": "string",
@@ -508,6 +510,7 @@
508510
},
509511
"DeltaArg": {
510512
"type": "object",
513+
"description": "Represents argument with specified inner type and delta for it.",
511514
"properties": {
512515
"$": {
513516
"type": "string",
@@ -531,6 +534,7 @@
531534
},
532535
"StackArg": {
533536
"type": "object",
537+
"description": "Represents a stack argument with a constant bit length equal to 4 and a range of valid values. This argument can be serialized and deserialized as a plain integer with `slice.load_uint(4)` and `builder.store_uint(t, 4)`.",
534538
"properties": {
535539
"$": {
536540
"type": "string",
@@ -554,6 +558,7 @@
554558
},
555559
"ControlArg": {
556560
"type": "object",
561+
"description": "Represents a control register argument with a constant bit length equal to 4 and a range of valid values. This argument can be serialized and deserialized as a plain integer with `slice.load_uint(4)` and `builder.store_uint(t, 4)`.",
557562
"properties": {
558563
"$": {
559564
"type": "string",
@@ -573,6 +578,7 @@
573578
},
574579
"PlduzArg": {
575580
"type": "object",
581+
"description": "Represents a special `PLDUZ` argument with a constant bit length equal to 3 and a range of valid values. This argument can be deserialized as follows: `((slice.load_uint(3) & 7) + 1) << 5` and serialized as `builder.store_uint(((value >> 5) - 1) & 7, 3)`.",
576582
"properties": {
577583
"$": {
578584
"type": "string",
@@ -592,6 +598,7 @@
592598
},
593599
"TinyIntArg": {
594600
"type": "object",
601+
"description": "Represents a special `PUSHINT_4` argument with a constant bit length equal to 4 and a range of valid values. This argument can be deserialized as follows: `((int64(slice.load_uint(4)) + 5) & 15) - 5` and serialized as `builder.store_uint((value + 16) & 15, 4)`.",
595602
"properties": {
596603
"$": {
597604
"type": "string",
@@ -611,6 +618,7 @@
611618
},
612619
"LargeIntArg": {
613620
"type": "object",
621+
"description": "Represents a special `PUSHINT_LONG` argument with a range of valid values. This argument can be deserialized as follows: `len = slice.load_uint(5); value = slice.load_uint(3 + ((len & 31) + 2) * 8) )` and serialized as\n\nlen = t === 0n ? 1 : t.toString(2).length + (t < 0n ? 0 : 1);\nlen2 = trunc((len + 7) / 8) - 2;\nif (len2 <= 0 || len2 >= 32) \n b.store_uint(t, 24);\n return;\n\ncount_bits = ceil((len - 19) / 8);\nb.store_uint(count_bits, 5);\ndata_bits = 8 * count_bits + 19;\nb.store_int(t, data_bits);\n.",
614622
"properties": {
615623
"$": {
616624
"type": "string",
@@ -679,6 +687,7 @@
679687
},
680688
"SliceArg": {
681689
"type": "object",
690+
"description": "Represents data slice argument.",
682691
"properties": {
683692
"$": {
684693
"type": "string",
@@ -706,6 +715,7 @@
706715
},
707716
"CodeSliceArg": {
708717
"type": "object",
718+
"description": "Represents code slice argument. This slice is always padded to 8 bytes.",
709719
"properties": {
710720
"$": {
711721
"type": "string",
@@ -729,6 +739,7 @@
729739
},
730740
"RefCodeSliceArg": {
731741
"type": "object",
742+
"description": "Represents code cell argument stored in a ref. This argument can be deserialized as follows: `slice.load_ref()` and serialized as `builder.store_ref(cell)`.",
732743
"properties": {
733744
"$": {
734745
"type": "string",
@@ -744,6 +755,7 @@
744755
},
745756
"InlineCodeSliceArg": {
746757
"type": "object",
758+
"description": "Represents code slice argument that embedded in current slice bytes. This slice is always padded to 8 bytes. This argument can be deserialized as follows: `y = slice.load_uint(bits); data = slice.load_slice(y * 8)` and serialized as `builder.store_uint(ceil(data.len / 8), bits); builder.store_slice(data)`.",
747759
"properties": {
748760
"$": {
749761
"type": "string",
@@ -763,6 +775,7 @@
763775
},
764776
"InlineDictArg": {
765777
"type": "object",
778+
"description": "Represents dictionary argument. This argument can only be paired with a dictionary length represented as `uint(10)`, and they are `DICTPUSHCONSTS` type instructions and must be processed separately.",
766779
"properties": {
767780
"$": {
768781
"type": "string",
@@ -793,6 +806,7 @@
793806
},
794807
"DebugstrArg": {
795808
"type": "object",
809+
"description": "Represents `DEBUGSTR` argument. This slice is always padded to 8 bytes. This argument can be deserialized as follows: `y = slice.load_uint(4); bits = slice.load_slice((y + 1) * 8)` and serialized as `y = ceil((data.length - 8) / 8); builder.store_uint(y, 4); builder.store_slice(data, bits)`.",
796810
"properties": {
797811
"$": {
798812
"type": "string",

src/types/specification-schema.ts

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,9 @@ export interface ArgRange {
413413
max: string
414414
}
415415

416+
/**
417+
* Represents an unsigned integer argument with a specified length and a range of valid values.
418+
*/
416419
export interface UintArg {
417420
$: "uint"
418421
/**
@@ -426,6 +429,9 @@ export interface UintArg {
426429
range: ArgRange
427430
}
428431

432+
/**
433+
* Represents a signed integer argument with a specified length and a range of valid values.
434+
*/
429435
export interface IntArg {
430436
$: "int"
431437
/**
@@ -439,6 +445,9 @@ export interface IntArg {
439445
range: ArgRange
440446
}
441447

448+
/**
449+
* Represents argument with specified inner type and delta for it.
450+
*/
442451
export interface DeltaArg {
443452
$: "delta"
444453
/**
@@ -455,6 +464,11 @@ export interface DeltaArg {
455464
arg: Arg
456465
}
457466

467+
/**
468+
* Represents a stack argument with a constant bit length equal to 4 and a range of valid values.
469+
* This argument can be serialized and deserialized as a plain integer with `slice.load_uint(4)`
470+
* and `builder.store_uint(t, 4)`.
471+
*/
458472
export interface StackArg {
459473
$: "stack"
460474
/**
@@ -468,6 +482,11 @@ export interface StackArg {
468482
range: ArgRange
469483
}
470484

485+
/**
486+
* Represents a control register argument with a constant bit length equal to 4 and a range of
487+
* valid values. This argument can be serialized and deserialized as a plain integer
488+
* with `slice.load_uint(4)` and `builder.store_uint(t, 4)`.
489+
*/
471490
export interface ControlArg {
472491
$: "control"
473492
/**
@@ -477,6 +496,26 @@ export interface ControlArg {
477496
range: ArgRange
478497
}
479498

499+
/**
500+
* Value range for the control argument
501+
*/
502+
export interface ArgRange {
503+
/**
504+
* Minimum value for the argument range
505+
*/
506+
min: string
507+
/**
508+
* Maximum value for the argument range
509+
*/
510+
max: string
511+
}
512+
513+
/**
514+
* Represents a special `PLDUZ` argument with a constant bit length equal to 3 and a range of valid values.
515+
*
516+
* This argument can be deserialized as follows:`((slice.load_uint(3) & 7) + 1) << 5`
517+
* and serialized as `builder.store_uint(((value >> 5) - 1) & 7, 3)`.
518+
*/
480519
export interface PlduzArg {
481520
$: "plduzArg"
482521
/**
@@ -486,6 +525,12 @@ export interface PlduzArg {
486525
range: ArgRange
487526
}
488527

528+
/**
529+
* Represents a special `PUSHINT_4` argument with a constant bit length equal to 4 and a range of valid values.
530+
*
531+
* This argument can be deserialized as follows: `((int64(slice.load_uint(4)) + 5) & 15) - 5`
532+
* and serialized as `builder.store_uint((value + 16) & 15, 4)`.
533+
*/
489534
export interface TinyIntArg {
490535
$: "tinyInt"
491536
/**
@@ -495,6 +540,31 @@ export interface TinyIntArg {
495540
range: ArgRange
496541
}
497542

543+
/**
544+
* Represents a special `PUSHINT_LONG` argument with a range of valid values.
545+
*
546+
* This argument can be deserialized as follows:
547+
*
548+
* ```
549+
* len = slice.load_uint(5);
550+
* value = slice.load_uint(3 + ((len & 31) + 2) * 8) );
551+
* ```
552+
*
553+
* and serialized as
554+
*
555+
* ```
556+
* len = t === 0n ? 1 : t.toString(2).length + (t < 0n ? 0 : 1);
557+
* len2 = trunc((len + 7) / 8) - 2;
558+
* if (len2 <= 0 || len2 >= 32) {
559+
* b.store_uint(t, 24);
560+
* return;
561+
* }
562+
* count_bits = ceil((len - 19) / 8);
563+
* b.store_uint(count_bits, 5);
564+
* data_bits = 8 * count_bits + 19;
565+
* b.store_int(t, data_bits);
566+
* ```
567+
*/
498568
export interface LargeIntArg {
499569
$: "largeInt"
500570
/**
@@ -529,6 +599,9 @@ export interface SetcpArg {
529599
range: ArgRange
530600
}
531601

602+
/**
603+
* Represents data slice argument.
604+
*/
532605
export interface SliceArg {
533606
$: "slice"
534607
/**
@@ -549,6 +622,9 @@ export interface SliceArg {
549622
pad: number
550623
}
551624

625+
/**
626+
* Represents code slice argument. This slice is always padded to 8 bytes.
627+
*/
552628
export interface CodeSliceArg {
553629
$: "codeSlice"
554630
/**
@@ -565,6 +641,12 @@ export interface CodeSliceArg {
565641
bits: Arg
566642
}
567643

644+
/**
645+
* Represents dictionary argument.
646+
*
647+
* This argument can only be paired with a dictionary length represented as `uint(10)`,
648+
* and they are `DICTPUSHCONST` type instructions and must be processed separately.
649+
*/
568650
export interface Dict {
569651
$: "dict"
570652
/**
@@ -573,6 +655,12 @@ export interface Dict {
573655
name?: string
574656
}
575657

658+
/**
659+
* Represents code cell argument stored in a ref.
660+
*
661+
* This argument can be deserialized as follows: `slice.load_ref()`
662+
* and serialized as `builder.store_ref(cell)`.
663+
*/
576664
export interface RefCodeSliceArg {
577665
$: "refCodeSlice"
578666
/**
@@ -581,6 +669,20 @@ export interface RefCodeSliceArg {
581669
name?: string
582670
}
583671

672+
/**
673+
* Represents code slice argument that embedded in current slice bytes. This slice is always padded to 8 bytes.
674+
*
675+
* This argument can be deserialized as follows:
676+
* ```
677+
* y = slice.load_uint(bits);
678+
* data = slice.load_slice(y * 8);
679+
* ```
680+
* and serialized as
681+
* ```
682+
* builder.store_uint(ceil(data.len / 8), bits);
683+
* builder.store_slice(data);
684+
* ```
685+
*/
584686
export interface InlineCodeSliceArg {
585687
$: "inlineCodeSlice"
586688
/**
@@ -601,6 +703,21 @@ export interface ExoticCellArg {
601703
name?: string
602704
}
603705

706+
/**
707+
* Represents `DEBUGSTR` argument. This slice is always padded to 8 bytes.
708+
*
709+
* This argument can be deserialized as follows:
710+
* ```
711+
* y = slice.load_uint(4);
712+
* bits = slice.load_slice((y + 1) * 8)
713+
* ```
714+
* and serialized as
715+
* ```
716+
* y = ceil((data.length - 8) / 8);
717+
* builder.store_uint(y, 4);
718+
* builder.store_slice(data, bits)
719+
* ```
720+
*/
604721
export interface DebugstrArg {
605722
$: "debugstr"
606723
/**

0 commit comments

Comments
 (0)