Exemple #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;
}
Exemple #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;
}
Exemple #3
0
VALUE LinkNamespace(const char* identifier)
{
    VALUE ref_namespace;
    ref_namespace.type = VAL_REFERENCE;
    ref_namespace.data.reference = (CLOSURE*)ALLOC(sizeof(CLOSURE));
    ref_namespace.data.reference->parent = NULL;
    ref_namespace.data.reference->list = NULL;
    ref_namespace.data.reference->ref_count = -1;
    StoreRecord(identifier, ref_namespace, gGlobalContext);

    GCAddContext(ref_namespace.data.reference, &gGCManager);

    return ref_namespace;
}
Exemple #4
0
/*
int Interpret(SYNTAX_TREE* tree)
    ---------------------------------------------------------
    Run a duck program from the command console by parsing it
    into a syntax tree and then interating over the program
    definitions.
*/
int Interpret(SYNTAX_TREE* tree)
{
    CreateEnvironment();

    gc_inst_count = 0;
    gc_collect_count = 0;

    test_inst_count = 0;

    /* global NameSpace */
    gCurrentContext = gGlobalContext = (CLOSURE*)ALLOC(sizeof(CLOSURE));
    gCurrentContext->parent = NULL;
    gCurrentContext->list = NULL;
    gCurrentContext->ref_count = -1;
    GCAddContext(gGlobalContext, &gGCManager);

    /* current expression */
    gLastExpression.type = VAL_NIL;
    gLastExpression.data.primitive = 0;

    /* global variables */
    gParameterListing = NULL;
    gDictionaryInit = NULL;
    gArrayIndex = 0;
    gArgumentEvaluation = NULL;

    /* l-value bound context */
    gLValueIdentifier = NULL;
    gLValueContext = NULL;
    gLValueIndex.type = VAL_NIL;
    gLValueIndex.data.primitive = 0;
    gLValueDictionary = NULL;
    array_indexing = 0;

    /* libraries */
    BindStandardLibrary();
    BindMathLibrary();
    BindAdditionalLibraries();
    BindRandLibrary();

    /* function definition */
    gParameterListing = NULL;

    /* program control */
    returning = 0;
    breaking = 0;
    continuing = 0;
    halting = 0;

    /* profiling */
    greatest_stack_depth;
    stack_depth;

    /* clear call stack */
    ClearCallStack(&gStackTrace);
    line_error = 0;
    failed_production = NULL;
    
    /* run */
    int error = InterpretNode(tree);
    while (PopExecutionStack());
    //ForceFreeContext(gGlobalContext);
    return error;
}