include "sources.fbs"; namespace Patio; // == Data layouts == union PatioDataLayoutValue { PatioDataLayoutArray, PatioDataLayoutBool, PatioDataLayoutByte, PatioDataLayoutDataPtr, PatioDataLayoutFunctionPtr, PatioDataLayoutInt, PatioDataLayoutInt32, PatioDataLayoutStruct, } table PatioDataLayout { value:PatioDataLayoutValue (required); } table PatioDataLayoutArray { element:PatioDataLayout (required); size:uint; } table PatioDataLayoutBool { } table PatioDataLayoutByte { } table PatioDataLayoutDataPtr { } table PatioDataLayoutFunctionPtr { } table PatioDataLayoutInt { } table PatioDataLayoutInt32 { } table PatioDataLayoutStruct { elements:[PatioDataLayout] (required); } // == Data ptr values == union PatioDataPtrValueValue { PatioDataPtrValueDataElement, PatioDataPtrValueNull, } table PatioDataPtrValue { value:PatioDataPtrValueValue (required); } table PatioDataPtrValueDataElement { name:string (required); } table PatioDataPtrValueNull { } // == Int values == union PatioIntValueValue { PatioIntValueByteOffsetOf, PatioIntValueByteSizeOf, PatioIntValueLiteral, } table PatioIntValue { value:PatioIntValueValue (required); } table PatioIntValueByteOffsetOf { layout:PatioDataLayout (required); element_offsets:[uint] (required); } table PatioIntValueByteSizeOf { layout:PatioDataLayout (required); } table PatioIntValueLiteral { value:int; } // == Data values == union PatioDataValueValue { PatioDataValueArray, PatioDataValueBool, PatioDataValueByte, PatioDataValueDataPtr, PatioDataValueInt, PatioDataValueInt32, PatioDataValueStruct, } table PatioDataValue { value:PatioDataValueValue (required); } table PatioDataValueArray { element_layout:PatioDataLayout (required); elements:[PatioDataValue] (required); } table PatioDataValueBool { value:bool; } table PatioDataValueByte { value:uint; } table PatioDataValueDataPtr { value:PatioDataPtrValue (required); } table PatioDataValueInt { value:PatioIntValue (required); } table PatioDataValueInt32 { value:PatioIntValue (required); } table PatioDataValueStruct { elements:[PatioDataValue] (required); } // == Types == union PatioTypeValue { PatioBoolType, PatioByteType, PatioDataPtrType, PatioFunctionPtrType, PatioIntType, PatioInt32Type, } table PatioType { value:PatioTypeValue (required); } table PatioBoolType { } table PatioByteType { } table PatioDataPtrType { } table PatioFunctionPtrType { } table PatioIntType { } table PatioInt32Type { } // == Operands == union PatioOperandValue { PatioBoolConst, PatioByteConst, PatioDataPtrConst, PatioFunctionPtrConst, PatioIntConst, PatioInt32Const, PatioLocalRef, } table PatioOperand { value:PatioOperandValue (required); } table PatioBoolConst { value:bool; } table PatioByteConst { value:uint; } table PatioDataPtrConst { value:PatioDataPtrValue (required); } table PatioFunctionPtrConst { name:string (required); } table PatioIntConst { value:PatioIntValue (required); } table PatioInt32Const { value:PatioIntValue (required); } table PatioLocalRef { name:string (required); } // == Instructions == union PatioInstructionValue { PatioBlock, PatioBoolToInt, PatioCall, PatioCallPointer, PatioDataPtrToInt, PatioIf, PatioIntAdd, PatioIntEquals, PatioIntNotEqual, PatioIntSub, PatioIntToBool, PatioIntToDataPtr, PatioLocalStore, PatioLoop, PatioLoopBreak, PatioLoopContinue, PatioMemoryLoad, PatioMemoryStore, PatioReturn, PatioSwitch, PatioThrow, PatioTry, PatioUnreachable, PatioVarLoad, PatioVarStore, } table PatioInstruction { value:PatioInstructionValue (required); } table PatioBlock { source:Sources.Source (required); body:[PatioInstruction] (required); results:[PatioOperand] (required); } table PatioBoolToInt { source:Sources.Source (required); destination:PatioLocalRef (required); value:PatioOperand (required); } table PatioCall { source:Sources.Source (required); destinations:[PatioLocalRef] (required); function_name:string (required); args:[PatioOperand] (required); } table PatioCallPointer { source:Sources.Source (required); destinations:[PatioLocalRef] (required); function_pointer:PatioOperand (required); args:[PatioOperand] (required); } table PatioDataPtrToInt { source:Sources.Source (required); destination:PatioLocalRef (required); value:PatioOperand (required); } table PatioIf { source:Sources.Source (required); destinations:[PatioLocalRef] (required); condition:PatioOperand (required); true_body:PatioBlock (required); false_body:PatioBlock (required); } table PatioIntAdd { source:Sources.Source (required); destination:PatioLocalRef (required); left:PatioOperand (required); right:PatioOperand (required); } table PatioIntEquals { source:Sources.Source (required); destination:PatioLocalRef (required); left:PatioOperand (required); right:PatioOperand (required); } table PatioIntNotEqual { source:Sources.Source (required); destination:PatioLocalRef (required); left:PatioOperand (required); right:PatioOperand (required); } table PatioIntSub { source:Sources.Source (required); destination:PatioLocalRef (required); left:PatioOperand (required); right:PatioOperand (required); } table PatioIntToBool { source:Sources.Source (required); destination:PatioLocalRef (required); value:PatioOperand (required); } table PatioIntToDataPtr { source:Sources.Source (required); destination:PatioLocalRef (required); value:PatioOperand (required); } table PatioLocalStore { source:Sources.Source (required); destination:PatioLocalRef (required); value:PatioOperand (required); } table PatioLoop { source:Sources.Source (required); body:[PatioInstruction] (required); } table PatioLoopBreak { source:Sources.Source (required); } table PatioLoopContinue { source:Sources.Source (required); } table PatioMemoryLoad { source:Sources.Source (required); destination:PatioLocalRef (required); pointer:PatioOperand (required); layout:PatioDataLayout (required); element_offsets:[uint] (required); } table PatioMemoryStore { source:Sources.Source (required); pointer:PatioOperand (required); layout:PatioDataLayout (required); element_offsets:[uint] (required); value:PatioOperand (required); } table PatioReturn { source:Sources.Source (required); values:[PatioOperand] (required); } table PatioSwitch { source:Sources.Source (required); destinations:[PatioLocalRef] (required); value:PatioOperand (required); cases:[PatioSwitchCase] (required); default_body:PatioBlock (required); } table PatioSwitchCase { source:Sources.Source (required); value:uint; body:PatioBlock (required); } table PatioThrow { source:Sources.Source (required); exception_type_name:string (required); value:PatioOperand (required); } table PatioTry { source:Sources.Source (required); destinations:[PatioLocalRef] (required); catch_clauses:[PatioCatchClause] (required); body:PatioBlock (required); } table PatioCatchClause { source:Sources.Source (required); exception_type_name:string (required); destination:PatioLocalRef (required); body:PatioBlock (required); } table PatioUnreachable { source:Sources.Source (required); } table PatioVarLoad { source:Sources.Source (required); destination:PatioLocalRef (required); var:PatioLocalRef (required); } table PatioVarStore { source:Sources.Source (required); var:PatioLocalRef (required); value:PatioOperand (required); } // == Visibility == enum PatioVisibility : int { PRIVATE = 0, PUBLIC = 1, } // == Locals == enum PatioLocalType : int { PARAM = 0, VAL = 1, VAR = 2, } table PatioLocal { name:string (required); type:PatioType (required); local_type:PatioLocalType; } // == Compilation unit elements == union PatioCompilationUnitElementValue { PatioDataElementImmutableDefinition, PatioDataElementMutableDeclaration, PatioDataElementMutableDefinition, PatioExceptionTypeDefinition, PatioFunctionDeclaration, PatioFunctionDefinition, } table PatioCompilationUnitElement { value:PatioCompilationUnitElementValue (required); } table PatioDataElementImmutableDefinition { source:Sources.Source (required); name:string (required); visibility:PatioVisibility; value:PatioDataValue (required); } table PatioDataElementMutableDeclaration { source:Sources.Source (required); name:string (required); layout:PatioDataLayout (required); } table PatioDataElementMutableDefinition { source:Sources.Source (required); name:string (required); visibility:PatioVisibility; initial_value:PatioDataValue (required); } table PatioExceptionTypeDefinition { source:Sources.Source (required); name:string (required); value_type:PatioType (required); } table PatioFunctionDeclaration { source:Sources.Source (required); name:string (required); params:[PatioLocal] (required); return_types:[PatioType] (required); } table PatioFunctionDefinition { source:Sources.Source (required); name:string (required); visibility:PatioVisibility; locals:[PatioLocal] (required); return_types:[PatioType] (required); body:[PatioInstruction] (required); } // == Compilation unit == table PatioCompilationUnit { source:Sources.Source (required); elements:[PatioCompilationUnitElement] (required); } root_type PatioCompilationUnit;