hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit a7937382cf85537e6cc7fe5a5f810121c1df3163
parent dc75fea624fffe0a27bb67c982565bc3fd840f8a
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue,  5 Oct 2021 14:09:59 +0200

all: updates following reflection standardization

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mhare/types/hash.ha | 4++--
Mslice/void.ha | 2+-
Mtypes/classes.ha | 2+-
Mtypes/reflect.ha | 33+++++++++++----------------------
Mtypes/util.ha | 14+++++++++++++-
5 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/hare/types/hash.ha b/hare/types/hash.ha @@ -6,8 +6,8 @@ use fmt; // Keep ordered with respect to bootstrap harec:include/types.h type storage = enum u8 { - BOOL, CHAR, ENUM, F32, F64, I16, I32, I64, I8, INT, NULL, RUNE, SIZE, - STRING, U16, U32, U64, U8, UINT, UINTPTR, VOID, TYPE, ALIAS, ARRAY, + BOOL, CHAR, F32, F64, I16, I32, I64, I8, INT, NULL, RUNE, SIZE, STRING, + U16, U32, U64, U8, UINT, UINTPTR, VOID, TYPE, ALIAS, ARRAY, ENUM, FUNCTION, POINTER, SLICE, STRUCT, TAGGED, TUPLE, UNION, }; diff --git a/slice/void.ha b/slice/void.ha @@ -6,7 +6,7 @@ export fn appendto(sl: *[]void, itemsz: size, items: const *void...) void = { if (len(items) == 0) { return; }; - let sl = sl: *types::slice; + let sl = sl: *types::slice_repr; let end = sl.length; sl.length += len(items); rt::ensure(sl, itemsz); diff --git a/types/classes.ha b/types/classes.ha @@ -30,7 +30,7 @@ export type string = struct { // A type representing the internal structure of slices, useful for low-level // slice manipulation. -export type slice = struct { +export type slice_repr = struct { // The slice contents. data: nullable *void, diff --git a/types/reflect.ha b/types/reflect.ha @@ -12,22 +12,10 @@ export type typeinfo = struct { }; // Returns [[typeinfo]] for the provided type. -export fn reflect(in: type) *typeinfo = in: *typeinfo; - -// Returns [[typeinfo]] for the provided type, unwrapping any aliases along the -// way. -export fn unwrap(in: type) *typeinfo = { - let info = reflect(in); - match (info.repr) { - case a: alias => - return unwrap(a.secondary); - case => - return info; - }; -}; +export fn reflect(in: type) const *typeinfo = in: *typeinfo; // Type flags. -export type flags = enum u8 { +export type flags = enum uint { NONE = 0, CONST = 1 << 0, ERROR = 1 << 1, @@ -51,15 +39,15 @@ export type array = struct { }; // A built-in type. -export type builtin = enum u8 { - BOOL, CHAR, ENUM, F32, F64, I16, I32, I64, I8, INT, NULL, RUNE, SIZE, - STR, U16, U32, U64, U8, UINT, UINTPTR, VOID, TYPE, +export type builtin = enum uint { + BOOL, CHAR, F32, F64, I16, I32, I64, I8, INT, NULL, RUNE, SIZE, STR, + U16, U32, U64, U8, UINT, UINTPTR, VOID, TYPE, }; // An enum type. export type enumerated = struct { storage: builtin, - values: [](str, u64), + values: [](str, union { u: u64, i: i64 }), }; // Indicates the variadism of a [[func]]. @@ -71,6 +59,7 @@ export type variadism = enum { // Indicats if a [[func]] has the @noreturn attribute. export type func_flags = enum uint { + NONE = 0, NORETURN = 1 << 0, }; @@ -83,7 +72,7 @@ export type func = struct { }; // Flags which apply to a pointer type. -export type pointer_flags = enum u8 { +export type pointer_flags = enum uint { NONE = 0, NULLABLE = 1 << 0, }; @@ -94,9 +83,9 @@ export type pointer = struct { flags: pointer_flags, }; -// Type information for slice members. Distinct from [[slice]], which is the -// representation of a slice object at runtime. -export type slice_repr = type; +// Type information for slice members. Distinct from [[slice_repr]], which is +// the representation of a slice object at runtime. +export type slice = type; // Indicates if a [[_struct]] was declared as a struct or union type. export type struct_kind = enum { diff --git a/types/util.ha b/types/util.ha @@ -33,10 +33,22 @@ export fn strenum(ty: type, val: *void) str = { }; for (let i = 0z; i < len(en.values); i += 1) { - if (en.values[i].1 == value) { + if (en.values[i].1.u == value) { return en.values[i].0; }; }; abort("enum has invalid value"); }; + +// Returns [[typeinfo]] for the provided type, unwrapping any aliases along the +// way. +export fn unwrap(in: type) const *typeinfo = { + let info = reflect(in); + match (info.repr) { + case a: alias => + return unwrap(a.secondary); + case => + return info; + }; +};