|
| 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