MCPcopy Create free account
hub / github.com/devosoft/avida / VisitFunctionCall

Method VisitFunctionCall

avida-core/source/script/cDirectInterpretASTVisitor.cc:1151–1326  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1149
1150
1151void cDirectInterpretASTVisitor::VisitFunctionCall(cASTFunctionCall& node)
1152{
1153 if (node.IsASFunction()) {
1154 // Call internal function
1155 const cASFunction* func = node.GetASFunction();
1156
1157 // Setup arguments
1158 cASCPPParameter* args = new cASCPPParameter[func->GetArity()];
1159 if (func->GetArity()) {
1160 tListIterator<cASTNode> cit = node.GetArguments()->Iterator();
1161 cASTNode* an = NULL;
1162 for (int i = 0; i < func->GetArity(); i++) {
1163 an = cit.Next();
1164 an->Accept(*this);
1165
1166 switch (func->GetArgumentType(i).type) {
1167 case TYPE(BOOL): args[i].Set(asBool(m_rtype, m_rvalue, node)); break;
1168 case TYPE(CHAR): args[i].Set(asChar(m_rtype, m_rvalue, node)); break;
1169 case TYPE(FLOAT): args[i].Set(asFloat(m_rtype, m_rvalue, node)); break;
1170 case TYPE(INT): args[i].Set(asInt(m_rtype, m_rvalue, node)); break;
1171 case TYPE(STRING): args[i].Set(asString(m_rtype, m_rvalue, node)); break;
1172 case TYPE(OBJECT_REF): args[i].Set(asNativeObject(func->GetArgumentType(i).info, m_rtype, m_rvalue, node)); break;
1173
1174 default:
1175 INTERPRET_ERROR(INTERNAL);
1176 }
1177 }
1178 }
1179
1180 // Call the function
1181 cASCPPParameter rvalue = func->Call(args);
1182
1183 // Handle the return value
1184 switch (node.GetType().type) {
1185 case TYPE(BOOL): m_rvalue.as_bool = rvalue.Get<bool>(); break;
1186 case TYPE(CHAR): m_rvalue.as_char = rvalue.Get<char>(); break;
1187 case TYPE(FLOAT): m_rvalue.as_float = rvalue.Get<double>(); break;
1188 case TYPE(INT): m_rvalue.as_int = rvalue.Get<int>(); break;
1189 case TYPE(STRING): m_rvalue.as_string = rvalue.Get<cString*>(); break;
1190 case TYPE(OBJECT_REF): m_rvalue.as_nobj = rvalue.Get<cASNativeObject*>(); break;
1191 case TYPE(VOID): break;
1192
1193 default:
1194 INTERPRET_ERROR(INTERNAL);
1195 }
1196 m_rtype = node.GetType();
1197
1198 // Clean up arguments
1199 for (int i = 0; i < func->GetArity(); i++) {
1200 switch (func->GetArgumentType(i).type) {
1201 case TYPE(BOOL): break;
1202 case TYPE(CHAR): break;
1203 case TYPE(FLOAT): break;
1204 case TYPE(INT): break;
1205 case TYPE(STRING): delete args[i].Get<cString*>(); break;
1206 case TYPE(OBJECT_REF):
1207 args[i].Get<cASNativeObject*>()->RemoveReference(); break;
1208

Callers

nothing calls this directly

Calls 15

IsASFunctionMethod · 0.80
GetASFunctionMethod · 0.80
AcceptMethod · 0.80
Get<bool>Method · 0.80
Get<char>Method · 0.80
Get<double>Method · 0.80
Get<int>Method · 0.80
Get<cString*>Method · 0.80
Get<cASNativeObject*>Method · 0.80
IsFuncGlobalMethod · 0.80
GetFuncIDMethod · 0.80

Tested by

no test coverage detected