// a binary operator, you cannot pass a custom allocator.
#operator + (x: str, y: str) -> str {
- return string.concat(x, y);
+ return string.concat(x, y);
}
main :: (args: [] cstr) {
// As a side note, '==' is already overloaded for strings in the
// standard library, so you can do this:
-
+
if array.contains(cast([] str) strings, "is ") {
println("The array contains 'is '.");
} else {
// Utilities
-get_site_hash :: (site: CallSite, increment := 0) -> UI_Id {
+get_site_hash :: macro (site: CallSite, increment := 0) -> UI_Id {
hash :: package core.hash
file_hash := hash.to_u32(site.file);
if *value > target - step && *value < target + step do *value = target;
}
-#private color_lerp :: (t: f32, c1: gfx.Color4, c2: gfx.Color4) -> gfx.Color4 {
+#private color_lerp :: macro (t: f32, c1: gfx.Color4, c2: gfx.Color4) -> gfx.Color4 {
return .{
r = c1.r * (1 - t) + c2.r * t,
g = c1.g * (1 - t) + c2.g * t,
else if (binop->operation == Binary_Op_Assign_Sar) operation = Binary_Op_Sar;
AstBinaryOp* new_right = make_binary_op(context.ast_alloc, operation, binop->left, binop->right);
- new_right->token = binop->token;
- CHECK(binaryop, &new_right);
-
binop->right = (AstTyped *) new_right;
+ new_right->token = binop->token;
binop->operation = Binary_Op_Assign;
+
+ CHECK(binaryop, (AstBinaryOp **) &binop->right);
}
if (binop->right->type == NULL) {
char* err_msg = NULL;
if (!fill_in_arguments(&sl->args, (AstNode *) sl, &err_msg)) {
onyx_report_error(sl->token->pos, err_msg);
-
+
bh_arr_each(AstTyped *, value, sl->args.values) {
if (*value == NULL) {
i32 member_idx = value - sl->args.values; // Pointer subtraction hack
}
}
- if (!type_is_array_accessible(sub->addr->type))
- ERROR_(sub->token->pos,
- "Expected pointer or array type for left of array access, got '%s'.",
- node_get_type_name(sub->addr));
+ if (!type_is_array_accessible(sub->addr->type)) {
+ report_bad_binaryop((AstBinaryOp *) sub);
+ return Check_Error;
+ }
if (types_are_compatible(sub->expr->type, builtin_range_type_type)) {
Type *of = NULL;
else {
// FIXME: Slice creation should be allowed for slice types and dynamic array types, like it
// is below, but this code doesn't look at that.
+ report_bad_binaryop((AstBinaryOp *) sub);
ERROR(sub->token->pos, "Invalid type for left of slice creation.");
}
resolve_expression_type(sub->expr);
if (sub->expr->type->kind != Type_Kind_Basic
|| (sub->expr->type->Basic.kind != Basic_Kind_I32 && sub->expr->type->Basic.kind != Basic_Kind_U32)) {
+ report_bad_binaryop((AstBinaryOp *) sub);
ERROR_(sub->token->pos,
"Expected type u32 or i32 for index, got '%s'.",
node_get_type_name(sub->expr));
sub->type = sub->addr->type->Pointer.elem;
}
else {
+ report_bad_binaryop((AstBinaryOp *) sub);
ERROR(sub->token->pos, "Invalid type for left of array access.");
}