Commit ab8a9a6605
Changed files (4)
src-self-hosted
test
stage2
src-self-hosted/astgen.zig
@@ -1223,9 +1223,10 @@ fn identifier(mod: *Module, scope: *Scope, rl: ResultLoc, ident: *ast.Node.OneTo
}
if (mod.lookupDeclName(scope, ident_name)) |decl| {
- // TODO handle lvalues
const result = try addZIRInst(mod, scope, src, zir.Inst.DeclValInModule, .{ .decl = decl }, .{});
- return rlWrap(mod, scope, rl, result);
+ if (rl == .lvalue or rl == .ref)
+ return result;
+ return rlWrap(mod, scope, rl, try addZIRUnOp(mod, scope, src, .deref, result));
}
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
// line lengths and new lines
var len = lines.len - 1;
for (lines) |line| {
- len += tree.tokenSlice(line).len - 2;
+ // 2 for the '//' + 1 for '\n'
+ len += tree.tokenSlice(line).len - 3;
}
const bytes = try scope.arena().alloc(u8, len);
@@ -1268,9 +1270,9 @@ fn multilineStrLiteral(mod: *Module, scope: *Scope, node: *ast.Node.MultilineStr
bytes[i] = '\n';
i += 1;
}
- const slice = tree.tokenSlice(line)[2..];
- mem.copy(u8, bytes[i..], slice);
- i += slice.len;
+ const slice = tree.tokenSlice(line);
+ mem.copy(u8, bytes[i..], slice[2..slice.len - 1]);
+ i += slice.len - 3;
}
return addZIRInst(mod, scope, src, zir.Inst.Str, .{ .bytes = bytes }, .{});
src-self-hosted/type.zig
@@ -457,7 +457,8 @@ pub const Type = extern union {
try param_type.format("", .{}, out_stream);
}
try out_stream.writeAll(") ");
- try payload.return_type.format("", .{}, out_stream);
+ ty = payload.return_type;
+ continue;
},
.array_u8 => {
src-self-hosted/zir_sema.zig
@@ -581,8 +581,7 @@ fn analyzeInstDeclVal(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclVal) Inne
fn analyzeInstDeclValInModule(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclValInModule) InnerError!*Inst {
const decl = inst.positionals.decl;
- const ptr = try mod.analyzeDeclRef(scope, inst.base.src, decl);
- return mod.analyzeDeref(scope, inst.base.src, ptr, inst.base.src);
+ return mod.analyzeDeclRef(scope, inst.base.src, decl);
}
fn analyzeInstCall(mod: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerError!*Inst {
test/stage2/compare_output.zig
@@ -617,6 +617,37 @@ pub fn addCases(ctx: *TestContext) !void {
,
"",
);
+
+ case.addCompareOutput(
+ \\export fn _start() noreturn {
+ \\ add(aa, bb);
+ \\
+ \\ exit();
+ \\}
+ \\
+ \\const aa = 'ぁ';
+ \\const bb = '\x03';
+ \\
+ \\fn add(a: u32, b: u32) void {
+ \\ assert(a + b == 12356);
+ \\}
+ \\
+ \\pub fn assert(ok: bool) void {
+ \\ if (!ok) unreachable; // assertion failure
+ \\}
+ \\
+ \\fn exit() noreturn {
+ \\ asm volatile ("syscall"
+ \\ :
+ \\ : [number] "{rax}" (231),
+ \\ [arg1] "{rdi}" (0)
+ \\ : "rcx", "r11", "memory"
+ \\ );
+ \\ unreachable;
+ \\}
+ ,
+ "",
+ );
}
{