Ejemplo n.º 1
0
/**
 * FnApp = { Atom | ( "`" Atom "`" ) }
 *
 * A series of at least one expr-atom. If multiple, then the last is a
 * function to which the others are applied. Instead, one of them may
 * be explicitly marked in backticks as the function.
 */
static ast* parseFnApp (parserCtx* ctx) {
    /*Filled iff there is a backtick function*/
    ast* fn = 0;

    vector(ast*) nodes = vectorInit(3, malloc);

    /*Require at least one expr*/
    if (!see(ctx, "!"))
        vectorPush(&nodes, parseAtom(ctx));

    while (waiting_for_delim(ctx)) {
        if (try_match(ctx, "!")) {
            if (fn) {
                error(ctx)("Multiple explicit functions: '%s'\n", ctx->current.buffer);
                vectorPush(&nodes, fn);
            }

            fn = parseAtom(ctx);

        } else
            vectorPush(&nodes, parseAtom(ctx));
    }

    if (fn)
        return astCreateFnApp(nodes, fn);

    else if (nodes.length == 0) {
        /*Shouldn't happen due to the way it parses*/
        errprintf("FnApp took no AST nodes");
        return astCreateInvalid();

    } else if (nodes.length == 1) {
        /*No application*/
        ast* node = vectorPop(&nodes);
        vectorFree(&nodes);
        return node;

    } else {
    	/*The last node is the fn*/
        fn = vectorPop(&nodes);
        return astCreateFnApp(nodes, fn);
    }
}
Ejemplo n.º 2
0
Archivo: ast.c Proyecto: Fedjmike/tush
void astDestroy (ast* node) {
    if (node->l)
        astDestroy(node->l);

    if (node->r)
        astDestroy(node->r);

    vectorFreeObjs(&node->children, (vectorDtor) astDestroy);

    if (   node->kind == astStrLit || node->kind == astFileLit
        || node->kind == astGlobLit)
        free(node->literal.str);

    if (node->kind == astFnLit && node->captured) {
        vectorFree(node->captured);
        /*Stored indirectly*/
        free(node->captured);
    }

    free(node);
}
Ejemplo n.º 3
0
void vectorFreeObjs (vector* v, vectorDtor dtor) {
    /*This will mess up the vector, watevs*/
    vectorMap(v, (vectorMapper) dtor, v);
    vectorFree(v);
}
Ejemplo n.º 4
0
void vectorClear(Vector *pVector){
	vectorFree(pVector);
	vectorInit(pVector);
}