diff options
Diffstat (limited to 'src/analyzer.h')
-rw-r--r-- | src/analyzer.h | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/src/analyzer.h b/src/analyzer.h index 726b4e5..a1c55f5 100644 --- a/src/analyzer.h +++ b/src/analyzer.h @@ -3,14 +3,26 @@ #include <stdint.h> +#include "alloc.h" #include "lexer.h" #include "parser.h" +#include "types.h" +/* The different base types */ enum { - TYPE_UNSET = 0, - TYPE_CHECKING = 1, + /* No type exists (or hasn’t yet been typechecked) */ + TYPE_UNSET, + + /* Currently in the process of being typechecked. Useful for + detecting cyclic definitions. */ + TYPE_CHECKING, + + /* A numeric type */ TYPE_NUM, + + /* A function type */ TYPE_FN, + _TYPE_LAST_ENT, }; @@ -18,18 +30,32 @@ typedef uint8_t type_kind_t_; static_assert(_TYPE_LAST_ENT - 1 <= (type_kind_t_)-1, "Too many AST tokens to fix in TYPE_KIND_T_"); +typedef struct symtab symtab; + +struct scope { + idx_t_ up, i; + symtab *map; +}; + +/* A variable type */ struct type { type_kind_t_ kind; - uint8_t size : 6; /* bytes */ - bool issigned : 1; - bool isfloat : 1; - /* For functions */ - const struct type *params, *ret; - idx_t_ paramcnt; + union { + struct { + uint8_t size; + bool issigned; + bool isfloat; + }; + struct { + const struct type *params, *ret; + idx_t_ paramcnt; + }; + }; }; -struct type *analyzeprog(struct ast, struct lexemes) - __attribute__((returns_nonnull)); +void analyzeprog(struct ast, struct lexemes, arena *, struct type **, + struct scope **) + __attribute__((nonnull)); #endif /* !ORYX_ANALYZER_H */ |