AssemblyScript

AssemblyScript is a TypeScript-based programming language that is optimized for, and statically compiled to, WebAssembly (currently using asc, the reference AssemblyScript compiler). Resembling ECMAScript and JavaScript, but with static data types, the language is developed by the AssemblyScript Project[6] with contributions from the AssemblyScript community.

Overview

In 2017, the availability of support for WebAssembly, a standard definition for a low-levelbytecode and an associated virtual machine, became widespread among major web browsers, providing web programs a lower-level and potentially higher-performance compiling target for client-side programs and applications to execute within web browsers, along with the interpreted (and in practice dynamically compiled) JavaScript web scripting language.[7] WebAssembly allows programs and code to be statically compiled ahead of time in order to run at potentially native-level or bare machine (metal) performance within web browsers, without the overhead of interpretation or the initial latency of dynamic compilation.[8]

With the adoption of WebAssembly in major web browsers, Alon Zakai, creator of Emscripten, an LLVMClang-based C and C++ compiler that targeted a subset of JavaScript named asm.js, added support for WebAssembly as a compiling target in Emscripten, allowing C and/or C++ programs and code to be compiled directly to WebAssembly.[9]

While Emscripten and similar compilers allow writing new code, or porting extant code, written in a high-level programming language such as C, C++, Go, and Rust to WebAssembly to achieve potentially higher, native-level execution performance in web browsers, this forces web developers accustomed to developing client-side web scripts and applications in ECMAScript–JavaScript (the de facto client-side programming language in web browsers) to use a different language to target WebAssembly than JavaScript. AssemblyScript, as a variant of TypeScript that is syntactically similar to JavaScript, allows developers accustomed to JavaScript to use a familiar language to target WebAssembly, potentially reducing the learning curve of a separate language that can be compiled to WebAssembly. Also, because AssemblyScript was designed to be an optimal source language for WebAssembly, the language's type system closely reflects that of WebAssembly,[10] and the language provides standard low-level functions (typically implemented as macros) that map directly to WebAssembly instructions that mirror instructions available on modern processors such as single instruction, multiple data (SIMD) and vector instructions and more specialized instructions such as clz (count leading zero bits), ctz (count trailing zero bits), and popcnt (population count), used in applications such as encryption and cryptographic libraries.[11]

asc, the reference AssemblyScript compiler, is based on Binaryen , a back-end compiler toolchain developed by Alon Zakai that compiles to WebAssembly and is a component of Emscripten (which Zakai also developed). The asc compiler and other tooling are available via the npm package manager.

على الرغم من أن WebAssembly صُممت في الأصل للتنفيذ داخل متصفحات الويب، إلا أن تطوير WASI (واجهة نظام WebAssembly)، وهي مواصفات مجتمعية لواجهة برمجة تطبيقات قياسية تتيح لبرامج WebAssembly الوصول إلى استدعاءات النظام ووظائف نظام التشغيل الأخرى ، [ 12 ] قد أدى إلى تطوير بيئات تشغيل WebAssembly من خلال مشاريع مثل Wasmtime  ، [ 13 ] وWebAssembly Micro Runtime  و Wasmer  ، [ 14 ] و WasmEdge  و wazero  ، والتي تسمح بتشغيل WebAssembly، والبرامج المكتوبة بلغات مثل AssemblyScript التي يمكن ترجمتها إليه، في بيئات غير ويب أيضًا. [ 15 ]

التوافق مع جافا سكريبت

يُترجم AssemblyScript إلى وحدات WebAssembly، والتي يمكن بعد ذلك استخدامها في صفحات الويب من جانب العميل باستخدام طرق JavaScript القياسية، WebAssembly.compileStreamingتمامًا WebAssembly.instantiateStreamingمثل ملفات WebAssembly الثنائية القياسية. [ 16 ] ويكون تبادل البيانات بين JavaScript ووحدات WebAssembly المُترجمة، بالإضافة إلى استدعاءات الدوال بين JavaScript وWebAssembly، مماثلاً لأي وحدة WebAssembly أخرى. [ 17 ]

