global variable table may be weak

This commit is contained in:
Yuichi Nishiwaki 2015-08-05 09:36:32 +09:00
parent 673198bbb6
commit 5fa24f9767
5 changed files with 12 additions and 8 deletions

View File

@ -436,7 +436,7 @@ define_var(pic_state *pic, analyze_scope *scope, pic_sym *sym)
int ret; int ret;
if (search_scope(scope, sym)) { if (search_scope(scope, sym)) {
if (scope->depth > 0 || (pic_dict_has(pic, pic->globals, sym) && ! pic_invalid_p(pic_box_ptr(pic_dict_ref(pic, pic->globals, sym))->value))) { if (scope->depth > 0 || (pic_reg_has(pic, pic->globals, sym) && ! pic_invalid_p(pic_box_ptr(pic_reg_ref(pic, pic->globals, sym))->value))) {
pic_warnf(pic, "redefining variable: ~s", pic_obj_value(sym)); pic_warnf(pic, "redefining variable: ~s", pic_obj_value(sym));
} }
return; return;

View File

@ -484,6 +484,7 @@ gc_mark_phase(pic_state *pic)
M(uDEFINE); M(uLAMBDA); M(uIF); M(uBEGIN); M(uQUOTE); M(uSETBANG); M(uDEFINE_MACRO); M(uDEFINE); M(uLAMBDA); M(uIF); M(uBEGIN); M(uQUOTE); M(uSETBANG); M(uDEFINE_MACRO);
M(uDEFINE_LIBRARY); M(uIMPORT); M(uEXPORT); M(uCOND_EXPAND); M(uDEFINE_LIBRARY); M(uIMPORT); M(uEXPORT); M(uCOND_EXPAND);
M(uCONS); M(uCAR); M(uCDR); M(uNILP); M(uSYMBOLP); M(uPAIRP); M(uCONS); M(uCAR); M(uCDR); M(uNILP); M(uSYMBOLP); M(uPAIRP);
M(uADD); M(uSUB); M(uMUL); M(uDIV); M(uEQ); M(uLT); M(uLE); M(uGT); M(uGE); M(uNOT); M(uADD); M(uSUB); M(uMUL); M(uDIV); M(uEQ); M(uLT); M(uLE); M(uGT); M(uGE); M(uNOT);
@ -491,6 +492,9 @@ gc_mark_phase(pic_state *pic)
P(pCONS); P(pCAR); P(pCDR); P(pNILP); P(pSYMBOLP); P(pPAIRP); P(pNOT); P(pCONS); P(pCAR); P(pCDR); P(pNILP); P(pSYMBOLP); P(pPAIRP); P(pNOT);
P(pADD); P(pSUB); P(pMUL); P(pDIV); P(pEQ); P(pLT); P(pLE); P(pGT); P(pGE); P(pADD); P(pSUB); P(pMUL); P(pDIV); P(pEQ); P(pLT); P(pLE); P(pGT); P(pGE);
M(cCONS); M(cCAR); M(cCDR); M(cNILP); M(cSYMBOLP); M(cPAIRP); M(cNOT);
M(cADD); M(cSUB); M(cMUL); M(cDIV); M(cEQ); M(cLT); M(cLE); M(cGT); M(cGE);
/* global variables */ /* global variables */
if (pic->globals) { if (pic->globals) {
gc_mark_object(pic, (union object *)pic->globals); gc_mark_object(pic, (union object *)pic->globals);

View File

@ -119,7 +119,7 @@ struct pic_state {
khash_t(s) syms; /* name to symbol */ khash_t(s) syms; /* name to symbol */
int ucnt; int ucnt;
struct pic_dict *globals; struct pic_reg *globals;
struct pic_dict *macros; struct pic_dict *macros;
pic_value libs; pic_value libs;
struct pic_reg *attrs; struct pic_reg *attrs;

View File

@ -407,7 +407,7 @@ pic_open(pic_allocf allocf, void *userdata)
pic->pGE = pic_invalid_value(); pic->pGE = pic_invalid_value();
/* root tables */ /* root tables */
pic->globals = pic_make_dict(pic); pic->globals = pic_make_reg(pic);
pic->macros = pic_make_dict(pic); pic->macros = pic_make_dict(pic);
pic->attrs = pic_make_reg(pic); pic->attrs = pic_make_reg(pic);

View File

@ -387,15 +387,15 @@ pic_get_args(pic_state *pic, const char *format, ...)
} }
struct pic_box * struct pic_box *
pic_vm_gref_slot(pic_state *pic, pic_sym *uid) pic_vm_gref_slot(pic_state *pic, pic_sym *uid) /* TODO: make this static */
{ {
struct pic_box *box; struct pic_box *box;
if (pic_dict_has(pic, pic->globals, uid)) { if (pic_reg_has(pic, pic->globals, uid)) {
return pic_box_ptr(pic_dict_ref(pic, pic->globals, uid)); return pic_box_ptr(pic_reg_ref(pic, pic->globals, uid));
} }
box = pic_box(pic, pic_invalid_value()); box = pic_box(pic, pic_invalid_value());
pic_dict_set(pic, pic->globals, uid, pic_obj_value(box)); pic_reg_set(pic, pic->globals, uid, pic_obj_value(box));
return box; return box;
} }
@ -1112,7 +1112,7 @@ pic_define_(pic_state *pic, const char *name, pic_value val)
if ((uid = pic_find_variable(pic, pic->lib->env, pic_obj_value(sym))) == NULL) { if ((uid = pic_find_variable(pic, pic->lib->env, pic_obj_value(sym))) == NULL) {
uid = pic_add_variable(pic, pic->lib->env, pic_obj_value(sym)); uid = pic_add_variable(pic, pic->lib->env, pic_obj_value(sym));
} else { } else {
if (pic_dict_has(pic, pic->globals, uid)) { if (pic_reg_has(pic, pic->globals, uid)) {
pic_warnf(pic, "redefining variable: ~s", pic_obj_value(uid)); pic_warnf(pic, "redefining variable: ~s", pic_obj_value(uid));
} }
} }