Added support for global variables

This commit is contained in:
luccie-cmd 2025-08-04 19:21:12 +02:00
parent 1da655d164
commit 94195fc774
5 changed files with 158 additions and 52 deletions

View file

@ -723,6 +723,18 @@ const IRParserState = struct {
try self.fix_branches_for_block(start, end, jump_addr);
}
fn parseGlobal(self: *IRParserState) !void {
while (true) {
const op = self.parser.peek() orelse return Parser.Error.unterminated_wasm;
if (op == 0x0B) {
_ = try self.parser.readByte();
break;
} else {
try self.parseExpression();
}
}
}
fn parseIf(self: *IRParserState) !void {
// TODO: Should we do something with this?
_ = try self.parseBlockType();
@ -831,3 +843,19 @@ pub fn parse(parser: *Parser) !IR {
.select_valtypes = &.{},
};
}
pub fn parseGlobalExpr(parser: *Parser) !IR {
var state = IRParserState{
.opcodes = .{},
.indices = .{},
.branches = .{},
.parser = parser,
.allocator = parser.allocator,
};
try state.parseGlobal();
return .{
.opcodes = try state.opcodes.toOwnedSlice(state.allocator),
.indices = try state.indices.toOwnedSlice(state.allocator),
.select_valtypes = &.{},
};
}