| author | |
| committer | |
| log | ab8a9a6605900fc0b064c321504ac4e7dc1ca6f4 |
| tree | 46b5cd9da18d8df31b60756eab2347de1b62896b |
| parent | 338a495648f07a2734e012034fd301a0e77f8202 |
4 files changed, 42 insertions(+), 9 deletions(-)
src-self-hosted/astgen.zig+8-6| ... | ... | @@ -1223,9 +1223,10 @@ fn identifier(mod: *Module, scope: *Scope, rl: ResultLoc, ident: *ast.Node.OneTo |
| 1223 | 1223 | } |
| 1224 | 1224 | |
| 1225 | 1225 | if (mod.lookupDeclName(scope, ident_name)) |decl| { |
| 1226 | // TODO handle lvalues | |
| 1227 | 1226 | const result = try addZIRInst(mod, scope, src, zir.Inst.DeclValInModule, .{ .decl = decl }, .{}); |
| 1228 | return rlWrap(mod, scope, rl, result); | |
| 1227 | if (rl == .lvalue or rl == .ref) | |
| 1228 | return result; | |
| 1229 | return rlWrap(mod, scope, rl, try addZIRUnOp(mod, scope, src, .deref, result)); | |
| 1229 | 1230 | } |
| 1230 | 1231 | |
| 1231 | 1232 | return mod.failNode(scope, &ident.base, "use of undeclared identifier '{}'", .{ident_name}); |
| ... | ... | @@ -1258,7 +1259,8 @@ fn multilineStrLiteral(mod: *Module, scope: *Scope, node: *ast.Node.MultilineStr |
| 1258 | 1259 | // line lengths and new lines |
| 1259 | 1260 | var len = lines.len - 1; |
| 1260 | 1261 | for (lines) |line| { |
| 1261 | len += tree.tokenSlice(line).len - 2; | |
| 1262 | // 2 for the '//' + 1 for '\n' | |
| 1263 | len += tree.tokenSlice(line).len - 3; | |
| 1262 | 1264 | } |
| 1263 | 1265 | |
| 1264 | 1266 | const bytes = try scope.arena().alloc(u8, len); |
| ... | ... | @@ -1268,9 +1270,9 @@ fn multilineStrLiteral(mod: *Module, scope: *Scope, node: *ast.Node.MultilineStr |
| 1268 | 1270 | bytes[i] = '\n'; |
| 1269 | 1271 | i += 1; |
| 1270 | 1272 | } |
| 1271 | const slice = tree.tokenSlice(line)[2..]; | |
| 1272 | mem.copy(u8, bytes[i..], slice); | |
| 1273 | i += slice.len; | |
| 1273 | const slice = tree.tokenSlice(line); | |
| 1274 | mem.copy(u8, bytes[i..], slice[2..slice.len - 1]); | |
| 1275 | i += slice.len - 3; | |
| 1274 | 1276 | } |
| 1275 | 1277 | |
| 1276 | 1278 | return addZIRInst(mod, scope, src, zir.Inst.Str, .{ .bytes = bytes }, .{}); |
src-self-hosted/type.zig+2-1| ... | ... | @@ -457,7 +457,8 @@ pub const Type = extern union { |
| 457 | 457 | try param_type.format("", .{}, out_stream); |
| 458 | 458 | } |
| 459 | 459 | try out_stream.writeAll(") "); |
| 460 | try payload.return_type.format("", .{}, out_stream); | |
| 460 | ty = payload.return_type; | |
| 461 | continue; | |
| 461 | 462 | }, |
| 462 | 463 | |
| 463 | 464 | .array_u8 => { |
src-self-hosted/zir_sema.zig+1-2| ... | ... | @@ -581,8 +581,7 @@ fn analyzeInstDeclVal(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclVal) Inne |
| 581 | 581 | |
| 582 | 582 | fn analyzeInstDeclValInModule(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclValInModule) InnerError!*Inst { |
| 583 | 583 | const decl = inst.positionals.decl; |
| 584 | const ptr = try mod.analyzeDeclRef(scope, inst.base.src, decl); | |
| 585 | return mod.analyzeDeref(scope, inst.base.src, ptr, inst.base.src); | |
| 584 | return mod.analyzeDeclRef(scope, inst.base.src, decl); | |
| 586 | 585 | } |
| 587 | 586 | |
| 588 | 587 | fn analyzeInstCall(mod: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerError!*Inst { |
test/stage2/compare_output.zig+31| ... | ... | @@ -617,6 +617,37 @@ pub fn addCases(ctx: *TestContext) !void { |
| 617 | 617 | , |
| 618 | 618 | "", |
| 619 | 619 | ); |
| 620 | ||
| 621 | case.addCompareOutput( | |
| 622 | \\export fn _start() noreturn { | |
| 623 | \\ add(aa, bb); | |
| 624 | \\ | |
| 625 | \\ exit(); | |
| 626 | \\} | |
| 627 | \\ | |
| 628 | \\const aa = 'ぁ'; | |
| 629 | \\const bb = '\x03'; | |
| 630 | \\ | |
| 631 | \\fn add(a: u32, b: u32) void { | |
| 632 | \\ assert(a + b == 12356); | |
| 633 | \\} | |
| 634 | \\ | |
| 635 | \\pub fn assert(ok: bool) void { | |
| 636 | \\ if (!ok) unreachable; // assertion failure | |
| 637 | \\} | |
| 638 | \\ | |
| 639 | \\fn exit() noreturn { | |
| 640 | \\ asm volatile ("syscall" | |
| 641 | \\ : | |
| 642 | \\ : [number] "{rax}" (231), | |
| 643 | \\ [arg1] "{rdi}" (0) | |
| 644 | \\ : "rcx", "r11", "memory" | |
| 645 | \\ ); | |
| 646 | \\ unreachable; | |
| 647 | \\} | |
| 648 | , | |
| 649 | "", | |
| 650 | ); | |
| 620 | 651 | } |
| 621 | 652 | |
| 622 | 653 | { |