| ... | ... | @@ -510,6 +510,10 @@ pub const Context = struct { |
| 510 | 510 | locals: std.ArrayListUnmanaged(u8), |
| 511 | 511 | /// The Target we're emitting (used to call intInfo) |
| 512 | 512 | target: std.Target, |
| 513 | /// Table with the global error set. Consists of every error found in |
| 514 | /// the compiled code. Each error name maps to a `Module.ErrorInt` which is emitted |
| 515 | /// during codegen to determine the error value. |
| 516 | global_error_set: std.StringHashMapUnmanaged(Module.ErrorInt), |
| 513 | 517 | |
| 514 | 518 | const InnerError = error{ |
| 515 | 519 | OutOfMemory, |
| ... | ... | @@ -559,7 +563,6 @@ pub const Context = struct { |
| 559 | 563 | if (info.bits > 32 and info.bits <= 64) break :blk wasm.Valtype.i64; |
| 560 | 564 | return self.fail(src, "Integer bit size not supported by wasm: '{d}'", .{info.bits}); |
| 561 | 565 | }, |
| 562 | | .Bool, .Pointer, .Struct => wasm.Valtype.i32, |
| 563 | 566 | .Enum => switch (ty.tag()) { |
| 564 | 567 | .enum_simple => wasm.Valtype.i32, |
| 565 | 568 | else => self.typeToValtype( |
| ... | ... | @@ -567,6 +570,11 @@ pub const Context = struct { |
| 567 | 570 | ty.cast(Type.Payload.EnumFull).?.data.tag_ty, |
| 568 | 571 | ), |
| 569 | 572 | }, |
| 573 | .Bool, |
| 574 | .Pointer, |
| 575 | .Struct, |
| 576 | .ErrorSet, |
| 577 | => wasm.Valtype.i32, |
| 570 | 578 | else => self.fail(src, "TODO - Wasm valtype for type '{s}'", .{ty.zigTypeTag()}), |
| 571 | 579 | }; |
| 572 | 580 | } |
| ... | ... | @@ -959,6 +967,11 @@ pub const Context = struct { |
| 959 | 967 | try self.emitConstant(src, value, int_tag_ty); |
| 960 | 968 | } |
| 961 | 969 | }, |
| 970 | .ErrorSet => { |
| 971 | const error_index = self.global_error_set.get(value.getError().?).?; |
| 972 | try writer.writeByte(wasm.opcode(.i32_const)); |
| 973 | try leb.writeULEB128(writer, error_index); |
| 974 | }, |
| 962 | 975 | else => |zig_type| return self.fail(src, "Wasm TODO: emitConstant for zigTypeTag {s}", .{zig_type}), |
| 963 | 976 | } |
| 964 | 977 | } |