mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Removed capacity arguments from new_slice and slice_ptr
This commit is contained in:
@@ -157,7 +157,7 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_Count] = {
|
||||
{STR_LIT(""), 0, false, Expr_Stmt},
|
||||
|
||||
{STR_LIT("new"), 1, false, Expr_Expr},
|
||||
{STR_LIT("new_slice"), 2, true, Expr_Expr},
|
||||
{STR_LIT("new_slice"), 2, false, Expr_Expr},
|
||||
|
||||
{STR_LIT("size_of"), 1, false, Expr_Expr},
|
||||
{STR_LIT("size_of_val"), 1, false, Expr_Expr},
|
||||
@@ -181,7 +181,7 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_Count] = {
|
||||
|
||||
// {STR_LIT("ptr_offset"), 2, false, Expr_Expr},
|
||||
// {STR_LIT("ptr_sub"), 2, false, Expr_Expr},
|
||||
{STR_LIT("slice_ptr"), 2, true, Expr_Expr},
|
||||
{STR_LIT("slice_ptr"), 2, false, Expr_Expr},
|
||||
|
||||
{STR_LIT("min"), 2, false, Expr_Expr},
|
||||
{STR_LIT("max"), 2, false, Expr_Expr},
|
||||
|
||||
+2
-46
@@ -2643,7 +2643,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
operand->type = make_type_pointer(c->allocator, type);
|
||||
} break;
|
||||
case BuiltinProc_new_slice: {
|
||||
// new_slice :: proc(Type, len: int[, cap: int]) -> []Type
|
||||
// new_slice :: proc(Type, len: int) -> []Type
|
||||
Operand op = {0};
|
||||
check_expr_or_type(c, &op, ce->args.e[0]);
|
||||
Type *type = op.type;
|
||||
@@ -2653,10 +2653,6 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
}
|
||||
|
||||
AstNode *len = ce->args.e[1];
|
||||
AstNode *cap = NULL;
|
||||
if (ce->args.count > 2) {
|
||||
cap = ce->args.e[2];
|
||||
}
|
||||
|
||||
check_expr(c, &op, len);
|
||||
if (op.mode == Addressing_Invalid) {
|
||||
@@ -2669,23 +2665,6 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cap != NULL) {
|
||||
check_expr(c, &op, cap);
|
||||
if (op.mode == Addressing_Invalid) {
|
||||
return false;
|
||||
}
|
||||
if (!is_type_integer(op.type)) {
|
||||
gbString type_str = type_to_string(operand->type);
|
||||
error_node(call, "Capacity for `new_slice` must be an integer, got `%s`", type_str);
|
||||
gb_string_free(type_str);
|
||||
return false;
|
||||
}
|
||||
if (ce->args.count > 3) {
|
||||
error_node(call, "Too many arguments to `new_slice`, expected either 2 or 3");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
operand->mode = Addressing_Value;
|
||||
operand->type = make_type_slice(c->allocator, type);
|
||||
} break;
|
||||
@@ -3166,7 +3145,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
#endif
|
||||
|
||||
case BuiltinProc_slice_ptr: {
|
||||
// slice_ptr :: proc(a: ^T, len: int[, cap: int]) -> []T
|
||||
// slice_ptr :: proc(a: ^T, len: int) -> []T
|
||||
// ^T cannot be rawptr
|
||||
Type *ptr_type = base_type(operand->type);
|
||||
if (!is_type_pointer(ptr_type)) {
|
||||
@@ -3185,10 +3164,6 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
}
|
||||
|
||||
AstNode *len = ce->args.e[1];
|
||||
AstNode *cap = NULL;
|
||||
if (ce->args.count > 2) {
|
||||
cap = ce->args.e[2];
|
||||
}
|
||||
|
||||
Operand op = {0};
|
||||
check_expr(c, &op, len);
|
||||
@@ -3203,25 +3178,6 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cap != NULL) {
|
||||
check_expr(c, &op, cap);
|
||||
if (op.mode == Addressing_Invalid)
|
||||
return false;
|
||||
if (!is_type_integer(op.type)) {
|
||||
gbString type_str = type_to_string(operand->type);
|
||||
error_node(call,
|
||||
"Capacity for `slice_ptr` must be an integer, got `%s`",
|
||||
type_str);
|
||||
gb_string_free(type_str);
|
||||
return false;
|
||||
}
|
||||
if (ce->args.count > 3) {
|
||||
error_node(call,
|
||||
"Too many arguments to `slice_ptr`, expected either 2 or 3");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
operand->type = make_type_slice(c->allocator, ptr_type->Pointer.elem);
|
||||
operand->mode = Addressing_Value;
|
||||
} break;
|
||||
|
||||
Reference in New Issue
Block a user