نظرًا لأن لغة AssemblyScript هي في الأساس مجموعة فرعية من TypeScript، فمن الممكن نظريًا كتابة برنامج AssemblyScript باستخدام هذه المجموعة الفرعية، ثم ترجمته إلى كلٍ من JavaScript وWebAssembly، باستخدام مترجم TypeScript ومترجم AssemblyScript على التوالي. وهذا يتيح إمكانية نقل الشيفرة البرمجية واستخدامها في بيئات تشغيل JavaScript أو WebAssembly .

يستخدم

اعتبارًا من مايو 2025 أكثر من 29000 مشروع مُستضاف على GitHub مكتوبة، كليًا أو جزئيًا، بلغة AssemblyScript، [ 18 ] مع ما يقرب من 50000 عملية تنزيل لمترجم AssemblyScript أسبوعيًا عبر npm . [ 19 ] [ 20 ]

في عام 2021، بدأ Webpack باستخدام AssemblyScript لتسريع حساب دوال التجزئة مثل xxhash وmd4 . وقد أتاح ذلك أيضًا إمكانية إزالة التبعيات الأصلية.

استقبال

وصف ألون زكاي، كبير مطوري Emscripten، لغة AssemblyScript بأنها "مصممة مع مراعاة WebAssembly وحجم الكود. إنها ليست لغة موجودة نستخدمها لغرض جديد، بل هي لغة مصممة خصيصًا لـ WebAssembly. تتميز wasm-optبتكامل رائع - في الواقع، هي مبنية عليه - ومن السهل جدًا الحصول على حجم كود مناسب." [ 21 ]

Norwegian musician Peter Salomonsen, in a 2020 WebAssembly Summit talk titled, "WebAssembly Music," demonstrated the use of AssemblyScript for real-time compiling to WebAssembly in live electronic music synthesis, saying, "I chose AssemblyScript because it has high-level readability and low-level control; it's like a high-level language, but you get that low-level feeling, and you can even write direct WebAssembly intrinsics if you want to."[22]

Aaron Turner, a senior engineer at Fastly, a cloud computing services provider that uses WebAssembly for the company's Compute@Edge serverless compute environment, in a review of AssemblyScript wrote:[23]

While AssemblyScript requires stricter typing than TypeScript does, it sticks as close as possible to TypeScript syntax and semantics—which means that most JavaScript developers will find AssemblyScript comfortable to use—and it enables great support for the modern JavaScript ecosystem. For instance, the AssemblyScript compiler is available on npm, as well as common AssemblyScript tools and libraries like as-pect. AssemblyScript files also use TypeScript's ‘.ts’ file extension, and it includes proper typings for allowing AssemblyScript to piggy-back on TypeScript tooling, such as the TypeScript linter. With the right small tweaks, AssemblyScript can even be used with the TypeScript compiler.

This is useful, as AssemblyScript offers a low-overhead entry-point for JavaScript developers to pick up a language to output WebAssembly—both in terms of learning to read and write AssemblyScript, and using much extant tooling that may already be in a JavaScript developer's workflow. AssemblyScript is often referred to in the WebAssembly community as a great gateway to picking up WebAssembly. It offers a large group of developers who already write applications for the web a path to pick up and learn WebAssembly. Even if you are starting from scratch and are not particularly familiar with JavaScript or TypeScript, AssemblyScript is a solid choice when picking a language to start outputting WebAssembly.

However, Turner went on to cite the language's relative newness and thus its lack of some features available in larger, more complex and established programming languages as potential but temporary shortcomings of the language.

See also

