MCPcopy Index your code
hub / github.com/processing/p5.js / functionCallNode

Function functionCallNode

src/strands/ir_builders.js:385–490  ·  view source on GitHub ↗
(
  strandsContext,
  functionName,
  rawUserArgs,
  { overloads: rawOverloads } = {},
)

Source from the content-addressed store, hash-verified

383}
384
385export function functionCallNode(
386 strandsContext,
387 functionName,
388 rawUserArgs,
389 { overloads: rawOverloads } = {},
390) {
391 const { cfg, dag } = strandsContext;
392 const overloads = rawOverloads || strandsBuiltinFunctions[functionName];
393
394 const preprocessedArgs = rawUserArgs.map((rawUserArg) => mapPrimitiveDepsToIDs(strandsContext, DataType.defer, rawUserArg));
395 const matchingArgsCounts = overloads.filter(overload => overload.params.length === preprocessedArgs.length);
396 if (matchingArgsCounts.length === 0) {
397 const argsLengthSet = new Set();
398 const argsLengthArr = [];
399 overloads.forEach((overload) => argsLengthSet.add(overload.params.length));
400 argsLengthSet.forEach((len) => argsLengthArr.push(`${len}`));
401 const argsLengthStr = argsLengthArr.join(', or ');
402 FES.userError("parameter validation error",`Function '${functionName}' has ${overloads.length} variants which expect ${argsLengthStr} arguments, but ${preprocessedArgs.length} arguments were provided.`);
403 }
404
405 const isGeneric = (T) => T.dimension === null;
406 let bestOverload = null;
407 let bestScore = 0;
408 let inferredReturnType = null;
409 let inferredDimension = null;
410
411 for (const overload of matchingArgsCounts) {
412 let isValid = true;
413 let similarity = 0;
414
415 for (let i = 0; i < preprocessedArgs.length; i++) {
416 const preArg = preprocessedArgs[i];
417 const argType = preArg.inferredTypeInfo;
418 const expectedType = overload.params[i];
419 let dimension = expectedType.dimension;
420
421 if (isGeneric(expectedType)) {
422 if (inferredDimension === null || inferredDimension === 1) {
423 inferredDimension = argType.dimension;
424 }
425
426 if (inferredDimension !== argType.dimension &&
427 !(argType.dimension === 1 && inferredDimension >= 1)
428 ) {
429 isValid = false;
430 }
431 dimension = inferredDimension;
432 }
433 else {
434 if (argType.dimension > dimension) {
435 isValid = false;
436 }
437 }
438
439 if (argType.baseType === expectedType.baseType) {
440 similarity += 2;
441 }
442 else if(expectedType.priority > argType.priority) {

Callers 1

castToFloatFunction · 0.85

Calls 7

typeEqualsFunction · 0.90
mapPrimitiveDepsToIDsFunction · 0.85
isGenericFunction · 0.85
constructTypeFromIDsFunction · 0.85
filterMethod · 0.45
addMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected