Skip to content

Commit d6118b2

Browse files
authored
feat: replace runvmArg and hash with uint for simplicity (#18)
1 parent d6e7262 commit d6118b2

File tree

8 files changed

+20
-78
lines changed

8 files changed

+20
-78
lines changed

src/generator/gen-constructors.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ const generateArg = (arg: $.arg): t.TSType => {
131131
case "control":
132132
case "plduzArg":
133133
case "tinyInt":
134-
case "runvmArg":
135134
case "minusOne":
136135
case "s1":
137136
case "setcpArg":
@@ -142,8 +141,6 @@ const generateArg = (arg: $.arg): t.TSType => {
142141
return t.tsBigIntKeyword()
143142
case "debugstr":
144143
return t.tsTypeReference(t.tsQualifiedName(TON_CORE_QUALIFIER, t.identifier("Slice")))
145-
case "hash":
146-
return t.tsTypeReference(t.tsQualifiedName(UTIL_QUALIFIER, t.identifier("Hash")))
147144
case "codeSlice":
148145
return t.tsTypeReference(t.tsQualifiedName(UTIL_QUALIFIER, t.identifier("Code")))
149146
case "refCodeSlice":

src/generator/gen-converter.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,8 @@ function isIntegerArg(arg: $.arg) {
215215
arg.$ === "uint" ||
216216
arg.$ === "plduzArg" ||
217217
arg.$ === "tinyInt" ||
218-
arg.$ === "runvmArg" ||
219218
arg.$ === "minusOne" ||
220219
arg.$ === "delta" ||
221-
arg.$ === "hash" || // TODO: separate type
222220
arg.$ === "setcpArg"
223221
)
224222
}

src/generator/gen-printer.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,8 @@ const generateArg = (name: string, arg: $.arg): t.Statement[] => {
150150
case "plduzArg":
151151
case "tinyInt":
152152
case "largeInt":
153-
case "runvmArg":
154153
case "minusOne":
155154
case "setcpArg":
156-
case "hash":
157155
return [writeToString(name)]
158156

159157
case "delta":

src/generator/gen-types.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,6 @@ const generateArg = (arg: $.arg): t.Expression => {
237237
return t.memberExpression(UTIL_QUALIFIER, t.identifier("tinyInt"))
238238
case "largeInt":
239239
return t.memberExpression(UTIL_QUALIFIER, t.identifier("largeInt"))
240-
case "runvmArg":
241-
return t.memberExpression(UTIL_QUALIFIER, t.identifier("runvmArg"))
242240
case "minusOne":
243241
return t.memberExpression(UTIL_QUALIFIER, t.identifier("minusOne"))
244242
case "s1":
@@ -250,8 +248,6 @@ const generateArg = (arg: $.arg): t.Expression => {
250248
t.numericLiteral(arg.delta),
251249
generateArg(arg.arg),
252250
])
253-
case "hash":
254-
return t.memberExpression(UTIL_QUALIFIER, t.identifier("hash"))
255251
case "codeSlice":
256252
return generateCodeSlice(arg)
257253
case "refCodeSlice":

src/generator/instructions.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ export type arg =
77
| plduzArg
88
| tinyInt
99
| largeInt
10-
| runvmArg
11-
| hash
1210
| minusOne
1311
| s1
1412
| setcpArg
@@ -62,12 +60,6 @@ export const s1: s1 = {$: "s1"}
6260
export type minusOne = {$: "minusOne"}
6361
export const minusOne: minusOne = {$: "minusOne"}
6462

65-
export type runvmArg = {$: "runvmArg"}
66-
export const runvmArg: runvmArg = {$: "runvmArg"}
67-
68-
export type hash = {$: "hash"}
69-
export const hash: hash = {$: "hash"}
70-
7163
// special case: [-15, 239]
7264
export type setcpArg = {$: "setcpArg", range: range}
7365
export const setcpArg: setcpArg = {$: "setcpArg", range: range(-15n, 239n)}
@@ -374,6 +366,7 @@ const uint7 = uint(7, uint7range)
374366
const uint8 = uint(8, uint8range)
375367
const uint11 = uint(11, uint11range)
376368
const uint14 = uint(14, uint14range)
369+
const hash = uint(8, {min: 0n, max: 4n})
377370

378371
export const instructions: Record<string, Opcode> = {
379372
PUSHNAN: cat("int_const", mksimple(0x83ff, 16, `exec_push_nan`)),
@@ -1177,7 +1170,7 @@ export const instructions: Record<string, Opcode> = {
11771170
SAVEALTCTR: cat("continuation_change", mkfixedrangen(0xedb0, 0xedb8, 16, 4, seq(control), `exec_savealt_ctr`)),
11781171
SAVEBOTHCTR: cat("continuation_change", mkfixedrangen(0xedc0, 0xedc8, 16, 4, seq(control), `exec_saveboth_ctr`)),
11791172

1180-
RUNVM: version(4, cat("continuation_jump", mkfixedn(0xdb4, 12, 12, seq(runvmArg), `exec_runvm`))),
1173+
RUNVM: version(4, cat("continuation_jump", mkfixedn(0xdb4, 12, 12, seq(uint(12, {min: 0n, max: 511n})), `exec_runvm`))),
11811174

11821175
// special case: numeric
11831176
"2SWAP": cat("stack", mksimple(0x5a, 8, `exec_2swap`)),

src/runtime/constructors.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6937,44 +6937,44 @@ export type LSHIFT_DIVMODC = {
69376937
arg0: number
69386938
loc: $.Loc | undefined
69396939
}
6940-
export const HASHEXT = (arg0: $.Hash, loc?: $.Loc): HASHEXT => ({
6940+
export const HASHEXT = (arg0: number, loc?: $.Loc): HASHEXT => ({
69416941
$: "HASHEXT",
69426942
arg0,
69436943
loc,
69446944
})
69456945
export type HASHEXT = {
69466946
$: "HASHEXT"
6947-
arg0: $.Hash
6947+
arg0: number
69486948
loc: $.Loc | undefined
69496949
}
6950-
export const HASHEXTR = (arg0: $.Hash, loc?: $.Loc): HASHEXTR => ({
6950+
export const HASHEXTR = (arg0: number, loc?: $.Loc): HASHEXTR => ({
69516951
$: "HASHEXTR",
69526952
arg0,
69536953
loc,
69546954
})
69556955
export type HASHEXTR = {
69566956
$: "HASHEXTR"
6957-
arg0: $.Hash
6957+
arg0: number
69586958
loc: $.Loc | undefined
69596959
}
6960-
export const HASHEXTA = (arg0: $.Hash, loc?: $.Loc): HASHEXTA => ({
6960+
export const HASHEXTA = (arg0: number, loc?: $.Loc): HASHEXTA => ({
69616961
$: "HASHEXTA",
69626962
arg0,
69636963
loc,
69646964
})
69656965
export type HASHEXTA = {
69666966
$: "HASHEXTA"
6967-
arg0: $.Hash
6967+
arg0: number
69686968
loc: $.Loc | undefined
69696969
}
6970-
export const HASHEXTAR = (arg0: $.Hash, loc?: $.Loc): HASHEXTAR => ({
6970+
export const HASHEXTAR = (arg0: number, loc?: $.Loc): HASHEXTAR => ({
69716971
$: "HASHEXTAR",
69726972
arg0,
69736973
loc,
69746974
})
69756975
export type HASHEXTAR = {
69766976
$: "HASHEXTAR"
6977-
arg0: $.Hash
6977+
arg0: number
69786978
loc: $.Loc | undefined
69796979
}
69806980
export const STREF = (loc?: $.Loc): STREF => ({

src/runtime/types.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7181,11 +7181,11 @@ export const SAVEBOTHCTR: $.Type<c.SAVEBOTHCTR> = {
71817181
export const RUNVM: $.Type<c.RUNVM> = {
71827182
load: s => {
71837183
s.skip(12)
7184-
return c.RUNVM($.runvmArg.load(s))
7184+
return c.RUNVM($.uint(12).load(s))
71857185
},
71867186
store: (b, val, options) => {
71877187
b.storeInstructionPrefix(3508, 12, val)
7188-
$.runvmArg.store(b, val.arg0, options)
7188+
$.uint(12).store(b, val.arg0, options)
71897189
},
71907190
}
71917191
export const SWAP2: $.Type<c.SWAP2> = {
@@ -7587,41 +7587,41 @@ export const LSHIFT_DIVMODC: $.Type<c.LSHIFT_DIVMODC> = {
75877587
export const HASHEXT: $.Type<c.HASHEXT> = {
75887588
load: s => {
75897589
s.skip(16)
7590-
return c.HASHEXT($.hash.load(s))
7590+
return c.HASHEXT($.uint(8).load(s))
75917591
},
75927592
store: (b, val, options) => {
75937593
b.storeInstructionPrefix(63748, 16, val)
7594-
$.hash.store(b, val.arg0, options)
7594+
$.uint(8).store(b, val.arg0, options)
75957595
},
75967596
}
75977597
export const HASHEXTR: $.Type<c.HASHEXTR> = {
75987598
load: s => {
75997599
s.skip(16)
7600-
return c.HASHEXTR($.hash.load(s))
7600+
return c.HASHEXTR($.uint(8).load(s))
76017601
},
76027602
store: (b, val, options) => {
76037603
b.storeInstructionPrefix(63749, 16, val)
7604-
$.hash.store(b, val.arg0, options)
7604+
$.uint(8).store(b, val.arg0, options)
76057605
},
76067606
}
76077607
export const HASHEXTA: $.Type<c.HASHEXTA> = {
76087608
load: s => {
76097609
s.skip(16)
7610-
return c.HASHEXTA($.hash.load(s))
7610+
return c.HASHEXTA($.uint(8).load(s))
76117611
},
76127612
store: (b, val, options) => {
76137613
b.storeInstructionPrefix(63750, 16, val)
7614-
$.hash.store(b, val.arg0, options)
7614+
$.uint(8).store(b, val.arg0, options)
76157615
},
76167616
}
76177617
export const HASHEXTAR: $.Type<c.HASHEXTAR> = {
76187618
load: s => {
76197619
s.skip(16)
7620-
return c.HASHEXTAR($.hash.load(s))
7620+
return c.HASHEXTAR($.uint(8).load(s))
76217621
},
76227622
store: (b, val, options) => {
76237623
b.storeInstructionPrefix(63751, 16, val)
7624-
$.hash.store(b, val.arg0, options)
7624+
$.uint(8).store(b, val.arg0, options)
76257625
},
76267626
}
76277627
export const STREF: $.Type<c.STREF> = {

src/runtime/util.ts

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -449,16 +449,9 @@ export const debugstr: Type<Slice> = {
449449
},
450450
}
451451

452-
// TODO: revert
453-
export const refs = (count: number): number => {
454-
return count
455-
}
456-
457452
const uint3 = uint(3)
458453
const uint4 = uint(4)
459454
const uint5 = uint(5)
460-
const uint8 = uint(8)
461-
const uint12 = uint(12)
462455

463456
export const control: Type<number> = {
464457
store: (b, t, options) => {
@@ -511,26 +504,6 @@ export const largeInt: Type<bigint> = {
511504
load: s => s.loadIntBig(3 + ((uint5.load(s) & 31) + 2) * 8),
512505
}
513506

514-
// special case: RUNVM { ... }
515-
// +1 = same_c3 (set c3 to code)
516-
// +2 = push_0 (push an implicit 0 before running the code)
517-
// +4 = load c4 (persistent data) from stack and return its final value
518-
// +8 = load gas limit from stack and return consumed gas
519-
// +16 = load c7 (smart-contract context)
520-
// +32 = return c5 (actions)
521-
// +64 = pop hard gas limit (enabled by ACCEPT) from stack as well
522-
// +128 = isolated gas consumption (separate set of visited cells, reset chksgn counter)
523-
// +256 = pop number N, return exactly N values from stack (only if res=0 or 1; if not enough then res=stk_und)
524-
// if (mode >= 512) { throw new VmError(Excno.range_chk, "invalid flags"); }
525-
export type RunVmArg = number
526-
527-
export const runvmArg: Type<RunVmArg> = {
528-
store: (b, t, options) => {
529-
uint12.store(b, t, options)
530-
},
531-
load: s => uint12.load(s),
532-
}
533-
534507
// special case: CALLXARGS $ -1
535508
export const minusOne: Type<number> = {
536509
store: (_b, t, _options) => {
@@ -567,19 +540,6 @@ export const delta = (n: number, ty: Type<number>): Type<number> => ({
567540
load: s => ty.load(s) + n,
568541
})
569542

570-
export const hash: Type<Hash> = {
571-
store: (b, t, options) => {
572-
uint8.store(b, t, options)
573-
},
574-
load: s => {
575-
const r = uint8.load(s)
576-
if (!(r in Hash)) {
577-
throw new Error("Wrong hash")
578-
}
579-
return r
580-
},
581-
}
582-
583543
// TODO: slice
584544
export const PSEUDO_PUSHSLICE: Type<c.PSEUDO_PUSHSLICE> = {
585545
load: _s => {

0 commit comments

Comments
 (0)