A WebAssembly interpreter written in C for demonstration.

Overview

wasmc

中文文档

A WebAssembly interpreter written in C for demonstration.

This repository implements a WebAssembly interpreter. It is written to clarify how a WebAssembly interpreter works and try out the latest proposal. So the code is easy to understand, and there are lots of code comments to explain the intention behind the code.

Build

You can get the executable via Makefile or CMake.

Makefile:

make

CMake:

cmake ./
make

Usage

You can call the executable with

[wasmc executable path] [wasm file path]

Wasmc loads the wasm file and return a REPL(read-eval-print-loop). You can invoke some exported function of the wasm file as shown below.

Note: the interpreter now only supports the wasm file compiled from wat file.

Examples

Here is description for ./examples.

File Description
./examples/arith.wasm Export add/sub/mul/div_u function with two i32 type of parameters
./examples/fib.wasm Export recursive fibonacci function with an i32 type of parameter
./examples/fac.wasm Export recursive factorial function with an i32 type of parameter

Implementation

Here are core modules.

├── cli.c          // the entry of interpreter
├── module.c       // decode from binary format to memory format
├── interpreter.c  // stack based virtual machine 
├── opcode.h       // webassembly opcode enum
└── utils.c        // utility libraries

Learn more via article below.

深入 WebAssembly 之解释器实现篇

Inspiration

You might also like...
A demonstration of implementing, and using, a "type safe", extensible, and lazy iterator interface in pure C99.

c-iterators A demonstration of implementing, and using, a "type safe", extensible, and lazy iterator interface in pure C99. The iterable is generic on

A simple demonstration of how PyTorch autograd works

简单地演示了 PyTorch 中自动求导机制的原理。 官方博客:https://pytorch.org/blog/overview-of-pytorch-autograd-engine/ 编译运行 使用 Bazel bazel run autograd_test 包含了一个使用 MSE 损失函数的一

A project demonstration on how to use the GigE camera to do the DeepStream Yolo3 object detection
A project demonstration on how to use the GigE camera to do the DeepStream Yolo3 object detection

A project demonstration on how to use the GigE camera to do the DeepStream Yolo3 object detection, how to set up the GigE camera, and deployment for the DeepStream apps.

ADTW demonstration application - implemented with EAP

Amerced DTW demonstration application Amerced DTW (ADTW) is a variant of DTW, "amercing" ("penalizing") warping steps by a fixed penalty. This is a NN

This is a demonstration repository for The Pitt Challenge project about medical image compression.
This is a demonstration repository for The Pitt Challenge project about medical image compression.

Image Compression for Portable Medical Records This is a demonstration repository for The Pitt Challenge project about medical image compression. Back

Care race game built in c++  with sfml. this project is done in 3rd semester of csit for demonstration of computer graphics.
Care race game built in c++ with sfml. this project is done in 3rd semester of csit for demonstration of computer graphics.

Car Race Car race is simple game which has been built by using SFML in c++ implementing concepts of Computer Graphics for project Work of 3rd semester

A demonstration of various different techniques for implementing 'threaded code,' a technique used in Forth and in virtual machines like the JVM.

Threaded code is a technique used in the implementation of virtual machines (VMs). It avoids the overhead of calling subroutines repeatedly by 'thread

A demonstration PoC for CVE-2022-21877 (storage spaces controller memory leak)
A demonstration PoC for CVE-2022-21877 (storage spaces controller memory leak)

POC CVE-2022-21877 This repository contains a POC for the CVE-2022-21877, found by Quang Linh, working at STAR Labs. This is an information leak found

Interpreter and miner for the LODA language written in C++

LODA Interpreter and Miner (C++) LODA is an assembly language, a computational model and a tool for mining integer sequences. You can use it to search

Yet another Chip-8 interpreter, this time written in C++ using GLFW and OpenGL as its graphics library 💻
Yet another Chip-8 interpreter, this time written in C++ using GLFW and OpenGL as its graphics library 💻

Yet another Chip-8 interpreter, but this time with a beautiful interface 💻

An interpreter for finding subtle bugs in programs written in standard C

tis-interpreter This is tis-interpreter, an interpreter of C for detecting undefined behavior. tis-interpreter detects subtle bugs in C programs that

Minimalistic C++/Python GUI library for OpenGL, GLES2/3, Metal, and WebAssembly/WebGL
Minimalistic C++/Python GUI library for OpenGL, GLES2/3, Metal, and WebAssembly/WebGL

NanoGUI NanoGUI is a minimalistic cross-platform widget library for OpenGL 3+, GLES 2/3, and Metal. It supports automatic layout generation, stateful

Portrait segmentation in your web browser with ncnn and webassembly

ncnn-webassembly-portrait-segmentation open https://nihui.github.io/ncnn-webassembly-portrait-segmentation and enjoy build and deploy Install emscript

