package org.shedlang.compiler.shidtopatio; import org.shedlang.compiler.ast.typed.FreeVariables; import org.shedlang.compiler.patio.operands.PatioLocalRef; import org.shedlang.compiler.patio.types.PatioDataLayout; import org.shedlang.compiler.patio.types.PatioDataLayouts; import org.shedlang.compiler.shid.instructions.ShidParam; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.types.NamespaceName; import java.util.List; import java.util.function.Function; public class ShidToPatioFunctions { private ShidToPatioFunctions() { } private static final PatioDataLayout ADDITIONAL_DATA_LAYOUT = PatioDataLayouts.struct(List.of()); private static ShidToPatioClosures.ClosureRuntimeType functionRuntimeType( FreeVariables freeVariables, ShidToPatioContext context ) { return ShidToPatioClosures.closureRuntimeType( ADDITIONAL_DATA_LAYOUT, freeVariables, context ); } public static ShidToPatioContext create( PatioLocalRef destination, String name, List positionalParams, List namedParams, FreeVariables freeVariables, Function generateBody, Source source, ShidToPatioContext context ) { var functionRuntimeType = functionRuntimeType(freeVariables, context); return ShidToPatioClosures.create( destination, ShidToPatioCompilationUnitElementSpace.FUNCTION, name, positionalParams, namedParams, functionRuntimeType, (closurePointer, storeContext) -> storeContext, freeVariables, (closurePointer, bodyContext) -> generateBody.apply(bodyContext), source, context ); } public static ShidToPatioContext createNative( PatioLocalRef destination, NamespaceName namespaceName, String name, List positionalParams, List namedParams, Source source, ShidToPatioContext context ) { var functionRuntimeType = functionRuntimeType(FreeVariables.empty(), context); return ShidToPatioClosures.createNative( destination, namespaceName, name, positionalParams, namedParams, functionRuntimeType, source, context ); } }