예제 #1
0
파일: gc.c 프로젝트: mtmiron/toi
void
memdealloc(VALUE obj)
{
#ifdef GCLOG
    static int fd = 0;
    char buf[65536];
#endif

    if (!TEST(obj))
        return;

    if (BASIC(obj).refcount == GC_NEVER_FREE)
        return;

    switch (TYPE(obj))
    {
    case T_CLASS:
    case T_SYMBOL:
    case T_MCALL:
    case T_CREF:
    case T_ASSIGN:
    case T_BRANCH:
    case T_BREAK:
    case T_TRUE:
    case T_NIL:
    case T_LABEL:
    case T_TRY:
    case T_CATCH:
    case T_BEGIN:
    case T_RESCUE:
        /* should never be garbage collected */
        return;

    case T_THREAD:
        if (main_thread() == obj)
            return;
    default:
        break;
    }

#ifdef GCLOG
    if (!fd)
    {
        fd = open("gc.log", O_WRONLY | O_CREAT | O_TRUNC);
        if (!fd)
        {
            perror("open");
            fail("error during logging of GC activity");
        }
    }
    snprintf(buf, sizeof(buf), "gc deallocating %s:%p\n", type2cstring(obj), (VALUE*)obj);
    write(fd, buf, strlen(buf));
#endif

    if (BASIC(obj).reap)
        BASIC(obj).reap(obj);

    free((VALUE*)obj);
}
예제 #2
0
파일: gc.c 프로젝트: mtmiron/toi
int
object_refcount_up(void *ptr)
{
    VALUE obj = (VALUE)ptr;

    if (BASIC(obj).refcount == GC_NEVER_FREE)
        return VECTOR_CONTINUE;

    BASIC(obj).refcount++;
    return VECTOR_CONTINUE;
}
예제 #3
0
파일: gc.c 프로젝트: mtmiron/toi
int
object_refcount_check(void *ptr)
{
    VALUE obj = (VALUE)ptr;

    if ( (BASIC(obj).refcount == GC_NEVER_FREE) ||
            (BASIC(obj).refcount > 0) )
        return VECTOR_CONTINUE;

    memdealloc(obj);
    return VECTOR_DELETE;
}
예제 #4
0
파일: hash.c 프로젝트: mtmiron/toi
VALUE
hash_new()
{
	VALUE hash;

	hash = NEW_OBJ(Hash);
	OBJ_SETUP(hash, T_HASH);
	BASIC(hash).klass = cHash;
	BASIC(hash).reap = hash_reap;
	HASH(hash)->ptr = st_init_numtable();

	return (VALUE)hash;
}
예제 #5
0
파일: thread.c 프로젝트: mtmiron/toi
VALUE
thread_new()
{
	VALUE thr;

	thr = NEW_OBJ(Thread);
	OBJ_SETUP(thr, T_THREAD);
	BASIC(thr).klass = cThread;

	vector_push(thr_stk, (void*)thr);

	THREAD(thr)->alive_p = 1;
	if (cur_thr)
		THREAD(thr)->branch = THREAD(cur_thr)->branch;
	if ((thr != main_thread()) && (thr != cur_thr))
		THREAD(thr)->recv = cur_thr;
	THREAD(thr)->up = cur_thr;
	THREAD(thr)->env_tbl = st_init_numtable();
	THREAD(thr)->obj_stk = vector_new();
	THREAD(thr)->self_stk = vector_new();
	THREAD(thr)->env_stk = vector_new();
	THREAD(thr)->tok_stk = vector_new();
	THREAD(thr)->stack = vector_new();
#ifdef SYMBOL_CACHE
	THREAD(thr)->modified_syms = vector_new();
#endif

	return thr;
}
예제 #6
0
파일: gc.c 프로젝트: mtmiron/toi
int
object_refcount_down(void *ptr)
{
    VALUE obj = (VALUE)ptr;

    if (BASIC(obj).refcount == GC_NEVER_FREE)
        return VECTOR_CONTINUE;
    else if (THREAD(cur_thr)->last == obj)
        return VECTOR_CONTINUE;
    else if (--(BASIC(obj).refcount) > 0)
        return VECTOR_CONTINUE;

    memdealloc(obj);
    vector_delete(THREAD(cur_thr)->obj_stk, (void*)obj);
    return VECTOR_DELETE;
}
예제 #7
0
파일: float.c 프로젝트: mtmiron/toi
VALUE
float_new(float num)
{
	VALUE obj;

	obj = NEW_OBJ(Float);
	OBJ_SETUP(obj, T_FLOAT);
	BASIC(obj).klass = cFloat;
	FLOAT(obj)->num = num;

	return (VALUE)obj;
}
예제 #8
0
파일: gc.c 프로젝트: mtmiron/toi
VALUE
gc_never_free(VALUE obj)
{
    if (!obj)
        return Qnil;
    BASIC(obj).refcount = GC_NEVER_FREE;

    if (TYPE(obj) == T_ARRAY)
        vector_foreach(ARRAY(obj)->ptr, gc_never_free0);
    else if (TYPE(obj) == T_HASH)
        st_foreach(HASH(obj)->ptr, gc_never_free_hash0, 0);

    return obj;
}
예제 #9
0
파일: exception.c 프로젝트: mtmiron/toi
void
Init_exception()
{
	cException = define_class(intern("Exception"), cObject);

	Qretry = NEW_OBJ(struct goon);
	OBJ_SETUP(Qretry, T_RETRY);
	BASIC(Qretry).klass = cException;
	gc_never_free(Qretry);

	define_global_function(intern("fail"), throw_exc, -1);
	define_global_function(intern("throw"), throw_exc, -1);
	define_global_function(intern("retry"), exception_retry, 0);
}
예제 #10
0
파일: thread.c 프로젝트: mtmiron/toi
void
Init_thread()
{
	if (!thr_stk)
		thr_stk = vector_new();
	if (!cur_thr)
		cur_thr = thread_new();

	cThread = define_class(intern("Thread"), cObject);
	OBJ_SETUP(cur_thr, T_THREAD);
	BASIC(cur_thr).klass = cThread;
	define_method(cThread, intern("call"), eval_thread, 1);

	define_singleton_method(cThread, intern("main"), main_thread, 0);
	define_singleton_method(cThread, intern("current"), thread_s_current, 0);
	define_singleton_method(cThread, intern("critical"), thread_get_critical, 0);
	define_singleton_method(cThread, intern("setcritical"), thread_set_critical, 1);

}
예제 #11
0
#define A_OPCODE(OPCODE15)	((OPCODE15) >> 2), PDP10_INSN_A_OPCODE
#define A_UNUSED(OPCODE9)	((OPCODE9) << 4), PDP10_INSN_A_UNUSED
#define IO(OPCODE15)		((OPCODE15) >> 2), PDP10_INSN_IO

