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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ton-assembly",
"version": "0.2.3",
"version": "0.2.4",
"description": "TON assembler and disassembler",
"keywords": [
"ton",
Expand Down
2 changes: 1 addition & 1 deletion src/generator/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ export const instructions: Record<string, Opcode> = {
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`)),
Expand Down
8 changes: 4 additions & 4 deletions src/runtime/constructors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
24 changes: 12 additions & 12 deletions src/runtime/fift-instr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
THROWIFNOT,
THROWIFNOT_SHORT,
XCHG_0I,
XCHG_01_LONG,
XCHG_0I_LONG,
XCHG_IJ,
SDBEGINS,
SDBEGINSQ,
Expand Down Expand Up @@ -479,7 +479,7 @@ export const fSTSLICECONST: $.Type<c.fSTSLICECONST> = {
export const fXCHG: $.Type<c.fXCHG> = {
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,
Expand Down Expand Up @@ -529,12 +529,12 @@ export const fXCHG: $.Type<c.fXCHG> = {
)
return
} else {
XCHG_01_LONG.store(
XCHG_0I_LONG.store(
b,
{
...val,
arg0: arg1,
$: "XCHG_01_LONG",
$: "XCHG_0I_LONG",
},
options,
)
Expand Down Expand Up @@ -572,30 +572,30 @@ export const fXCHG: $.Type<c.fXCHG> = {
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,
},
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/instr-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/instr-mapping-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4338,7 +4338,7 @@ export const rangeToName = [
{
min: 1114112,
max: 1179648,
name: "XCHG_01_LONG",
name: "XCHG_0I_LONG",
},
{
min: 131072,
Expand Down
12 changes: 6 additions & 6 deletions src/runtime/test/fift.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
`,
),
)
Expand Down
48 changes: 24 additions & 24 deletions src/runtime/test/testdata/WithExotic.tasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -3286,7 +3286,7 @@ export const instructions = [
),
]),
),
i.XCHG_01_LONG(17),
i.XCHG_0I_LONG(17),
i.CALLREF(
u.code([
i.PUSHNULL(),
Expand All @@ -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),
Expand Down Expand Up @@ -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(),
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8036,10 +8036,10 @@ export const PUSHINT_LONG: $.Type<c.PUSHINT_LONG> = {
$.largeInt.store(b, val.arg0, options)
},
}
export const XCHG_01_LONG: $.Type<c.XCHG_01_LONG> = {
export const XCHG_0I_LONG: $.Type<c.XCHG_0I_LONG> = {
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)
Expand Down
8 changes: 4 additions & 4 deletions src/text/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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":
Expand Down
2 changes: 1 addition & 1 deletion src/text/printer-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Loading