package org.shedlang.compiler.patio.instructions; import org.shedlang.compiler.patio.*; import org.shedlang.compiler.patio.operands.*; import org.shedlang.compiler.patio.types.PatioDataLayout; import org.shedlang.compiler.patio.types.PatioDataValue; import org.shedlang.compiler.patio.types.PatioType; import org.shedlang.compiler.patio.values.*; import org.shedlang.compiler.sources.Sources; import java.util.List; import java.util.Optional; public class Patio { private Patio() {} public static PatioBlock block( List body, List results ) { return new PatioBlock(body, results, Sources.NULL); } public static PatioOperand boolConst(boolean value) { return new PatioBoolConst(value); } public static PatioInstruction boolToInt(PatioLocalRef destination, PatioOperand value) { return new PatioBoolToInt(destination, value, Sources.NULL); } public static PatioOperand byteConst(byte value) { return new PatioByteConst(value); } public static PatioInstruction call( List destinations, String name, List args ) { return new PatioCall( destinations, name, args, Sources.NULL ); } public static PatioInstruction call( Optional destination, String name, List args ) { return new PatioCall( destination.stream().toList(), name, args, Sources.NULL ); } public static PatioInstruction callPointer( PatioLocalRef destination, PatioOperand functionPointer, List args ) { return new PatioCallPointer( List.of(destination), functionPointer, args, Sources.NULL ); } public static PatioCatchClause catchClause( String exceptionTypeName, PatioLocalRef destination, PatioBlock body ) { return new PatioCatchClause( exceptionTypeName, destination, body, Sources.NULL ); } public static PatioCompilationUnit compilationUnit( List elements ) { return new PatioCompilationUnit(elements, Sources.NULL); } public static PatioDataElementImmutableDefinition dataElementImmutableDefinition( String name, PatioVisibility visibility, PatioDataValue value ) { return new PatioDataElementImmutableDefinition( name, visibility, value, Sources.NULL ); } public static PatioDataElementMutableDeclaration dataElementMutableDeclaration( String name, PatioDataLayout layout ) { return new PatioDataElementMutableDeclaration( name, layout, Sources.NULL ); } public static PatioDataElementMutableDefinition dataElementMutableDefinition( String name, PatioVisibility visibility, PatioDataValue initialValue ) { return new PatioDataElementMutableDefinition( name, visibility, initialValue, Sources.NULL ); } public static PatioOperand dataPtrConst(String name) { return PatioDataPtrConst.dataElement(name); } public static PatioOperand dataPtrConst(PatioDataPtrValue value) { return new PatioDataPtrConst(value); } public static PatioInstruction dataPtrToInt(PatioLocalRef destination, PatioOperand value) { return new PatioDataPtrToInt( destination, value, Sources.NULL ); } public static PatioDataPtrValue dataPtrValueDataElement(String value) { return new PatioDataPtrValueDataElement(value); } public static PatioDataPtrValue dataPtrValueNull() { return new PatioDataPtrValueNull(); } public static PatioExceptionTypeDefinition exceptionTypeDefinition(String name, PatioType valueType) { return new PatioExceptionTypeDefinition(name, valueType, Sources.NULL); } public static PatioOperand functionPtrConst(String name) { return new PatioFunctionPtrConst(name); } public static PatioInstruction if_( List destinations, PatioOperand condition, PatioBlock trueBody, PatioBlock falseBody ) { return new PatioIf( destinations, condition, trueBody, falseBody, Sources.NULL ); } public static PatioOperand intConst(int value) { return PatioIntConst.of(value); } public static PatioOperand intConst(PatioIntValue value) { return new PatioIntConst(value); } public static PatioOperand int32Const(int value) { return PatioInt32Const.of(value); } public static PatioInstruction intAdd( PatioLocalRef destination, PatioOperand left, PatioOperand right ) { return new PatioIntAdd( destination, left, right, Sources.NULL ); } public static PatioInstruction intEquals( PatioLocalRef destination, PatioOperand left, PatioOperand right ) { return new PatioIntEquals(destination, left, right, Sources.NULL); } public static PatioInstruction intNotEqual( PatioLocalRef destination, PatioOperand left, PatioOperand right ) { return new PatioIntNotEqual(destination, left, right, Sources.NULL); } public static PatioInstruction intSub( PatioLocalRef destination, PatioOperand left, PatioOperand right ) { return new PatioIntSub(destination, left, right, Sources.NULL); } public static PatioInstruction intToBool(PatioLocalRef destination, PatioOperand value) { return new PatioIntToBool(destination, value, Sources.NULL); } public static PatioInstruction intToDataPtr(PatioLocalRef destination, PatioOperand value) { return new PatioIntToDataPtr( destination, value, Sources.NULL ); } public static PatioIntValue intValueByteOffsetOf( PatioDataLayout layout, List offset ) { return new PatioIntValueByteOffsetOf(layout, offset); } public static PatioIntValue intValueByteSizeOf( PatioDataLayout layout ) { return new PatioIntValueByteSizeOf(layout); } public static PatioIntValue intValueLiteral(int value) { return new PatioIntValueLiteral(value); } public static PatioInstruction localStore(PatioLocalRef destination, PatioOperand value) { return new PatioLocalStore( destination, value, Sources.NULL ); } public static PatioLocalRef localRef(String name) { return new PatioLocalRef(name); } public static PatioInstruction loop(List body) { return new PatioLoop(body, Sources.NULL); } public static PatioInstruction loopBreak() { return new PatioLoopBreak(Sources.NULL); } public static PatioInstruction loopContinue() { return new PatioLoopContinue(Sources.NULL); } public static PatioInstruction memoryLoad( PatioLocalRef destination, PatioOperand pointer, PatioDataLayout layout, List offset ) { return new PatioMemoryLoad( destination, pointer, layout, offset, Sources.NULL ); } public static PatioInstruction memoryStore( PatioOperand pointer, PatioDataLayout layout, List offset, PatioOperand value ) { return new PatioMemoryStore( pointer, layout, offset, value, Sources.NULL ); } public static PatioLocal param(String name, PatioType type) { return new PatioLocal(name, type, PatioLocalType.PARAM); } public static PatioInstruction return_(List values) { return new PatioReturn(values, Sources.NULL); } public static PatioInstruction return_(PatioOperand value) { return new PatioReturn(List.of(value), Sources.NULL); } public static PatioInstruction returnVoid() { return new PatioReturn(List.of(), Sources.NULL); } public static PatioInstruction switch_( List destinations, PatioOperand value, List cases, PatioBlock defaultBody ) { return new PatioSwitch(destinations, value, cases, defaultBody, Sources.NULL); } public static PatioSwitchCase switchCase(int value, PatioBlock body) { return new PatioSwitchCase(value, body, Sources.NULL); } public static PatioInstruction throw_(String exceptionTypeName, PatioOperand value) { return new PatioThrow(exceptionTypeName, value, Sources.NULL); } public static PatioTry try_( List destinations, List catchClauses, PatioBlock body ) { return new PatioTry(destinations, catchClauses, body, Sources.NULL); } public static PatioInstruction unreachable() { return new PatioUnreachable(Sources.NULL); } public static PatioLocal val(String name, PatioType type) { return new PatioLocal(name, type, PatioLocalType.VAL); } public static PatioLocal var(String name, PatioType type) { return new PatioLocal(name, type, PatioLocalType.VAR); } public static PatioInstruction varLoad(PatioLocalRef destination, PatioLocalRef value) { return new PatioVarLoad( destination, value, Sources.NULL ); } public static PatioInstruction varStore(PatioLocalRef destination, PatioOperand value) { return new PatioVarStore( destination, value, Sources.NULL ); } }