@@ -15,7 +15,7 @@ the package and about types used by symbols imported by the package from
15
15
other packages. It is therefore not necessary when compiling client C of
16
16
package P to read the files of P's dependencies, only the compiled output of P.
17
17
18
- Command Line
18
+ # Command Line
19
19
20
20
Usage:
21
21
@@ -150,14 +150,21 @@ Flags to debug the compiler itself:
150
150
-w
151
151
Debug type checking.
152
152
153
- Compiler Directives
153
+ # Compiler Directives
154
154
155
155
The compiler accepts directives in the form of comments.
156
- To distinguish them from non-directive comments, directives
157
- require no space between the comment opening and the name of the directive. However, since
158
- they are comments, tools unaware of the directive convention or of a particular
156
+ Each directive must be placed its own line, with only leading spaces and tabs
157
+ allowed before the comment, and there must be no space between the comment
158
+ opening and the name of the directive, to distinguish it from a regular comment.
159
+ Tools unaware of the directive convention or of a particular
159
160
directive can skip over a directive like any other comment.
161
+
162
+ Other than the line directive, which is a historical special case;
163
+ all other compiler directives are of the form
164
+ //go:name, indicating that they are defined by the Go toolchain.
160
165
*/
166
+ // # Line Directives
167
+ //
161
168
// Line directives come in several forms:
162
169
//
163
170
// //line :line
@@ -197,12 +204,9 @@ directive can skip over a directive like any other comment.
197
204
// Line directives typically appear in machine-generated code, so that compilers and debuggers
198
205
// will report positions in the original input to the generator.
199
206
/*
200
- The line directive is a historical special case; all other directives are of the form
201
- //go:name, indicating that they are defined by the Go toolchain.
202
- Each directive must be placed its own line, with only leading spaces and tabs
203
- allowed before the comment.
204
- Each directive applies to the Go code that immediately follows it,
205
- which typically must be a declaration.
207
+ # Function Directives
208
+
209
+ A function directive applies to the Go function that immediately follows it.
206
210
207
211
//go:noescape
208
212
@@ -245,6 +249,8 @@ It specifies that the function must omit its usual stack overflow check.
245
249
This is most commonly used by low-level runtime code invoked
246
250
at times when it is unsafe for the calling goroutine to be preempted.
247
251
252
+ # Linkname Directive
253
+
248
254
//go:linkname localname [importpath.name]
249
255
250
256
The //go:linkname directive conventionally precedes the var or func
@@ -295,17 +301,34 @@ The declaration of lower.f may also have a linkname directive with a
295
301
single argument, f. This is optional, but helps alert the reader that
296
302
the function is accessed from outside the package.
297
303
304
+ # WebAssembly Directives
305
+
298
306
//go:wasmimport importmodule importname
299
307
300
308
The //go:wasmimport directive is wasm-only and must be followed by a
301
- function declaration.
309
+ function declaration with no body .
302
310
It specifies that the function is provided by a wasm module identified
303
- by ``importmodule`` and ``importname``.
311
+ by ``importmodule'' and ``importname''. For example,
304
312
305
313
//go:wasmimport a_module f
306
314
func g()
307
315
308
- The types of parameters and return values to the Go function are translated to
316
+ causes g to refer to the WebAssembly function f from module a_module.
317
+
318
+ //go:wasmexport exportname
319
+
320
+ The //go:wasmexport directive is wasm-only and must be followed by a
321
+ function definition.
322
+ It specifies that the function is exported to the wasm host as ``exportname''.
323
+ For example,
324
+
325
+ //go:wasmexport h
326
+ func hWasm() { ... }
327
+
328
+ make Go function hWasm available outside this WebAssembly module as h.
329
+
330
+ For both go:wasmimport and go:wasmexport,
331
+ the types of parameters and return values to the Go function are translated to
309
332
Wasm according to the following table:
310
333
311
334
Go types Wasm types
@@ -318,24 +341,12 @@ Wasm according to the following table:
318
341
pointer i32 (more restrictions below)
319
342
string (i32, i32) (only permitted as a parameters, not a result)
320
343
344
+ Any other parameter types are disallowed by the compiler.
345
+
321
346
For a pointer type, its element type must be a bool, int8, uint8, int16, uint16,
322
347
int32, uint32, int64, uint64, float32, float64, an array whose element type is
323
348
a permitted pointer element type, or a struct, which, if non-empty, embeds
324
- structs.HostLayout, and contains only fields whose types are permitted pointer
349
+ [ structs.HostLayout] , and contains only fields whose types are permitted pointer
325
350
element types.
326
-
327
- Any other parameter types are disallowed by the compiler.
328
-
329
- //go:wasmexport exportname
330
-
331
- The //go:wasmexport directive is wasm-only and must be followed by a
332
- function definition.
333
- It specifies that the function is exported to the wasm host as ``exportname``.
334
-
335
- //go:wasmexport f
336
- func g()
337
-
338
- The types of parameters and return values to the Go function are permitted and
339
- translated to Wasm in the same way as //go:wasmimport functions.
340
351
*/
341
352
package main
0 commit comments