References

  1. 12"AssemblyScript Working Group". GitHub.com. AssemblyScript Project. April 24, 2020. Retrieved February 10, 2021. Daniel Wirtz (@dcodeIO) - Author of AssemblyScript
  2. Turner, Aaron (March 28, 2019). "WebAssembly for Javascript Developers". YouTube.com. WebAssembly SF. Retrieved February 10, 2021. @dcodeIO [Daniel Wirtz] and @MaxGraey [Max Graey]—they're the main two developers of AssemblyScript
  3. "assemblyscript 0.1.0". npmjs.com. AssemblyScript Project. 2017. Retrieved February 10, 2021.
  4. "Release 0.28.19". June 12, 2026. Retrieved June 13, 2026.
  5. "License". GitHub.com. The AssemblyScript Project. September 29, 2017. Retrieved February 10, 2021. AssemblyScript/assemblyscript is licensed under the Apache License 2.0
  6. "The AssemblyScript Project". GitHub.com. The AssemblyScript Project. Retrieved February 10, 2021.
  7. "Roadmap". WebAssembly.org. WebAssembly Community Group. November 2017. Retrieved February 10, 2021.
  8. WebAssembly Working Group. "WebAssembly". WebAssembly.org. WebAssembly Working Group. Retrieved February 10, 2021.
  9. Zakai, Alon; Others. "Emscripten". Emscripten.org. Emscripten project. Retrieved February 10, 2021.
  10. "Types". AssemblyScript.org. The AssemblyScript Project. Retrieved February 10, 2021.
  11. "Environment". AssemblyScript.org. The AssemblyScript Project. Retrieved February 10, 2012.
  12. The Wasmtime Project. "WASI: The WebAssembly System Interface". WASI.dev. The Wasmtime Project. Retrieved February 10, 2021.
  13. The Wasmtime Project. "Wasmtime: A small and efficient runtime for WebAssembly & WASI". Wasmtime.dev. The Wasmtime Project. Retrieved February 10, 2021.
  14. شركة واسمر. "واسمر: بيئة تشغيل WebAssembly العالمية" . Wasmer.io . شركة واسمر . تم الاطلاع عليه بتاريخ 10 فبراير 2021 .
  15. جاغوري، ساسان (1 أغسطس 2023). الحوسبة الفعّالة بدون خادم باستخدام WebAssembly (رسالة ماجستير). جامعة العلوم التطبيقية، حرم فيينا.
  16. شبكة مطوري موزيلا. "تحميل وتشغيل كود WebAssembly" . developer.mozilla.org . شبكة مطوري موزيلا . تم الاطلاع عليه بتاريخ 10 فبراير 2021 .
  17. شبكة مطوري موزيلا. "استخدام واجهة برمجة تطبيقات جافا سكريبت WebAssembly" . developer.mozilla.org . شبكة مطوري موزيلا . تم الاطلاع عليه بتاريخ 10 فبراير 2021 .
  18. "مخطط تبعية AssemblyScript/assemblyscript" . GitHub.com . GitHub . تم الاطلاع عليه في 26 مايو 2025 .
  19. npmjs. "تنزيلات أسبوعية من مكتبة AssemblyScript" . npmjs.com . تم الاطلاع عليه بتاريخ 26 مايو 2025 .
  20. "حل الأخطاء في تايب سكريبت" . 3 يونيو 2022.السبت، 7 مايو 2022
  21. ألون زكاي (19 فبراير 2020). "نشر إصدارات صغيرة من WebAssembly" . YouTube.com . WebAssembly-Summit.org . تم الاطلاع عليه في 10 فبراير 2021 .
  22. بيتر سالومونسن (19 فبراير 2020). "موسيقى WebAssembly" . YouTube.com . WebAssembly-Summit.org . تم الاطلاع عليه في 10 فبراير 2021 .
  23. آرون تيرنر (29 أكتوبر 2020). "تعرّف على لغة AssemblyScript: لغة البرمجة التالية" . Fastly.com . Fastly . تم الاطلاع عليه في 10 فبراير 2021 .