aboutsummaryrefslogtreecommitdiff
path: root/types.h
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-02-08 00:52:18 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-02-08 00:52:18 -0500
commit930c09f46d1e249fc889e8f1179046a48c1eaf32 (patch)
tree4900307e726dcbc643b12341a9bb7168edebdff5 /types.h
parentee0f45e2959484d390c30a8a1430a0f040f56631 (diff)
More features and progress
Diffstat (limited to 'types.h')
-rw-r--r--types.h123
1 files changed, 123 insertions, 0 deletions
diff --git a/types.h b/types.h
new file mode 100644
index 00000000..001167ab
--- /dev/null
+++ b/types.h
@@ -0,0 +1,123 @@
+#pragma once
+#include <libgccjit.h>
+#include <printf.h>
+#include <stdlib.h>
+#include <libgccjit.h>
+
+#include "ast.h"
+#include "builtins/array.h"
+
+typedef struct type_s type_t;
+
+typedef struct arg_s {
+ const char *name;
+ type_t *type;
+ ast_t *default_val;
+ struct arg_s *next;
+} arg_t;
+
+typedef struct tag_s {
+ const char *name;
+ int64_t tag_value;
+ type_t *type;
+ struct tag_s *next;
+} tag_t;
+
+typedef struct type_list_s {
+ type_t *type;
+ struct type_list_s *next;
+} type_list_t;
+
+struct type_s {
+ enum {
+ UnknownType,
+ AbortType,
+ VoidType,
+ MemoryType,
+ BoolType,
+ CharType,
+ IntType,
+ NumType,
+ ArrayType,
+ TableType,
+ FunctionType,
+ PointerType,
+ StructType,
+ EnumType,
+ VariantType,
+ TypeInfoType,
+ PlaceholderType,
+ } tag;
+
+ union {
+ struct {
+ } UnknownType, AbortType, VoidType, MemoryType, BoolType, CharType;
+ struct {
+ int64_t bits;
+ } IntType;
+ struct {
+ int64_t bits;
+ } NumType;
+ struct {
+ type_t *item_type;
+ } ArrayType;
+ struct {
+ type_t *key_type, *value_type;
+ } TableType;
+ struct {
+ arg_t *args;
+ type_t *ret;
+ } FunctionType;
+ struct {
+ type_t *pointed;
+ bool is_optional:1, is_stack:1, is_readonly:1;
+ } PointerType;
+ struct {
+ arg_t *fields;
+ } StructType;
+ struct {
+ tag_t *tags;
+ } EnumType;
+ struct {
+ const char *name, *filename;
+ type_t *variant_of;
+ type_t *namespace_type;
+ } VariantType;
+ struct {} TypeInfoType;
+ struct {
+ const char *filename, *name;
+ } PlaceholderType;
+ } __data;
+};
+
+#define Type(typetag, ...) new(type_t, .tag=typetag, .__data.typetag={__VA_ARGS__})
+#define INT_TYPE Type(IntType, .bits=64)
+#define NUM_TYPE Type(NumType, .bits=64)
+
+int printf_pointer_size(const struct printf_info *info, size_t n, int argtypes[n], int size[n]);
+int printf_type(FILE *stream, const struct printf_info *info, const void *const args[]);
+const char* type_to_string_concise(type_t *t);
+const char* type_to_typeof_string(type_t *t);
+const char* type_to_string(type_t *t);
+bool type_eq(type_t *a, type_t *b);
+bool type_is_a(type_t *t, type_t *req);
+type_t *type_or_type(type_t *a, type_t *b);
+type_t *value_type(type_t *a);
+bool is_integral(type_t *t);
+bool is_floating_point(type_t *t);
+bool is_numeric(type_t *t);
+typedef enum {NUM_PRECISION_EQUAL, NUM_PRECISION_LESS, NUM_PRECISION_MORE, NUM_PRECISION_INCOMPARABLE} precision_cmp_e;
+precision_cmp_e compare_precision(type_t *a, type_t *b);
+bool is_orderable(type_t *t);
+bool has_heap_memory(type_t *t);
+bool has_stack_memory(type_t *t);
+bool can_promote(type_t *actual, type_t *needed);
+bool can_leave_uninitialized(type_t *t);
+bool can_have_cycles(type_t *t);
+type_t *table_entry_type(type_t *table_t);
+type_t *base_variant(type_t *t);
+bool is_variant_of(type_t *t, type_t *base);
+type_t *base_value_type(type_t *t);
+type_t *replace_type(type_t *t, type_t *target, type_t *replacement);
+
+// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0