public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
206a827329a7b70fdb960490f0f06f5238de9bfd blob 2744 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
 
/*
 * Copyright (C) 2024 olang maintainers
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
#ifndef AST_H
#define AST_H

#include <stdint.h>

#include "arena.h"
#include "list.h"
#include "string_view.h"

typedef struct ast_node ast_node_t;

typedef enum
{
    AST_NODE_PROGRAM,
    AST_NODE_BLOCK,
    AST_NODE_FN_DEF,
    AST_NODE_BINARY_OP,
    AST_NODE_RETURN_STMT,
    AST_NODE_LITERAL,
    AST_NODE_UNKNOWN
} ast_node_kind_t;

typedef enum
{
    TYPE_U32
} type_t;

typedef struct ast_block
{
    list_t *nodes;
} ast_block_t;

typedef struct ast_program
{
    ast_node_t *fn;
} ast_program_t;

typedef struct ast_fn_definition
{
    string_view_t identifier;
    type_t return_type;
    ast_node_t *block;
} ast_fn_definition_t;

typedef enum
{
    AST_LITERAL_U32
} ast_literal_kind_t;

typedef union
{
    uint32_t as_u32;
} ast_literal_value_t;

typedef struct ast_literal
{
    ast_literal_kind_t kind;
    ast_literal_value_t value;
} ast_literal_t;

typedef enum ast_binary_op_kind
{
    AST_BINOP_ADDITION,
    AST_BINOP_SUBTRACTION,
    AST_BINOP_MULTIPLICATION,
    AST_BINOP_DIVISION,
} ast_binary_op_kind_t;

typedef struct ast_binary_op
{
    ast_binary_op_kind_t kind;
    ast_node_t *lhs;
    ast_node_t *rhs;
} ast_binary_op_t;

typedef struct ast_return_stmt
{
    ast_node_t *data;
} ast_return_stmt_t;

typedef union
{
    ast_program_t as_program;
    ast_fn_definition_t as_fn_def;
    ast_binary_op_t as_bin_op;
    ast_literal_t as_literal;
    ast_block_t as_block;
    ast_return_stmt_t as_return_stmt;
} ast_node_data_t;

typedef struct ast_node
{
    ast_node_kind_t kind;
    ast_node_data_t data;
} ast_node_t;

ast_node_t *
ast_new_program(arena_t *arena, ast_node_t *fn_def);

ast_node_t *
ast_new_node_fn_def(arena_t *arena, string_view_t identifier, type_t return_type, ast_node_t *block);

ast_node_t *
ast_new_node_bin_op(arena_t *arena, ast_binary_op_kind_t kind, ast_node_t *lhs, ast_node_t *rhs);

ast_node_t *
ast_new_node_literal_u32(arena_t *arena, uint32_t value);

ast_node_t *
ast_new_node_return_stmt(arena_t *arena);

ast_node_t *
ast_new_node_block(arena_t *arena);

#endif /* AST_H */
debug log:

solving 206a827 ...
found 206a827 in http://lists.johnnyrichard.com/olang/20240313212855.174554-3-johnny@johnnyrichard.com/
found 2b42781 in https://git.johnnyrichard.com/olang.git
preparing index
index prepared:
100644 2b42781ffdd758d6676d68d0bec48fffa8f71b51	src/ast.h

applying [1/1] http://lists.johnnyrichard.com/olang/20240313212855.174554-3-johnny@johnnyrichard.com/
diff --git a/src/ast.h b/src/ast.h
index 2b42781..206a827 100644

Checking patch src/ast.h...
Applied patch src/ast.h cleanly.

index at:
100644 206a827329a7b70fdb960490f0f06f5238de9bfd	src/ast.h

Code repositories for project(s) associated with this public inbox

	https://git.johnnyrichard.com/olang.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox