Skip to content

Commit b6fd7e3

Browse files
committed
Add "func.combXN8()"
1 parent 640df95 commit b6fd7e3

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7049,6 +7049,62 @@ public static DataObject combXN7Function(
70497049
), SCOPE_ID);
70507050
}
70517051

7052+
@LangFunction("combXN8")
7053+
@CombinatorFunction
7054+
@LangInfo("Combinator execution: a(b(c)(c))(b(d)(d))")
7055+
public static DataObject combXN8Function(
7056+
LangInterpreter interpreter, int SCOPE_ID,
7057+
@LangParameter("$a") @AllowedTypes(DataObject.DataType.FUNCTION_POINTER) DataObject a,
7058+
@LangParameter("$b") @AllowedTypes(DataObject.DataType.FUNCTION_POINTER) DataObject b,
7059+
@LangParameter("$c") DataObject c,
7060+
@LangParameter("$d") DataObject d
7061+
) {
7062+
FunctionPointerObject aFunc = a.getFunctionPointer();
7063+
FunctionPointerObject bFunc = b.getFunctionPointer();
7064+
7065+
DataObject retB = interpreter.callFunctionPointer(bFunc, b.getVariableName(), Arrays.asList(
7066+
c
7067+
), SCOPE_ID);
7068+
retB = LangUtils.nullToLangVoid(retB);
7069+
7070+
if(retB.getType() != DataType.FUNCTION_POINTER)
7071+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by b(c) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
7072+
7073+
FunctionPointerObject retBFunc = retB.getFunctionPointer();
7074+
7075+
DataObject retB2 = interpreter.callFunctionPointer(retBFunc, retB.getVariableName(), Arrays.asList(
7076+
c
7077+
), SCOPE_ID);
7078+
7079+
DataObject retA = interpreter.callFunctionPointer(aFunc, a.getVariableName(), Arrays.asList(
7080+
LangUtils.nullToLangVoid(retB2)
7081+
), SCOPE_ID);
7082+
retA = LangUtils.nullToLangVoid(retA);
7083+
7084+
if(retA.getType() != DataType.FUNCTION_POINTER)
7085+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by a(b(c)(c)) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
7086+
7087+
FunctionPointerObject retAFunc = retA.getFunctionPointer();
7088+
7089+
DataObject retB3 = interpreter.callFunctionPointer(bFunc, b.getVariableName(), Arrays.asList(
7090+
d
7091+
), SCOPE_ID);
7092+
retB3 = LangUtils.nullToLangVoid(retB3);
7093+
7094+
if(retB3.getType() != DataType.FUNCTION_POINTER)
7095+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by b(d) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
7096+
7097+
FunctionPointerObject retB3Func = retB3.getFunctionPointer();
7098+
7099+
DataObject retB4 = interpreter.callFunctionPointer(retB3Func, retB3.getVariableName(), Arrays.asList(
7100+
d
7101+
), SCOPE_ID);
7102+
7103+
return interpreter.callFunctionPointer(retAFunc, retA.getVariableName(), Arrays.asList(
7104+
LangUtils.nullToLangVoid(retB4)
7105+
), SCOPE_ID);
7106+
}
7107+
70527108
@LangFunction("combY")
70537109
@CombinatorFunction
70547110
@LangInfo("Combinator execution: (x -> f(x(x)))(x -> f(x(x)))")

0 commit comments

Comments
 (0)