| author | |
| committer | |
| log | 7deb1f4f6c038eaef815d5d179633683a9574ff0 |
| tree | fcfabab97a321af087a1bf03a54db3d4108a8a5a |
| parent | a46d24af1cf2885991c67bf39a2e639891c16121 |
4 files changed, 20 insertions(+), 7 deletions(-)
BRANCH_TODO created+2| ... | ... | @@ -0,0 +1,2 @@ |
| 1 | * no need for payload on inferred_alloc for the type | |
| 2 | * compile error for "variable of type '{}' must be const or comptime" after resolving types |
src/astgen.zig+3-3| ... | ... | @@ -625,9 +625,9 @@ fn varDecl( |
| 625 | 625 | const alloc = try addZIRUnOp(mod, scope, name_src, .alloc_mut, type_inst); |
| 626 | 626 | break :a .{ .alloc = alloc, .result_loc = .{ .ptr = alloc } }; |
| 627 | 627 | } else a: { |
| 628 | const alloc = try addZIRNoOp(mod, scope, name_src, .alloc_inferred_mut); | |
| 629 | resolve_inferred_alloc = alloc; | |
| 630 | break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc.castTag(.alloc_inferred_mut).? } }; | |
| 628 | const alloc = try addZIRNoOpT(mod, scope, name_src, .alloc_inferred); | |
| 629 | resolve_inferred_alloc = &alloc.base; | |
| 630 | break :a .{ .alloc = &alloc.base, .result_loc = .{ .inferred_ptr = alloc } }; | |
| 631 | 631 | }; |
| 632 | 632 | const init_inst = try expr(mod, scope, var_data.result_loc, init_node); |
| 633 | 633 | if (resolve_inferred_alloc) |inst| { |
src/codegen/c.zig+11-2| ... | ... | @@ -275,7 +275,6 @@ pub fn generate(file: *C, module: *Module, decl: *Decl) !void { |
| 275 | 275 | try writer.writeAll(" {"); |
| 276 | 276 | |
| 277 | 277 | const func: *Module.Fn = func_payload.data; |
| 278 | //func.dump(module.*); | |
| 279 | 278 | const instructions = func.analysis.success.instructions; |
| 280 | 279 | if (instructions.len > 0) { |
| 281 | 280 | try writer.writeAll("\n"); |
| ... | ... | @@ -297,6 +296,7 @@ pub fn generate(file: *C, module: *Module, decl: *Decl) !void { |
| 297 | 296 | .cmp_neq => try genBinOp(&ctx, file, inst.castTag(.cmp_neq).?, "!="), |
| 298 | 297 | .dbg_stmt => try genDbgStmt(&ctx, inst.castTag(.dbg_stmt).?), |
| 299 | 298 | .intcast => try genIntCast(&ctx, file, inst.castTag(.intcast).?), |
| 299 | .load => try genLoad(&ctx, file, inst.castTag(.load).?), | |
| 300 | 300 | .ret => try genRet(&ctx, file, inst.castTag(.ret).?), |
| 301 | 301 | .retvoid => try genRetVoid(file), |
| 302 | 302 | .store => try genStore(&ctx, file, inst.castTag(.store).?), |
| ... | ... | @@ -431,6 +431,16 @@ fn genRetVoid(file: *C) !?[]u8 { |
| 431 | 431 | return null; |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | fn genLoad(ctx: *Context, file: *C, inst: *Inst.UnOp) !?[]u8 { | |
| 435 | const operand = try ctx.resolveInst(inst.operand); | |
| 436 | const writer = file.main.writer(); | |
| 437 | try indent(file); | |
| 438 | const local_name = try ctx.name(); | |
| 439 | try renderTypeAndName(ctx, writer, inst.base.ty, local_name, .Const); | |
| 440 | try writer.print(" = *{s};\n", .{operand}); | |
| 441 | return local_name; | |
| 442 | } | |
| 443 | ||
| 434 | 444 | fn genRet(ctx: *Context, file: *C, inst: *Inst.UnOp) !?[]u8 { |
| 435 | 445 | try indent(file); |
| 436 | 446 | const writer = file.main.writer(); |
| ... | ... | @@ -442,7 +452,6 @@ fn genIntCast(ctx: *Context, file: *C, inst: *Inst.UnOp) !?[]u8 { |
| 442 | 452 | if (inst.base.isUnused()) |
| 443 | 453 | return null; |
| 444 | 454 | try indent(file); |
| 445 | const op = inst.operand; | |
| 446 | 455 | const writer = file.main.writer(); |
| 447 | 456 | const name = try ctx.name(); |
| 448 | 457 | const from = try ctx.resolveInst(inst.operand); |
test/stage2/cbe.zig+4-2| ... | ... | @@ -52,7 +52,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | { |
| 55 | var case = ctx.exeFromCompiledC("inferred local const", .{}); | |
| 55 | var case = ctx.exeFromCompiledC("inferred local const and var", .{}); | |
| 56 | 56 | |
| 57 | 57 | case.addCompareOutput( |
| 58 | 58 | \\fn add(a: i32, b: i32) i32 { |
| ... | ... | @@ -61,7 +61,9 @@ pub fn addCases(ctx: *TestContext) !void { |
| 61 | 61 | \\ |
| 62 | 62 | \\export fn main() c_int { |
| 63 | 63 | \\ const x = add(1, 2); |
| 64 | \\ return x - 3; | |
| 64 | \\ var y = add(3, 0); | |
| 65 | \\ y -= x; | |
| 66 | \\ return y; | |
| 65 | 67 | \\} |
| 66 | 68 | , ""); |
| 67 | 69 | } |