authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-06-19 20:52:06+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-06-22 23:19:12-04:00
log7b68385d7d4448e81cc882d9a5464bf58d10dc0d
treed70ca9aeb6a4d939d74388c2a8b0ea6ffb7a8804
parentd98aed6eff61628f97597e1fa68335db5b2fd466

self-hosted: astGenIntegerLiteral support other bases


1 files changed, 12 insertions(+), 9 deletions(-)

src-self-hosted/Module.zig+12-9
......@@ -1314,16 +1314,19 @@ fn astGenStringLiteral(self: *Module, scope: *Scope, str_lit: *ast.Node.StringLi
13141314fn astGenIntegerLiteral(self: *Module, scope: *Scope, int_lit: *ast.Node.IntegerLiteral) InnerError!*zir.Inst {
13151315 const arena = scope.arena();
13161316 const tree = scope.tree();
1317 const bytes = tree.tokenSlice(int_lit.token);
1317 var bytes = tree.tokenSlice(int_lit.token);
1318 const base = if (mem.startsWith(u8, bytes, "0x"))
1319 16
1320 else if (mem.startsWith(u8, bytes, "0o"))
1321 8
1322 else if (mem.startsWith(u8, bytes, "0b"))
1323 2
1324 else
1325 @as(u8, 10);
13181326
1319 if (mem.startsWith(u8, bytes, "0x")) {
1320 return self.failTok(scope, int_lit.token, "TODO implement 0x int prefix", .{});
1321 } else if (mem.startsWith(u8, bytes, "0o")) {
1322 return self.failTok(scope, int_lit.token, "TODO implement 0o int prefix", .{});
1323 } else if (mem.startsWith(u8, bytes, "0b")) {
1324 return self.failTok(scope, int_lit.token, "TODO implement 0b int prefix", .{});
1325 }
1326 if (std.fmt.parseInt(u64, bytes, 10)) |small_int| {
1327 if (base != 10) bytes = bytes[2..];
1328
1329 if (std.fmt.parseInt(u64, bytes, base)) |small_int| {
13271330 const int_payload = try arena.create(Value.Payload.Int_u64);
13281331 int_payload.* = .{ .int = small_int };
13291332 const src = tree.token_locs[int_lit.token].start;