MoonBit月兔编程语言 现代编程思想 第十四课 案例:堆栈虚拟机现代编程思想 案例:栈式虚拟机 Hongbo Zhang 1 编译与解释 编译 源程序 x 编译器 -> ⽬标程序 ⽬标程序 x 输⼊数据 -> 输出数据 解释 源程序 x 输⼊数据 x 解释器 -> 输出数据 CPU可以被视为⼴义上的解释器 拓展阅读:⼆村映射/部分计算 部分计算:程序优化,根据已知信息,运算进⾏特化 已知源程序与解释器,进⾏部分运算,获得⽬标程序 ⽬标程序 ⽬标程序 x 输⼊数据 -> 输出数据 2 虚拟机 ⼀处编写,处处运⾏ 定义⼀个不基于任何平台的指令集 在不同平台上实现解释器 两种常⻅的虚拟机 堆栈虚拟机:运算数存储在栈上,数据遵循先进后出原则 寄存器虚拟机:运算数存储在寄存器中 3 寄存器虚拟机 例:Lua VM (The Implementation of Lua 5.0) 取最⼤值 MOVE 2 0 0 ; R(2) JUMP -> 5 (4 + 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 $m0 码力 | 31 页 | 594.38 KB | 1 年前3
05-MoonBit 编程语言(WASM 技术)服务端应用展望以及对Kubernetes生态的影响MoonBit 编程语言(WASM 技术) 服务端应用展望 以及对Kubernetes生态的影响 沙渺(MoonBit 语言社区开发者) 本分享包含大量目前尚处在早期开发阶段甚至概念阶段, 尚未获得广泛应用的技术。 仅为前景展望,不推荐用于当前立项开发的实际工程。 敬请注意 内容 • WASM 技术栈现状和 WASM 后端应用的构想 • MoonBit 语言介绍 • MoonBit MoonBit 方案对 WASM 技术栈的作用 • 对 Kubernetes 提出的挑战 分享者 • 沙渺,大连本地独立开发者 • Rust 语言社区早期参与者 The Rust Programming Language(中文纸质版)译者3 • MoonBit 语言社区开发者 官方标准库代码、教程资料编写者 WebAssembly (WASM) WASM 现状 • 1.0 MVP 已稳定(2017)已被 interfaces 或 WASI)上 WASM 后端应用先驱 wasmCloud (CNCF-Sandbox) fermyon/spin WasmEdge (CNCF-Sandbox) • 多数特性已标准化 • 一些特性对后端应用 不可或缺 • 但各个运行时的实现, 成熟度不一 • 使用扩展特性,基本 需要限定运行时 WASM 扩展特性 • 基本接口已在 WASM 1.0 标准化 • 但只能交换简单数据类型0 码力 | 30 页 | 3.41 MB | 9 月前3
The Zig Programming Language 0.7.1 Documentation@wasmMemorySize(index: u32) u32 This function returns the size of the Wasm memory identified by index as an unsigned value in units of Wasm pages. Note that each Wasm page is 64KB in size. This function is a low level level intrinsic with no safety mechanisms usually useful for allocator designers targeting Wasm. So unless you are writing a new allocator from scratch, you should use something like @import("std").heap.WasmPageAllocator u32) i32 This function increases the size of the Wasm memory identified by index by delta in units of unsigned number of Wasm pages. Note that each Wasm page is 64KB in size. On success, returns previous0 码力 | 225 页 | 5.74 MB | 1 年前3
The Zig Programming Language 0.8.1 Documentation@wasmMemorySize(index: u32) u32 This function returns the size of the Wasm memory identified by index as an unsigned value in units of Wasm pages. Note that each Wasm page is 64KB in size. This function is a low level level intrinsic with no safety mechanisms usually useful for allocator designers targeting Wasm. So unless you are writing a new allocator from scratch, you should use something like @import("std").heap.WasmPageAllocator u32) i32 This function increases the size of the Wasm memory identified by index by delta in units of unsigned number of Wasm pages. Note that each Wasm page is 64KB in size. On success, returns previous0 码力 | 234 页 | 6.01 MB | 1 年前3
The Zig Programming Language 0.9.1 Documentationx: u32) u32 This function returns the size of the Wasm memory identified by index as an unsigned value in units of Wasm pages. Note that each Wasm page is 64KB in size. This function is a low level level intrinsic with no safety mechanisms usually useful for allocator designers targeting Wasm. So unless you are writing a new allocator from scratch, you should use something like @import("std").heap.WasmPageAllocator u32) i32 This function increases the size of the Wasm memory identified by index by delta in units of unsigned number of Wasm pages. Note that each Wasm page is 64KB in size. On success, returns previous0 码力 | 234 页 | 7.90 MB | 1 年前3
The Zig Programming Language 0.11.0 Documentationx: u32) u32 This function returns the size of the Wasm memory identified by index as an unsigned value in units of Wasm pages. Note that each Wasm page is 64KB in size. This function is a low level level intrinsic with no safety mechanisms usually useful for allocator designers targeting Wasm. So unless you are writing a new allocator from scratch, you should use something like @import("std").heap.WasmPageAllocator u32) i32 This function increases the size of the Wasm memory identified by index by delta in units of unsigned number of Wasm pages. Note that each Wasm page is 64KB in size. On success, returns previous0 码力 | 238 页 | 7.80 MB | 1 年前3
The Zig Programming Language 0.10.1 Documentationx: u32) u32 This function returns the size of the Wasm memory identified by index as an unsigned value in units of Wasm pages. Note that each Wasm page is 64KB in size. This function is a low level level intrinsic with no safety mechanisms usually useful for allocator designers targeting Wasm. So unless you are writing a new allocator from scratch, you should use something like @import("std").heap.WasmPageAllocator u32) i32 This function increases the size of the Wasm memory identified by index by delta in units of unsigned number of Wasm pages. Note that each Wasm page is 64KB in size. On success, returns previous0 码力 | 239 页 | 8.03 MB | 1 年前3
The Zig Programming Language 0.5.0 Documentationchoice, at least for your 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 hsail, hsail64, spir, spir64, kalimba: Kalimba, shave, lanai, wasm32, wasm64, renderscript32, renderscript64, pub const Arm32 = enum { v8_5a, simulator, macabi, }; pub const ObjectFormat = enum { unknown, coff, elf, macho, wasm, }; pub const GlobalLinkage = enum { Internal, Strong, Weak, LinkOnce, }; pub const0 码力 | 224 页 | 5.80 MB | 1 年前3
The Zig Programming Language 0.12.0 Documentationx: u32) u32 This function returns the size of the Wasm memory identified by index as an unsigned value in units of Wasm pages. Note that each Wasm page is 64KB in size. This function is a low level level intrinsic with no safety mechanisms usually useful for allocator designers targeting Wasm. So unless you are writing a new allocator from scratch, you should use something like @import("std").heap.WasmPageAllocator u32) i32 This function increases the size of the Wasm memory identified by index by delta in units of unsigned number of Wasm pages. Note that each Wasm page is 64KB in size. On success, returns previous0 码力 | 241 页 | 7.37 MB | 1 年前3
The Zig Programming Language 0.6.0 Documentationprint(a + b); } $ zig build-lib math.zig -target wasm32-freestanding test.js const fs = require('fs'); const source = fs.readFileSync("./math.wasm"); const typedArray = new Uint8Array(source); WebAssembly warn("{}: {}\n", .{i, arg}); } } $ zig build-exe wasi.zig -target wasm32-wasi $ wasmer run wasi.wasm 123 hello 0: wasi.wasm 1: 123 2: hello Targets Zig supports generating code for all targets v6t2 v5 v5te v4t i386 x86_64 (native) xcore nvptx nvptx64 lanai wasm32 wasm64 Operating Systems: freestanding ananas cloudabi dragonfly freebsd fuchsia ios0 码力 | 214 页 | 5.37 MB | 1 年前3
共 14 条
- 1
- 2













