libpulsar
A modular compiler for the pulsar programming language
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions
type.h File Reference
#include "def.h"
#include "enum/make.h"
#include "frontend/lexer/token.h"
#include "util/print.h"
#include "util/dynarr.h"
#include "type_type.h"

Go to the source code of this file.

Data Structures

struct  ps_type_field
 A pair (string, type). More...
 
struct  ps_type_variant
 A pair (string, types). More...
 
struct  ps_type_struct
 
struct  ps_type_enum
 
struct  ps_type
 

Macros

#define ps_type_field_arr_new()   ps_dynarr_new(struct ps_type_field_arr)
 
#define ps_type_field_arr_free(arr)   ps_dynarr_free(arr)
 
#define ps_type_variant_arr_new()   ps_dynarr_new(struct ps_type_variant_arr)
 
#define ps_type_variant_arr_free(arr)   ps_dynarr_free(arr)
 
#define ps_type_tuple_new()   ps_dynarr_new(struct ps_type_tuple)
 
#define ps_type_tuple_free(arr)   ps_dynarr_free(arr)
 
#define ENUM   TO_ENUM
 

Enumerations

enum  ps_type_type
 The type of a type :) More...
 

Functions

struct ps_type_field_arr ps_dynarr (struct ps_type_field)
 
struct ps_type_variant_arr ps_dynarr (struct ps_type_variant)
 
struct ps_type_tuple ps_dynarr (struct ps_type *)
 A struct ps_type_tuple is a list of struct ps_types.
 
bool ps_type_is_prim (enum ps_type_type type)
 Returns whether type represents a primitive type.
 
struct ps_typeps_type_prim_new (enum ps_type_type prim_type)
 Constructs a new primitive type specified by prim_type.
 
struct ps_typeps_type_struct_new (struct ps_token *name)
 Constructs a new empty struct type with the name name.
 
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_typeps_type_enum_new (struct ps_token *name)
 Constructs a new empty enum type with the name 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.
 
struct ps_typeps_type_unresolved_new (struct ps_token *name)
 Constructs a new unresolved type corresponding to the given name.
 
struct ps_typeps_type_from_name (struct ps_token *name)
 Returns the type associated with the given name (e.g.
 
struct ps_typeps_type_from_tuple (struct ps_type_tuple *tuple)
 Constructs and returns a type for the given tuple type tuple.
 
 PS_PRINT_DECL (ps_type)
 
 PS_PRINT_DECL (ps_type_tuple)
 
 PS_PRINT_DECL (ps_type_variant)
 
 PS_IPRINT_DECL (ps_type_struct)
 
 PS_IPRINT_DECL (ps_type_enum)
 
 PS_IPRINT_DECL (ps_type_field)
 
 PS_PRINT_DECL (ps_type_field_arr)
 

Macro Definition Documentation

◆ ENUM

#define ENUM   TO_ENUM

Definition at line 61 of file type.h.

◆ ps_type_field_arr_free

#define ps_type_field_arr_free (   arr)    ps_dynarr_free(arr)

Definition at line 31 of file type.h.

◆ ps_type_field_arr_new

#define ps_type_field_arr_new ( )    ps_dynarr_new(struct ps_type_field_arr)

Definition at line 30 of file type.h.

◆ ps_type_tuple_free

#define ps_type_tuple_free (   arr)    ps_dynarr_free(arr)

Definition at line 46 of file type.h.

◆ ps_type_tuple_new

#define ps_type_tuple_new ( )    ps_dynarr_new(struct ps_type_tuple)

Definition at line 45 of file type.h.

◆ ps_type_variant_arr_free

#define ps_type_variant_arr_free (   arr)    ps_dynarr_free(arr)

Definition at line 38 of file type.h.

◆ ps_type_variant_arr_new

#define ps_type_variant_arr_new ( )    ps_dynarr_new(struct ps_type_variant_arr)

Definition at line 37 of file type.h.

Enumeration Type Documentation

◆ ps_type_type

The type of a type :)

Definition at line 60 of file type.h.

Function Documentation

◆ ps_dynarr() [1/3]

struct ps_type_tuple ps_dynarr ( struct ps_type )

A struct ps_type_tuple is a list of struct ps_types.

See also
struct ps_type

◆ ps_dynarr() [2/3]

struct ps_type_field_arr ps_dynarr ( struct ps_type_field  )
See also
struct ps_type_field

◆ ps_dynarr() [3/3]

struct ps_type_variant_arr ps_dynarr ( struct ps_type_variant  )
See also
struct ps_type_variant

◆ PS_IPRINT_DECL() [1/3]

PS_IPRINT_DECL ( ps_type_enum  )

◆ PS_IPRINT_DECL() [2/3]

PS_IPRINT_DECL ( ps_type_field  )

◆ PS_IPRINT_DECL() [3/3]

PS_IPRINT_DECL ( ps_type_struct  )

◆ PS_PRINT_DECL() [1/4]

PS_PRINT_DECL ( ps_type  )

◆ PS_PRINT_DECL() [2/4]

PS_PRINT_DECL ( ps_type_field_arr  )

◆ PS_PRINT_DECL() [3/4]

PS_PRINT_DECL ( ps_type_tuple  )

◆ PS_PRINT_DECL() [4/4]

PS_PRINT_DECL ( ps_type_variant  )

◆ ps_type_enum_add()

void ps_type_enum_add ( struct ps_type type,
struct ps_type_variant  variant 
)

Adds the given variant variant to the struct type type.

Precondition
type represents a enum type.

Definition at line 62 of file type.c.

◆ ps_type_enum_new()

struct ps_type * ps_type_enum_new ( struct ps_token name)

Constructs a new empty enum type with the name name.

TODO: add trait implementations?

Definition at line 52 of file type.c.

◆ ps_type_from_name()

struct ps_type * ps_type_from_name ( struct ps_token name)

Returns the type associated with the given name (e.g.

a primitive type, a struct type).

Precondition
name is a valid pulsar identifier.

Definition at line 76 of file type.c.

◆ ps_type_from_tuple()

struct ps_type * ps_type_from_tuple ( struct ps_type_tuple *  tuple)

Constructs and returns a type for the given tuple type tuple.

Definition at line 86 of file type.c.

◆ ps_type_is_prim()

bool ps_type_is_prim ( enum ps_type_type  type)

Returns whether type represents a primitive type.

Definition at line 19 of file type.c.

◆ ps_type_prim_new()

struct ps_type * ps_type_prim_new ( enum ps_type_type  prim_type)

Constructs a new primitive type specified by prim_type.

Precondition
prim_type corresponds to a primitive type.

Definition at line 23 of file type.c.

◆ ps_type_struct_add()

void ps_type_struct_add ( struct ps_type type,
struct ps_type_field  field 
)

Adds the given field field to the struct type type.

Precondition
type represents a struct type.

Definition at line 47 of file type.c.

◆ ps_type_struct_new()

struct ps_type * ps_type_struct_new ( struct ps_token name)

Constructs a new empty struct type with the name name.

TODO: add trait implementations

Definition at line 37 of file type.c.

◆ ps_type_unresolved_new()

struct ps_type * ps_type_unresolved_new ( struct ps_token name)

Constructs a new unresolved type corresponding to the given name.

These types are resolved in later passes.

Definition at line 67 of file type.c.