예제 #1
0
int CallGCRecurseContext(CONTEXT* context, 
                         GC_DATA_MANAGEMENT* managed)
{
    PAIR* itr;
    int result = 0;

    while (context) {
        itr = context->list;
        if (GCAddContext(context, managed))
        {
            result = 1;
            while (itr) {
                if (itr->value.type == VAL_REFERENCE) {
                    CallGCRecurseContext(itr->value.data.reference, 
                                         managed);
                } else if (itr->value.type == VAL_FUNCTION) {
                    CallGCRecurseFunction(itr->value.data.function,
                                          managed);
                } else if (itr->value.type == VAL_DICTIONARY) {
                    CallGCRecurseDictionary(itr->value.data.dictionary,
                                            managed);
                } else if (itr->value.type == VAL_STRING &&
                           itr->value.const_string == 0) {
                    GCAddString((char*)itr->value.data.string, managed);
                }
                itr = itr->next;
            }
        }

        context = context->parent;
    }

    return result;
}
예제 #2
0
int GCAddValue(VALUE value,
                GC_DATA_MANAGEMENT* gc) 
{
    if (value.type == VAL_STRING &&
        value.const_string == 0 &&
        value.data.string)
    {
        return GCAddString((char*)value.data.string, gc);
    }
    else if (value.type == VAL_REFERENCE &&
             value.data.reference)
    {
        return GCAddContext(value.data.reference, gc);
    }
    else if (value.type == VAL_FUNCTION &&
             value.data.function)
    {
        return GCAddFunction(value.data.function, gc);
    }
    else if (value.type == VAL_DICTIONARY &&
             value.data.dictionary)
    {
        return GCAddDictionary(value.data.dictionary, gc);
    }
    return 0;
}
예제 #3
0
int StringSplit(int argument_count, void* data)
{
    int error = 0;

    VALUE argument = GetRecord("string", gCurrentContext);

    if (argument.type == VAL_STRING) 
    {
        const char* data = argument.data.string;
        unsigned int length = strlen(data);
        unsigned int index;

        HASH_TABLE* dictionary = CreateHashTable();
        GCAddDictionary(dictionary, &gGCManager);

        for (index = 0; index < length; index++)
        {
            VALUE key;
            VALUE expr;

            key.type = VAL_PRIMITIVE;
            key.data.primitive = index;
            
            expr.type = VAL_STRING;
            expr.const_string = 0;
            char* char_string = (char*)ALLOC(sizeof(char) * 2);
            GCAddString(char_string, &gGCManager);
            char_string[0] = data[index];
            char_string[1] = '\0';
            expr.data.string = char_string;

            HashStore(key, expr, dictionary);
        }

        gLastExpression.type = VAL_DICTIONARY;
        gLastExpression.data.dictionary = dictionary;
    } else {
        gLastExpression.type = VAL_NIL;
        gLastExpression.data.primitive = 0;
    }

    return error;
}
예제 #4
0
int CallGCRecurseDictionary(HASH_TABLE* table, 
                            GC_DATA_MANAGEMENT* managed)
{
    int result = 0;
    if (table && GCAddDictionary(table, managed))
    {
        unsigned int index;
        result = 1;

        for (index = 0;
             index < table->capacity;
             index++)
        {
            if (table->table[index].key.type != VAL_NIL)
            {
                VALUE value = table->table[index].value;
                
                if (value.type == VAL_REFERENCE) {
                    CallGCRecurseContext(value.data.reference, 
                                         managed);
                } else if (value.type == VAL_FUNCTION) {
                    CallGCRecurseFunction(value.data.function,
                                          managed);
                } else if (value.type == VAL_DICTIONARY) {
                    CallGCRecurseDictionary(value.data.dictionary,
                                            managed);
                } else if (value.type == VAL_STRING &&
                           value.const_string == 0) {
                    GCAddString((char*)value.data.string, managed);
                }
            }
        }
    }

    return result;
}