Example #1
0
ValueBase* NMethodCall::callScriptFunc(CodeGenContext& context)
{
    ValueBase * functionInfo = context.getVar(id.name);
    if (functionInfo->getType() != ValueType::VT_FUNCTION){
        std::cerr<< id.name <<" is not a function" <<endl;
        return NULL;
    }

    std::vector<Value*> args;
    std::vector<Type*> argsTypes;
    ExpressionList::const_iterator it;
    for (it = arguments.begin(); it != arguments.end(); it++) {
        ValueBase* arg = (**it).codeGen(context);
        argsTypes.push_back(arg->getRealType());
        args.push_back(arg->getValue());
    }

    ValueBase *value = ((FunctionValue*)functionInfo)->getFunctionInfo()->codeGen(context, argsTypes);
    CallInst *call = CallInst::Create(value->getValue(), makeArrayRef(args), "", context.currentBlock());
    //std::cout << "Creating method call: " << id.name << endl;
    return new LongValue(call);
}