remove gref slot

This commit is contained in:
Yuichi Nishiwaki 2016-02-07 22:17:56 +09:00
parent e076a8f4e0
commit f263e9432e
7 changed files with 18 additions and 78 deletions

View File

@ -146,12 +146,14 @@ define_var(pic_state *pic, analyze_scope *scope, pic_sym *sym)
int ret;
if (search_scope(scope, sym)) {
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))) {
if (scope->depth > 0 || pic_reg_has(pic, pic->globals, sym)) {
pic_warnf(pic, "redefining variable: ~s", pic_obj_value(sym));
}
return;
}
pic_reg_set(pic, pic->globals, sym, pic_invalid_value());
kh_put(a, &scope->locals, sym, &ret);
}
@ -514,15 +516,11 @@ index_local(codegen_context *cxt, pic_sym *sym)
static int
index_global(pic_state *pic, codegen_context *cxt, pic_sym *name)
{
extern struct pic_box *pic_vm_gref_slot(pic_state *, pic_sym *);
int pidx;
struct pic_box *slot;
slot = pic_vm_gref_slot(pic, name);
check_pool_size(pic, cxt);
pidx = (int)cxt->plen++;
cxt->pool[pidx] = (struct pic_object *)(slot);
cxt->pool[pidx] = (struct pic_object *)name;
return pidx;
}

View File

@ -35,7 +35,6 @@ struct pic_object {
struct pic_port port;
struct pic_error err;
struct pic_lib lib;
struct pic_box box;
struct pic_checkpoint cp;
} u;
};
@ -394,12 +393,6 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
pic->heap->regs = reg;
break;
}
case PIC_TT_BOX: {
if (pic_obj_p(obj->u.box.value)) {
LOOP(pic_obj_ptr(obj->u.box.value));
}
break;
}
case PIC_TT_CP: {
if (obj->u.cp.prev) {
gc_mark_object(pic, (struct pic_object *)obj->u.cp.prev);
@ -588,7 +581,6 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj)
case PIC_TT_LIB:
case PIC_TT_RECORD:
case PIC_TT_CP:
case PIC_TT_BOX:
break;
case PIC_TT_NIL:

View File

@ -251,7 +251,6 @@ pic_value pic_fdisplay(pic_state *, pic_value, xFILE *);
#include "picrin/symbol.h"
#include "picrin/vector.h"
#include "picrin/reg.h"
#include "picrin/box.h"
#if defined(__cplusplus)
}

View File

@ -1,34 +0,0 @@
/**
* See Copyright Notice in picrin.h
*/
#ifndef PICRIN_BOX_H
#define PICRIN_BOX_H
#if defined(__cplusplus)
extern "C" {
#endif
struct pic_box {
PIC_OBJECT_HEADER
pic_value value;
};
#define pic_box_p(v) (pic_type(v) == PIC_TT_BOX)
#define pic_box_ptr(v) ((struct pic_box *)pic_ptr(v))
PIC_INLINE struct pic_box *
pic_box(pic_state *pic, pic_value value)
{
struct pic_box *box;
box = (struct pic_box *)pic_obj_alloc(pic, sizeof(struct pic_box), PIC_TT_BOX);
box->value = value;
return box;
}
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -26,7 +26,6 @@ pic_value pic_reg_ref(pic_state *, struct pic_reg *, void *);
void pic_reg_set(pic_state *, struct pic_reg *, void *, pic_value);
void pic_reg_del(pic_state *, struct pic_reg *, void *);
bool pic_reg_has(pic_state *, struct pic_reg *, void *);
void *pic_reg_rev_ref(pic_state *, struct pic_reg *, pic_value);
#if defined(__cplusplus)
}

View File

@ -156,7 +156,6 @@ enum pic_tt {
PIC_TT_DICT,
PIC_TT_REG,
PIC_TT_RECORD,
PIC_TT_BOX,
PIC_TT_CXT,
PIC_TT_CP
};
@ -311,8 +310,6 @@ pic_type_repr(enum pic_tt tt)
return "dict";
case PIC_TT_REG:
return "reg";
case PIC_TT_BOX:
return "box";
case PIC_TT_RECORD:
return "record";
case PIC_TT_CP:

View File

@ -175,35 +175,24 @@ pic_get_args(pic_state *pic, const char *format, ...)
return argc;
}
struct pic_box *
pic_vm_gref_slot(pic_state *pic, pic_sym *uid) /* TODO: make this static */
{
struct pic_box *box;
if (pic_reg_has(pic, pic->globals, uid)) {
return pic_box_ptr(pic_reg_ref(pic, pic->globals, uid));
}
box = pic_box(pic, pic_invalid_value());
pic_reg_set(pic, pic->globals, uid, pic_obj_value(box));
return box;
}
static pic_value
vm_gref(pic_state *pic, struct pic_box *slot, pic_sym *uid)
vm_gref(pic_state *pic, pic_sym *uid)
{
if (pic_invalid_p(slot->value)) {
if (uid == NULL) {
uid = pic_reg_rev_ref(pic, pic->globals, pic_obj_value(slot));
}
if (! pic_reg_has(pic, pic->globals, uid)) {
pic_reg_set(pic, pic->globals, uid, pic_invalid_value());
pic_errorf(pic, "uninitialized global variable: %s", pic_symbol_name(pic, uid));
return pic_invalid_value();
}
return slot->value;
return pic_reg_ref(pic, pic->globals, uid);
}
static void
vm_gset(struct pic_box *slot, pic_value value)
vm_gset(pic_state *pic, pic_sym *uid, pic_value value)
{
slot->value = value;
pic_reg_set(pic, pic->globals, uid, value);
}
static void
@ -423,11 +412,11 @@ pic_apply(pic_state *pic, struct pic_proc *proc, int argc, pic_value *argv)
NEXT;
}
CASE(OP_GREF) {
PUSH(vm_gref(pic, (struct pic_box *)(pic->ci->irep->pool[c.a]), NULL)); /* FIXME */
PUSH(vm_gref(pic, (pic_sym *)pic->ci->irep->pool[c.a]));
NEXT;
}
CASE(OP_GSET) {
vm_gset((struct pic_box *)(pic->ci->irep->pool[c.a]), POP());
vm_gset(pic, (pic_sym *)pic->ci->irep->pool[c.a], POP());
PUSH(pic_undef_value());
NEXT;
}
@ -972,7 +961,7 @@ pic_ref(pic_state *pic, struct pic_lib *lib, const char *name)
pic_errorf(pic, "symbol \"%s\" not defined in library ~s", name, lib->name);
}
return vm_gref(pic, pic_vm_gref_slot(pic, uid), uid);
return vm_gref(pic, uid);
}
void
@ -986,7 +975,7 @@ pic_set(pic_state *pic, struct pic_lib *lib, const char *name, pic_value val)
pic_errorf(pic, "symbol \"%s\" not defined in library ~s", name, lib->name);
}
vm_gset(pic_vm_gref_slot(pic, uid), val);
vm_gset(pic, uid, val);
}
static struct pic_proc *