From 901812c924952673a19b0ef576461a4ff0806dc7 Mon Sep 17 00:00:00 2001 From: i582 <51853996+i582@users.noreply.github.com> Date: Fri, 15 Aug 2025 13:28:13 +0400 Subject: [PATCH 1/2] fix: rename `XCHG_01_LONG` to `XCHG_0I_LONG` --- package.json | 2 +- src/generator/instructions.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f87ad4a..68d695e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ton-assembly", - "version": "0.2.3", + "version": "0.2.4", "description": "TON assembler and disassembler", "keywords": [ "ton", diff --git a/src/generator/instructions.ts b/src/generator/instructions.ts index cbc791a..1c16c06 100644 --- a/src/generator/instructions.ts +++ b/src/generator/instructions.ts @@ -1287,7 +1287,7 @@ export const instructions: Record = { PUSHINT_16: cat("int_const", mkfixedn(0x81, 8, 16, seq(int16), `exec_push_smallint`)), PUSHINT_LONG: cat("int_const", mkextrange(0x820 << 1, (0x820 << 1) + 31, 13, 5, seq(largeInt), `exec_push_int`)), - XCHG_01_LONG: cat("stack", mkfixedn(0x11, 8, 8, seq(stack2(8, 1n)), `exec_xchg0_l`)), + XCHG_0I_LONG: cat("stack", mkfixedn(0x11, 8, 8, seq(stack2(8, 1n)), `exec_xchg0_l`)), XCHG_0I: cat("stack", mkfixedrangen(0x02, 0x10, 8, 4, seq(stack2(4, 1n)), `exec_xchg0`)), XCHG_IJ: cat("stack", mkfixedn(0x10, 8, 8, xchgArgs, `exec_xchg`)), XCHG_1I: cat("stack", mkfixedrangen(0x12, 0x20, 8, 4, seq(s1, stack2(4, 2n)), `exec_xchg1`)), From a9de7a85acab901eb4c9d2b6a19f53586bdeb414 Mon Sep 17 00:00:00 2001 From: i582 <51853996+i582@users.noreply.github.com> Date: Fri, 15 Aug 2025 13:30:25 +0400 Subject: [PATCH 2/2] rename --- src/runtime/constructors.ts | 8 ++-- src/runtime/fift-instr.ts | 24 +++++----- src/runtime/instr-gen.ts | 6 +-- src/runtime/instr-mapping-gen.ts | 2 +- src/runtime/test/fift.spec.ts | 12 ++--- src/runtime/test/testdata/WithExotic.tasm.ts | 48 ++++++++++---------- src/runtime/types.ts | 4 +- src/text/convert.ts | 8 ++-- src/text/printer-gen.ts | 2 +- 9 files changed, 57 insertions(+), 57 deletions(-) diff --git a/src/runtime/constructors.ts b/src/runtime/constructors.ts index 2485a5e..3d486a8 100644 --- a/src/runtime/constructors.ts +++ b/src/runtime/constructors.ts @@ -7381,13 +7381,13 @@ export type PUSHINT_LONG = { arg0: bigint loc: $.Loc | undefined } -export const XCHG_01_LONG = (arg0: number, loc?: $.Loc): XCHG_01_LONG => ({ - $: "XCHG_01_LONG", +export const XCHG_0I_LONG = (arg0: number, loc?: $.Loc): XCHG_0I_LONG => ({ + $: "XCHG_0I_LONG", arg0, loc, }) -export type XCHG_01_LONG = { - $: "XCHG_01_LONG" +export type XCHG_0I_LONG = { + $: "XCHG_0I_LONG" arg0: number loc: $.Loc | undefined } diff --git a/src/runtime/fift-instr.ts b/src/runtime/fift-instr.ts index 01db001..a05d716 100644 --- a/src/runtime/fift-instr.ts +++ b/src/runtime/fift-instr.ts @@ -39,7 +39,7 @@ import { THROWIFNOT, THROWIFNOT_SHORT, XCHG_0I, - XCHG_01_LONG, + XCHG_0I_LONG, XCHG_IJ, SDBEGINS, SDBEGINSQ, @@ -479,7 +479,7 @@ export const fSTSLICECONST: $.Type = { export const fXCHG: $.Type = { load: s => { const loaded = instr.load(s) - if (loaded.$ === "XCHG_0I" || loaded.$ === "XCHG_01_LONG") { + if (loaded.$ === "XCHG_0I" || loaded.$ === "XCHG_0I_LONG") { return { $: "fXCHG", arg0: 0, @@ -529,12 +529,12 @@ export const fXCHG: $.Type = { ) return } else { - XCHG_01_LONG.store( + XCHG_0I_LONG.store( b, { ...val, arg0: arg1, - $: "XCHG_01_LONG", + $: "XCHG_0I_LONG", }, options, ) @@ -572,30 +572,30 @@ export const fXCHG: $.Type = { return } - // For large indices, we need to emit multiple XCHG_01_LONG operations - // XCHG si, sj = XCHG_01_LONG si, XCHG_01_LONG sj, XCHG_01_LONG si - XCHG_01_LONG.store( + // For large indices, we need to emit multiple XCHG_0I_LONG operations + // XCHG si, sj = XCHG_0I_LONG si, XCHG_0I_LONG sj, XCHG_0I_LONG si + XCHG_0I_LONG.store( b, { - $: "XCHG_01_LONG", + $: "XCHG_0I_LONG", arg0: arg0, loc: val.loc, }, options, ) - XCHG_01_LONG.store( + XCHG_0I_LONG.store( b, { - $: "XCHG_01_LONG", + $: "XCHG_0I_LONG", arg0: arg1, loc: val.loc, }, options, ) - XCHG_01_LONG.store( + XCHG_0I_LONG.store( b, { - $: "XCHG_01_LONG", + $: "XCHG_0I_LONG", arg0: arg0, loc: val.loc, }, diff --git a/src/runtime/instr-gen.ts b/src/runtime/instr-gen.ts index 7479663..647a3d6 100644 --- a/src/runtime/instr-gen.ts +++ b/src/runtime/instr-gen.ts @@ -872,7 +872,7 @@ export type Instr = | c.PUSHINT_8 | c.PUSHINT_16 | c.PUSHINT_LONG - | c.XCHG_01_LONG + | c.XCHG_0I_LONG | c.XCHG_0I | c.XCHG_IJ | c.XCHG_1I @@ -5272,7 +5272,7 @@ export const rangeToType = [ { min: 1114112, max: 1179648, - load: types.XCHG_01_LONG.load, + load: types.XCHG_0I_LONG.load, }, { min: 131072, @@ -6348,7 +6348,7 @@ storeMapping.set("PUSHINT_4", types.PUSHINT_4.store) storeMapping.set("PUSHINT_8", types.PUSHINT_8.store) storeMapping.set("PUSHINT_16", types.PUSHINT_16.store) storeMapping.set("PUSHINT_LONG", types.PUSHINT_LONG.store) -storeMapping.set("XCHG_01_LONG", types.XCHG_01_LONG.store) +storeMapping.set("XCHG_0I_LONG", types.XCHG_0I_LONG.store) storeMapping.set("XCHG_0I", types.XCHG_0I.store) storeMapping.set("XCHG_IJ", types.XCHG_IJ.store) storeMapping.set("XCHG_1I", types.XCHG_1I.store) diff --git a/src/runtime/instr-mapping-gen.ts b/src/runtime/instr-mapping-gen.ts index dccf863..e8bdce6 100644 --- a/src/runtime/instr-mapping-gen.ts +++ b/src/runtime/instr-mapping-gen.ts @@ -4338,7 +4338,7 @@ export const rangeToName = [ { min: 1114112, max: 1179648, - name: "XCHG_01_LONG", + name: "XCHG_0I_LONG", }, { min: 131072, diff --git a/src/runtime/test/fift.spec.ts b/src/runtime/test/fift.spec.ts index 05fcd5d..09279ed 100644 --- a/src/runtime/test/fift.spec.ts +++ b/src/runtime/test/fift.spec.ts @@ -391,22 +391,22 @@ describe("Test XCHG Fift instruction", () => { ), ) it( - "with s0, s16 -> XCHG_01_LONG", + "with s0, s16 -> XCHG_0I_LONG", test( [fXCHG(0, 16)], ` - XCHG_01_LONG s16 + XCHG_0I_LONG s16 `, ), ) it( - "with large indices -> triple XCHG_01_LONG sequence", + "with large indices -> triple XCHG_0I_LONG sequence", test( [fXCHG(5, 20)], ` - XCHG_01_LONG s5 - XCHG_01_LONG s20 - XCHG_01_LONG s5 + XCHG_0I_LONG s5 + XCHG_0I_LONG s20 + XCHG_0I_LONG s5 `, ), ) diff --git a/src/runtime/test/testdata/WithExotic.tasm.ts b/src/runtime/test/testdata/WithExotic.tasm.ts index 38b1dbf..943ec92 100644 --- a/src/runtime/test/testdata/WithExotic.tasm.ts +++ b/src/runtime/test/testdata/WithExotic.tasm.ts @@ -2604,24 +2604,24 @@ export const instructions = [ i.PUSHINT_4(0), i.SENDRAWMSG(), i.XCHG_0I(6), - i.XCHG_01_LONG(22), + i.XCHG_0I_LONG(22), i.XCHG_0I(6), i.XCHG_0I(5), - i.XCHG_01_LONG(21), + i.XCHG_0I_LONG(21), i.XCHG_0I(5), i.XCHG_0I(4), - i.XCHG_01_LONG(20), + i.XCHG_0I_LONG(20), i.XCHG_0I(4), i.XCHG_0I(3), - i.XCHG_01_LONG(19), + i.XCHG_0I_LONG(19), i.XCHG_0I(3), i.XCHG_0I(2), - i.XCHG_01_LONG(18), + i.XCHG_0I_LONG(18), i.XCHG_0I(2), i.SWAP(), - i.XCHG_01_LONG(17), + i.XCHG_0I_LONG(17), i.SWAP(), - i.XCHG_01_LONG(16), + i.XCHG_0I_LONG(16), i.PUSH(13), i.CALLREF( u.code([ @@ -3286,7 +3286,7 @@ export const instructions = [ ), ]), ), - i.XCHG_01_LONG(17), + i.XCHG_0I_LONG(17), i.CALLREF( u.code([ i.PUSHNULL(), @@ -3308,7 +3308,7 @@ export const instructions = [ ]), ), i.SWAP(), - i.XCHG_01_LONG(17), + i.XCHG_0I_LONG(17), i.SWAP(), i.DUP2(), i.PUSHINT_4(0), @@ -3355,42 +3355,42 @@ export const instructions = [ i.EQUAL(), i.THROWIFNOT(136), i.XCHG_0I(14), - i.XCHG_01_LONG(17), + i.XCHG_0I_LONG(17), i.XCHG_0I(14), i.XCHG_0I(13), - i.XCHG_01_LONG(16), + i.XCHG_0I_LONG(16), i.XCHG_0I(13), i.XCHG_IJ(12, 15), i.XCHG_0I(11), - i.XCHG_01_LONG(17), + i.XCHG_0I_LONG(17), i.XCHG_0I(11), i.XCHG_0I(10), - i.XCHG_01_LONG(16), + i.XCHG_0I_LONG(16), i.XCHG_0I(10), i.XCHG_IJ(9, 15), i.XCHG_0I(8), - i.XCHG_01_LONG(17), + i.XCHG_0I_LONG(17), i.XCHG_0I(8), i.XCHG_0I(7), - i.XCHG_01_LONG(16), + i.XCHG_0I_LONG(16), i.XCHG_0I(7), i.XCHG_IJ(6, 15), i.XCHG_0I(5), - i.XCHG_01_LONG(24), + i.XCHG_0I_LONG(24), i.XCHG_0I(5), i.XCHG_0I(4), - i.XCHG_01_LONG(23), + i.XCHG_0I_LONG(23), i.XCHG_0I(4), i.XCHG_0I(3), - i.XCHG_01_LONG(22), + i.XCHG_0I_LONG(22), i.XCHG_0I(3), i.XCHG_0I(2), - i.XCHG_01_LONG(21), + i.XCHG_0I_LONG(21), i.XCHG_0I(2), i.SWAP(), - i.XCHG_01_LONG(20), + i.XCHG_0I_LONG(20), i.SWAP(), - i.XCHG_01_LONG(19), + i.XCHG_0I_LONG(19), i.PSEUDO_PUSHREF( u.code([ i.NEWC(), @@ -3401,7 +3401,7 @@ export const instructions = [ 1022504860n, ), i.SWAP(), - i.XCHG_01_LONG(16), + i.XCHG_0I_LONG(16), i.STU(32), i.XCHG_1I(1, 14), i.STU(64), @@ -5396,10 +5396,10 @@ export const instructions = [ i.XCHG_IJ(7, 10), i.XCHG_IJ(6, 9), i.XCHG_0I(5), - i.XCHG_01_LONG(17), + i.XCHG_0I_LONG(17), i.XCHG_0I(5), i.XCHG_0I(4), - i.XCHG_01_LONG(16), + i.XCHG_0I_LONG(16), i.XCHG_0I(4), i.XCHG_IJ(3, 15), i.XCHG3(14, 13, 12), diff --git a/src/runtime/types.ts b/src/runtime/types.ts index af8a88a..87960a9 100644 --- a/src/runtime/types.ts +++ b/src/runtime/types.ts @@ -8036,10 +8036,10 @@ export const PUSHINT_LONG: $.Type = { $.largeInt.store(b, val.arg0, options) }, } -export const XCHG_01_LONG: $.Type = { +export const XCHG_0I_LONG: $.Type = { load: s => { s.skip(8) - return c.XCHG_01_LONG($.uint(8).load(s)) + return c.XCHG_0I_LONG($.uint(8).load(s)) }, store: (b, val, options) => { b.storeInstructionPrefix(17, 8, val) diff --git a/src/text/convert.ts b/src/text/convert.ts index bb38cc7..0ed1e77 100644 --- a/src/text/convert.ts +++ b/src/text/convert.ts @@ -3743,10 +3743,10 @@ export const PUSHINT_LONG: $.Convert = (ctx, instr, loc) => { const args = $.singleBigIntArg(instr) return c.PUSHINT_LONG(args, loc) } -export const XCHG_01_LONG: $.Convert = (ctx, instr, loc) => { +export const XCHG_0I_LONG: $.Convert = (ctx, instr, loc) => { u.assertSingleArgs(instr, loc) const args = $.singleStackArg(instr) - return c.XCHG_01_LONG(args, loc) + return c.XCHG_0I_LONG(args, loc) } export const XCHG_0I: $.Convert = (ctx, instr, loc) => { u.assertSingleArgs(instr, loc) @@ -5801,8 +5801,8 @@ export const convertInstruction = (ctx: $.Ctx, instr: $ast.Instruction, loc: c.u return PUSHINT_16(ctx, instr, loc) case "PUSHINT_LONG": return PUSHINT_LONG(ctx, instr, loc) - case "XCHG_01_LONG": - return XCHG_01_LONG(ctx, instr, loc) + case "XCHG_0I_LONG": + return XCHG_0I_LONG(ctx, instr, loc) case "XCHG_0I": return XCHG_0I(ctx, instr, loc) case "XCHG_IJ": diff --git a/src/text/printer-gen.ts b/src/text/printer-gen.ts index a2b4931..ab6c20c 100644 --- a/src/text/printer-gen.ts +++ b/src/text/printer-gen.ts @@ -2233,7 +2233,7 @@ export const printInstruction = (p: $.Printer, instr: c.Instr) => { p.append(" ") p.append(instr.arg0.toString()) return - case "XCHG_01_LONG": + case "XCHG_0I_LONG": p.append(" ") p.append("s") p.append(instr.arg0.toString())