mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Remove iptrdiff and uptrdiff. Bump version to 0.3.100
This commit is contained in:
@@ -32,8 +32,8 @@ module stack <Type>;
|
||||
|
||||
struct Stack
|
||||
{
|
||||
usize capacity;
|
||||
usize size;
|
||||
usz capacity;
|
||||
usz size;
|
||||
Type* elems;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ const bool I128_NATIVE_SUPPORT = $$PLATFORM_I128_SUPPORTED;
|
||||
const bool F16_SUPPORT = $$PLATFORM_F16_SUPPORTED;
|
||||
const bool F128_SUPPORT = $$PLATFORM_F128_SUPPORTED;
|
||||
const bool COMPILER_SAFE_MODE = $$COMPILER_SAFE_MODE;
|
||||
const usize LLVM_VERSION = $$LLVM_VERSION;
|
||||
const usz LLVM_VERSION = $$LLVM_VERSION;
|
||||
const bool BENCHMARKING = $$BENCHMARKING;
|
||||
const bool TESTING = $$TESTING;
|
||||
const usz TEMP_ALLOCATOR_SIZE = 128 * 1024;
|
||||
|
||||
@@ -61,7 +61,7 @@ fn void encode(char[] in, char *out)
|
||||
}
|
||||
|
||||
// move back
|
||||
usize last = in.len - 1;
|
||||
usz last = in.len - 1;
|
||||
// check the last and add padding
|
||||
switch (last % 3)
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ fn String bin(int x)
|
||||
str.append_repeat('0', bits);
|
||||
for (int i = 0; i < bits; i++)
|
||||
{
|
||||
str.set((usize)(bits - i - 1), x & 1 ? '1' : '0');
|
||||
str.set((usz)(bits - i - 1), x & 1 ? '1' : '0');
|
||||
x >>= 1;
|
||||
}
|
||||
return str;
|
||||
|
||||
@@ -10,7 +10,7 @@ fault InterpretError
|
||||
INTEPRET_FAILED
|
||||
}
|
||||
|
||||
fn void! print_error(usize pos, char[] err)
|
||||
fn void! print_error(usz pos, char[] err)
|
||||
{
|
||||
io::printfln("Error at %s: %s", pos, err);
|
||||
return InterpretError.INTEPRET_FAILED!;
|
||||
@@ -18,8 +18,8 @@ fn void! print_error(usize pos, char[] err)
|
||||
|
||||
fn void! brainf(char[] program)
|
||||
{
|
||||
usize sp = 0;
|
||||
usize mem = 0;
|
||||
usz sp = 0;
|
||||
usz mem = 0;
|
||||
while (sp < program.len)
|
||||
{
|
||||
char c = program[sp++];
|
||||
@@ -41,9 +41,9 @@ fn void! brainf(char[] program)
|
||||
case ',':
|
||||
memory[mem] = io::stdin().getc()!!;
|
||||
case '[':
|
||||
usize indent = 1;
|
||||
usz indent = 1;
|
||||
if (memory[mem]) continue;
|
||||
usize start = sp - 1;
|
||||
usz start = sp - 1;
|
||||
while (indent)
|
||||
{
|
||||
if (sp == program.len) return print_error(start, "No matching ']'");
|
||||
@@ -56,8 +56,8 @@ fn void! brainf(char[] program)
|
||||
}
|
||||
case ']':
|
||||
if (!memory[mem]) continue;
|
||||
usize start = sp--;
|
||||
usize indent = 1;
|
||||
usz start = sp--;
|
||||
usz indent = 1;
|
||||
while (indent)
|
||||
{
|
||||
if (!sp) return print_error(start, "No matching '['");
|
||||
|
||||
@@ -14,8 +14,8 @@ struct Summary
|
||||
private struct StringData
|
||||
{
|
||||
Allocator allocator;
|
||||
usize len;
|
||||
usize capacity;
|
||||
usz len;
|
||||
usz capacity;
|
||||
char[*] chars;
|
||||
}
|
||||
|
||||
@@ -27,12 +27,12 @@ fn void Summary.print(Summary *s, File out)
|
||||
|
||||
fn bool contains(char[] haystack, char[] needle)
|
||||
{
|
||||
usize len = haystack.len;
|
||||
usize needle_len = needle.len;
|
||||
usz len = haystack.len;
|
||||
usz needle_len = needle.len;
|
||||
if (len < needle_len) return false;
|
||||
if (!needle_len) return true;
|
||||
len -= needle_len - 1;
|
||||
for (usize i = 0; i < len; i++)
|
||||
for (usz i = 0; i < len; i++)
|
||||
{
|
||||
if (mem::equals(haystack[i..], needle))
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@ module guess_number;
|
||||
import std::io;
|
||||
import libc;
|
||||
|
||||
extern fn isize getline(char** linep, usize* linecapp, CFile stream);
|
||||
extern fn isz getline(char** linep, usz* linecapp, CFile stream);
|
||||
|
||||
struct Game
|
||||
{
|
||||
@@ -33,7 +33,7 @@ fn int! askGuess(int high)
|
||||
fn char[]! readLine()
|
||||
{
|
||||
char* chars = tmalloc(1024)?;
|
||||
isize loaded = getline(&chars, &&(usize)1023, libc::stdin());
|
||||
isz loaded = getline(&chars, &&(usz)1023, libc::stdin());
|
||||
if (loaded < 0) return InputResult.FAILED_TO_READ!;
|
||||
chars[loaded] = 0;
|
||||
return chars[0..(loaded - 1)];
|
||||
|
||||
@@ -56,7 +56,7 @@ const LINELEN = 60;
|
||||
// slowest character-at-a-time output
|
||||
fn void repeat_fasta(char[] seq, int n)
|
||||
{
|
||||
usize len = seq.len;
|
||||
usz len = seq.len;
|
||||
int i = void;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
|
||||
@@ -10,14 +10,14 @@ struct Entry
|
||||
{
|
||||
Key key;
|
||||
Type value;
|
||||
usize hash;
|
||||
usz hash;
|
||||
Entry* next;
|
||||
bool used;
|
||||
}
|
||||
|
||||
struct Map
|
||||
{
|
||||
usize size;
|
||||
usz size;
|
||||
Entry* map;
|
||||
uint mod;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ fn Type! Map.valueForKey(Map *map, Key key)
|
||||
{
|
||||
if (!map.map) return MapResult.KEY_NOT_FOUND!;
|
||||
uint hash = key.hash();
|
||||
usize pos = hash & map.mod;
|
||||
usz pos = hash & map.mod;
|
||||
Entry* entry = &map.map[pos];
|
||||
if (!entry) return MapResult.KEY_NOT_FOUND!;
|
||||
while (entry)
|
||||
@@ -91,7 +91,7 @@ fn Type! Map.set(Map *map, Key key, Type value) @maydiscard
|
||||
}
|
||||
}
|
||||
|
||||
fn usize Map.size(Map* map)
|
||||
fn usz Map.size(Map* map)
|
||||
{
|
||||
return map.size;
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@ struct Planet
|
||||
|
||||
fn void advance(Planet[] bodies) @noinline
|
||||
{
|
||||
usize nbodies = bodies.len;
|
||||
usz nbodies = bodies.len;
|
||||
foreach (i, Planet* &b : bodies)
|
||||
{
|
||||
for (usize j = i + 1; j < nbodies; j++)
|
||||
for (usz j = i + 1; j < nbodies; j++)
|
||||
{
|
||||
Planet* b2 = &bodies[j];
|
||||
double dx = b.x - b2.x;
|
||||
@@ -45,12 +45,12 @@ fn void advance(Planet[] bodies) @noinline
|
||||
fn double energy(Planet[] bodies)
|
||||
{
|
||||
double e;
|
||||
usize nbodies = bodies.len;
|
||||
usz nbodies = bodies.len;
|
||||
|
||||
foreach (i, Planet* &b : bodies)
|
||||
{
|
||||
e += 0.5 * b.mass * (b.vx * b.vx + b.vy * b.vy + b.vz * b.vz);
|
||||
for (usize j = i + 1; j < nbodies; j++)
|
||||
for (usz j = i + 1; j < nbodies; j++)
|
||||
{
|
||||
Planet* b2 = &bodies[j];
|
||||
double dx = b.x - b2.x;
|
||||
|
||||
@@ -16,14 +16,14 @@ macro assert_exp($c, $e)
|
||||
*/
|
||||
|
||||
/** A signed integer, whose size matches Value */
|
||||
typedef isize Aint;
|
||||
typedef isz Aint;
|
||||
/** An unsigned integer, whose size matches Value */
|
||||
typedef usize Auint;
|
||||
typedef usz Auint;
|
||||
|
||||
|
||||
/** A float, whose size matches Value (see avm_env.h) */
|
||||
$assert(usize.size == 8 || usize.size == 4)
|
||||
$if (usize.size == 8)
|
||||
$assert(usz.size == 8 || usz.size == 4)
|
||||
$if (usz.size == 8)
|
||||
{
|
||||
typedef double as Afloat;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ fn char[]! read_next(char[]* remaining)
|
||||
|
||||
// Store the beginning of the parse
|
||||
char* ptr_start = remaining.ptr;
|
||||
usize len = 0;
|
||||
usz len = 0;
|
||||
while (remaining.len > 0 && (*remaining)[0] != ' ')
|
||||
{
|
||||
// Increase length
|
||||
|
||||
@@ -5,8 +5,8 @@ import std::io;
|
||||
struct String
|
||||
{
|
||||
Allocator allocator;
|
||||
usize len;
|
||||
usize capacity;
|
||||
usz len;
|
||||
usz capacity;
|
||||
char* ptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -1810,7 +1810,7 @@ extern Type *type_bool, *type_void, *type_voidptr;
|
||||
extern Type *type_float16, *type_float, *type_double, *type_f128;
|
||||
extern Type *type_ichar, *type_short, *type_int, *type_long, *type_isize, *type_isz;
|
||||
extern Type *type_char, *type_ushort, *type_uint, *type_ulong, *type_usize, *type_usz;
|
||||
extern Type *type_iptr, *type_uptr, *type_iptrdiff, *type_uptrdiff;
|
||||
extern Type *type_iptr, *type_uptr;
|
||||
extern Type *type_u128, *type_i128;
|
||||
extern Type *type_typeid, *type_anyerr, *type_typeinfo, *type_member;
|
||||
extern Type *type_any;
|
||||
|
||||
@@ -470,7 +470,6 @@ typedef enum
|
||||
TOKEN_ICHAR,
|
||||
TOKEN_INT,
|
||||
TOKEN_IPTR,
|
||||
TOKEN_IPTRDIFF,
|
||||
TOKEN_ISIZE,
|
||||
TOKEN_ISZ,
|
||||
TOKEN_LONG,
|
||||
@@ -479,7 +478,6 @@ typedef enum
|
||||
TOKEN_UINT,
|
||||
TOKEN_ULONG,
|
||||
TOKEN_UPTR,
|
||||
TOKEN_UPTRDIFF,
|
||||
TOKEN_USHORT,
|
||||
TOKEN_USIZE,
|
||||
TOKEN_USZ,
|
||||
@@ -604,9 +602,9 @@ typedef enum
|
||||
#define NON_VOID_TYPE_TOKENS \
|
||||
TOKEN_BOOL: case TOKEN_CHAR: case TOKEN_DOUBLE: case TOKEN_FLOAT: \
|
||||
case TOKEN_FLOAT16: case TOKEN_INT128: case TOKEN_ICHAR: case TOKEN_INT: \
|
||||
case TOKEN_IPTR: case TOKEN_IPTRDIFF: case TOKEN_ISIZE: case TOKEN_LONG: \
|
||||
case TOKEN_IPTR: case TOKEN_ISIZE: case TOKEN_LONG: \
|
||||
case TOKEN_SHORT: case TOKEN_UINT128: case TOKEN_UINT: case TOKEN_ULONG: \
|
||||
case TOKEN_UPTR: case TOKEN_UPTRDIFF: case TOKEN_USHORT: case TOKEN_USIZE:\
|
||||
case TOKEN_UPTR: case TOKEN_USHORT: case TOKEN_USIZE:\
|
||||
case TOKEN_USZ: case TOKEN_ISZ: case TOKEN_FLOAT128: case TOKEN_TYPEID: case TOKEN_ANYERR: case TOKEN_VARIANT
|
||||
#define TYPE_TOKENS NON_VOID_TYPE_TOKENS: case TOKEN_VOID
|
||||
#define TYPELIKE_TOKENS TYPE_TOKENS: case TOKEN_TYPE_IDENT: \
|
||||
|
||||
@@ -3524,10 +3524,10 @@ void llvm_emit_binary(GenContext *c, BEValue *be_value, Expr *expr, BEValue *lhs
|
||||
{
|
||||
if (lhs_type == rhs_type)
|
||||
{
|
||||
LLVMTypeRef int_type = llvm_get_type(c, type_iptrdiff);
|
||||
LLVMTypeRef int_type = llvm_get_type(c, type_isz);
|
||||
val = LLVMBuildSub(c->builder, LLVMBuildPtrToInt(c->builder, lhs_value, int_type, ""),
|
||||
LLVMBuildPtrToInt(c->builder, rhs_value, int_type, ""), "");
|
||||
val = LLVMBuildExactSDiv(c->builder, val, llvm_const_int(c, type_iptrdiff, type_abi_alignment(lhs_type->pointer)), "");
|
||||
val = LLVMBuildExactSDiv(c->builder, val, llvm_const_int(c, type_isz, type_abi_alignment(lhs_type->pointer)), "");
|
||||
break;
|
||||
}
|
||||
rhs_value = LLVMBuildNeg(c->builder, rhs_value, "");
|
||||
|
||||
@@ -1690,8 +1690,6 @@ ParseRule rules[TOKEN_EOF + 1] = {
|
||||
[TOKEN_USZ] = { parse_type_identifier, NULL, PREC_NONE },
|
||||
[TOKEN_IPTR] = { parse_type_identifier, NULL, PREC_NONE },
|
||||
[TOKEN_UPTR] = { parse_type_identifier, NULL, PREC_NONE },
|
||||
[TOKEN_IPTRDIFF] = { parse_type_identifier, NULL, PREC_NONE },
|
||||
[TOKEN_UPTRDIFF] = { parse_type_identifier, NULL, PREC_NONE },
|
||||
[TOKEN_FLOAT] = { parse_type_identifier, NULL, PREC_NONE },
|
||||
[TOKEN_DOUBLE] = { parse_type_identifier, NULL, PREC_NONE },
|
||||
[TOKEN_FLOAT16] = { parse_type_identifier, NULL, PREC_NONE },
|
||||
|
||||
@@ -1676,12 +1676,12 @@ bool cast_to_index(Expr *index)
|
||||
case TYPE_I16:
|
||||
case TYPE_I32:
|
||||
case TYPE_I64:
|
||||
return cast(index, type_iptrdiff);
|
||||
return cast(index, type_isz);
|
||||
case TYPE_U8:
|
||||
case TYPE_U16:
|
||||
case TYPE_U32:
|
||||
case TYPE_U64:
|
||||
return cast(index, type_uptrdiff);
|
||||
return cast(index, type_usz);
|
||||
case TYPE_U128:
|
||||
SEMA_ERROR(index, "You need to explicitly cast this to a uint or ulong.");
|
||||
return false;
|
||||
|
||||
@@ -2446,7 +2446,7 @@ static inline bool sema_expr_analyse_pointer_offset(SemaContext *context, Expr *
|
||||
// 2. Evaluate the offset.
|
||||
Expr *offset = exprptr(expr->pointer_offset_expr.offset);
|
||||
if (!sema_analyse_expr(context, offset)) return false;
|
||||
if (!cast_implicit(context, offset, type_iptrdiff)) return false;
|
||||
if (!cast_implicit(context, offset, type_isz)) return false;
|
||||
|
||||
// 3. Store optionality
|
||||
bool is_optional = IS_OPTIONAL(pointer) || IS_OPTIONAL(offset);
|
||||
@@ -4301,12 +4301,12 @@ static bool sema_expr_analyse_sub(SemaContext *context, Expr *expr, Expr *left,
|
||||
|
||||
if (expr_both_const(left, right))
|
||||
{
|
||||
expr_rewrite_const_int(expr, type_iptrdiff, (left->const_expr.ptr - right->const_expr.ptr) /
|
||||
expr_rewrite_const_int(expr, type_isz, (left->const_expr.ptr - right->const_expr.ptr) /
|
||||
type_size(left_type->pointer), false);
|
||||
return true;
|
||||
}
|
||||
// 3b. Set the type
|
||||
expr->type = type_iptrdiff;
|
||||
expr->type = type_isz;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -4320,15 +4320,15 @@ static bool sema_expr_analyse_sub(SemaContext *context, Expr *expr, Expr *left,
|
||||
return false;
|
||||
}
|
||||
|
||||
// 5. Make sure that the integer does not exceed iptrdiff in size.
|
||||
if (type_size(right_type) > type_size(type_iptrdiff))
|
||||
// 5. Make sure that the integer does not exceed isz in size.
|
||||
if (type_size(right_type) > type_size(type_isz))
|
||||
{
|
||||
SEMA_ERROR(expr, "Cannot subtract a '%s' from a pointer, please first cast it to '%s'.", type_to_error_string(right_type), type_to_error_string(type_iptrdiff));
|
||||
SEMA_ERROR(expr, "Cannot subtract a '%s' from a pointer, please first cast it to '%s'.", type_to_error_string(right_type), type_to_error_string(type_isz));
|
||||
return false;
|
||||
}
|
||||
|
||||
// 6. Convert to iptrdiff
|
||||
if (!cast_implicit(context, right, type_iptrdiff)) return true;
|
||||
// 6. Convert to isz
|
||||
if (!cast_implicit(context, right, type_isz)) return true;
|
||||
|
||||
if (left->expr_kind == EXPR_POINTER_OFFSET)
|
||||
{
|
||||
@@ -4452,7 +4452,7 @@ static bool sema_expr_analyse_add(SemaContext *context, Expr *expr, Expr *left,
|
||||
|
||||
// 3b. Cast it to usize or isize depending on underlying type.
|
||||
// Either is fine, but it looks a bit nicer if we actually do this and keep the sign.
|
||||
bool success = cast_implicit(context, right, type_iptrdiff);
|
||||
bool success = cast_implicit(context, right, type_isz);
|
||||
|
||||
// No need to check the cast we just ensured it was an integer.
|
||||
assert(success && "This should always work");
|
||||
@@ -6597,7 +6597,7 @@ static inline bool sema_expr_analyse_ct_offsetof(SemaContext *context, Expr *exp
|
||||
type = result_type;
|
||||
}
|
||||
|
||||
expr_rewrite_const_int(expr, type_iptrdiff, offset, true);
|
||||
expr_rewrite_const_int(expr, type_isz, offset, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -574,10 +574,10 @@ void tinybackend_emit_binary(TbContext *c, TBEValue *TBE_VALUE, Expr *expr, TBEV
|
||||
/*bool is_constant = LLVMIsConstant(lhs_value) && LLVMIsConstant(rhs_value);
|
||||
if (lhs_type == rhs_type)
|
||||
{
|
||||
LLVMTypeRef int_type = llvm_get_type(c, type_iptrdiff);
|
||||
LLVMTypeRef int_type = llvm_get_type(c, type_isz);
|
||||
val = LLVMBuildSub(c->builder, LLVMBuildPtrToInt(c->builder, lhs_value, int_type, ""),
|
||||
LLVMBuildPtrToInt(c->builder, rhs_value, int_type, ""), "");
|
||||
val = LLVMBuildExactSDiv(c->builder, val, llvm_const_int(c, type_iptrdiff, type_abi_alignment(lhs_type->pointer)), "");
|
||||
val = LLVMBuildExactSDiv(c->builder, val, llvm_const_int(c, type_isz, type_abi_alignment(lhs_type->pointer)), "");
|
||||
break;
|
||||
}
|
||||
rhs_value = LLVMConstNeg(rhs_value);
|
||||
|
||||
@@ -315,10 +315,6 @@ const char *token_type_to_string(TokenType type)
|
||||
return "iptr";
|
||||
case TOKEN_UPTR:
|
||||
return "uptr";
|
||||
case TOKEN_IPTRDIFF:
|
||||
return "iptrdiff";
|
||||
case TOKEN_UPTRDIFF:
|
||||
return "uptrdiff";
|
||||
case TOKEN_FLOAT16:
|
||||
return "float16";
|
||||
case TOKEN_DOCS_START:
|
||||
|
||||
@@ -11,7 +11,7 @@ static struct
|
||||
Type u0, u1, i8, i16, i32, i64, i128, ixx;
|
||||
Type u8, u16, u32, u64, u128;
|
||||
Type f16, f32, f64, f128, fxx;
|
||||
Type usz, isz, usize, isize, uptr, iptr, uptrdiff, iptrdiff;
|
||||
Type usz, isz, usize, isize, uptr, iptr;
|
||||
Type voidstar, typeid, anyerr, member, typeinfo, untyped_list;
|
||||
Type any, anyfail;
|
||||
} t;
|
||||
@@ -32,7 +32,6 @@ Type *type_int = &t.i32;
|
||||
Type *type_long = &t.i64;
|
||||
Type *type_i128 = &t.i128;
|
||||
Type *type_iptr = &t.iptr;
|
||||
Type *type_iptrdiff = &t.iptrdiff;
|
||||
Type *type_isize = &t.isize;
|
||||
Type *type_isz = &t.isz;
|
||||
Type *type_char = &t.u8;
|
||||
@@ -41,7 +40,6 @@ Type *type_uint = &t.u32;
|
||||
Type *type_ulong = &t.u64;
|
||||
Type *type_u128 = &t.u128;
|
||||
Type *type_uptr = &t.uptr;
|
||||
Type *type_uptrdiff = &t.uptrdiff;
|
||||
Type *type_usize = &t.usize;
|
||||
Type *type_usz = &t.usz;
|
||||
Type *type_anyerr = &t.anyerr;
|
||||
@@ -1465,9 +1463,6 @@ void type_setup(PlatformTarget *target)
|
||||
type_create_alias("uptr", &t.uptr, type_int_unsigned_by_bitsize(target->width_pointer));
|
||||
type_create_alias("iptr", &t.iptr, type_int_signed_by_bitsize(target->width_pointer));
|
||||
|
||||
type_create_alias("uptrdiff", &t.uptrdiff, type_int_unsigned_by_bitsize(target->width_pointer));
|
||||
type_create_alias("iptrdiff", &t.iptrdiff, type_int_signed_by_bitsize(target->width_pointer));
|
||||
|
||||
alignment_subarray = MAX(type_abi_alignment(&t.voidstar), type_abi_alignment(t.usz.canonical));
|
||||
size_subarray = (unsigned)(alignment_subarray * 2);
|
||||
type_init("anyerr", &t.anyerr, TYPE_ANYERR, target->width_pointer, target->align_pointer);
|
||||
@@ -1602,8 +1597,6 @@ Type *type_from_token(TokenType type)
|
||||
return type_int;
|
||||
case TOKEN_IPTR:
|
||||
return type_iptr;
|
||||
case TOKEN_IPTRDIFF:
|
||||
return type_iptrdiff;
|
||||
case TOKEN_ISIZE:
|
||||
return type_isize;
|
||||
case TOKEN_ISZ:
|
||||
@@ -1620,8 +1613,6 @@ Type *type_from_token(TokenType type)
|
||||
return type_ulong;
|
||||
case TOKEN_UPTR:
|
||||
return type_uptr;
|
||||
case TOKEN_UPTRDIFF:
|
||||
return type_uptrdiff;
|
||||
case TOKEN_USHORT:
|
||||
return type_ushort;
|
||||
case TOKEN_USIZE:
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define COMPILER_VERSION "0.3.99"
|
||||
#define COMPILER_VERSION "0.3.100"
|
||||
@@ -5,7 +5,7 @@ module foo;
|
||||
struct StringRef
|
||||
{
|
||||
char* str;
|
||||
usize size;
|
||||
usz size;
|
||||
}
|
||||
|
||||
char gc;
|
||||
|
||||
@@ -5,7 +5,7 @@ module foo;
|
||||
struct StringRef
|
||||
{
|
||||
char* str;
|
||||
usize size;
|
||||
usz size;
|
||||
}
|
||||
|
||||
char gc;
|
||||
|
||||
@@ -13,7 +13,7 @@ fn void main()
|
||||
int* gp = &g;
|
||||
int[4] a = { 3, 4, 5, 6 };
|
||||
int* xa = &a;
|
||||
usize asf = 1;
|
||||
usz asf = 1;
|
||||
int aa = 3;
|
||||
asm
|
||||
{
|
||||
|
||||
@@ -4,12 +4,12 @@ module test;
|
||||
const uptr ABC = 0x213;
|
||||
const void* BAC = (void*)144 - 1;
|
||||
const void* EXX = (void*)155;
|
||||
const iptrdiff KEX = BAC - EXX;
|
||||
const isz KEX = BAC - EXX;
|
||||
const void* CAB = BAC;
|
||||
const uptr ZAB = (uptr)CAB;
|
||||
const int* BOB = (int*)16 - 1;
|
||||
const int* BAB = (int*)16 + 1;
|
||||
const iptrdiff AO = BAB - BOB;
|
||||
const isz AO = BAB - BOB;
|
||||
|
||||
$if (ZAB > 100):
|
||||
int abc = 123;
|
||||
|
||||
@@ -14,6 +14,6 @@ define StructArr = distinct Struct2[3];
|
||||
fn void test(int x)
|
||||
{
|
||||
StructArr z = { { .x = 1 }, { .y = x }, { 1, 2 }};
|
||||
usize len = z.len;
|
||||
usz len = z.len;
|
||||
Foo zz = z[2].x;
|
||||
}
|
||||
|
||||
@@ -22,12 +22,12 @@ fn void Summary.print(Summary *s, CFile out)
|
||||
|
||||
fn bool contains(char[] haystack, char[] needle)
|
||||
{
|
||||
usize len = haystack.len;
|
||||
usize needle_len = needle.len;
|
||||
usz len = haystack.len;
|
||||
usz needle_len = needle.len;
|
||||
if (len < needle_len) return false;
|
||||
if (!needle_len) return true;
|
||||
len -= needle_len - 1;
|
||||
for (usize i = 0; i < len; i++)
|
||||
for (usz i = 0; i < len; i++)
|
||||
{
|
||||
if (libc::memcmp(&haystack[i], needle.ptr, needle_len) == 0)
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ extern fn int atoi(char *val);
|
||||
extern void *__stdoutp;
|
||||
extern fn void fflush(void *std);
|
||||
extern fn int rand();
|
||||
extern fn void* malloc(usize size);
|
||||
extern fn void* malloc(usz size);
|
||||
extern fn void usleep(int time);
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ struct Struct
|
||||
int x;
|
||||
}
|
||||
|
||||
enum Enum : uptr
|
||||
enum Enum : usz
|
||||
{
|
||||
A, B
|
||||
}
|
||||
@@ -36,7 +36,7 @@ fn void test4(Func arg)
|
||||
|
||||
fn void test7(Func arg)
|
||||
{
|
||||
usize g = (usize)(arg);
|
||||
usz g = (usz)(arg);
|
||||
FuncOther k = (FuncOther)(arg);
|
||||
FuncSame l = (FuncSame)(arg);
|
||||
FuncOther ke = arg; // #error: 'Func' (fn void(int)) to 'FuncOther' (fn bool(char*))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
fn void test(int* array, usize n)
|
||||
fn void test(int* array, usz n)
|
||||
{
|
||||
array[n] = 33;
|
||||
n[array] = 33; // #error: Cannot index
|
||||
|
||||
@@ -16,9 +16,9 @@ macro print_type_info(...)
|
||||
fn void main()
|
||||
{
|
||||
io::printfln("Unsigned integers:");
|
||||
print_type_info(char, ushort, uint, ulong, uptr, uptrdiff, usize);
|
||||
print_type_info(char, ushort, uint, ulong, uptr, usz, usz);
|
||||
io::printfln("Signed integers:");
|
||||
print_type_info(ichar, short, int, long, iptr, iptrdiff, isize);
|
||||
print_type_info(ichar, short, int, long, iptr, isz, isz);
|
||||
io::printfln("Floats:");
|
||||
print_type_info(float, double);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ const LINELEN = 60;
|
||||
// slowest character-at-a-time output
|
||||
fn void repeat_fasta(char[] seq, int n)
|
||||
{
|
||||
usize len = seq.len;
|
||||
usz len = seq.len;
|
||||
int i = void;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
|
||||
@@ -4,33 +4,33 @@ macro testbitcast(expr, $Type)
|
||||
{
|
||||
$assert($sizeof(expr) == $Type.sizeof, "Cannot bitcast between types of different size.");
|
||||
$Type x = void;
|
||||
var $size = (usize)($sizeof(expr));
|
||||
var $size = (usz)($sizeof(expr));
|
||||
|
||||
$if ($alignof(expr) >= 8 && $Type.alignof >= 8):
|
||||
ulong *b = (ulong*)(&expr);
|
||||
ulong *to = (ulong*)(&x);
|
||||
for (usize i = 0; i < $size; i += 8)
|
||||
for (usz i = 0; i < $size; i += 8)
|
||||
{
|
||||
to[i] = b[i];
|
||||
}
|
||||
$elif ($alignof(expr) >= 4 && $Type.alignof >= 4):
|
||||
uint* b = (uint*)(&expr);
|
||||
uint* to = (uint*)(&x);
|
||||
for (usize i = 0; i < $size; i += 4)
|
||||
for (usz i = 0; i < $size; i += 4)
|
||||
{
|
||||
to[i] = b[i];
|
||||
}
|
||||
$elif ($alignof(expr) >= 2 && $Type.alignof >= 2):
|
||||
ushort* b = (ushort*)(&expr);
|
||||
ushort* to = (ushort*)(&x);
|
||||
for (usize i = 0; i < $size; i += 2)
|
||||
for (usz i = 0; i < $size; i += 2)
|
||||
{
|
||||
to[i] = b[i];
|
||||
}
|
||||
$else:
|
||||
char* b = (char*)(&expr);
|
||||
char* to = (char*)(&x);
|
||||
for (usize i = 0; i < $size; i++)
|
||||
for (usz i = 0; i < $size; i++)
|
||||
{
|
||||
to[i] = b[i];
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ define IntArray = List<int>;
|
||||
|
||||
extern fn void printf(char*, ...);
|
||||
|
||||
fn void IntArray.someFunc(IntArray *this, usize param) {
|
||||
fn void IntArray.someFunc(IntArray *this, usz param) {
|
||||
//do something
|
||||
this.push((int)param);
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@ struct Foo
|
||||
int[] x;
|
||||
}
|
||||
|
||||
macro int Foo.@operator_element_at(Foo &foo, usize index) @operator([])
|
||||
macro int Foo.@operator_element_at(Foo &foo, usz index) @operator([])
|
||||
{
|
||||
return foo.x[index];
|
||||
}
|
||||
|
||||
macro usize Foo.@operator_len(Foo &foo) @operator(len)
|
||||
macro usz Foo.@operator_len(Foo &foo) @operator(len)
|
||||
{
|
||||
return foo.x.len;
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ struct Foo
|
||||
int[] x;
|
||||
}
|
||||
|
||||
macro int Foo.@operator_element_at(Foo &foo, usize index) @operator([])
|
||||
macro int Foo.@operator_element_at(Foo &foo, usz index) @operator([])
|
||||
{
|
||||
return foo.x[index];
|
||||
}
|
||||
|
||||
macro usize Foo.@operator_len(Foo &foo) @operator(len)
|
||||
macro usz Foo.@operator_len(Foo &foo) @operator(len)
|
||||
{
|
||||
return foo.x.len;
|
||||
}
|
||||
|
||||
@@ -4,21 +4,21 @@ module test;
|
||||
import std::io;
|
||||
struct Vector
|
||||
{
|
||||
usize size;
|
||||
usz size;
|
||||
int* elements;
|
||||
}
|
||||
|
||||
macro int Vector.get(Vector* vector, usize element) @operator([])
|
||||
macro int Vector.get(Vector* vector, usz element) @operator([])
|
||||
{
|
||||
return vector.elements[element];
|
||||
}
|
||||
|
||||
macro int* Vector.get_ref(Vector* vector, usize element) @operator(&[])
|
||||
macro int* Vector.get_ref(Vector* vector, usz element) @operator(&[])
|
||||
{
|
||||
return &vector.elements[element];
|
||||
}
|
||||
|
||||
macro usize Vector.size(Vector vector) @operator(len) {
|
||||
macro usz Vector.size(Vector vector) @operator(len) {
|
||||
return vector.size;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,12 +6,12 @@ struct Foo
|
||||
int[] x;
|
||||
}
|
||||
|
||||
macro int Foo.@operator_element_at(Foo &foo, usize index) @operator([])
|
||||
macro int Foo.@operator_element_at(Foo &foo, usz index) @operator([])
|
||||
{
|
||||
return foo.x[index];
|
||||
}
|
||||
|
||||
macro usize Foo.@operator_len(Foo &foo) @operator(len)
|
||||
macro usz Foo.@operator_len(Foo &foo) @operator(len)
|
||||
{
|
||||
return foo.x.len;
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ struct Foo
|
||||
int[] x;
|
||||
}
|
||||
|
||||
macro int Foo.@operator_element_at(Foo &foo, usize index) @operator([])
|
||||
macro int Foo.@operator_element_at(Foo &foo, usz index) @operator([])
|
||||
{
|
||||
return foo.x[index];
|
||||
}
|
||||
|
||||
macro usize Foo.@operator_len(Foo &foo) @operator(len)
|
||||
macro usz Foo.@operator_len(Foo &foo) @operator(len)
|
||||
{
|
||||
return foo.x.len;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ struct Foo
|
||||
long bar;
|
||||
}
|
||||
|
||||
private usize x = Foo.sizeof;
|
||||
private usz x = Foo.sizeof;
|
||||
|
||||
private Foo foo1 = { 1, 2 };
|
||||
private Foo foo2 = { .foo = 2 };
|
||||
|
||||
@@ -5,7 +5,7 @@ module foo;
|
||||
struct StringRef
|
||||
{
|
||||
char* str;
|
||||
usize size;
|
||||
usz size;
|
||||
}
|
||||
|
||||
char gc;
|
||||
|
||||
@@ -5,7 +5,7 @@ module foo;
|
||||
struct StringRef
|
||||
{
|
||||
char* str;
|
||||
usize size;
|
||||
usz size;
|
||||
}
|
||||
|
||||
char gc;
|
||||
|
||||
@@ -13,7 +13,7 @@ fn void main()
|
||||
int* gp = &g;
|
||||
int[4] a = { 3, 4, 5, 6 };
|
||||
int* xa = &a;
|
||||
usize asf = 1;
|
||||
usz asf = 1;
|
||||
int aa = 3;
|
||||
asm
|
||||
{
|
||||
|
||||
@@ -4,12 +4,12 @@ module test;
|
||||
const uptr ABC = 0x213;
|
||||
const void* BAC = (void*)144 - 1;
|
||||
const void* EXX = (void*)155;
|
||||
const iptrdiff KEX = BAC - EXX;
|
||||
const isz KEX = BAC - EXX;
|
||||
const void* CAB = BAC;
|
||||
const uptr ZAB = (uptr)CAB;
|
||||
const int* BOB = (int*)16 - 1;
|
||||
const int* BAB = (int*)16 + 1;
|
||||
const iptrdiff AO = BAB - BOB;
|
||||
const isz AO = BAB - BOB;
|
||||
|
||||
$if (ZAB > 100):
|
||||
int abc = 123;
|
||||
|
||||
@@ -14,6 +14,6 @@ define StructArr = distinct Struct2[3];
|
||||
fn void test(int x)
|
||||
{
|
||||
StructArr z = { { .x = 1 }, { .y = x }, { 1, 2 }};
|
||||
usize len = z.len;
|
||||
usz len = z.len;
|
||||
Foo zz = z[2].x;
|
||||
}
|
||||
|
||||
@@ -22,12 +22,12 @@ fn void Summary.print(Summary *s, CFile out)
|
||||
|
||||
fn bool contains(char[] haystack, char[] needle)
|
||||
{
|
||||
usize len = haystack.len;
|
||||
usize needle_len = needle.len;
|
||||
usz len = haystack.len;
|
||||
usz needle_len = needle.len;
|
||||
if (len < needle_len) return false;
|
||||
if (!needle_len) return true;
|
||||
len -= needle_len - 1;
|
||||
for (usize i = 0; i < len; i++)
|
||||
for (usz i = 0; i < len; i++)
|
||||
{
|
||||
if (libc::memcmp(&haystack[i], needle.ptr, needle_len) == 0)
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ extern fn int atoi(char *val);
|
||||
extern void *__stdoutp;
|
||||
extern fn void fflush(void *std);
|
||||
extern fn int rand();
|
||||
extern fn void* malloc(usize size);
|
||||
extern fn void* malloc(usz size);
|
||||
extern fn void usleep(int time);
|
||||
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ fn void test4(Func arg)
|
||||
|
||||
fn void test7(Func arg)
|
||||
{
|
||||
usize g = (usize)(arg);
|
||||
usz g = (usz)(arg);
|
||||
FuncOther k = (FuncOther)(arg);
|
||||
FuncSame l = (FuncSame)(arg);
|
||||
FuncOther ke = arg; // #error: 'Func' (fn void(int)) to 'FuncOther' (fn bool(char*))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
fn void test(int* array, usize n)
|
||||
fn void test(int* array, usz n)
|
||||
{
|
||||
array[n] = 33;
|
||||
n[array] = 33; // #error: Cannot index
|
||||
|
||||
@@ -16,9 +16,9 @@ macro print_type_info(...)
|
||||
fn void main()
|
||||
{
|
||||
io::printfln("Unsigned integers:");
|
||||
print_type_info(char, ushort, uint, ulong, uptr, uptrdiff, usize);
|
||||
print_type_info(char, ushort, uint, ulong, uptr, usz, usz);
|
||||
io::printfln("Signed integers:");
|
||||
print_type_info(ichar, short, int, long, iptr, iptrdiff, isize);
|
||||
print_type_info(ichar, short, int, long, iptr, isz, isz);
|
||||
io::printfln("Floats:");
|
||||
print_type_info(float, double);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ const LINELEN = 60;
|
||||
// slowest character-at-a-time output
|
||||
fn void repeat_fasta(char[] seq, int n)
|
||||
{
|
||||
usize len = seq.len;
|
||||
usz len = seq.len;
|
||||
int i = void;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
|
||||
@@ -4,33 +4,33 @@ macro testbitcast(expr, $Type)
|
||||
{
|
||||
$assert($sizeof(expr) == $Type.sizeof, "Cannot bitcast between types of different size.");
|
||||
$Type x = void;
|
||||
var $size = (usize)($sizeof(expr));
|
||||
var $size = (usz)($sizeof(expr));
|
||||
|
||||
$if ($alignof(expr) >= 8 && $Type.alignof >= 8):
|
||||
ulong *b = (ulong*)(&expr);
|
||||
ulong *to = (ulong*)(&x);
|
||||
for (usize i = 0; i < $size; i += 8)
|
||||
for (usz i = 0; i < $size; i += 8)
|
||||
{
|
||||
to[i] = b[i];
|
||||
}
|
||||
$elif ($alignof(expr) >= 4 && $Type.alignof >= 4):
|
||||
uint* b = (uint*)(&expr);
|
||||
uint* to = (uint*)(&x);
|
||||
for (usize i = 0; i < $size; i += 4)
|
||||
for (usz i = 0; i < $size; i += 4)
|
||||
{
|
||||
to[i] = b[i];
|
||||
}
|
||||
$elif ($alignof(expr) >= 2 && $Type.alignof >= 2):
|
||||
ushort* b = (ushort*)(&expr);
|
||||
ushort* to = (ushort*)(&x);
|
||||
for (usize i = 0; i < $size; i += 2)
|
||||
for (usz i = 0; i < $size; i += 2)
|
||||
{
|
||||
to[i] = b[i];
|
||||
}
|
||||
$else:
|
||||
char* b = (char*)(&expr);
|
||||
char* to = (char*)(&x);
|
||||
for (usize i = 0; i < $size; i++)
|
||||
for (usz i = 0; i < $size; i++)
|
||||
{
|
||||
to[i] = b[i];
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ define IntArray = List<int>;
|
||||
|
||||
extern fn void printf(char*, ...);
|
||||
|
||||
fn void IntArray.someFunc(IntArray *this, usize param) {
|
||||
fn void IntArray.someFunc(IntArray *this, usz param) {
|
||||
//do something
|
||||
this.push((int)param);
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@ struct Foo
|
||||
int[] x;
|
||||
}
|
||||
|
||||
macro int Foo.@operator_element_at(Foo &foo, usize index) @operator([])
|
||||
macro int Foo.@operator_element_at(Foo &foo, usz index) @operator([])
|
||||
{
|
||||
return foo.x[index];
|
||||
}
|
||||
|
||||
macro usize Foo.@operator_len(Foo &foo) @operator(len)
|
||||
macro usz Foo.@operator_len(Foo &foo) @operator(len)
|
||||
{
|
||||
return foo.x.len;
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ struct Foo
|
||||
int[] x;
|
||||
}
|
||||
|
||||
macro int Foo.@operator_element_at(Foo &foo, usize index) @operator([])
|
||||
macro int Foo.@operator_element_at(Foo &foo, usz index) @operator([])
|
||||
{
|
||||
return foo.x[index];
|
||||
}
|
||||
|
||||
macro usize Foo.@operator_len(Foo &foo) @operator(len)
|
||||
macro usz Foo.@operator_len(Foo &foo) @operator(len)
|
||||
{
|
||||
return foo.x.len;
|
||||
}
|
||||
|
||||
@@ -4,21 +4,21 @@ module test;
|
||||
import std::io;
|
||||
struct Vector
|
||||
{
|
||||
usize size;
|
||||
usz size;
|
||||
int* elements;
|
||||
}
|
||||
|
||||
macro int Vector.get(Vector* vector, usize element) @operator([])
|
||||
macro int Vector.get(Vector* vector, usz element) @operator([])
|
||||
{
|
||||
return vector.elements[element];
|
||||
}
|
||||
|
||||
macro int* Vector.get_ref(Vector* vector, usize element) @operator(&[])
|
||||
macro int* Vector.get_ref(Vector* vector, usz element) @operator(&[])
|
||||
{
|
||||
return &vector.elements[element];
|
||||
}
|
||||
|
||||
macro usize Vector.size(Vector vector) @operator(len) {
|
||||
macro usz Vector.size(Vector vector) @operator(len) {
|
||||
return vector.size;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,12 +6,12 @@ struct Foo
|
||||
int[] x;
|
||||
}
|
||||
|
||||
macro int Foo.@operator_element_at(Foo &foo, usize index) @operator([])
|
||||
macro int Foo.@operator_element_at(Foo &foo, usz index) @operator([])
|
||||
{
|
||||
return foo.x[index];
|
||||
}
|
||||
|
||||
macro usize Foo.@operator_len(Foo &foo) @operator(len)
|
||||
macro usz Foo.@operator_len(Foo &foo) @operator(len)
|
||||
{
|
||||
return foo.x.len;
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ struct Foo
|
||||
int[] x;
|
||||
}
|
||||
|
||||
macro int Foo.@operator_element_at(Foo &foo, usize index) @operator([])
|
||||
macro int Foo.@operator_element_at(Foo &foo, usz index) @operator([])
|
||||
{
|
||||
return foo.x[index];
|
||||
}
|
||||
|
||||
macro usize Foo.@operator_len(Foo &foo) @operator(len)
|
||||
macro usz Foo.@operator_len(Foo &foo) @operator(len)
|
||||
{
|
||||
return foo.x.len;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ struct Foo
|
||||
long bar;
|
||||
}
|
||||
|
||||
private usize x = Foo.sizeof;
|
||||
private usz x = Foo.sizeof;
|
||||
|
||||
private Foo foo1 = { 1, 2 };
|
||||
private Foo foo2 = { .foo = 2 };
|
||||
|
||||
Reference in New Issue
Block a user