Skip to content

Commit ec42b3e

Browse files
committed
Add "func.combXND()"
1 parent 3c66a0b commit ec42b3e

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

src/main/java/at/jddev0/lang/LangPredefinedFunctions.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7370,6 +7370,63 @@ public static DataObject combXNCFunction(
73707370
), SCOPE_ID);
73717371
}
73727372

7373+
@LangFunction("combXND")
7374+
@CombinatorFunction
7375+
@LangInfo("Combinator execution: a(b(e)(c))(b(e)(d))")
7376+
public static DataObject combXNDFunction(
7377+
LangInterpreter interpreter, int SCOPE_ID,
7378+
@LangParameter("$a") @AllowedTypes(DataObject.DataType.FUNCTION_POINTER) DataObject a,
7379+
@LangParameter("$b") @AllowedTypes(DataObject.DataType.FUNCTION_POINTER) DataObject b,
7380+
@LangParameter("$c") DataObject c,
7381+
@LangParameter("$d") DataObject d,
7382+
@LangParameter("$e") DataObject e
7383+
) {
7384+
FunctionPointerObject aFunc = a.getFunctionPointer();
7385+
FunctionPointerObject bFunc = b.getFunctionPointer();
7386+
7387+
DataObject retB = interpreter.callFunctionPointer(bFunc, b.getVariableName(), Arrays.asList(
7388+
e
7389+
), SCOPE_ID);
7390+
retB = LangUtils.nullToLangVoid(retB);
7391+
7392+
if(retB.getType() != DataType.FUNCTION_POINTER)
7393+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by b(e) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
7394+
7395+
FunctionPointerObject retBFunc = retB.getFunctionPointer();
7396+
7397+
DataObject retB2 = interpreter.callFunctionPointer(retBFunc, retB.getVariableName(), Arrays.asList(
7398+
c
7399+
), SCOPE_ID);
7400+
7401+
DataObject retA = interpreter.callFunctionPointer(aFunc, a.getVariableName(), Arrays.asList(
7402+
LangUtils.nullToLangVoid(retB2)
7403+
), SCOPE_ID);
7404+
retA = LangUtils.nullToLangVoid(retA);
7405+
7406+
if(retA.getType() != DataType.FUNCTION_POINTER)
7407+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by a(b(e)(c)) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
7408+
7409+
FunctionPointerObject retAFunc = retA.getFunctionPointer();
7410+
7411+
DataObject retB3 = interpreter.callFunctionPointer(bFunc, b.getVariableName(), Arrays.asList(
7412+
e
7413+
), SCOPE_ID);
7414+
retB3 = LangUtils.nullToLangVoid(retB3);
7415+
7416+
if(retB3.getType() != DataType.FUNCTION_POINTER)
7417+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by b(e) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
7418+
7419+
FunctionPointerObject retB3Func = retB3.getFunctionPointer();
7420+
7421+
DataObject retB4 = interpreter.callFunctionPointer(retB3Func, retB3.getVariableName(), Arrays.asList(
7422+
d
7423+
), SCOPE_ID);
7424+
7425+
return interpreter.callFunctionPointer(retAFunc, retA.getVariableName(), Arrays.asList(
7426+
LangUtils.nullToLangVoid(retB4)
7427+
), SCOPE_ID);
7428+
}
7429+
73737430
@LangFunction("combY")
73747431
@CombinatorFunction
73757432
@LangInfo("Combinator execution: (x -> f(x(x)))(x -> f(x(x)))")

0 commit comments

Comments
 (0)