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.4.0",
"version": "0.5.0",
"description": "TON assembler and disassembler",
"author": "TON Studio & TON Core",
"repository": {
Expand Down
3 changes: 3 additions & 0 deletions src/generator/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,9 @@ export const instructions: Record<string, Opcode> = {
INMSG_STATEINIT: version(11, cat("config", mksimple(0xf899, 16, `exec_get_in_msg_param`))),
INMSGPARAM: version(11, cat("config", mkfixedrangen(0xf89a, 0xf8a0, 16, 4, seq(uint4), `exec_get_var_in_msg_param`))),

BTOS: version(12, cat("cell_deserialize", mksimple(0xcf50, 16, "exec_builder_to_slice"))),
HASHBU: version(12, cat("crypto_common", mksimple(0xf916, 16, "exec_compute_hash"))),

DEBUGMARK: cat("int_const", mkfixedn(0xF955, 16, 16, seq(uint(16, range(0n, 0n))), `exec_push_pow2dec`)),

fPUSHSLICE: cat("int_const", mkfixedn(0, 0, 0, seq(slice(uint4, uint4, 0)), "")),
Expand Down
16 changes: 16 additions & 0 deletions src/runtime/constructors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7801,6 +7801,22 @@ export type INMSGPARAM = {
arg0: number
loc: $.Loc | undefined
}
export const BTOS = (loc?: $.Loc): BTOS => ({
$: "BTOS",
loc,
})
export type BTOS = {
$: "BTOS"
loc: $.Loc | undefined
}
export const HASHBU = (loc?: $.Loc): HASHBU => ({
$: "HASHBU",
loc,
})
export type HASHBU = {
$: "HASHBU"
loc: $.Loc | undefined
}
export const DEBUGMARK = (arg0: number, loc?: $.Loc): DEBUGMARK => ({
$: "DEBUGMARK",
arg0,
Expand Down
14 changes: 14 additions & 0 deletions src/runtime/instr-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,8 @@ export type Instr =
| c.INMSG_VALUEEXTRA
| c.INMSG_STATEINIT
| c.INMSGPARAM
| c.BTOS
| c.HASHBU
| c.DEBUGMARK
| cf.fPUSHINT
| cf.fPUSHSLICE
Expand Down Expand Up @@ -5474,6 +5476,16 @@ export const rangeToType = [
max: 16293888,
load: types.INMSGPARAM.load,
},
{
min: 13586432,
max: 13586688,
load: types.BTOS.load,
},
{
min: 16324096,
max: 16324352,
load: types.HASHBU.load,
},
{
min: 16340224,
max: 16340480,
Expand Down Expand Up @@ -6389,6 +6401,8 @@ storeMapping.set("INMSG_VALUE", types.INMSG_VALUE.store)
storeMapping.set("INMSG_VALUEEXTRA", types.INMSG_VALUEEXTRA.store)
storeMapping.set("INMSG_STATEINIT", types.INMSG_STATEINIT.store)
storeMapping.set("INMSGPARAM", types.INMSGPARAM.store)
storeMapping.set("BTOS", types.BTOS.store)
storeMapping.set("HASHBU", types.HASHBU.store)
storeMapping.set("DEBUGMARK", types.DEBUGMARK.store)
storeMapping.set("fPUSHINT", ftypes.fPUSHINT.store)
storeMapping.set("fPUSHSLICE", ftypes.fPUSHSLICE.store)
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/test/tests-decompile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
ENDC,
STREF2CONST,
SUB,
BTOS,
HASHBU,
} from "../index"
import {call, execute} from "../../helpers"
import {bin, code, dictMap, hex} from "../util"
Expand Down Expand Up @@ -349,4 +351,6 @@ ENDC
`DEBUGSTR slice should be byte aligned, but 9-bit slice given`,
),
)
it("with TVM 12 BTOS", test([BTOS()], `BTOS\n`))
it("with TVM 12 HASHBU", test([HASHBU()], `HASHBU\n`))
})
18 changes: 18 additions & 0 deletions src/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8436,6 +8436,24 @@ export const INMSGPARAM: $.Type<c.INMSGPARAM> = {
$.uint(4).store(b, val.arg0, options)
},
}
export const BTOS: $.Type<c.BTOS> = {
load: s => {
s.skip(16)
return c.BTOS()
},
store: (b, val, options) => {
b.storeInstructionPrefix(53072, 16, val)
},
}
export const HASHBU: $.Type<c.HASHBU> = {
load: s => {
s.skip(16)
return c.HASHBU()
},
store: (b, val, options) => {
b.storeInstructionPrefix(63766, 16, val)
},
}
export const DEBUGMARK: $.Type<c.DEBUGMARK> = {
load: s => {
s.skip(16)
Expand Down
12 changes: 12 additions & 0 deletions src/text/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3946,6 +3946,14 @@ export const INMSGPARAM: $.Convert = (ctx, instr, loc) => {
const args = $.singleIntegerArg(instr)
return c.INMSGPARAM(args, loc)
}
export const BTOS: $.Convert = (ctx, instr, loc) => {
u.assertZeroArgs(instr, loc)
return c.BTOS(loc)
}
export const HASHBU: $.Convert = (ctx, instr, loc) => {
u.assertZeroArgs(instr, loc)
return c.HASHBU(loc)
}
export const DEBUGMARK: $.Convert = (ctx, instr, loc) => {
u.assertSingleArgs(instr, loc)
const args = $.singleIntegerArg(instr)
Expand Down Expand Up @@ -5883,6 +5891,10 @@ export const convertInstruction = (ctx: $.Ctx, instr: $ast.Instruction, loc: c.u
return INMSG_STATEINIT(ctx, instr, loc)
case "INMSGPARAM":
return INMSGPARAM(ctx, instr, loc)
case "BTOS":
return BTOS(ctx, instr, loc)
case "HASHBU":
return HASHBU(ctx, instr, loc)
case "DEBUGMARK":
return DEBUGMARK(ctx, instr, loc)
case "fPUSHINT":
Expand Down
4 changes: 4 additions & 0 deletions src/text/printer-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2389,6 +2389,10 @@ export const printInstruction = (p: $.Printer, instr: c.Instr) => {
p.append(" ")
p.append(instr.arg0.toString())
return
case "BTOS":
return
case "HASHBU":
return
case "DEBUGMARK":
p.append(" ")
p.append(instr.arg0.toString())
Expand Down
6 changes: 6 additions & 0 deletions src/text/test/__snapshots__/parser.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ exports[`assembly-parser should give an error for too big number 1`] = `"ParseE

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"`;

exports[`assembly-parser should parse TVM 12 instructions 1`] = `
"BTOS
HASHBU
"
`;

exports[`assembly-parser should parse assembly with invalid raw pushref 1`] = `
"PUSHREF {
embed x{22221}
Expand Down
13 changes: 13 additions & 0 deletions src/text/test/parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,19 @@ describe("assembly-parser", () => {
expect(print(res.instructions)).toMatchSnapshot()
})

it("should parse TVM 12 instructions", () => {
const code = `
BTOS
HASHBU
`
const res = parse("test.asm", code)
if (res.$ === "ParseFailure") {
throw new Error("unexpected parser error")
}

expect(print(res.instructions)).toMatchSnapshot()
})

it("should parse fift instruction", () => {
const code = `
fPUSHINT 10
Expand Down