| ... | @@ -17,6 +17,7 @@ pub const Inst = struct { | ... | @@ -17,6 +17,7 @@ pub const Inst = struct { |
| 17 | @"asm", | 17 | @"asm", |
| 18 | @"unreachable", | 18 | @"unreachable", |
| 19 | @"fn", | 19 | @"fn", |
| | 20 | @"export", |
| 20 | }; | 21 | }; |
| 21 | | 22 | |
| 22 | pub fn TagToType(tag: Tag) type { | 23 | pub fn TagToType(tag: Tag) type { |
| ... | @@ -26,8 +27,9 @@ pub const Inst = struct { | ... | @@ -26,8 +27,9 @@ pub const Inst = struct { |
| 26 | .fieldptr => FieldPtr, | 27 | .fieldptr => FieldPtr, |
| 27 | .deref => Deref, | 28 | .deref => Deref, |
| 28 | .@"asm" => Assembly, | 29 | .@"asm" => Assembly, |
| 29 | .@"unreachable" => Unreach, | 30 | .@"unreachable" => Unreachable, |
| 30 | .@"fn" => Fn, | 31 | .@"fn" => Fn, |
| | 32 | .@"export" => Export, |
| 31 | }; | 33 | }; |
| 32 | } | 34 | } |
| 33 | | 35 | |
| ... | @@ -87,8 +89,8 @@ pub const Inst = struct { | ... | @@ -87,8 +89,8 @@ pub const Inst = struct { |
| 87 | }, | 89 | }, |
| 88 | }; | 90 | }; |
| 89 | | 91 | |
| 90 | pub const Unreach = struct { | 92 | pub const Unreachable = struct { |
| 91 | base: Inst = Inst{ .tag = .unreach }, | 93 | base: Inst = Inst{ .tag = .@"unreachable" }, |
| 92 | | 94 | |
| 93 | positionals: struct {}, | 95 | positionals: struct {}, |
| 94 | kw_args: struct {}, | 96 | kw_args: struct {}, |
| ... | @@ -108,6 +110,16 @@ pub const Inst = struct { | ... | @@ -108,6 +110,16 @@ pub const Inst = struct { |
| 108 | instructions: []*Inst, | 110 | instructions: []*Inst, |
| 109 | }; | 111 | }; |
| 110 | }; | 112 | }; |
| | 113 | |
| | 114 | pub const Export = struct { |
| | 115 | base: Inst = Inst{ .tag = .@"export" }, |
| | 116 | |
| | 117 | positionals: struct { |
| | 118 | symbol_name: *Inst, |
| | 119 | value: *Inst, |
| | 120 | }, |
| | 121 | kw_args: struct {}, |
| | 122 | }; |
| 111 | }; | 123 | }; |
| 112 | | 124 | |
| 113 | pub const ErrorMsg = struct { | 125 | pub const ErrorMsg = struct { |
| ... | @@ -319,7 +331,6 @@ fn parseParameterGeneric(ctx: *ParseContext, comptime T: type, body_ctx: ?*BodyC | ... | @@ -319,7 +331,6 @@ fn parseParameterGeneric(ctx: *ParseContext, comptime T: type, body_ctx: ?*BodyC |
| 319 | while (ctx.i < ctx.source.len) : (ctx.i += 1) switch (ctx.source[ctx.i]) { | 331 | while (ctx.i < ctx.source.len) : (ctx.i += 1) switch (ctx.source[ctx.i]) { |
| 320 | ' ', '\n', ',', ')' => { | 332 | ' ', '\n', ',', ')' => { |
| 321 | const enum_name = ctx.source[start..ctx.i]; | 333 | const enum_name = ctx.source[start..ctx.i]; |
| 322 | ctx.i += 1; | | |
| 323 | return std.meta.stringToEnum(T, enum_name) orelse { | 334 | return std.meta.stringToEnum(T, enum_name) orelse { |
| 324 | return parseError(ctx, "tag '{}' not a member of enum '{}'", .{ enum_name, @typeName(T) }); | 335 | return parseError(ctx, "tag '{}' not a member of enum '{}'", .{ enum_name, @typeName(T) }); |
| 325 | }; | 336 | }; |
| ... | @@ -427,6 +438,10 @@ fn parseBody(ctx: *ParseContext) !Inst.Fn.Body { | ... | @@ -427,6 +438,10 @@ fn parseBody(ctx: *ParseContext) !Inst.Fn.Body { |
| 427 | continue; | 438 | continue; |
| 428 | }, | 439 | }, |
| 429 | ' ', '\n' => continue, | 440 | ' ', '\n' => continue, |
| | 441 | '}' => { |
| | 442 | ctx.i += 1; |
| | 443 | break; |
| | 444 | }, |
| 430 | else => |byte| return parseError(ctx, "unexpected byte: '{c}'", .{byte}), | 445 | else => |byte| return parseError(ctx, "unexpected byte: '{c}'", .{byte}), |
| 431 | }; | 446 | }; |
| 432 | | 447 | |