adding types opcodes

This commit is contained in:
2026-01-01 04:18:11 +01:00
parent 3283ed42a8
commit c228d86e91
4 changed files with 301 additions and 57 deletions

View File

@@ -1,6 +1,8 @@
const std = @import("std");
const spv = @import("spv.zig");
const RuntimeError = @import("Runtime.zig").RuntimeError;
const SpvWord = spv.SpvWord;
const Self = @This();
@@ -15,16 +17,22 @@ pub fn init(buffer: []const SpvWord) Self {
};
}
pub fn next(self: *Self) ?SpvWord {
pub fn nextOrNull(self: *Self) ?SpvWord {
const word = self.peek() orelse return null;
self.index += 1;
return word;
}
pub fn nextAs(self: *Self, comptime E: type) ?E {
const word = self.peek() orelse return null;
self.index += 1;
return std.enums.fromInt(E, word);
pub inline fn nextAsOrNull(self: *Self, comptime E: type) ?E {
return if (self.nextOrNull()) |word| std.enums.fromInt(E, word) else null;
}
pub inline fn next(self: *Self) RuntimeError!SpvWord {
return self.nextOrNull() orelse return RuntimeError.InvalidSpirV;
}
pub fn nextAs(self: *Self, comptime E: type) RuntimeError!E {
return self.nextAsOrNull(E) orelse return RuntimeError.InvalidSpirV;
}
pub fn peek(self: *const Self) ?SpvWord {