Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33,114 changes: 0 additions & 33,114 deletions server/src/languages/fift/asm/asm.json

This file was deleted.

5 changes: 2 additions & 3 deletions server/src/languages/fift/asm/gas.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// SPDX-License-Identifier: MIT
// Copyright © 2025 TON Studio
import {getStackPresentation} from "./types"

export function instructionPresentation(
gas: string | undefined,
stack: string | undefined,
stack: string,
format: string,
): string {
if (!gas || gas === "") {
return ": no data"
}
return format.replace("{gas}", gas).replace("{stack}", getStackPresentation(stack))
return format.replace("{gas}", gas).replace("{stack}", stack)
}
1,389 changes: 793 additions & 596 deletions server/src/languages/fift/asm/schema.json

Large diffs are not rendered by default.

142 changes: 142 additions & 0 deletions server/src/languages/fift/asm/specification-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import type {InstructionSignature, Continuation} from "./stack-signatures-schema"

export interface Specification {
readonly $schema: string
readonly version: string
readonly instructions: readonly Instruction[]
readonly fift_instructions: readonly FiftInstruction[]
}

export type FiftArgument = number | string

export interface FiftInstruction {
readonly name: string
readonly actual_name: string
readonly arguments: readonly FiftArgument[]
readonly description?: string
}

export interface ImplementationInfo {
readonly commit_hash: string
readonly file_path: string
readonly line_number: number
readonly function_name: string
}

export interface Instruction {
readonly name: string
readonly category: string
readonly sub_category: string
readonly description: Description
readonly layout: Layout
readonly effects?: readonly string[]
readonly signature?: InstructionSignature
readonly control_flow?: ControlFlowOfInstruction
readonly implementation?: ImplementationInfo
}

export interface ExitCode {
readonly errno: string
readonly condition: string
}

export interface OtherImplementation {
readonly exact: boolean
readonly instructions: readonly string[]
}

export interface ExampleInstruction {
readonly instruction: string
readonly comment?: string
readonly is_main?: boolean
}

export interface ExampleStack {
readonly input: readonly string[]
readonly output: readonly string[]
}

export interface Example {
readonly instructions: readonly ExampleInstruction[]
readonly stack: ExampleStack
readonly exit_code?: number
}

export interface GasConsumptionEntry {
readonly value: number
readonly description: string
readonly formula?: string
}

export interface DocsLink {
readonly name: string
readonly url: string
}

export interface Description {
readonly short: string
readonly long: string
readonly tags: readonly string[]
readonly operands: readonly string[]
readonly exit_codes?: readonly ExitCode[]
readonly other_implementations?: readonly OtherImplementation[]
readonly related_instructions?: readonly string[]
readonly examples?: readonly Example[]
readonly gas?: readonly GasConsumptionEntry[]
readonly docs_links?: readonly DocsLink[]
}

export interface Layout {
readonly min: number
readonly max: number
readonly checkLen: number
readonly skipLen: number
readonly args: Args
readonly exec: string
readonly kind: "ext" | "ext-range" | "fixed" | "fixed-range" | "simple"
readonly prefix: number
readonly prefix_str: string
readonly tlb: string
readonly version?: number
}

export interface Args {
readonly $: "dictpush" | "simpleArgs" | "xchgArgs"
readonly children?: readonly Child[]
readonly range?: ArgRange
}

export interface Child {
readonly $: string
readonly len?: number
readonly range?: ArgRange
readonly delta?: number
readonly arg?: Arg
readonly refs?: Refs
readonly bits?: Arg
readonly pad?: number
}

export interface Arg {
readonly $: "stack" | "uint"
readonly len: number
readonly range: ArgRange
}

export interface ArgRange {
readonly min: string
readonly max: string
}

export interface Refs {
readonly $: string
readonly count?: number
readonly delta?: number
readonly arg?: Arg
readonly len?: number
readonly range?: ArgRange
}

export interface ControlFlowOfInstruction {
readonly branches: Continuation[]
}
202 changes: 202 additions & 0 deletions server/src/languages/fift/asm/stack-signatures-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/**
* Allowed chars are `a-zA-Z0-9_`, must not begin with digit or underscore and must not end with underscore.
*/
export type VariableName = string

