GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — PeachCompiler/symresolver.c at main · nibblebits/PeachCompiler Expand file tree/ Copy pathsymresolver.cMore file actions 169 lines (139 loc) · 4.67 KB / Copy pathsymresolver.cFile metadata and controls169 lines (139 loc) · 4.67 KB 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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 /* * PeachCompiler C Compiler Project * Copyright (C) 2026 Daniel McCarthy <[email protected]> * This file is part of the PeachCompiler. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * * 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 version 2 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/>. * * For full source code, documentation, and structured learning, * see the official compiler development video course by Daniel McCarthy here: * dragonzap.com/course/creating-a-c-compiler-from-scratch * * Learn to build your own C compiler from scratch with that video course over 39 hours of video content available. */ #include "compiler.h" #include "helpers/vector.h" static void symresolver_push_symbol(struct compile_process* process, struct symbol* sym) { vector_push(process->symbols.table, &sym); } void symresolver_initialize(struct compile_process* process) { process->symbols.tables = vector_create(sizeof(struct vector*)); } void symresolver_new_table(struct compile_process* process) { // Save the current table vector_push(process->symbols.tables, &process->symbols.table); // Overwrite the active table process->symbols.table = vector_create(sizeof(struct symbol*)); } void symresolver_end_table(struct compile_process* process) { struct vector* last_table = vector_back_ptr(process->symbols.tables); process->symbols.table = last_table; vector_pop(process->symbols.tables); } struct symbol* symresolver_get_symbol(struct compile_process* process, const char* name) { vector_set_peek_pointer(process->symbols.table, 0); struct symbol* symbol = vector_peek_ptr(process->symbols.table); while(symbol) { if (S_EQ(symbol->name, name)) { break; } symbol = vector_peek_ptr(process->symbols.table); } return symbol; } struct symbol* symresolver_get_symbol_for_native_function(struct compile_process* process, const char* name) { struct symbol* sym = symresolver_get_symbol(process, name); if (!sym) { return NULL; } if (sym->type != SYMBOL_TYPE_NATIVE_FUNCTION) { return NULL; } return sym; } struct symbol* symresolver_register_symbol(struct compile_process* process, const char* sym_name, int type, void* data) { if (symresolver_get_symbol(process, sym_name)) { return NULL; } struct symbol* sym = calloc(1, sizeof(struct symbol)); sym->name = sym_name; sym->type = type; sym->data = data; symresolver_push_symbol(process, sym); return sym; } struct node* symresolver_node(struct symbol* sym) { if (sym->type != SYMBOL_TYPE_NODE) { return NULL; } return sym->data; } void symresolver_build_for_variable_node(struct compile_process* process, struct node* node) { symresolver_register_symbol(process, node->var.name, SYMBOL_TYPE_NODE, node); } void symresolver_build_for_function_node(struct compile_process* process, struct node* node) { symresolver_register_symbol(process, node->func.name, SYMBOL_TYPE_NODE, node); } void symresolver_build_for_structure_node(struct compile_process* process, struct node* node) { if (node->flags & NODE_FLAG_IS_FORWARD_DECLARATION) { // We do not register forward declarations. return; } symresolver_register_symbol(process, node->_struct.name, SYMBOL_TYPE_NODE, node); } void symresolver_build_for_union_node(struct compile_process* process, struct node* node) { if (node->flags & NODE_FLAG_IS_FORWARD_DECLARATION) { // We do not register forward declarations. return; } symresolver_register_symbol(process, node->_union.name, SYMBOL_TYPE_NODE, node); } void symresolver_build_for_node(struct compile_process* process, struct node* node) { switch(node->type) { case NODE_TYPE_VARIABLE: symresolver_build_for_variable_node(process, node); break; case NODE_TYPE_FUNCTION: symresolver_build_for_function_node(process, node); break; case NODE_TYPE_STRUCT: symresolver_build_for_structure_node(process, node); break; case NODE_TYPE_UNION: symresolver_build_for_union_node(process, node); break; // Ignore all other node types, because they cant become symbols. } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |