From 218934fa2ed1c702a6d3923d2aa2cc6b43c48684 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:43:23 -0500 Subject: initial commit --- files/tr/webassembly/concepts/index.html | 152 +++++++++++++++++++++++++++++++ files/tr/webassembly/index.html | 117 ++++++++++++++++++++++++ 2 files changed, 269 insertions(+) create mode 100644 files/tr/webassembly/concepts/index.html create mode 100644 files/tr/webassembly/index.html (limited to 'files/tr/webassembly') diff --git a/files/tr/webassembly/concepts/index.html b/files/tr/webassembly/concepts/index.html new file mode 100644 index 0000000000..859c82bc59 --- /dev/null +++ b/files/tr/webassembly/concepts/index.html @@ -0,0 +1,152 @@ +--- +title: WebAssembly Kavramları +slug: WebAssembly/Concepts +translation_of: WebAssembly/Concepts +--- +
{{WebAssemblySidebar}}
+ +

This article explains the concepts behind how WebAssembly works including its goals, the problems it solves, and how it runs inside the web browser's rendering engine.

+ +

What is WebAssembly?

+ +

WebAssembly is a new type of code that can be run in modern web browsers and provides new features and major gains in performance. It is not primarily intended to be written by hand, rather it is designed to be an effective compilation target for source languages like C, C++, Rust, etc.

+ +

This has huge implications for the web platform — it provides a way to run code written in multiple languages on the web at near-native speed, with client apps running on the web that previously couldn’t have done so.

+ +

What’s more, you don’t even have to know how to create WebAssembly code to take advantage of it. WebAssembly modules can be imported into a web (or Node.js) app, exposing WebAssembly functions for use via JavaScript. JavaScript frameworks could make use of WebAssembly to confer massive performance advantages and new features while still making functionality easily available to web developers.

+ +

WebAssembly goals

+ +

WebAssembly is being created as an open standard inside the W3C WebAssembly Community Group with the following goals:

+ + + +
+

Note: WebAssembly will also have uses outside web and JavaScript environments (see Non-web embeddings).

+
+ +

How does WebAssembly fit into the web platform?

+ +

The web platform can be thought of as having two parts:

+ + + +

Historically, the VM has been able to load only JavaScript. This has worked well for us as JavaScript is powerful enough to solve most problems people have on the Web today. We have run into performance problems, however, when trying to use JavaScript for more intensive use cases like 3D games, Virtual and Augmented Reality, computer vision, image/video editing, and a number of other domains that demand native performance (see WebAssembly use cases for more ideas).

+ +

Additionally, the cost of downloading, parsing, and compiling very large JavaScript applications can be prohibitive. Mobile and other resource-constrained platforms can further amplify these performance bottlenecks.

+ +

WebAssembly is a different language from JavaScript, but it is not intended as a replacement. Instead, it is designed to complement and work alongside JavaScript, allowing web developers to take advantage of both languages' strong points:

+ + + +

With the advent of WebAssembly appearing in browsers, the virtual machine that we talked about earlier will now load and run two types of code — JavaScript AND WebAssembly.

+ +

The different code types can call each other as required — the WebAssembly JavaScript API wraps exported WebAssembly code with JavaScript functions that can be called normally, and WebAssembly code can import and synchronously call normal JavaScript functions. In fact, the basic unit of WebAssembly code is called a module and WebAssembly modules are symmetric in many ways to ES2015 modules.

+ +

WebAssembly key concepts

+ +

There are several key concepts needed to understand how WebAssembly runs in the browser. All of these concepts are reflected 1:1 in the WebAssembly JavaScript API.

+ + + +

The JavaScript API provides developers with the ability to create modules, memories, tables, and instances. Given a WebAssembly instance, JavaScript code can synchronously call its exports, which are exposed as normal JavaScript functions. Arbitrary JavaScript functions can also be synchronously called by WebAssembly code by passing in those JavaScript functions as the imports to a WebAssembly instance.

+ +

Since JavaScript has complete control over how WebAssembly code is downloaded, compiled and run, JavaScript developers could even think of WebAssembly as just a JavaScript feature for efficiently generating high-performance functions.

+ +

In the future, WebAssembly modules will be loadable just like ES2015 modules (using <script type='module'>), meaning that JavaScript will be able to fetch, compile, and import a WebAssembly module as easily as an ES2015 module.

+ +

How do I use WebAssembly in my app?

+ +

Above we talked about the raw primitives that WebAssembly adds to the Web platform: a binary format for code and APIs for loading and running this binary code. Now let’s talk about how we can use these primitives in practice.

+ +

The WebAssembly ecosystem is at a nascent stage; more tools will undoubtedly emerge going forward. Right now, there are four main entry points:

+ + + +

Let’s talk about these options:

+ +

Porting from C/C++

+ +

Two of the many options for creating WASM code are an online wasm assembler or Emscripten. There are a number of online WASM assembler choices, such as:

+ + + +

These are great resources for people who are trying to figure out where to start, but they lack some of the tooling and optimizations of Emscripten.

+ +

The Emscripten tool is able to take just about any C/C++ source code and compile it into a .wasm module, plus the necessary JavaScript "glue" code for loading and running the module, and an HTML document to display the results of the code.

+ +

+ +

In a nutshell, the process works as follows:

+ +
    +
  1. Emscripten first feeds the C/C++ into clang+LLVM — a mature open-source C/C++ compiler toolchain, shipped as part of XCode on OSX for example.
  2. +
  3. Emscripten transforms the compiled result of clang+LLVM into a .wasm binary.
  4. +
  5. By itself, WebAssembly cannot currently directly access the DOM; it can only call JavaScript, passing in integer and floating point primitive data types. Thus, to access any Web API, WebAssembly needs to call out to JavaScript, which then makes the Web API call. Emscripten therefore creates the HTML and JavaScript glue code needed to achieve this.
  6. +
+ +
+

Note: There are future plans to allow WebAssembly to call Web APIs directly.

+
+ +

The JavaScript glue code is not as simple as you might imagine. For a start, Emscripten implements popular C/C++ libraries like SDL, OpenGL, OpenAL, and parts of POSIX. These libraries are implemented in terms of Web APIs and thus each one requires some JavaScript glue code to connect WebAssembly to the underlying Web API.

+ +

So part of the glue code is implementing the functionality of each respective library used by the C/C++ code. The glue code also contains the logic for calling the above-mentioned WebAssembly JavaScript APIs to fetch, load and run the .wasm file.

+ +

The generated HTML document loads the JavaScript glue file and writes stdout to a {{htmlelement("textarea")}}. If the application uses OpenGL, the HTML also contains a {{htmlelement("canvas")}} element that is used as the rendering target. It’s very easy to modify the Emscripten output and turn it into whatever web app you require.

+ +

You can find full documentation on Emscripten at emscripten.org, and a guide to implementing the toolchain and compiling your own C/C++ app across to wasm at Compiling from C/C++ to WebAssembly.

+ +

Writing WebAssembly directly

+ +

Do you want to build your own compiler, or your own tools, or make a JavaScript library that generates WebAssembly at runtime?

+ +

In the same fashion as physical assembly languages, the WebAssembly binary format has a text representation — the two have a 1:1 correspondence. You can write or generate this format by hand and then convert it into the binary format with any of several WebAssemby text-to-binary tools.

+ +

For a simple guide on how to do this, see our Converting WebAssembly text format to wasm article.

+ +

Writing Rust Targeting WebAssembly

+ +

It is also possible to write Rust code and compile over to WebAssembly, thanks to the tireless work of the Rust WebAssembly Working Group. You can get started with installing the necessary toolchain, compiling a sample Rust program to a WebAssembly npm package, and using that in a sample web app, over at our Compiling from Rust to WebAssembly article.

+ +

Using AssemblyScript

+ +

For web developers who want to try WebAssembly without needing to learn the details of C or Rust, AssemblyScript will be the best option. It generates a small bundle and it's performance is slightly slower compared to C or Rust. You can check its documentation on https://assemblyscript.org/.

+ +

Summary

+ +

This article has given you an explanation of what WebAssembly is, why it is so useful, how it fits into the web, and how you can make use of it.

+ +

See also

+ + diff --git a/files/tr/webassembly/index.html b/files/tr/webassembly/index.html new file mode 100644 index 0000000000..0694b4bb44 --- /dev/null +++ b/files/tr/webassembly/index.html @@ -0,0 +1,117 @@ +--- +title: WebAssembly +slug: WebAssembly +tags: + - Landing + - WebAssembly + - wasm +translation_of: WebAssembly +--- +
{{WebAssemblySidebar}}
+ +
WebAssembly, modern web tarayıcılarda çalıştırılabilen yeni bir kod türüdür — yerel performansa yakın bir performansla çalışan ve C/C++, C# ve Rust gibi dillerle kompakt bir ikili biçime sahip düşük seviyeli bir dildir. Web üzerinde çalışabilmeleri için bir derleme hedefi ile JavaScript ile birlikte çalışabilecek şekilde tasarlanmıştır.
+ +

In a Nutshell

+ +

WebAssembly has huge implications for the web platform — it provides a way to run code written in multiple languages on the web at near native speed, with client apps running on the web that previously couldn’t have done so.

