Skip to content

Commit 4b79f52

Browse files
authored
feat: use latest TVM specification (#193)
1 parent 39519d5 commit 4b79f52

File tree

11 files changed

+72741
-33820
lines changed

11 files changed

+72741
-33820
lines changed

server/src/languages/fift/asm/asm.json

Lines changed: 0 additions & 33114 deletions
This file was deleted.
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
// SPDX-License-Identifier: MIT
22
// Copyright © 2025 TON Studio
3-
import {getStackPresentation} from "./types"
43

54
export function instructionPresentation(
65
gas: string | undefined,
7-
stack: string | undefined,
6+
stack: string,
87
format: string,
98
): string {
109
if (!gas || gas === "") {
1110
return ": no data"
1211
}
13-
return format.replace("{gas}", gas).replace("{stack}", getStackPresentation(stack))
12+
return format.replace("{gas}", gas).replace("{stack}", stack)
1413
}

server/src/languages/fift/asm/schema.json

Lines changed: 793 additions & 596 deletions
Large diffs are not rendered by default.
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
import type {InstructionSignature, Continuation} from "./stack-signatures-schema"
2+
3+
export interface Specification {
4+
readonly $schema: string
5+
readonly version: string
6+
readonly instructions: readonly Instruction[]
7+
readonly fift_instructions: readonly FiftInstruction[]
8+
}
9+
10+
export type FiftArgument = number | string
11+
12+
export interface FiftInstruction {
13+
readonly name: string
14+
readonly actual_name: string
15+
readonly arguments: readonly FiftArgument[]
16+
readonly description?: string
17+
}
18+
19+
export interface ImplementationInfo {
20+
readonly commit_hash: string
21+
readonly file_path: string
22+
readonly line_number: number
23+
readonly function_name: string
24+
}
25+
26+
export interface Instruction {
27+
readonly name: string
28+
readonly category: string
29+
readonly sub_category: string
30+
readonly description: Description
31+
readonly layout: Layout
32+
readonly effects?: readonly string[]
33+
readonly signature?: InstructionSignature
34+
readonly control_flow?: ControlFlowOfInstruction
35+
readonly implementation?: ImplementationInfo
36+
}
37+
38+
export interface ExitCode {
39+
readonly errno: string
40+
readonly condition: string
41+
}
42+
43+
export interface OtherImplementation {
44+
readonly exact: boolean
45+
readonly instructions: readonly string[]
46+
}
47+
48+
export interface ExampleInstruction {
49+
readonly instruction: string
50+
readonly comment?: string
51+
readonly is_main?: boolean
52+
}
53+
54+
export interface ExampleStack {
55+
readonly input: readonly string[]
56+
readonly output: readonly string[]
57+
}
58+
59+
export interface Example {
60+
readonly instructions: readonly ExampleInstruction[]
61+
readonly stack: ExampleStack
62+
readonly exit_code?: number
63+
}
64+
65+
export interface GasConsumptionEntry {
66+
readonly value: number
67+
readonly description: string
68+
readonly formula?: string
69+
}
70+
71+
export interface DocsLink {
72+
readonly name: string
73+
readonly url: string
74+
}
75+
76+
export interface Description {
77+
readonly short: string
78+
readonly long: string
79+
readonly tags: readonly string[]
80+
readonly operands: readonly string[]
81+
readonly exit_codes?: readonly ExitCode[]
82+
readonly other_implementations?: readonly OtherImplementation[]
83+
readonly related_instructions?: readonly string[]
84+
readonly examples?: readonly Example[]
85+
readonly gas?: readonly GasConsumptionEntry[]
86+
readonly docs_links?: readonly DocsLink[]
87+
}
88+
89+
export interface Layout {
90+
readonly min: number
91+
readonly max: number
92+
readonly checkLen: number
93+
readonly skipLen: number
94+
readonly args: Args
95+
readonly exec: string
96+
readonly kind: "ext" | "ext-range" | "fixed" | "fixed-range" | "simple"
97+
readonly prefix: number
98+
readonly prefix_str: string
99+
readonly tlb: string
100+
readonly version?: number
101+
}
102+
103+
export interface Args {
104+
readonly $: "dictpush" | "simpleArgs" | "xchgArgs"
105+
readonly children?: readonly Child[]
106+
readonly range?: ArgRange
107+
}
108+
109+
export interface Child {
110+
readonly $: string
111+
readonly len?: number
112+
readonly range?: ArgRange
113+
readonly delta?: number
114+
readonly arg?: Arg
115+
readonly refs?: Refs
116+
readonly bits?: Arg
117+
readonly pad?: number
118+
}
119+
120+
export interface Arg {
121+
readonly $: "stack" | "uint"
122+
readonly len: number
123+
readonly range: ArgRange
124+
}
125+
126+
export interface ArgRange {
127+
readonly min: string
128+
readonly max: string
129+
}
130+
131+
export interface Refs {
132+
readonly $: string
133+
readonly count?: number
134+
readonly delta?: number
135+
readonly arg?: Arg
136+
readonly len?: number
137+
readonly range?: ArgRange
138+
}
139+
140+
export interface ControlFlowOfInstruction {
141+
readonly branches: Continuation[]
142+
}
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
/**
2+
* Allowed chars are `a-zA-Z0-9_`, must not begin with digit or underscore and must not end with underscore.
3+
*/
4+
export type VariableName = string
5+
6+
export interface PossibleValueRange {
7+
readonly min: number
8+
readonly max: number
9+
}
10+
/**
11+
* Representation of stack entry or group of stack entries
12+
*/
13+
export type StackEntry =
14+
| {
15+
readonly type: "simple"
16+
readonly name: VariableName
17+
readonly range?: PossibleValueRange
18+
readonly presentation: string
19+
readonly value_types?: PossibleValueTypes
20+
readonly mutations?: Mutation[]
21+
}
22+
| {
23+
readonly type: "const"
24+
readonly value_type: ConstantType
25+
readonly value: ConstantValue
26+
}
27+
| {
28+
readonly type: "conditional"
29+
readonly name: VariableName1
30+
readonly match: MatchArm[]
31+
readonly else?: StackValues
32+
}
33+
| {
34+
readonly type: "array"
35+
readonly name: VariableName
36+
readonly length_var: VariableName2
37+
readonly array_entry: ArraySingleEntryDefinition
38+
}
39+
export type PossibleValueTypes = readonly (
40+
| "Int"
41+
| "Bool"
42+
| "Cell"
43+
| "Builder"
44+
| "Slice"
45+
| "Tuple"
46+
| "Continuation"
47+
| "Null"
48+
)[]
49+
export type ConstantType = "Int" | "Null"
50+
export type ConstantValue = number | null | "NaN"
51+
/**
52+
* Allowed chars are `a-zA-Z0-9_`, must not begin with digit or underscore and must not end with underscore.
53+
*/
54+
export type VariableName1 = string
55+
export type ArmValue = number
56+
/**
57+
* Allowed chars are `a-zA-Z0-9_`, must not begin with digit or underscore and must not end with underscore.
58+
*/
59+
export type VariableName2 = string
60+
/**
61+
* Array is a structure like `x1 y1 z1 x2 y2 z2 ... x_n y_n z_n n` which contains `n` entries of `x_i y_i z_i`. This property defines the structure of a single entry.
62+
*/
63+
export type ArraySingleEntryDefinition = StackValues
64+
/**
65+
* Stack constraints. Top of stack is the last value.
66+
*/
67+
export type StackValues = readonly StackEntry[]
68+
/**
69+
* Represents read/write access to a register
70+
*/
71+
export type Register =
72+
| {
73+
readonly type: "constant"
74+
readonly index: number
75+
}
76+
| {
77+
readonly type: "variable"
78+
readonly var_name: VariableName
79+
}
80+
| {
81+
readonly type: "special"
82+
readonly name: "gas" | "cstate" | "r"
83+
}
84+
export type RegisterValues = readonly Register[]
85+
/**
86+
* Description of a continuation with static savelist
87+
*/
88+
export type Continuation =
89+
| {
90+
readonly type: "cc"
91+
readonly save?: ContinuationSavelist
92+
}
93+
| {
94+
readonly type: "variable"
95+
readonly var_name: VariableName3
96+
readonly save?: ContinuationSavelist
97+
}
98+
| {
99+
readonly type: "register"
100+
readonly index: RegisterNumber03
101+
readonly save?: ContinuationSavelist
102+
}
103+
| {
104+
readonly type: "special"
105+
readonly name: "until"
106+
readonly args: {
107+
readonly body: Continuation
108+
readonly after: Continuation
109+
}
110+
}
111+
| {
112+
readonly type: "special"
113+
readonly name: "while"
114+
readonly args: {
115+
readonly cond: Continuation
116+
readonly body: Continuation
117+
readonly after: Continuation
118+
}
119+
}
120+
| {
121+
readonly type: "special"
122+
readonly name: "again"
123+
readonly args: {
124+
readonly body: Continuation
125+
}
126+
}
127+
| {
128+
readonly type: "special"
129+
readonly name: "repeat"
130+
readonly args: {
131+
readonly count: VariableName4
132+
readonly body: Continuation
133+
readonly after: Continuation
134+
}
135+
}
136+
| {
137+
readonly type: "special"
138+
readonly name: "pushint"
139+
readonly args: {
140+
readonly value: IntegerToPushToStack
141+
readonly next: Continuation
142+
}
143+
}
144+
/**
145+
* Allowed chars are `a-zA-Z0-9_`, must not begin with digit or underscore and must not end with underscore.
146+
*/
147+
export type VariableName3 = string
148+
export type RegisterNumber03 = number
149+
/**
150+
* Allowed chars are `a-zA-Z0-9_`, must not begin with digit or underscore and must not end with underscore.
151+
*/
152+
export type VariableName4 = string
153+
export type IntegerToPushToStack = number
154+
155+
export interface Mutation {
156+
readonly length: {
157+
readonly amount_arg?: number
158+
readonly stack_amount_arg?: number
159+
}
160+
}
161+
162+
export type Schema = Record<string, InstructionSignature>
163+
164+
/**
165+
* Information related to usage of stack and registers by instruction.
166+
*/
167+
export interface InstructionSignature {
168+
readonly stack_string?: string
169+
readonly inputs?: InstructionInputs
170+
readonly outputs?: InstructionOutputs
171+
}
172+
173+
/**
174+
* Incoming values constraints.
175+
*/
176+
export interface InstructionInputs {
177+
readonly stack?: StackValues
178+
readonly registers: RegisterValues
179+
}
180+
181+
export interface MatchArm {
182+
readonly value: ArmValue
183+
readonly stack: StackValues
184+
}
185+
186+
/**
187+
* Outgoing values constraints.
188+
*/
189+
export interface InstructionOutputs {
190+
readonly stack?: StackValues
191+
readonly registers: RegisterValues
192+
}
193+
194+
/**
195+
* Values of saved control flow registers c0-c3
196+
*/
197+
export interface ContinuationSavelist {
198+
readonly c0?: Continuation
199+
readonly c1?: Continuation
200+
readonly c2?: Continuation
201+
readonly c3?: Continuation
202+
}

0 commit comments

Comments
 (0)