Example #1
0
static ChimpRef *
_chimp_symtable_init (ChimpRef *self, ChimpRef *args)
{
    ChimpRef *filename;
    ChimpRef *ast;

    if (!chimp_method_parse_args (args, "oo", &filename, &ast)) {
        return NULL;
    }

    CHIMP_ANY(self)->klass = chimp_symtable_class;
    CHIMP_SYMTABLE(self)->filename = filename;
    CHIMP_SYMTABLE(self)->ste = chimp_nil;
    CHIMP_SYMTABLE(self)->lookup = chimp_hash_new ();
    if (CHIMP_SYMTABLE(self)->lookup == NULL) {
        return NULL;
    }
    CHIMP_SYMTABLE(self)->stack = chimp_array_new ();
    if (CHIMP_SYMTABLE(self)->stack == NULL) {
        return NULL;
    }

    if (CHIMP_ANY_CLASS(ast) == chimp_ast_mod_class) {
        if (!chimp_symtable_visit_mod (self, ast))
            return NULL;
    }
    else {
        CHIMP_BUG ("unknown top-level AST node type: %s",
                    CHIMP_STR_DATA(CHIMP_CLASS(CHIMP_ANY_CLASS(ast))->name));
        return NULL;
    }

    return self;
}
Example #2
0
static ChimpRef *
_chimp_symtable_entry_init (ChimpRef *self, ChimpRef *args)
{
    int64_t flags;
    ChimpRef *symtable;
    ChimpRef *scope;
    ChimpRef *parent;

    if (!chimp_method_parse_args (
            args, "oooI", &symtable, &parent, &scope, &flags)) {
        return NULL;
    }

    CHIMP_SYMTABLE_ENTRY(self)->flags = flags;
    CHIMP_SYMTABLE_ENTRY(self)->symtable = symtable;
    CHIMP_SYMTABLE_ENTRY(self)->scope = scope;
    CHIMP_SYMTABLE_ENTRY(self)->parent = parent;
    CHIMP_SYMTABLE_ENTRY(self)->symbols = chimp_hash_new ();
    if (CHIMP_SYMTABLE_ENTRY(self)->symbols == NULL) {
        return NULL;
    }
    CHIMP_SYMTABLE_ENTRY(self)->children = chimp_array_new ();
    if (CHIMP_SYMTABLE_ENTRY(self)->children == NULL) {
        return NULL;
    }
    return self;
}
Example #3
0
File: task.c Project: eax/chimp
chimp_bool_t
chimp_task_add_module (ChimpTaskInternal *task, ChimpRef *module)
{
    if (task == NULL) {
        task = chimp_task_current ();
    }

    if (task->modules == NULL) {
        task->modules = chimp_hash_new ();
        if (task->modules == NULL) {
            return CHIMP_FALSE;
        }
        chimp_gc_make_root (NULL, task->modules);
    }

    return chimp_hash_put (task->modules, CHIMP_MODULE(module)->name, module);
}