annotate lwbasic/attic/symtab.c @ 262:7de7b14ebaee

Add support for os9 module edition byte Add support for the symbol "edition" in the __os9 section which defines the module edition byte which follows immedately after the module name in the module. It defaults to not setting one.
author William Astle <lost@l-w.ca>
date Mon, 04 Feb 2013 21:03:59 -0700
parents cca933d32298
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
1 /*
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
2 symtab.c
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
3
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
4 Copyright © 2011 William Astle
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
5
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
6 This file is part of LWTOOLS.
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
7
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
11 version.
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
12
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
16 more details.
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
17
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
20 */
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
21
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
22 /*
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
23 Symbol table handling
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
24 */
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
25
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
26 #include <stdlib.h>
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
27 #include <string.h>
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
28
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
29 #include <lw_alloc.h>
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
30 #include <lw_string.h>
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
31
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
32 #define __symtab_c_seen__
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
33 #include "symtab.h"
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
34
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
35 symtab_t *symtab_init(void)
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
36 {
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
37 symtab_t *st;
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
38
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
39 st = lw_alloc(sizeof(symtab_t));
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
40 st -> head = NULL;
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
41 return st;
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
42 }
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
43
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
44 void symtab_destroy(symtab_t *st)
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
45 {
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
46 symtab_entry_t *se;
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
47
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
48 while (st -> head)
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
49 {
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
50 se = st -> head;
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
51 st -> head = se -> next;
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
52 lw_free(se -> name);
32
49d608aecc4d Framework for handling local stack frame and/or variables
lost@l-w.ca
parents: 29
diff changeset
53 lw_free(se -> privdata);
29
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
54 lw_free(se);
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
55 }
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
56 lw_free(st);
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
57 }
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
58
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
59 symtab_entry_t *symtab_find(symtab_t *st, char *name)
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
60 {
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
61 symtab_entry_t *se;
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
62
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
63 for (se = st -> head; se; se = se -> next)
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
64 {
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
65 if (strcmp(se -> name, name) == 0)
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
66 return se;
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
67 }
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
68 return NULL;
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
69 }
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
70
32
49d608aecc4d Framework for handling local stack frame and/or variables
lost@l-w.ca
parents: 29
diff changeset
71 void symtab_register(symtab_t *st, char *name, int addr, int symtype, void *privdata)
29
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
72 {
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
73 symtab_entry_t *se;
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
74
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
75 se = lw_alloc(sizeof(symtab_entry_t));
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
76 se -> name = lw_strdup(name);
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
77 se -> addr = addr;
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
78 se -> symtype = symtype;
32
49d608aecc4d Framework for handling local stack frame and/or variables
lost@l-w.ca
parents: 29
diff changeset
79 se -> privdata = privdata;
29
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
80 se -> next = st -> head;
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
81 st -> head = se;
bc96cd02fbf4 Added basic symbol table structure
lost@l-w.ca
parents:
diff changeset
82 }