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
1 change: 0 additions & 1 deletion src/generator/gen-constructors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ const generateArg = (arg: $.arg): t.TSType => {
switch (arg.$) {
case "int":
case "uint":
case "refs":
case "stack":
case "control":
case "plduzArg":
Expand Down
1 change: 0 additions & 1 deletion src/generator/gen-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ function isIntegerArg(arg: $.arg) {
return (
arg.$ === "int" ||
arg.$ === "uint" ||
arg.$ === "refs" ||
arg.$ === "plduzArg" ||
arg.$ === "tinyInt" ||
arg.$ === "runvmArg" ||
Expand Down
1 change: 0 additions & 1 deletion src/generator/gen-printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ const generateArg = (name: string, arg: $.arg): t.Statement[] => {
switch (arg.$) {
case "int":
case "uint":
case "refs":
case "plduzArg":
case "tinyInt":
case "largeInt":
Expand Down
2 changes: 0 additions & 2 deletions src/generator/gen-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ const generateArg = (arg: $.arg): t.Expression => {
return generateTypeDescription("int", arg.len)
case "uint":
return generateTypeDescription("uint", arg.len)
case "refs":
return generateTypeDescription("refs", arg.count)
case "stack":
return generateTypeDescription("uint", arg.len)
case "control":
Expand Down
13 changes: 5 additions & 8 deletions src/generator/instructions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export type arg =
| uint
| int
| refs
| delta
| stack
| control
Expand Down Expand Up @@ -29,9 +28,6 @@ export const uint = (len: number, range: range): uint => ({$: "uint", len, range
export type int = {$: "int", len: number, range: range}
export const int = (len: number, range: range): int => ({$: "int", len, range})

export type refs = {$: "refs", count: number}
export const refs = (count: number): refs => ({$: "refs", count})

export type delta = {$: "delta", delta: number, arg: arg}
export const delta = (delta: number, arg: arg): delta => ({$: "delta", delta, arg})

Expand Down Expand Up @@ -368,6 +364,7 @@ const uint14range = range(0n, BigInt(Math.pow(2, 14) - 1))
const int8 = int(8, int8range)
const int16 = int(16, int16range)

const uint0 = uint(0, {min: 0n, max: 0n})
const uint2 = uint(2, uint2range)
const uint3 = uint(3, uint3range)
const uint4 = uint(4, uint4range)
Expand Down Expand Up @@ -1161,8 +1158,8 @@ export const instructions: Record<string, Opcode> = {
// SECTION: sdbegins
SDBEGINSX: cat("cell_deserialize", mksimple(0xd726, 16, `(_1) => exec_slice_begins_with(_1, false)`)),
SDBEGINSXQ: cat("cell_deserialize", mksimple(0xd727, 16, `(_1) => exec_slice_begins_with(_1, true)`)),
SDBEGINS: cat("cell_deserialize", mkext(0xd728 >> 2, 14, 7, seq(slice(refs(0), uint7, 3)), `exec_slice_begins_with_const`)),
SDBEGINSQ: cat("cell_deserialize", mkext(0xd72c >> 2, 14, 7, seq(slice(refs(0), uint7, 3)), `exec_slice_begins_with_const`)),
SDBEGINS: cat("cell_deserialize", mkext(0xd728 >> 2, 14, 7, seq(slice(uint0, uint7, 3)), `exec_slice_begins_with_const`)),
SDBEGINSQ: cat("cell_deserialize", mkext(0xd72c >> 2, 14, 7, seq(slice(uint0, uint7, 3)), `exec_slice_begins_with_const`)),
// END SECTION

STREFCONST: cat("cell_serialize", mkextrange(0xcf20, 0xcf21, 16, 0, seq(refCodeSlice), `exec_store_const_ref`)),
Expand Down Expand Up @@ -1308,7 +1305,7 @@ export const instructions: Record<string, Opcode> = {
CALLXARGS: cat("continuation_jump", mkfixedn(0xdb0, 12, 4, seq(uint4, minusOne), `exec_callx_args_p`)),
CALLXARGS_1: cat("continuation_jump", mkfixedn(0xda, 8, 8, seq(uint4, uint4), `exec_callx_args`)),

PUSHSLICE: cat("cell_const", mkext(0x8b, 8, 4, seq(slice(refs(0), uint4, 4)), `exec_push_slice`)),
PUSHSLICE: cat("cell_const", mkext(0x8b, 8, 4, seq(slice(uint0, uint4, 4)), `exec_push_slice`)),
PUSHSLICE_REFS: cat("cell_const", mkext(0x8c, 8, 7, seq(slice(delta(1, uint2), uint5, 1)), `exec_push_slice_r`)),
PUSHSLICE_LONG: cat("cell_const", mkextrange((0x8d << 3) << 7, ((0x8d << 3) + 5) << 7, 18, 10, seq(slice(uint3, uint7, 6)), `exec_push_slice_r2`)),

Expand All @@ -1324,7 +1321,7 @@ export const instructions: Record<string, Opcode> = {
// SETCP: cat("codepage", mkfixedrangen(0xff00, 0x10000, 16, 8, seq(setcpArg), `exec_set_cp`)),

PSEUDO_PUSHREF: cat("cell_const", mkfixedpseudo(0, seq(refCodeSlice))),
PSEUDO_PUSHSLICE: cat("cell_const", mkfixedpseudo(0, seq(slice(refs(1), uint(0, range(0n, 0n)), 0)))),
PSEUDO_PUSHSLICE: cat("cell_const", mkfixedpseudo(0, seq(slice(uint0, uint(0, range(0n, 0n)), 0)))),
PSEUDO_EXOTIC: cat("cell_const", mkfixedpseudo(0, seq(exoticCell))),

// TVM 11 instructions
Expand Down
12 changes: 6 additions & 6 deletions src/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7042,21 +7042,21 @@ export const SDBEGINSXQ: $.Type<c.SDBEGINSXQ> = {
export const SDBEGINS: $.Type<c.SDBEGINS> = {
load: s => {
s.skip(14)
return c.SDBEGINS($.slice($.refs(0), $.uint(7), 3).load(s))
return c.SDBEGINS($.slice($.uint(0), $.uint(7), 3).load(s))
},
store: (b, val, options) => {
b.storeInstructionPrefix(13770, 14, val)
$.slice($.refs(0), $.uint(7), 3).store(b, val.arg0, options)
$.slice($.uint(0), $.uint(7), 3).store(b, val.arg0, options)
},
}
export const SDBEGINSQ: $.Type<c.SDBEGINSQ> = {
load: s => {
s.skip(14)
return c.SDBEGINSQ($.slice($.refs(0), $.uint(7), 3).load(s))
return c.SDBEGINSQ($.slice($.uint(0), $.uint(7), 3).load(s))
},
store: (b, val, options) => {
b.storeInstructionPrefix(13771, 14, val)
$.slice($.refs(0), $.uint(7), 3).store(b, val.arg0, options)
$.slice($.uint(0), $.uint(7), 3).store(b, val.arg0, options)
},
}
export const STREFCONST: $.Type<c.STREFCONST> = {
Expand Down Expand Up @@ -8221,11 +8221,11 @@ export const CALLXARGS_1: $.Type<c.CALLXARGS_1> = {
export const PUSHSLICE: $.Type<c.PUSHSLICE> = {
load: s => {
s.skip(8)
return c.PUSHSLICE($.slice($.refs(0), $.uint(4), 4).load(s))
return c.PUSHSLICE($.slice($.uint(0), $.uint(4), 4).load(s))
},
store: (b, val, options) => {
b.storeInstructionPrefix(139, 8, val)
$.slice($.refs(0), $.uint(4), 4).store(b, val.arg0, options)
$.slice($.uint(0), $.uint(4), 4).store(b, val.arg0, options)
},
}
export const PUSHSLICE_REFS: $.Type<c.PUSHSLICE_REFS> = {
Expand Down
20 changes: 11 additions & 9 deletions src/runtime/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export type Type<T> = {
}

export function uint(bits: number): Type<number> {
if (bits === 0) {
return {
store: (_b, _t, _options) => {},
load: _s => 0,
}
}
return {
store: (b, t, _options) => b.storeUint(t, bits),
load: s => s.loadUint(bits),
Expand Down Expand Up @@ -227,16 +233,11 @@ export const inlineCodeSlice = (bits: Type<number>): Type<Code> => {
}
}

export const slice = (
refs: Type<number> | number, // TODO: remove union
bits: Type<number>,
pad: number,
): Type<Slice> => {
export const slice = (refs: Type<number>, bits: Type<number>, pad: number): Type<Slice> => {
return {
store: (b, slice, options) => {
if (typeof refs !== "number") {
refs.store(b, slice.remainingRefs, options)
}
// For instructions without refs, we use uint(0) that doesn't write anything
refs.store(b, slice.remainingRefs, options)
const length = slice.remainingBits + 1
const y = Math.ceil((length - pad) / 8)
bits.store(b, y, options)
Expand All @@ -246,7 +247,8 @@ export const slice = (
b.storeUint(0x0, realLength - length)
},
load: s => {
const countRefs = typeof refs === "number" ? refs : refs.load(s)
// For instructions without refs, we use uint(0) that will return a zero from load
const countRefs = refs.load(s)
const y = bits.load(s)
const realLength = y * 8 + pad
const r = s.loadBits(realLength)
Expand Down