export interface PossibleValueRange {
readonly min: number
readonly max: number
}
/**
* Representation of stack entry or group of stack entries
*/
export type StackEntry =
| {
readonly type: "simple"
readonly name: VariableName
readonly range?: PossibleValueRange
readonly presentation: string
readonly value_types?: PossibleValueTypes
readonly mutations?: Mutation[]
}
| {
readonly type: "const"
readonly value_type: ConstantType
readonly value: ConstantValue
}
| {
readonly type: "conditional"
readonly name: VariableName1
readonly match: MatchArm[]
readonly else?: StackValues
}
| {
readonly type: "array"
readonly name: VariableName
readonly length_var: VariableName2
readonly array_entry: ArraySingleEntryDefinition
}
export type PossibleValueTypes = readonly (
| "Int"
| "Bool"
| "Cell"
| "Builder"
| "Slice"
| "Tuple"
| "Continuation"
| "Null"
)[]
export type ConstantType = "Int" | "Null"
export type ConstantValue = number | null | "NaN"
/**
* Allowed chars are `a-zA-Z0-9_`, must not begin with digit or underscore and must not end with underscore.
*/
export type VariableName1 = string
export type ArmValue = number
/**
* Allowed chars are `a-zA-Z0-9_`, must not begin with digit or underscore and must not end with underscore.
*/
export type VariableName2 = string
/**
* 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.
*/
export type ArraySingleEntryDefinition = StackValues
/**
* Stack constraints. Top of stack is the last value.
*/
export type StackValues = readonly StackEntry[]
/**
* Represents read/write access to a register
*/
export type Register =
| {
readonly type: "constant"
readonly index: number
}
| {
readonly type: "variable"
readonly var_name: VariableName
}
| {
readonly type: "special"
readonly name: "gas" | "cstate" | "r"
}
export type RegisterValues = readonly Register[]
/**
* Description of a continuation with static savelist
*/
export type Continuation =
| {
readonly type: "cc"
readonly save?: ContinuationSavelist
}
| {
readonly type: "variable"
readonly var_name: VariableName3
readonly save?: ContinuationSavelist
}
| {
readonly type: "register"
readonly index: RegisterNumber03
readonly save?: ContinuationSavelist
}
| {
readonly type: "special"
readonly name: "until"
readonly args: {
readonly body: Continuation
readonly after: Continuation
}
}
| {
readonly type: "special"
readonly name: "while"
readonly args: {
readonly cond: Continuation
readonly body: Continuation
readonly after: Continuation
}
}
| {
readonly type: "special"
readonly name: "again"
readonly args: {
readonly body: Continuation
}
}
| {
readonly type: "special"
readonly name: "repeat"
readonly args: {
readonly count: VariableName4
readonly body: Continuation
readonly after: Continuation
}
}
| {
readonly type: "special"
readonly name: "pushint"
readonly args: {
readonly value: IntegerToPushToStack
readonly next: Continuation
}
}
/**
* Allowed chars are `a-zA-Z0-9_`, must not begin with digit or underscore and must not end with underscore.
*/
export type VariableName3 = string
export type RegisterNumber03 = number
/**
* Allowed chars are `a-zA-Z0-9_`, must not begin with digit or underscore and must not end with underscore.
*/
export type VariableName4 = string
export type IntegerToPushToStack = number

export interface Mutation {
readonly length: {
readonly amount_arg?: number
readonly stack_amount_arg?: number
}
}

export type Schema = Record<string, InstructionSignature>

/**
* Information related to usage of stack and registers by instruction.
*/
export interface InstructionSignature {
readonly stack_string?: string
readonly inputs?: InstructionInputs
readonly outputs?: InstructionOutputs
}

/**
* Incoming values constraints.
*/
export interface InstructionInputs {
readonly stack?: StackValues
readonly registers: RegisterValues
}

export interface MatchArm {
readonly value: ArmValue
readonly stack: StackValues
}

/**
* Outgoing values constraints.
*/
export interface InstructionOutputs {
readonly stack?: StackValues
readonly registers: RegisterValues
}

/**
* Values of saved control flow registers c0-c3
*/
export interface ContinuationSavelist {
readonly c0?: Continuation
readonly c1?: Continuation
readonly c2?: Continuation
readonly c3?: Continuation
}
Loading