Example #1
0
ValueBase* NIdentifier::codeGen(CodeGenContext& context)
{
	//std::cout << "Creating identifier reference: " << name << endl;
	ValueBase *value = context.getVar(name);
	if (value == NULL) {
		return NULL;
	}

	return createValue(value->getType(), new LoadInst(value->getValue(), "", false, context.currentBlock()));
}
Example #2
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);
}