/* Much of the contents of these tables is based on code in
   Lars Brinkhoff's pdp10-its-disassembler, but the code has
   since been completely rewritten and extended.  */

static const struct pdp10_insn pdp10_insn[] = {
    /* name,		high13,	fmt,		models */

    /* 000: ILLEGAL */
    /* 001-037: LUUOs */

    /* ITS MUUOs */
    { ".iot",		BASIC(0040),		PDP10_ITS },
    { ".open",		BASIC(0041),		PDP10_ITS },
    { ".oper",		BASIC(0042),		PDP10_ITS },
    { ".call",		A_OPCODE(004300),	PDP10_ITS },
    { ".dismis",	A_OPCODE(004304),	PDP10_ITS },
    { ".lose",		A_OPCODE(004310),	PDP10_ITS }, /* XXX: .trans? */
    { ".tranad",	A_OPCODE(004314),	PDP10_ITS },
    { ".value",		A_OPCODE(004320),	PDP10_ITS },
    { ".utran",		A_OPCODE(004324),	PDP10_ITS },
    { ".core",		A_OPCODE(004330),	PDP10_ITS },
    { ".trand",		A_OPCODE(004334),	PDP10_ITS },
    { ".dstart",	A_OPCODE(004340),	PDP10_ITS },
    { ".fdele",		A_OPCODE(004344),	PDP10_ITS },
    { ".dstrtl",	A_OPCODE(004350),	PDP10_ITS },
    { ".suset",		A_OPCODE(004354),	PDP10_ITS },
    { ".ltpen",		A_OPCODE(004360),	PDP10_ITS },