int main(void) { if (!xpost_init()) { fprintf(stderr, "Fail to initialize xpost dict test\n"); return -1; } init(); printf("\n^test gc.c\n"); ctx = &itpdata->ctab[0]; mem = ctx->lo; stac = ctx->os; xpost_stack_push(mem, stac, xpost_int_cons(5)); xpost_stack_push(mem, stac, xpost_int_cons(6)); xpost_stack_push(mem, stac, xpost_real_cons(7.0)); Xpost_Object ar; ar = xpost_array_cons_memory(mem, 3); int i; for (i=0; i < 3; i++) xpost_array_put_memory(mem, ar, i, xpost_stack_pop(mem, stac)); xpost_stack_push(mem, stac, ar); /* array on stack */ xpost_stack_push(mem, stac, xpost_int_cons(1)); xpost_stack_push(mem, stac, xpost_int_cons(2)); xpost_stack_push(mem, stac, xpost_int_cons(3)); ar = xpost_array_cons_memory(mem, 3); for (i=0; i < 3; i++) xpost_array_put_memory(mem, ar, i, xpost_stack_pop(mem, stac)); xpost_object_dump(ar); /* array not on stack */ #define CNT_STR(x) sizeof(x), x xpost_stack_push(mem, stac, xpost_string_cons_memory(mem, CNT_STR("string on stack"))); xpost_object_dump(xpost_string_cons_memory(mem, CNT_STR("string not on stack"))); collect(mem); xpost_stack_push(mem, stac, xpost_string_cons_memory(mem, CNT_STR("string on stack"))); xpost_object_dump(xpost_string_cons_memory(mem, CNT_STR("string not on stack"))); collect(mem); xpost_memory_file_dump(mem); printf("stackaedr: %04x\n", stac); dumpmtab(mem, 0); /* ^ent 8 (8): adr 3404 0x0d4c, sz [24], mark _ */ /* ^ 06 00 00 00 6en 67g 20 6en 6fo 74t 20 */ printf("gc: look at the mark field . . . . . . . .^\n"); printf("also, see that the first 4 bytes of strings not on stack\n" "have been obliterated to link-up the free list.\n"); xpost_quit(); }
/* 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; }