Exemple #1
0
        private static void freeObject(ref Obj object_)
        {
#if DEBUG_LOG_GC
            System.Console.WriteLine("{0} free type {1}", object_._mem_id.ToString(), object_.type.ToString());
#endif
            switch (object_.type)
            {
            case ObjType.OBJ_BOUND_METHOD:
                object_._free();
                object_ = null;
                break;

            case ObjType.OBJ_CLASS:
            {
                ObjClass klass = (ObjClass)object_;
                Table.freeTable(ref klass.methods);
                //FREE<ObjClass>(ref object_);
                object_._free();
                object_ = null;
                break;
            }

            case ObjType.OBJ_CLOSURE:
            {
                ObjClosure closure = (ObjClosure)object_;
                FREE_ARRAY <ObjUpvalue>(typeof(ObjUpvalue), ref closure.upvalues, closure.upvalueCount);
                object_._free();
                object_ = null;
                break;
            }

            case ObjType.OBJ_FUNCTION:
            {
                ObjFunction function = (ObjFunction)object_;
                Chunk.freeChunk(ref function.chunk);         // the function's byte code
                object_._free();
                object_ = null;
                break;
            }

            case ObjType.OBJ_INSTANCE:
            {
                ObjInstance instance = (ObjInstance)object_;
                Table.freeTable(ref instance.fields);
                object_._free();
                object_ = null;
                break;
            }

            case ObjType.OBJ_NATIVE:
            {
                object_._free();
                object_ = null;
                break;
            }

            case ObjType.OBJ_STRING:
            {
                ObjString string_ = (ObjString)object_;
                FREE_ARRAY <char>(typeof(char), ref string_.chars, string_.length + 1);
                object_._free();
                object_ = null;
                break;
            }

            case ObjType.OBJ_UPVALUE:
                cHeap.values.remove(((ObjUpvalue)object_).location);
                object_._free();
                object_ = null;
                break;
            }
        }
Exemple #2
0
        private static void blackenObject(Obj object_)
        {
#if DEBUG_LOG_GC
            System.Console.Write("{0} blacken ", object_._mem_id.ToString());
            Value.printValue(Value.OBJ_VAL(object_));
            System.Console.WriteLine();
#endif

            switch (object_.type)
            {
            case ObjType.OBJ_BOUND_METHOD:
            {
                ObjBoundMethod bound = (ObjBoundMethod)object_;
                markValue(ref bound.receiver);
                markObject((Obj)bound.method);
                break;
            }

            case ObjType.OBJ_CLASS:
            {
                ObjClass klass = (ObjClass)object_;
                markObject((Obj)klass.name);
                Table.markTable(ref klass.methods);
                break;
            }

            case ObjType.OBJ_CLOSURE:
            {
                ObjClosure closure = (ObjClosure)object_;
                markObject((Obj)closure.function);
                for (int i = 0; i < closure.upvalueCount; i++)
                {
                    markObject((Obj)closure.upvalues[i]);
                }
                break;
            }

            case ObjType.OBJ_FUNCTION:
            {
                ObjFunction function = (ObjFunction)object_;
                markObject((Obj)function.name);
                markArray(ref function.chunk.constants);
                break;
            }

            case ObjType.OBJ_INSTANCE:
            {
                ObjInstance instance = (ObjInstance)object_;
                markObject((Obj)(instance.klass));
                Table.markTable(ref instance.fields);
                break;
            }

            case ObjType.OBJ_UPVALUE:
                markValue(ref ((ObjUpvalue)object_).closed);
                break;

            case ObjType.OBJ_NATIVE:
            case ObjType.OBJ_STRING:
                break;
            }
        }