Beispiel #1
0
void TypeCheckerVisitor::visitCallNode(CallNode* node) {
	uint32_t params_count = node->parametersNumber();
	AstFunction* refFunc = _current_scope->lookupFunction(node->name(), true);
	bool matchesRefedFunction = (refFunc!= NULL) && (refFunc->parametersNumber() == params_count);
	for (uint32_t i = 0; i < params_count; i++) {
		AstNode* param = node->parameterAt(i);
		param->visit(this);
		if (matchesRefedFunction && !isAssignable(refFunc->parameterType(i), getNodeType(param))) {
			setErrorMessage(param, "Wrong type parameter");
		}
	}
	if (matchesRefedFunction) {
		setNodeType(node, refFunc->returnType());
	} else {
		setNodeType(node, VT_INVALID);
	}
}
Beispiel #2
0
void BytecodeTranslatorVisitor::visitCallNode(CallNode* node) {
    onVisitNode(node);

    AstFunction* f = scope()->lookupFunction(node->name());
    if (!f) ERROR("Unknown function " + f->name());
    checkSignature(node, f);

    for (uint16_t i = 0; i < node->parametersNumber(); i++)
        visitTyped(node->parameterAt(i), f->parameterType(i));

    if (isNative(f))
        EMIT(BC_CALLNATIVE);
    else
        EMIT(BC_CALL);

    EMIT_ID(getFunctionId(f));

    pushType(f->returnType());
}
Beispiel #3
0
void TypeChecker::visitCallNode(CallNode* node) {
    size_t nodePos = node->position();
    string const callName = node->name();
    Scope* curScope = currentScope();
    AstFunction* funToCall = curScope->lookupFunction(callName);
    if(funToCall == 0) {
        throw ExceptionWithPos(undeclaredFunMsg(callName), nodePos);
    }
    for(size_t i = 0; i != node->parametersNumber(); ++i) {
        node->parameterAt(i)->visit(this);
        VarType actualArgType = nodeType(node->parameterAt(i));
        VarType expectedArgType = funToCall->parameterType(i);
        if(actualArgType != expectedArgType &&
           !isIntDoublePair(actualArgType, expectedArgType))
        {
            throw ExceptionWithPos(wrongArgTypeMsg(callName, i), nodePos);
        }
    }
    node->setInfo(new VarType(funToCall->returnType()));
}
Beispiel #4
0
void Generator::visitCallNode(CallNode *node)
{
	AstFunction *function = lookup_function(node->name());
	uint16_t id = lookup_function(function)->id();
	for (uint32_t i = 0; i != node->parametersNumber(); ++i)
	{
	    uint32_t pos = node->parametersNumber() - i - 1;
	    switch (function->parameterType(pos))
	    {
	    case VT_INT:
	        eval_int(node->parameterAt(pos));
	        break;
        case VT_DOUBLE:
	        eval_double(node->parameterAt(pos));
	        break;
        case VT_STRING:
	        eval_string(node->parameterAt(pos));
	        break;
        default: assert(0);
	    }
	}
	bytecode()->addInsn(BC_CALL);
	bytecode()->addInt16(id);
	switch (function->returnType())
	{
	case VT_INT:
	    bytecode()->addInsn(BC_LOADIVAR0);
	    break;
	case VT_DOUBLE:
	    bytecode()->addInsn(BC_LOADDVAR0);
	    break;
	case VT_STRING:
	    bytecode()->addInsn(BC_LOADSVAR0);
	    break;
    default: break;
	}
}