MoonBit月兔编程语言 现代编程思想 第十四课 案例:堆栈虚拟机
+ 1) MOVE 2 1 0 ; R(2) = R(1) RETURN 2 2 0 ; return R(2) RETURN 0 1 0 ; return 4 堆栈虚拟机 例:WebAssembly Virtual Machine 取最⼤值 fn max(a : Int, b : Int) -> Int 1. local.get $a local.set $m get $m ;; m 5 WebAssembly WebAssembly是什么? ⼀个虚拟指令集 可以在浏览器以及其他运⾏时(Wasmtime WAMR WasmEdge等)中运⾏ MoonBit的第⼀个后端 WebAssembly指令集的⼦集为例 6 简单指令集 数据 只考虑32位有符号整数 ⾮零代表 true 在线尝试 https://webassembly.github.io/wabt/demo/wat2wasm/ 1. const wasmInstance = new WebAssembly.Instance(wasmModule, {"spectest":{"print_int": console.log}}); 17 构造编译器 指令 WebAssembly指令 Const(0) i320 码力 | 31 页 | 594.38 KB | 1 年前3The Zig Programming Language 0.5.0 Documentation
String Literals Import from C Header File C Pointers Exporting a C Library Mixing Object Files WebAssembly Freestanding WASI Targets Style Guide Whitespace Names Examples Source Encoding Keyword Reference main allocator. �. Are you building for WebAssembly? In this case, std.heap.wasm_allocator is likely the right choice for your main allocator as it uses WebAssembly's memory instructions. �. Is the maximum Targets Zig Build System WebAssembly Zig supports building for WebAssembly out of the box. There is also a specialized std.heap.wasm_allocator memory allocator for WebAssembly environments. Freestanding0 码力 | 224 页 | 5.80 MB | 1 年前3The Zig Programming Language 0.7.1 Documentation
/zig-cache/bin/test all your base are belong to us See also: Targets Zig Build System WebAssembly Zig supports building for WebAssembly out of the box. Freestanding For host environments like the web browser and a library using the freestanding OS target. Here's an example of running Zig code compiled to WebAssembly with nodejs. math.zig extern fn print(i32) void; export fn add(a: i32, b: i32) void { print(a require('fs'); const source = fs.readFileSync("./math.wasm"); const typedArray = new Uint8Array(source); WebAssembly.instantiate(typedArray, { env: { print: (result) => { console.log(`The result is ${result}`);0 码力 | 225 页 | 5.74 MB | 1 年前3The Zig Programming Language 0.6.0 Documentation
/zig-cache/bin/test all your base are belong to us See also: Targets Zig Build System WebAssembly Zig supports building for WebAssembly out of the box. Freestanding For host environments like the web browser and a library using the freestanding OS target. Here's an example of running Zig code compiled to WebAssembly with nodejs. math.zig extern fn print(i32) void; export fn add(a: i32, b: i32) void { print(a require('fs'); const source = fs.readFileSync("./math.wasm"); const typedArray = new Uint8Array(source); WebAssembly.instantiate(typedArray, { env: { print: (result) => { console.log(`The result is ${result}`);0 码力 | 214 页 | 5.37 MB | 1 年前305-MoonBit 编程语言(WASM 技术)服务端应用展望以及对Kubernetes生态的影响
• Rust 语言社区早期参与者 The Rust Programming Language(中文纸质版)译者3 • MoonBit 语言社区开发者 官方标准库代码、教程资料编写者 WebAssembly (WASM) WASM 现状 • 1.0 MVP 已稳定(2017)已被 Web 前端应用实际接受 • 有后端应用潜力,但更多具体疑问仍待解答 • 问题集中在扩展特性(features)、外部语言接口(FFI)、 WASM 扩展特性 • 基本接口已在 WASM 1.0 标准化 • 但只能交换简单数据类型 • 交换缓冲区和高级数据结构的方法各有不一 WASM 外部语言接口(FFI) • WASI (WebAssembly System Interface) • 用于允许 WASM 代码调用操作系统的能力 (stdout、socket这些) • 目前处在 0.2 预览版 • 功能缺口和争议都很大 WASM0 码力 | 30 页 | 3.41 MB | 9 月前3The Zig Programming Language 0.8.1 Documentation
/zig-out/bin/test all your base are belong to us See also: Targets Zig Build System WebAssembly Zig supports building for WebAssembly out of the box. Freestanding For host environments like the web browser and dynamic library using the freestanding OS target. Here's an example of running Zig code compiled to WebAssembly with nodejs. math.zig extern fn print(i32) void; export fn add(a: i32, b: i32) void { print(a require('fs'); const source = fs.readFileSync("./math.wasm"); const typedArray = new Uint8Array(source); WebAssembly.instantiate(typedArray, { env: { print: (result) => { console.log(`The result is ${result}`);0 码力 | 234 页 | 6.01 MB | 1 年前3The Zig Programming Language 0.12.0 Documentation
/zig-out/bin/test all your base are belong to us See also: Targets Zig Build System WebAssembly Zig supports building for WebAssembly out of the box. Freestanding For host environments like the web browser and executable using the freestanding OS target. Here's an example of running Zig code compiled to WebAssembly with nodejs. math.zig extern fn print(i32) void; export fn add(a: i32, b: i32) void { print(a require('fs'); const source = fs.readFileSync("./math.wasm"); const typedArray = new Uint8Array(source); WebAssembly.instantiate(typedArray, { env: { print: (result) => { console.log(`The result is ${result}`);0 码力 | 241 页 | 7.37 MB | 1 年前3The Zig Programming Language 0.9.1 Documentation
/zig-out/bin/test 3 all your base are belong to us See also: Targets Zig Build System WebAssembly Zig supports building for WebAssembly out of the box. Freestanding For host environments like the web browser and dynamic library using the freestanding OS target. Here's an example of running Zig code compiled to WebAssembly with nodejs. math.zig 1 extern fn print(i32) void; 2 3 export fn add(a: i32, b: i32) void { const source = fs.readFileSync("./math.wasm"); 3 const typedArray = new Uint8Array(source); 4 5 WebAssembly.instantiate(typedArray, { 6 env: { 7 print: (result) => { console.log(`The result is ${result}`);0 码力 | 234 页 | 7.90 MB | 1 年前3The Zig Programming Language 0.11.0 Documentation
/zig-out/bin/test all your base are belong to us See also: Targets Zig Build System 47. WebAssembly Zig supports building for WebAssembly out of the box. 47.1. Freestanding For host environments like the web browser dynamic library using the freestanding OS target. Here's an example of running Zig code compiled to WebAssembly with nodejs. math.zig 1 extern fn print(i32) void; 2 3 export fn add(a: i32, b: i32) void { const source = fs.readFileSync("./math.wasm"); 3 const typedArray = new Uint8Array(source); 4 5 WebAssembly.instantiate(typedArray, { 6 env: { 7 print: (result) => { console.log(`The result is ${result}`);0 码力 | 238 页 | 7.80 MB | 1 年前3The Zig Programming Language 0.10.1 Documentation
/zig-out/bin/test 3 all your base are belong to us See also: Targets Zig Build System WebAssembly Zig supports building for WebAssembly out of the box. Freestanding For host environments like the web browser and dynamic library using the freestanding OS target. Here's an example of running Zig code compiled to WebAssembly with nodejs. math.zig 1 extern fn print(i32) void; 2 3 export fn add(a: i32, b: i32) void { const source = fs.readFileSync("./math.wasm"); 3 const typedArray = new Uint8Array(source); 4 5 WebAssembly.instantiate(typedArray, { 6 env: { 7 print: (result) => { console.log(`The result is ${result}`);0 码力 | 239 页 | 8.03 MB | 1 年前3
共 10 条
- 1