Skip to content

Commit d688301

Browse files
committed
Add "func.combXNB()"
1 parent 4272d69 commit d688301

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

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

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7237,6 +7237,82 @@ public static DataObject combXNAFunction(
72377237
), SCOPE_ID);
72387238
}
72397239

7240+
@LangFunction("combXNB")
7241+
@CombinatorFunction
7242+
@LangInfo("Combinator execution: a(b(d)(c)(d))(b(c)(d)(c))")
7243+
public static DataObject combXNBFunction(
7244+
LangInterpreter interpreter, int SCOPE_ID,
7245+
@LangParameter("$a") @AllowedTypes(DataObject.DataType.FUNCTION_POINTER) DataObject a,
7246+
@LangParameter("$b") @AllowedTypes(DataObject.DataType.FUNCTION_POINTER) DataObject b,
7247+
@LangParameter("$c") DataObject c,
7248+
@LangParameter("$d") DataObject d
7249+
) {
7250+
FunctionPointerObject aFunc = a.getFunctionPointer();
7251+
FunctionPointerObject bFunc = b.getFunctionPointer();
7252+
7253+
DataObject retB = interpreter.callFunctionPointer(bFunc, b.getVariableName(), Arrays.asList(
7254+
d
7255+
), SCOPE_ID);
7256+
retB = LangUtils.nullToLangVoid(retB);
7257+
7258+
if(retB.getType() != DataType.FUNCTION_POINTER)
7259+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by b(d) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
7260+
7261+
FunctionPointerObject retBFunc = retB.getFunctionPointer();
7262+
7263+
DataObject retB2 = interpreter.callFunctionPointer(retBFunc, retB.getVariableName(), Arrays.asList(
7264+
c
7265+
), SCOPE_ID);
7266+
retB2 = LangUtils.nullToLangVoid(retB2);
7267+
7268+
if(retB2.getType() != DataType.FUNCTION_POINTER)
7269+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by b(d)(c) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
7270+
7271+
FunctionPointerObject retB2Func = retB2.getFunctionPointer();
7272+
7273+
DataObject retB3 = interpreter.callFunctionPointer(retB2Func, retB2.getVariableName(), Arrays.asList(
7274+
d
7275+
), SCOPE_ID);
7276+
7277+
DataObject retA = interpreter.callFunctionPointer(aFunc, a.getVariableName(), Arrays.asList(
7278+
LangUtils.nullToLangVoid(retB3)
7279+
), SCOPE_ID);
7280+
retA = LangUtils.nullToLangVoid(retA);
7281+
7282+
if(retA.getType() != DataType.FUNCTION_POINTER)
7283+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by a(b(d)(c)(d)) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
7284+
7285+
FunctionPointerObject retAFunc = retA.getFunctionPointer();
7286+
7287+
DataObject retB4 = interpreter.callFunctionPointer(bFunc, b.getVariableName(), Arrays.asList(
7288+
c
7289+
), SCOPE_ID);
7290+
retB4 = LangUtils.nullToLangVoid(retB4);
7291+
7292+
if(retB4.getType() != DataType.FUNCTION_POINTER)
7293+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by b(c) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
7294+
7295+
FunctionPointerObject retB4Func = retB4.getFunctionPointer();
7296+
7297+
DataObject retB5 = interpreter.callFunctionPointer(retB4Func, retB4.getVariableName(), Arrays.asList(
7298+
d
7299+
), SCOPE_ID);
7300+
retB5 = LangUtils.nullToLangVoid(retB5);
7301+
7302+
if(retB5.getType() != DataType.FUNCTION_POINTER)
7303+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by b(c)(d) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
7304+
7305+
FunctionPointerObject retB5Func = retB5.getFunctionPointer();
7306+
7307+
DataObject retB6 = interpreter.callFunctionPointer(retB5Func, retB5.getVariableName(), Arrays.asList(
7308+
c
7309+
), SCOPE_ID);
7310+
7311+
return interpreter.callFunctionPointer(retAFunc, retA.getVariableName(), Arrays.asList(
7312+
LangUtils.nullToLangVoid(retB6)
7313+
), SCOPE_ID);
7314+
}
7315+
72407316
@LangFunction("combY")
72417317
@CombinatorFunction
72427318
@LangInfo("Combinator execution: (x -> f(x(x)))(x -> f(x(x)))")

0 commit comments

Comments
 (0)