Skip to content

Commit 3c66a0b

Browse files
committed
Add "func.combXNC()"
1 parent d688301 commit 3c66a0b

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
@@ -7313,6 +7313,63 @@ public static DataObject combXNBFunction(
73137313
), SCOPE_ID);
73147314
}
73157315

7316+
@LangFunction("combXNC")
7317+
@CombinatorFunction
7318+
@LangInfo("Combinator execution: a(b(c)(e))(b(d)(e))")
7319+
public static DataObject combXNCFunction(
7320+
LangInterpreter interpreter, int SCOPE_ID,
7321+
@LangParameter("$a") @AllowedTypes(DataObject.DataType.FUNCTION_POINTER) DataObject a,
7322+
@LangParameter("$b") @AllowedTypes(DataObject.DataType.FUNCTION_POINTER) DataObject b,
7323+
@LangParameter("$c") DataObject c,
7324+
@LangParameter("$d") DataObject d,
7325+
@LangParameter("$e") DataObject e
7326+
) {
7327+
FunctionPointerObject aFunc = a.getFunctionPointer();
7328+
FunctionPointerObject bFunc = b.getFunctionPointer();
7329+
7330+
DataObject retB = interpreter.callFunctionPointer(bFunc, b.getVariableName(), Arrays.asList(
7331+
c
7332+
), SCOPE_ID);
7333+
retB = LangUtils.nullToLangVoid(retB);
7334+
7335+
if(retB.getType() != DataType.FUNCTION_POINTER)
7336+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by b(c) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
7337+
7338+
FunctionPointerObject retBFunc = retB.getFunctionPointer();
7339+
7340+
DataObject retB2 = interpreter.callFunctionPointer(retBFunc, retB.getVariableName(), Arrays.asList(
7341+
e
7342+
), SCOPE_ID);
7343+
7344+
DataObject retA = interpreter.callFunctionPointer(aFunc, a.getVariableName(), Arrays.asList(
7345+
LangUtils.nullToLangVoid(retB2)
7346+
), SCOPE_ID);
7347+
retA = LangUtils.nullToLangVoid(retA);
7348+
7349+
if(retA.getType() != DataType.FUNCTION_POINTER)
7350+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by a(b(c)(e)) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
7351+
7352+
FunctionPointerObject retAFunc = retA.getFunctionPointer();
7353+
7354+
DataObject retB3 = interpreter.callFunctionPointer(bFunc, b.getVariableName(), Arrays.asList(
7355+
d
7356+
), SCOPE_ID);
7357+
retB3 = LangUtils.nullToLangVoid(retB3);
7358+
7359+
if(retB3.getType() != DataType.FUNCTION_POINTER)
7360+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by b(d) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
7361+
7362+
FunctionPointerObject retB3Func = retB3.getFunctionPointer();
7363+
7364+
DataObject retB4 = interpreter.callFunctionPointer(retB3Func, retB3.getVariableName(), Arrays.asList(
7365+
e
7366+
), SCOPE_ID);
7367+
7368+
return interpreter.callFunctionPointer(retAFunc, retA.getVariableName(), Arrays.asList(
7369+
LangUtils.nullToLangVoid(retB4)
7370+
), SCOPE_ID);
7371+
}
7372+
73167373
@LangFunction("combY")
73177374
@CombinatorFunction
73187375
@LangInfo("Combinator execution: (x -> f(x(x)))(x -> f(x(x)))")

0 commit comments

Comments
 (0)