diff options
| author | Luke Wagner <mail@lukewagner.name> | 2015-05-07 11:06:54 -0500 |
|---|---|---|
| committer | Luke Wagner <mail@lukewagner.name> | 2015-05-07 11:06:54 -0500 |
| commit | 78ea0caaa46abc6613881a1e4c0dcfbc8d9d91c8 (patch) | |
| tree | e8c6be66362fbd42a00ae8a9771b19787422c99d | |
| parent | bf5ab6a5af023d40adb57a4780d19ec8e1280658 (diff) | |
| parent | 2aea11463d41cc0bfe4c7b6d7c3b9b6546c36b14 (diff) | |
| download | nanowasm-design-78ea0caaa46abc6613881a1e4c0dcfbc8d9d91c8.tar.gz | |
Merge pull request #31 from WebAssembly/update-function-pointers
Move and merge 'Function pointers' section from V1.md into AstSematics.md
| -rw-r--r-- | AstSemantics.md | 41 | ||||
| -rw-r--r-- | V1.md | 11 |
2 files changed, 27 insertions, 25 deletions
diff --git a/AstSemantics.md b/AstSemantics.md index f6e28ee..dc54bc0 100644 --- a/AstSemantics.md +++ b/AstSemantics.md @@ -102,24 +102,37 @@ all global accesses can be considered "non-atomic". ## Calls -Calls to functions can be direction (by index), or indirect. Each function -has a signature in terms of local types, and calls must match the function -signature exactly. Multiple return value calls will be possible. - -The details of indirect calls need clarification. +Direct calls to a function specify the callee by index into a function table. * CallDirect - call function directly - * CallIndirect - call function indirectly -The details of multiple-return-value calls needs clarification. -Calling a function that returns multiple values will likely have to be a -statement that specifies multiple local variables to which to assign the -corresponding return values. +Each function has a signature in terms of local types, and calls must match the +function signature exactly. [Imported functions](V1.md#code-loading-and-imports) +also have signatures and are added to the same function table and are thus also +callable via `CallDirect`. -Calls to external (stdlib) functions can be expressed as direct calls to -an "external" function in the function table. The linking of that function -will be specified through the module system. A call to an unlinked function -should be a runtime error. +Indirect calls may be made to a value of function-pointer type. A function- +pointer value may be obtained for a given function as specified by its index +in the function table. + + * CallIndirect - call function indirectly + * AddressOf - obtain a function pointer value for a given function + +Function-pointer values are comparable for equality and the `AddressOf` operator +is monomorphic. Function-pointer values can be explicitly coerced to and from +integers (which, in particular, is necessary when loading/storing to the heap +since the heap only provides integer types). For security and safety reasons, +the integer value of a coerced function-pointer value is an abstract index and +does not reveal the actual machine code address of the target function. + +In v.1 function pointer values are +local to a single module. The [dynamic linking](FutureFeatures.md#dynamic-linking) +feature is necessary for two modules to pass function pointers back and forth. + +Multiple return value calls will be possible, though possibly not in v.1. The +details of multiple-return-value calls needs clarification. Calling a function +that returns multiple values will likely have to be a statement that specifies +multiple local variables to which to assign the corresponding return values. ## Literals @@ -110,17 +110,6 @@ precise descriptions of: but when aliased by JS, it appears as a regular ArrayBuffer. * To keep an ArrayBuffer's length immutable, resizing a module's heap detaches any existant ArrayBuffers. -## Function pointers - * In v.1, function pointers are local to a single module. - * The [dynamic linking](FutureFeatures.md#dynamic-linking) feature will be necessary for two modules - to pass function pointers back and forth. - * Function pointers have a unique type per signature that is coercible to and from an int32. - * The heap can only load/store integer types, so a coercion is required when loading/storing - function pointers to the heap. - * Values of function pointer types are comparable for equality and callable. - * Function pointer values are created via special `AddressOf` ops that take a function's index - and return a function pointer value unique to the function index. - ## Non-browser embedding * Host environments can define builtin modules that are implemented natively and thus be imported directly by WebAssembly modules. |
