A distinct inline pointer type can now participate in pointer arithmetics.

This commit is contained in:
Christoffer Lerno
2024-11-16 23:08:54 +01:00
parent f9e9cac6e8
commit 8ed390c394
4 changed files with 25 additions and 2 deletions

View File

@@ -10,6 +10,7 @@
- Fix bug where `a > 0 ? f() : g()` could cause a compiler crash if both returned `void!`.
- `@builtin` was not respected for generic modules #1617.
- Fix issue writing a single byte in the WriteBuffer
- A distinct inline pointer type can now participate in pointer arithmetics.
### Stdlib changes
- Add `io::MultiReader`, `io::MultiWriter`, and `io::TeeReader` structs.

View File

@@ -2698,10 +2698,25 @@ INLINE CanonicalType *type_pointer_type(Type *type)
return res->pointer;
}
static inline Type *type_flat_distinct_inline(Type *type);
INLINE bool type_is_pointer_like(Type *type)
{
TypeKind kind = type->type_kind;
return kind == TYPE_POINTER || (kind == TYPE_VECTOR && type->array.base->canonical->type_kind == TYPE_POINTER);
if (kind == TYPE_DISTINCT)
{
type = type_flat_distinct_inline(type);
kind = type->type_kind;
}
switch (kind)
{
case TYPE_POINTER:
return true;
case TYPE_VECTOR:
return type_is_pointer_like(type->array.base->canonical);
default:
return false;
}
}
INLINE bool type_is_pointer_vector(Type *type)

View File

@@ -276,7 +276,7 @@ LLVMTypeRef llvm_func_type(GenContext *context, FunctionPrototype *prototype)
LLVMTypeRef llvm_get_pointee_type(GenContext *c, Type *any_type)
{
any_type = any_type->canonical;
any_type = type_lowering(any_type);
ASSERT0(any_type->type_kind == TYPE_POINTER);
if (any_type == type_voidptr) return llvm_get_type(c, type_char);
return llvm_get_type(c, any_type->pointer);

View File

@@ -0,0 +1,7 @@
import std;
fn void main()
{
ZString a = "abc";
ZString b = a + 1;
io::printfn("%s", b);
}