static void name(Parser* p, Item* item)
#endif
-/* Default Symbol List
- *****************************************************************************/
-static Symbol BoolSym = {
- .class = SYM_TYPE,
- .name = "Bool",
- .type = &BoolType
-};
-
-static Symbol IntSym = {
- .next = &BoolSym,
- .class = SYM_TYPE,
- .name = "Int",
- .type = &IntType
-};
-
-static Symbol RealSym = {
- .next = &IntSym,
- .class = SYM_TYPE,
- .name = "Real",
- .type = &RealType
-};
-
/* Item Handling
*****************************************************************************/
static void init_item(Item* item, Symbol* sym)
export = accept(p, '*');
sym = symbol_new(p, 0, name, SYM_VAR, export);
first = (nsyms == 0 ? sym : first);
- sym->global = (p->level <= 1 ? 1 : 0);
+// sym->global = (p->level <= 1 ? 1 : 0);
nsyms++;
}
while (accept(p, ','));
char* fcontents = file_load(fname);
Parser* p = &(Parser){
.name = NULL,
- .scope = &RealSym,
+// .scope = &RealSym,
.file = &(LexFile){
.path = fname,
.fbeg = fcontents,
},
.curr_reg = 0
};
+
+ symbol_new(p, 0, "Bool", SYM_TYPE, 0)->type = &BoolType;
+ symbol_new(p, 0, "Int", SYM_TYPE, 0)->type = &IntType;
+ symbol_new(p, 0, "Real", SYM_TYPE, 0)->type = &RealType;
+ symbol_new(p, 0, "String", SYM_TYPE, 0)->type = &StringType;
+
codegen_startmod(p);
module(p, &(Item){0});
codegen_main(p);
Parser Ctx = {0};
-static Symbol InitialScope = {
- .next = &RealSym,
- .class = SYM_SCOPE,
-};
-
static void parse_init(char* fname, char* string)
{
memset(&Ctx, 0, sizeof(Ctx));
- Ctx.scope = &InitialScope;
- InitialScope.desc = NULL;
+ symbol_new(&Ctx, 0, "Bool", SYM_TYPE, 0)->type = &BoolType;
+ symbol_new(&Ctx, 0, "Int", SYM_TYPE, 0)->type = &IntType;
+ symbol_new(&Ctx, 0, "Real", SYM_TYPE, 0)->type = &RealType;
+ symbol_new(&Ctx, 0, "String", SYM_TYPE, 0)->type = &StringType;
LexFile* file = calloc(sizeof(LexFile), 1u);
file->path = strdup(fname);
file->fbeg = file->fpos = strdup(string);
static int sym_matches(Parser* p, int class, char* name, Symbol* sym)
{
+// printf("%s == %s\n", name, sym->name);
if (name && sym->name && !strcmp(sym->name, name))
{
if (class >= 0 && (int)sym->class != class)
Symbol* sym = NULL;
size_t index = lookup(p, 0, name, class);
- if (NIL_SYMBOL != index)
+ if (NIL_SYMBOL == index)
{
error(p, "unknown symbol '%s'", name);
}