Skip to content

Commit 06da4b7

Browse files
committed
negative offset
1 parent 113d9d8 commit 06da4b7

File tree

5 files changed

+197
-0
lines changed

5 files changed

+197
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
Module {
2+
span: Span {
3+
offset: 1,
4+
},
5+
id: None,
6+
name: None,
7+
kind: Text(
8+
[
9+
Memory(
10+
Memory {
11+
span: Span {
12+
offset: 11,
13+
},
14+
id: Some(
15+
"memory",
16+
),
17+
name: None,
18+
exports: InlineExport {
19+
names: [
20+
"memory",
21+
],
22+
},
23+
kind: Normal(
24+
B32 {
25+
limits: Limits {
26+
min: 1,
27+
max: None,
28+
},
29+
shared: false,
30+
},
31+
),
32+
},
33+
),
34+
Func(
35+
Func {
36+
span: Span {
37+
offset: 51,
38+
},
39+
id: Some(
40+
"entry",
41+
),
42+
name: None,
43+
exports: InlineExport {
44+
names: [
45+
"entry",
46+
],
47+
},
48+
kind: Inline {
49+
locals: [],
50+
expression: Expression {
51+
instrs: [
52+
I32Const(
53+
0,
54+
),
55+
LocalGet(
56+
Id(
57+
"value",
58+
),
59+
),
60+
I32Store(
61+
MemArg {
62+
align: 4,
63+
offset: 20,
64+
memory: Num(
65+
0,
66+
Span {
67+
offset: 162,
68+
},
69+
),
70+
},
71+
),
72+
I32Const(
73+
0,
74+
),
75+
I32Load(
76+
MemArg {
77+
align: 4,
78+
offset: 20,
79+
memory: Num(
80+
0,
81+
Span {
82+
offset: 202,
83+
},
84+
),
85+
},
86+
),
87+
],
88+
},
89+
},
90+
ty: TypeUse {
91+
index: None,
92+
inline: Some(
93+
FunctionType {
94+
params: [
95+
(
96+
Some(
97+
"value",
98+
),
99+
None,
100+
I32,
101+
),
102+
],
103+
results: [
104+
I32,
105+
],
106+
},
107+
),
108+
},
109+
},
110+
),
111+
],
112+
),
113+
}
114+
115+
116+
117+
118+
{
119+
"I32Const": 2,
120+
"LocalGet": 1,
121+
"I32Store": 1,
122+
"I32Load": 1,
123+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { Expect, Equal } from 'type-testing';
2+
import type { entry } from "./memory-offset-negative"
3+
4+
import { getWasm } from '../utils'
5+
import { expect, test } from 'vitest';
6+
7+
const name = 'memory-offset-negative';
8+
test(name, async () => {
9+
const entry = await getWasm("from-wat", name);
10+
expect(entry(-2)).toStrictEqual(-2);
11+
expect(entry(-1)).toStrictEqual(-1);
12+
expect(entry( 0)).toStrictEqual( 0);
13+
expect(entry( 1)).toStrictEqual( 1);
14+
expect(entry( 2)).toStrictEqual( 2);
15+
});
16+
17+
type testCases = [
18+
Expect<Equal<entry<[-2]>, -2>>,
19+
Expect<Equal<entry<[-1]>, -1>>,
20+
Expect<Equal<entry<[0]>, 0>>,
21+
Expect<Equal<entry<[1]>, 1>>,
22+
Expect<Equal<entry<[2]>, 2>>,
23+
// Expect<Equal<entry<[-1, -100, 10]>, -89>>,
24+
// Expect<Equal<entry<[-1, -2, -3]>, -4>>,
25+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import type { Func, bootstrap } from 'wasm-to-typescript-types'
2+
3+
type $entry = Satisfies<Func, {
4+
kind: 'func';
5+
params: ['$value'];
6+
paramsTypes: ['i32'];
7+
resultTypes: ['i32'];
8+
locals: [];
9+
instructions: [
10+
{ kind: 'Const'; value: '00000000000000000000000000000000' },
11+
{ kind: 'LocalGet'; id: '$value' },
12+
{ kind: 'Store'; subkind: 'I32Store'; offset: '00000000000000000000000000010100' },
13+
{ kind: 'Const'; value: '00000000000000000000000000000000' },
14+
{ kind: 'Load'; subkind: 'I32Load'; offset: '00000000000000000000000000010100' },
15+
];
16+
}>
17+
18+
export type funcs = {
19+
$entry: $entry;
20+
}
21+
22+
export type entry<
23+
arguments extends [number],
24+
debugMode extends boolean = false,
25+
stopAt extends number = number,
26+
> = bootstrap<
27+
{
28+
arguments: arguments;
29+
funcs: funcs;
30+
globals: {};
31+
memory: {};
32+
memorySize: '00000000000000000000000000000001';
33+
indirect: {};
34+
},
35+
debugMode,
36+
stopAt
37+
>
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(module
2+
(memory $memory (export "memory") 1)
3+
4+
(func $entry (export "entry") (param $value i32) (result i32)
5+
i32.const -1
6+
local.get $value
7+
i32.store offset=20
8+
9+
i32.const -1
10+
i32.load offset=20
11+
)
12+
)

0 commit comments

Comments
 (0)