@@ -7082,7 +7082,7 @@ fn builtinCall(
7082
7082
.bit_cast = > return bitCast ( gz , scope , rl , node , params [0 ], params [1 ]),
7083
7083
.TypeOf = > return typeOf ( gz , scope , rl , node , params ),
7084
7084
.union_init = > return unionInit (gz , scope , rl , node , params ),
7085
- .c_import = > return cImport ( gz , scope , rl , node , params [0 ]),
7085
+ .c_import = > return cImport ( gz , scope , node , params [0 ]),
7086
7086
7087
7087
.@"export" = > {
7088
7088
const node_tags = tree .nodes .items (.tag );
@@ -7269,6 +7269,7 @@ fn builtinCall(
7269
7269
return rvalue (gz , rl , result , node );
7270
7270
},
7271
7271
.c_define = > {
7272
+ if (! gz .c_import ) return gz .astgen .failNode (node , "C define valid only inside C import block" , .{});
7272
7273
const name = try comptimeExpr (gz , scope , .{ .ty = .const_slice_u8_type }, params [0 ]);
7273
7274
const value = try comptimeExpr (gz , scope , .none , params [1 ]);
7274
7275
const result = try gz .addExtendedPayload (.c_define , Zir.Inst.BinNode {
@@ -7641,6 +7642,8 @@ fn simpleCBuiltin(
7641
7642
operand_node : Ast.Node.Index ,
7642
7643
tag : Zir.Inst.Extended ,
7643
7644
) InnerError ! Zir.Inst.Ref {
7645
+ const name : []const u8 = if (tag == .c_undef ) "C undef" else "C include" ;
7646
+ if (! gz .c_import ) return gz .astgen .failNode (node , "{s} valid only inside C import block" , .{name });
7644
7647
const operand = try comptimeExpr (gz , scope , .{ .ty = .const_slice_u8_type }, operand_node );
7645
7648
_ = try gz .addExtendedPayload (tag , Zir.Inst.UnNode {
7646
7649
.node = gz .nodeIndexToRelative (node ),
@@ -7689,7 +7692,6 @@ fn shiftOp(
7689
7692
fn cImport (
7690
7693
gz : * GenZir ,
7691
7694
scope : * Scope ,
7692
- rl : ResultLoc ,
7693
7695
node : Ast.Node.Index ,
7694
7696
body_node : Ast.Node.Index ,
7695
7697
) InnerError ! Zir.Inst.Ref {
@@ -7698,6 +7700,7 @@ fn cImport(
7698
7700
7699
7701
var block_scope = gz .makeSubBlock (scope );
7700
7702
block_scope .force_comptime = true ;
7703
+ block_scope .c_import = true ;
7701
7704
defer block_scope .instructions .deinit (gpa );
7702
7705
7703
7706
const block_inst = try gz .addBlock (.c_import , node );
@@ -7708,7 +7711,7 @@ fn cImport(
7708
7711
try block_scope .setBlockBody (block_inst );
7709
7712
try gz .instructions .append (gpa , block_inst );
7710
7713
7711
- return rvalue ( gz , rl , .void_value , node );
7714
+ return indexToRef ( block_inst );
7712
7715
}
7713
7716
7714
7717
fn overflowArithmetic (
@@ -9025,6 +9028,7 @@ const GenZir = struct {
9025
9028
base : Scope = Scope { .tag = base_tag },
9026
9029
force_comptime : bool ,
9027
9030
in_defer : bool ,
9031
+ c_import : bool = false ,
9028
9032
/// How decls created in this scope should be named.
9029
9033
anon_name_strategy : Zir.Inst.NameStrategy = .anon ,
9030
9034
/// The containing decl AST node.
@@ -9070,6 +9074,7 @@ const GenZir = struct {
9070
9074
return .{
9071
9075
.force_comptime = gz .force_comptime ,
9072
9076
.in_defer = gz .in_defer ,
9077
+ .c_import = gz .c_import ,
9073
9078
.decl_node_index = gz .decl_node_index ,
9074
9079
.decl_line = gz .decl_line ,
9075
9080
.parent = scope ,
0 commit comments