cImport
Function parameters
Parameters
- gz:*GenZir
- scope:*Scope
- node:Ast.Node.Index
- body_node:Ast.Node.Index
Functions in this namespace
Functions
Source
Implementation
fn cImport(
gz: *GenZir,
scope: *Scope,
node: Ast.Node.Index,
body_node: Ast.Node.Index,
) InnerError!Zir.Inst.Ref {
const astgen = gz.astgen;
const gpa = astgen.gpa;
if (gz.c_import) return gz.astgen.failNode(node, "cannot nest @cImport", .{});
var block_scope = gz.makeSubBlock(scope);
block_scope.is_comptime = true;
block_scope.c_import = true;
defer block_scope.unstack();
const block_inst = try gz.makeBlockInst(.c_import, node);
const block_result = try fullBodyExpr(&block_scope, &block_scope.base, .{ .rl = .none }, body_node, .normal);
_ = try gz.addUnNode(.ensure_result_used, block_result, node);
if (!gz.refIsNoReturn(block_result)) {
_ = try block_scope.addBreak(.break_inline, block_inst, .void_value);
}
try block_scope.setBlockBody(block_inst);
// block_scope unstacked now, can add new instructions to gz
try gz.instructions.append(gpa, block_inst);
return block_inst.toRef();
}