/* initialize the name special entities XPOST_MEMORY_TABLE_SPECIAL_NAME_STACK, NAME_TREE */ int xpost_name_init(Xpost_Context *ctx) { Xpost_Memory_Table *tab; unsigned int ent; unsigned int t; unsigned int mode; unsigned int nstk; int ret; mode = ctx->vmmode; ctx->vmmode = GLOBAL; ret = xpost_memory_table_alloc(ctx->gl, 0, 0, &ent); //gl:NAMES if (!ret) { return 0; } //assert(ent == XPOST_MEMORY_TABLE_SPECIAL_NAME_STACK); if (ent != XPOST_MEMORY_TABLE_SPECIAL_NAME_STACK) XPOST_LOG_ERR("Warning: name stack is not in special position"); ret = xpost_memory_table_alloc(ctx->gl, 0, 0, &ent); //gl:NAMET if (!ret) { return 0; } //assert(ent == XPOST_MEMORY_TABLE_SPECIAL_NAME_TREE); if (ent != XPOST_MEMORY_TABLE_SPECIAL_NAME_TREE) XPOST_LOG_ERR("Warning: name tree is not in special position"); xpost_stack_init(ctx->gl, &t); tab = &ctx->gl->table; //recalc pointer tab->tab[XPOST_MEMORY_TABLE_SPECIAL_NAME_STACK].adr = t; tab->tab[XPOST_MEMORY_TABLE_SPECIAL_NAME_TREE].adr = 0; xpost_memory_table_get_addr(ctx->gl, XPOST_MEMORY_TABLE_SPECIAL_NAME_STACK, &nstk); xpost_stack_push(ctx->gl, nstk, xpost_string_cons(ctx, CNT_STR("_not_a_name_"))); assert (xpost_object_get_ent(xpost_stack_topdown_fetch(ctx->gl, nstk, 0)) == XPOST_MEMORY_TABLE_SPECIAL_BOGUS_NAME); ctx->vmmode = LOCAL; ret = xpost_memory_table_alloc(ctx->lo, 0, 0, &ent); //lo:NAMES if (!ret) { return 0; } //assert(ent == XPOST_MEMORY_TABLE_SPECIAL_NAME_STACK); if (ent != XPOST_MEMORY_TABLE_SPECIAL_NAME_STACK) XPOST_LOG_ERR("Warning: name stack is not in special position"); ret = xpost_memory_table_alloc(ctx->lo, 0, 0, &ent); //lo:NAMET if (!ret) { return 0; } //assert(ent == XPOST_MEMORY_TABLE_SPECIAL_NAME_TREE); if (ent != XPOST_MEMORY_TABLE_SPECIAL_NAME_TREE) XPOST_LOG_ERR("Warning: name tree is not in special position"); xpost_stack_init(ctx->lo, &t); tab = &ctx->lo->table; //recalc pointer tab->tab[XPOST_MEMORY_TABLE_SPECIAL_NAME_STACK].adr = t; tab->tab[XPOST_MEMORY_TABLE_SPECIAL_NAME_TREE].adr = 0; xpost_memory_table_get_addr(ctx->lo, XPOST_MEMORY_TABLE_SPECIAL_NAME_STACK, &nstk); xpost_stack_push(ctx->lo, nstk, xpost_string_cons(ctx, CNT_STR("_not_a_name_"))); //assert (xpost_object_get_ent(xpost_stack_topdown_fetch(ctx->lo, nstk, 0)) == XPOST_MEMORY_TABLE_SPECIAL_BOGUS_NAME); if (xpost_object_get_ent(xpost_stack_topdown_fetch(ctx->lo, nstk, 0)) != XPOST_MEMORY_TABLE_SPECIAL_BOGUS_NAME) XPOST_LOG_ERR("Warning: bogus name not in special position"); ctx->vmmode = mode; return 1; }
static int init_test_garbage(int (*xpost_interpreter_cid_init)(unsigned int *cid), Xpost_Context *(*xpost_interpreter_cid_get_context)(unsigned int cid), int (*xpost_interpreter_get_initializing)(void), void (*xpost_interpreter_set_initializing)(int), Xpost_Memory_File *(*xpost_interpreter_alloc_global_memory)(void), Xpost_Memory_File *(*xpost_interpreter_alloc_local_memory)(void)) { int fd; unsigned int cid; char fname[] = "xmemXXXXXX"; unsigned int tadr; int ret; unsigned int ent; /* create interpreter and context */ itpdata = malloc(sizeof*itpdata); if (!itpdata) return 0; memset(itpdata, 0, sizeof*itpdata); ret = xpost_interpreter_cid_init(&cid); if (!ret) return 0; ctx = xpost_interpreter_cid_get_context(cid); ctx->id = cid; /* create global memory file */ ctx->gl = xpost_interpreter_alloc_global_memory(); if (ctx->gl == NULL) { return 0; } fd = mkstemp(fname); ret = xpost_memory_file_init(ctx->gl, fname, fd, xpost_interpreter_cid_get_context, xpost_interpreter_get_initializing, xpost_interpreter_set_initializing); if (!ret) { close(fd); return 0; } ret = xpost_memory_table_init(ctx->gl, &tadr); if (!ret) { xpost_memory_file_exit(ctx->gl); return 0; } ret = xpost_free_init(ctx->gl); if (!ret) { xpost_memory_file_exit(ctx->gl); return 0; } ret = xpost_save_init(ctx->gl); if (!ret) { xpost_memory_file_exit(ctx->gl); return 0; } ret = xpost_context_init_ctxlist(ctx->gl); if (!ret) { xpost_memory_file_exit(ctx->gl); return 0; } xpost_context_append_ctxlist(ctx->gl, ctx->id); ctx->gl->start = XPOST_MEMORY_TABLE_SPECIAL_OPERATOR_TABLE + 1; /* create local memory file */ ctx->lo = xpost_interpreter_alloc_local_memory(); if (ctx->lo == NULL) { xpost_memory_file_exit(ctx->gl); return 0; } strcpy(fname, "xmemXXXXXX"); fd = mkstemp(fname); ret = xpost_memory_file_init(ctx->lo, fname, fd, xpost_interpreter_cid_get_context, xpost_interpreter_get_initializing, xpost_interpreter_set_initializing); if (!ret) { close(fd); xpost_memory_file_exit(ctx->gl); return 0; } ret = xpost_memory_table_init(ctx->lo, &tadr); if (!ret) { xpost_memory_file_exit(ctx->gl); xpost_memory_file_exit(ctx->lo); return 0; } ret = xpost_free_init(ctx->lo); if (!ret) { xpost_memory_file_exit(ctx->gl); xpost_memory_file_exit(ctx->lo); return 0; } ret = xpost_save_init(ctx->lo); if (!ret) { xpost_memory_file_exit(ctx->gl); xpost_memory_file_exit(ctx->lo); return 0; } ret = xpost_context_init_ctxlist(ctx->lo); if (!ret) { xpost_memory_file_exit(ctx->gl); xpost_memory_file_exit(ctx->lo); return 0; } xpost_context_append_ctxlist(ctx->lo, ctx->id); ctx->lo->start = XPOST_MEMORY_TABLE_SPECIAL_BOGUS_NAME + 1; /* create names in both mfiles */ ret = xpost_name_init(ctx); if (!ret) { xpost_memory_file_exit(ctx->gl); xpost_memory_file_exit(ctx->lo); return 0; } /* create global OPTAB */ ctx->vmmode = GLOBAL; /*ret = initoptab(ctx);*/ /* NO! only need to allocate something in the table slot */ ret = xpost_memory_table_alloc(ctx->gl, 1024, 0, &ent); if (!ret) { xpost_memory_file_exit(ctx->gl); xpost_memory_file_exit(ctx->lo); return 0; } /* ... no initop(). don't need operators for this. */ /* only need one stack */ ctx->vmmode = LOCAL; xpost_stack_init(ctx->lo, &ctx->hold); ctx->os = ctx->ds = ctx->es = ctx->hold; ctx->gl->interpreter_set_initializing(0); /* garbage collector won't run otherwise */ return 1; }