authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-03-26 15:20:11+01:00
committergravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-03-26 15:20:11+01:00
logd8ee8794e16d2ab1b574089e0457ce230da117f5
tree78e576599e8ba670b63820f50b8cc153830ebfc9
parent5eea13f5cc6ffc3c582faa59214010718b1390a4
signature Commit is signed but in an unrecognized format.

astgen: implement more builtin functions


1 files changed, 21 insertions(+), 20 deletions(-)

src/astgen.zig+21-20
......@@ -3237,22 +3237,28 @@ fn builtinCall(
32373237 return rvalue(mod, scope, rl, result, node);
32383238 },
32393239 .float_cast => {
3240 if (true) @panic("TODO update for zir-memory-layout");
32413240 const dest_type = try typeExpr(mod, scope, params[0]);
32423241 const rhs = try expr(mod, scope, .none, params[1]);
3243 const result = try addZIRBinOp(mod, scope, src, .floatcast, dest_type, rhs);
3242 const result = try gz.addPlNode(.floatcast, node, zir.Inst.Bin{
3243 .lhs = dest_type,
3244 .rhs = rhs,
3245 });
32443246 return rvalue(mod, scope, rl, result, node);
32453247 },
32463248 .int_cast => {
3247 if (true) @panic("TODO update for zir-memory-layout");
32483249 const dest_type = try typeExpr(mod, scope, params[0]);
32493250 const rhs = try expr(mod, scope, .none, params[1]);
3250 const result = try addZIRBinOp(mod, scope, src, .intcast, dest_type, rhs);
3251 const result = try gz.addPlNode(.intcast, node, zir.Inst.Bin{
3252 .lhs = dest_type,
3253 .rhs = rhs,
3254 });
32513255 return rvalue(mod, scope, rl, result, node);
32523256 },
32533257 .breakpoint => {
3254 if (true) @panic("TODO update for zir-memory-layout");
3255 const result = try addZIRNoOp(mod, scope, src, .breakpoint);
3258 const result = try gz.add(.{
3259 .tag = .breakpoint,
3260 .data = .{ .node = gz.zir_code.decl.nodeIndexToRelative(node) },
3261 });
32563262 return rvalue(mod, scope, rl, result, node);
32573263 },
32583264 .import => {
......@@ -3283,23 +3289,18 @@ fn builtinCall(
32833289 return rvalue(mod, scope, rl, result, node);
32843290 },
32853291 .field => {
3286 if (true) @panic("TODO update for zir-memory-layout");
3287 const string_type = try addZIRInstConst(mod, scope, src, .{
3288 .ty = Type.initTag(.type),
3289 .val = Value.initTag(.const_slice_u8_type),
3290 });
3291 const string_rl: ResultLoc = .{ .ty = string_type };
3292
3292 const field_name = try comptimeExpr(mod, scope, .{ .ty = .const_slice_u8_type }, params[1]);
32933293 if (rl == .ref) {
3294 return addZirInstTag(mod, scope, src, .field_ptr_named, .{
3295 .object = try expr(mod, scope, .ref, params[0]),
3296 .field_name = try comptimeExpr(mod, scope, string_rl, params[1]),
3294 return try gz.addPlNode(.field_ptr_named, node, zir.Inst.FieldNamed{
3295 .lhs = try expr(mod, scope, .ref, params[0]),
3296 .field_name = field_name,
32973297 });
32983298 }
3299 return rvalue(mod, scope, rl, try addZirInstTag(mod, scope, src, .field_val_named, .{
3300 .object = try expr(mod, scope, .none, params[0]),
3301 .field_name = try comptimeExpr(mod, scope, string_rl, params[1]),
3302 }), node);
3299 const result = try gz.addPlNode(.field_val_named, node, zir.Inst.FieldNamed{
3300 .lhs = try expr(mod, scope, .none, params[0]),
3301 .field_name = field_name,
3302 });
3303 return rvalue(mod, scope, rl, result, node);
33033304 },
33043305 .as => return as(mod, scope, rl, builtin_token, node, params[0], params[1]),
33053306 .bit_cast => return bitCast(mod, scope, rl, builtin_token, node, params[0], params[1]),