haku2: on the client
resource indicators are currently unimplemented
This commit is contained in:
parent
45c954cb03
commit
e667c6336a
10 changed files with 437 additions and 364 deletions
|
@ -10,7 +10,7 @@ const value = @import("value.zig");
|
|||
const Vm = @import("vm.zig");
|
||||
const log = @import("log.zig");
|
||||
|
||||
const debug_logs = false;
|
||||
const debug_logs = true;
|
||||
|
||||
pub const allocator =
|
||||
if (builtin.cpu.arch == .wasm32)
|
||||
|
@ -23,6 +23,16 @@ pub const std_options: std.Options = .{
|
|||
.logFn = log.logFn,
|
||||
};
|
||||
|
||||
// Allocator
|
||||
|
||||
export fn haku2_alloc(size: usize, alignment: usize) ?[*]u8 {
|
||||
return allocator.rawAlloc(size, mem.Alignment.fromByteUnits(alignment), @returnAddress());
|
||||
}
|
||||
|
||||
export fn haku2_free(alloc: [*]u8, size: usize, alignment: usize) void {
|
||||
allocator.rawFree(alloc[0..size], mem.Alignment.fromByteUnits(alignment), @returnAddress());
|
||||
}
|
||||
|
||||
// Scratch
|
||||
|
||||
export fn haku2_scratch_new(max: usize) ?*Scratch {
|
||||
|
|
|
@ -9,6 +9,8 @@ use std::{
|
|||
|
||||
use log::trace;
|
||||
|
||||
pub static WASM: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/zig-out/bin/haku2.wasm"));
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn __haku2_alloc(size: usize, align: usize) -> *mut u8 {
|
||||
if let Ok(layout) = Layout::from_size_align(size, align) {
|
||||
|
|
|
@ -60,7 +60,7 @@ pub fn reset(vm: *Vm, fuel: u32) void {
|
|||
}
|
||||
|
||||
pub fn throw(vm: *Vm, comptime fmt: []const u8, args: anytype) Error {
|
||||
log.debug("throw: fmt={s}", .{fmt});
|
||||
log.info("throw: fmt={s}", .{fmt});
|
||||
|
||||
const Args = @TypeOf(args);
|
||||
const max_args_size = @sizeOf(@TypeOf(vm.exception.?.args));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue