wcc: add the size primitive type (TY_SIZE), classify as unsigned int (#85)

fold-1: type exists + classifies; mirrors TY_UINTPTR at every site, both stages. size(T)/len() return types UNCHANGED (fold-2). Regenerates the 5 combined.ww (lib/ww embedded).
This commit is contained in:
2026-05-26 01:26:03 +09:00
parent 68dbb77d6c
commit bd7181ae1f
7 changed files with 38 additions and 15 deletions

View File

@@ -711,7 +711,7 @@ let_emit_size(Type *t)
case TY_BOOL: case TY_RUNE:
case TY_I8: case TY_I16: case TY_I32: case TY_I64:
case TY_U8: case TY_U16: case TY_U32: case TY_U64:
case TY_INT: case TY_UINT: case TY_UINTPTR:
case TY_INT: case TY_UINT: case TY_UINTPTR: case TY_SIZE:
case TY_PTR:
return 8;
case TY_F32:

View File

@@ -12,7 +12,7 @@
Type *ty_void, *ty_bool, *ty_rune;
Type *ty_i8, *ty_i16, *ty_i32, *ty_i64;
Type *ty_u8, *ty_u16, *ty_u32, *ty_u64;
Type *ty_int, *ty_uint, *ty_uintptr;
Type *ty_int, *ty_uint, *ty_uintptr, *ty_size;
Type *ty_f32, *ty_f64, *ty_str;
Type *ty_err;
Type *ty_never;
@@ -58,6 +58,7 @@ typesinit(Arena *a)
ty_int = prim(a, TY_INT, "int", 8, 8); /* amd64 */
ty_uint = prim(a, TY_UINT, "uint", 8, 8);
ty_uintptr= prim(a, TY_UINTPTR,"uintptr", 8, 8);
ty_size = prim(a, TY_SIZE, "size", 8, 8); /* #85: mirrors uintptr */
ty_f32 = prim(a, TY_F32, "f32", 4, 4);
ty_f64 = prim(a, TY_F64, "f64", 8, 8);
/* str IS []u8: { *u8, len, cap } — 24 bytes, 3-reg ABI (#1/Phase 3).
@@ -148,7 +149,7 @@ type_isint(Type *t)
switch (t->kind) {
case TY_I8: case TY_I16: case TY_I32: case TY_I64:
case TY_U8: case TY_U16: case TY_U32: case TY_U64:
case TY_INT: case TY_UINT: case TY_UINTPTR:
case TY_INT: case TY_UINT: case TY_UINTPTR: case TY_SIZE:
case TY_RUNE:
case TY_UNTYPED_INT:
case TY_UNTYPED_RUNE:
@@ -183,7 +184,7 @@ type_isunsigned(Type *t)
if (t == NULL) return 0;
switch (t->kind) {
case TY_U8: case TY_U16: case TY_U32: case TY_U64:
case TY_UINT: case TY_UINTPTR:
case TY_UINT: case TY_UINTPTR: case TY_SIZE:
case TY_RUNE:
return 1;
case TY_NAMED: return type_isunsigned(t->under);
@@ -373,6 +374,7 @@ type_name(Arena *a, Type *t)
case TY_INT: return "int";
case TY_UINT: return "uint";
case TY_UINTPTR: return "uintptr";
case TY_SIZE: return "size";
case TY_F32: return "f32";
case TY_F64: return "f64";
case TY_STR: return "str";

View File

@@ -389,8 +389,11 @@ typedef enum {
TY_UNTYPED_NIL,
/* Appended at the tail to keep existing TY_* values stable —
* lib/ww/typ.ww mirrors them as explicit `def` numbers. */
TY_ENUM /* `enum [storage] { ... }`. sub=storage,
TY_ENUM, /* `enum [storage] { ... }`. sub=storage,
* fields=member list (Tfield.offset = u64 value). */
TY_SIZE /* platform-width unsigned int; mirrors TY_UINTPTR
* (8/8 on amd64). Hare: `size`, SIZE_MAX=U64_MAX
* (ref/hare/types/arch+x86_64.ha:17,20). #85 fold-1. */
} TypeKind;
typedef struct Tfield Tfield;
@@ -436,7 +439,7 @@ struct Type {
extern Type *ty_void, *ty_bool, *ty_rune;
extern Type *ty_i8, *ty_i16, *ty_i32, *ty_i64;
extern Type *ty_u8, *ty_u16, *ty_u32, *ty_u64;
extern Type *ty_int, *ty_uint, *ty_uintptr;
extern Type *ty_int, *ty_uint, *ty_uintptr, *ty_size;
extern Type *ty_f32, *ty_f64, *ty_str;
extern Type *ty_err;
extern Type *ty_never;