diff options
| author | Veikka Tuominen <git@vexu.eu> | 2021-09-19 11:51:32 +0300 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-09-20 20:50:55 -0700 |
| commit | 9a54ff72df5cc8631c467f3478117eb85a952ced (patch) | |
| tree | c303fa7cdde3c8165d034da1ed8357175c260e3d /src/AstGen.zig | |
| parent | 1ad905c71e0896295d4781853cd577bbe1b4111a (diff) | |
| download | zig-9a54ff72df5cc8631c467f3478117eb85a952ced.tar.gz zig-9a54ff72df5cc8631c467f3478117eb85a952ced.zip | |
stage2: implement cImport
Diffstat (limited to 'src/AstGen.zig')
| -rw-r--r-- | src/AstGen.zig | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig index f1eabe4c0c..32b62fc3f5 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -7269,6 +7269,7 @@ fn builtinCall( return rvalue(gz, rl, result, node); }, .c_define => { + if (!gz.c_import) return gz.astgen.failNode(node, "C define valid only inside C import block", .{}); const name = try comptimeExpr(gz, scope, .{ .ty = .const_slice_u8_type }, params[0]); const value = try comptimeExpr(gz, scope, .none, params[1]); const result = try gz.addExtendedPayload(.c_define, Zir.Inst.BinNode{ @@ -7641,6 +7642,8 @@ fn simpleCBuiltin( operand_node: Ast.Node.Index, tag: Zir.Inst.Extended, ) InnerError!Zir.Inst.Ref { + const name: []const u8 = if (tag == .c_undef) "C undef" else "C include"; + if (!gz.c_import) return gz.astgen.failNode(node, "{s} valid only inside C import block", .{name}); const operand = try comptimeExpr(gz, scope, .{ .ty = .const_slice_u8_type }, operand_node); _ = try gz.addExtendedPayload(tag, Zir.Inst.UnNode{ .node = gz.nodeIndexToRelative(node), @@ -7698,6 +7701,7 @@ fn cImport( var block_scope = gz.makeSubBlock(scope); block_scope.force_comptime = true; + block_scope.c_import = true; defer block_scope.instructions.deinit(gpa); const block_inst = try gz.addBlock(.c_import, node); @@ -9025,6 +9029,7 @@ const GenZir = struct { base: Scope = Scope{ .tag = base_tag }, force_comptime: bool, in_defer: bool, + c_import: bool = false, /// How decls created in this scope should be named. anon_name_strategy: Zir.Inst.NameStrategy = .anon, /// The containing decl AST node. @@ -9070,6 +9075,7 @@ const GenZir = struct { return .{ .force_comptime = gz.force_comptime, .in_defer = gz.in_defer, + .c_import = gz.c_import, .decl_node_index = gz.decl_node_index, .decl_line = gz.decl_line, .parent = scope, |
