diff --git a/.gitignore b/.gitignore index 99dcfcf7..6739bb2b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ **/*~ **/*.tmproj -_build +**/*.pyc +**/_build +**/_output diff --git a/.travis.yml b/.travis.yml index 8df6e941..adcc169b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,30 @@ language: c++ +language: python +python: + - "2.7" -sudo: off +sudo: on -install: ./interpreter/travis/install-ocaml.sh +before_install: + - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - + - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list + - sudo apt-get update -qq -script: ./interpreter/travis/build-test.sh +install: + - ./interpreter/meta/travis/install-ocaml.sh + - sudo pip install sphinx==1.7.9 + - sudo apt-get install texlive-full yarn + - git clone https://github.com/tabatkins/bikeshed.git + - pip install --editable $PWD/bikeshed + - bikeshed update -os: - - linux - - osx +script: + - ./interpreter/meta/travis/build-test.sh + - bash ./document/travis-deploy.sh + +os: linux + +env: + global: + - ENCRYPTION_LABEL: "5d9ec396f41d" + - COMMIT_AUTHOR_EMAIL: "noreply@webassembly.org" diff --git a/LICENSE b/LICENSE index 8f71f43f..de2cac69 100644 --- a/LICENSE +++ b/LICENSE @@ -1,202 +1,8 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ +Please see the LICENSE file in each top-level directory for the terms applicable to that directory and its relative sub-directories. - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +The relevant directories and licenses are: +document/ - W3C Software and Document Notice and License +interpreter/ - Apache License 2.0 +test/ - Apache License 2.0 +papers/ - Creative Commons Attribution 4.0 International License diff --git a/README.md b/README.md index a987ee7c..5f17800d 100644 --- a/README.md +++ b/README.md @@ -7,14 +7,26 @@ holds a [proposal](https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md) for adding exception handling to WebAssembly. -The repository is a copy -of [WebAssembly/spec](https://github.com/WebAssembly/spec). +The repository is a clone +of [WebAssembly/spec](https://github.com/WebAssembly/spec), and is rebased on the spec of its dependent proposal [WebAssembly/reference-types](https://github.com/WebAssembly/reference-types). -The remainder of the document is contents of the -original [README.md](https://github.com/WebAssembly/spec/blob/master/README.md) +The remainder of the document is contents of the [README.md](https://github.com/WebAssembly/reference-types/blob/master/README.md) document of that repository. -## spec +# Reference Types Proposal for WebAssembly + +[](https://travis-ci.org/WebAssembly/reference-types) + +This repository is a clone of [github.com/WebAssembly/spec/](https://github.com/WebAssembly/spec/). +It is meant for discussion, prototype specification and implementation of a proposal to add support for basic reference types to WebAssembly. + +* See the [overview](proposals/reference-types/Overview.md) for a summary of the proposal. + +* See the [modified spec](https://webassembly.github.io/reference-types/core/) for details. + +Original `README` from upstream repository follows... + +# spec This repository holds a prototypical reference implementation for WebAssembly, which is currently serving as the official specification. Eventually, we expect diff --git a/document/js-api/index.bs b/document/js-api/index.bs index c72be764..87598c6f 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -6,7 +6,7 @@ Status: ED Level: 1 TR: https://www.w3.org/TR/wasm-js-api-1/ ED: https://webassembly.github.io/spec/js-api/ -Editor: Daniel Ehrenberg (Igalia) +Editor: Ms2ger (Igalia) Repository: WebAssembly/spec Markup Shorthands: css no, markdown yes Abstract: This document provides an explicit JavaScript API for interacting with WebAssembly. @@ -85,7 +85,10 @@ urlPrefix: https://tc39.github.io/ecma262/; spec: ECMASCRIPT text: the Number value; url: sec-ecmascript-language-types-number-type text: NumberToRawBytes; url: sec-numbertorawbytes text: Built-in Function Objects; url: sec-built-in-function-objects -urlPrefix: https://webassembly.github.io/reference-types/core/; spec: WebAssembly; type: dfn + text: NativeError Object Structure; url: sec-nativeerror-object-structure + type: abstract-op + text: CreateMethodProperty; url: sec-createmethodproperty +urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: dfn url: valid/modules.html#valid-module text: valid text: WebAssembly module validation @@ -149,6 +152,7 @@ urlPrefix: https://webassembly.github.io/reference-types/core/; spec: WebAssembl url: syntax/types.html#syntax-reftype text: anyref text: funcref + text: nullref text: function element; url: exec/runtime.html#syntax-funcelem text: import component; url: syntax/modules.html#imports text: external value; url: exec/runtime.html#syntax-externval @@ -174,6 +178,9 @@ urlPrefix: https://webassembly.github.io/reference-types/core/; spec: WebAssembl text: 𝗆𝗈𝖽𝗎𝗅𝖾; url: exec/runtime.html#syntax-frame text: 𝗆𝖾𝗆𝖺𝖽𝖽𝗋𝗌; url: exec/runtime.html#syntax-moduleinst text: sequence; url: syntax/conventions.html#grammar-notation +urlPrefix: https://heycam.github.io/webidl/; spec: WebIDL + type: dfn + text: create a namespace object; url: create-a-namespace-object
@@ -183,9 +190,15 @@ spec:infra; type:dfn; for:set; text:append spec:ecmascript; type:exception; for:ECMAScript; text:TypeError spec:ecmascript; type:exception; for:ECMAScript; text:RangeError spec:ecmascript; type:interface; for:ECMAScript; text:ArrayBuffer -spec:promises-guide-1; type:dfn; text:resolve +spec:webidl; type:dfn; text:resolve+ + This API privides a way to access WebAssembly [[WEBASSEMBLY]] through a bridge to explicitly construct modules from JavaScript [[ECMASCRIPT]].
enum TableKind { + "nullref", "anyref", "anyfunc", // Note: More values may be added in future iterations, @@ -856,6 +870,10 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each 1. If |s| equals "i64", return [=𝗂𝟨𝟦=]. 1. If |s| equals "f32", return [=𝖿𝟥𝟤=]. 1. If |s| equals "f64", return [=𝖿𝟨𝟦=]. + 1. If |s| equals "anyref", return [=anyref=]. + 1. If |s| equals "funcref", return [=funcref=]. + 1. If |s| equals "nullref", return [=nullref=]. + 1. Assert: This step is not reached.@@ -864,7 +882,7 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each 1. If |valuetype| equals [=𝗂𝟨𝟦=], return [=𝗂𝟨𝟦.𝖼𝗈𝗇𝗌𝗍=] 0. 1. If |valuetype| equals [=𝖿𝟥𝟤=], return [=𝖿𝟥𝟤.𝖼𝗈𝗇𝗌𝗍=] 0. 1. If |valuetype| equals [=𝖿𝟨𝟦=], return [=𝖿𝟨𝟦.𝖼𝗈𝗇𝗌𝗍=] 0. - 1. Assert: This step is not reached. + 1. Else, return [=ref.null=].@@ -986,12 +1004,11 @@ Note: [=call an Exported Function|Calling an Exported Function=] executes in the Note: Exported Functions do not have a \[[Construct]] method and thus it is not possible to call one with the `new` operator.- To run a host function from the JavaScript object |func| and type |functype|, perform the following steps: + To run a host function from the JavaScript object |func|, type |functype|, and [=list=] of [=WebAssembly values=] |arguments|, perform the following steps: 1. Let [|parameters|] → [|results|] be |functype|. 1. Assert: |results|'s [=list/size=] is at most one. 1. If either |parameters| or |results| contains [=𝗂𝟨𝟦=], throw a {{TypeError}}. - 1. Let |arguments| be a [=list=] of the arguments of the invocation of this function. 1. Let |jsArguments| be an empty [=list=]. 1. For each |arg| in |arguments|, 1. [=list/Append=] ! [=ToJSValue=](|arg|) to |jsArguments|. @@ -1003,15 +1020,16 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is notTo create a host function from the JavaScript object |func| and type |functype|, perform the following steps: - 1. Let |hostfunc| be a [=host function=] which performs the following steps when called: - 1. Let |result| be the result of [=run a host function|running a host function=] from |func| and |functype|. - 1. Assert: |result|.\[[Type]] is throw or return. - 1. If |result|.\[[Type]] is [=throw=], then trigger a WebAssembly trap, and propagate |result|.\[[Value]] to the enclosing JavaScript. + 1. Assert: [=IsCallable=](|func|). + 1. Let |hostfunc| be a [=host function=] which performs the following steps when called with arguments |arguments|: + 1. Let |result| be the result of [=run a host function|running a host function=] from |func|, |functype|, and |arguments|. + 1. Assert: |result|.\[[Type]] isthrow orreturn . + 1. If |result|.\[[Type]] isthrow , then trigger a WebAssembly trap, and propagate |result|.\[[Value]] to the enclosing JavaScript. 1. Otherwise, return |result|.\[[Value]]. 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. 1. Let (|store|, |funcaddr|) be [=func_alloc=](|store|, |functype|, |hostfunc|). 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. - 1. Return |funcaddr| + 1. Return |funcaddr|.@@ -1051,11 +1069,14 @@ The algorithm ToWebAssemblyValue(|v|, |type|, |error|) coerces a Java 1. If |type| is [=𝖿𝟨𝟦=], 1. Let |f64| be ? [=ToNumber=](|v|). 1. Return [=𝖿𝟨𝟦.𝖼𝗈𝗇𝗌𝗍=] |f64|. +1. Assert: |type| is a reference type. 1. If |type| is [=anyref=], - 1. Return the result of [=allocating a host address=] for |v|. + 1. Do nothing. 1. If |type| is [=funcref=], 1. If |v| is not an [=Exported function=] or null, throw |error|. - 1. Return the result of [=allocating a host address=] for |v|. +1. If |type| is [=nullref=], + 1. If |v| is not null, throw |error|. +1. Return the result of [=allocating a host address=] for |v|.@@ -1077,21 +1098,23 @@ The algorithm ToWebAssemblyValue(|v|, |type|, |error|) coerces a JavaError Objects
-WebAssembly defines the following Error classes: {{CompileError}}, {{LinkError}}, and {{RuntimeError}}. WebAssembly errors have the following custom bindings: -- Unlike normal interface types, the interface prototype object for these exception classes must have as its \[[Prototype]] the intrinsic object [=%ErrorPrototype%=]. -- The constructor and properties of WebAssembly errors is as specified for {{NativeError}}. -- If an implementation gives native Error objects special powers or nonstandard properties (such as a stack property), it should also expose those on these exception instances. +WebAssembly defines the following Error classes: CompileError, LinkError, and RuntimeError. --[LegacyNamespace=WebAssembly] -interface CompileError { }; ++When the [=namespace object=] for the {{WebAssembly}} namespace is [=create a namespace object|created=], the following steps must be run: -[LegacyNamespace=WebAssembly] -interface LinkError { }; +1. Let |namespaceObject| the [=namespace object=]. +1. [=list/iterate|For each=] |error| of « "CompileError", "LinkError", "RuntimeError" », + 1. Let |constructor| be a new object, implementing the [=NativeError Object Structure=], with NativeError set to |error|. + 1. ! [$CreateMethodProperty$](|namespaceObject|, |error|, |constructor|). + ++ +Note: This defines {{CompileError}}, {{LinkError}}, and {{RuntimeError}} classes on the {{WebAssembly}} namespace, which are produced by the APIs defined in this specification. +They expose the same interface as native JavaScript errors like {{TypeError}} and {{RangeError}}. + +Note: It is not currently possible to define this behavior using Web IDL. -[LegacyNamespace=WebAssembly] -interface RuntimeError { }; -Error Condition Mappings to JavaScript
diff --git a/interpreter/.gitignore b/interpreter/.gitignore index 6c3de62c..0a02ff70 100644 --- a/interpreter/.gitignore +++ b/interpreter/.gitignore @@ -9,4 +9,5 @@ *.mlpack _build wasm +wasm.debug diff --git a/interpreter/LICENSE b/interpreter/LICENSE new file mode 100644 index 00000000..8f71f43f --- /dev/null +++ b/interpreter/LICENSE @@ -0,0 +1,202 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/interpreter/Makefile b/interpreter/Makefile index 4aab9150..629018a6 100644 --- a/interpreter/Makefile +++ b/interpreter/Makefile @@ -10,51 +10,66 @@ # Configuration NAME = wasm -UNOPT = $(NAME) -OPT = $(NAME).opt +UNOPT = $(NAME).debug +OPT = $(NAME) LIB = $(NAME) ZIP = $(NAME).zip JSLIB = wast.js WINMAKE = winmake.bat -DIRS = util spec text host host/import +DIRS = util syntax binary text valid runtime exec script host main LIBS = bigarray -FLAGS = -cflags '-w +a-4-27-42-44-45 -warn-error +a' +FLAGS = -cflags '-w +a-3-4-27-42-44-45 -warn-error +a' OCB = ocamlbuild $(FLAGS) $(DIRS:%=-I %) $(LIBS:%=-libs %) JS = # set to JS shell command to run JS tests # Main targets -.PHONY: unopt opt libunopt libopt all land zip +.PHONY: default opt unopt libopt libunopt jslib all land zip -unopt: $(UNOPT) +default: opt +debug: unopt opt: $(OPT) -libunopt: _build/$(LIB).cmo +unopt: $(UNOPT) libopt: _build/$(LIB).cmx +libunopt: _build/$(LIB).cmo +jslib: $(JSLIB) all: unopt opt libunopt libopt test -land: all $(WINMAKE) +land: $(WINMAKE) all zip: $(ZIP) # Building executable -$(UNOPT): main.d.byte +empty = +space = $(empty) $(empty) +comma = , + +.INTERMEDIATE: _tags +_tags: + echo >$@ "true: bin_annot" + echo >>$@ "true: debug" + echo >>$@ "<{$(subst $(space),$(comma),$(DIRS))}/*.cmx>: for-pack($(PACK))" + +$(UNOPT): main.byte mv $< $@ $(OPT): main.native mv $< $@ -.PHONY: main.d.byte main.native -main.d.byte: +.PHONY: main.byte main.native +main.byte: _tags $(OCB) -quiet $@ -main.native: +main.native: _tags $(OCB) -quiet $@ # Building library +PACK = $(shell echo `echo $(LIB) | sed 's/^\(.\).*$$/\\1/g' | tr [:lower:] [:upper:]``echo $(LIB) | sed 's/^.\(.*\)$$/\\1/g'`) + .INTERMEDIATE: $(LIB).mlpack $(LIB).mlpack: $(DIRS) ls $(DIRS:%=%/*.ml*) \ @@ -63,10 +78,10 @@ $(LIB).mlpack: $(DIRS) | sort | uniq \ >$@ -_build/$(LIB).cmo: $(LIB).mlpack +_build/$(LIB).cmo: $(LIB).mlpack _tags $(OCB) -quiet $(LIB).cmo -_build/$(LIB).cmx: $(LIB).mlpack +_build/$(LIB).cmx: $(LIB).mlpack _tags $(OCB) -quiet $(LIB).cmx @@ -75,8 +90,8 @@ _build/$(LIB).cmx: $(LIB).mlpack .PHONY: $(JSLIB) $(JSLIB): $(UNOPT) mkdir -p _build/jslib/src - cp jslib/* _build/jslib - cp $(DIRS:%=_build/%/*.ml*) jslib/*.ml _build/jslib/src + cp meta/jslib/* _build/jslib + cp $(DIRS:%=_build/%/*.ml*) meta/jslib/*.ml _build/jslib/src rm _build/jslib/src/*.ml[^i] (cd _build/jslib; ./build.sh ../../$@) @@ -87,32 +102,43 @@ $(WINMAKE): clean echo rem Auto-generated from Makefile! >$@ echo set NAME=$(NAME) >>$@ echo if \'%1\' neq \'\' set NAME=%1 >>$@ - $(OCB) main.d.byte \ + $(OCB) main.byte \ | grep -v ocamldep \ | grep -v mkdir \ | sed s:`which ocaml`:ocaml:g \ - | sed s:host/main.d.byte:%NAME%.exe: \ + | sed s:main/main.d.byte:%NAME%.exe: \ >>$@ -# Miscellaneous targets +# Executing test suite -.PHONY: test clean +.PHONY: test debugtest -$(ZIP): $(WINMAKE) - git archive --format=zip --prefix=$(NAME)/ -o $@ HEAD +test: $(OPT) + ../test/core/run.py --wasm `pwd`/$(OPT) $(if $(JS),--js '$(JS)',) +debugtest: $(UNOPT) + ../test/core/run.py --wasm `pwd`/$(UNOPT) $(if $(JS),--js '$(JS)',) + +test/%: $(OPT) + ../test/core/run.py --wasm `pwd`/$(OPT) $(if $(JS),--js '$(JS)',) $(@:test/%=../test/core/%.wast) +debugtest/%: $(UNOPT) + ../test/core/run.py --wasm `pwd`/$(UNOPT) $(if $(JS),--js '$(JS)',) $(@:debugtest/%=../test/core/%.wast) + +run/%: $(OPT) + ./$(OPT) $(@:run/%=../test/core/%.wast) +debug/%: $(UNOPT) + ./$(UNOPT) $(@:debug/%=../test/core/%.wast) -test: $(NAME) - ../test/core/run.py --wasm `pwd`/$(NAME) $(if $(JS),--js '$(JS)',) -test/%: $(NAME) - ../test/core/run.py --wasm `pwd`/$(NAME) $(if $(JS),--js '$(JS)',) $(@:test/%=../test/core/%.wast) +# Miscellaneous targets + +.PHONY: clean -run/%: $(NAME) - ./$(NAME) $(@:run/%=../test/core/%.wast) +$(ZIP): $(WINMAKE) + git archive --format=zip --prefix=$(NAME)/ -o $@ HEAD clean: - rm -rf _build/jslib + rm -rf _build/jslib $(LIB).mlpack _tags $(OCB) -clean @@ -126,9 +152,9 @@ check: ocamlfind query $(LIBS) install: _build/$(LIB).cmx _build/$(LIB).cmo - ocamlfind install wasm findlib/META _build/wasm.o \ + ocamlfind install $(LIB) meta/findlib/META _build/$(LIB).o \ $(wildcard _build/$(LIB).cm*) \ $(wildcard $(DIRS:%=%/*.mli)) uninstall: - ocamlfind remove wasm + ocamlfind remove $(LIB) diff --git a/interpreter/README.md b/interpreter/README.md index c0b42b77..77c6a543 100644 --- a/interpreter/README.md +++ b/interpreter/README.md @@ -1,6 +1,6 @@ -# WebAssembly Interpreter +# WebAssembly Reference Interpreter -This repository implements a reference interpreter for WebAssembly. It is written for clarity and simplicity, _not_ speed. It is intended as a playground for trying out ideas and a device for nailing down the exact semantics, and as a proxy for the (yet to be produced) formal specification of WebAssembly. For that purpose, the code is written in a fairly declarative, "speccy" way. +This repository implements a interpreter for WebAssembly. It is written for clarity and simplicity, _not_ speed. It is intended as a playground for trying out ideas and a device for nailing down the exact semantics, and as a proxy for the (yet to be produced) formal specification of WebAssembly. For that purpose, the code is written in a fairly declarative, "speccy" way. The interpreter can @@ -58,7 +58,7 @@ Either way, in order to run the test suite you'll need to have Python installed. #### Cross-compiling the Interpreter to JavaScript #### -The Makefile also provides a target to compile (parts of) the interpreter into a (Javacript library)[javascript-library]: +The Makefile also provides a target to compile (parts of) the interpreter into a [JavaScript library](#javascript-library): ``` make wast.js ``` @@ -75,7 +75,7 @@ You can call the executable with wasm [option | file ...] ``` -where `file`, depending on its extension, either should be an S-expression script file (see below) to be run, or a binary module file to be loaded. +where `file`, depending on its extension, either should be a binary (`.wasm`) or textual (`.wat`) module file to be loaded, or a script file (`.wast`, see below) to be run. By default, the interpreter validates all modules. The `-u` option selects "unchecked mode", which skips validation and runs code as is. @@ -86,8 +86,8 @@ Runtime type errors will be captured and reported appropriately. A file prefixed by `-o` is taken to be an output file. Depending on its extension, this will write out the preceding module definition in either S-expression or binary format. This option can be used to convert between the two in both directions, e.g.: ``` -wasm -d module.wast -o module.wasm -wasm -d module.wasm -o module.wast +wasm -d module.wat -o module.wasm +wasm -d module.wasm -o module.wat ``` In the second case, the produced script contains exactly one module definition. @@ -107,7 +107,6 @@ The first creates a new test scripts where all embedded modules are converted to The last invocation produces an equivalent, self-contained JavaScript test file. The flag `-h` can be used to omit the test harness from the converted file; it then is the client's responsibility to provide versions of the necessary functions. -By default, the generated script will not require `assert_soft_invalid` (see below) to detect validation failures. Use the `-c` flag ("checked hard") to activate these assertions for full validity checks. #### Command Line Expressions @@ -119,10 +118,10 @@ wasm module.wasm -e '(invoke "foo")' #### Interactive Mode -If neither a file nor any of the previous options is given, you'll land in the REPL and can enter script commands interactively. You can also get into the REPL by explicitly passing `-` as a file name. You can do that in combination to giving a module file, so that you can then invoke its exports interactively, e.g.: +If neither a file nor any of the previous options is given, you'll land in the REPL and can enter script commands interactively. You can also get into the REPL by explicitly passing `-` as a file name. You can do that in combination to giving a module or script file, so that you can then invoke its exports interactively, e.g.: ``` -wasm module.wast - +wasm module.wat - ``` See `wasm -h` for (the few) additional options. @@ -130,7 +129,7 @@ See `wasm -h` for (the few) additional options. #### JavaScript Library #### -The file `wast.js` generated by the respective (Makefile target)[cross-compiling-the-interpreter-to-javascript] is a self-contained JavaScript library for making the [S-expression syntax](s-expression-syntax) available directly within JavaScript. +The file `wast.js` generated by the respective [Makefile target](#cross-compiling-the-interpreter-to-javascript) is a self-contained JavaScript library for making the [S-expression syntax](#s-expression-syntax) available directly within JavaScript. It provides a global object named `WebAssemblyText` that currently provides two methods, ``` WebAssemblyText.encode(source) @@ -143,7 +142,7 @@ which pretty-prints a binary back into a canonicalised S-expression string. For example: ``` -let source = '(module (func (export "f") (param i32 i32) (result i32) (i32.add (get_local 0) (get_local 1))))' +let source = '(module (func (export "f") (param i32 i32) (result i32) (i32.add (local.get 0) (local.get 1))))' let binary = WebAssemblyText.encode(source) (new WebAssembly.Instance(new WebAssembly.Module(binary))).exports.f(3, 4) @@ -153,7 +152,7 @@ WebAssemblyText.decode(binary) // => // (module // (type $0 (func (param i32 i32) (result i32))) -// (func $0 (type 0) (get_local 0) (get_local 1) (i32.add)) +// (func $0 (type 0) (local.get 0) (local.get 1) (i32.add)) // (export "f" (func 0)) // ) ``` @@ -161,47 +160,53 @@ WebAssemblyText.decode(binary) ## S-Expression Syntax -The implementation consumes a WebAssembly AST given in S-expression syntax. Here is an overview of the grammar of types, expressions, functions, and modules, mirroring what's described in the [design doc](https://github.com/WebAssembly/design/blob/master/Semantics.md): +The implementation consumes a WebAssembly AST given in S-expression syntax. Here is an overview of the grammar of types, expressions, functions, and modules, mirroring what's described in the [design doc](https://github.com/WebAssembly/design/blob/master/Semantics.md). +Note: The grammar is shown here for convenience, the definite source is the [specification of the text format](https://webassembly.github.io/spec/core/text/). ``` -value:| -var: | -name: $( | | _ | . | + | - | * | / | \ | ^ | ~ | = | < | > | ! | ? | @ | # | $ | % | & | | | : | ' | `)+ -string: "( | \n | \t | \\ | \' | \" | \ )*" +num: (_? )* +hexnum: (_? )* +nat: | 0x +int: | + | - +float: . ?(e|E )? | 0x . ?(p|P )? +name: $( | | _ | . | + | - | * | / | \ | ^ | ~ | = | < | > | ! | ? | @ | # | $ | % | & | | | : | ' | `)+ +string: "( | \n | \t | \\ | \' | \" | \ | \u{ +})*" -type: i32 | i64 | f32 | f64 -elem_type: anyfunc +num: | +var: | unop: ctz | clz | popcnt | ... binop: add | sub | mul | ... relop: eq | ne | lt | ... -sign: s|u +sign: s|u offset: offset= align: align=(1|2|4|8|...) -cvtop: trunc_s | trunc_u | extend_s | extend_u | ... +cvtop: trunc | extend | wrap | ... -block_sig : * -func_sig: ( type )? * * -global_sig: | ( mut ) -table_sig: ? -memory_sig: ? +num_type: i32 | i64 | f32 | f64 +ref_type: anyref | funcref | nullref +val_type: num_type | ref_type +block_type : ( result * )* +func_type: ( type )? * * +global_type: | ( mut ) +table_type: ? +memory_type: ? expr: ( ) ( + ) ;; = + ( ) - ( block ? ? * ) - ( loop ? ? * ) - ( if ? ? ( then * ) ( else * )? ) - ( if ? ? ( then * ) ( else * )? ) ;; = (if ? ? (then *) (else *)?) - ( if ? ? ? ) ;; = (if ? ? (then ) (else ?)) + ( block ? * ) + ( loop ? * ) + ( if ? ( then * ) ( else * )? ) + ( if ? + ( then * ) ( else * )? ) ;; = + (if ? (then *) (else *)?) instr: ;; = ( ) - block ? ? * end ? ;; = (block ? ? *) - loop ? ? * end ? ;; = (loop ? ? *) - if ? ? * end ? ;; = (if ? ? (then *)) - if ? ? * else ? * end ? ;; = (if ? ? (then *) (else *)) + block ? * end ? ;; = (block ? *) + loop ? * end ? ;; = (loop ? *) + if ? * end ? ;; = (if ? (then *)) + if ? * else ? * end ? ;; = (if ? (then *) (else *)) op: unreachable @@ -211,65 +216,74 @@ op: br_table + return call - call_indirect + call_indirect drop select - get_local - set_local - tee_local - get_global - set_global - .load((8|16|32)_ )? ? ? - .store(8|16|32)? ? ? - current_memory - grow_memory - .const - . - . - . - . - . / - -func: ( func ? * * ) - ( func ? ( export ) * * ) ;; = (export (func )) (func ? * *) - ( func ? ( import ) ) ;; = (import ? (func )) -param: ( param * ) | ( param ) -result: ( result ) -local: ( local * ) | ( local ) - -global: ( global ? * ) - ( global ? ( export ) * ) ;; = (export (global )) (global ? *) - ( global ? ( import ) ) ;; = (import ?