v2 / vlib / wasm / functions.v
53 lines · 45 sloc · 890 bytes · c42291948116b957642ea13e147342c362685ab4
Raw
1// Copyright (c) 2023 l-m.dev. All rights reserved.
2// Use of this source code is governed by an MIT license
3// that can be found in the LICENSE file.
4module wasm
5
6struct ImportCallPatch {
7 mod string
8 name string
9mut:
10 pos int
11}
12
13struct FunctionCallPatch {
14 name string
15mut:
16 pos int
17}
18
19type CallPatch = FunctionCallPatch | ImportCallPatch
20
21struct FunctionGlobalPatch {
22 idx GlobalIndex
23mut:
24 pos int
25}
26
27type FunctionPatch = CallPatch | FunctionGlobalPatch
28
29struct FunctionLocal {
30 typ ValType
31 name ?string
32}
33
34pub struct Function {
35 tidx int
36 idx int
37mut:
38 patches []FunctionPatch // sorted
39 label int
40 export bool
41 mod &Module = unsafe { nil }
42 code []u8
43 locals []FunctionLocal
44pub:
45 name string
46pub mut:
47 export_name ?string
48}
49
50// export_name sets the export name of the function to `name`
51pub fn (mut func Function) export_name(name string) {
52 func.export_name = name
53}
54