From 9cc3f85bf25089e4db840380fb09cbdac34ec821 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 20 Dec 2023 17:17:22 +0000 Subject: Remove redundant package --- .../compiler/backends/PatioTextBackend.java | 2 +- .../backends/llvm/codegen/PatioToLlvm.java | 8 +- .../llvm/codegen/PatioToLlvmFunctionContext.java | 2 +- .../compiler/backends/wasm/PatioToWasm.java | 8 +- .../compiler/patio/PatioCompilationUnit.java | 11 + .../patio/PatioCompilationUnitElement.java | 8 + .../compiler/patio/PatioDataElementImmutable.java | 11 + .../compiler/patio/PatioDataElementMutable.java | 11 + .../patio/PatioExceptionTypeDefinition.java | 11 + .../compiler/patio/PatioFunctionDeclaration.java | 64 +++ .../compiler/patio/PatioFunctionDefinition.java | 105 ++++ .../org/shedlang/compiler/patio/PatioLocal.java | 14 + .../shedlang/compiler/patio/PatioLocalType.java | 7 + .../shedlang/compiler/patio/PatioSerializer.java | 551 +++++++++++++++++++++ .../shedlang/compiler/patio/PatioVisibility.java | 6 + .../compiler/patio/ast/PatioCompilationUnit.java | 11 - .../patio/ast/PatioCompilationUnitElement.java | 8 - .../patio/ast/PatioDataElementImmutable.java | 11 - .../patio/ast/PatioDataElementMutable.java | 11 - .../patio/ast/PatioExceptionTypeDefinition.java | 11 - .../patio/ast/PatioFunctionDeclaration.java | 64 --- .../patio/ast/PatioFunctionDefinition.java | 105 ---- .../shedlang/compiler/patio/ast/PatioLocal.java | 14 - .../compiler/patio/ast/PatioLocalType.java | 7 - .../compiler/patio/ast/PatioSerializer.java | 551 --------------------- .../compiler/patio/ast/PatioVisibility.java | 6 - .../patio/ast/instructions/PatioAllocHeap.java | 24 - .../patio/ast/instructions/PatioAllocStack.java | 21 - .../patio/ast/instructions/PatioBlock.java | 31 -- .../patio/ast/instructions/PatioBoolToInt.java | 16 - .../compiler/patio/ast/instructions/PatioCall.java | 24 - .../patio/ast/instructions/PatioCallPointer.java | 23 - .../patio/ast/instructions/PatioCatchClause.java | 17 - .../patio/ast/instructions/PatioDataPtrToInt.java | 16 - .../compiler/patio/ast/instructions/PatioIf.java | 27 - .../patio/ast/instructions/PatioInstruction.java | 8 - .../PatioInstructionBinaryOperation.java | 10 - .../patio/ast/instructions/PatioIntAdd.java | 17 - .../patio/ast/instructions/PatioIntEquals.java | 17 - .../patio/ast/instructions/PatioIntNotEqual.java | 21 - .../patio/ast/instructions/PatioIntSub.java | 21 - .../patio/ast/instructions/PatioIntToBool.java | 16 - .../patio/ast/instructions/PatioIntToDataPtr.java | 16 - .../patio/ast/instructions/PatioLocalStore.java | 19 - .../compiler/patio/ast/instructions/PatioLoop.java | 20 - .../patio/ast/instructions/PatioLoopBreak.java | 13 - .../patio/ast/instructions/PatioLoopContinue.java | 13 - .../patio/ast/instructions/PatioMemoryLoad.java | 25 - .../patio/ast/instructions/PatioMemoryStore.java | 23 - .../patio/ast/instructions/PatioResume.java | 15 - .../patio/ast/instructions/PatioReturn.java | 14 - .../patio/ast/instructions/PatioReturnVoid.java | 13 - .../patio/ast/instructions/PatioSwitch.java | 31 -- .../patio/ast/instructions/PatioThrow.java | 21 - .../compiler/patio/ast/instructions/PatioTry.java | 29 -- .../patio/ast/instructions/PatioUnreachable.java | 14 - .../patio/ast/instructions/PatioVarLoad.java | 18 - .../patio/ast/instructions/PatioVarStore.java | 19 - .../compiler/patio/ast/operands/PatioBool.java | 4 - .../compiler/patio/ast/operands/PatioDataPtr.java | 4 - .../patio/ast/operands/PatioFunctionPtr.java | 4 - .../compiler/patio/ast/operands/PatioInt.java | 4 - .../compiler/patio/ast/operands/PatioLocalRef.java | 6 - .../compiler/patio/ast/operands/PatioOperand.java | 5 - .../compiler/patio/ast/types/PatioBoolType.java | 5 - .../compiler/patio/ast/types/PatioByteType.java | 5 - .../compiler/patio/ast/types/PatioDataLayout.java | 4 - .../patio/ast/types/PatioDataLayoutArray.java | 4 - .../patio/ast/types/PatioDataLayoutBool.java | 5 - .../patio/ast/types/PatioDataLayoutByte.java | 5 - .../ast/types/PatioDataLayoutDataPointer.java | 5 - .../ast/types/PatioDataLayoutFunctionPointer.java | 5 - .../patio/ast/types/PatioDataLayoutInt.java | 5 - .../patio/ast/types/PatioDataLayoutStruct.java | 8 - .../compiler/patio/ast/types/PatioDataLayouts.java | 44 -- .../patio/ast/types/PatioDataPointerType.java | 5 - .../compiler/patio/ast/types/PatioDataValue.java | 5 - .../patio/ast/types/PatioDataValueArray.java | 13 - .../patio/ast/types/PatioDataValueBool.java | 8 - .../patio/ast/types/PatioDataValueByte.java | 8 - .../ast/types/PatioDataValueDataPointerNull.java | 8 - .../patio/ast/types/PatioDataValueInt.java | 8 - .../patio/ast/types/PatioDataValueStruct.java | 14 - .../compiler/patio/ast/types/PatioDataValues.java | 34 -- .../patio/ast/types/PatioFunctionPointerType.java | 5 - .../compiler/patio/ast/types/PatioIntType.java | 5 - .../compiler/patio/ast/types/PatioType.java | 4 - .../compiler/patio/ast/types/PatioTypes.java | 13 - .../compiler/patio/ast/types/PatioVoidType.java | 5 - .../patio/instructions/PatioAllocHeap.java | 24 + .../patio/instructions/PatioAllocStack.java | 21 + .../compiler/patio/instructions/PatioBlock.java | 31 ++ .../patio/instructions/PatioBoolToInt.java | 16 + .../compiler/patio/instructions/PatioCall.java | 24 + .../patio/instructions/PatioCallPointer.java | 23 + .../patio/instructions/PatioCatchClause.java | 17 + .../patio/instructions/PatioDataPtrToInt.java | 16 + .../compiler/patio/instructions/PatioIf.java | 27 + .../patio/instructions/PatioInstruction.java | 8 + .../PatioInstructionBinaryOperation.java | 10 + .../compiler/patio/instructions/PatioIntAdd.java | 17 + .../patio/instructions/PatioIntEquals.java | 17 + .../patio/instructions/PatioIntNotEqual.java | 21 + .../compiler/patio/instructions/PatioIntSub.java | 21 + .../patio/instructions/PatioIntToBool.java | 16 + .../patio/instructions/PatioIntToDataPtr.java | 16 + .../patio/instructions/PatioLocalStore.java | 19 + .../compiler/patio/instructions/PatioLoop.java | 20 + .../patio/instructions/PatioLoopBreak.java | 13 + .../patio/instructions/PatioLoopContinue.java | 13 + .../patio/instructions/PatioMemoryLoad.java | 25 + .../patio/instructions/PatioMemoryStore.java | 23 + .../compiler/patio/instructions/PatioResume.java | 15 + .../compiler/patio/instructions/PatioReturn.java | 14 + .../patio/instructions/PatioReturnVoid.java | 13 + .../compiler/patio/instructions/PatioSwitch.java | 31 ++ .../compiler/patio/instructions/PatioThrow.java | 21 + .../compiler/patio/instructions/PatioTry.java | 29 ++ .../patio/instructions/PatioUnreachable.java | 14 + .../compiler/patio/instructions/PatioVarLoad.java | 18 + .../compiler/patio/instructions/PatioVarStore.java | 19 + .../compiler/patio/operands/PatioBool.java | 4 + .../compiler/patio/operands/PatioDataPtr.java | 4 + .../compiler/patio/operands/PatioFunctionPtr.java | 4 + .../shedlang/compiler/patio/operands/PatioInt.java | 4 + .../compiler/patio/operands/PatioLocalRef.java | 4 + .../compiler/patio/operands/PatioOperand.java | 5 + .../compiler/patio/types/PatioBoolType.java | 5 + .../compiler/patio/types/PatioByteType.java | 5 + .../compiler/patio/types/PatioDataLayout.java | 4 + .../compiler/patio/types/PatioDataLayoutArray.java | 4 + .../compiler/patio/types/PatioDataLayoutBool.java | 5 + .../compiler/patio/types/PatioDataLayoutByte.java | 5 + .../patio/types/PatioDataLayoutDataPointer.java | 5 + .../types/PatioDataLayoutFunctionPointer.java | 5 + .../compiler/patio/types/PatioDataLayoutInt.java | 5 + .../patio/types/PatioDataLayoutStruct.java | 8 + .../compiler/patio/types/PatioDataLayouts.java | 44 ++ .../compiler/patio/types/PatioDataPointerType.java | 5 + .../compiler/patio/types/PatioDataValue.java | 5 + .../compiler/patio/types/PatioDataValueArray.java | 13 + .../compiler/patio/types/PatioDataValueBool.java | 8 + .../compiler/patio/types/PatioDataValueByte.java | 8 + .../patio/types/PatioDataValueDataPointerNull.java | 8 + .../compiler/patio/types/PatioDataValueInt.java | 8 + .../compiler/patio/types/PatioDataValueStruct.java | 14 + .../compiler/patio/types/PatioDataValues.java | 34 ++ .../patio/types/PatioFunctionPointerType.java | 5 + .../compiler/patio/types/PatioIntType.java | 5 + .../shedlang/compiler/patio/types/PatioType.java | 4 + .../shedlang/compiler/patio/types/PatioTypes.java | 13 + .../compiler/patio/types/PatioVoidType.java | 5 + .../shedlang/compiler/shidtopatio/ShidToPatio.java | 14 +- .../compiler/shidtopatio/ShidToPatioClosures.java | 18 +- .../compiler/shidtopatio/ShidToPatioContext.java | 14 +- .../compiler/shidtopatio/ShidToPatioEffects.java | 22 +- .../compiler/shidtopatio/ShidToPatioFunctions.java | 6 +- .../compiler/shidtopatio/ShidToPatioGc.java | 14 +- .../compiler/shidtopatio/ShidToPatioInts.java | 16 +- .../shidtopatio/ShidToPatioNamespaces.java | 16 +- .../compiler/shidtopatio/ShidToPatioStrings.java | 20 +- .../compiler/shidtopatio/ShidToPatioStructs.java | 14 +- .../compiler/shidtopatio/ShidToPatioTuples.java | 14 +- .../compiler/shidtopatio/ShidToPatioTypes.java | 4 +- .../compiler/shidtopatio/ShidToPatioVars.java | 14 +- 165 files changed, 1769 insertions(+), 1771 deletions(-) create mode 100644 src/main/java/org/shedlang/compiler/patio/PatioCompilationUnit.java create mode 100644 src/main/java/org/shedlang/compiler/patio/PatioCompilationUnitElement.java create mode 100644 src/main/java/org/shedlang/compiler/patio/PatioDataElementImmutable.java create mode 100644 src/main/java/org/shedlang/compiler/patio/PatioDataElementMutable.java create mode 100644 src/main/java/org/shedlang/compiler/patio/PatioExceptionTypeDefinition.java create mode 100644 src/main/java/org/shedlang/compiler/patio/PatioFunctionDeclaration.java create mode 100644 src/main/java/org/shedlang/compiler/patio/PatioFunctionDefinition.java create mode 100644 src/main/java/org/shedlang/compiler/patio/PatioLocal.java create mode 100644 src/main/java/org/shedlang/compiler/patio/PatioLocalType.java create mode 100644 src/main/java/org/shedlang/compiler/patio/PatioSerializer.java create mode 100644 src/main/java/org/shedlang/compiler/patio/PatioVisibility.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/PatioCompilationUnit.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/PatioCompilationUnitElement.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/PatioDataElementImmutable.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/PatioDataElementMutable.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/PatioExceptionTypeDefinition.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/PatioFunctionDeclaration.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/PatioFunctionDefinition.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/PatioLocal.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/PatioLocalType.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/PatioVisibility.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAllocHeap.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAllocStack.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioBlock.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioBoolToInt.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioCall.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioCallPointer.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioCatchClause.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioDataPtrToInt.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIf.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioInstruction.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioInstructionBinaryOperation.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntAdd.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntEquals.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntNotEqual.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntSub.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntToBool.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntToDataPtr.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLocalStore.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLoop.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLoopBreak.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLoopContinue.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryLoad.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryStore.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioResume.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioReturn.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioReturnVoid.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioSwitch.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioThrow.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioTry.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioUnreachable.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioVarLoad.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioVarStore.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/operands/PatioBool.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/operands/PatioDataPtr.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/operands/PatioFunctionPtr.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/operands/PatioInt.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/operands/PatioLocalRef.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/operands/PatioOperand.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioBoolType.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioByteType.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayout.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutArray.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutBool.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutByte.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutDataPointer.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutFunctionPointer.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutInt.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutStruct.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayouts.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataPointerType.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValue.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueArray.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueBool.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueByte.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueDataPointerNull.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueInt.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueStruct.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValues.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioFunctionPointerType.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioIntType.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioType.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioTypes.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioVoidType.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioAllocHeap.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioAllocStack.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioBlock.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioBoolToInt.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioCall.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioCallPointer.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioCatchClause.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioDataPtrToInt.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioIf.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioInstruction.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioInstructionBinaryOperation.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioIntAdd.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioIntEquals.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioIntNotEqual.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioIntSub.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioIntToBool.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioIntToDataPtr.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioLocalStore.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioLoop.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioLoopBreak.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioLoopContinue.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryLoad.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryStore.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioResume.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioReturn.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioReturnVoid.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioSwitch.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioThrow.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioTry.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioUnreachable.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioVarLoad.java create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioVarStore.java create mode 100644 src/main/java/org/shedlang/compiler/patio/operands/PatioBool.java create mode 100644 src/main/java/org/shedlang/compiler/patio/operands/PatioDataPtr.java create mode 100644 src/main/java/org/shedlang/compiler/patio/operands/PatioFunctionPtr.java create mode 100644 src/main/java/org/shedlang/compiler/patio/operands/PatioInt.java create mode 100644 src/main/java/org/shedlang/compiler/patio/operands/PatioLocalRef.java create mode 100644 src/main/java/org/shedlang/compiler/patio/operands/PatioOperand.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioBoolType.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioByteType.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioDataLayout.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutArray.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutBool.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutByte.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutDataPointer.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutFunctionPointer.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutInt.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutStruct.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioDataLayouts.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioDataPointerType.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioDataValue.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioDataValueArray.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioDataValueBool.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioDataValueByte.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioDataValueDataPointerNull.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioDataValueInt.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioDataValueStruct.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioDataValues.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioFunctionPointerType.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioIntType.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioType.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioTypes.java create mode 100644 src/main/java/org/shedlang/compiler/patio/types/PatioVoidType.java (limited to 'src/main/java') diff --git a/src/main/java/org/shedlang/compiler/backends/PatioTextBackend.java b/src/main/java/org/shedlang/compiler/backends/PatioTextBackend.java index d5ebb923..0b4c5198 100644 --- a/src/main/java/org/shedlang/compiler/backends/PatioTextBackend.java +++ b/src/main/java/org/shedlang/compiler/backends/PatioTextBackend.java @@ -4,7 +4,7 @@ import org.shedlang.compiler.backends.paths.TargetDir; import org.shedlang.compiler.config.ProjectConfig; import org.shedlang.compiler.shidtopatio.ShidToPatio; import org.shedlang.compiler.shidtopatio.ShidToPatioContext; -import org.shedlang.compiler.patio.ast.PatioSerializer; +import org.shedlang.compiler.patio.PatioSerializer; import org.shedlang.compiler.shid.ShidNamespace; import org.shedlang.compiler.typechecker.TypeInfos; diff --git a/src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvm.java b/src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvm.java index 92ab8bb8..545a4e2f 100644 --- a/src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvm.java +++ b/src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvm.java @@ -10,10 +10,10 @@ import org.shedlang.compiler.backends.llvm.ir.ast.operands.*; import org.shedlang.compiler.backends.llvm.ir.ast.types.LlvmType; import org.shedlang.compiler.backends.llvm.ir.ast.types.LlvmTypes; import org.shedlang.compiler.filesystem.ShedCompilerFiles; -import org.shedlang.compiler.patio.ast.*; -import org.shedlang.compiler.patio.ast.instructions.*; -import org.shedlang.compiler.patio.ast.operands.*; -import org.shedlang.compiler.patio.ast.types.*; +import org.shedlang.compiler.patio.*; +import org.shedlang.compiler.patio.instructions.*; +import org.shedlang.compiler.patio.operands.*; +import org.shedlang.compiler.patio.types.*; import org.shedlang.compiler.util.Lazy; import org.shedlang.compiler.util.Lists; import org.shedlang.compiler.util.P; diff --git a/src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvmFunctionContext.java b/src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvmFunctionContext.java index 584d3202..18e46e3c 100644 --- a/src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvmFunctionContext.java +++ b/src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvmFunctionContext.java @@ -12,7 +12,7 @@ import org.shedlang.compiler.backends.llvm.ir.ast.instructions.LlvmTerminatorIns import org.shedlang.compiler.backends.llvm.ir.ast.operands.LlvmOperand; import org.shedlang.compiler.backends.llvm.ir.ast.operands.LlvmVariableLocal; import org.shedlang.compiler.backends.llvm.ir.ast.types.LlvmType; -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioLocalRef; import org.shedlang.compiler.util.P; import java.util.Optional; diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java b/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java index 44abd376..e1204eb6 100644 --- a/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java +++ b/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java @@ -8,10 +8,10 @@ import org.shedlang.compiler.backends.wasm.structure.ast.linking.WasmMemoryAddre import org.shedlang.compiler.backends.wasm.structure.ast.modules.*; import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmFuncType; import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmValueType; -import org.shedlang.compiler.patio.ast.*; -import org.shedlang.compiler.patio.ast.instructions.*; -import org.shedlang.compiler.patio.ast.operands.*; -import org.shedlang.compiler.patio.ast.types.*; +import org.shedlang.compiler.patio.*; +import org.shedlang.compiler.patio.instructions.*; +import org.shedlang.compiler.patio.operands.*; +import org.shedlang.compiler.patio.types.*; import org.shedlang.compiler.util.Lists; import org.shedlang.compiler.util.P; diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCompilationUnit.java b/src/main/java/org/shedlang/compiler/patio/PatioCompilationUnit.java new file mode 100644 index 00000000..9ac30658 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/PatioCompilationUnit.java @@ -0,0 +1,11 @@ +package org.shedlang.compiler.patio; + +import org.shedlang.compiler.sources.Source; + +import java.util.List; + +public record PatioCompilationUnit( + List elements, + Source source +) { +} diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCompilationUnitElement.java b/src/main/java/org/shedlang/compiler/patio/PatioCompilationUnitElement.java new file mode 100644 index 00000000..791b06d1 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/PatioCompilationUnitElement.java @@ -0,0 +1,8 @@ +package org.shedlang.compiler.patio; + +import org.shedlang.compiler.sources.Source; + +public sealed interface PatioCompilationUnitElement permits PatioDataElementImmutable, PatioDataElementMutable, PatioExceptionTypeDefinition, PatioFunctionDeclaration, PatioFunctionDefinition { + String name(); + Source source(); +} diff --git a/src/main/java/org/shedlang/compiler/patio/PatioDataElementImmutable.java b/src/main/java/org/shedlang/compiler/patio/PatioDataElementImmutable.java new file mode 100644 index 00000000..fef9f1fd --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/PatioDataElementImmutable.java @@ -0,0 +1,11 @@ +package org.shedlang.compiler.patio; + +import org.shedlang.compiler.patio.types.PatioDataValue; +import org.shedlang.compiler.sources.Source; + +public record PatioDataElementImmutable( + String name, + PatioDataValue value, + Source source +) implements PatioCompilationUnitElement { +} diff --git a/src/main/java/org/shedlang/compiler/patio/PatioDataElementMutable.java b/src/main/java/org/shedlang/compiler/patio/PatioDataElementMutable.java new file mode 100644 index 00000000..674a52a3 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/PatioDataElementMutable.java @@ -0,0 +1,11 @@ +package org.shedlang.compiler.patio; + +import org.shedlang.compiler.patio.types.PatioDataValue; +import org.shedlang.compiler.sources.Source; + +public record PatioDataElementMutable( + String name, + PatioDataValue initialValue, + Source source +) implements PatioCompilationUnitElement { +} diff --git a/src/main/java/org/shedlang/compiler/patio/PatioExceptionTypeDefinition.java b/src/main/java/org/shedlang/compiler/patio/PatioExceptionTypeDefinition.java new file mode 100644 index 00000000..083aab4f --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/PatioExceptionTypeDefinition.java @@ -0,0 +1,11 @@ +package org.shedlang.compiler.patio; + +import org.shedlang.compiler.patio.types.PatioType; +import org.shedlang.compiler.sources.Source; + +public record PatioExceptionTypeDefinition( + String name, + PatioType valueType, + Source source +) implements PatioCompilationUnitElement { +} diff --git a/src/main/java/org/shedlang/compiler/patio/PatioFunctionDeclaration.java b/src/main/java/org/shedlang/compiler/patio/PatioFunctionDeclaration.java new file mode 100644 index 00000000..8b9b29ae --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/PatioFunctionDeclaration.java @@ -0,0 +1,64 @@ +package org.shedlang.compiler.patio; + +import org.pcollections.PVector; +import org.shedlang.compiler.patio.types.PatioType; +import org.shedlang.compiler.patio.types.PatioTypes; +import org.shedlang.compiler.sources.Source; +import org.shedlang.compiler.sources.Sources; +import org.shedlang.compiler.util.P; + +import java.util.List; + +public record PatioFunctionDeclaration( + String name, + List params, + PatioType returnType, + Source source +) implements PatioCompilationUnitElement { + public static Builder builder() { + return new Builder( + "f", + P.vector(), + PatioTypes.INT + ); + } + + public record Builder( + String name, + PVector params, + PatioType returnType + ) { + public Builder withName(String name) { + return new Builder( + name, + this.params, + this.returnType + ); + } + + public Builder addParam(PatioLocal param) { + return new Builder( + this.name, + this.params.plus(param), + this.returnType + ); + } + + public Builder withReturnType(PatioType returnType) { + return new Builder( + this.name, + this.params, + returnType + ); + } + + public PatioFunctionDeclaration build() { + return new PatioFunctionDeclaration( + this.name, + this.params, + this.returnType, + Sources.NULL + ); + } + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/PatioFunctionDefinition.java b/src/main/java/org/shedlang/compiler/patio/PatioFunctionDefinition.java new file mode 100644 index 00000000..2cf0f4aa --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/PatioFunctionDefinition.java @@ -0,0 +1,105 @@ +package org.shedlang.compiler.patio; + +import org.pcollections.PVector; +import org.shedlang.compiler.patio.instructions.PatioInstruction; +import org.shedlang.compiler.patio.types.PatioType; +import org.shedlang.compiler.patio.types.PatioTypes; +import org.shedlang.compiler.sources.Source; +import org.shedlang.compiler.sources.Sources; +import org.shedlang.compiler.util.P; + +import java.util.List; + +public record PatioFunctionDefinition( + String name, + PatioVisibility visibility, + List locals, + PatioType returnType, + List body, + Source source +) implements PatioCompilationUnitElement { + public Iterable params() { + return locals.stream() + .filter(local -> local.localType() == PatioLocalType.PARAM) + .toList(); + } + + public static Builder builder() { + return new Builder( + "f", + PatioVisibility.PRIVATE, + P.vector(), + PatioTypes.INT, + P.vector() + ); + } + + public record Builder( + String name, + PatioVisibility visibility, + PVector locals, + PatioType returnType, + PVector body + ) { + public Builder withName(String name) { + return new Builder( + name, + this.visibility, + this.locals, + this.returnType, + this.body + ); + } + + public Builder withVisibility(PatioVisibility visibility) { + return new Builder( + this.name, + visibility, + this.locals, + this.returnType, + this.body + ); + } + + public Builder addLocal(PatioLocal local) { + return new Builder( + this.name, + this.visibility, + this.locals.plus(local), + this.returnType, + this.body + ); + } + + public Builder addBodyInstruction(PatioInstruction instruction) { + return new Builder( + this.name, + this.visibility, + this.locals, + this.returnType, + this.body.plus(instruction) + ); + } + + public Builder withReturnType(PatioType returnType) { + return new Builder( + this.name, + this.visibility, + this.locals, + returnType, + this.body + ); + } + + public PatioFunctionDefinition build() { + return new PatioFunctionDefinition( + this.name, + this.visibility, + this.locals, + this.returnType, + this.body, + Sources.NULL + ); + } + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/PatioLocal.java b/src/main/java/org/shedlang/compiler/patio/PatioLocal.java new file mode 100644 index 00000000..fb600c54 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/PatioLocal.java @@ -0,0 +1,14 @@ +package org.shedlang.compiler.patio; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.types.PatioType; + +public record PatioLocal(String name, PatioType type, PatioLocalType localType) { + public static PatioLocal param(String name, PatioType type) { + return new PatioLocal(name, type, PatioLocalType.PARAM); + } + + public PatioLocalRef ref() { + return new PatioLocalRef(name()); + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/PatioLocalType.java b/src/main/java/org/shedlang/compiler/patio/PatioLocalType.java new file mode 100644 index 00000000..00c31ec7 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/PatioLocalType.java @@ -0,0 +1,7 @@ +package org.shedlang.compiler.patio; + +public enum PatioLocalType { + PARAM, + VAL, + VAR, +} diff --git a/src/main/java/org/shedlang/compiler/patio/PatioSerializer.java b/src/main/java/org/shedlang/compiler/patio/PatioSerializer.java new file mode 100644 index 00000000..ff274bce --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/PatioSerializer.java @@ -0,0 +1,551 @@ +package org.shedlang.compiler.patio; + +import org.shedlang.compiler.patio.instructions.*; +import org.shedlang.compiler.patio.operands.*; +import org.shedlang.compiler.patio.types.*; +import org.shedlang.compiler.treetext.Tree; + +import java.util.List; +import java.util.Optional; + +import static org.shedlang.compiler.treetext.TreeSerializer.serializeTree; +import static org.shedlang.compiler.treetext.Trees.*; + +public class PatioSerializer { + private PatioSerializer() {} + + public static void serializeCompilationUnit( + PatioCompilationUnit compilationUnit, + StringBuilder builder + ) { + var tree = compilationUnitToTree(compilationUnit); + serializeTree(tree, builder, 0); + } + + public static void serializeCompilationUnitElement( + PatioCompilationUnitElement element, + StringBuilder builder + ) { + var tree = compilationUnitElementToTree(element); + serializeTree(tree, builder, 0); + } + + public static void serializeDataLayout( + PatioDataLayout layout, + StringBuilder builder + ) { + var tree = dataLayoutToTree(layout); + serializeTree(tree, builder, 0); + } + + public static void serializeDataValue( + PatioDataValue value, + StringBuilder builder + ) { + var tree = dataValueToTree(value); + serializeTree(tree, builder, 0); + } + + public static void serializeInstructions(List instructions, StringBuilder builder) { + var tree = instructionsToTree(instructions); + serializeTree(tree, builder, 0); + } + + public static void serializeInstruction(PatioInstruction instruction, StringBuilder builder) { + var tree = instructionToTree(instruction); + serializeTree(tree, builder, 0); + } + + public static void serializeLocal(PatioLocal local, StringBuilder builder) { + var tree = localToTree(local); + serializeTree(tree, builder, 0); + } + + public static void serializeOperand(PatioOperand operand, StringBuilder builder) { + var tree = operandToTree(operand); + serializeTree(tree, builder, 0); + } + + public static void serializeType(PatioType type, StringBuilder builder) { + var tree = typeToTree(type); + serializeTree(tree, builder, 0); + } + + private static Tree compilationUnitToTree(PatioCompilationUnit compilationUnit) { + return treeListIndented( + compilationUnit.elements().stream() + .map(element -> compilationUnitElementToTree(element)) + .toList() + ); + } + + private static Tree compilationUnitElementToTree(PatioCompilationUnitElement element) { + return switch (element) { + case PatioDataElementImmutable dataElementImmutable -> + treeList( + treeIdentifier("data-immutable"), + treeString(dataElementImmutable.name()), + dataValueToTree(dataElementImmutable.value()) + ); + + case PatioDataElementMutable dataElementMutable -> + treeList( + treeIdentifier("data-mutable"), + treeString(dataElementMutable.name()), + dataValueToTree(dataElementMutable.initialValue()) + ); + + case PatioExceptionTypeDefinition exceptionTypeDefinition -> + treeList( + treeIdentifier("exception-type"), + treeString(exceptionTypeDefinition.name()), + typeToTree(exceptionTypeDefinition.valueType()) + ); + + case PatioFunctionDeclaration functionDeclaration -> + treeListIndented( + treeIdentifier("function-decl"), + treeString(element.name()), + treeNamed("params", treeList( + functionDeclaration.params().stream() + .map(param -> localToTree(param)) + .toList() + )), + treeNamed("return-type", typeToTree(functionDeclaration.returnType())) + ); + + case PatioFunctionDefinition functionDefinition -> + treeListIndented( + treeIdentifier("function"), + treeString(element.name()), + treeNamed("visibility", visibilityToTree(functionDefinition.visibility())), + treeNamed("locals", treeList( + functionDefinition.locals().stream() + .map(local -> localToTree(local)) + .toList() + )), + treeNamed("return-type", typeToTree(functionDefinition.returnType())), + treeNamed("body", instructionsToTree(functionDefinition.body())) + ); + }; + } + + private static Tree instructionsToTree(List instructions) { + return treeListIndented( + instructions.stream() + .map(instruction -> instructionToTree(instruction)) + .toList() + ); + } + + private static Tree instructionToTree(PatioInstruction instruction) { + return switch (instruction) { + case PatioAllocHeap allocHeap -> + treeList( + treeIdentifier("alloc-heap"), + operandToTree(allocHeap.target()), + dataLayoutToTree(allocHeap.layout()) + ); + + case PatioAllocStack allocStack -> + treeList( + treeIdentifier("alloc-stack"), + operandToTree(allocStack.target()), + dataLayoutToTree(allocStack.layout()) + ); + + case PatioBlock block -> + blockToTree(block); + + case PatioBoolToInt boolToInt -> + treeList( + treeIdentifier("bool-to-int"), + operandToTree(boolToInt.target()), + operandToTree(boolToInt.value()) + ); + + case PatioCall call -> + treeList( + treeIdentifier("call"), + optionalOperandToTree(call.target()), + treeString(call.functionName()), + operandsToTree(call.args()) + ); + + case PatioCallPointer callPointer -> + treeList( + treeIdentifier("call-pointer"), + operandToTree(callPointer.target()), + operandToTree(callPointer.functionPointer()), + operandsToTree(callPointer.args()) + ); + + case PatioDataPtrToInt dataPtrToInt -> + treeList( + treeIdentifier("data-ptr-to-int"), + operandToTree(dataPtrToInt.target()), + operandToTree(dataPtrToInt.value()) + ); + + case PatioIf if_ -> + treeListIndented( + treeIdentifier("if"), + operandsToTree(if_.targets()), + operandToTree(if_.condition()), + blockToTree(if_.trueBody()), + blockToTree(if_.falseBody()) + ); + + case PatioIntAdd intAdd -> + treeList( + treeIdentifier("int-add"), + operandToTree(intAdd.target()), + operandToTree(intAdd.left()), + operandToTree(intAdd.right()) + ); + + case PatioIntEquals intEquals -> + treeList( + treeIdentifier("int-eq"), + operandToTree(intEquals.target()), + operandToTree(intEquals.left()), + operandToTree(intEquals.right()) + ); + + case PatioIntNotEqual intNotEqual -> + treeList( + treeIdentifier("int-ne"), + operandToTree(intNotEqual.target()), + operandToTree(intNotEqual.left()), + operandToTree(intNotEqual.right()) + ); + + + case PatioIntSub intSub -> + treeList( + treeIdentifier("int-sub"), + operandToTree(intSub.target()), + operandToTree(intSub.left()), + operandToTree(intSub.right()) + ); + + case PatioIntToBool intToBool -> + treeList( + treeIdentifier("int-to-bool"), + operandToTree(intToBool.target()), + operandToTree(intToBool.value()) + ); + + case PatioIntToDataPtr intToDataPtr -> + treeList( + treeIdentifier("int-to-data-ptr"), + operandToTree(intToDataPtr.target()), + operandToTree(intToDataPtr.value()) + ); + + case PatioLocalStore localStore -> + treeList( + treeIdentifier("local-store"), + operandToTree(localStore.target()), + operandToTree(localStore.value()) + ); + + case PatioLoop loop -> + treeListIndented( + treeIdentifier("loop"), + instructionsToTree(loop.body()) + ); + + case PatioLoopBreak loopBreak -> + treeList( + treeIdentifier("break") + ); + + case PatioLoopContinue loopContinue -> + treeList( + treeIdentifier("continue") + ); + + case PatioMemoryLoad memoryLoad -> + treeListIndented( + treeIdentifier("memory-load"), + operandToTree(memoryLoad.target()), + treeNamed("pointer", operandToTree(memoryLoad.pointer())), + treeNamed("layout", dataLayoutToTree(memoryLoad.layout())), + treeNamed("offset", treeList( + memoryLoad.offset().stream() + .map(offset -> treeInt(offset)) + .toList() + )) + ); + + case PatioMemoryStore memoryStore -> + treeListIndented( + treeIdentifier("memory-store"), + treeNamed("pointer", operandToTree(memoryStore.pointer())), + treeNamed("layout", dataLayoutToTree(memoryStore.layout())), + treeNamed("offset", treeList( + memoryStore.offset().stream() + .map(offset -> treeInt(offset)) + .toList() + )), + treeNamed("value", operandToTree(memoryStore.value())) + ); + + case PatioResume resume -> + treeList( + treeIdentifier("resume"), + operandToTree(resume.value()) + ); + + case PatioReturn return_ -> + treeList( + treeIdentifier("return"), + operandToTree(return_.value()) + ); + + case PatioReturnVoid returnVoid -> + treeList( + treeIdentifier("return-void") + ); + + case PatioSwitch switch_ -> + treeListIndented( + treeIdentifier("switch"), + operandsToTree(switch_.targets()), + operandToTree(switch_.value()), + treeListIndented( + switch_.cases().stream() + .map(switchCase -> treeListIndented( + treeIdentifier("case"), + treeInt(switchCase.value()), + blockToTree(switchCase.body()) + )) + .toList() + ), + blockToTree(switch_.defaultBody()) + ); + + case PatioTry try_ -> + treeListIndented( + treeIdentifier("try"), + operandsToTree(try_.targets()), + treeListIndented( + try_.catchClauses().stream() + .map(catchClause -> treeListIndented( + treeIdentifier("catch"), + treeString(catchClause.exceptionTypeName()), + operandToTree(catchClause.target()), + blockToTree(catchClause.body()) + )) + .toList() + ), + blockToTree(try_.body()) + ); + + case PatioThrow throw_ -> + treeList( + treeIdentifier("throw"), + treeString(throw_.exceptionTypeName()), + operandToTree(throw_.value()) + ); + + case PatioUnreachable unreachable -> + treeList(treeIdentifier("unreachable")); + + case PatioVarLoad varLoad -> + treeList( + treeIdentifier("var-load"), + operandToTree(varLoad.target()), + operandToTree(varLoad.var()) + ); + + case PatioVarStore varStore -> + treeList( + treeIdentifier("var-store"), + operandToTree(varStore.var()), + operandToTree(varStore.value()) + ); + }; + } + + private static Tree blockToTree(PatioBlock block) { + return treeListIndented( + treeIdentifier("block"), + instructionsToTree(block.body()), + treeNamed( + "results", + treeList( + block.results().stream() + .map(result -> operandToTree(result)) + .toList() + ) + ) + ); + } + + private static Tree localToTree(PatioLocal local) { + var localType = switch (local.localType()) { + case PARAM -> + "param"; + + case VAL -> + "val"; + + case VAR -> + "var"; + }; + + return treeList( + treeIdentifier(localType), + treeString(local.name()), + typeToTree(local.type()) + ); + } + + private static Tree optionalOperandToTree(Optional target) { + if (target.isEmpty()) { + return treeIdentifier("_"); + } else { + return operandToTree(target.get()); + } + } + + private static Tree operandsToTree(List operands) { + return treeList( + operands.stream() + .map(target -> operandToTree(target)) + .toList() + ); + } + + private static Tree operandToTree(PatioOperand operand) { + return switch (operand) { + case PatioBool bool -> + treeList(treeIdentifier("bool"), treeBool(bool.value())); + + case PatioDataPtr dataPtr -> + treeList(treeIdentifier("data-ptr"), treeString(dataPtr.name())); + + case PatioFunctionPtr functionPtr -> + treeList(treeIdentifier("function-ptr"), treeString(functionPtr.name())); + + case PatioInt int_ -> + treeList(treeIdentifier("int"), treeInt(int_.value())); + + case PatioLocalRef localRef -> + treeList(treeIdentifier("local"), treeString(localRef.name())); + }; + } + + private static Tree typeToTree(PatioType type) { + return switch (type) { + case PatioBoolType boolType -> + treeIdentifier("bool"); + + case PatioByteType byteType -> + treeIdentifier("byte"); + + case PatioDataPointerType dataPointerType -> + treeIdentifier("data-ptr"); + + case PatioFunctionPointerType functionPointerType -> + treeIdentifier("function-ptr"); + + case PatioIntType intType -> + treeIdentifier("int"); + + case PatioVoidType voidType -> + treeIdentifier("void"); + }; + } + + private static Tree dataLayoutToTree(PatioDataLayout layout) { + return switch (layout) { + case PatioDataLayoutArray array -> + treeList( + treeIdentifier("array"), + dataLayoutToTree(array.element()), + treeInt(array.size()) + ); + + case PatioDataLayoutBool bool -> + treeIdentifier("bool"); + + case PatioDataLayoutByte byte_ -> + treeIdentifier("byte"); + + case PatioDataLayoutDataPointer dataPointer -> + treeIdentifier("data-ptr"); + + case PatioDataLayoutFunctionPointer functionPointer -> + treeIdentifier("function-ptr"); + + case PatioDataLayoutInt int_ -> + treeIdentifier("int"); + + case PatioDataLayoutStruct struct -> + treeList( + treeIdentifier("struct"), + treeList( + struct.elements().stream() + .map(element -> dataLayoutToTree(element)) + .toList() + ) + ); + }; + } + + private static Tree dataValueToTree(PatioDataValue value) { + return switch (value) { + case PatioDataValueArray array -> + treeList( + treeIdentifier("array"), + dataLayoutToTree(array.elementLayout()), + treeList( + array.elements().stream() + .map(element -> dataValueToTree(element)) + .toList() + ) + ); + + case PatioDataValueBool bool -> + treeList( + treeIdentifier("bool"), + treeIdentifier(bool.value() ? "true" : "false") + ); + + case PatioDataValueByte byte_ -> + treeList( + treeIdentifier("byte"), + treeIdentifier(String.format("0x%02x", byte_.value())) + ); + + case PatioDataValueDataPointerNull dataPointerNull -> + treeList(treeIdentifier("data-ptr"), treeIdentifier("null")); + + case PatioDataValueInt int_ -> + treeList( + treeIdentifier("int"), + treeIdentifier(Integer.toString(int_.value())) + ); + + case PatioDataValueStruct struct -> + treeList( + treeIdentifier("struct"), + treeList( + struct.elements().stream() + .map(element -> dataValueToTree(element)) + .toList() + ) + ); + }; + } + + private static Tree visibilityToTree(PatioVisibility visibility) { + return treeIdentifier(switch (visibility) { + case PRIVATE -> "private"; + case PUBLIC -> "public"; + }); + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/PatioVisibility.java b/src/main/java/org/shedlang/compiler/patio/PatioVisibility.java new file mode 100644 index 00000000..55ccc361 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/PatioVisibility.java @@ -0,0 +1,6 @@ +package org.shedlang.compiler.patio; + +public enum PatioVisibility { + PRIVATE, + PUBLIC, +} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/PatioCompilationUnit.java b/src/main/java/org/shedlang/compiler/patio/ast/PatioCompilationUnit.java deleted file mode 100644 index 227c38d2..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/PatioCompilationUnit.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.shedlang.compiler.patio.ast; - -import org.shedlang.compiler.sources.Source; - -import java.util.List; - -public record PatioCompilationUnit( - List elements, - Source source -) { -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/PatioCompilationUnitElement.java b/src/main/java/org/shedlang/compiler/patio/ast/PatioCompilationUnitElement.java deleted file mode 100644 index 038b0fba..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/PatioCompilationUnitElement.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.shedlang.compiler.patio.ast; - -import org.shedlang.compiler.sources.Source; - -public sealed interface PatioCompilationUnitElement permits PatioDataElementImmutable, PatioDataElementMutable, PatioExceptionTypeDefinition, PatioFunctionDeclaration, PatioFunctionDefinition { - String name(); - Source source(); -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/PatioDataElementImmutable.java b/src/main/java/org/shedlang/compiler/patio/ast/PatioDataElementImmutable.java deleted file mode 100644 index 14c2bee2..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/PatioDataElementImmutable.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.shedlang.compiler.patio.ast; - -import org.shedlang.compiler.patio.ast.types.PatioDataValue; -import org.shedlang.compiler.sources.Source; - -public record PatioDataElementImmutable( - String name, - PatioDataValue value, - Source source -) implements PatioCompilationUnitElement { -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/PatioDataElementMutable.java b/src/main/java/org/shedlang/compiler/patio/ast/PatioDataElementMutable.java deleted file mode 100644 index 568a86e9..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/PatioDataElementMutable.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.shedlang.compiler.patio.ast; - -import org.shedlang.compiler.patio.ast.types.PatioDataValue; -import org.shedlang.compiler.sources.Source; - -public record PatioDataElementMutable( - String name, - PatioDataValue initialValue, - Source source -) implements PatioCompilationUnitElement { -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/PatioExceptionTypeDefinition.java b/src/main/java/org/shedlang/compiler/patio/ast/PatioExceptionTypeDefinition.java deleted file mode 100644 index 7dabc809..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/PatioExceptionTypeDefinition.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.shedlang.compiler.patio.ast; - -import org.shedlang.compiler.patio.ast.types.PatioType; -import org.shedlang.compiler.sources.Source; - -public record PatioExceptionTypeDefinition( - String name, - PatioType valueType, - Source source -) implements PatioCompilationUnitElement { -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/PatioFunctionDeclaration.java b/src/main/java/org/shedlang/compiler/patio/ast/PatioFunctionDeclaration.java deleted file mode 100644 index 28810b5e..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/PatioFunctionDeclaration.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.shedlang.compiler.patio.ast; - -import org.pcollections.PVector; -import org.shedlang.compiler.patio.ast.types.PatioType; -import org.shedlang.compiler.patio.ast.types.PatioTypes; -import org.shedlang.compiler.sources.Source; -import org.shedlang.compiler.sources.Sources; -import org.shedlang.compiler.util.P; - -import java.util.List; - -public record PatioFunctionDeclaration( - String name, - List params, - PatioType returnType, - Source source -) implements PatioCompilationUnitElement { - public static Builder builder() { - return new Builder( - "f", - P.vector(), - PatioTypes.INT - ); - } - - public record Builder( - String name, - PVector params, - PatioType returnType - ) { - public Builder withName(String name) { - return new Builder( - name, - this.params, - this.returnType - ); - } - - public Builder addParam(PatioLocal param) { - return new Builder( - this.name, - this.params.plus(param), - this.returnType - ); - } - - public Builder withReturnType(PatioType returnType) { - return new Builder( - this.name, - this.params, - returnType - ); - } - - public PatioFunctionDeclaration build() { - return new PatioFunctionDeclaration( - this.name, - this.params, - this.returnType, - Sources.NULL - ); - } - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/PatioFunctionDefinition.java b/src/main/java/org/shedlang/compiler/patio/ast/PatioFunctionDefinition.java deleted file mode 100644 index cc477244..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/PatioFunctionDefinition.java +++ /dev/null @@ -1,105 +0,0 @@ -package org.shedlang.compiler.patio.ast; - -import org.pcollections.PVector; -import org.shedlang.compiler.patio.ast.instructions.PatioInstruction; -import org.shedlang.compiler.patio.ast.types.PatioType; -import org.shedlang.compiler.patio.ast.types.PatioTypes; -import org.shedlang.compiler.sources.Source; -import org.shedlang.compiler.sources.Sources; -import org.shedlang.compiler.util.P; - -import java.util.List; - -public record PatioFunctionDefinition( - String name, - PatioVisibility visibility, - List locals, - PatioType returnType, - List body, - Source source -) implements PatioCompilationUnitElement { - public Iterable params() { - return locals.stream() - .filter(local -> local.localType() == PatioLocalType.PARAM) - .toList(); - } - - public static Builder builder() { - return new Builder( - "f", - PatioVisibility.PRIVATE, - P.vector(), - PatioTypes.INT, - P.vector() - ); - } - - public record Builder( - String name, - PatioVisibility visibility, - PVector locals, - PatioType returnType, - PVector body - ) { - public Builder withName(String name) { - return new Builder( - name, - this.visibility, - this.locals, - this.returnType, - this.body - ); - } - - public Builder withVisibility(PatioVisibility visibility) { - return new Builder( - this.name, - visibility, - this.locals, - this.returnType, - this.body - ); - } - - public Builder addLocal(PatioLocal local) { - return new Builder( - this.name, - this.visibility, - this.locals.plus(local), - this.returnType, - this.body - ); - } - - public Builder addBodyInstruction(PatioInstruction instruction) { - return new Builder( - this.name, - this.visibility, - this.locals, - this.returnType, - this.body.plus(instruction) - ); - } - - public Builder withReturnType(PatioType returnType) { - return new Builder( - this.name, - this.visibility, - this.locals, - returnType, - this.body - ); - } - - public PatioFunctionDefinition build() { - return new PatioFunctionDefinition( - this.name, - this.visibility, - this.locals, - this.returnType, - this.body, - Sources.NULL - ); - } - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/PatioLocal.java b/src/main/java/org/shedlang/compiler/patio/ast/PatioLocal.java deleted file mode 100644 index 497a641d..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/PatioLocal.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.shedlang.compiler.patio.ast; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.types.PatioType; - -public record PatioLocal(String name, PatioType type, PatioLocalType localType) { - public static PatioLocal param(String name, PatioType type) { - return new PatioLocal(name, type, PatioLocalType.PARAM); - } - - public PatioLocalRef ref() { - return new PatioLocalRef(name()); - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/PatioLocalType.java b/src/main/java/org/shedlang/compiler/patio/ast/PatioLocalType.java deleted file mode 100644 index 8c8dec39..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/PatioLocalType.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.shedlang.compiler.patio.ast; - -public enum PatioLocalType { - PARAM, - VAL, - VAR, -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java b/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java deleted file mode 100644 index 53508766..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java +++ /dev/null @@ -1,551 +0,0 @@ -package org.shedlang.compiler.patio.ast; - -import org.shedlang.compiler.patio.ast.instructions.*; -import org.shedlang.compiler.patio.ast.operands.*; -import org.shedlang.compiler.patio.ast.types.*; -import org.shedlang.compiler.treetext.Tree; - -import java.util.List; -import java.util.Optional; - -import static org.shedlang.compiler.treetext.TreeSerializer.serializeTree; -import static org.shedlang.compiler.treetext.Trees.*; - -public class PatioSerializer { - private PatioSerializer() {} - - public static void serializeCompilationUnit( - PatioCompilationUnit compilationUnit, - StringBuilder builder - ) { - var tree = compilationUnitToTree(compilationUnit); - serializeTree(tree, builder, 0); - } - - public static void serializeCompilationUnitElement( - PatioCompilationUnitElement element, - StringBuilder builder - ) { - var tree = compilationUnitElementToTree(element); - serializeTree(tree, builder, 0); - } - - public static void serializeDataLayout( - PatioDataLayout layout, - StringBuilder builder - ) { - var tree = dataLayoutToTree(layout); - serializeTree(tree, builder, 0); - } - - public static void serializeDataValue( - PatioDataValue value, - StringBuilder builder - ) { - var tree = dataValueToTree(value); - serializeTree(tree, builder, 0); - } - - public static void serializeInstructions(List instructions, StringBuilder builder) { - var tree = instructionsToTree(instructions); - serializeTree(tree, builder, 0); - } - - public static void serializeInstruction(PatioInstruction instruction, StringBuilder builder) { - var tree = instructionToTree(instruction); - serializeTree(tree, builder, 0); - } - - public static void serializeLocal(PatioLocal local, StringBuilder builder) { - var tree = localToTree(local); - serializeTree(tree, builder, 0); - } - - public static void serializeOperand(PatioOperand operand, StringBuilder builder) { - var tree = operandToTree(operand); - serializeTree(tree, builder, 0); - } - - public static void serializeType(PatioType type, StringBuilder builder) { - var tree = typeToTree(type); - serializeTree(tree, builder, 0); - } - - private static Tree compilationUnitToTree(PatioCompilationUnit compilationUnit) { - return treeListIndented( - compilationUnit.elements().stream() - .map(element -> compilationUnitElementToTree(element)) - .toList() - ); - } - - private static Tree compilationUnitElementToTree(PatioCompilationUnitElement element) { - return switch (element) { - case PatioDataElementImmutable dataElementImmutable -> - treeList( - treeIdentifier("data-immutable"), - treeString(dataElementImmutable.name()), - dataValueToTree(dataElementImmutable.value()) - ); - - case PatioDataElementMutable dataElementMutable -> - treeList( - treeIdentifier("data-mutable"), - treeString(dataElementMutable.name()), - dataValueToTree(dataElementMutable.initialValue()) - ); - - case PatioExceptionTypeDefinition exceptionTypeDefinition -> - treeList( - treeIdentifier("exception-type"), - treeString(exceptionTypeDefinition.name()), - typeToTree(exceptionTypeDefinition.valueType()) - ); - - case PatioFunctionDeclaration functionDeclaration -> - treeListIndented( - treeIdentifier("function-decl"), - treeString(element.name()), - treeNamed("params", treeList( - functionDeclaration.params().stream() - .map(param -> localToTree(param)) - .toList() - )), - treeNamed("return-type", typeToTree(functionDeclaration.returnType())) - ); - - case PatioFunctionDefinition functionDefinition -> - treeListIndented( - treeIdentifier("function"), - treeString(element.name()), - treeNamed("visibility", visibilityToTree(functionDefinition.visibility())), - treeNamed("locals", treeList( - functionDefinition.locals().stream() - .map(local -> localToTree(local)) - .toList() - )), - treeNamed("return-type", typeToTree(functionDefinition.returnType())), - treeNamed("body", instructionsToTree(functionDefinition.body())) - ); - }; - } - - private static Tree instructionsToTree(List instructions) { - return treeListIndented( - instructions.stream() - .map(instruction -> instructionToTree(instruction)) - .toList() - ); - } - - private static Tree instructionToTree(PatioInstruction instruction) { - return switch (instruction) { - case PatioAllocHeap allocHeap -> - treeList( - treeIdentifier("alloc-heap"), - operandToTree(allocHeap.target()), - dataLayoutToTree(allocHeap.layout()) - ); - - case PatioAllocStack allocStack -> - treeList( - treeIdentifier("alloc-stack"), - operandToTree(allocStack.target()), - dataLayoutToTree(allocStack.layout()) - ); - - case PatioBlock block -> - blockToTree(block); - - case PatioBoolToInt boolToInt -> - treeList( - treeIdentifier("bool-to-int"), - operandToTree(boolToInt.target()), - operandToTree(boolToInt.value()) - ); - - case PatioCall call -> - treeList( - treeIdentifier("call"), - optionalOperandToTree(call.target()), - treeString(call.functionName()), - operandsToTree(call.args()) - ); - - case PatioCallPointer callPointer -> - treeList( - treeIdentifier("call-pointer"), - operandToTree(callPointer.target()), - operandToTree(callPointer.functionPointer()), - operandsToTree(callPointer.args()) - ); - - case PatioDataPtrToInt dataPtrToInt -> - treeList( - treeIdentifier("data-ptr-to-int"), - operandToTree(dataPtrToInt.target()), - operandToTree(dataPtrToInt.value()) - ); - - case PatioIf if_ -> - treeListIndented( - treeIdentifier("if"), - operandsToTree(if_.targets()), - operandToTree(if_.condition()), - blockToTree(if_.trueBody()), - blockToTree(if_.falseBody()) - ); - - case PatioIntAdd intAdd -> - treeList( - treeIdentifier("int-add"), - operandToTree(intAdd.target()), - operandToTree(intAdd.left()), - operandToTree(intAdd.right()) - ); - - case PatioIntEquals intEquals -> - treeList( - treeIdentifier("int-eq"), - operandToTree(intEquals.target()), - operandToTree(intEquals.left()), - operandToTree(intEquals.right()) - ); - - case PatioIntNotEqual intNotEqual -> - treeList( - treeIdentifier("int-ne"), - operandToTree(intNotEqual.target()), - operandToTree(intNotEqual.left()), - operandToTree(intNotEqual.right()) - ); - - - case PatioIntSub intSub -> - treeList( - treeIdentifier("int-sub"), - operandToTree(intSub.target()), - operandToTree(intSub.left()), - operandToTree(intSub.right()) - ); - - case PatioIntToBool intToBool -> - treeList( - treeIdentifier("int-to-bool"), - operandToTree(intToBool.target()), - operandToTree(intToBool.value()) - ); - - case PatioIntToDataPtr intToDataPtr -> - treeList( - treeIdentifier("int-to-data-ptr"), - operandToTree(intToDataPtr.target()), - operandToTree(intToDataPtr.value()) - ); - - case PatioLocalStore localStore -> - treeList( - treeIdentifier("local-store"), - operandToTree(localStore.target()), - operandToTree(localStore.value()) - ); - - case PatioLoop loop -> - treeListIndented( - treeIdentifier("loop"), - instructionsToTree(loop.body()) - ); - - case PatioLoopBreak loopBreak -> - treeList( - treeIdentifier("break") - ); - - case PatioLoopContinue loopContinue -> - treeList( - treeIdentifier("continue") - ); - - case PatioMemoryLoad memoryLoad -> - treeListIndented( - treeIdentifier("memory-load"), - operandToTree(memoryLoad.target()), - treeNamed("pointer", operandToTree(memoryLoad.pointer())), - treeNamed("layout", dataLayoutToTree(memoryLoad.layout())), - treeNamed("offset", treeList( - memoryLoad.offset().stream() - .map(offset -> treeInt(offset)) - .toList() - )) - ); - - case PatioMemoryStore memoryStore -> - treeListIndented( - treeIdentifier("memory-store"), - treeNamed("pointer", operandToTree(memoryStore.pointer())), - treeNamed("layout", dataLayoutToTree(memoryStore.layout())), - treeNamed("offset", treeList( - memoryStore.offset().stream() - .map(offset -> treeInt(offset)) - .toList() - )), - treeNamed("value", operandToTree(memoryStore.value())) - ); - - case PatioResume resume -> - treeList( - treeIdentifier("resume"), - operandToTree(resume.value()) - ); - - case PatioReturn return_ -> - treeList( - treeIdentifier("return"), - operandToTree(return_.value()) - ); - - case PatioReturnVoid returnVoid -> - treeList( - treeIdentifier("return-void") - ); - - case PatioSwitch switch_ -> - treeListIndented( - treeIdentifier("switch"), - operandsToTree(switch_.targets()), - operandToTree(switch_.value()), - treeListIndented( - switch_.cases().stream() - .map(switchCase -> treeListIndented( - treeIdentifier("case"), - treeInt(switchCase.value()), - blockToTree(switchCase.body()) - )) - .toList() - ), - blockToTree(switch_.defaultBody()) - ); - - case PatioTry try_ -> - treeListIndented( - treeIdentifier("try"), - operandsToTree(try_.targets()), - treeListIndented( - try_.catchClauses().stream() - .map(catchClause -> treeListIndented( - treeIdentifier("catch"), - treeString(catchClause.exceptionTypeName()), - operandToTree(catchClause.target()), - blockToTree(catchClause.body()) - )) - .toList() - ), - blockToTree(try_.body()) - ); - - case PatioThrow throw_ -> - treeList( - treeIdentifier("throw"), - treeString(throw_.exceptionTypeName()), - operandToTree(throw_.value()) - ); - - case PatioUnreachable unreachable -> - treeList(treeIdentifier("unreachable")); - - case PatioVarLoad varLoad -> - treeList( - treeIdentifier("var-load"), - operandToTree(varLoad.target()), - operandToTree(varLoad.var()) - ); - - case PatioVarStore varStore -> - treeList( - treeIdentifier("var-store"), - operandToTree(varStore.var()), - operandToTree(varStore.value()) - ); - }; - } - - private static Tree blockToTree(PatioBlock block) { - return treeListIndented( - treeIdentifier("block"), - instructionsToTree(block.body()), - treeNamed( - "results", - treeList( - block.results().stream() - .map(result -> operandToTree(result)) - .toList() - ) - ) - ); - } - - private static Tree localToTree(PatioLocal local) { - var localType = switch (local.localType()) { - case PARAM -> - "param"; - - case VAL -> - "val"; - - case VAR -> - "var"; - }; - - return treeList( - treeIdentifier(localType), - treeString(local.name()), - typeToTree(local.type()) - ); - } - - private static Tree optionalOperandToTree(Optional target) { - if (target.isEmpty()) { - return treeIdentifier("_"); - } else { - return operandToTree(target.get()); - } - } - - private static Tree operandsToTree(List operands) { - return treeList( - operands.stream() - .map(target -> operandToTree(target)) - .toList() - ); - } - - private static Tree operandToTree(PatioOperand operand) { - return switch (operand) { - case PatioBool bool -> - treeList(treeIdentifier("bool"), treeBool(bool.value())); - - case PatioDataPtr dataPtr -> - treeList(treeIdentifier("data-ptr"), treeString(dataPtr.name())); - - case PatioFunctionPtr functionPtr -> - treeList(treeIdentifier("function-ptr"), treeString(functionPtr.name())); - - case PatioInt int_ -> - treeList(treeIdentifier("int"), treeInt(int_.value())); - - case PatioLocalRef localRef -> - treeList(treeIdentifier("local"), treeString(localRef.name())); - }; - } - - private static Tree typeToTree(PatioType type) { - return switch (type) { - case PatioBoolType boolType -> - treeIdentifier("bool"); - - case PatioByteType byteType -> - treeIdentifier("byte"); - - case PatioDataPointerType dataPointerType -> - treeIdentifier("data-ptr"); - - case PatioFunctionPointerType functionPointerType -> - treeIdentifier("function-ptr"); - - case PatioIntType intType -> - treeIdentifier("int"); - - case PatioVoidType voidType -> - treeIdentifier("void"); - }; - } - - private static Tree dataLayoutToTree(PatioDataLayout layout) { - return switch (layout) { - case PatioDataLayoutArray array -> - treeList( - treeIdentifier("array"), - dataLayoutToTree(array.element()), - treeInt(array.size()) - ); - - case PatioDataLayoutBool bool -> - treeIdentifier("bool"); - - case PatioDataLayoutByte byte_ -> - treeIdentifier("byte"); - - case PatioDataLayoutDataPointer dataPointer -> - treeIdentifier("data-ptr"); - - case PatioDataLayoutFunctionPointer functionPointer -> - treeIdentifier("function-ptr"); - - case PatioDataLayoutInt int_ -> - treeIdentifier("int"); - - case PatioDataLayoutStruct struct -> - treeList( - treeIdentifier("struct"), - treeList( - struct.elements().stream() - .map(element -> dataLayoutToTree(element)) - .toList() - ) - ); - }; - } - - private static Tree dataValueToTree(PatioDataValue value) { - return switch (value) { - case PatioDataValueArray array -> - treeList( - treeIdentifier("array"), - dataLayoutToTree(array.elementLayout()), - treeList( - array.elements().stream() - .map(element -> dataValueToTree(element)) - .toList() - ) - ); - - case PatioDataValueBool bool -> - treeList( - treeIdentifier("bool"), - treeIdentifier(bool.value() ? "true" : "false") - ); - - case PatioDataValueByte byte_ -> - treeList( - treeIdentifier("byte"), - treeIdentifier(String.format("0x%02x", byte_.value())) - ); - - case PatioDataValueDataPointerNull dataPointerNull -> - treeList(treeIdentifier("data-ptr"), treeIdentifier("null")); - - case PatioDataValueInt int_ -> - treeList( - treeIdentifier("int"), - treeIdentifier(Integer.toString(int_.value())) - ); - - case PatioDataValueStruct struct -> - treeList( - treeIdentifier("struct"), - treeList( - struct.elements().stream() - .map(element -> dataValueToTree(element)) - .toList() - ) - ); - }; - } - - private static Tree visibilityToTree(PatioVisibility visibility) { - return treeIdentifier(switch (visibility) { - case PRIVATE -> "private"; - case PUBLIC -> "public"; - }); - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/PatioVisibility.java b/src/main/java/org/shedlang/compiler/patio/ast/PatioVisibility.java deleted file mode 100644 index ee5b555f..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/PatioVisibility.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.shedlang.compiler.patio.ast; - -public enum PatioVisibility { - PRIVATE, - PUBLIC, -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAllocHeap.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAllocHeap.java deleted file mode 100644 index 65f3b4c5..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAllocHeap.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.types.PatioDataLayout; -import org.shedlang.compiler.sources.Source; - -import java.util.List; - -/** - * Allocate space on the heap for the given data layout, and store the pointer - * to the allocated memory in the target local. - */ -public record PatioAllocHeap( - PatioLocalRef target, - PatioDataLayout layout, - List gcChildrenOffset, - int gcChildrenCount, - Source source -) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return false; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAllocStack.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAllocStack.java deleted file mode 100644 index 2473b679..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAllocStack.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.types.PatioDataLayout; -import org.shedlang.compiler.sources.Source; - -/** - * Allocate space for the given data layout on the memory stack for the current - * call frame, and store the pointer to the allocated memory in the target - * local. - */ -public record PatioAllocStack( - PatioLocalRef target, - PatioDataLayout layout, - Source source -) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return false; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioBlock.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioBlock.java deleted file mode 100644 index ce4a2407..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioBlock.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.sources.Source; -import org.shedlang.compiler.util.Lists; - -import java.util.List; - -/** - * Execute the instructions in the body of the block. The results may be used in - * the parent scope, but any other variables (as distinct from values) are no - * longer in use. - */ -public record PatioBlock( - List body, - List results, - Source source -) implements PatioInstruction { - public PatioBlock addInstruction(PatioInstruction instruction) { - return new PatioBlock( - Lists.concat(this.body, List.of(instruction)), - this.results, - this.source - ); - } - - @Override - public boolean isBlockTerminator() { - return false; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioBoolToInt.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioBoolToInt.java deleted file mode 100644 index d3b6baf1..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioBoolToInt.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.sources.Source; - -public record PatioBoolToInt( - PatioLocalRef target, - PatioOperand value, - Source source -) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return false; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioCall.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioCall.java deleted file mode 100644 index f920c319..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioCall.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.sources.Source; - -import java.util.List; -import java.util.Optional; - -/** - * Call the function with the given name, and store the returned value in the - * target local. - */ -public record PatioCall( - Optional target, - String functionName, - List args, - Source source -) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return false; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioCallPointer.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioCallPointer.java deleted file mode 100644 index 5ff10331..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioCallPointer.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.sources.Source; - -import java.util.List; - -/** - * Call the function pointed to by the function pointer with the given - * arguments, and store the returned value in the target local. - */ -public record PatioCallPointer( - PatioLocalRef target, - PatioOperand functionPointer, - List args, - Source source -) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return false; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioCatchClause.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioCatchClause.java deleted file mode 100644 index 05af2450..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioCatchClause.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.sources.Source; - -/** - * A catch clause can accept an exception of a given type. If executed, it will - * stored the value of the exception in the given target, and then execute the - * body. - */ -public record PatioCatchClause( - String exceptionTypeName, - PatioLocalRef target, - PatioBlock body, - Source source -) { -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioDataPtrToInt.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioDataPtrToInt.java deleted file mode 100644 index 3d21f005..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioDataPtrToInt.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.sources.Source; - -public record PatioDataPtrToInt( - PatioLocalRef target, - PatioOperand value, - Source source -) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return false; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIf.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIf.java deleted file mode 100644 index fc5a0dc7..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIf.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.sources.Source; - -import java.util.List; - -/** - * If the condition is true, execute the instructions in the "true" body, - * otherwise execute the instructions in the "false" body. - *

- * Each block must have the same number of results as targets. Each result is - * assigned to the target with the same index. - */ -public record PatioIf( - List targets, - PatioOperand condition, - PatioBlock trueBody, - PatioBlock falseBody, - Source source -) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return false; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioInstruction.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioInstruction.java deleted file mode 100644 index 088282d4..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioInstruction.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.sources.Source; - -public sealed interface PatioInstruction permits PatioAllocHeap, PatioAllocStack, PatioBlock, PatioBoolToInt, PatioCall, PatioCallPointer, PatioDataPtrToInt, PatioIf, PatioIntAdd, PatioIntEquals, PatioIntNotEqual, PatioIntSub, PatioIntToBool, PatioIntToDataPtr, PatioLocalStore, PatioLoop, PatioLoopBreak, PatioLoopContinue, PatioMemoryLoad, PatioMemoryStore, PatioResume, PatioReturn, PatioReturnVoid, PatioSwitch, PatioThrow, PatioTry, PatioUnreachable, PatioVarLoad, PatioVarStore { - boolean isBlockTerminator(); - Source source(); -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioInstructionBinaryOperation.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioInstructionBinaryOperation.java deleted file mode 100644 index 1737ecf1..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioInstructionBinaryOperation.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; - -public interface PatioInstructionBinaryOperation { - PatioLocalRef target(); - PatioOperand left(); - PatioOperand right(); -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntAdd.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntAdd.java deleted file mode 100644 index fda748c5..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntAdd.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.sources.Source; - -public record PatioIntAdd( - PatioLocalRef target, - PatioOperand left, - PatioOperand right, - Source source -) implements PatioInstructionBinaryOperation, PatioInstruction { - @Override - public boolean isBlockTerminator() { - return false; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntEquals.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntEquals.java deleted file mode 100644 index a261d854..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntEquals.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.sources.Source; - -public record PatioIntEquals( - PatioLocalRef target, - PatioOperand left, - PatioOperand right, - Source source -) implements PatioInstructionBinaryOperation, PatioInstruction { - @Override - public boolean isBlockTerminator() { - return false; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntNotEqual.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntNotEqual.java deleted file mode 100644 index cc426c8e..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntNotEqual.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.sources.Source; - -/** - * Compare the left and right operands. If they are equal, store false in the - * target, otherwise store true in the target. - */ -public record PatioIntNotEqual( - PatioLocalRef target, - PatioOperand left, - PatioOperand right, - Source source -) implements PatioInstructionBinaryOperation, PatioInstruction { - @Override - public boolean isBlockTerminator() { - return false; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntSub.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntSub.java deleted file mode 100644 index 35aa51a9..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntSub.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.sources.Source; - -/** - * Calculate the left operand minus the right operand, and store the result in - * the target. - */ -public record PatioIntSub( - PatioLocalRef target, - PatioOperand left, - PatioOperand right, - Source source -) implements PatioInstructionBinaryOperation, PatioInstruction { - @Override - public boolean isBlockTerminator() { - return false; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntToBool.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntToBool.java deleted file mode 100644 index fe5205ed..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntToBool.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.sources.Source; - -public record PatioIntToBool( - PatioLocalRef target, - PatioOperand value, - Source source -) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return false; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntToDataPtr.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntToDataPtr.java deleted file mode 100644 index bf66c616..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntToDataPtr.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.sources.Source; - -public record PatioIntToDataPtr( - PatioLocalRef target, - PatioOperand value, - Source source -) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return false; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLocalStore.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLocalStore.java deleted file mode 100644 index 6c4b4ba9..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLocalStore.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.sources.Source; - -/** - * Store the given value in the target local. - */ -public record PatioLocalStore( - PatioLocalRef target, - PatioOperand value, - Source source -) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return false; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLoop.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLoop.java deleted file mode 100644 index d849fa8c..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLoop.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.sources.Source; - -import java.util.List; - -/** - * Execute the body. The continue instruction can jump back to the - * start of the body. The break instruction can jump to the end of - * the body. - */ -public record PatioLoop( - List body, - Source source -) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return false; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLoopBreak.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLoopBreak.java deleted file mode 100644 index 2f4ed046..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLoopBreak.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.sources.Source; - -/** - * Jump to the end of the enclosing loop instruction's body. - */ -public record PatioLoopBreak(Source source) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return true; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLoopContinue.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLoopContinue.java deleted file mode 100644 index 7d6eeaaf..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLoopContinue.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.sources.Source; - -/** - * Jump to the start of the enclosing loop instruction's body. - */ -public record PatioLoopContinue(Source source) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return true; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryLoad.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryLoad.java deleted file mode 100644 index 3339b7e2..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryLoad.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.patio.ast.types.PatioDataLayout; -import org.shedlang.compiler.sources.Source; - -import java.util.List; - -/** - * Load the value at the given offset from the given pointer and store it in the - * target local. - */ -public record PatioMemoryLoad( - PatioLocalRef target, - PatioOperand pointer, - PatioDataLayout layout, - List offset, - Source source -) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return false; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryStore.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryStore.java deleted file mode 100644 index 3bff3fe6..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryStore.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.patio.ast.types.PatioDataLayout; -import org.shedlang.compiler.sources.Source; - -import java.util.List; - -/** - * Store the given value at the given offset from the given pointer. - */ -public record PatioMemoryStore( - PatioOperand pointer, - PatioDataLayout layout, - List offset, - PatioOperand value, - Source source -) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return false; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioResume.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioResume.java deleted file mode 100644 index fca36a7f..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioResume.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.sources.Source; - -/** - * Return with the given value from the effect handler method back to the effect - * call. - */ -public record PatioResume(PatioOperand value, Source source) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return true; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioReturn.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioReturn.java deleted file mode 100644 index 355715c2..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioReturn.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.sources.Source; - -/** - * Return with the given value from the current function. - */ -public record PatioReturn(PatioOperand value, Source source) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return true; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioReturnVoid.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioReturnVoid.java deleted file mode 100644 index 2d3001af..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioReturnVoid.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.sources.Source; - -/** - * Return with no value from the current function. - */ -public record PatioReturnVoid(Source source) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return true; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioSwitch.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioSwitch.java deleted file mode 100644 index 14220320..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioSwitch.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.sources.Source; - -import java.util.List; - -/** - * Find a case with a value matching that of the instruction's value. If such a - * case is found, execute the body of that case, otherwise execute the default - * body. - *

- * Each block must have the same number of results as targets. Each result - * is assigned to the target with the same index. - */ -public record PatioSwitch( - List targets, - PatioOperand value, - List cases, - PatioBlock defaultBody, - Source source -) implements PatioInstruction { - public record Case(int value, PatioBlock body, Source source) { - } - - @Override - public boolean isBlockTerminator() { - return true; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioThrow.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioThrow.java deleted file mode 100644 index 10c627a6..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioThrow.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.sources.Source; - -/** - * Search the stack for an exception handler with a catch clause matching the - * thrown exception type. Unwind the stack up to and including this exception - * handler, and run the body of the catch clause. If no such exception handler - * is found, the process should abort. - */ -public record PatioThrow( - String exceptionTypeName, - PatioOperand value, - Source source -) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return true; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioTry.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioTry.java deleted file mode 100644 index 4eab249c..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioTry.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.sources.Source; - -import java.util.List; - -/** - * Push an exception handler with the given catch clauses onto the control flow - * stack, and then execute the instructions in its body. - *

- * If the exception handler catches an exception, the body of the corresponding - * is executed instead. - *

- * Each block (that is, the body of the try and the body of each catch clause) - * must have the same number of results as targets. Each result is assigned to - * the target with the same index. - */ -public record PatioTry( - List targets, - List catchClauses, - PatioBlock body, - Source source -) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return false; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioUnreachable.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioUnreachable.java deleted file mode 100644 index 20f990cb..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioUnreachable.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.sources.Source; - -/** - * Unreachable instructions have undefined behaviour, and are used to indicate - * that an instruction sequence is unreachable. - */ -public record PatioUnreachable(Source source) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return true; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioVarLoad.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioVarLoad.java deleted file mode 100644 index 6169ff18..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioVarLoad.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.sources.Source; - -/** - * Load the value from the given var and store it in the target local. - */ -public record PatioVarLoad( - PatioLocalRef target, - PatioLocalRef var, - Source source -) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return false; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioVarStore.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioVarStore.java deleted file mode 100644 index 51e4993f..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioVarStore.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.shedlang.compiler.patio.ast.instructions; - -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.sources.Source; - -/** - * Store the given value in the target var. - */ -public record PatioVarStore( - PatioLocalRef var, - PatioOperand value, - Source source -) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return false; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/operands/PatioBool.java b/src/main/java/org/shedlang/compiler/patio/ast/operands/PatioBool.java deleted file mode 100644 index c39c17d3..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/operands/PatioBool.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.shedlang.compiler.patio.ast.operands; - -public record PatioBool(boolean value) implements PatioOperand { -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/operands/PatioDataPtr.java b/src/main/java/org/shedlang/compiler/patio/ast/operands/PatioDataPtr.java deleted file mode 100644 index 27d9333b..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/operands/PatioDataPtr.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.shedlang.compiler.patio.ast.operands; - -public record PatioDataPtr(String name) implements PatioOperand { -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/operands/PatioFunctionPtr.java b/src/main/java/org/shedlang/compiler/patio/ast/operands/PatioFunctionPtr.java deleted file mode 100644 index 87b4dd19..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/operands/PatioFunctionPtr.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.shedlang.compiler.patio.ast.operands; - -public record PatioFunctionPtr(String name) implements PatioOperand { -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/operands/PatioInt.java b/src/main/java/org/shedlang/compiler/patio/ast/operands/PatioInt.java deleted file mode 100644 index 0a19de4e..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/operands/PatioInt.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.shedlang.compiler.patio.ast.operands; - -public record PatioInt(int value) implements PatioOperand { -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/operands/PatioLocalRef.java b/src/main/java/org/shedlang/compiler/patio/ast/operands/PatioLocalRef.java deleted file mode 100644 index c0a37c9d..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/operands/PatioLocalRef.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.shedlang.compiler.patio.ast.operands; - -import org.shedlang.compiler.patio.ast.operands.PatioOperand; - -public record PatioLocalRef(String name) implements PatioOperand { -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/operands/PatioOperand.java b/src/main/java/org/shedlang/compiler/patio/ast/operands/PatioOperand.java deleted file mode 100644 index ccad9a11..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/operands/PatioOperand.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.shedlang.compiler.patio.ast.operands; - -public sealed interface PatioOperand permits PatioBool, PatioDataPtr, PatioFunctionPtr, PatioInt, PatioLocalRef { - -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioBoolType.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioBoolType.java deleted file mode 100644 index 3415335d..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioBoolType.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -public record PatioBoolType() implements PatioType { - static final PatioBoolType INSTANCE = new PatioBoolType(); -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioByteType.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioByteType.java deleted file mode 100644 index 5159512d..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioByteType.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -public record PatioByteType() implements PatioType { - static final PatioByteType INSTANCE = new PatioByteType(); -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayout.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayout.java deleted file mode 100644 index 72654af1..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayout.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -public sealed interface PatioDataLayout permits PatioDataLayoutArray, PatioDataLayoutBool, PatioDataLayoutByte, PatioDataLayoutDataPointer, PatioDataLayoutFunctionPointer, PatioDataLayoutInt, PatioDataLayoutStruct { -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutArray.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutArray.java deleted file mode 100644 index eec92389..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutArray.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -public record PatioDataLayoutArray(PatioDataLayout element, int size) implements PatioDataLayout { -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutBool.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutBool.java deleted file mode 100644 index bd878387..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutBool.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -public record PatioDataLayoutBool() implements PatioDataLayout { - public static final PatioDataLayoutBool INSTANCE = new PatioDataLayoutBool(); -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutByte.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutByte.java deleted file mode 100644 index 682fa24c..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutByte.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -public record PatioDataLayoutByte() implements PatioDataLayout { - public static final PatioDataLayoutByte INSTANCE = new PatioDataLayoutByte(); -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutDataPointer.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutDataPointer.java deleted file mode 100644 index 4e208641..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutDataPointer.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -public record PatioDataLayoutDataPointer() implements PatioDataLayout { - public static final PatioDataLayoutDataPointer INSTANCE = new PatioDataLayoutDataPointer(); -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutFunctionPointer.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutFunctionPointer.java deleted file mode 100644 index bdcc2f25..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutFunctionPointer.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -public record PatioDataLayoutFunctionPointer() implements PatioDataLayout { - public static final PatioDataLayoutFunctionPointer INSTANCE = new PatioDataLayoutFunctionPointer(); -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutInt.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutInt.java deleted file mode 100644 index 33716fc9..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutInt.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -public record PatioDataLayoutInt() implements PatioDataLayout { - public static final PatioDataLayoutInt INSTANCE = new PatioDataLayoutInt(); -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutStruct.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutStruct.java deleted file mode 100644 index 6834f660..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayoutStruct.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -import java.util.List; - -public record PatioDataLayoutStruct( - List elements -) implements PatioDataLayout { -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayouts.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayouts.java deleted file mode 100644 index ba1dd9d1..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataLayouts.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -import java.util.List; - -public class PatioDataLayouts { - private PatioDataLayouts() { - } - - public static final PatioDataLayout BOOL = PatioDataLayoutBool.INSTANCE; - public static final PatioDataLayout BYTE = PatioDataLayoutByte.INSTANCE; - public static final PatioDataLayout DATA_POINTER = PatioDataLayoutDataPointer.INSTANCE; - public static final PatioDataLayout FUNCTION_POINTER = PatioDataLayoutFunctionPointer.INSTANCE; - public static final PatioDataLayout INT = PatioDataLayoutInt.INSTANCE; - - public static PatioDataLayout array(PatioDataLayout element, int size) { - return new PatioDataLayoutArray(element, size); - } - - public static PatioDataLayout struct(List elements) { - return new PatioDataLayoutStruct(elements); - } - - public static PatioDataLayout fromType(PatioType type) { - return switch (type) { - case PatioBoolType patioBoolType -> - BOOL; - - case PatioByteType patioByteType -> - BYTE; - - case PatioDataPointerType patioDataPointerType -> - DATA_POINTER; - - case PatioFunctionPointerType patioFunctionPointerType -> - FUNCTION_POINTER; - - case PatioIntType patioIntType -> - INT; - - case PatioVoidType patioVoidType -> - throw new UnsupportedOperationException("TODO"); - }; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataPointerType.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataPointerType.java deleted file mode 100644 index d16d0f3a..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataPointerType.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -public record PatioDataPointerType() implements PatioType { - public static final PatioDataPointerType INSTANCE = new PatioDataPointerType(); -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValue.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValue.java deleted file mode 100644 index 0726ba3d..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValue.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -public sealed interface PatioDataValue permits PatioDataValueArray, PatioDataValueBool, PatioDataValueByte, PatioDataValueDataPointerNull, PatioDataValueInt, PatioDataValueStruct { - PatioDataLayout layout(); -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueArray.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueArray.java deleted file mode 100644 index e2681c72..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueArray.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -import java.util.List; - -public record PatioDataValueArray( - PatioDataLayout elementLayout, - List elements -) implements PatioDataValue { - @Override - public PatioDataLayout layout() { - return PatioDataLayouts.array(elementLayout, elements.size()); - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueBool.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueBool.java deleted file mode 100644 index 57ca6851..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueBool.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -public record PatioDataValueBool(boolean value) implements PatioDataValue { - @Override - public PatioDataLayout layout() { - return PatioDataLayouts.BOOL; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueByte.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueByte.java deleted file mode 100644 index 4f300f02..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueByte.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -public record PatioDataValueByte(byte value) implements PatioDataValue { - @Override - public PatioDataLayout layout() { - return PatioDataLayouts.BYTE; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueDataPointerNull.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueDataPointerNull.java deleted file mode 100644 index a305d00c..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueDataPointerNull.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -public record PatioDataValueDataPointerNull() implements PatioDataValue { - @Override - public PatioDataLayout layout() { - return PatioDataLayouts.DATA_POINTER; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueInt.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueInt.java deleted file mode 100644 index 96542f68..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueInt.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -public record PatioDataValueInt(int value) implements PatioDataValue { - @Override - public PatioDataLayout layout() { - return PatioDataLayouts.INT; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueStruct.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueStruct.java deleted file mode 100644 index 279d2a79..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueStruct.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -import java.util.List; - -public record PatioDataValueStruct(List elements) implements PatioDataValue { - @Override - public PatioDataLayout layout() { - return PatioDataLayouts.struct( - elements.stream() - .map(element -> element.layout()) - .toList() - ); - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValues.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValues.java deleted file mode 100644 index 10c09e74..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValues.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -import java.util.List; - -public class PatioDataValues { - private PatioDataValues() {} - - public static PatioDataValue array( - PatioDataLayout elementLayout, - List elements - ) { - return new PatioDataValueArray(elementLayout, elements); - } - - public static PatioDataValue bool(boolean value) { - return new PatioDataValueBool(value); - } - - public static PatioDataValue byte_(int value) { - return new PatioDataValueByte((byte) value); - } - - public static PatioDataValue dataPointerNull() { - return new PatioDataValueDataPointerNull(); - } - - public static PatioDataValue int_(int value) { - return new PatioDataValueInt(value); - } - - public static PatioDataValue struct(List elements) { - return new PatioDataValueStruct(elements); - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioFunctionPointerType.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioFunctionPointerType.java deleted file mode 100644 index 86f0ac51..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioFunctionPointerType.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -public record PatioFunctionPointerType() implements PatioType { - public static final PatioFunctionPointerType INSTANCE = new PatioFunctionPointerType(); -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioIntType.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioIntType.java deleted file mode 100644 index b5312754..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioIntType.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -public record PatioIntType() implements PatioType { - static final PatioIntType INSTANCE = new PatioIntType(); -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioType.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioType.java deleted file mode 100644 index b3a1bfa5..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioType.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -public sealed interface PatioType permits PatioBoolType, PatioByteType, PatioDataPointerType, PatioFunctionPointerType, PatioIntType, PatioVoidType { -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioTypes.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioTypes.java deleted file mode 100644 index edf24ef0..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioTypes.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -public class PatioTypes { - private PatioTypes() { - } - - public static final PatioBoolType BOOL = PatioBoolType.INSTANCE; - public static final PatioByteType BYTE = PatioByteType.INSTANCE; - public static final PatioDataPointerType DATA_POINTER = PatioDataPointerType.INSTANCE; - public static final PatioFunctionPointerType FUNCTION_POINTER = PatioFunctionPointerType.INSTANCE; - public static final PatioIntType INT = PatioIntType.INSTANCE; - public static final PatioVoidType VOID = PatioVoidType.INSTANCE; -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioVoidType.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioVoidType.java deleted file mode 100644 index 359f17e3..00000000 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioVoidType.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.shedlang.compiler.patio.ast.types; - -public record PatioVoidType() implements PatioType { - public static final PatioVoidType INSTANCE = new PatioVoidType(); -} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioAllocHeap.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioAllocHeap.java new file mode 100644 index 00000000..2737a52d --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioAllocHeap.java @@ -0,0 +1,24 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.types.PatioDataLayout; +import org.shedlang.compiler.sources.Source; + +import java.util.List; + +/** + * Allocate space on the heap for the given data layout, and store the pointer + * to the allocated memory in the target local. + */ +public record PatioAllocHeap( + PatioLocalRef target, + PatioDataLayout layout, + List gcChildrenOffset, + int gcChildrenCount, + Source source +) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioAllocStack.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioAllocStack.java new file mode 100644 index 00000000..a028ed1d --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioAllocStack.java @@ -0,0 +1,21 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.types.PatioDataLayout; +import org.shedlang.compiler.sources.Source; + +/** + * Allocate space for the given data layout on the memory stack for the current + * call frame, and store the pointer to the allocated memory in the target + * local. + */ +public record PatioAllocStack( + PatioLocalRef target, + PatioDataLayout layout, + Source source +) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioBlock.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioBlock.java new file mode 100644 index 00000000..5858159f --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioBlock.java @@ -0,0 +1,31 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.sources.Source; +import org.shedlang.compiler.util.Lists; + +import java.util.List; + +/** + * Execute the instructions in the body of the block. The results may be used in + * the parent scope, but any other variables (as distinct from values) are no + * longer in use. + */ +public record PatioBlock( + List body, + List results, + Source source +) implements PatioInstruction { + public PatioBlock addInstruction(PatioInstruction instruction) { + return new PatioBlock( + Lists.concat(this.body, List.of(instruction)), + this.results, + this.source + ); + } + + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioBoolToInt.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioBoolToInt.java new file mode 100644 index 00000000..db01b703 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioBoolToInt.java @@ -0,0 +1,16 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.sources.Source; + +public record PatioBoolToInt( + PatioLocalRef target, + PatioOperand value, + Source source +) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioCall.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioCall.java new file mode 100644 index 00000000..3a97bc34 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioCall.java @@ -0,0 +1,24 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.sources.Source; + +import java.util.List; +import java.util.Optional; + +/** + * Call the function with the given name, and store the returned value in the + * target local. + */ +public record PatioCall( + Optional target, + String functionName, + List args, + Source source +) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioCallPointer.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioCallPointer.java new file mode 100644 index 00000000..64059ef4 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioCallPointer.java @@ -0,0 +1,23 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.sources.Source; + +import java.util.List; + +/** + * Call the function pointed to by the function pointer with the given + * arguments, and store the returned value in the target local. + */ +public record PatioCallPointer( + PatioLocalRef target, + PatioOperand functionPointer, + List args, + Source source +) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioCatchClause.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioCatchClause.java new file mode 100644 index 00000000..aa92bd60 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioCatchClause.java @@ -0,0 +1,17 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.sources.Source; + +/** + * A catch clause can accept an exception of a given type. If executed, it will + * stored the value of the exception in the given target, and then execute the + * body. + */ +public record PatioCatchClause( + String exceptionTypeName, + PatioLocalRef target, + PatioBlock body, + Source source +) { +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioDataPtrToInt.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioDataPtrToInt.java new file mode 100644 index 00000000..55bfc374 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioDataPtrToInt.java @@ -0,0 +1,16 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.sources.Source; + +public record PatioDataPtrToInt( + PatioLocalRef target, + PatioOperand value, + Source source +) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioIf.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioIf.java new file mode 100644 index 00000000..f404291f --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioIf.java @@ -0,0 +1,27 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.sources.Source; + +import java.util.List; + +/** + * If the condition is true, execute the instructions in the "true" body, + * otherwise execute the instructions in the "false" body. + *

+ * Each block must have the same number of results as targets. Each result is + * assigned to the target with the same index. + */ +public record PatioIf( + List targets, + PatioOperand condition, + PatioBlock trueBody, + PatioBlock falseBody, + Source source +) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioInstruction.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioInstruction.java new file mode 100644 index 00000000..8c5860a7 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioInstruction.java @@ -0,0 +1,8 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.sources.Source; + +public sealed interface PatioInstruction permits PatioAllocHeap, PatioAllocStack, PatioBlock, PatioBoolToInt, PatioCall, PatioCallPointer, PatioDataPtrToInt, PatioIf, PatioIntAdd, PatioIntEquals, PatioIntNotEqual, PatioIntSub, PatioIntToBool, PatioIntToDataPtr, PatioLocalStore, PatioLoop, PatioLoopBreak, PatioLoopContinue, PatioMemoryLoad, PatioMemoryStore, PatioResume, PatioReturn, PatioReturnVoid, PatioSwitch, PatioThrow, PatioTry, PatioUnreachable, PatioVarLoad, PatioVarStore { + boolean isBlockTerminator(); + Source source(); +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioInstructionBinaryOperation.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioInstructionBinaryOperation.java new file mode 100644 index 00000000..2098e4be --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioInstructionBinaryOperation.java @@ -0,0 +1,10 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; + +public interface PatioInstructionBinaryOperation { + PatioLocalRef target(); + PatioOperand left(); + PatioOperand right(); +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntAdd.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntAdd.java new file mode 100644 index 00000000..91e90425 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntAdd.java @@ -0,0 +1,17 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.sources.Source; + +public record PatioIntAdd( + PatioLocalRef target, + PatioOperand left, + PatioOperand right, + Source source +) implements PatioInstructionBinaryOperation, PatioInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntEquals.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntEquals.java new file mode 100644 index 00000000..a996fddf --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntEquals.java @@ -0,0 +1,17 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.sources.Source; + +public record PatioIntEquals( + PatioLocalRef target, + PatioOperand left, + PatioOperand right, + Source source +) implements PatioInstructionBinaryOperation, PatioInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntNotEqual.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntNotEqual.java new file mode 100644 index 00000000..c8c1fc81 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntNotEqual.java @@ -0,0 +1,21 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.sources.Source; + +/** + * Compare the left and right operands. If they are equal, store false in the + * target, otherwise store true in the target. + */ +public record PatioIntNotEqual( + PatioLocalRef target, + PatioOperand left, + PatioOperand right, + Source source +) implements PatioInstructionBinaryOperation, PatioInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntSub.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntSub.java new file mode 100644 index 00000000..605705e7 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntSub.java @@ -0,0 +1,21 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.sources.Source; + +/** + * Calculate the left operand minus the right operand, and store the result in + * the target. + */ +public record PatioIntSub( + PatioLocalRef target, + PatioOperand left, + PatioOperand right, + Source source +) implements PatioInstructionBinaryOperation, PatioInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntToBool.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntToBool.java new file mode 100644 index 00000000..b8b969a2 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntToBool.java @@ -0,0 +1,16 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.sources.Source; + +public record PatioIntToBool( + PatioLocalRef target, + PatioOperand value, + Source source +) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntToDataPtr.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntToDataPtr.java new file mode 100644 index 00000000..81b6bebc --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntToDataPtr.java @@ -0,0 +1,16 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.sources.Source; + +public record PatioIntToDataPtr( + PatioLocalRef target, + PatioOperand value, + Source source +) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioLocalStore.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioLocalStore.java new file mode 100644 index 00000000..2b971642 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioLocalStore.java @@ -0,0 +1,19 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.sources.Source; + +/** + * Store the given value in the target local. + */ +public record PatioLocalStore( + PatioLocalRef target, + PatioOperand value, + Source source +) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioLoop.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioLoop.java new file mode 100644 index 00000000..650b1108 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioLoop.java @@ -0,0 +1,20 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.sources.Source; + +import java.util.List; + +/** + * Execute the body. The continue instruction can jump back to the + * start of the body. The break instruction can jump to the end of + * the body. + */ +public record PatioLoop( + List body, + Source source +) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioLoopBreak.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioLoopBreak.java new file mode 100644 index 00000000..bad43e15 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioLoopBreak.java @@ -0,0 +1,13 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.sources.Source; + +/** + * Jump to the end of the enclosing loop instruction's body. + */ +public record PatioLoopBreak(Source source) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return true; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioLoopContinue.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioLoopContinue.java new file mode 100644 index 00000000..41dcc6fd --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioLoopContinue.java @@ -0,0 +1,13 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.sources.Source; + +/** + * Jump to the start of the enclosing loop instruction's body. + */ +public record PatioLoopContinue(Source source) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return true; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryLoad.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryLoad.java new file mode 100644 index 00000000..9237ca81 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryLoad.java @@ -0,0 +1,25 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.patio.types.PatioDataLayout; +import org.shedlang.compiler.sources.Source; + +import java.util.List; + +/** + * Load the value at the given offset from the given pointer and store it in the + * target local. + */ +public record PatioMemoryLoad( + PatioLocalRef target, + PatioOperand pointer, + PatioDataLayout layout, + List offset, + Source source +) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryStore.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryStore.java new file mode 100644 index 00000000..ccc5c36a --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryStore.java @@ -0,0 +1,23 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.patio.types.PatioDataLayout; +import org.shedlang.compiler.sources.Source; + +import java.util.List; + +/** + * Store the given value at the given offset from the given pointer. + */ +public record PatioMemoryStore( + PatioOperand pointer, + PatioDataLayout layout, + List offset, + PatioOperand value, + Source source +) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioResume.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioResume.java new file mode 100644 index 00000000..6b1838d2 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioResume.java @@ -0,0 +1,15 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.sources.Source; + +/** + * Return with the given value from the effect handler method back to the effect + * call. + */ +public record PatioResume(PatioOperand value, Source source) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return true; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioReturn.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioReturn.java new file mode 100644 index 00000000..fcf84f51 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioReturn.java @@ -0,0 +1,14 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.sources.Source; + +/** + * Return with the given value from the current function. + */ +public record PatioReturn(PatioOperand value, Source source) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return true; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioReturnVoid.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioReturnVoid.java new file mode 100644 index 00000000..b4a8ef3e --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioReturnVoid.java @@ -0,0 +1,13 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.sources.Source; + +/** + * Return with no value from the current function. + */ +public record PatioReturnVoid(Source source) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return true; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioSwitch.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioSwitch.java new file mode 100644 index 00000000..58e67ac8 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioSwitch.java @@ -0,0 +1,31 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.sources.Source; + +import java.util.List; + +/** + * Find a case with a value matching that of the instruction's value. If such a + * case is found, execute the body of that case, otherwise execute the default + * body. + *

+ * Each block must have the same number of results as targets. Each result + * is assigned to the target with the same index. + */ +public record PatioSwitch( + List targets, + PatioOperand value, + List cases, + PatioBlock defaultBody, + Source source +) implements PatioInstruction { + public record Case(int value, PatioBlock body, Source source) { + } + + @Override + public boolean isBlockTerminator() { + return true; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioThrow.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioThrow.java new file mode 100644 index 00000000..86a3afbb --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioThrow.java @@ -0,0 +1,21 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.sources.Source; + +/** + * Search the stack for an exception handler with a catch clause matching the + * thrown exception type. Unwind the stack up to and including this exception + * handler, and run the body of the catch clause. If no such exception handler + * is found, the process should abort. + */ +public record PatioThrow( + String exceptionTypeName, + PatioOperand value, + Source source +) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return true; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioTry.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioTry.java new file mode 100644 index 00000000..98798c60 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioTry.java @@ -0,0 +1,29 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.sources.Source; + +import java.util.List; + +/** + * Push an exception handler with the given catch clauses onto the control flow + * stack, and then execute the instructions in its body. + *

+ * If the exception handler catches an exception, the body of the corresponding + * is executed instead. + *

+ * Each block (that is, the body of the try and the body of each catch clause) + * must have the same number of results as targets. Each result is assigned to + * the target with the same index. + */ +public record PatioTry( + List targets, + List catchClauses, + PatioBlock body, + Source source +) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioUnreachable.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioUnreachable.java new file mode 100644 index 00000000..1550105c --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioUnreachable.java @@ -0,0 +1,14 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.sources.Source; + +/** + * Unreachable instructions have undefined behaviour, and are used to indicate + * that an instruction sequence is unreachable. + */ +public record PatioUnreachable(Source source) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return true; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioVarLoad.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioVarLoad.java new file mode 100644 index 00000000..a03b6766 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioVarLoad.java @@ -0,0 +1,18 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.sources.Source; + +/** + * Load the value from the given var and store it in the target local. + */ +public record PatioVarLoad( + PatioLocalRef target, + PatioLocalRef var, + Source source +) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioVarStore.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioVarStore.java new file mode 100644 index 00000000..f6aad952 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioVarStore.java @@ -0,0 +1,19 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.sources.Source; + +/** + * Store the given value in the target var. + */ +public record PatioVarStore( + PatioLocalRef var, + PatioOperand value, + Source source +) implements PatioInstruction { + @Override + public boolean isBlockTerminator() { + return false; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/operands/PatioBool.java b/src/main/java/org/shedlang/compiler/patio/operands/PatioBool.java new file mode 100644 index 00000000..769667c1 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/operands/PatioBool.java @@ -0,0 +1,4 @@ +package org.shedlang.compiler.patio.operands; + +public record PatioBool(boolean value) implements PatioOperand { +} diff --git a/src/main/java/org/shedlang/compiler/patio/operands/PatioDataPtr.java b/src/main/java/org/shedlang/compiler/patio/operands/PatioDataPtr.java new file mode 100644 index 00000000..9907733b --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/operands/PatioDataPtr.java @@ -0,0 +1,4 @@ +package org.shedlang.compiler.patio.operands; + +public record PatioDataPtr(String name) implements PatioOperand { +} diff --git a/src/main/java/org/shedlang/compiler/patio/operands/PatioFunctionPtr.java b/src/main/java/org/shedlang/compiler/patio/operands/PatioFunctionPtr.java new file mode 100644 index 00000000..b025089e --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/operands/PatioFunctionPtr.java @@ -0,0 +1,4 @@ +package org.shedlang.compiler.patio.operands; + +public record PatioFunctionPtr(String name) implements PatioOperand { +} diff --git a/src/main/java/org/shedlang/compiler/patio/operands/PatioInt.java b/src/main/java/org/shedlang/compiler/patio/operands/PatioInt.java new file mode 100644 index 00000000..4191def2 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/operands/PatioInt.java @@ -0,0 +1,4 @@ +package org.shedlang.compiler.patio.operands; + +public record PatioInt(int value) implements PatioOperand { +} diff --git a/src/main/java/org/shedlang/compiler/patio/operands/PatioLocalRef.java b/src/main/java/org/shedlang/compiler/patio/operands/PatioLocalRef.java new file mode 100644 index 00000000..a3c93021 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/operands/PatioLocalRef.java @@ -0,0 +1,4 @@ +package org.shedlang.compiler.patio.operands; + +public record PatioLocalRef(String name) implements PatioOperand { +} diff --git a/src/main/java/org/shedlang/compiler/patio/operands/PatioOperand.java b/src/main/java/org/shedlang/compiler/patio/operands/PatioOperand.java new file mode 100644 index 00000000..3bd1849c --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/operands/PatioOperand.java @@ -0,0 +1,5 @@ +package org.shedlang.compiler.patio.operands; + +public sealed interface PatioOperand permits PatioBool, PatioDataPtr, PatioFunctionPtr, PatioInt, PatioLocalRef { + +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioBoolType.java b/src/main/java/org/shedlang/compiler/patio/types/PatioBoolType.java new file mode 100644 index 00000000..17bf8d7f --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioBoolType.java @@ -0,0 +1,5 @@ +package org.shedlang.compiler.patio.types; + +public record PatioBoolType() implements PatioType { + static final PatioBoolType INSTANCE = new PatioBoolType(); +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioByteType.java b/src/main/java/org/shedlang/compiler/patio/types/PatioByteType.java new file mode 100644 index 00000000..a9cdd28a --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioByteType.java @@ -0,0 +1,5 @@ +package org.shedlang.compiler.patio.types; + +public record PatioByteType() implements PatioType { + static final PatioByteType INSTANCE = new PatioByteType(); +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayout.java b/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayout.java new file mode 100644 index 00000000..9649cecf --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayout.java @@ -0,0 +1,4 @@ +package org.shedlang.compiler.patio.types; + +public sealed interface PatioDataLayout permits PatioDataLayoutArray, PatioDataLayoutBool, PatioDataLayoutByte, PatioDataLayoutDataPointer, PatioDataLayoutFunctionPointer, PatioDataLayoutInt, PatioDataLayoutStruct { +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutArray.java b/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutArray.java new file mode 100644 index 00000000..4c8ff200 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutArray.java @@ -0,0 +1,4 @@ +package org.shedlang.compiler.patio.types; + +public record PatioDataLayoutArray(PatioDataLayout element, int size) implements PatioDataLayout { +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutBool.java b/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutBool.java new file mode 100644 index 00000000..fab33c47 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutBool.java @@ -0,0 +1,5 @@ +package org.shedlang.compiler.patio.types; + +public record PatioDataLayoutBool() implements PatioDataLayout { + public static final PatioDataLayoutBool INSTANCE = new PatioDataLayoutBool(); +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutByte.java b/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutByte.java new file mode 100644 index 00000000..b8745ddd --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutByte.java @@ -0,0 +1,5 @@ +package org.shedlang.compiler.patio.types; + +public record PatioDataLayoutByte() implements PatioDataLayout { + public static final PatioDataLayoutByte INSTANCE = new PatioDataLayoutByte(); +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutDataPointer.java b/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutDataPointer.java new file mode 100644 index 00000000..76982d45 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutDataPointer.java @@ -0,0 +1,5 @@ +package org.shedlang.compiler.patio.types; + +public record PatioDataLayoutDataPointer() implements PatioDataLayout { + public static final PatioDataLayoutDataPointer INSTANCE = new PatioDataLayoutDataPointer(); +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutFunctionPointer.java b/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutFunctionPointer.java new file mode 100644 index 00000000..8dd8ca75 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutFunctionPointer.java @@ -0,0 +1,5 @@ +package org.shedlang.compiler.patio.types; + +public record PatioDataLayoutFunctionPointer() implements PatioDataLayout { + public static final PatioDataLayoutFunctionPointer INSTANCE = new PatioDataLayoutFunctionPointer(); +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutInt.java b/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutInt.java new file mode 100644 index 00000000..5b738606 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutInt.java @@ -0,0 +1,5 @@ +package org.shedlang.compiler.patio.types; + +public record PatioDataLayoutInt() implements PatioDataLayout { + public static final PatioDataLayoutInt INSTANCE = new PatioDataLayoutInt(); +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutStruct.java b/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutStruct.java new file mode 100644 index 00000000..037a16d0 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayoutStruct.java @@ -0,0 +1,8 @@ +package org.shedlang.compiler.patio.types; + +import java.util.List; + +public record PatioDataLayoutStruct( + List elements +) implements PatioDataLayout { +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayouts.java b/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayouts.java new file mode 100644 index 00000000..c28124aa --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayouts.java @@ -0,0 +1,44 @@ +package org.shedlang.compiler.patio.types; + +import java.util.List; + +public class PatioDataLayouts { + private PatioDataLayouts() { + } + + public static final PatioDataLayout BOOL = PatioDataLayoutBool.INSTANCE; + public static final PatioDataLayout BYTE = PatioDataLayoutByte.INSTANCE; + public static final PatioDataLayout DATA_POINTER = PatioDataLayoutDataPointer.INSTANCE; + public static final PatioDataLayout FUNCTION_POINTER = PatioDataLayoutFunctionPointer.INSTANCE; + public static final PatioDataLayout INT = PatioDataLayoutInt.INSTANCE; + + public static PatioDataLayout array(PatioDataLayout element, int size) { + return new PatioDataLayoutArray(element, size); + } + + public static PatioDataLayout struct(List elements) { + return new PatioDataLayoutStruct(elements); + } + + public static PatioDataLayout fromType(PatioType type) { + return switch (type) { + case PatioBoolType patioBoolType -> + BOOL; + + case PatioByteType patioByteType -> + BYTE; + + case PatioDataPointerType patioDataPointerType -> + DATA_POINTER; + + case PatioFunctionPointerType patioFunctionPointerType -> + FUNCTION_POINTER; + + case PatioIntType patioIntType -> + INT; + + case PatioVoidType patioVoidType -> + throw new UnsupportedOperationException("TODO"); + }; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioDataPointerType.java b/src/main/java/org/shedlang/compiler/patio/types/PatioDataPointerType.java new file mode 100644 index 00000000..d52eb1cf --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioDataPointerType.java @@ -0,0 +1,5 @@ +package org.shedlang.compiler.patio.types; + +public record PatioDataPointerType() implements PatioType { + public static final PatioDataPointerType INSTANCE = new PatioDataPointerType(); +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioDataValue.java b/src/main/java/org/shedlang/compiler/patio/types/PatioDataValue.java new file mode 100644 index 00000000..8f3056a6 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioDataValue.java @@ -0,0 +1,5 @@ +package org.shedlang.compiler.patio.types; + +public sealed interface PatioDataValue permits PatioDataValueArray, PatioDataValueBool, PatioDataValueByte, PatioDataValueDataPointerNull, PatioDataValueInt, PatioDataValueStruct { + PatioDataLayout layout(); +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioDataValueArray.java b/src/main/java/org/shedlang/compiler/patio/types/PatioDataValueArray.java new file mode 100644 index 00000000..6a911432 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioDataValueArray.java @@ -0,0 +1,13 @@ +package org.shedlang.compiler.patio.types; + +import java.util.List; + +public record PatioDataValueArray( + PatioDataLayout elementLayout, + List elements +) implements PatioDataValue { + @Override + public PatioDataLayout layout() { + return PatioDataLayouts.array(elementLayout, elements.size()); + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioDataValueBool.java b/src/main/java/org/shedlang/compiler/patio/types/PatioDataValueBool.java new file mode 100644 index 00000000..9ca7b405 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioDataValueBool.java @@ -0,0 +1,8 @@ +package org.shedlang.compiler.patio.types; + +public record PatioDataValueBool(boolean value) implements PatioDataValue { + @Override + public PatioDataLayout layout() { + return PatioDataLayouts.BOOL; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioDataValueByte.java b/src/main/java/org/shedlang/compiler/patio/types/PatioDataValueByte.java new file mode 100644 index 00000000..69888433 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioDataValueByte.java @@ -0,0 +1,8 @@ +package org.shedlang.compiler.patio.types; + +public record PatioDataValueByte(byte value) implements PatioDataValue { + @Override + public PatioDataLayout layout() { + return PatioDataLayouts.BYTE; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioDataValueDataPointerNull.java b/src/main/java/org/shedlang/compiler/patio/types/PatioDataValueDataPointerNull.java new file mode 100644 index 00000000..214ee35d --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioDataValueDataPointerNull.java @@ -0,0 +1,8 @@ +package org.shedlang.compiler.patio.types; + +public record PatioDataValueDataPointerNull() implements PatioDataValue { + @Override + public PatioDataLayout layout() { + return PatioDataLayouts.DATA_POINTER; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioDataValueInt.java b/src/main/java/org/shedlang/compiler/patio/types/PatioDataValueInt.java new file mode 100644 index 00000000..54053200 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioDataValueInt.java @@ -0,0 +1,8 @@ +package org.shedlang.compiler.patio.types; + +public record PatioDataValueInt(int value) implements PatioDataValue { + @Override + public PatioDataLayout layout() { + return PatioDataLayouts.INT; + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioDataValueStruct.java b/src/main/java/org/shedlang/compiler/patio/types/PatioDataValueStruct.java new file mode 100644 index 00000000..be73e30f --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioDataValueStruct.java @@ -0,0 +1,14 @@ +package org.shedlang.compiler.patio.types; + +import java.util.List; + +public record PatioDataValueStruct(List elements) implements PatioDataValue { + @Override + public PatioDataLayout layout() { + return PatioDataLayouts.struct( + elements.stream() + .map(element -> element.layout()) + .toList() + ); + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioDataValues.java b/src/main/java/org/shedlang/compiler/patio/types/PatioDataValues.java new file mode 100644 index 00000000..fe1f6844 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioDataValues.java @@ -0,0 +1,34 @@ +package org.shedlang.compiler.patio.types; + +import java.util.List; + +public class PatioDataValues { + private PatioDataValues() {} + + public static PatioDataValue array( + PatioDataLayout elementLayout, + List elements + ) { + return new PatioDataValueArray(elementLayout, elements); + } + + public static PatioDataValue bool(boolean value) { + return new PatioDataValueBool(value); + } + + public static PatioDataValue byte_(int value) { + return new PatioDataValueByte((byte) value); + } + + public static PatioDataValue dataPointerNull() { + return new PatioDataValueDataPointerNull(); + } + + public static PatioDataValue int_(int value) { + return new PatioDataValueInt(value); + } + + public static PatioDataValue struct(List elements) { + return new PatioDataValueStruct(elements); + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioFunctionPointerType.java b/src/main/java/org/shedlang/compiler/patio/types/PatioFunctionPointerType.java new file mode 100644 index 00000000..e98940aa --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioFunctionPointerType.java @@ -0,0 +1,5 @@ +package org.shedlang.compiler.patio.types; + +public record PatioFunctionPointerType() implements PatioType { + public static final PatioFunctionPointerType INSTANCE = new PatioFunctionPointerType(); +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioIntType.java b/src/main/java/org/shedlang/compiler/patio/types/PatioIntType.java new file mode 100644 index 00000000..7a7171ef --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioIntType.java @@ -0,0 +1,5 @@ +package org.shedlang.compiler.patio.types; + +public record PatioIntType() implements PatioType { + static final PatioIntType INSTANCE = new PatioIntType(); +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioType.java b/src/main/java/org/shedlang/compiler/patio/types/PatioType.java new file mode 100644 index 00000000..13caa01d --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioType.java @@ -0,0 +1,4 @@ +package org.shedlang.compiler.patio.types; + +public sealed interface PatioType permits PatioBoolType, PatioByteType, PatioDataPointerType, PatioFunctionPointerType, PatioIntType, PatioVoidType { +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioTypes.java b/src/main/java/org/shedlang/compiler/patio/types/PatioTypes.java new file mode 100644 index 00000000..dcfbd08e --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioTypes.java @@ -0,0 +1,13 @@ +package org.shedlang.compiler.patio.types; + +public class PatioTypes { + private PatioTypes() { + } + + public static final PatioBoolType BOOL = PatioBoolType.INSTANCE; + public static final PatioByteType BYTE = PatioByteType.INSTANCE; + public static final PatioDataPointerType DATA_POINTER = PatioDataPointerType.INSTANCE; + public static final PatioFunctionPointerType FUNCTION_POINTER = PatioFunctionPointerType.INSTANCE; + public static final PatioIntType INT = PatioIntType.INSTANCE; + public static final PatioVoidType VOID = PatioVoidType.INSTANCE; +} diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioVoidType.java b/src/main/java/org/shedlang/compiler/patio/types/PatioVoidType.java new file mode 100644 index 00000000..2075a03c --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioVoidType.java @@ -0,0 +1,5 @@ +package org.shedlang.compiler.patio.types; + +public record PatioVoidType() implements PatioType { + public static final PatioVoidType INSTANCE = new PatioVoidType(); +} diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java index 62d374a3..1d35207c 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java @@ -1,12 +1,12 @@ package org.shedlang.compiler.shidtopatio; -import org.shedlang.compiler.patio.ast.PatioCompilationUnit; -import org.shedlang.compiler.patio.ast.PatioVisibility; -import org.shedlang.compiler.patio.ast.instructions.*; -import org.shedlang.compiler.patio.ast.operands.PatioInt; -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.patio.ast.types.PatioTypes; +import org.shedlang.compiler.patio.PatioCompilationUnit; +import org.shedlang.compiler.patio.PatioVisibility; +import org.shedlang.compiler.patio.instructions.*; +import org.shedlang.compiler.patio.operands.PatioInt; +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.patio.types.PatioTypes; import org.shedlang.compiler.shid.ShidNamespace; import org.shedlang.compiler.shid.instructions.*; import org.shedlang.compiler.sources.Source; diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioClosures.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioClosures.java index 5bc55bc3..f1e00e50 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioClosures.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioClosures.java @@ -2,15 +2,15 @@ package org.shedlang.compiler.shidtopatio; import org.shedlang.compiler.ast.typed.FreeVariable; import org.shedlang.compiler.ast.typed.FreeVariables; -import org.shedlang.compiler.patio.ast.PatioVisibility; -import org.shedlang.compiler.patio.ast.instructions.*; -import org.shedlang.compiler.patio.ast.operands.PatioFunctionPtr; -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.patio.ast.types.PatioDataLayout; -import org.shedlang.compiler.patio.ast.types.PatioDataLayouts; -import org.shedlang.compiler.patio.ast.types.PatioType; -import org.shedlang.compiler.patio.ast.types.PatioTypes; +import org.shedlang.compiler.patio.PatioVisibility; +import org.shedlang.compiler.patio.instructions.*; +import org.shedlang.compiler.patio.operands.PatioFunctionPtr; +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.patio.types.PatioDataLayout; +import org.shedlang.compiler.patio.types.PatioDataLayouts; +import org.shedlang.compiler.patio.types.PatioType; +import org.shedlang.compiler.patio.types.PatioTypes; import org.shedlang.compiler.shid.instructions.ShidDefineFunction; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.util.P; diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioContext.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioContext.java index 8870bc17..dc338c83 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioContext.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioContext.java @@ -5,13 +5,13 @@ import org.pcollections.PMap; import org.pcollections.PStack; import org.pcollections.PVector; import org.shedlang.compiler.backends.NameAllocator; -import org.shedlang.compiler.patio.ast.*; -import org.shedlang.compiler.patio.ast.instructions.PatioInstruction; -import org.shedlang.compiler.patio.ast.instructions.PatioLocalStore; -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.patio.ast.types.PatioDataValue; -import org.shedlang.compiler.patio.ast.types.PatioType; +import org.shedlang.compiler.patio.*; +import org.shedlang.compiler.patio.instructions.PatioInstruction; +import org.shedlang.compiler.patio.instructions.PatioLocalStore; +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.patio.types.PatioDataValue; +import org.shedlang.compiler.patio.types.PatioType; import org.shedlang.compiler.shidtopatio.errors.DuplicateCompilationUnitElementName; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.typechecker.TypeInfos; diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioEffects.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioEffects.java index cbb321d6..0b78429a 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioEffects.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioEffects.java @@ -1,17 +1,17 @@ package org.shedlang.compiler.shidtopatio; import org.shedlang.compiler.ast.typed.FreeVariables; -import org.shedlang.compiler.patio.ast.PatioExceptionTypeDefinition; -import org.shedlang.compiler.patio.ast.PatioFunctionDeclaration; -import org.shedlang.compiler.patio.ast.PatioLocal; -import org.shedlang.compiler.patio.ast.instructions.*; -import org.shedlang.compiler.patio.ast.operands.PatioInt; -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.patio.ast.types.PatioDataLayout; -import org.shedlang.compiler.patio.ast.types.PatioDataLayouts; -import org.shedlang.compiler.patio.ast.types.PatioType; -import org.shedlang.compiler.patio.ast.types.PatioTypes; +import org.shedlang.compiler.patio.PatioExceptionTypeDefinition; +import org.shedlang.compiler.patio.PatioFunctionDeclaration; +import org.shedlang.compiler.patio.PatioLocal; +import org.shedlang.compiler.patio.instructions.*; +import org.shedlang.compiler.patio.operands.PatioInt; +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.patio.types.PatioDataLayout; +import org.shedlang.compiler.patio.types.PatioDataLayouts; +import org.shedlang.compiler.patio.types.PatioType; +import org.shedlang.compiler.patio.types.PatioTypes; import org.shedlang.compiler.shid.instructions.ShidDefineFunction; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.sources.Sources; diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioFunctions.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioFunctions.java index e6e7259a..c0a6ad74 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioFunctions.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioFunctions.java @@ -1,9 +1,9 @@ package org.shedlang.compiler.shidtopatio; import org.shedlang.compiler.ast.typed.FreeVariables; -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.types.PatioDataLayout; -import org.shedlang.compiler.patio.ast.types.PatioDataLayouts; +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.ShidDefineFunction; import org.shedlang.compiler.sources.Source; diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioGc.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioGc.java index 7a55f67e..90466728 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioGc.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioGc.java @@ -1,12 +1,12 @@ package org.shedlang.compiler.shidtopatio; -import org.shedlang.compiler.patio.ast.PatioFunctionDeclaration; -import org.shedlang.compiler.patio.ast.PatioLocal; -import org.shedlang.compiler.patio.ast.instructions.PatioAllocHeap; -import org.shedlang.compiler.patio.ast.instructions.PatioCall; -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.patio.ast.types.*; +import org.shedlang.compiler.patio.PatioFunctionDeclaration; +import org.shedlang.compiler.patio.PatioLocal; +import org.shedlang.compiler.patio.instructions.PatioAllocHeap; +import org.shedlang.compiler.patio.instructions.PatioCall; +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.patio.types.*; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.sources.Sources; import org.shedlang.compiler.util.Lists; diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioInts.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioInts.java index 98dfea10..e26a6f27 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioInts.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioInts.java @@ -1,13 +1,13 @@ package org.shedlang.compiler.shidtopatio; -import org.shedlang.compiler.patio.ast.PatioFunctionDeclaration; -import org.shedlang.compiler.patio.ast.PatioLocal; -import org.shedlang.compiler.patio.ast.instructions.PatioCall; -import org.shedlang.compiler.patio.ast.operands.PatioInt; -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.patio.ast.types.PatioType; -import org.shedlang.compiler.patio.ast.types.PatioTypes; +import org.shedlang.compiler.patio.PatioFunctionDeclaration; +import org.shedlang.compiler.patio.PatioLocal; +import org.shedlang.compiler.patio.instructions.PatioCall; +import org.shedlang.compiler.patio.operands.PatioInt; +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.patio.types.PatioType; +import org.shedlang.compiler.patio.types.PatioTypes; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.sources.Sources; diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioNamespaces.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioNamespaces.java index 68d55634..7a9cc011 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioNamespaces.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioNamespaces.java @@ -1,13 +1,13 @@ package org.shedlang.compiler.shidtopatio; -import org.shedlang.compiler.patio.ast.PatioFunctionDeclaration; -import org.shedlang.compiler.patio.ast.PatioVisibility; -import org.shedlang.compiler.patio.ast.instructions.*; -import org.shedlang.compiler.patio.ast.operands.PatioBool; -import org.shedlang.compiler.patio.ast.operands.PatioDataPtr; -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.patio.ast.types.*; +import org.shedlang.compiler.patio.PatioFunctionDeclaration; +import org.shedlang.compiler.patio.PatioVisibility; +import org.shedlang.compiler.patio.instructions.*; +import org.shedlang.compiler.patio.operands.PatioBool; +import org.shedlang.compiler.patio.operands.PatioDataPtr; +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.patio.types.*; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.sources.Sources; import org.shedlang.compiler.types.NamespaceName; diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioStrings.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioStrings.java index 06cb5855..fee60d76 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioStrings.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioStrings.java @@ -1,15 +1,15 @@ package org.shedlang.compiler.shidtopatio; -import org.shedlang.compiler.patio.ast.PatioDataElementImmutable; -import org.shedlang.compiler.patio.ast.PatioFunctionDeclaration; -import org.shedlang.compiler.patio.ast.PatioLocal; -import org.shedlang.compiler.patio.ast.instructions.PatioCall; -import org.shedlang.compiler.patio.ast.operands.PatioDataPtr; -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.patio.ast.types.PatioDataLayouts; -import org.shedlang.compiler.patio.ast.types.PatioDataValue; -import org.shedlang.compiler.patio.ast.types.PatioDataValues; +import org.shedlang.compiler.patio.PatioDataElementImmutable; +import org.shedlang.compiler.patio.PatioFunctionDeclaration; +import org.shedlang.compiler.patio.PatioLocal; +import org.shedlang.compiler.patio.instructions.PatioCall; +import org.shedlang.compiler.patio.operands.PatioDataPtr; +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.patio.types.PatioDataLayouts; +import org.shedlang.compiler.patio.types.PatioDataValue; +import org.shedlang.compiler.patio.types.PatioDataValues; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.sources.Sources; diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioStructs.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioStructs.java index 7e8159d2..0f18b9e9 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioStructs.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioStructs.java @@ -1,13 +1,13 @@ package org.shedlang.compiler.shidtopatio; import org.shedlang.compiler.ast.typed.FreeVariables; -import org.shedlang.compiler.patio.ast.instructions.*; -import org.shedlang.compiler.patio.ast.operands.PatioInt; -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.patio.ast.types.PatioDataLayout; -import org.shedlang.compiler.patio.ast.types.PatioDataLayouts; -import org.shedlang.compiler.patio.ast.types.PatioTypes; +import org.shedlang.compiler.patio.instructions.*; +import org.shedlang.compiler.patio.operands.PatioInt; +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.patio.types.PatioDataLayout; +import org.shedlang.compiler.patio.types.PatioDataLayouts; +import org.shedlang.compiler.patio.types.PatioTypes; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.shid.instructions.ShidDefineFunction; import org.shedlang.compiler.shid.instructions.ShidDefineStruct; diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioTuples.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioTuples.java index 75815fcb..501badc5 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioTuples.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioTuples.java @@ -1,12 +1,12 @@ package org.shedlang.compiler.shidtopatio; -import org.shedlang.compiler.patio.ast.instructions.*; -import org.shedlang.compiler.patio.ast.operands.PatioInt; -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.patio.ast.types.PatioDataLayout; -import org.shedlang.compiler.patio.ast.types.PatioDataLayouts; -import org.shedlang.compiler.patio.ast.types.PatioTypes; +import org.shedlang.compiler.patio.instructions.*; +import org.shedlang.compiler.patio.operands.PatioInt; +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.patio.types.PatioDataLayout; +import org.shedlang.compiler.patio.types.PatioDataLayouts; +import org.shedlang.compiler.patio.types.PatioTypes; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.util.Lists; diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioTypes.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioTypes.java index 1d6a6567..1288d430 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioTypes.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioTypes.java @@ -1,7 +1,7 @@ package org.shedlang.compiler.shidtopatio; -import org.shedlang.compiler.patio.ast.types.PatioType; -import org.shedlang.compiler.patio.ast.types.PatioTypes; +import org.shedlang.compiler.patio.types.PatioType; +import org.shedlang.compiler.patio.types.PatioTypes; public class ShidToPatioTypes { private ShidToPatioTypes() {} diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioVars.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioVars.java index 1aca893f..b38012f0 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioVars.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioVars.java @@ -1,12 +1,12 @@ package org.shedlang.compiler.shidtopatio; -import org.shedlang.compiler.patio.ast.instructions.PatioMemoryLoad; -import org.shedlang.compiler.patio.ast.instructions.PatioMemoryStore; -import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.patio.ast.operands.PatioOperand; -import org.shedlang.compiler.patio.ast.types.PatioDataLayout; -import org.shedlang.compiler.patio.ast.types.PatioDataLayouts; -import org.shedlang.compiler.patio.ast.types.PatioTypes; +import org.shedlang.compiler.patio.instructions.PatioMemoryLoad; +import org.shedlang.compiler.patio.instructions.PatioMemoryStore; +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.patio.types.PatioDataLayout; +import org.shedlang.compiler.patio.types.PatioDataLayouts; +import org.shedlang.compiler.patio.types.PatioTypes; import org.shedlang.compiler.sources.Source; import java.util.List; -- cgit v1.2.3