示例#1
0
// Documented in spec.
zvalue formalsMinArgs(zvalue formals) {
    zint minArgs = 0;
    zint sz = get_size(formals);

    for (zint i = 0; i < sz; i++) {
        zvalue one = cm_nth(formals, i);
        zvalue repeat = cm_get(one, SYM(repeat));
        if (!(cmpEqNullOk(repeat, SYM(CH_QMARK))
              || cmpEqNullOk(repeat, SYM(CH_STAR)))) {
            minArgs++;
        }
    }

    return intFromZint(minArgs);
}
示例#2
0
// Documented in spec.
zvalue formalsMaxArgs(zvalue formals) {
    zint maxArgs = 0;
    zint sz = get_size(formals);

    for (zint i = 0; i < sz; i++) {
        zvalue one = cm_nth(formals, i);
        zvalue repeat = cm_get(one, SYM(repeat));
        if (cmpEqNullOk(repeat, SYM(CH_STAR))
            || cmpEqNullOk(repeat, SYM(CH_PLUS))) {
            maxArgs = -1;
            break;
        }
        maxArgs++;
    }

    return intFromZint(maxArgs);
}
示例#3
0
文件: If.c 项目: tstellanova/samizdat
// Documented in spec.
CMETH_IMPL_2_opt(If, cases, testFunction, valueFunctions, defaultFunction) {
    zvalue value = FUN_CALL(testFunction);

    if (value == NULL) {
        die("Void result from `cases` call to `testFunction`.");
    }

    zvalue consequentFunction = cm_get(valueFunctions, value);

    if (consequentFunction != NULL) {
        return FUN_CALL(consequentFunction, value);
    }

    return (defaultFunction == NULL)
        ? NULL
        : FUN_CALL(defaultFunction, value);
}
示例#4
0
// Documented in spec.
zvalue extractLiteral(zvalue node) {
    return nodeRecTypeIs(node, NODE_literal)
        ? cm_get(node, SYM(value))
        : NULL;
}