20 return type >= PS_TYPE_U8 && type <= PS_TYPE_B;
32 type->type = prim_type;
40 type->type = PS_TYPE_STRUCT;
41 type->value.struct_.name = name;
55 type->type = PS_TYPE_ENUM;
56 type->value.enum_.name = name;
70 type->type = PS_TYPE_UNRESOLVED;
71 type->value.unresolved = name;
77 ps_assert(name->
type == PS_TOKEN_ID,
"type name should be an identifer");
89 type->type = PS_TYPE_TUPLE;
98 fputs(_STRING(PS_PRIM_TYPE_U8), stdout);
141 case PS_TYPE_TUPLE: {
142 ps_type_tuple_print(self->value.tuple, 0);
145 case PS_TYPE_STRUCT: {
146 ps_type_struct_print(&self->value.struct_, 0, 0);
150 ps_type_enum_print(&self->value.enum_, 0, 0);
153 case PS_TYPE_UNRESOLVED: {
154 printf(
"%s", self->value.unresolved->start);
158 ps_abort(
"unknown type encountered");
166 for (
usize i = 0; i < self->length; i++) {
167 ps_type_print(self->contents[i], 0);
168 if (i < self->
length - 1) {
176 printf(
"%s", self->name);
177 ps_type_tuple_print(self->args, 0);
182 printf(
"struct %.*s {\n", (
int)self->name->length, self->name->start);
183 for (
usize i = 0; i < self->fields->length; i++) {
193 printf(
"enum %.*s {\n", (
int)self->name->length, self->name->start);
194 for (
usize i = 0; i < self->variants->length; i++) {
195 ps_type_variant_print(&$arr(self->variants)[i], 0);
204 printf(
"%s: ", self->name);
205 ps_type_print(self->type, 0);
210 for (
usize i = 0; i < self->length; i++) {
212 ps_type_field_print(&self->contents[i], 0, 0);
Defines assertion and abortion functionality.
#define ps_abort(msg)
Aborts the program with the given message.
#define PS_NO_MEMORY()
Aborts the program due to exhaustion of virtual memory.
#define ps_assert(cond, msg)
Asserts the given condition cond, aborting via ps_abort with the given msg otherwise.
Defines an arena allocator for the compiler.
#define ps_push(__arrptr, __new_elem)
#define PS_IPRINT_IMPL(T,...)
#define ps_print_indent()
#define PS_PRINT_IMPL(T,...)
struct ps_type_tuple * tuple
struct ps_type * ps_type_struct_new(struct ps_token *name)
Constructs a new empty struct type with the name name.
struct ps_type * ps_type_from_name(struct ps_token *name)
Returns the type associated with the given name (e.g.
struct ps_type * ps_type_enum_new(struct ps_token *name)
Constructs a new empty enum type with the name name.
bool ps_type_is_prim(enum ps_type_type type)
Returns whether type represents a primitive type.
struct ps_type * ps_type_from_tuple(struct ps_type_tuple *tuple)
Constructs and returns a type for the given tuple type tuple.
STR prim_type_names[]
For each type PS_TYPE_U8 to PS_TYPE_B, this array indexes by prim_type_names[PS_TYPE_U8] == _STRING(P...
void ps_type_struct_add(struct ps_type *type, struct ps_type_field field)
Adds the given field field to the struct type type.
struct ps_type * ps_type_prim_new(enum ps_type_type prim_type)
Constructs a new primitive type specified by prim_type.
struct ps_type * ps_type_unresolved_new(struct ps_token *name)
Constructs a new unresolved type corresponding to the given name.
void ps_type_enum_add(struct ps_type *type, struct ps_type_variant variant)
Adds the given variant variant to the struct type type.
#define ps_type_field_arr_new()
ps_type_type
The type of a type :)
#define ps_type_variant_arr_new()