| author | |
| committer | |
| log | c234761eddc2fe932046767756b9e6df82a73b65 |
| tree | 959a1873c66019485873a425fd5a915b490871ed |
| parent | fffb0904f898d47800aa418085dc6064d02c32fe |
| signature | Signed by PGP key 4AEE18F83AFDEB23 |
3 files changed, 26 insertions(+), 6 deletions(-)
src/astgen.zig+3-3| ... | ... | @@ -616,11 +616,11 @@ fn varDecl( |
| 616 | 616 | .Keyword_var => { |
| 617 | 617 | const var_data: struct { result_loc: ResultLoc, alloc: *zir.Inst } = if (node.getTypeNode()) |type_node| a: { |
| 618 | 618 | const type_inst = try typeExpr(mod, scope, type_node); |
| 619 | const alloc = try addZIRUnOp(mod, scope, name_src, .alloc, type_inst); | |
| 619 | const alloc = try addZIRUnOp(mod, scope, name_src, .alloc_mut, type_inst); | |
| 620 | 620 | break :a .{ .alloc = alloc, .result_loc = .{ .ptr = alloc } }; |
| 621 | 621 | } else a: { |
| 622 | const alloc = try addZIRNoOp(mod, scope, name_src, .alloc_inferred); | |
| 623 | break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc.castTag(.alloc_inferred).? } }; | |
| 622 | const alloc = try addZIRNoOp(mod, scope, name_src, .alloc_inferred_mut); | |
| 623 | break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc.castTag(.alloc_inferred_mut).? } }; | |
| 624 | 624 | }; |
| 625 | 625 | const init_inst = try expr(mod, scope, var_data.result_loc, init_node); |
| 626 | 626 | const sub_scope = try block_arena.create(Scope.LocalPtr); |
src/zir.zig+10-2| ... | ... | @@ -41,8 +41,12 @@ pub const Inst = struct { |
| 41 | 41 | /// Allocates stack local memory. Its lifetime ends when the block ends that contains |
| 42 | 42 | /// this instruction. The operand is the type of the allocated object. |
| 43 | 43 | alloc, |
| 44 | /// Same as `alloc` except mutable. | |
| 45 | alloc_mut, | |
| 44 | 46 | /// Same as `alloc` except the type is inferred. |
| 45 | 47 | alloc_inferred, |
| 48 | /// Same as `alloc_inferred` except mutable. | |
| 49 | alloc_inferred_mut, | |
| 46 | 50 | /// Create an `anyframe->T`. |
| 47 | 51 | anyframe_type, |
| 48 | 52 | /// Array concatenation. `a ++ b` |
| ... | ... | @@ -289,16 +293,19 @@ pub const Inst = struct { |
| 289 | 293 | |
| 290 | 294 | pub fn Type(tag: Tag) type { |
| 291 | 295 | return switch (tag) { |
| 296 | .alloc_inferred, | |
| 297 | .alloc_inferred_mut, | |
| 292 | 298 | .breakpoint, |
| 293 | 299 | .dbg_stmt, |
| 294 | 300 | .returnvoid, |
| 295 | .alloc_inferred, | |
| 296 | 301 | .ret_ptr, |
| 297 | 302 | .ret_type, |
| 298 | 303 | .unreach_nocheck, |
| 299 | 304 | .@"unreachable", |
| 300 | 305 | => NoOp, |
| 301 | 306 | |
| 307 | .alloc, | |
| 308 | .alloc_mut, | |
| 302 | 309 | .boolnot, |
| 303 | 310 | .compileerror, |
| 304 | 311 | .deref, |
| ... | ... | @@ -307,7 +314,6 @@ pub const Inst = struct { |
| 307 | 314 | .isnonnull, |
| 308 | 315 | .iserr, |
| 309 | 316 | .ptrtoint, |
| 310 | .alloc, | |
| 311 | 317 | .ensure_result_used, |
| 312 | 318 | .ensure_result_non_error, |
| 313 | 319 | .ensure_indexable, |
| ... | ... | @@ -419,7 +425,9 @@ pub const Inst = struct { |
| 419 | 425 | .add, |
| 420 | 426 | .addwrap, |
| 421 | 427 | .alloc, |
| 428 | .alloc_mut, | |
| 422 | 429 | .alloc_inferred, |
| 430 | .alloc_inferred_mut, | |
| 423 | 431 | .array_cat, |
| 424 | 432 | .array_mul, |
| 425 | 433 | .array_type, |
src/zir_sema.zig+13-1| ... | ... | @@ -27,7 +27,9 @@ const Decl = Module.Decl; |
| 27 | 27 | pub fn analyzeInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError!*Inst { |
| 28 | 28 | switch (old_inst.tag) { |
| 29 | 29 | .alloc => return analyzeInstAlloc(mod, scope, old_inst.castTag(.alloc).?), |
| 30 | .alloc_mut => return analyzeInstAllocMut(mod, scope, old_inst.castTag(.alloc_mut).?), | |
| 30 | 31 | .alloc_inferred => return analyzeInstAllocInferred(mod, scope, old_inst.castTag(.alloc_inferred).?), |
| 32 | .alloc_inferred_mut => return analyzeInstAllocInferredMut(mod, scope, old_inst.castTag(.alloc_inferred_mut).?), | |
| 31 | 33 | .arg => return analyzeInstArg(mod, scope, old_inst.castTag(.arg).?), |
| 32 | 34 | .bitcast_ref => return analyzeInstBitCastRef(mod, scope, old_inst.castTag(.bitcast_ref).?), |
| 33 | 35 | .bitcast_result_ptr => return analyzeInstBitCastResultPtr(mod, scope, old_inst.castTag(.bitcast_result_ptr).?), |
| ... | ... | @@ -410,7 +412,13 @@ fn analyzeInstEnsureIndexable(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) |
| 410 | 412 | |
| 411 | 413 | fn analyzeInstAlloc(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst { |
| 412 | 414 | const var_type = try resolveType(mod, scope, inst.positionals.operand); |
| 413 | // TODO this should happen only for var allocs | |
| 415 | const ptr_type = try mod.simplePtrType(scope, inst.base.src, var_type, true, .One); | |
| 416 | const b = try mod.requireRuntimeBlock(scope, inst.base.src); | |
| 417 | return mod.addNoOp(b, inst.base.src, ptr_type, .alloc); | |
| 418 | } | |
| 419 | ||
| 420 | fn analyzeInstAllocMut(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst { | |
| 421 | const var_type = try resolveType(mod, scope, inst.positionals.operand); | |
| 414 | 422 | if (!var_type.isValidVarType(false)) { |
| 415 | 423 | return mod.fail(scope, inst.base.src, "variable of type '{}' must be const or comptime", .{var_type}); |
| 416 | 424 | } |
| ... | ... | @@ -423,6 +431,10 @@ fn analyzeInstAllocInferred(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) I |
| 423 | 431 | return mod.fail(scope, inst.base.src, "TODO implement analyzeInstAllocInferred", .{}); |
| 424 | 432 | } |
| 425 | 433 | |
| 434 | fn analyzeInstAllocInferredMut(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst { | |
| 435 | return mod.fail(scope, inst.base.src, "TODO implement analyzeInstAllocInferredMut", .{}); | |
| 436 | } | |
| 437 | ||
| 426 | 438 | fn analyzeInstStore(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst { |
| 427 | 439 | const ptr = try resolveInst(mod, scope, inst.positionals.lhs); |
| 428 | 440 | const value = try resolveInst(mod, scope, inst.positionals.rhs); |