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(...@@ -3237,22 +3237,28 @@ fn builtinCall(
3237 return rvalue(mod, scope, rl, result, node);3237 return rvalue(mod, scope, rl, result, node);
3238 },3238 },
3239 .float_cast => {3239 .float_cast => {
3240 if (true) @panic("TODO update for zir-memory-layout");
3241 const dest_type = try typeExpr(mod, scope, params[0]);3240 const dest_type = try typeExpr(mod, scope, params[0]);
3242 const rhs = try expr(mod, scope, .none, params[1]);3241 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 });
3244 return rvalue(mod, scope, rl, result, node);3246 return rvalue(mod, scope, rl, result, node);
3245 },3247 },
3246 .int_cast => {3248 .int_cast => {
3247 if (true) @panic("TODO update for zir-memory-layout");
3248 const dest_type = try typeExpr(mod, scope, params[0]);3249 const dest_type = try typeExpr(mod, scope, params[0]);
3249 const rhs = try expr(mod, scope, .none, params[1]);3250 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 });
3251 return rvalue(mod, scope, rl, result, node);3255 return rvalue(mod, scope, rl, result, node);
3252 },3256 },
3253 .breakpoint => {3257 .breakpoint => {
3254 if (true) @panic("TODO update for zir-memory-layout");3258 const result = try gz.add(.{
3255 const result = try addZIRNoOp(mod, scope, src, .breakpoint);3259 .tag = .breakpoint,
3260 .data = .{ .node = gz.zir_code.decl.nodeIndexToRelative(node) },
3261 });
3256 return rvalue(mod, scope, rl, result, node);3262 return rvalue(mod, scope, rl, result, node);
3257 },3263 },
3258 .import => {3264 .import => {
...@@ -3283,23 +3289,18 @@ fn builtinCall(...@@ -3283,23 +3289,18 @@ fn builtinCall(
3283 return rvalue(mod, scope, rl, result, node);3289 return rvalue(mod, scope, rl, result, node);
3284 },3290 },
3285 .field => {3291 .field => {
3286 if (true) @panic("TODO update for zir-memory-layout");3292 const field_name = try comptimeExpr(mod, scope, .{ .ty = .const_slice_u8_type }, params[1]);
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
3293 if (rl == .ref) {3293 if (rl == .ref) {
3294 return addZirInstTag(mod, scope, src, .field_ptr_named, .{3294 return try gz.addPlNode(.field_ptr_named, node, zir.Inst.FieldNamed{
3295 .object = try expr(mod, scope, .ref, params[0]),3295 .lhs = try expr(mod, scope, .ref, params[0]),
3296 .field_name = try comptimeExpr(mod, scope, string_rl, params[1]),3296 .field_name = field_name,
3297 });3297 });
3298 }3298 }
3299 return rvalue(mod, scope, rl, try addZirInstTag(mod, scope, src, .field_val_named, .{3299 const result = try gz.addPlNode(.field_val_named, node, zir.Inst.FieldNamed{
3300 .object = try expr(mod, scope, .none, params[0]),3300 .lhs = try expr(mod, scope, .none, params[0]),
3301 .field_name = try comptimeExpr(mod, scope, string_rl, params[1]),3301 .field_name = field_name,
3302 }), node);3302 });
3303 return rvalue(mod, scope, rl, result, node);
3303 },3304 },
3304 .as => return as(mod, scope, rl, builtin_token, node, params[0], params[1]),3305 .as => return as(mod, scope, rl, builtin_token, node, params[0], params[1]),
3305 .bit_cast => return bitCast(mod, scope, rl, builtin_token, node, params[0], params[1]),3306 .bit_cast => return bitCast(mod, scope, rl, builtin_token, node, params[0], params[1]),