Skip to content

Commit ecd081e

Browse files
committed
Add "func.combXN4()"
1 parent d335499 commit ecd081e

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6867,6 +6867,48 @@ public static DataObject combXN3Function(
68676867
), SCOPE_ID);
68686868
}
68696869

6870+
@LangFunction("combXN4")
6871+
@CombinatorFunction
6872+
@LangInfo("Combinator execution: a(b(d)(c))(d)")
6873+
public static DataObject combXN4Function(
6874+
LangInterpreter interpreter, int SCOPE_ID,
6875+
@LangParameter("$a") @AllowedTypes(DataObject.DataType.FUNCTION_POINTER) DataObject a,
6876+
@LangParameter("$b") @AllowedTypes(DataObject.DataType.FUNCTION_POINTER) DataObject b,
6877+
@LangParameter("$c") DataObject c,
6878+
@LangParameter("$d") DataObject d
6879+
) {
6880+
FunctionPointerObject aFunc = a.getFunctionPointer();
6881+
FunctionPointerObject bFunc = b.getFunctionPointer();
6882+
6883+
DataObject retB = interpreter.callFunctionPointer(bFunc, b.getVariableName(), Arrays.asList(
6884+
d
6885+
), SCOPE_ID);
6886+
retB = LangUtils.nullToLangVoid(retB);
6887+
6888+
if(retB.getType() != DataType.FUNCTION_POINTER)
6889+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by b(d) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
6890+
6891+
FunctionPointerObject retBFunc = retB.getFunctionPointer();
6892+
6893+
DataObject retB2 = interpreter.callFunctionPointer(retBFunc, retB.getVariableName(), Arrays.asList(
6894+
c
6895+
), SCOPE_ID);
6896+
6897+
DataObject retA = interpreter.callFunctionPointer(aFunc, a.getVariableName(), Arrays.asList(
6898+
LangUtils.nullToLangVoid(retB2)
6899+
), SCOPE_ID);
6900+
retA = LangUtils.nullToLangVoid(retA);
6901+
6902+
if(retA.getType() != DataType.FUNCTION_POINTER)
6903+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by a(b(d)(c)) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
6904+
6905+
FunctionPointerObject retAFunc = retA.getFunctionPointer();
6906+
6907+
return interpreter.callFunctionPointer(retAFunc, retA.getVariableName(), Arrays.asList(
6908+
d
6909+
), SCOPE_ID);
6910+
}
6911+
68706912
@LangFunction("combY")
68716913
@CombinatorFunction
68726914
@LangInfo("Combinator execution: (x -> f(x(x)))(x -> f(x(x)))")

0 commit comments

Comments
 (0)