Skip to content

Commit 4272d69

Browse files
committed
Add "func.combXNA()"
1 parent 128116d commit 4272d69

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
@@ -7161,6 +7161,82 @@ public static DataObject combXN9Function(
71617161
), SCOPE_ID);
71627162
}
71637163

7164+
@LangFunction("combXNA")
7165+
@CombinatorFunction
7166+
@LangInfo("Combinator execution: a(b(c)(d)(c))(b(d)(c)(d))")
7167+
public static DataObject combXNAFunction(
7168+
LangInterpreter interpreter, int SCOPE_ID,
7169+
@LangParameter("$a") @AllowedTypes(DataObject.DataType.FUNCTION_POINTER) DataObject a,
7170+
@LangParameter("$b") @AllowedTypes(DataObject.DataType.FUNCTION_POINTER) DataObject b,
7171+
@LangParameter("$c") DataObject c,
7172+
@LangParameter("$d") DataObject d
7173+
) {
7174+
FunctionPointerObject aFunc = a.getFunctionPointer();
7175+
FunctionPointerObject bFunc = b.getFunctionPointer();
7176+
7177+
DataObject retB = interpreter.callFunctionPointer(bFunc, b.getVariableName(), Arrays.asList(
7178+
c
7179+
), SCOPE_ID);
7180+
retB = LangUtils.nullToLangVoid(retB);
7181+
7182+
if(retB.getType() != DataType.FUNCTION_POINTER)
7183+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by b(c) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
7184+
7185+
FunctionPointerObject retBFunc = retB.getFunctionPointer();
7186+
7187+
DataObject retB2 = interpreter.callFunctionPointer(retBFunc, retB.getVariableName(), Arrays.asList(
7188+
d
7189+
), SCOPE_ID);
7190+
retB2 = LangUtils.nullToLangVoid(retB2);
7191+
7192+
if(retB2.getType() != DataType.FUNCTION_POINTER)
7193+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by b(c)(d) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
7194+
7195+
FunctionPointerObject retB2Func = retB2.getFunctionPointer();
7196+
7197+
DataObject retB3 = interpreter.callFunctionPointer(retB2Func, retB2.getVariableName(), Arrays.asList(
7198+
c
7199+
), SCOPE_ID);
7200+
7201+
DataObject retA = interpreter.callFunctionPointer(aFunc, a.getVariableName(), Arrays.asList(
7202+
LangUtils.nullToLangVoid(retB3)
7203+
), SCOPE_ID);
7204+
retA = LangUtils.nullToLangVoid(retA);
7205+
7206+
if(retA.getType() != DataType.FUNCTION_POINTER)
7207+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by a(b(c)(d)(c)) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
7208+
7209+
FunctionPointerObject retAFunc = retA.getFunctionPointer();
7210+
7211+
DataObject retB4 = interpreter.callFunctionPointer(bFunc, b.getVariableName(), Arrays.asList(
7212+
d
7213+
), SCOPE_ID);
7214+
retB4 = LangUtils.nullToLangVoid(retB4);
7215+
7216+
if(retB4.getType() != DataType.FUNCTION_POINTER)
7217+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by b(d) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
7218+
7219+
FunctionPointerObject retB4Func = retB4.getFunctionPointer();
7220+
7221+
DataObject retB5 = interpreter.callFunctionPointer(retB4Func, retB4.getVariableName(), Arrays.asList(
7222+
c
7223+
), SCOPE_ID);
7224+
retB5 = LangUtils.nullToLangVoid(retB5);
7225+
7226+
if(retB5.getType() != DataType.FUNCTION_POINTER)
7227+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by b(d)(c) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
7228+
7229+
FunctionPointerObject retB5Func = retB5.getFunctionPointer();
7230+
7231+
DataObject retB6 = interpreter.callFunctionPointer(retB5Func, retB5.getVariableName(), Arrays.asList(
7232+
d
7233+
), SCOPE_ID);
7234+
7235+
return interpreter.callFunctionPointer(retAFunc, retA.getVariableName(), Arrays.asList(
7236+
LangUtils.nullToLangVoid(retB6)
7237+
), SCOPE_ID);
7238+
}
7239+
71647240
@LangFunction("combY")
71657241
@CombinatorFunction
71667242
@LangInfo("Combinator execution: (x -> f(x(x)))(x -> f(x(x)))")

0 commit comments

Comments
 (0)