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(...@@ -2959,26 +2959,32 @@ fn floatLiteral(
2959 mod: *Module,2959 mod: *Module,
2960 scope: *Scope,2960 scope: *Scope,
2961 rl: ResultLoc,2961 rl: ResultLoc,
2962 float_lit: ast.Node.Index,2962 node: ast.Node.Index,
2963) InnerError!zir.Inst.Ref {2963) InnerError!zir.Inst.Ref {
2964 if (true) @panic("TODO update for zir-memory-layout");
2965 const arena = scope.arena();2964 const arena = scope.arena();
2966 const tree = scope.tree();2965 const tree = scope.tree();
2967 const main_tokens = tree.nodes.items(.main_token);2966 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];
2970 const bytes = tree.tokenSlice(main_token);2970 const bytes = tree.tokenSlice(main_token);
2971 if (bytes.len > 2 and bytes[1] == 'x') {2971 if (bytes.len > 2 and bytes[1] == 'x') {
2972 assert(bytes[0] == '0'); // validated by tokenizer
2972 return mod.failTok(scope, main_token, "TODO implement hex floats", .{});2973 return mod.failTok(scope, main_token, "TODO implement hex floats", .{});
2973 }2974 }
2974 const float_number = std.fmt.parseFloat(f128, bytes) catch |e| switch (e) {2975 const float_number = std.fmt.parseFloat(f128, bytes) catch |e| switch (e) {
2975 error.InvalidCharacter => unreachable, // validated by tokenizer2976 error.InvalidCharacter => unreachable, // validated by tokenizer
2976 };2977 };
2977 const result = try addZIRInstConst(mod, scope, src, .{2978 const typed_value = try arena.create(TypedValue);
2979 typed_value.* = .{
2978 .ty = Type.initTag(.comptime_float),2980 .ty = Type.initTag(.comptime_float),
2979 .val = try Value.Tag.float_128.create(arena, float_number),2981 .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 },
2980 });2986 });
2981 return rvalue(mod, scope, rl, result);2987 return rvalue(mod, scope, rl, result, node);
2982}2988}
29832989
2984fn asmExpr(2990fn asmExpr(