Skip to content

Commit d335499

Browse files
committed
Add "func.combXN3()"
1 parent 1201260 commit d335499

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
@@ -6825,6 +6825,48 @@ public static DataObject combXN2Function(
68256825
), SCOPE_ID);
68266826
}
68276827

6828+
@LangFunction("combXN3")
6829+
@CombinatorFunction
6830+
@LangInfo("Combinator execution: a(b(c)(d))(c)")
6831+
public static DataObject combXN3Function(
6832+
LangInterpreter interpreter, int SCOPE_ID,
6833+
@LangParameter("$a") @AllowedTypes(DataObject.DataType.FUNCTION_POINTER) DataObject a,
6834+
@LangParameter("$b") @AllowedTypes(DataObject.DataType.FUNCTION_POINTER) DataObject b,
6835+
@LangParameter("$c") DataObject c,
6836+
@LangParameter("$d") DataObject d
6837+
) {
6838+
FunctionPointerObject aFunc = a.getFunctionPointer();
6839+
FunctionPointerObject bFunc = b.getFunctionPointer();
6840+
6841+
DataObject retB = interpreter.callFunctionPointer(bFunc, b.getVariableName(), Arrays.asList(
6842+
c
6843+
), SCOPE_ID);
6844+
retB = LangUtils.nullToLangVoid(retB);
6845+
6846+
if(retB.getType() != DataType.FUNCTION_POINTER)
6847+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by b(c) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
6848+
6849+
FunctionPointerObject retBFunc = retB.getFunctionPointer();
6850+
6851+
DataObject retB2 = interpreter.callFunctionPointer(retBFunc, retB.getVariableName(), Arrays.asList(
6852+
d
6853+
), SCOPE_ID);
6854+
6855+
DataObject retA = interpreter.callFunctionPointer(aFunc, a.getVariableName(), Arrays.asList(
6856+
LangUtils.nullToLangVoid(retB2)
6857+
), SCOPE_ID);
6858+
retA = LangUtils.nullToLangVoid(retA);
6859+
6860+
if(retA.getType() != DataType.FUNCTION_POINTER)
6861+
return interpreter.setErrnoErrorObject(InterpretingError.INVALID_FUNC_PTR, "The value returned by a(b(c)(d)) must be of type " + DataType.FUNCTION_POINTER, SCOPE_ID);
6862+
6863+
FunctionPointerObject retAFunc = retA.getFunctionPointer();
6864+
6865+
return interpreter.callFunctionPointer(retAFunc, retA.getVariableName(), Arrays.asList(
6866+
c
6867+
), SCOPE_ID);
6868+
}
6869+
68286870
@LangFunction("combY")
68296871
@CombinatorFunction
68306872
@LangInfo("Combinator execution: (x -> f(x(x)))(x -> f(x(x)))")

0 commit comments

Comments
 (0)