| ... | @@ -1384,18 +1384,35 @@ fn astGenAsm(self: *Module, scope: *Scope, asm_node: *ast.Node.Asm) InnerError!* | ... | @@ -1384,18 +1384,35 @@ fn astGenAsm(self: *Module, scope: *Scope, asm_node: *ast.Node.Asm) InnerError!* |
| 1384 | fn astGenBuiltinCall(self: *Module, scope: *Scope, call: *ast.Node.BuiltinCall) InnerError!*zir.Inst { | 1384 | fn astGenBuiltinCall(self: *Module, scope: *Scope, call: *ast.Node.BuiltinCall) InnerError!*zir.Inst { |
| 1385 | const tree = scope.tree(); | 1385 | const tree = scope.tree(); |
| 1386 | const builtin_name = tree.tokenSlice(call.builtin_token); | 1386 | const builtin_name = tree.tokenSlice(call.builtin_token); |
| | 1387 | const src = tree.token_locs[call.builtin_token].start; |
| | 1388 | |
| | 1389 | inline for (std.meta.declarations(zir.Inst)) |inst| { |
| | 1390 | if (inst.data != .Type) continue; |
| | 1391 | const T = inst.data.Type; |
| | 1392 | if (!@hasDecl(T, "builtin_name")) continue; |
| | 1393 | if (std.mem.eql(u8, builtin_name, T.builtin_name)) { |
| | 1394 | var value: T = undefined; |
| | 1395 | const positionals = @typeInfo(std.meta.fieldInfo(T, "positionals").field_type).Struct; |
| | 1396 | if (positionals.fields.len == 0) { |
| | 1397 | return self.addZIRInst(scope, src, T, value.positionals, value.kw_args); |
| | 1398 | } |
| | 1399 | const arg_count: ?usize = if (positionals.fields[0].field_type == []*zir.Inst) null else positionals.fields.len; |
| | 1400 | if (arg_count) |some| { |
| | 1401 | if (call.params_len != some) { |
| | 1402 | return self.failTok(scope, call.builtin_token, "expected {} parameter, found {}", .{ some, call.params_len }); |
| | 1403 | } |
| | 1404 | const params = call.params(); |
| | 1405 | inline for (positionals.fields) |p, i| { |
| | 1406 | @field(value.positionals, p.name) = try self.astGenExpr(scope, params[i]); |
| | 1407 | } |
| | 1408 | } else { |
| | 1409 | return self.failTok(scope, call.builtin_token, "TODO var args builtin '{}'", .{builtin_name}); |
| | 1410 | } |
| 1387 | | 1411 | |
| 1388 | if (mem.eql(u8, builtin_name, "@ptrToInt")) { | 1412 | return self.addZIRInst(scope, src, T, value.positionals, .{}); |
| 1389 | if (call.params_len != 1) { | | |
| 1390 | return self.failTok(scope, call.builtin_token, "expected 1 parameter, found {}", .{call.params_len}); | | |
| 1391 | } | 1413 | } |
| 1392 | const src = tree.token_locs[call.builtin_token].start; | | |
| 1393 | return self.addZIRInst(scope, src, zir.Inst.PtrToInt, .{ | | |
| 1394 | .ptr = try self.astGenExpr(scope, call.params()[0]), | | |
| 1395 | }, .{}); | | |
| 1396 | } else { | | |
| 1397 | return self.failTok(scope, call.builtin_token, "TODO implement builtin call for '{}'", .{builtin_name}); | | |
| 1398 | } | 1414 | } |
| | 1415 | return self.failTok(scope, call.builtin_token, "TODO implement builtin call for '{}'", .{builtin_name}); |
| 1399 | } | 1416 | } |
| 1400 | | 1417 | |
| 1401 | fn astGenCall(self: *Module, scope: *Scope, call: *ast.Node.Call) InnerError!*zir.Inst { | 1418 | fn astGenCall(self: *Module, scope: *Scope, call: *ast.Node.Call) InnerError!*zir.Inst { |