commit bdd2d174e1593e01b449aebfde85cbf1026112c3
parent 010ade7aa39f93cbc89fa4c08dbdc458e9f3ce55
Author: Drew DeVault <sir@cmpwn.com>
Date: Fri, 3 Sep 2021 12:54:01 +0200
rt: add static typeinfo globals
Diffstat:
4 files changed, 109 insertions(+), 2 deletions(-)
diff --git a/rt/Makefile b/rt/Makefile
@@ -8,7 +8,8 @@ libhart_srcs+=\
rt/memmove.ha \
rt/memset.ha \
rt/rtmain.ha \
- rt/strcmp.ha
+ rt/strcmp.ha \
+ rt/types.ha
libhart.a: harec $(libhart_srcs) $(libhart_objs) $(rtstart)
@printf 'HAREC\t$@\n'
diff --git a/rt/configure b/rt/configure
@@ -13,7 +13,8 @@ rt() {
rt/+linux/errno.ha \
rt/+linux/segmalloc.ha \
rt/+linux/syscallno+$arch.ha \
- rt/+linux/syscalls.ha
+ rt/+linux/syscalls.ha \
+ rt/types_arch+$arch.ha
libhart_objs=\
rt/+linux/syscall+$arch.o
diff --git a/rt/types.ha b/rt/types.ha
@@ -0,0 +1,76 @@
+// This defines a subset of types/reflect.ha so we can declare static typeinfo
+// structures for builtins.
+type types::typeinfo = struct {
+ id: uint,
+ sz: size,
+ al: size,
+ flags: types::flags,
+ repr: types::repr,
+};
+
+type types::flags = enum u8 {
+ NONE = 0,
+ CONST = 1 << 0,
+ ERROR = 1 << 1,
+};
+
+type types::repr = (types::builtin | void);
+
+type types::builtin = enum u8 {
+ BOOL, CHAR, F32, F64, I16, I32, I64, I8, INT, NULL, RUNE, SIZE, STR,
+ U16, U32, U64, U8, UINT, UINTPTR, VOID,
+};
+
+export const builtin_char: types::typeinfo = types::typeinfo {
+ id = 3950255460,
+ sz = 1, al = 1, flags = 0,
+ repr = types::builtin::CHAR,
+}, builtin_f32: types::typeinfo = types::typeinfo {
+ id = 930681398,
+ sz = 4, al = 4, flags = 0,
+ repr = types::builtin::F32,
+}, builtin_f64: types::typeinfo = types::typeinfo {
+ id = 2037165609,
+ sz = 8, al = 8, flags = 0,
+ repr = types::builtin::F64,
+}, builtin_i8: types::typeinfo = types::typeinfo {
+ id = 461893804,
+ sz = 1, al = 1, flags = 0,
+ repr = types::builtin::I8,
+}, builtin_i16: types::typeinfo = types::typeinfo {
+ id = 3312558843,
+ sz = 2, al = 2, flags = 0,
+ repr = types::builtin::I16,
+}, builtin_i32: types::typeinfo = types::typeinfo {
+ id = 2674862226,
+ sz = 4, al = 4, flags = 0,
+ repr = types::builtin::I32,
+}, builtin_i64: types::typeinfo = types::typeinfo {
+ id = 1099590421,
+ sz = 8, al = 8, flags = 0,
+ repr = types::builtin::I64,
+}, builtin_rune: types::typeinfo = types::typeinfo {
+ id = 2206074632,
+ sz = 4, al = 4, flags = 0,
+ repr = types::builtin::RUNE,
+}, builtin_u8: types::typeinfo = types::typeinfo {
+ id = 3181589295,
+ sz = 1, al = 1, flags = 0,
+ repr = types::builtin::U8,
+}, builtin_u16: types::typeinfo = types::typeinfo {
+ id = 3481467866,
+ sz = 2, al = 2, flags = 0,
+ repr = types::builtin::U16,
+}, builtin_u32: types::typeinfo = types::typeinfo {
+ id = 1906196061,
+ sz = 4, al = 4, flags = 0,
+ repr = types::builtin::U32,
+}, builtin_u64: types::typeinfo = types::typeinfo {
+ id = 1268499444,
+ sz = 8, al = 8, flags = 0,
+ repr = types::builtin::U64,
+}, builtin_void: types::typeinfo = types::typeinfo {
+ id = 3012680272,
+ sz = 0, al = 0, flags = 0,
+ repr = types::builtin::VOID,
+};
diff --git a/rt/types_arch+x86_64.ha b/rt/types_arch+x86_64.ha
@@ -0,0 +1,29 @@
+export const builtin_int: types::typeinfo = types::typeinfo {
+ id = 1737287038,
+ sz = 4, al = 4, flags = 0,
+ repr = types::builtin::INT,
+}, builtin_uint: types::typeinfo = types::typeinfo {
+ id = 2543892678,
+ sz = 4, al = 4, flags = 0,
+ repr = types::builtin::UINT,
+}, builtin_bool: types::typeinfo = types::typeinfo {
+ id = 292984781,
+ sz = 4, al = 4, flags = 0,
+ repr = types::builtin::BOOL,
+}, builtin_size: types::typeinfo = types::typeinfo {
+ id = 4119164483,
+ sz = 8, al = 8, flags = 0,
+ repr = types::builtin::SIZE,
+}, builtin_uintptr: types::typeinfo = types::typeinfo {
+ id = 3650376889,
+ sz = 8, al = 8, flags = 0,
+ repr = types::builtin::UINTPTR,
+}, builtin_str: types::typeinfo = types::typeinfo {
+ id = 3350498318,
+ sz = 24, al = 8, flags = 0,
+ repr = types::builtin::STR,
+}, builtin_null: types::typeinfo = types::typeinfo {
+ id = 2843771249,
+ sz = 8, al = 8, flags = 0,
+ repr = types::builtin::NULL,
+};