mighty

The mighty programming language, compiler and tools (WIP)
Log | Files | Refs

types.h (1063B)



#pragma once

#include <stddef.h>
#include "token.h"

struct span {
    const char *filename;
    size_t line, col;
    size_t start, stop;
};

struct token {
    enum token_type token_type;
    struct span span;
};

struct lexer {
    const char *file;
    const char *src;
    size_t src_len;
    struct token *tokens;
    size_t tok_len;
    size_t tok_cap;
};

struct scope {
    void *tbd;
};

enum node_type {
    NODE_PROGRAM = 100,
    NODE_FUNC_DECL,
};

struct node {
    enum node_type type;
    struct token token;
    struct scope *scope;
    union {
        /* clang-format off */
        struct { struct node **declarations; size_t len, cap; } program;
        struct { struct node* return_type; struct node** params; size_t p_len, p_cap; struct node* body; bool is_public; } func_decl;
        struct { struct node* type; } func_decl_param;
        /* clang-format on */
    };
};

struct parser {
    struct lexer *lexer;
    struct node **nodes;
    size_t nodes_len, nodes_cap;
    size_t pos;
    size_t err_len, err_cap;
    char *errors;
};