+ +

WebAssembly is designed to complement and run alongside JavaScript — using the WebAssembly JavaScript APIs, you can load WebAssembly modules into a JavaScript app and share functionality between the two. This allows you to take advantage of WebAssembly's performance and power and JavaScript's expressiveness and flexibility in the same apps, even if you don't know how to write WebAssembly code.

+ +

And what's even better is that it is being developed as a web standard via the W3C WebAssembly Working Group and Community Group with active participation from all major browser vendors.

+ +
+
+

Guides

+ +
+
WebAssembly concepts
+
Get started by reading the high-level concepts behind WebAssembly — what it is, why it is so useful, how it fits into the web platform (and beyond), and how to use it.
+
Compiling a New C/C++ Module to WebAssembly
+
When you’ve written code in C/C++, you can then compile it into .wasm using a tool like Emscripten. Let’s look at how it works.
+
Compiling an Existing C Module to WebAssembly
+
A core use-case for WebAssembly is to take the existing ecosystem of C libraries and allow developers to use them on the web.
+
Compiling from Rust to WebAssembly
+
If you've written some Rust code, you can compile it into WebAssembly! This tutorial takes you through all you need to know to compile a Rust project to wasm and use it in an existing web app.
+
Loading and running WebAssembly code
+
After you have a .wasm, this article covers how to fetch, compile and instantiate it, combining the WebAssembly JavaScript API with the Fetch or XHR APIs.
+
Using the WebAssembly JavaScript API
+
Once you've loaded a .wasm module, you'll want to use it. In this article we show you how to use WebAssembly via the WebAssembly JavaScript API.
+
Exported WebAssembly functions
+
Exported WebAssembly functions are the JavaScript reflections of WebAssembly functions which allow calling WebAssembly code from JavaScript. This article describes what they are.
+
Understanding WebAssembly text format
+
This article explains the wasm text format. This is the low-level textual representation of a .wasm module shown in browser developer tools when debugging.
+
Converting WebAssembly text format to wasm
+
This article provides a guide on how to convert a WebAssembly module written in the text format into a .wasm binary.
+
+
+ +
+

API reference

+ +
+
{{jsxref("Global_objects/WebAssembly", "WebAssembly")}}
+
This object acts as the namespace for all WebAssembly related functionality.
+
{{jsxref("Global_objects/WebAssembly/Global", "WebAssembly.Global()")}}
+
A WebAssembly.Global object represents a global variable instance, accessible from both JavaScript and importable/exportable across one or more {{jsxref("WebAssembly.Module")}} instances. This allows dynamic linking of multiple modules.
+
{{jsxref("Global_objects/WebAssembly/Module", "WebAssembly.Module()")}}
+
A WebAssembly.Module object contains stateless WebAssembly code that has already been compiled by the browser and can be efficiently shared with Workers, and instantiated multiple times.
+
{{jsxref("Global_objects/WebAssembly/Instance", "WebAssembly.Instance()")}}
+
A WebAssembly.Instance object is a stateful, executable instance of a ModuleInstance objects contain all the Exported WebAssembly functions that allow calling into WebAssembly code from JavaScript.
+
{{jsxref("Global_objects/WebAssembly/instantiateStreaming", "WebAssembly.instantiateStreaming()")}}
+
The WebAssembly.instantiateStreaming() function is the primary API for compiling and instantiating WebAssembly code, returning both a Module and its first Instance.
+
{{jsxref("Global_objects/WebAssembly/Memory", "WebAssembly.Memory()")}}
+
A WebAssembly.Memory object is a resizable {{jsxref("Global_objects/ArrayBuffer", "ArrayBuffer")}} that holds the raw bytes of memory accessed by an Instance.
+
{{jsxref("Global_objects/WebAssembly/Table", "WebAssembly.Table()")}}
+
A WebAssembly.Table object is a resizable typed array of opaque values, like function references, that are accessed by an Instance.
+
{{jsxref("WebAssembly.CompileError()")}}
+
Creates a new WebAssembly CompileError object.
+
{{jsxref("WebAssembly.LinkError()")}}
+
Creates a new WebAssembly LinkError object.
+
{{jsxref("WebAssembly.RuntimeError()")}}
+
Creates a new WebAssembly RuntimeError object.
+
+
+
+ +

Examples

+ + + +

Specifications

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('WebAssembly JS')}}{{Spec2('WebAssembly JS')}}Initial draft definition of the JavaScript API.
+ +

Browser compatibility

+ + + +

{{Compat("javascript.builtins.WebAssembly")}}

+ +

See also

+ + -- cgit v1.2.3-54-g00ecf