GithubHelp home page GithubHelp logo

xwang98 / wasmnizer-ts Goto Github PK

View Code? Open in Web Editor NEW

This project forked from web-devkits/wasmnizer-ts

0.0 0.0 0.0 1.41 MB

Toolchain for compiling TypeScript to WasmGC

License: Apache License 2.0

Shell 0.27% JavaScript 2.72% C++ 2.69% Python 1.66% C 14.17% TypeScript 77.86% CMake 0.40% Dockerfile 0.08% WebAssembly 0.15%

wasmnizer-ts's Introduction

Wasmnizer-ts

Toolchain for compiling TypeScript to WasmGC

Overview

Wasmnizer-ts utilizes WasmGC to compile TypeScript source code into WebAssembly bytecode, and support dynamic type (such as any) through host APIs. The Wasmnizer-ts now supports a strict subset of TypeScript and continuously strives to accommodate more semantics.

There are three components in Wasmnizer-ts:

  • ts2wasm-compiler: a compiler for compiling TypeScript source code into WasmGC bytecode.
  • ts2wasm-stdlib: standard library implemented in ts source code, will be compiled with application together. See standard library.
  • ts2wasm-runtime-library: runtime libraries for exposing host APIs required for running the generated wasm module, including:
    1. libdyntype: support dynamic objects, see API spec here. We have proposed a WASI proposal.
    2. libstruct-indirect: access WasmGC struct fields through index calculated during runtime, see API spec here. These APIs are used to emulate the behaviour of the proposed struct.get/set_indirect opcode.
    3. libstd: standard library implemented in native, such as console.log, see standard library.

Note: This project is highly experimental and under active development, DO NOT use in production

Features

  • garbage collection. ts2wasm-compiler leverage WebAssembly GC proposal, which can benefit from runtime's GC capability.
  • optimization. ts2wasm-compiler uses binaryen as backend, which can benefit from binaryen's powerful optimization capabilities.
  • small footprint. Data structures in source code is represented as WasmGC types, which avoids the requirement for memory allocator and garbage collector inside wasm module.
  • static compilation. Type information in TypeScript source code is used to create static WasmGC types, which avoids the overhead of dynamic type checking.
  • dynamic typing. any and other dynamic types in TypeScript source code are supported by host APIs.

Execution environment

The wasm module generated by ts2wasm-compiler is designed to be executed in a WasmGC runtime environment. The runtime should provide the following capabilities:

  • WebAssembly proposals:
    • WasmGC (mandatory): WasmGC proposal, which is a garbage collection mechanism for WebAssembly.

      Note: the GC opcode generated by binaryen is slightly different than GC MVP, please see here for details.

    • Exception handling (required by try-catch statements): exception handling proposal, which adds exception handling mechanism to WebAssembly.
    • stringref (required by stringref feature): reference-typed strings proposal, provide a language independent string representation.
  • APIs:
    • libdyntype API (required by dynamic typing): APIs for supporting dynamic objects.
    • libstruct-indirect API (required by interface type): APIs for accessing WasmGC struct fields through index calculated during runtime.
    • libstd API (required by standard libraries): APIs for providing standard libraries from host environment.

Wasmnizer-ts currently implemented host APIs on multiple environments:

  • WebAssembly Micro Runtime (WAMR): libdyntype API, libstruct-indirect API and libstd API
  • chrome browser and nodejs (20.6.1+): part of libdyntype API implemented with JavaScript

Please see feature list for supporting status of each feature.

Please goto Getting Started for how to use the project and Introduction for more details.

Contributing

We welcome contributions to Wasmnizer-ts. You can find more details in CONTRIBUTING.md .

License

Wasmnizer-ts uses the same license as LLVM: the Apache 2.0 license with the LLVM exception. See the LICENSE file for details. Any contributions you make will be under the same license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.