web server & client. Fully C++/WebAssembly. Server runs on google cloud function. Client uses a C++ virtual dom.

Starter project. A web server and client fully made with C++/WebAssembly. A simple CMake configuration describes how to build and run everything.

WasmEdge Runtime is a high-performance, extensible, and hardware optimized WebAssembly Virtual Machine for automotive, cloud, AI, and blockchain applications.

WasmEdge Runtime is a high-performance, extensible, and hardware optimized WebAssembly Virtual Machine for automotive, cloud, AI, and blockchain applications.

Deploy SCRFD, an efficient high accuracy face detection approach, in your web browser with ncnn and webassembly

ncnn-webassembly-scrfd open https://nihui.github.io/ncnn-webassembly-scrfd and enjoy build and deploy Install emscripten

A (relatively) small node library to clone and pull git repositories in a standalone manner thanks to libgit2, powered by WebAssembly and Emscripten

simple-git-wasm A (relatively) small node library to clone and pull git repositories in a standalone manner thanks to libgit2, powered by WebAssembly

Deploy OcrLite in your web browser with ncnn and webassembly
Deploy OcrLite in your web browser with ncnn and webassembly

ncnn-webassembly-ocrlite Requirements ncnn webassembly opencv-mobile webassembly 3.4.13 Build Install emscripten git clone https://github.com/emscript

Chocolate Doom WebAssembly port with WebSockets support

Wasm Doom This is a Chocolate Doom WebAssembly port with WebSockets support. Requirements You need to install Emscripten and a few other tools first:

Comments
  • 关于wasm导入函数部分

    关于wasm导入函数部分

    interpreter.c文件第382行。实现外部函数调用有多种方式。

    1. 如果是基本类型,可以使用ABI调用。就是对应平台函数的参数传递规则等的使用。更简单的使用方式是使用ffi的库去实现。
    2. 对于复杂类型,或者通用的类型。可以采用bind的方式。意思是使用编写一个函数,可以去虚拟机的执行堆栈获取所需要的函数数据。就行v8的function,提供的v8::FunctionCallbackInfo一样。
    opened by dengweichi 1
Owner
湮远
Focus on WebAssembly
湮远
C++ WebAssembly assembler

wasmblr A single header file WebAssembly assembler. This library makes it easier to generate web assembly binaries directly from C++. Useful for JIT c

Bram Wasti 148 Dec 23, 2022
A high-performance REST Toolkit written in C++

Pistache Pistache is a modern and elegant HTTP and REST framework for C++. It is entirely written in pure-C++14 and provides a clear and pleasant API.

null 2.8k Dec 29, 2022
a very based, minimal, and flexible static site generator written in pure C89 with no external deps.

based-ssg is a very based, minimal, and flexible static site generator written in pure C89 with no external deps.

null 15 Dec 22, 2022
Tntnet is a web application server for web applications written in C++.

Tntnet is a web application server for web applications written in C++.

Tommi Mäkitalo 73 Sep 26, 2022
Python bindings for Wasm3, the fastest WebAssembly interpreter

pywasm3 Python bindings for Wasm3, the fastest WebAssembly interpreter Main repository: Wasm3 project Install # Latest release: pip3 install pywasm3

Wasm3 Labs 49 Dec 27, 2022
🚀 The fastest WebAssembly interpreter, and the most universal runtime

Wasm3 The fastest WebAssembly interpreter, and the most universal runtime. Based on CoreMark 1.0 and independent benchmarks. Your mileage may vary. Ge

Wasm3 Labs 5.6k Dec 31, 2022
Freeze OS is a cross-platform operating system emulator that runs on top of an interpreter called the Freeze interpreter.

Freeze OS is a cross-platform operating system emulator that runs on top of an interpreter called the Freeze interpreter. The operating system code is basically written in the Freeze programming language that is passed to the Freeze interpreter. The idea is to skip instances where the operating system needs to handle low level operators and focus on higher level stuff, like malware analysis, AI, and others.

null 24 May 2, 2022
2048 written in C and compiled to WebAssembly

2048.wasm 2048 written in C and compiled to WebAssembly Play Use the arrow keys ( ᐊ ᐅ ᐃ ᐁ ) to slide the tiles. press n to play over. Usage Compile C

Nishchith Shetty 48 Nov 1, 2022
This is an experimental OS-from-scratch project. Just for demonstration, not useful at all.

OS Playground This is an experimental OS-from-scratch project. Just for demonstration, not useful at all. Different from OS in other projects, this OS

null 5 Nov 5, 2022
x64 Windows kernel code execution via user-mode, arbitrary syscall, vulnerable IOCTLs demonstration

anycall x64 Windows kernel code execution via user-mode, arbitrary syscall, vulnerable IOCTLs demonstration Read: https://www.godeye.club/2021/05/14/0

Kento Oki 160 Dec 30, 2022