Skip to content

Commit 1f99cc1

Browse files
authored
feat: support TVM 12 instructions (#15)
1 parent 0a74b8e commit 1f99cc1

File tree

10 files changed

+91
-1
lines changed

10 files changed

+91
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ton-assembly",
3-
"version": "0.4.0",
3+
"version": "0.5.0",
44
"description": "TON assembler and disassembler",
55
"author": "TON Studio & TON Core",
66
"repository": {

src/generator/instructions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,9 @@ export const instructions: Record<string, Opcode> = {
13461346
INMSG_STATEINIT: version(11, cat("config", mksimple(0xf899, 16, `exec_get_in_msg_param`))),
13471347
INMSGPARAM: version(11, cat("config", mkfixedrangen(0xf89a, 0xf8a0, 16, 4, seq(uint4), `exec_get_var_in_msg_param`))),
13481348

1349+
BTOS: version(12, cat("cell_deserialize", mksimple(0xcf50, 16, "exec_builder_to_slice"))),
1350+
HASHBU: version(12, cat("crypto_common", mksimple(0xf916, 16, "exec_compute_hash"))),
1351+
13491352
DEBUGMARK: cat("int_const", mkfixedn(0xF955, 16, 16, seq(uint(16, range(0n, 0n))), `exec_push_pow2dec`)),
13501353

13511354
fPUSHSLICE: cat("int_const", mkfixedn(0, 0, 0, seq(slice(uint4, uint4, 0)), "")),

src/runtime/constructors.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7801,6 +7801,22 @@ export type INMSGPARAM = {
78017801
arg0: number
78027802
loc: $.Loc | undefined
78037803
}
7804+
export const BTOS = (loc?: $.Loc): BTOS => ({
7805+
$: "BTOS",
7806+
loc,
7807+
})
7808+
export type BTOS = {
7809+
$: "BTOS"
7810+
loc: $.Loc | undefined
7811+
}
7812+
export const HASHBU = (loc?: $.Loc): HASHBU => ({
7813+
$: "HASHBU",
7814+
loc,
7815+
})
7816+
export type HASHBU = {
7817+
$: "HASHBU"
7818+
loc: $.Loc | undefined
7819+
}
78047820
export const DEBUGMARK = (arg0: number, loc?: $.Loc): DEBUGMARK => ({
78057821
$: "DEBUGMARK",
78067822
arg0,

src/runtime/instr-gen.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,8 @@ export type Instr =
916916
| c.INMSG_VALUEEXTRA
917917
| c.INMSG_STATEINIT
918918
| c.INMSGPARAM
919+
| c.BTOS
920+
| c.HASHBU
919921
| c.DEBUGMARK
920922
| cf.fPUSHINT
921923
| cf.fPUSHSLICE
@@ -5474,6 +5476,16 @@ export const rangeToType = [
54745476
max: 16293888,
54755477
load: types.INMSGPARAM.load,
54765478
},
5479+
{
5480+
min: 13586432,
5481+
max: 13586688,
5482+
load: types.BTOS.load,
5483+
},
5484+
{
5485+
min: 16324096,
5486+
max: 16324352,
5487+
load: types.HASHBU.load,
5488+
},
54775489
{
54785490
min: 16340224,
54795491
max: 16340480,
@@ -6389,6 +6401,8 @@ storeMapping.set("INMSG_VALUE", types.INMSG_VALUE.store)
63896401
storeMapping.set("INMSG_VALUEEXTRA", types.INMSG_VALUEEXTRA.store)
63906402
storeMapping.set("INMSG_STATEINIT", types.INMSG_STATEINIT.store)
63916403
storeMapping.set("INMSGPARAM", types.INMSGPARAM.store)
6404+
storeMapping.set("BTOS", types.BTOS.store)
6405+
storeMapping.set("HASHBU", types.HASHBU.store)
63926406
storeMapping.set("DEBUGMARK", types.DEBUGMARK.store)
63936407
storeMapping.set("fPUSHINT", ftypes.fPUSHINT.store)
63946408
storeMapping.set("fPUSHSLICE", ftypes.fPUSHSLICE.store)

src/runtime/test/tests-decompile.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {
2020
ENDC,
2121
STREF2CONST,
2222
SUB,
23+
BTOS,
24+
HASHBU,
2325
} from "../index"
2426
import {call, execute} from "../../helpers"
2527
import {bin, code, dictMap, hex} from "../util"
@@ -349,4 +351,6 @@ ENDC
349351
`DEBUGSTR slice should be byte aligned, but 9-bit slice given`,
350352
),
351353
)
354+
it("with TVM 12 BTOS", test([BTOS()], `BTOS\n`))
355+
it("with TVM 12 HASHBU", test([HASHBU()], `HASHBU\n`))
352356
})

src/runtime/types.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8436,6 +8436,24 @@ export const INMSGPARAM: $.Type<c.INMSGPARAM> = {
84368436
$.uint(4).store(b, val.arg0, options)
84378437
},
84388438
}
8439+
export const BTOS: $.Type<c.BTOS> = {
8440+
load: s => {
8441+
s.skip(16)
8442+
return c.BTOS()
8443+
},
8444+
store: (b, val, options) => {
8445+
b.storeInstructionPrefix(53072, 16, val)
8446+
},
8447+
}
8448+
export const HASHBU: $.Type<c.HASHBU> = {
8449+
load: s => {
8450+
s.skip(16)
8451+
return c.HASHBU()
8452+
},
8453+
store: (b, val, options) => {
8454+
b.storeInstructionPrefix(63766, 16, val)
8455+
},
8456+
}
84398457
export const DEBUGMARK: $.Type<c.DEBUGMARK> = {
84408458
load: s => {
84418459
s.skip(16)

src/text/convert.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3946,6 +3946,14 @@ export const INMSGPARAM: $.Convert = (ctx, instr, loc) => {
39463946
const args = $.singleIntegerArg(instr)
39473947
return c.INMSGPARAM(args, loc)
39483948
}
3949+
export const BTOS: $.Convert = (ctx, instr, loc) => {
3950+
u.assertZeroArgs(instr, loc)
3951+
return c.BTOS(loc)
3952+
}
3953+
export const HASHBU: $.Convert = (ctx, instr, loc) => {
3954+
u.assertZeroArgs(instr, loc)
3955+
return c.HASHBU(loc)
3956+
}
39493957
export const DEBUGMARK: $.Convert = (ctx, instr, loc) => {
39503958
u.assertSingleArgs(instr, loc)
39513959
const args = $.singleIntegerArg(instr)
@@ -5883,6 +5891,10 @@ export const convertInstruction = (ctx: $.Ctx, instr: $ast.Instruction, loc: c.u
58835891
return INMSG_STATEINIT(ctx, instr, loc)
58845892
case "INMSGPARAM":
58855893
return INMSGPARAM(ctx, instr, loc)
5894+
case "BTOS":
5895+
return BTOS(ctx, instr, loc)
5896+
case "HASHBU":
5897+
return HASHBU(ctx, instr, loc)
58865898
case "DEBUGMARK":
58875899
return DEBUGMARK(ctx, instr, loc)
58885900
case "fPUSHINT":

src/text/printer-gen.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,6 +2389,10 @@ export const printInstruction = (p: $.Printer, instr: c.Instr) => {
23892389
p.append(" ")
23902390
p.append(instr.arg0.toString())
23912391
return
2392+
case "BTOS":
2393+
return
2394+
case "HASHBU":
2395+
return
23922396
case "DEBUGMARK":
23932397
p.append(" ")
23942398
p.append(instr.arg0.toString())

src/text/test/__snapshots__/parser.spec.ts.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ exports[`assembly-parser should give an error for too big number 1`] = `"ParseE
66

77
exports[`assembly-parser should not parse assembly with error 1`] = `"ParseError: Expected "-", "0", "[", "\\"", "boc{", "b{", "c", "embed", "exotic", "ref", "s", "x{", "{", digit, or identifier at test.asm:1"`;
88
9+
exports[`assembly-parser should parse TVM 12 instructions 1`] = `
10+
"BTOS
11+
HASHBU
12+
"
13+
`;
14+
915
exports[`assembly-parser should parse assembly with invalid raw pushref 1`] = `
1016
"PUSHREF {
1117
embed x{22221}

src/text/test/parser.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,19 @@ describe("assembly-parser", () => {
273273
expect(print(res.instructions)).toMatchSnapshot()
274274
})
275275

276+
it("should parse TVM 12 instructions", () => {
277+
const code = `
278+
BTOS
279+
HASHBU
280+
`
281+
const res = parse("test.asm", code)
282+
if (res.$ === "ParseFailure") {
283+
throw new Error("unexpected parser error")
284+
}
285+
286+
expect(print(res.instructions)).toMatchSnapshot()
287+
})
288+
276289
it("should parse fift instruction", () => {
277290
const code = `
278291
fPUSHINT 10

0 commit comments

Comments
 (0)