authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-03-26 15:41:49+01:00
committergravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-03-26 15:46:50+01:00
log22338d781679f3210fe599a4a4972d4835589adb
treed61ecac710a877a8a6722c581723296870b0c55b
parentd8ee8794e16d2ab1b574089e0457ce230da117f5
signature Commit is signed but in an unrecognized format.

astgen: implement float literals


1 files changed, 11 insertions(+), 5 deletions(-)

src/astgen.zig+11-5
......@@ -2959,26 +2959,32 @@ fn floatLiteral(
29592959 mod: *Module,
29602960 scope: *Scope,
29612961 rl: ResultLoc,
2962 float_lit: ast.Node.Index,
2962 node: ast.Node.Index,
29632963) InnerError!zir.Inst.Ref {
2964 if (true) @panic("TODO update for zir-memory-layout");
29652964 const arena = scope.arena();
29662965 const tree = scope.tree();
29672966 const main_tokens = tree.nodes.items(.main_token);
2967 const gz = scope.getGenZir();
29682968
2969 const main_token = main_tokens[float_lit];
2969 const main_token = main_tokens[node];
29702970 const bytes = tree.tokenSlice(main_token);
29712971 if (bytes.len > 2 and bytes[1] == 'x') {
2972 assert(bytes[0] == '0'); // validated by tokenizer
29722973 return mod.failTok(scope, main_token, "TODO implement hex floats", .{});
29732974 }
29742975 const float_number = std.fmt.parseFloat(f128, bytes) catch |e| switch (e) {
29752976 error.InvalidCharacter => unreachable, // validated by tokenizer
29762977 };
2977 const result = try addZIRInstConst(mod, scope, src, .{
2978 const typed_value = try arena.create(TypedValue);
2979 typed_value.* = .{
29782980 .ty = Type.initTag(.comptime_float),
29792981 .val = try Value.Tag.float_128.create(arena, float_number),
2982 };
2983 const result = try gz.add(.{
2984 .tag = .@"const",
2985 .data = .{ .@"const" = typed_value },
29802986 });
2981 return rvalue(mod, scope, rl, result);
2987 return rvalue(mod, scope, rl, result, node);
29822988}
29832989
29842990fn asmExpr(