Beispiel #1
0
void initializeLambda(LambdaPtr x, EnvPtr env)
{
    assert(!x->initialized);
    x->initialized = true;

    string lname = lambdaName(x);

    ostringstream ostr;
    ostr << "%closureData:" << lname;
    string closureDataName = ostr.str();

    convertFreeVars(x, env, closureDataName, x->freeVars);
    getProcedureMonoTypes(x->mono, env, x->formalArgs, x->formalVarArg);
    if (x->freeVars.empty()) {
        initializeLambdaWithoutFreeVars(x, env, closureDataName, lname);
    }
    else {
        initializeLambdaWithFreeVars(x, env, closureDataName, lname);
    }
}
Beispiel #2
0
void addProcedureOverload(ProcedurePtr proc, EnvPtr env, OverloadPtr x) {
    if (!!proc->singleOverload && proc->singleOverload != x) {
        // TODO: points to wrong line
        error(x->location, "standalone functions cannot be overloaded");
    }

    if (proc->privateOverload) {
        if (proc->module != x->module) {
            error("symbol " + toString(proc->name->str) + " is declared as private for overload");
        }
    }

    if (proc->interface != NULL) {
        if (maxParamCount(proc->interface->code) < minParamCount(x->code)) {
            error(x->location,
                    "overload has more parameters (" + paramCountString(x->code) +  ")"
                    " than declaration (" + paramCountString(proc->interface->code) + ")");
        }

        if (maxParamCount(x->code) < minParamCount(proc->interface->code)) {
            error(x->location,
                    "overload has fewer parameters (" + paramCountString(x->code) +  ")"
                    " than declaration (" + paramCountString(proc->interface->code) + ")");
        }

        if (proc->interface->code->returnSpecsDeclared && x->code->returnSpecsDeclared) {
            if (x->code->returnSpecs.size() != proc->interface->code->returnSpecs.size()) {
                error(x->location, string() +
                        "overload return count (" + toString(x->code->returnSpecs.size())  + ")"
                        " must be equal to define return count (" + toString(proc->interface->code->returnSpecs.size()) + ")");
            }
        }
    }

    proc->overloads.insert(proc->overloads.begin(), x);
    getProcedureMonoTypes(proc->mono, env,
        x->code->formalArgs,
        x->code->hasVarArg);
}
Beispiel #3
0
void addProcedureOverload(ProcedurePtr proc, OverloadPtr x) {
    proc->overloads.insert(proc->overloads.begin(), x);
    getProcedureMonoTypes(proc->mono, overloadPatternEnv(x),
        x->code->formalArgs,
        x->code->formalVarArg);
}