diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-31 14:45:04 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-31 15:22:40 +0100 |
| commit | 91860485774924e82da9b0774179d4c3c8da810a (patch) | |
| tree | e06f52f147502e80aea139c20adac706479cb7ea | |
| parent | 410fff7b7ecf6f36a0a46ab1d90553169e3728f1 (diff) | |
Use transient-0 instead of flatbuffersmain
38 files changed, 2856 insertions, 5036 deletions
diff --git a/flatbuffers/patio.fbs b/flatbuffers/patio.fbs deleted file mode 100644 index e8c91892..00000000 --- a/flatbuffers/patio.fbs +++ /dev/null @@ -1,503 +0,0 @@ -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; diff --git a/flatbuffers/sources.fbs b/flatbuffers/sources.fbs deleted file mode 100644 index 3b797d71..00000000 --- a/flatbuffers/sources.fbs +++ /dev/null @@ -1,28 +0,0 @@ -namespace Sources; - -union SourceValue { - NullSource, - RuntimeSource, - FileFragmentSource, -} - -table Source { - value:SourceValue (required); -} - -table NullSource { -} - -table RuntimeSource { -} - -table FileFragmentSource { - source_text:SourceText; - start_character_index:uint; - end_character_index:uint; -} - -table SourceText { - name:string (required); - contents:string (required); -} diff --git a/hobgoblin/hobgoblin.json5 b/hobgoblin/hobgoblin.json5 index 365c19a6..489ad4d5 100644 --- a/hobgoblin/hobgoblin.json5 +++ b/hobgoblin/hobgoblin.json5 @@ -14,7 +14,11 @@ generators: [ { generator: "java-transient-0", - path: "../src/gen/java", + path: "../src/transient-0/java", + }, + { + generator: "rust-types", + path: "../patio-to-cranelift/src/gen", }, { generator: "rust-transient-0", diff --git a/hobgoblin/src/patio/instructions.hob b/hobgoblin/src/patio/instructions.hob index c6f33976..97571a35 100644 --- a/hobgoblin/src/patio/instructions.hob +++ b/hobgoblin/src/patio/instructions.hob @@ -157,6 +157,7 @@ struct PatioMemoryLoad { field destination: PatioLocalRef; field pointer: PatioOperand; field layout: PatioDataLayout; + // TODO: should be UInt32 field elementOffsets: List[Int32]; field source: Source; } @@ -165,6 +166,7 @@ struct PatioMemoryLoad { struct PatioMemoryStore { field pointer: PatioOperand; field layout: PatioDataLayout; + // TODO: should be UInt32 field elementOffsets: List[Int32]; field value: PatioOperand; field source: Source; diff --git a/hobgoblin/src/patio/types.hob b/hobgoblin/src/patio/types.hob index 3155e576..2bd2e47a 100644 --- a/hobgoblin/src/patio/types.hob +++ b/hobgoblin/src/patio/types.hob @@ -38,7 +38,7 @@ struct PatioIntType { // == Data layouts == sum PatioDataLayout { - variant PatioDataLayoutArray; + variant PatioDataLayoutArray box; variant PatioDataLayoutBool; variant PatioDataLayoutByte; variant PatioDataLayoutDataPtr; @@ -50,6 +50,7 @@ sum PatioDataLayout { struct PatioDataLayoutArray { field element: PatioDataLayout; + // TODO: should be UInt32 field size: Int32; } diff --git a/hobgoblin/src/patio/values.hob b/hobgoblin/src/patio/values.hob index 0e14cf35..dcd303b8 100644 --- a/hobgoblin/src/patio/values.hob +++ b/hobgoblin/src/patio/values.hob @@ -27,6 +27,7 @@ sum PatioIntValue { /// The offset, in bytes, of an offset in a data layout. struct PatioIntValueByteOffsetOf { field layout: PatioDataLayout; + // TODO: should be UInt32 field elementOffsets: List[Int32]; } @@ -28,12 +28,11 @@ build-runtime: src/gen/java: rm -rf src/gen/java mkdir -p src/gen/java - python3 generate-flatbuffers.py + make hobgoblin .PHONY: patio-to-cranelift -patio-to-cranelift: - flatc-25.12.19 -o patio-to-cranelift/src/gen --rust flatbuffers/* +patio-to-cranelift: hobgoblin cd patio-to-cranelift; cargo fmt && cargo build && cargo test .PHONY: hobgoblin diff --git a/patio-to-cranelift/src/codegen/mod.rs b/patio-to-cranelift/src/codegen/mod.rs index be98a0a3..a9cfab5b 100644 --- a/patio-to-cranelift/src/codegen/mod.rs +++ b/patio-to-cranelift/src/codegen/mod.rs @@ -9,12 +9,10 @@ use crate::{ }, errors::CompileError, patio::{ - compilation_unit::{ - PatioCompilationUnit, PatioCompilationUnitElement, PatioDataElementImmutableDefinition, - PatioDataElementMutableDeclaration, PatioDataElementMutableDefinition, - PatioFunctionDeclaration, PatioFunctionDefinition, PatioLocal, PatioLocalType, - PatioVisibility, - }, + PatioCompilationUnit, PatioCompilationUnitElement, PatioDataElementImmutableDefinition, + PatioDataElementMutableDeclaration, PatioDataElementMutableDefinition, + PatioFunctionDeclaration, PatioFunctionDefinition, PatioLocal, PatioLocalType, + PatioVisibility, instructions::{ PatioBlock, PatioBoolToInt, PatioCall, PatioCallPointer, PatioDataPtrToInt, PatioIf, PatioInstruction, PatioIntAdd, PatioIntEquals, PatioIntNotEqual, PatioIntSub, @@ -23,7 +21,10 @@ use crate::{ PatioUnreachable, PatioVarLoad, PatioVarStore, }, operands::{PatioLocalRef, PatioOperand}, - types::PatioType, + types::{ + PatioBoolType, PatioByteType, PatioDataPtrType, PatioFunctionPtrType, PatioInt32Type, + PatioIntType, PatioType, + }, values::{PatioDataPtrValue, PatioIntValue}, }, }; @@ -84,29 +85,31 @@ fn declare_compilation_unit_element( context: &mut CompilerContext, ) { match element { - PatioCompilationUnitElement::DataElementImmutableDefinition( + PatioCompilationUnitElement::PatioDataElementImmutableDefinition( data_element_immutable_definition, ) => { declare_data_element_immutable_definition(data_element_immutable_definition, context); } - PatioCompilationUnitElement::DataElementMutableDeclaration( + PatioCompilationUnitElement::PatioDataElementMutableDeclaration( data_element_mutable_declaration, ) => { declare_data_element_mutable_declaration(data_element_mutable_declaration, context); } - PatioCompilationUnitElement::DataElementMutableDefinition( + PatioCompilationUnitElement::PatioDataElementMutableDefinition( data_element_mutable_definition, ) => { declare_data_element_mutable_definition(data_element_mutable_definition, context); } - PatioCompilationUnitElement::FunctionDeclaration(function_declaration) => { + PatioCompilationUnitElement::PatioExceptionTypeDefinition(_) => todo!(), + + PatioCompilationUnitElement::PatioFunctionDeclaration(function_declaration) => { declare_function_declaration(function_declaration, context); } - PatioCompilationUnitElement::FunctionDefinition(function_definition) => { + PatioCompilationUnitElement::PatioFunctionDefinition(function_definition) => { declare_function_definition(function_definition, context); } } @@ -117,23 +120,25 @@ fn define_compilation_unit_element( context: &mut CompilerContext, ) { match element { - PatioCompilationUnitElement::DataElementImmutableDefinition( + PatioCompilationUnitElement::PatioDataElementImmutableDefinition( data_element_immutable_definition, ) => { define_data_element_immutable_definition(data_element_immutable_definition, context); } - PatioCompilationUnitElement::DataElementMutableDeclaration(_) => {} + PatioCompilationUnitElement::PatioDataElementMutableDeclaration(_) => {} - PatioCompilationUnitElement::DataElementMutableDefinition( + PatioCompilationUnitElement::PatioDataElementMutableDefinition( data_element_mutable_definition, ) => { define_data_element_mutable_definition(data_element_mutable_definition, context); } - PatioCompilationUnitElement::FunctionDeclaration(_) => {} + PatioCompilationUnitElement::PatioExceptionTypeDefinition(_) => todo!(), - PatioCompilationUnitElement::FunctionDefinition(function_definition) => { + PatioCompilationUnitElement::PatioFunctionDeclaration(_) => {} + + PatioCompilationUnitElement::PatioFunctionDefinition(function_definition) => { define_function_definition(&function_definition, context); } } @@ -254,7 +259,7 @@ fn define_function_definition( for local in &function_definition.locals { let cranelift_type = types::patio_type_to_cranelift_type( - local.type_, + &local.r#type, &function_context.target_triple, ); @@ -284,95 +289,103 @@ fn define_function_definition( fn compile_instruction(instruction: &PatioInstruction, context: &mut CompilerFunctionContext<'_>) { match instruction { - PatioInstruction::Block(block) => { + PatioInstruction::PatioBlock(block) => { compile_block(block, context); } - PatioInstruction::BoolToInt(bool_to_int) => { + PatioInstruction::PatioBoolToInt(bool_to_int) => { compile_bool_to_int(bool_to_int, context); } - PatioInstruction::Call(call) => { + PatioInstruction::PatioCall(call) => { compile_call(call, context); } - PatioInstruction::CallPointer(call_pointer) => { + PatioInstruction::PatioCallPointer(call_pointer) => { compile_call_pointer(call_pointer, context); } - PatioInstruction::DataPtrToInt(data_ptr_to_int) => { + PatioInstruction::PatioDataPtrToInt(data_ptr_to_int) => { compile_data_ptr_to_int(data_ptr_to_int, context); } - PatioInstruction::If(if_) => { + PatioInstruction::PatioIf(if_) => { compile_if(if_, context); } - PatioInstruction::IntAdd(int_add) => { + PatioInstruction::PatioIntAdd(int_add) => { compile_int_add(int_add, context); } - PatioInstruction::IntEquals(int_equals) => { + PatioInstruction::PatioIntEquals(int_equals) => { compile_int_equals(int_equals, context); } - PatioInstruction::IntNotEqual(int_not_equal) => { + PatioInstruction::PatioIntNotEqual(int_not_equal) => { compile_int_not_equal(int_not_equal, context); } - PatioInstruction::IntSub(int_sub) => { + PatioInstruction::PatioIntSub(int_sub) => { compile_int_sub(int_sub, context); } - PatioInstruction::IntToBool(int_to_bool) => { + PatioInstruction::PatioIntToBool(int_to_bool) => { compile_int_to_bool(int_to_bool, context); } - PatioInstruction::IntToDataPtr(int_to_data_ptr) => { + PatioInstruction::PatioIntToDataPtr(int_to_data_ptr) => { compile_int_to_data_ptr(int_to_data_ptr, context); } - PatioInstruction::LocalStore(local_store) => { + PatioInstruction::PatioLocalStore(local_store) => { compile_local_store(local_store, context); } - PatioInstruction::Loop(loop_) => { + PatioInstruction::PatioLoop(loop_) => { compile_loop(loop_, context); } - PatioInstruction::LoopBreak(loop_break) => { + PatioInstruction::PatioLoopBreak(loop_break) => { compile_loop_break(loop_break, context); } - PatioInstruction::LoopContinue(loop_continue) => { + PatioInstruction::PatioLoopContinue(loop_continue) => { compile_loop_continue(loop_continue, context); } - PatioInstruction::MemoryLoad(memory_load) => { + PatioInstruction::PatioMemoryLoad(memory_load) => { compile_memory_load(memory_load, context); } - PatioInstruction::MemoryStore(memory_store) => { + PatioInstruction::PatioMemoryStore(memory_store) => { compile_memory_store(memory_store, context); } - PatioInstruction::Return(return_) => { + PatioInstruction::PatioReturn(return_) => { compile_return(return_, context); } - PatioInstruction::Switch(switch) => { + PatioInstruction::PatioSwitch(switch) => { compile_switch(switch, context); } - PatioInstruction::Unreachable(unreachable) => { + PatioInstruction::PatioThrow(_) => { + todo!(); + } + + PatioInstruction::PatioTry(_) => { + todo!(); + } + + PatioInstruction::PatioUnreachable(unreachable) => { compile_unreachable(unreachable, context); } - PatioInstruction::VarLoad(var_load) => { + PatioInstruction::PatioVarLoad(var_load) => { compile_var_load(var_load, context); } - PatioInstruction::VarStore(var_store) => { + PatioInstruction::PatioVarStore(var_store) => { compile_var_store(var_store, context); } } @@ -640,7 +653,7 @@ fn compile_memory_load(memory_load: &PatioMemoryLoad, context: &mut CompilerFunc let value_layout = types::data_layout_element_at(&memory_load.layout, &memory_load.element_offsets); let value_type = types::data_layout_to_type(value_layout); - let cranelift_type = types::patio_type_to_cranelift_type(value_type, &context.target_triple); + let cranelift_type = types::patio_type_to_cranelift_type(&value_type, &context.target_triple); let cranelift_pointer = compile_operand(&memory_load.pointer, context); let cranelift_flags = cranelift_codegen::ir::MemFlags::new(); @@ -719,7 +732,7 @@ fn compile_switch(switch: &PatioSwitch, context: &mut CompilerFunctionContext<'_ // Create the jump itself. let mut cranelift_switch = cranelift::frontend::Switch::new(); for (case, case_block) in switch.cases.iter().zip(&case_blocks) { - cranelift_switch.set_entry(case.value.into(), *case_block); + cranelift_switch.set_entry(case.value.try_into().unwrap(), *case_block); } cranelift_switch.emit( &mut context.function_builder, @@ -796,8 +809,8 @@ fn compile_operand( context: &mut CompilerFunctionContext<'_>, ) -> cranelift::prelude::Value { match operand { - PatioOperand::BoolConst(value) => { - let integer_value = if *value { 1 } else { 0 }; + PatioOperand::PatioBoolConst(bool_const) => { + let integer_value = if bool_const.value { 1 } else { 0 }; context .function_builder @@ -805,10 +818,12 @@ fn compile_operand( .iconst(types::CRANELIFT_BOOL_TYPE, integer_value) } - PatioOperand::DataPtrConst(value) => compile_data_ptr_value(&value, context), + PatioOperand::PatioDataPtrConst(data_ptr_const) => { + compile_data_ptr_value(&data_ptr_const.value, context) + } - PatioOperand::FunctionPtrConst(name) => { - let func_ref = context.func_id(name); + PatioOperand::PatioFunctionPtrConst(function_ptr_const) => { + let func_ref = context.func_id(&function_ptr_const.name); let function_ptr_type = context.pointer_type(); context @@ -817,16 +832,16 @@ fn compile_operand( .func_addr(function_ptr_type, func_ref) } - PatioOperand::IntConst(value) => { + PatioOperand::PatioIntConst(int_const) => { let cranelift_int_type = types::cranelift_int_type(&context.target_triple); - compile_int_value(&value, cranelift_int_type, context) + compile_int_value(&int_const.value, cranelift_int_type, context) } - PatioOperand::Int32Const(value) => { - compile_int_value(&value, types::CRANELIFT_INT_32_TYPE, context) + PatioOperand::PatioInt32Const(int_32_const) => { + compile_int_value(&int_32_const.value, types::CRANELIFT_INT_32_TYPE, context) } - PatioOperand::LocalRef(local_ref) => context.local_load(&local_ref.name), + PatioOperand::PatioLocalRef(local_ref) => context.local_load(&local_ref.name), _ => { todo!("Unhandled operand: {operand:?}",) @@ -841,15 +856,17 @@ fn compile_data_ptr_value( let data_ptr_type = context.pointer_type(); match data_ptr_value { - PatioDataPtrValue::DataElement { name } => { - let global_value = context.data_ptr(name); + PatioDataPtrValue::PatioDataPtrValueDataElement(data_element) => { + let global_value = context.data_ptr(&data_element.name); context .function_builder .ins() .global_value(data_ptr_type, global_value) } - PatioDataPtrValue::Null => context.function_builder.ins().iconst(data_ptr_type, 0), + PatioDataPtrValue::PatioDataPtrValueNull(_) => { + context.function_builder.ins().iconst(data_ptr_type, 0) + } } } @@ -896,7 +913,7 @@ fn cranelift_signature<'a>( for local in locals { if local.local_type == PatioLocalType::Param { - let param_type = types::patio_type_to_cranelift_type(local.type_, &target_triple); + let param_type = types::patio_type_to_cranelift_type(&local.r#type, &target_triple); let param = cranelift::prelude::AbiParam::new(param_type); signature.params.push(param); } @@ -904,7 +921,7 @@ fn cranelift_signature<'a>( for return_type in return_types { let cranelift_return_type = - types::patio_type_to_cranelift_type(*return_type, &target_triple); + types::patio_type_to_cranelift_type(return_type, &target_triple); let returns = cranelift::prelude::AbiParam::new(cranelift_return_type); signature.returns.push(returns); } @@ -924,25 +941,25 @@ fn patio_operand_to_cranelift_type( context: &mut CompilerFunctionContext<'_>, ) -> cranelift_codegen::ir::Type { match operand { - PatioOperand::BoolConst(_) => { - patio_type_to_cranelift_type(PatioType::Bool, &context.target_triple) + PatioOperand::PatioBoolConst(_) => { + patio_type_to_cranelift_type(&PatioBoolType.into(), &context.target_triple) } - PatioOperand::ByteConst(_) => { - patio_type_to_cranelift_type(PatioType::Byte, &context.target_triple) + PatioOperand::PatioByteConst(_) => { + patio_type_to_cranelift_type(&PatioByteType.into(), &context.target_triple) } - PatioOperand::DataPtrConst(_) => { - patio_type_to_cranelift_type(PatioType::DataPtr, &context.target_triple) + PatioOperand::PatioDataPtrConst(_) => { + patio_type_to_cranelift_type(&PatioDataPtrType.into(), &context.target_triple) } - PatioOperand::FunctionPtrConst(_) => { - patio_type_to_cranelift_type(PatioType::FunctionPtr, &context.target_triple) + PatioOperand::PatioFunctionPtrConst(_) => { + patio_type_to_cranelift_type(&PatioFunctionPtrType.into(), &context.target_triple) } - PatioOperand::IntConst(_) => { - patio_type_to_cranelift_type(PatioType::Int, &context.target_triple) + PatioOperand::PatioIntConst(_) => { + patio_type_to_cranelift_type(&PatioIntType.into(), &context.target_triple) } - PatioOperand::Int32Const(_) => { - patio_type_to_cranelift_type(PatioType::Int32, &context.target_triple) + PatioOperand::PatioInt32Const(_) => { + patio_type_to_cranelift_type(&PatioInt32Type.into(), &context.target_triple) } - PatioOperand::LocalRef(local_ref) => context.local_type(&local_ref.name), + PatioOperand::PatioLocalRef(local_ref) => context.local_type(&local_ref.name), } } diff --git a/patio-to-cranelift/src/codegen/types.rs b/patio-to-cranelift/src/codegen/types.rs index 21833f3f..616520f7 100644 --- a/patio-to-cranelift/src/codegen/types.rs +++ b/patio-to-cranelift/src/codegen/types.rs @@ -1,21 +1,28 @@ -use crate::patio::types::{PatioDataLayout, PatioType}; +use crate::patio::types::{ + PatioBoolType, PatioByteType, PatioDataLayout, PatioDataPtrType, PatioFunctionPtrType, + PatioInt32Type, PatioIntType, PatioType, +}; pub(crate) fn patio_type_to_cranelift_type( - patio_type: PatioType, + patio_type: &PatioType, target_triple: &target_lexicon::Triple, ) -> cranelift::prelude::Type { match patio_type { - PatioType::Bool => CRANELIFT_BOOL_TYPE, + PatioType::PatioBoolType(_) => CRANELIFT_BOOL_TYPE, - PatioType::Byte => CRANELIFT_BYTE_TYPE, + PatioType::PatioByteType(_) => CRANELIFT_BYTE_TYPE, - PatioType::DataPtr => cranelift::prelude::Type::triple_pointer_type(&target_triple), + PatioType::PatioDataPtrType(_) => { + cranelift::prelude::Type::triple_pointer_type(&target_triple) + } - PatioType::FunctionPtr => cranelift::prelude::Type::triple_pointer_type(&target_triple), + PatioType::PatioFunctionPtrType(_) => { + cranelift::prelude::Type::triple_pointer_type(&target_triple) + } - PatioType::Int => cranelift_int_type(target_triple), + PatioType::PatioIntType(_) => cranelift_int_type(target_triple), - PatioType::Int32 => CRANELIFT_INT_32_TYPE, + PatioType::PatioInt32Type(_) => CRANELIFT_INT_32_TYPE, } } @@ -41,27 +48,29 @@ pub(crate) fn data_layout_byte_size( target_triple: &target_lexicon::Triple, ) -> u32 { match layout { - PatioDataLayout::Array { element, size } => { - data_layout_byte_size(element, target_triple) * size + PatioDataLayout::PatioDataLayoutArray(array) => { + data_layout_byte_size(&array.element, target_triple) + * u32::try_from(array.size).unwrap() } - PatioDataLayout::Bool => CRANELIFT_BOOL_TYPE.bytes(), + PatioDataLayout::PatioDataLayoutBool(_) => CRANELIFT_BOOL_TYPE.bytes(), - PatioDataLayout::Byte => CRANELIFT_BYTE_TYPE.bytes(), + PatioDataLayout::PatioDataLayoutByte(_) => CRANELIFT_BYTE_TYPE.bytes(), - PatioDataLayout::DataPtr => { + PatioDataLayout::PatioDataLayoutDataPtr(_) => { cranelift::prelude::Type::triple_pointer_type(&target_triple).bytes() } - PatioDataLayout::FunctionPtr => { + PatioDataLayout::PatioDataLayoutFunctionPtr(_) => { cranelift::prelude::Type::triple_pointer_type(&target_triple).bytes() } - PatioDataLayout::Int => cranelift_int_type(target_triple).bytes(), + PatioDataLayout::PatioDataLayoutInt(_) => cranelift_int_type(target_triple).bytes(), - PatioDataLayout::Int32 => CRANELIFT_INT_32_TYPE.bytes(), + PatioDataLayout::PatioDataLayoutInt32(_) => CRANELIFT_INT_32_TYPE.bytes(), - PatioDataLayout::Struct { elements } => elements + PatioDataLayout::PatioDataLayoutStruct(layout_struct) => layout_struct + .elements .iter() .map(|element| data_layout_byte_size(element, target_triple)) .sum(), @@ -72,7 +81,11 @@ pub(crate) fn data_layout_byte_size( mod data_layout_byte_size_test { use std::str::FromStr; - use crate::patio::types::PatioDataLayout; + use crate::patio::types::{ + PatioDataLayout, PatioDataLayoutArray, PatioDataLayoutBool, PatioDataLayoutByte, + PatioDataLayoutDataPtr, PatioDataLayoutFunctionPtr, PatioDataLayoutInt, + PatioDataLayoutInt32, PatioDataLayoutStruct, + }; fn data_layout_byte_size(layout: &PatioDataLayout) -> u32 { super::data_layout_byte_size( @@ -83,38 +96,44 @@ mod data_layout_byte_size_test { #[test] fn bool_is_one_byte() { - assert_eq!(data_layout_byte_size(&PatioDataLayout::Bool), 1); + assert_eq!(data_layout_byte_size(&PatioDataLayoutBool.into()), 1); } #[test] fn byte_is_one_byte() { - assert_eq!(data_layout_byte_size(&PatioDataLayout::Byte), 1); + assert_eq!(data_layout_byte_size(&PatioDataLayoutByte.into()), 1); } #[test] fn data_ptr_is_width_of_pointer() { - assert_eq!(data_layout_byte_size(&PatioDataLayout::DataPtr), 8); + assert_eq!(data_layout_byte_size(&PatioDataLayoutDataPtr.into()), 8); } #[test] fn function_ptr_is_width_of_pointer() { - assert_eq!(data_layout_byte_size(&PatioDataLayout::FunctionPtr), 8); + assert_eq!(data_layout_byte_size(&PatioDataLayoutFunctionPtr.into()), 8); } #[test] fn int_is_width_of_pointer_and_at_least_32_bits() { - assert_eq!(data_layout_byte_size(&PatioDataLayout::Int), 8); + assert_eq!(data_layout_byte_size(&PatioDataLayoutInt.into()), 8); } #[test] fn int32_is_four_bytes() { - assert_eq!(data_layout_byte_size(&PatioDataLayout::Int32), 4); + assert_eq!(data_layout_byte_size(&PatioDataLayoutInt32.into()), 4); } #[test] fn array_size_is_size_of_each_element_multiplied_by_number_of_elements() { assert_eq!( - data_layout_byte_size(&PatioDataLayout::array(PatioDataLayout::Int32, 7)), + data_layout_byte_size( + &PatioDataLayoutArray { + element: PatioDataLayoutInt32.into(), + size: 7 + } + .into() + ), 28 ); } @@ -122,10 +141,15 @@ mod data_layout_byte_size_test { #[test] fn struct_size_is_sum_of_element_sizes() { assert_eq!( - data_layout_byte_size(&PatioDataLayout::struct_(vec![ - PatioDataLayout::Int32, - PatioDataLayout::Byte - ])), + data_layout_byte_size( + &PatioDataLayoutStruct { + elements: vec![ + PatioDataLayout::PatioDataLayoutInt32(PatioDataLayoutInt32), + PatioDataLayout::PatioDataLayoutByte(PatioDataLayoutByte) + ] + } + .into() + ), 5 ); } @@ -133,7 +157,7 @@ mod data_layout_byte_size_test { pub(crate) fn data_layout_byte_offset( layout: &PatioDataLayout, - element_offsets: &[u32], + element_offsets: &[i32], target_triple: &target_lexicon::Triple, ) -> u32 { let mut byte_offset = 0; @@ -141,24 +165,32 @@ pub(crate) fn data_layout_byte_offset( for element_offset in element_offsets { match current_element { - PatioDataLayout::Array { element, size: _ } => { - byte_offset += data_layout_byte_size(element, target_triple) * element_offset; - current_element = element; + PatioDataLayout::PatioDataLayoutArray(array) => { + byte_offset += data_layout_byte_size(&array.element, target_triple) + * u32::try_from(*element_offset).unwrap(); + current_element = &array.element; } - PatioDataLayout::Bool => panic!("offset not allowed for bool"), - PatioDataLayout::Byte => panic!("offset not allowed for byte"), - PatioDataLayout::DataPtr => panic!("offset not allowed for data ptr"), - PatioDataLayout::FunctionPtr => panic!("offset not allowed for function ptr"), - PatioDataLayout::Int => panic!("offset not allowed for int"), - PatioDataLayout::Int32 => panic!("offset not allowed for int32"), - - PatioDataLayout::Struct { elements } => { - for element in elements.iter().take((*element_offset).try_into().unwrap()) { + PatioDataLayout::PatioDataLayoutBool(_) => panic!("offset not allowed for bool"), + PatioDataLayout::PatioDataLayoutByte(_) => panic!("offset not allowed for byte"), + PatioDataLayout::PatioDataLayoutDataPtr(_) => panic!("offset not allowed for data ptr"), + PatioDataLayout::PatioDataLayoutFunctionPtr(_) => { + panic!("offset not allowed for function ptr") + } + PatioDataLayout::PatioDataLayoutInt(_) => panic!("offset not allowed for int"), + PatioDataLayout::PatioDataLayoutInt32(_) => panic!("offset not allowed for int32"), + + PatioDataLayout::PatioDataLayoutStruct(layout_struct) => { + for element in layout_struct + .elements + .iter() + .take((*element_offset).try_into().unwrap()) + { byte_offset += data_layout_byte_size(element, target_triple); } - current_element = &elements[usize::try_from(*element_offset).unwrap()]; + current_element = + &layout_struct.elements[usize::try_from(*element_offset).unwrap()]; } } } @@ -170,9 +202,12 @@ pub(crate) fn data_layout_byte_offset( mod data_layout_byte_offset_test { use std::str::FromStr; - use crate::patio::types::PatioDataLayout; + use crate::patio::types::{ + PatioDataLayout, PatioDataLayoutArray, PatioDataLayoutByte, PatioDataLayoutDataPtr, + PatioDataLayoutInt32, PatioDataLayoutStruct, + }; - fn data_layout_byte_offset(layout: &PatioDataLayout, element_offsets: Vec<u32>) -> u32 { + fn data_layout_byte_offset(layout: &PatioDataLayout, element_offsets: Vec<i32>) -> u32 { super::data_layout_byte_offset( layout, &element_offsets, @@ -182,7 +217,11 @@ mod data_layout_byte_offset_test { #[test] fn byte_offset_of_first_element_of_array_is_zero() { - let layout = PatioDataLayout::array(PatioDataLayout::Int32, 2); + let layout = PatioDataLayoutArray { + element: PatioDataLayoutInt32.into(), + size: 2, + } + .into(); let byte_offset = data_layout_byte_offset(&layout, vec![0]); @@ -191,7 +230,11 @@ mod data_layout_byte_offset_test { #[test] fn byte_offset_of_element_of_array_is_size_of_skipped_elements() { - let layout = PatioDataLayout::array(PatioDataLayout::Int32, 5); + let layout = PatioDataLayoutArray { + element: PatioDataLayoutInt32.into(), + size: 5, + } + .into(); let byte_offset = data_layout_byte_offset(&layout, vec![2]); @@ -200,7 +243,15 @@ mod data_layout_byte_offset_test { #[test] fn byte_offset_of_element_of_element_of_array_is_size_of_skipped_elements() { - let layout = PatioDataLayout::array(PatioDataLayout::array(PatioDataLayout::Byte, 7), 5); + let layout = PatioDataLayoutArray { + element: PatioDataLayoutArray { + element: PatioDataLayoutByte.into(), + size: 7, + } + .into(), + size: 5, + } + .into(); let byte_offset = data_layout_byte_offset(&layout, vec![2, 3]); @@ -209,11 +260,14 @@ mod data_layout_byte_offset_test { #[test] fn byte_offset_of_first_element_of_struct_is_zero() { - let layout = PatioDataLayout::struct_(vec![ - PatioDataLayout::Int32, - PatioDataLayout::Byte, - PatioDataLayout::DataPtr, - ]); + let layout = PatioDataLayoutStruct { + elements: vec![ + PatioDataLayoutInt32.into(), + PatioDataLayoutByte.into(), + PatioDataLayoutDataPtr.into(), + ], + } + .into(); let byte_offset = data_layout_byte_offset(&layout, vec![0]); @@ -222,11 +276,14 @@ mod data_layout_byte_offset_test { #[test] fn byte_offset_of_element_of_struct_is_size_of_skipped_elements() { - let layout = PatioDataLayout::struct_(vec![ - PatioDataLayout::Int32, - PatioDataLayout::Byte, - PatioDataLayout::DataPtr, - ]); + let layout = PatioDataLayoutStruct { + elements: vec![ + PatioDataLayoutInt32.into(), + PatioDataLayoutByte.into(), + PatioDataLayoutDataPtr.into(), + ], + } + .into(); let byte_offset = data_layout_byte_offset(&layout, vec![2]); @@ -235,15 +292,21 @@ mod data_layout_byte_offset_test { #[test] fn byte_offset_of_element_of_element_of_struct_is_size_of_skipped_elements() { - let layout = PatioDataLayout::struct_(vec![ - PatioDataLayout::Int32, - PatioDataLayout::struct_(vec![ - PatioDataLayout::Byte, - PatioDataLayout::DataPtr, - PatioDataLayout::Byte, - ]), - PatioDataLayout::Int32, - ]); + let layout = PatioDataLayoutStruct { + elements: vec![ + PatioDataLayoutInt32.into(), + PatioDataLayoutStruct { + elements: vec![ + PatioDataLayoutByte.into(), + PatioDataLayoutDataPtr.into(), + PatioDataLayoutByte.into(), + ], + } + .into(), + PatioDataLayoutInt32.into(), + ], + } + .into(); let byte_offset = data_layout_byte_offset(&layout, vec![1, 2]); @@ -253,25 +316,28 @@ mod data_layout_byte_offset_test { pub(crate) fn data_layout_element_at<'a>( layout: &'a PatioDataLayout, - element_offsets: &[u32], + element_offsets: &[i32], ) -> &'a PatioDataLayout { let mut current_element = layout; for element_offset in element_offsets { match current_element { - PatioDataLayout::Array { element, size: _ } => { - current_element = element; + PatioDataLayout::PatioDataLayoutArray(array) => { + current_element = &array.element; } - PatioDataLayout::Bool => panic!("offset not allowed for bool"), - PatioDataLayout::Byte => panic!("offset not allowed for byte"), - PatioDataLayout::DataPtr => panic!("offset not allowed for data ptr"), - PatioDataLayout::FunctionPtr => panic!("offset not allowed for function ptr"), - PatioDataLayout::Int => panic!("offset not allowed for int"), - PatioDataLayout::Int32 => panic!("offset not allowed for int32"), + PatioDataLayout::PatioDataLayoutBool(_) => panic!("offset not allowed for bool"), + PatioDataLayout::PatioDataLayoutByte(_) => panic!("offset not allowed for byte"), + PatioDataLayout::PatioDataLayoutDataPtr(_) => panic!("offset not allowed for data ptr"), + PatioDataLayout::PatioDataLayoutFunctionPtr(_) => { + panic!("offset not allowed for function ptr") + } + PatioDataLayout::PatioDataLayoutInt(_) => panic!("offset not allowed for int"), + PatioDataLayout::PatioDataLayoutInt32(_) => panic!("offset not allowed for int32"), - PatioDataLayout::Struct { elements } => { - current_element = &elements[usize::try_from(*element_offset).unwrap()]; + PatioDataLayout::PatioDataLayoutStruct(layout_struct) => { + current_element = + &layout_struct.elements[usize::try_from(*element_offset).unwrap()]; } } } @@ -281,86 +347,113 @@ pub(crate) fn data_layout_element_at<'a>( #[cfg(test)] mod data_layout_element_at_test { - use crate::patio::types::PatioDataLayout; + use crate::patio::types::{ + PatioDataLayout, PatioDataLayoutArray, PatioDataLayoutByte, PatioDataLayoutDataPtr, + PatioDataLayoutInt32, PatioDataLayoutStruct, + }; fn data_layout_element_at( layout: &PatioDataLayout, - element_offsets: Vec<u32>, + element_offsets: Vec<i32>, ) -> &PatioDataLayout { super::data_layout_element_at(layout, &element_offsets) } #[test] fn element_of_array_is_element_layout() { - let layout = PatioDataLayout::array(PatioDataLayout::Int32, 2); + let layout = PatioDataLayoutArray { + element: PatioDataLayoutInt32.into(), + size: 2, + } + .into(); let element = data_layout_element_at(&layout, vec![0]); - assert_eq!(element, &PatioDataLayout::Int32); + assert_eq!(element, &PatioDataLayoutInt32.into()); } #[test] fn element_of_element_of_array() { - let layout = PatioDataLayout::array(PatioDataLayout::array(PatioDataLayout::Byte, 7), 5); + let layout = PatioDataLayoutArray { + element: PatioDataLayoutArray { + element: PatioDataLayoutByte.into(), + size: 7, + } + .into(), + size: 5, + } + .into(); let element = data_layout_element_at(&layout, vec![2, 3]); - assert_eq!(element, &PatioDataLayout::Byte); + assert_eq!(element, &PatioDataLayoutByte.into()); } #[test] fn first_element_of_struct() { - let layout = PatioDataLayout::struct_(vec![ - PatioDataLayout::Int32, - PatioDataLayout::Byte, - PatioDataLayout::DataPtr, - ]); + let layout = PatioDataLayoutStruct { + elements: vec![ + PatioDataLayoutInt32.into(), + PatioDataLayoutByte.into(), + PatioDataLayoutDataPtr.into(), + ], + } + .into(); let element = data_layout_element_at(&layout, vec![0]); - assert_eq!(element, &PatioDataLayout::Int32); + assert_eq!(element, &PatioDataLayoutInt32.into()); } #[test] fn non_first_element_of_struct() { - let layout = PatioDataLayout::struct_(vec![ - PatioDataLayout::Int32, - PatioDataLayout::Byte, - PatioDataLayout::DataPtr, - ]); + let layout = PatioDataLayoutStruct { + elements: vec![ + PatioDataLayoutInt32.into(), + PatioDataLayoutByte.into(), + PatioDataLayoutDataPtr.into(), + ], + } + .into(); let element = data_layout_element_at(&layout, vec![2]); - assert_eq!(element, &PatioDataLayout::DataPtr); + assert_eq!(element, &PatioDataLayoutDataPtr.into()); } #[test] fn element_of_element_of_struct() { - let layout = PatioDataLayout::struct_(vec![ - PatioDataLayout::Int32, - PatioDataLayout::struct_(vec![ - PatioDataLayout::Byte, - PatioDataLayout::DataPtr, - PatioDataLayout::Byte, - ]), - PatioDataLayout::Int32, - ]); + let layout = PatioDataLayoutStruct { + elements: vec![ + PatioDataLayoutInt32.into(), + PatioDataLayoutStruct { + elements: vec![ + PatioDataLayoutByte.into(), + PatioDataLayoutDataPtr.into(), + PatioDataLayoutByte.into(), + ], + } + .into(), + PatioDataLayoutInt32.into(), + ], + } + .into(); let element = data_layout_element_at(&layout, vec![1, 2]); - assert_eq!(element, &PatioDataLayout::Byte); + assert_eq!(element, &PatioDataLayoutByte.into()); } } pub(crate) fn data_layout_to_type(layout: &PatioDataLayout) -> PatioType { match layout { - PatioDataLayout::Array { .. } => panic!("array cannot be represented as type"), - PatioDataLayout::Bool => PatioType::Bool, - PatioDataLayout::Byte => PatioType::Byte, - PatioDataLayout::DataPtr => PatioType::DataPtr, - PatioDataLayout::FunctionPtr => PatioType::FunctionPtr, - PatioDataLayout::Int => PatioType::Int, - PatioDataLayout::Int32 => PatioType::Int32, - PatioDataLayout::Struct { .. } => panic!("struct cannot be represented as type"), + PatioDataLayout::PatioDataLayoutArray(_) => panic!("array cannot be represented as type"), + PatioDataLayout::PatioDataLayoutBool(_) => PatioBoolType.into(), + PatioDataLayout::PatioDataLayoutByte(_) => PatioByteType.into(), + PatioDataLayout::PatioDataLayoutDataPtr(_) => PatioDataPtrType.into(), + PatioDataLayout::PatioDataLayoutFunctionPtr(_) => PatioFunctionPtrType.into(), + PatioDataLayout::PatioDataLayoutInt(_) => PatioIntType.into(), + PatioDataLayout::PatioDataLayoutInt32(_) => PatioInt32Type.into(), + PatioDataLayout::PatioDataLayoutStruct(_) => panic!("struct cannot be represented as type"), } } diff --git a/patio-to-cranelift/src/codegen/values.rs b/patio-to-cranelift/src/codegen/values.rs index 229dbc6f..e4bcec2b 100644 --- a/patio-to-cranelift/src/codegen/values.rs +++ b/patio-to-cranelift/src/codegen/values.rs @@ -1,6 +1,9 @@ use crate::{ codegen::types, - patio::values::{PatioDataPtrValue, PatioDataValue, PatioIntValue}, + patio::{ + types::{PatioDataValue, PatioDataValueDataPtr}, + values::{PatioDataPtrValue, PatioIntValue}, + }, }; pub(crate) fn data_value_to_bytes( @@ -24,37 +27,38 @@ fn write_data_value( target_triple: &target_lexicon::Triple, ) { match value { - PatioDataValue::Array { - element_layout: _, - elements, - } => { - for element in elements { + PatioDataValue::PatioDataValueArray(array) => { + for element in &array.elements { write_data_value(element, bytes, target_triple); } } - PatioDataValue::Bool(value) => bytes.push(if *value { 1 } else { 0 }), + PatioDataValue::PatioDataValueBool(bool) => bytes.push(if bool.value { 1 } else { 0 }), - PatioDataValue::Byte(value) => bytes.push(*value), + PatioDataValue::PatioDataValueByte(byte) => bytes.push(byte.value as u8), - PatioDataValue::DataPtr(PatioDataPtrValue::DataElement { name: _ }) => todo!(), + PatioDataValue::PatioDataValueDataPtr(PatioDataValueDataPtr { + value: PatioDataPtrValue::PatioDataPtrValueDataElement(_), + }) => todo!(), - PatioDataValue::DataPtr(PatioDataPtrValue::Null) => { + PatioDataValue::PatioDataValueDataPtr(PatioDataValueDataPtr { + value: PatioDataPtrValue::PatioDataPtrValueNull(_), + }) => { write_patio_int(0, bytes, target_triple); } - PatioDataValue::Int(int_value) => { - let value = eval_int_value(int_value, target_triple); + PatioDataValue::PatioDataValueInt(int_value) => { + let value = eval_int_value(&int_value.value, target_triple); write_patio_int(value, bytes, target_triple); } - PatioDataValue::Int32(int_value) => { - let value: i32 = eval_int_value(int_value, target_triple); + PatioDataValue::PatioDataValueInt32(int_value) => { + let value: i32 = eval_int_value(&int_value.value, target_triple); bytes.extend_from_slice(&value.to_le_bytes()); } - PatioDataValue::Struct { elements } => { - for element in elements { + PatioDataValue::PatioDataValueStruct(value_struct) => { + for element in &value_struct.elements { write_data_value(element, bytes, target_triple); } } @@ -80,18 +84,21 @@ fn write_patio_int(value: i32, bytes: &mut Vec<u8>, target_triple: &target_lexic pub(crate) fn eval_int_value(value: &PatioIntValue, target_triple: &target_lexicon::Triple) -> i32 { match value { - PatioIntValue::ByteOffsetOf { - layout, - element_offsets, - } => types::data_layout_byte_offset(layout, element_offsets, target_triple) - .try_into() - .unwrap(), + PatioIntValue::PatioIntValueByteOffsetOf(byte_offset_of) => types::data_layout_byte_offset( + &byte_offset_of.layout, + &byte_offset_of.element_offsets, + target_triple, + ) + .try_into() + .unwrap(), - PatioIntValue::ByteSizeOf { layout } => types::data_layout_byte_size(layout, target_triple) - .try_into() - .unwrap(), + PatioIntValue::PatioIntValueByteSizeOf(byte_size_of) => { + types::data_layout_byte_size(&byte_size_of.layout, target_triple) + .try_into() + .unwrap() + } - PatioIntValue::Literal { value } => *value, + PatioIntValue::PatioIntValueLiteral(literal) => literal.value, } } @@ -100,8 +107,12 @@ mod data_value_to_bytes_test { use std::str::FromStr; use crate::patio::{ - types::PatioDataLayout, - values::{PatioDataPtrValue, PatioDataValue, PatioIntValue}, + types::{ + PatioDataLayoutInt32, PatioDataValue, PatioDataValueArray, PatioDataValueBool, + PatioDataValueByte, PatioDataValueDataPtr, PatioDataValueInt, PatioDataValueInt32, + PatioDataValueStruct, + }, + values::{PatioDataPtrValueNull, PatioIntValueLiteral}, }; fn data_value_to_bytes(data_value: PatioDataValue) -> Box<[u8]> { @@ -113,13 +124,20 @@ mod data_value_to_bytes_test { #[test] fn array_is_written_as_elements() { - let data_value = PatioDataValue::Array { - element_layout: PatioDataLayout::Int32, + let data_value = PatioDataValueArray { + element_layout: PatioDataLayoutInt32.into(), elements: vec![ - PatioDataValue::Int32(PatioIntValue::Literal { value: 0x12345678 }), - PatioDataValue::Int32(PatioIntValue::Literal { value: 0x23456789 }), + PatioDataValueInt32 { + value: PatioIntValueLiteral { value: 0x12345678 }.into(), + } + .into(), + PatioDataValueInt32 { + value: PatioIntValueLiteral { value: 0x23456789 }.into(), + } + .into(), ], - }; + } + .into(); let bytes = data_value_to_bytes(data_value); @@ -131,7 +149,7 @@ mod data_value_to_bytes_test { #[test] fn false_is_single_byte_0() { - let data_value = PatioDataValue::Bool(false); + let data_value = PatioDataValueBool { value: false }.into(); let bytes = data_value_to_bytes(data_value); @@ -140,7 +158,7 @@ mod data_value_to_bytes_test { #[test] fn true_is_single_byte_1() { - let data_value = PatioDataValue::Bool(true); + let data_value = PatioDataValueBool { value: true }.into(); let bytes = data_value_to_bytes(data_value); @@ -149,7 +167,7 @@ mod data_value_to_bytes_test { #[test] fn byte_is_written_as_single_byte() { - let data_value = PatioDataValue::Byte(42); + let data_value = PatioDataValueByte { value: 42 }.into(); let bytes = data_value_to_bytes(data_value); @@ -159,7 +177,10 @@ mod data_value_to_bytes_test { #[test] fn given_pointer_is_64_bits_wide_then_null_data_ptr_is_written_as_64_bit_0() { let target_triple = target_lexicon::Triple::from_str("x86_64-unknown-linux-gnu").unwrap(); - let data_value = PatioDataValue::DataPtr(PatioDataPtrValue::Null); + let data_value = PatioDataValueDataPtr { + value: PatioDataPtrValueNull {}.into(), + } + .into(); let bytes = super::data_value_to_bytes(&data_value, &target_triple); @@ -169,7 +190,10 @@ mod data_value_to_bytes_test { #[test] fn given_pointer_is_32_bits_wide_then_null_data_ptr_is_written_as_32_bit_0() { let target_triple = target_lexicon::Triple::from_str("i686-unknown-linux-gnu").unwrap(); - let data_value = PatioDataValue::DataPtr(PatioDataPtrValue::Null); + let data_value = PatioDataValueDataPtr { + value: PatioDataPtrValueNull {}.into(), + } + .into(); let bytes = super::data_value_to_bytes(&data_value, &target_triple); @@ -179,7 +203,10 @@ mod data_value_to_bytes_test { #[test] fn given_pointer_is_64_bits_wide_then_int_is_written_with_pointer_width() { let target_triple = target_lexicon::Triple::from_str("x86_64-unknown-linux-gnu").unwrap(); - let data_value = PatioDataValue::Int(PatioIntValue::Literal { value: 0x12345678 }); + let data_value = PatioDataValueInt { + value: PatioIntValueLiteral { value: 0x12345678 }.into(), + } + .into(); let bytes = super::data_value_to_bytes(&data_value, &target_triple); @@ -189,7 +216,10 @@ mod data_value_to_bytes_test { #[test] fn given_pointer_is_32_bits_wide_then_int_is_written_with_pointer_width() { let target_triple = target_lexicon::Triple::from_str("i686-unknown-linux-gnu").unwrap(); - let data_value = PatioDataValue::Int(PatioIntValue::Literal { value: 0x12345678 }); + let data_value = PatioDataValueInt { + value: PatioIntValueLiteral { value: 0x12345678 }.into(), + } + .into(); let bytes = super::data_value_to_bytes(&data_value, &target_triple); @@ -198,7 +228,10 @@ mod data_value_to_bytes_test { #[test] fn int_32_is_written_as_four_bytes() { - let data_value = PatioDataValue::Int32(PatioIntValue::Literal { value: 0x12345678 }); + let data_value = PatioDataValueInt32 { + value: PatioIntValueLiteral { value: 0x12345678 }.into(), + } + .into(); let bytes = data_value_to_bytes(data_value); @@ -207,12 +240,19 @@ mod data_value_to_bytes_test { #[test] fn struct_is_written_as_elements() { - let data_value = PatioDataValue::Struct { + let data_value = PatioDataValueStruct { elements: vec![ - PatioDataValue::Int32(PatioIntValue::Literal { value: 0x12345678 }), - PatioDataValue::Int32(PatioIntValue::Literal { value: 0x23456789 }), + PatioDataValueInt32 { + value: PatioIntValueLiteral { value: 0x12345678 }.into(), + } + .into(), + PatioDataValueInt32 { + value: PatioIntValueLiteral { value: 0x23456789 }.into(), + } + .into(), ], - }; + } + .into(); let bytes = data_value_to_bytes(data_value); @@ -227,7 +267,12 @@ mod data_value_to_bytes_test { mod eval_int_value_test { use std::str::FromStr; - use crate::patio::{types::PatioDataLayout, values::PatioIntValue}; + use crate::patio::{ + types::{PatioDataLayoutArray, PatioDataLayoutInt32}, + values::{ + PatioIntValue, PatioIntValueByteOffsetOf, PatioIntValueByteSizeOf, PatioIntValueLiteral, + }, + }; fn eval_int_value(int_value: PatioIntValue) -> i32 { super::eval_int_value( @@ -238,7 +283,7 @@ mod eval_int_value_test { #[test] fn int_value_literal_is_used_verbatim() { - let int_value = PatioIntValue::Literal { value: 0x12345678 }; + let int_value = PatioIntValueLiteral { value: 0x12345678 }.into(); let value = eval_int_value(int_value); @@ -247,9 +292,10 @@ mod eval_int_value_test { #[test] fn int_can_have_size_of_layout() { - let int_value = PatioIntValue::ByteSizeOf { - layout: PatioDataLayout::Int32, - }; + let int_value = PatioIntValueByteSizeOf { + layout: PatioDataLayoutInt32.into(), + } + .into(); let value = eval_int_value(int_value); @@ -258,10 +304,15 @@ mod eval_int_value_test { #[test] fn int_can_have_byte_offset() { - let int_value = PatioIntValue::ByteOffsetOf { - layout: PatioDataLayout::array(PatioDataLayout::Int32, 7), + let int_value = PatioIntValueByteOffsetOf { + layout: PatioDataLayoutArray { + element: PatioDataLayoutInt32.into(), + size: 7, + } + .into(), element_offsets: vec![5], - }; + } + .into(); let value = eval_int_value(int_value); diff --git a/patio-to-cranelift/src/errors.rs b/patio-to-cranelift/src/errors.rs index 09e9a2a4..0bffe856 100644 --- a/patio-to-cranelift/src/errors.rs +++ b/patio-to-cranelift/src/errors.rs @@ -3,8 +3,8 @@ pub enum CompileError { /// Reading the bytes of the patio source file failed. ReadSourceBytes(#[allow(dead_code)] std::io::Error), - /// The bytes of the patio source were an invalid flatbuffer. - InvalidFlatbuffer(#[allow(dead_code)] flatbuffers::InvalidFlatbuffer), + /// The Patio source file was invalid. + InvalidPatioSource(#[allow(dead_code)] std::io::Error), /// Enabling PIC failed. EnablePicFailed(#[allow(dead_code)] cranelift_codegen::settings::SetError), diff --git a/patio-to-cranelift/src/lib.rs b/patio-to-cranelift/src/lib.rs index 80d22840..2c7e8d8f 100644 --- a/patio-to-cranelift/src/lib.rs +++ b/patio-to-cranelift/src/lib.rs @@ -1,19 +1,61 @@ -use std::{path::Path, str::FromStr}; +use std::{io::Cursor, path::Path, str::FromStr}; -use crate::{errors::CompileError, patio::compilation_unit::PatioCompilationUnit}; - -#[allow(dead_code, unused_imports)] -#[path = "./gen/patio_generated.rs"] -mod patio_generated; - -#[allow(dead_code, unused_imports)] -#[path = "./gen/sources_generated.rs"] -mod sources_generated; +use crate::errors::CompileError; mod codegen; mod errors; mod patio; +mod sources { + include!("./gen/sources.rs"); + + #[allow(unused)] + pub(crate) mod transient_0 { + include!("./gen/sources/transient_0.rs"); + } +} + +mod sourcetext { + include!("./gen/sourcetext.rs"); + + #[derive(Clone, Debug, Hash, PartialEq)] + pub struct SourceText { + name: String, + contents: String, + } + + #[allow(unused)] + pub(crate) mod transient_0 { + use std::{any::Any, collections::HashMap, sync::Arc}; + + use crate::sourcetext::SourceText; + + include!("./gen/sourcetext/transient_0.rs"); + + fn encode_source_text( + value: &SourceText, + writer: &mut impl std::io::Write, + shared_values: &mut HashMap<usize, i64>, + ) -> std::io::Result<()> { + todo!(); + } + + fn decode_source_text( + reader: &mut impl std::io::Read, + shared_values: &mut Vec<Arc<dyn Any + Sync + Send>>, + ) -> std::io::Result<SourceText> { + let name = crate::transient_0::decode_string(reader, shared_values)?; + let contents = crate::transient_0::decode_string(reader, shared_values)?; + Ok(SourceText { name, contents }) + } + } +} + +#[allow(unused)] +mod transient_0 { + include!("./gen/transient_0.rs"); +} + pub fn compile( source_path: &Path, target_str: &str, @@ -21,10 +63,11 @@ pub fn compile( ) -> Result<(), CompileError> { let source_bytes = std::fs::read(source_path).map_err(CompileError::ReadSourceBytes)?; - let compilation_unit: PatioCompilationUnit = - patio_generated::patio::root_as_patio_compilation_unit(&source_bytes) - .map_err(CompileError::InvalidFlatbuffer)? - .into(); + let compilation_unit = patio::transient_0::decode_patio_compilation_unit( + &mut Cursor::new(source_bytes), + &mut Vec::new(), + ) + .map_err(CompileError::InvalidPatioSource)?; let target_triple = target_lexicon::Triple::from_str(target_str).map_err(CompileError::ParseTargetTriple)?; diff --git a/patio-to-cranelift/src/patio/compilation_unit.rs b/patio-to-cranelift/src/patio/compilation_unit.rs deleted file mode 100644 index af8b4d3f..00000000 --- a/patio-to-cranelift/src/patio/compilation_unit.rs +++ /dev/null @@ -1,67 +0,0 @@ -use crate::patio::{ - instructions::PatioInstruction, - types::{PatioDataLayout, PatioType}, - values::PatioDataValue, -}; - -pub(crate) struct PatioCompilationUnit { - pub(crate) elements: Vec<PatioCompilationUnitElement>, -} - -pub(crate) enum PatioCompilationUnitElement { - DataElementImmutableDefinition(PatioDataElementImmutableDefinition), - DataElementMutableDefinition(PatioDataElementMutableDefinition), - DataElementMutableDeclaration(PatioDataElementMutableDeclaration), - FunctionDeclaration(PatioFunctionDeclaration), - FunctionDefinition(PatioFunctionDefinition), -} - -pub(crate) struct PatioDataElementImmutableDefinition { - pub(crate) name: String, - pub(crate) visibility: PatioVisibility, - pub(crate) value: PatioDataValue, -} - -pub(crate) struct PatioDataElementMutableDefinition { - pub(crate) name: String, - pub(crate) visibility: PatioVisibility, - pub(crate) initial_value: PatioDataValue, -} - -pub(crate) struct PatioDataElementMutableDeclaration { - pub(crate) name: String, - pub(crate) layout: PatioDataLayout, -} - -pub(crate) struct PatioFunctionDeclaration { - pub(crate) name: String, - pub(crate) params: Vec<PatioLocal>, - pub(crate) return_types: Vec<PatioType>, -} - -pub(crate) struct PatioFunctionDefinition { - pub(crate) name: String, - pub(crate) visibility: PatioVisibility, - pub(crate) locals: Vec<PatioLocal>, - pub(crate) return_types: Vec<PatioType>, - pub(crate) body: Vec<PatioInstruction>, -} - -pub(crate) struct PatioLocal { - pub(crate) name: String, - pub(crate) type_: PatioType, - pub(crate) local_type: PatioLocalType, -} - -#[derive(Eq, PartialEq)] -pub(crate) enum PatioLocalType { - Param, - Val, - Var, -} - -#[derive(Clone, Copy)] -pub(crate) enum PatioVisibility { - Public, - Private, -} diff --git a/patio-to-cranelift/src/patio/flatbuffers.rs b/patio-to-cranelift/src/patio/flatbuffers.rs deleted file mode 100644 index e35b2c8a..00000000 --- a/patio-to-cranelift/src/patio/flatbuffers.rs +++ /dev/null @@ -1,619 +0,0 @@ -use crate::{ - patio::{ - compilation_unit::{ - PatioCompilationUnit, PatioCompilationUnitElement, PatioDataElementImmutableDefinition, - PatioDataElementMutableDeclaration, PatioDataElementMutableDefinition, - PatioFunctionDeclaration, PatioFunctionDefinition, PatioLocal, PatioLocalType, - PatioVisibility, - }, - instructions::{ - PatioBlock, PatioBoolToInt, PatioCall, PatioCallPointer, PatioDataPtrToInt, PatioIf, - PatioInstruction, PatioIntAdd, PatioIntEquals, PatioIntNotEqual, PatioIntSub, - PatioIntToBool, PatioIntToDataPtr, PatioLocalStore, PatioLoop, PatioLoopBreak, - PatioLoopContinue, PatioMemoryLoad, PatioMemoryStore, PatioReturn, PatioSwitch, - PatioSwitchCase, PatioUnreachable, PatioVarLoad, PatioVarStore, - }, - operands::{PatioLocalRef, PatioOperand}, - types::{PatioDataLayout, PatioType}, - values::{PatioDataPtrValue, PatioDataValue, PatioIntValue}, - }, - patio_generated::{ - self, - patio::{PatioDataLayoutValue, PatioDataValueValue, PatioIntValueValue, PatioTypeValue}, - }, -}; - -// == Compilation unit == - -impl From<patio_generated::patio::PatioCompilationUnit<'_>> for PatioCompilationUnit { - fn from(value: patio_generated::patio::PatioCompilationUnit<'_>) -> Self { - Self { - elements: value.elements().iter().map(Into::into).collect(), - } - } -} - -// == Compilation unit elements == - -impl From<patio_generated::patio::PatioCompilationUnitElement<'_>> for PatioCompilationUnitElement { - fn from(value: patio_generated::patio::PatioCompilationUnitElement<'_>) -> Self { - match value.value_type() { - patio_generated::patio::PatioCompilationUnitElementValue::PatioDataElementImmutableDefinition => { - let data_element_immutable_definition = value.value_as_patio_data_element_immutable_definition().unwrap(); - - Self::DataElementImmutableDefinition(PatioDataElementImmutableDefinition { - name: data_element_immutable_definition.name().to_string(), - visibility: data_element_immutable_definition.visibility().into(), - value: data_element_immutable_definition.value().into(), - }) - } - - patio_generated::patio::PatioCompilationUnitElementValue::PatioDataElementMutableDeclaration => { - let data_element_mutable_declaration = value.value_as_patio_data_element_mutable_declaration().unwrap(); - - Self::DataElementMutableDeclaration(PatioDataElementMutableDeclaration { - name: data_element_mutable_declaration.name().to_string(), - layout: data_element_mutable_declaration.layout().into(), - }) - } - - patio_generated::patio::PatioCompilationUnitElementValue::PatioDataElementMutableDefinition => { - let data_element_mutable_definition = value.value_as_patio_data_element_mutable_definition().unwrap(); - - Self::DataElementMutableDefinition(PatioDataElementMutableDefinition { - name: data_element_mutable_definition.name().to_string(), - visibility: data_element_mutable_definition.visibility().into(), - initial_value: data_element_mutable_definition.initial_value().into(), - }) - } - - patio_generated::patio::PatioCompilationUnitElementValue::PatioFunctionDeclaration => { - let function_declaration = value.value_as_patio_function_declaration().unwrap(); - - Self::FunctionDeclaration(PatioFunctionDeclaration { - name: function_declaration.name().to_string(), - params: function_declaration - .params() - .iter() - .map(Into::into) - .collect(), - return_types: function_declaration.return_types().iter().map(Into::into).collect(), - }) - } - - patio_generated::patio::PatioCompilationUnitElementValue::PatioFunctionDefinition => { - let function_definition = value.value_as_patio_function_definition().unwrap(); - - Self::FunctionDefinition(PatioFunctionDefinition { - name: function_definition.name().to_string(), - visibility: function_definition.visibility().into(), - locals: function_definition - .locals() - .iter() - .map(Into::into) - .collect(), - return_types: function_definition.return_types().iter().map(Into::into).collect(), - body: function_definition.body().iter().map(Into::into).collect(), - }) - } - - element_type => todo!( - "Unhandled compilation unit element type: {:?} {}", - element_type.variant_name(), - element_type.0 - ), - } - } -} - -impl From<patio_generated::patio::PatioLocal<'_>> for PatioLocal { - fn from(value: patio_generated::patio::PatioLocal<'_>) -> Self { - Self { - name: value.name().to_string(), - type_: value.type_().into(), - local_type: value.local_type().into(), - } - } -} - -impl From<patio_generated::patio::PatioLocalType> for PatioLocalType { - fn from(value: patio_generated::patio::PatioLocalType) -> Self { - match value { - patio_generated::patio::PatioLocalType::PARAM => Self::Param, - patio_generated::patio::PatioLocalType::VAL => Self::Val, - patio_generated::patio::PatioLocalType::VAR => Self::Var, - local_type_type => todo!( - "Unhandled local type type: {:?} {}", - local_type_type.variant_name(), - local_type_type.0 - ), - } - } -} - -impl From<patio_generated::patio::PatioVisibility> for PatioVisibility { - fn from(value: patio_generated::patio::PatioVisibility) -> Self { - match value { - patio_generated::patio::PatioVisibility::PRIVATE => Self::Private, - patio_generated::patio::PatioVisibility::PUBLIC => Self::Public, - visibility_type => todo!( - "Unhandled visibility type: {:?} {}", - visibility_type.variant_name(), - visibility_type.0 - ), - } - } -} - -// == Instructions == - -impl From<patio_generated::patio::PatioInstruction<'_>> for PatioInstruction { - fn from(value: patio_generated::patio::PatioInstruction<'_>) -> Self { - match value.value_type() { - patio_generated::patio::PatioInstructionValue::PatioBlock => { - let block = value.value_as_patio_block().unwrap(); - - Self::Block(block.into()) - } - - patio_generated::patio::PatioInstructionValue::PatioBoolToInt => { - let bool_to_int = value.value_as_patio_bool_to_int().unwrap(); - - Self::BoolToInt(PatioBoolToInt { - destination: bool_to_int.destination().into(), - value: bool_to_int.value().into(), - }) - } - - patio_generated::patio::PatioInstructionValue::PatioCall => { - let call = value.value_as_patio_call().unwrap(); - - Self::Call(PatioCall { - destinations: call.destinations().iter().map(Into::into).collect(), - function_name: call.function_name().into(), - args: call.args().iter().map(Into::into).collect(), - }) - } - - patio_generated::patio::PatioInstructionValue::PatioCallPointer => { - let call_pointer = value.value_as_patio_call_pointer().unwrap(); - - Self::CallPointer(PatioCallPointer { - destinations: call_pointer.destinations().iter().map(Into::into).collect(), - function_pointer: call_pointer.function_pointer().into(), - args: call_pointer.args().iter().map(Into::into).collect(), - }) - } - - patio_generated::patio::PatioInstructionValue::PatioDataPtrToInt => { - let data_ptr_to_int = value.value_as_patio_data_ptr_to_int().unwrap(); - - Self::DataPtrToInt(PatioDataPtrToInt { - destination: data_ptr_to_int.destination().into(), - value: data_ptr_to_int.value().into(), - }) - } - - patio_generated::patio::PatioInstructionValue::PatioIf => { - let if_ = value.value_as_patio_if().unwrap(); - - Self::If(PatioIf { - destinations: if_.destinations().iter().map(Into::into).collect(), - condition: if_.condition().into(), - true_body: if_.true_body().into(), - false_body: if_.false_body().into(), - }) - } - - patio_generated::patio::PatioInstructionValue::PatioIntAdd => { - let int_add = value.value_as_patio_int_add().unwrap(); - - Self::IntAdd(PatioIntAdd { - destination: int_add.destination().into(), - left: int_add.left().into(), - right: int_add.right().into(), - }) - } - - patio_generated::patio::PatioInstructionValue::PatioIntEquals => { - let int_add = value.value_as_patio_int_equals().unwrap(); - - Self::IntEquals(PatioIntEquals { - destination: int_add.destination().into(), - left: int_add.left().into(), - right: int_add.right().into(), - }) - } - - patio_generated::patio::PatioInstructionValue::PatioIntNotEqual => { - let int_not_equal = value.value_as_patio_int_not_equal().unwrap(); - - Self::IntNotEqual(PatioIntNotEqual { - destination: int_not_equal.destination().into(), - left: int_not_equal.left().into(), - right: int_not_equal.right().into(), - }) - } - - patio_generated::patio::PatioInstructionValue::PatioIntSub => { - let int_sub = value.value_as_patio_int_sub().unwrap(); - - Self::IntSub(PatioIntSub { - destination: int_sub.destination().into(), - left: int_sub.left().into(), - right: int_sub.right().into(), - }) - } - - patio_generated::patio::PatioInstructionValue::PatioIntToBool => { - let int_to_bool = value.value_as_patio_int_to_bool().unwrap(); - - Self::IntToBool(PatioIntToBool { - destination: int_to_bool.destination().into(), - value: int_to_bool.value().into(), - }) - } - - patio_generated::patio::PatioInstructionValue::PatioIntToDataPtr => { - let int_to_data_ptr = value.value_as_patio_int_to_data_ptr().unwrap(); - - Self::IntToDataPtr(PatioIntToDataPtr { - destination: int_to_data_ptr.destination().into(), - value: int_to_data_ptr.value().into(), - }) - } - - patio_generated::patio::PatioInstructionValue::PatioLocalStore => { - let local_store = value.value_as_patio_local_store().unwrap(); - - Self::LocalStore(PatioLocalStore { - destination: local_store.destination().into(), - value: local_store.value().into(), - }) - } - - patio_generated::patio::PatioInstructionValue::PatioLoop => { - let loop_ = value.value_as_patio_loop().unwrap(); - - Self::Loop(PatioLoop { - body: loop_.body().iter().map(Into::into).collect(), - }) - } - - patio_generated::patio::PatioInstructionValue::PatioLoopBreak => { - Self::LoopBreak(PatioLoopBreak) - } - - patio_generated::patio::PatioInstructionValue::PatioLoopContinue => { - Self::LoopContinue(PatioLoopContinue) - } - - patio_generated::patio::PatioInstructionValue::PatioMemoryLoad => { - let memory_load = value.value_as_patio_memory_load().unwrap(); - - Self::MemoryLoad(PatioMemoryLoad { - destination: memory_load.destination().into(), - pointer: memory_load.pointer().into(), - layout: memory_load.layout().into(), - element_offsets: memory_load.element_offsets().iter().collect(), - }) - } - - patio_generated::patio::PatioInstructionValue::PatioMemoryStore => { - let memory_store = value.value_as_patio_memory_store().unwrap(); - - Self::MemoryStore(PatioMemoryStore { - pointer: memory_store.pointer().into(), - layout: memory_store.layout().into(), - element_offsets: memory_store.element_offsets().iter().collect(), - value: memory_store.value().into(), - }) - } - - patio_generated::patio::PatioInstructionValue::PatioReturn => { - let return_ = value.value_as_patio_return().unwrap(); - - Self::Return(PatioReturn { - values: return_.values().iter().map(Into::into).collect(), - }) - } - - patio_generated::patio::PatioInstructionValue::PatioSwitch => { - let switch = value.value_as_patio_switch().unwrap(); - - Self::Switch(PatioSwitch { - destinations: switch.destinations().iter().map(Into::into).collect(), - value: switch.value().into(), - cases: switch.cases().iter().map(Into::into).collect(), - default_body: switch.default_body().into(), - }) - } - - patio_generated::patio::PatioInstructionValue::PatioUnreachable => { - Self::Unreachable(PatioUnreachable) - } - - patio_generated::patio::PatioInstructionValue::PatioVarLoad => { - let var_load = value.value_as_patio_var_load().unwrap(); - - Self::VarLoad(PatioVarLoad { - destination: var_load.destination().into(), - var: var_load.var().into(), - }) - } - - patio_generated::patio::PatioInstructionValue::PatioVarStore => { - let var_store = value.value_as_patio_var_store().unwrap(); - - Self::VarStore(PatioVarStore { - var: var_store.var().into(), - value: var_store.value().into(), - }) - } - - instruction_type => todo!( - "Unhandled instruction type: {:?} {}", - instruction_type.variant_name(), - instruction_type.0 - ), - } - } -} - -impl From<patio_generated::patio::PatioBlock<'_>> for PatioBlock { - fn from(value: patio_generated::patio::PatioBlock<'_>) -> Self { - Self { - body: value.body().iter().map(Into::into).collect(), - results: value.results().iter().map(Into::into).collect(), - } - } -} - -impl From<patio_generated::patio::PatioSwitchCase<'_>> for PatioSwitchCase { - fn from(value: patio_generated::patio::PatioSwitchCase<'_>) -> Self { - Self { - value: value.value(), - body: value.body().into(), - } - } -} - -// == Operands == - -impl From<patio_generated::patio::PatioOperand<'_>> for PatioOperand { - fn from(value: patio_generated::patio::PatioOperand<'_>) -> Self { - match value.value_type() { - patio_generated::patio::PatioOperandValue::PatioBoolConst => { - let bool_const = value.value_as_patio_bool_const().unwrap(); - Self::BoolConst(bool_const.value()) - } - - patio_generated::patio::PatioOperandValue::PatioByteConst => { - let byte_const = value.value_as_patio_byte_const().unwrap(); - Self::ByteConst(byte_const.value().try_into().unwrap()) - } - - patio_generated::patio::PatioOperandValue::PatioDataPtrConst => { - let data_ptr_const = value.value_as_patio_data_ptr_const().unwrap(); - Self::DataPtrConst(data_ptr_const.value().into()) - } - - patio_generated::patio::PatioOperandValue::PatioFunctionPtrConst => { - let function_ptr_const = value.value_as_patio_function_ptr_const().unwrap(); - Self::FunctionPtrConst(function_ptr_const.name().to_string()) - } - - patio_generated::patio::PatioOperandValue::PatioIntConst => { - let int_const = value.value_as_patio_int_const().unwrap(); - Self::IntConst(int_const.value().into()) - } - - patio_generated::patio::PatioOperandValue::PatioInt32Const => { - let int32_const = value.value_as_patio_int_32_const().unwrap(); - Self::Int32Const(int32_const.value().into()) - } - - patio_generated::patio::PatioOperandValue::PatioLocalRef => { - let local_ref = value.value_as_patio_local_ref().unwrap(); - Self::LocalRef(local_ref.into()) - } - - operand_type => todo!( - "Unhandled operand type: {:?} {}", - operand_type.variant_name(), - operand_type.0 - ), - } - } -} - -impl From<patio_generated::patio::PatioLocalRef<'_>> for PatioLocalRef { - fn from(value: patio_generated::patio::PatioLocalRef<'_>) -> Self { - Self { - name: value.name().to_string(), - } - } -} - -// == Data ptr values == - -impl From<patio_generated::patio::PatioDataPtrValue<'_>> for PatioDataPtrValue { - fn from(value: patio_generated::patio::PatioDataPtrValue<'_>) -> Self { - match value.value_type() { - patio_generated::patio::PatioDataPtrValueValue::PatioDataPtrValueDataElement => { - let data_element = value.value_as_patio_data_ptr_value_data_element().unwrap(); - Self::DataElement { - name: data_element.name().to_string(), - } - } - - patio_generated::patio::PatioDataPtrValueValue::PatioDataPtrValueNull => Self::Null, - - data_ptr_value_type => todo!( - "Unhandled data ptr value type: {:?} {}", - data_ptr_value_type.variant_name(), - data_ptr_value_type.0 - ), - } - } -} - -// == Int values == - -impl From<patio_generated::patio::PatioIntValue<'_>> for PatioIntValue { - fn from(value: patio_generated::patio::PatioIntValue<'_>) -> Self { - match value.value_type() { - PatioIntValueValue::PatioIntValueByteOffsetOf => { - let byte_offset_of = value.value_as_patio_int_value_byte_offset_of().unwrap(); - Self::ByteOffsetOf { - layout: byte_offset_of.layout().into(), - element_offsets: byte_offset_of.element_offsets().iter().collect(), - } - } - - PatioIntValueValue::PatioIntValueByteSizeOf => { - let byte_size_of = value.value_as_patio_int_value_byte_size_of().unwrap(); - Self::ByteSizeOf { - layout: byte_size_of.layout().into(), - } - } - - PatioIntValueValue::PatioIntValueLiteral => { - let literal = value.value_as_patio_int_value_literal().unwrap(); - Self::Literal { - value: literal.value(), - } - } - - int_value_type => todo!( - "Unhandled int value type: {:?} {}", - int_value_type.variant_name(), - int_value_type.0 - ), - } - } -} - -// == Types == - -impl From<patio_generated::patio::PatioType<'_>> for PatioType { - fn from(value: patio_generated::patio::PatioType<'_>) -> Self { - match value.value_type() { - PatioTypeValue::PatioBoolType => Self::Bool, - PatioTypeValue::PatioByteType => Self::Byte, - PatioTypeValue::PatioDataPtrType => Self::DataPtr, - PatioTypeValue::PatioFunctionPtrType => Self::FunctionPtr, - PatioTypeValue::PatioIntType => Self::Int, - PatioTypeValue::PatioInt32Type => Self::Int32, - - type_type => { - todo!( - "Unhandled type type: {:?} {}", - type_type.variant_name(), - type_type.0 - ) - } - } - } -} - -// == Data layouts == - -impl From<patio_generated::patio::PatioDataLayout<'_>> for PatioDataLayout { - fn from(value: patio_generated::patio::PatioDataLayout<'_>) -> Self { - match value.value_type() { - PatioDataLayoutValue::PatioDataLayoutArray => { - let array = value.value_as_patio_data_layout_array().unwrap(); - PatioDataLayout::array(array.element().into(), array.size()) - } - - PatioDataLayoutValue::PatioDataLayoutBool => PatioDataLayout::Bool, - - PatioDataLayoutValue::PatioDataLayoutByte => PatioDataLayout::Byte, - - PatioDataLayoutValue::PatioDataLayoutDataPtr => PatioDataLayout::DataPtr, - - PatioDataLayoutValue::PatioDataLayoutFunctionPtr => PatioDataLayout::FunctionPtr, - - PatioDataLayoutValue::PatioDataLayoutInt => PatioDataLayout::Int, - - PatioDataLayoutValue::PatioDataLayoutInt32 => PatioDataLayout::Int32, - - PatioDataLayoutValue::PatioDataLayoutStruct => { - let struct_ = value.value_as_patio_data_layout_struct().unwrap(); - - PatioDataLayout::struct_( - struct_ - .elements() - .iter() - .map(|element| element.into()) - .collect(), - ) - } - - layout_type => { - todo!( - "Unhandled data layout type: {:?} {}", - layout_type.variant_name(), - layout_type.0 - ) - } - } - } -} - -// == Data values == - -impl From<patio_generated::patio::PatioDataValue<'_>> for PatioDataValue { - fn from(value: patio_generated::patio::PatioDataValue<'_>) -> Self { - match value.value_type() { - PatioDataValueValue::PatioDataValueArray => { - let array = value.value_as_patio_data_value_array().unwrap(); - Self::Array { - element_layout: array.element_layout().into(), - elements: array.elements().iter().map(Into::into).collect(), - } - } - - PatioDataValueValue::PatioDataValueBool => { - let bool = value.value_as_patio_data_value_bool().unwrap(); - Self::Bool(bool.value()) - } - - PatioDataValueValue::PatioDataValueByte => { - let byte = value.value_as_patio_data_value_byte().unwrap(); - Self::Byte(byte.value().try_into().unwrap()) - } - - PatioDataValueValue::PatioDataValueDataPtr => { - let data_ptr = value.value_as_patio_data_value_data_ptr().unwrap(); - Self::DataPtr(data_ptr.value().into()) - } - - PatioDataValueValue::PatioDataValueInt => { - let int = value.value_as_patio_data_value_int().unwrap(); - Self::Int(int.value().into()) - } - - PatioDataValueValue::PatioDataValueInt32 => { - let int32 = value.value_as_patio_data_value_int_32().unwrap(); - Self::Int32(int32.value().into()) - } - - PatioDataValueValue::PatioDataValueStruct => { - let struct_ = value.value_as_patio_data_value_struct().unwrap(); - Self::Struct { - elements: struct_.elements().iter().map(Into::into).collect(), - } - } - - value_type => { - todo!( - "Unhandled data value type: {:?} {}", - value_type.variant_name(), - value_type.0 - ) - } - } - } -} diff --git a/patio-to-cranelift/src/patio/instructions.rs b/patio-to-cranelift/src/patio/instructions.rs deleted file mode 100644 index bdfcc28e..00000000 --- a/patio-to-cranelift/src/patio/instructions.rs +++ /dev/null @@ -1,153 +0,0 @@ -use crate::patio::{ - operands::{PatioLocalRef, PatioOperand}, - types::PatioDataLayout, -}; - -pub(crate) enum PatioInstruction { - Block(PatioBlock), - BoolToInt(PatioBoolToInt), - Call(PatioCall), - CallPointer(PatioCallPointer), - DataPtrToInt(PatioDataPtrToInt), - If(PatioIf), - IntAdd(PatioIntAdd), - IntEquals(PatioIntEquals), - IntNotEqual(PatioIntNotEqual), - IntSub(PatioIntSub), - IntToBool(PatioIntToBool), - IntToDataPtr(PatioIntToDataPtr), - LocalStore(PatioLocalStore), - Loop(PatioLoop), - LoopBreak(PatioLoopBreak), - LoopContinue(PatioLoopContinue), - MemoryLoad(PatioMemoryLoad), - MemoryStore(PatioMemoryStore), - Return(PatioReturn), - Switch(PatioSwitch), - Unreachable(PatioUnreachable), - VarLoad(PatioVarLoad), - VarStore(PatioVarStore), -} - -pub(crate) struct PatioBlock { - pub(crate) body: Vec<PatioInstruction>, - pub(crate) results: Vec<PatioOperand>, -} - -pub(crate) struct PatioBoolToInt { - pub(crate) destination: PatioLocalRef, - pub(crate) value: PatioOperand, -} - -pub(crate) struct PatioCall { - pub(crate) destinations: Vec<PatioLocalRef>, - pub(crate) function_name: String, - pub(crate) args: Vec<PatioOperand>, -} - -pub(crate) struct PatioCallPointer { - pub(crate) destinations: Vec<PatioLocalRef>, - pub(crate) function_pointer: PatioOperand, - pub(crate) args: Vec<PatioOperand>, -} - -pub(crate) struct PatioDataPtrToInt { - pub(crate) destination: PatioLocalRef, - pub(crate) value: PatioOperand, -} - -pub(crate) struct PatioIf { - pub(crate) destinations: Vec<PatioLocalRef>, - pub(crate) condition: PatioOperand, - pub(crate) true_body: PatioBlock, - pub(crate) false_body: PatioBlock, -} - -pub(crate) struct PatioIntAdd { - pub(crate) destination: PatioLocalRef, - pub(crate) left: PatioOperand, - pub(crate) right: PatioOperand, -} - -pub(crate) struct PatioIntEquals { - pub(crate) destination: PatioLocalRef, - pub(crate) left: PatioOperand, - pub(crate) right: PatioOperand, -} - -pub(crate) struct PatioIntNotEqual { - pub(crate) destination: PatioLocalRef, - pub(crate) left: PatioOperand, - pub(crate) right: PatioOperand, -} - -pub(crate) struct PatioIntSub { - pub(crate) destination: PatioLocalRef, - pub(crate) left: PatioOperand, - pub(crate) right: PatioOperand, -} - -pub(crate) struct PatioIntToBool { - pub(crate) destination: PatioLocalRef, - pub(crate) value: PatioOperand, -} - -pub(crate) struct PatioIntToDataPtr { - pub(crate) destination: PatioLocalRef, - pub(crate) value: PatioOperand, -} - -pub(crate) struct PatioLocalStore { - pub(crate) destination: PatioLocalRef, - pub(crate) value: PatioOperand, -} - -pub(crate) struct PatioLoop { - pub(crate) body: Vec<PatioInstruction>, -} - -pub(crate) struct PatioLoopBreak; - -pub(crate) struct PatioLoopContinue; - -pub(crate) struct PatioMemoryLoad { - pub(crate) destination: PatioLocalRef, - pub(crate) pointer: PatioOperand, - pub(crate) layout: PatioDataLayout, - pub(crate) element_offsets: Vec<u32>, -} - -pub(crate) struct PatioMemoryStore { - pub(crate) pointer: PatioOperand, - pub(crate) layout: PatioDataLayout, - pub(crate) element_offsets: Vec<u32>, - pub(crate) value: PatioOperand, -} - -pub(crate) struct PatioReturn { - pub(crate) values: Vec<PatioOperand>, -} - -pub(crate) struct PatioSwitch { - pub(crate) destinations: Vec<PatioLocalRef>, - pub(crate) value: PatioOperand, - pub(crate) cases: Vec<PatioSwitchCase>, - pub(crate) default_body: PatioBlock, -} - -pub(crate) struct PatioSwitchCase { - pub(crate) value: u32, - pub(crate) body: PatioBlock, -} - -pub(crate) struct PatioUnreachable; - -pub(crate) struct PatioVarLoad { - pub(crate) destination: PatioLocalRef, - pub(crate) var: PatioLocalRef, -} - -pub(crate) struct PatioVarStore { - pub(crate) var: PatioLocalRef, - pub(crate) value: PatioOperand, -} diff --git a/patio-to-cranelift/src/patio/mod.rs b/patio-to-cranelift/src/patio/mod.rs index 4316b519..3027cda4 100644 --- a/patio-to-cranelift/src/patio/mod.rs +++ b/patio-to-cranelift/src/patio/mod.rs @@ -1,6 +1,67 @@ -pub(crate) mod compilation_unit; -pub(crate) mod flatbuffers; -pub(crate) mod instructions; -pub(crate) mod operands; -pub(crate) mod types; -pub(crate) mod values; +include!("../gen/patio.rs"); + +pub(crate) mod instructions { + include!("../gen/patio/instructions.rs"); + + #[allow(unused)] + pub(crate) mod transient_0 { + include!("../gen/patio/instructions/transient_0.rs"); + } +} + +pub(crate) mod operands { + include!("../gen/patio/operands.rs"); + + #[allow(unused)] + pub(crate) mod transient_0 { + include!("../gen/patio/operands/transient_0.rs"); + } +} + +pub(crate) mod types { + include!("../gen/patio/types.rs"); + + impl PatioDataValue { + pub(crate) fn layout(&self) -> PatioDataLayout { + match self { + PatioDataValue::PatioDataValueArray(array) => PatioDataLayoutArray { + element: array.element_layout.clone(), + size: array.elements.len().try_into().unwrap(), + } + .into(), + PatioDataValue::PatioDataValueBool(_) => PatioDataLayoutBool.into(), + PatioDataValue::PatioDataValueByte(_) => PatioDataLayoutByte.into(), + PatioDataValue::PatioDataValueDataPtr(_) => PatioDataLayoutDataPtr.into(), + PatioDataValue::PatioDataValueInt(_) => PatioDataLayoutInt.into(), + PatioDataValue::PatioDataValueInt32(_) => PatioDataLayoutInt32.into(), + PatioDataValue::PatioDataValueStruct(value_struct) => PatioDataLayoutStruct { + elements: value_struct + .elements + .iter() + .map(|element| element.layout()) + .collect(), + } + .into(), + } + } + } + + #[allow(unused)] + pub(crate) mod transient_0 { + include!("../gen/patio/types/transient_0.rs"); + } +} + +pub(crate) mod values { + include!("../gen/patio/values.rs"); + + #[allow(unused)] + pub(crate) mod transient_0 { + include!("../gen/patio/values/transient_0.rs"); + } +} + +#[allow(unused)] +pub(crate) mod transient_0 { + include!("../gen/patio/transient_0.rs"); +} diff --git a/patio-to-cranelift/src/patio/operands.rs b/patio-to-cranelift/src/patio/operands.rs deleted file mode 100644 index ca8eb3bc..00000000 --- a/patio-to-cranelift/src/patio/operands.rs +++ /dev/null @@ -1,17 +0,0 @@ -use crate::patio::values::{PatioDataPtrValue, PatioIntValue}; - -#[derive(Debug)] -pub(crate) enum PatioOperand { - BoolConst(bool), - ByteConst(u8), - DataPtrConst(PatioDataPtrValue), - FunctionPtrConst(String), - IntConst(PatioIntValue), - Int32Const(PatioIntValue), - LocalRef(PatioLocalRef), -} - -#[derive(Debug)] -pub(crate) struct PatioLocalRef { - pub(crate) name: String, -} diff --git a/patio-to-cranelift/src/patio/types.rs b/patio-to-cranelift/src/patio/types.rs deleted file mode 100644 index 49bce09a..00000000 --- a/patio-to-cranelift/src/patio/types.rs +++ /dev/null @@ -1,39 +0,0 @@ -#[derive(Clone, Copy, Eq, PartialEq)] -pub(crate) enum PatioType { - Bool, - Byte, - DataPtr, - FunctionPtr, - Int, - Int32, -} - -#[derive(Clone, Debug, PartialEq)] -pub(crate) enum PatioDataLayout { - Array { - element: Box<PatioDataLayout>, - size: u32, - }, - Bool, - Byte, - DataPtr, - FunctionPtr, - Int, - Int32, - Struct { - elements: Vec<PatioDataLayout>, - }, -} - -impl PatioDataLayout { - pub(crate) fn array(element: PatioDataLayout, size: u32) -> Self { - Self::Array { - element: Box::new(element), - size, - } - } - - pub(crate) fn struct_(elements: Vec<PatioDataLayout>) -> Self { - Self::Struct { elements } - } -} diff --git a/patio-to-cranelift/src/patio/values.rs b/patio-to-cranelift/src/patio/values.rs deleted file mode 100644 index fe511437..00000000 --- a/patio-to-cranelift/src/patio/values.rs +++ /dev/null @@ -1,55 +0,0 @@ -use crate::patio::types::PatioDataLayout; - -pub(crate) enum PatioDataValue { - Array { - element_layout: PatioDataLayout, - elements: Vec<PatioDataValue>, - }, - Bool(bool), - Byte(u8), - DataPtr(PatioDataPtrValue), - Int(PatioIntValue), - Int32(PatioIntValue), - Struct { - elements: Vec<PatioDataValue>, - }, -} - -impl PatioDataValue { - pub(crate) fn layout(&self) -> PatioDataLayout { - match self { - PatioDataValue::Array { - element_layout, - elements, - } => PatioDataLayout::array(element_layout.clone(), elements.len().try_into().unwrap()), - PatioDataValue::Bool(_) => PatioDataLayout::Bool, - PatioDataValue::Byte(_) => PatioDataLayout::Byte, - PatioDataValue::DataPtr(_) => PatioDataLayout::DataPtr, - PatioDataValue::Int(_) => PatioDataLayout::Int, - PatioDataValue::Int32(_) => PatioDataLayout::Int32, - PatioDataValue::Struct { elements } => { - PatioDataLayout::struct_(elements.iter().map(|element| element.layout()).collect()) - } - } - } -} - -#[derive(Debug)] -pub(crate) enum PatioDataPtrValue { - DataElement { name: String }, - Null, -} - -#[derive(Debug)] -pub(crate) enum PatioIntValue { - ByteOffsetOf { - layout: PatioDataLayout, - element_offsets: Vec<u32>, - }, - ByteSizeOf { - layout: PatioDataLayout, - }, - Literal { - value: i32, - }, -} @@ -124,7 +124,7 @@ </goals> <configuration> <sources> - <source>src/gen/java</source> + <source>src/transient-0/java</source> </sources> </configuration> </execution> diff --git a/src/main/java/org/shedlang/compiler/backends/cranelift/CraneliftBackend.java b/src/main/java/org/shedlang/compiler/backends/cranelift/CraneliftBackend.java index 75794092..31fdb1af 100644 --- a/src/main/java/org/shedlang/compiler/backends/cranelift/CraneliftBackend.java +++ b/src/main/java/org/shedlang/compiler/backends/cranelift/CraneliftBackend.java @@ -1,18 +1,17 @@ package org.shedlang.compiler.backends.cranelift; -import com.google.flatbuffers.FlatBufferBuilder; import org.pcollections.PVector; import org.shedlang.compiler.backends.Backend; import org.shedlang.compiler.backends.PatioBackends; import org.shedlang.compiler.backends.llvm.LlvmBackend; -import org.shedlang.compiler.backends.targets.NativeTarget; import org.shedlang.compiler.backends.paths.PartialTargetPath; import org.shedlang.compiler.backends.paths.TargetDir; +import org.shedlang.compiler.backends.targets.NativeTarget; import org.shedlang.compiler.config.ProfileConfig; import org.shedlang.compiler.config.ProjectConfig; import org.shedlang.compiler.filesystem.ShedCompilerFiles; import org.shedlang.compiler.patio.PatioCompilationUnit; -import org.shedlang.compiler.patio.serialization.PatioToFlatbuffers; +import org.shedlang.compiler.patio.serialization.PatioToTransient0; import org.shedlang.compiler.runtime.ShedRuntime; import org.shedlang.compiler.shid.ShidNamespace; import org.shedlang.compiler.typechecker.TypeInfos; @@ -20,6 +19,7 @@ import org.shedlang.compiler.types.NamespaceName; import org.shedlang.compiler.util.P; import org.shedlang.compiler.util.processes.ProcessError; +import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -62,14 +62,11 @@ public class CraneliftBackend implements Backend { Optional<String> mainFunctionName, PartialTargetPath partialTargetPath ) throws IOException, InterruptedException { - var fbsBuilder = new FlatBufferBuilder(); - var compilationUnitOffset = PatioToFlatbuffers.serializeCompilationUnit(fbsBuilder, patio); - fbsBuilder.finish(compilationUnitOffset); - - // TODO: avoid the copy var patioPath = partialTargetPath.withExtension(".patio"); Files.createDirectories(patioPath.getParent()); - Files.write(patioPath, fbsBuilder.sizedByteArray()); + try (var outputStream = new FileOutputStream(patioPath.toFile())) { + PatioToTransient0.serializeCompilationUnit(patio, outputStream); + } var patioToCraneliftArgs = new ArrayList<String>(); patioToCraneliftArgs.add( diff --git a/src/main/java/org/shedlang/compiler/patio/serialization/PatioToFlatbuffers.java b/src/main/java/org/shedlang/compiler/patio/serialization/PatioToFlatbuffers.java deleted file mode 100644 index 1f2e34c8..00000000 --- a/src/main/java/org/shedlang/compiler/patio/serialization/PatioToFlatbuffers.java +++ /dev/null @@ -1,2712 +0,0 @@ -package org.shedlang.compiler.patio.serialization; - -import com.google.flatbuffers.FlatBufferBuilder; -import com.google.flatbuffers.IntVector; -import org.shedlang.compiler.patio.*; -import org.shedlang.compiler.patio.flatbuffers.*; -import org.shedlang.compiler.patio.instructions.*; -import org.shedlang.compiler.patio.operands.*; -import org.shedlang.compiler.patio.types.*; -import org.shedlang.compiler.patio.values.*; -import org.shedlang.compiler.sources.Source; -import org.shedlang.compiler.sources.serialization.SourceToFlatbuffers; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.function.Function; - -public class PatioToFlatbuffers { - // == Compilation units == - - public static int serializeCompilationUnit( - FlatBufferBuilder builder, - PatioCompilationUnit compilationUnit - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - compilationUnit.source(), - Optional.empty() - ); - - var elementsOffsetsFbs = compilationUnit.elements().stream() - .mapToInt(element -> serializeCompilationUnitElement(builder, element, compilationUnit.source())) - .toArray(); - var elementsVectorFbs = PatioCompilationUnitFbs.createElementsVector(builder, elementsOffsetsFbs); - - PatioCompilationUnitFbs.startPatioCompilationUnitFbs(builder); - PatioCompilationUnitFbs.addSource(builder, sourceFbs); - PatioCompilationUnitFbs.addElements(builder, elementsVectorFbs); - return PatioCompilationUnitFbs.endPatioCompilationUnitFbs(builder); - } - - public static PatioCompilationUnit deserializeCompilationUnit( - PatioCompilationUnitFbs compilationUnitFbs - ) { - var source = SourceToFlatbuffers.deserializeSource( - compilationUnitFbs.source(), - Optional.empty() - ); - - var elements = deserializeVector( - compilationUnitFbs::elements, - compilationUnitFbs.elementsLength(), - elementFbs -> deserializeCompilationUnitElement(elementFbs, source) - ); - - return new PatioCompilationUnit(elements, source); - } - - // == Compilation unit elements == - - public static int serializeCompilationUnitElement( - FlatBufferBuilder builder, - PatioCompilationUnitElement element, - Source parentSource - ) { - return switch (element) { - case PatioDataElementImmutableDefinition dataElementImmutableDefinition -> { - var valueFbs = serializeDataElementImmutableDefinition(builder, dataElementImmutableDefinition, parentSource); - - PatioCompilationUnitElementFbs.startPatioCompilationUnitElementFbs(builder); - PatioCompilationUnitElementFbs.addValueType( - builder, - PatioCompilationUnitElementValueFbs.PatioDataElementImmutableDefinitionFbs - ); - PatioCompilationUnitElementFbs.addValue(builder, valueFbs); - yield PatioCompilationUnitElementFbs.endPatioCompilationUnitElementFbs(builder); - } - - case PatioDataElementMutableDeclaration dataElementMutableDeclaration -> { - var valueFbs = serializeDataElementMutableDeclaration(builder, dataElementMutableDeclaration, parentSource); - - PatioCompilationUnitElementFbs.startPatioCompilationUnitElementFbs(builder); - PatioCompilationUnitElementFbs.addValueType( - builder, - PatioCompilationUnitElementValueFbs.PatioDataElementMutableDeclarationFbs - ); - PatioCompilationUnitElementFbs.addValue(builder, valueFbs); - yield PatioCompilationUnitElementFbs.endPatioCompilationUnitElementFbs(builder); - } - - case PatioDataElementMutableDefinition dataElementMutableDefinition -> { - var valueFbs = serializeDataElementMutableDefinition(builder, dataElementMutableDefinition, parentSource); - - PatioCompilationUnitElementFbs.startPatioCompilationUnitElementFbs(builder); - PatioCompilationUnitElementFbs.addValueType( - builder, - PatioCompilationUnitElementValueFbs.PatioDataElementMutableDefinitionFbs - ); - PatioCompilationUnitElementFbs.addValue(builder, valueFbs); - yield PatioCompilationUnitElementFbs.endPatioCompilationUnitElementFbs(builder); - } - - case PatioExceptionTypeDefinition exceptionTypeDefinition -> { - var valueFbs = serializeExceptionTypeDefinition(builder, exceptionTypeDefinition, parentSource); - - PatioCompilationUnitElementFbs.startPatioCompilationUnitElementFbs(builder); - PatioCompilationUnitElementFbs.addValueType( - builder, - PatioCompilationUnitElementValueFbs.PatioExceptionTypeDefinitionFbs - ); - PatioCompilationUnitElementFbs.addValue(builder, valueFbs); - yield PatioCompilationUnitElementFbs.endPatioCompilationUnitElementFbs(builder); - } - - case PatioFunctionDeclaration functionDeclaration -> { - var valueFbs = serializeFunctionDeclaration(builder, functionDeclaration, parentSource); - - PatioCompilationUnitElementFbs.startPatioCompilationUnitElementFbs(builder); - PatioCompilationUnitElementFbs.addValueType( - builder, - PatioCompilationUnitElementValueFbs.PatioFunctionDeclarationFbs - ); - PatioCompilationUnitElementFbs.addValue(builder, valueFbs); - yield PatioCompilationUnitElementFbs.endPatioCompilationUnitElementFbs(builder); - } - - case PatioFunctionDefinition functionDefinition -> { - var valueFbs = serializeFunctionDefinition(builder, functionDefinition, parentSource); - - PatioCompilationUnitElementFbs.startPatioCompilationUnitElementFbs(builder); - PatioCompilationUnitElementFbs.addValueType( - builder, - PatioCompilationUnitElementValueFbs.PatioFunctionDefinitionFbs - ); - PatioCompilationUnitElementFbs.addValue(builder, valueFbs); - yield PatioCompilationUnitElementFbs.endPatioCompilationUnitElementFbs(builder); - } - }; - } - - public static PatioCompilationUnitElement deserializeCompilationUnitElement( - PatioCompilationUnitElementFbs elementFbs, - Source parentSource - ) { - return switch (elementFbs.valueType()) { - case PatioCompilationUnitElementValueFbs.PatioDataElementImmutableDefinitionFbs -> { - var dataElementImmutableDefinitionFbs = - (PatioDataElementImmutableDefinitionFbs) elementFbs.value(new PatioDataElementImmutableDefinitionFbs()); - yield deserializeDataElementImmutableDefinition(dataElementImmutableDefinitionFbs, parentSource); - } - - case PatioCompilationUnitElementValueFbs.PatioDataElementMutableDeclarationFbs -> { - var dataElementMutableDeclarationFbs = - (PatioDataElementMutableDeclarationFbs) elementFbs.value(new PatioDataElementMutableDeclarationFbs()); - yield deserializeDataElementMutableDeclaration(dataElementMutableDeclarationFbs, parentSource); - } - - case PatioCompilationUnitElementValueFbs.PatioDataElementMutableDefinitionFbs -> { - var dataElementMutableDefinitionFbs = - (PatioDataElementMutableDefinitionFbs) elementFbs.value(new PatioDataElementMutableDefinitionFbs()); - yield deserializeDataElementMutableDefinition(dataElementMutableDefinitionFbs, parentSource); - } - - case PatioCompilationUnitElementValueFbs.PatioExceptionTypeDefinitionFbs -> { - var exceptionTypeDefinitionFbs = - (PatioExceptionTypeDefinitionFbs) elementFbs.value(new PatioExceptionTypeDefinitionFbs()); - yield deserializeExceptionTypeDefinition(exceptionTypeDefinitionFbs, parentSource); - } - - case PatioCompilationUnitElementValueFbs.PatioFunctionDeclarationFbs -> { - var functionDeclarationFbs = - (PatioFunctionDeclarationFbs) elementFbs.value(new PatioFunctionDeclarationFbs()); - yield deserializeFunctionDeclaration(functionDeclarationFbs, parentSource); - } - - case PatioCompilationUnitElementValueFbs.PatioFunctionDefinitionFbs -> { - var functionDefinitionFbs = - (PatioFunctionDefinitionFbs) elementFbs.value(new PatioFunctionDefinitionFbs()); - yield deserializeFunctionDefinition(functionDefinitionFbs, parentSource); - } - - default -> - throw new UnsupportedOperationException("TODO"); - }; - } - - private static int serializeDataElementImmutableDefinition( - FlatBufferBuilder builder, - PatioDataElementImmutableDefinition dataElementImmutableDefinition, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - dataElementImmutableDefinition.source(), - parentSource - ); - - var nameFbs = builder.createString(dataElementImmutableDefinition.name()); - - var visibilityFbs = serializeVisibility(dataElementImmutableDefinition.visibility()); - - var valueFbs = serializeDataValue(builder, dataElementImmutableDefinition.value()); - - PatioDataElementImmutableDefinitionFbs.startPatioDataElementImmutableDefinitionFbs(builder); - PatioDataElementImmutableDefinitionFbs.addSource(builder, sourceFbs); - PatioDataElementImmutableDefinitionFbs.addName(builder, nameFbs); - PatioDataElementImmutableDefinitionFbs.addVisibility( - builder, - visibilityFbs - ); - PatioDataElementImmutableDefinitionFbs.addValue(builder, valueFbs); - return PatioDataElementImmutableDefinitionFbs.endPatioDataElementImmutableDefinitionFbs(builder); - } - - private static PatioDataElementImmutableDefinition deserializeDataElementImmutableDefinition( - PatioDataElementImmutableDefinitionFbs dataElementImmutableDefinitionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource( - dataElementImmutableDefinitionFbs.source(), - parentSource - ); - - var name = dataElementImmutableDefinitionFbs.name(); - var visibility = deserializeVisibility(dataElementImmutableDefinitionFbs.visibility()); - var value = deserializeDataValue(dataElementImmutableDefinitionFbs.value()); - - return new PatioDataElementImmutableDefinition(name, visibility, value, source); - } - - private static int serializeDataElementMutableDeclaration( - FlatBufferBuilder builder, - PatioDataElementMutableDeclaration dataElementMutableDeclaration, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - dataElementMutableDeclaration.source(), - parentSource - ); - - var nameFbs = builder.createString(dataElementMutableDeclaration.name()); - - var layoutFbs = serializeDataLayout(builder, dataElementMutableDeclaration.layout()); - - PatioDataElementMutableDeclarationFbs.startPatioDataElementMutableDeclarationFbs(builder); - PatioDataElementMutableDeclarationFbs.addSource(builder, sourceFbs); - PatioDataElementMutableDeclarationFbs.addName(builder, nameFbs); - PatioDataElementMutableDeclarationFbs.addLayout(builder, layoutFbs); - return PatioDataElementMutableDeclarationFbs.endPatioDataElementMutableDeclarationFbs(builder); - } - - private static PatioDataElementMutableDeclaration deserializeDataElementMutableDeclaration( - PatioDataElementMutableDeclarationFbs dataElementMutableDeclarationFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource( - dataElementMutableDeclarationFbs.source(), - parentSource - ); - - var name = dataElementMutableDeclarationFbs.name(); - var layout = deserializeDataLayout(dataElementMutableDeclarationFbs.layout()); - - return new PatioDataElementMutableDeclaration(name, layout, source); - } - - private static int serializeDataElementMutableDefinition( - FlatBufferBuilder builder, - PatioDataElementMutableDefinition dataElementMutableDefinition, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - dataElementMutableDefinition.source(), - parentSource - ); - - var nameFbs = builder.createString(dataElementMutableDefinition.name()); - - var visibilityFbs = serializeVisibility(dataElementMutableDefinition.visibility()); - - var initialValueFbs = serializeDataValue(builder, dataElementMutableDefinition.initialValue()); - - PatioDataElementMutableDefinitionFbs.startPatioDataElementMutableDefinitionFbs(builder); - PatioDataElementMutableDefinitionFbs.addSource(builder, sourceFbs); - PatioDataElementMutableDefinitionFbs.addName(builder, nameFbs); - PatioDataElementMutableDefinitionFbs.addVisibility( - builder, - visibilityFbs - ); - PatioDataElementMutableDefinitionFbs.addInitialValue(builder, initialValueFbs); - return PatioDataElementMutableDefinitionFbs.endPatioDataElementMutableDefinitionFbs(builder); - } - - private static PatioDataElementMutableDefinition deserializeDataElementMutableDefinition( - PatioDataElementMutableDefinitionFbs dataElementMutableDefinitionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource( - dataElementMutableDefinitionFbs.source(), - parentSource - ); - - var name = dataElementMutableDefinitionFbs.name(); - var visibility = deserializeVisibility(dataElementMutableDefinitionFbs.visibility()); - var initialValue = deserializeDataValue(dataElementMutableDefinitionFbs.initialValue()); - - return new PatioDataElementMutableDefinition(name, visibility, initialValue, source); - } - - private static int serializeExceptionTypeDefinition( - FlatBufferBuilder builder, - PatioExceptionTypeDefinition exceptionTypeDefinition, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - exceptionTypeDefinition.source(), - parentSource - ); - - var nameFbs = builder.createString(exceptionTypeDefinition.name()); - var valueTypeFbs = serializeType(builder, exceptionTypeDefinition.valueType()); - - PatioExceptionTypeDefinitionFbs.startPatioExceptionTypeDefinitionFbs(builder); - PatioExceptionTypeDefinitionFbs.addSource(builder, sourceFbs); - PatioExceptionTypeDefinitionFbs.addName(builder, nameFbs); - PatioExceptionTypeDefinitionFbs.addValueType(builder, valueTypeFbs); - return PatioExceptionTypeDefinitionFbs.endPatioExceptionTypeDefinitionFbs(builder); - } - - private static PatioExceptionTypeDefinition deserializeExceptionTypeDefinition( - PatioExceptionTypeDefinitionFbs exceptionTypeDefinitionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource( - exceptionTypeDefinitionFbs.source(), - parentSource - ); - - var name = exceptionTypeDefinitionFbs.name(); - var valueType = deserializeType(exceptionTypeDefinitionFbs.valueType()); - - return new PatioExceptionTypeDefinition(name, valueType, source); - } - - private static int serializeFunctionDeclaration( - FlatBufferBuilder builder, - PatioFunctionDeclaration functionDeclaration, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - functionDeclaration.source(), - parentSource - ); - - var nameFbs = builder.createString(functionDeclaration.name()); - - var paramsOffsetsFbs = functionDeclaration.params().stream() - .mapToInt(param -> serializeLocal(builder, param)) - .toArray(); - var paramsVectorFbs = PatioFunctionDeclarationFbs.createParamsVector(builder, paramsOffsetsFbs); - - var returnTypesOffsetsFbs = functionDeclaration.returnTypes().stream() - .mapToInt(returnType -> serializeType(builder, returnType)) - .toArray(); - var returnTypesVectorFbs = PatioFunctionDeclarationFbs.createReturnTypesVector(builder, returnTypesOffsetsFbs); - - PatioFunctionDeclarationFbs.startPatioFunctionDeclarationFbs(builder); - PatioFunctionDeclarationFbs.addSource(builder, sourceFbs); - PatioFunctionDeclarationFbs.addName(builder, nameFbs); - PatioFunctionDeclarationFbs.addParams(builder, paramsVectorFbs); - PatioFunctionDeclarationFbs.addReturnTypes(builder, returnTypesVectorFbs); - return PatioFunctionDeclarationFbs.endPatioFunctionDeclarationFbs(builder); - } - - private static PatioFunctionDeclaration deserializeFunctionDeclaration( - PatioFunctionDeclarationFbs functionDeclarationFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource( - functionDeclarationFbs.source(), - parentSource - ); - - var name = functionDeclarationFbs.name(); - var params = deserializeVector( - functionDeclarationFbs::params, - functionDeclarationFbs.paramsLength(), - PatioToFlatbuffers::deserializeLocal - ); - var returnTypes = deserializeVector( - functionDeclarationFbs::returnTypes, - functionDeclarationFbs.returnTypesLength(), - PatioToFlatbuffers::deserializeType - ); - - return new PatioFunctionDeclaration(name, params, returnTypes, source); - } - - private static int serializeFunctionDefinition( - FlatBufferBuilder builder, - PatioFunctionDefinition functionDefinition, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - functionDefinition.source(), - parentSource - ); - - var nameFbs = builder.createString(functionDefinition.name()); - - var visibilityFbs = serializeVisibility(functionDefinition.visibility()); - - var localsOffsetsFbs = functionDefinition.locals().stream() - .mapToInt(local -> serializeLocal(builder, local)) - .toArray(); - var localsVectorFbs = PatioFunctionDefinitionFbs.createLocalsVector(builder, localsOffsetsFbs); - - var returnTypesOffsetsFbs = functionDefinition.returnTypes().stream() - .mapToInt(returnType -> serializeType(builder, returnType)) - .toArray(); - var returnTypesVectorFbs = PatioFunctionDefinitionFbs.createReturnTypesVector(builder, returnTypesOffsetsFbs); - - var bodyOffsetsFbs = functionDefinition.body().stream() - .mapToInt(bodyInstruction -> serializeInstruction(builder, bodyInstruction, functionDefinition.source())) - .toArray(); - var bodyVectorFbs = PatioFunctionDefinitionFbs.createBodyVector(builder, bodyOffsetsFbs); - - PatioFunctionDefinitionFbs.startPatioFunctionDefinitionFbs(builder); - PatioFunctionDefinitionFbs.addSource(builder, sourceFbs); - PatioFunctionDefinitionFbs.addName(builder, nameFbs); - PatioFunctionDefinitionFbs.addVisibility( - builder, - visibilityFbs - ); - PatioFunctionDefinitionFbs.addLocals(builder, localsVectorFbs); - PatioFunctionDefinitionFbs.addReturnTypes(builder, returnTypesVectorFbs); - PatioFunctionDefinitionFbs.addBody(builder, bodyVectorFbs); - return PatioFunctionDefinitionFbs.endPatioFunctionDefinitionFbs(builder); - } - - private static PatioFunctionDefinition deserializeFunctionDefinition( - PatioFunctionDefinitionFbs functionDefinitionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource( - functionDefinitionFbs.source(), - parentSource - ); - - var name = functionDefinitionFbs.name(); - var visibility = deserializeVisibility(functionDefinitionFbs.visibility()); - var locals = deserializeVector( - functionDefinitionFbs::locals, - functionDefinitionFbs.localsLength(), - PatioToFlatbuffers::deserializeLocal - ); - var returnTypes = deserializeVector( - functionDefinitionFbs::returnTypes, - functionDefinitionFbs.returnTypesLength(), - PatioToFlatbuffers::deserializeType - ); - var body = deserializeVector( - functionDefinitionFbs::body, - functionDefinitionFbs.bodyLength(), - instructionFbs -> deserializeInstruction(instructionFbs, source) - ); - - return new PatioFunctionDefinition(name, visibility, locals, returnTypes, body, source); - } - - // == Visibility == - - private static int serializeVisibility(PatioVisibility visibility) { - return switch (visibility) { - case PRIVATE -> - PatioVisibilityFbs.PRIVATE; - - case PUBLIC -> - PatioVisibilityFbs.PUBLIC; - }; - } - - private static PatioVisibility deserializeVisibility(int visibilityFbs) { - return switch (visibilityFbs) { - case PatioVisibilityFbs.PRIVATE -> - PatioVisibility.PRIVATE; - - case PatioVisibilityFbs.PUBLIC -> - PatioVisibility.PUBLIC; - - default -> - throw new UnsupportedOperationException("TODO"); - }; - } - - // == Locals == - - private static int serializeLocal(FlatBufferBuilder builder, PatioLocal local) { - var nameFbs = builder.createString(local.name()); - var typeFbs = serializeType(builder, local.type()); - var localTypeFbs = serializeLocalType(local.localType()); - - PatioLocalFbs.startPatioLocalFbs(builder); - PatioLocalFbs.addName(builder, nameFbs); - PatioLocalFbs.addType(builder, typeFbs); - PatioLocalFbs.addLocalType(builder, localTypeFbs); - return PatioLocalFbs.endPatioLocalFbs(builder); - } - - private static PatioLocal deserializeLocal(PatioLocalFbs localFbs) { - var name = localFbs.name(); - var type = deserializeType(localFbs.type()); - var localType = deserializeLocalType(localFbs.localType()); - - return new PatioLocal(name, type, localType); - } - - private static int serializeLocalType(PatioLocalType localType) { - return switch (localType) { - case PARAM -> - PatioLocalTypeFbs.PARAM; - - case VAL -> - PatioLocalTypeFbs.VAL; - - case VAR -> - PatioLocalTypeFbs.VAR; - }; - } - - private static PatioLocalType deserializeLocalType(int localTypeFbs) { - return switch (localTypeFbs) { - case PatioLocalTypeFbs.PARAM -> - PatioLocalType.PARAM; - - case PatioLocalTypeFbs.VAL -> - PatioLocalType.VAL; - - case PatioLocalTypeFbs.VAR -> - PatioLocalType.VAR; - - default -> - throw new UnsupportedOperationException("TODO"); - }; - } - - // == Instructions == - - public static int serializeInstruction( - FlatBufferBuilder builder, - PatioInstruction instruction, - Source parentSource - ) { - return switch (instruction) { - case PatioBlock block -> { - var blockFbs = serializeBlock(builder, block, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioBlockFbs); - PatioInstructionFbs.addValue(builder, blockFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioBoolToInt boolToInt -> { - var boolToIntFbs = serializeBoolToInt(builder, boolToInt, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioBoolToIntFbs); - PatioInstructionFbs.addValue(builder, boolToIntFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioCall call -> { - var callFbs = serializeCall(builder, call, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioCallFbs); - PatioInstructionFbs.addValue(builder, callFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioCallPointer callPointer -> { - var callPointerFbs = serializeCallPointer(builder, callPointer, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioCallPointerFbs); - PatioInstructionFbs.addValue(builder, callPointerFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioDataPtrToInt dataPtrToInt -> { - var dataPtrToIntFbs = serializeDataPtrToInt(builder, dataPtrToInt, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioDataPtrToIntFbs); - PatioInstructionFbs.addValue(builder, dataPtrToIntFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioIf if_ -> { - var ifFbs = serializeIf(builder, if_, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioIfFbs); - PatioInstructionFbs.addValue(builder, ifFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioIntAdd intAdd -> { - var intAddFbs = serializeIntAdd(builder, intAdd, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioIntAddFbs); - PatioInstructionFbs.addValue(builder, intAddFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioIntEquals intEquals -> { - var intEqualsFbs = serializeIntEquals(builder, intEquals, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioIntEqualsFbs); - PatioInstructionFbs.addValue(builder, intEqualsFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioIntNotEqual intNotEqual -> { - var intNotEqualFbs = serializeIntNotEqual(builder, intNotEqual, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioIntNotEqualFbs); - PatioInstructionFbs.addValue(builder, intNotEqualFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioIntSub intSub -> { - var intSubFbs = serializeIntSub(builder, intSub, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioIntSubFbs); - PatioInstructionFbs.addValue(builder, intSubFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioIntToBool intToBool -> { - var intToBoolFbs = serializeIntToBool(builder, intToBool, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioIntToBoolFbs); - PatioInstructionFbs.addValue(builder, intToBoolFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioIntToDataPtr intToDataPtr -> { - var intToDataPtrFbs = serializeIntToDataPtr(builder, intToDataPtr, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioIntToDataPtrFbs); - PatioInstructionFbs.addValue(builder, intToDataPtrFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioLocalStore localStore -> { - var localStoreFbs = serializeLocalStore(builder, localStore, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioLocalStoreFbs); - PatioInstructionFbs.addValue(builder, localStoreFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioLoop loop -> { - var loopFbs = serializeLoop(builder, loop, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioLoopFbs); - PatioInstructionFbs.addValue(builder, loopFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioLoopBreak loopBreak -> { - var loopBreakFbs = serializeLoopBreak(builder, loopBreak, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioLoopBreakFbs); - PatioInstructionFbs.addValue(builder, loopBreakFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioLoopContinue loopContinue -> { - var loopContinueFbs = serializeLoopContinue(builder, loopContinue, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioLoopContinueFbs); - PatioInstructionFbs.addValue(builder, loopContinueFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioMemoryLoad memoryLoad -> { - var memoryLoadFbs = serializeMemoryLoad(builder, memoryLoad, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioMemoryLoadFbs); - PatioInstructionFbs.addValue(builder, memoryLoadFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioMemoryStore memoryStore -> { - var memoryStoreFbs = serializeMemoryStore(builder, memoryStore, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioMemoryStoreFbs); - PatioInstructionFbs.addValue(builder, memoryStoreFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioReturn return_ -> { - var returnFbs = serializeReturn(builder, return_, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioReturnFbs); - PatioInstructionFbs.addValue(builder, returnFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioSwitch switch_ -> { - var switchFbs = serializeSwitch(builder, switch_, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioSwitchFbs); - PatioInstructionFbs.addValue(builder, switchFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioThrow throw_ -> { - var throwFbs = serializeThrow(builder, throw_, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioThrowFbs); - PatioInstructionFbs.addValue(builder, throwFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioTry try_ -> { - var tryFbs = serializeTry(builder, try_, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioTryFbs); - PatioInstructionFbs.addValue(builder, tryFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioUnreachable unreachable -> { - var unreachableFbs = serializeUnreachable(builder, unreachable, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioUnreachableFbs); - PatioInstructionFbs.addValue(builder, unreachableFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioVarLoad varLoad -> { - var varLoadFbs = serializeVarLoad(builder, varLoad, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioVarLoadFbs); - PatioInstructionFbs.addValue(builder, varLoadFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - - case PatioVarStore varStore -> { - var varStoreFbs = serializeVarStore(builder, varStore, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioVarStoreFbs); - PatioInstructionFbs.addValue(builder, varStoreFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - }; - } - - public static PatioInstruction deserializeInstruction( - PatioInstructionFbs instructionFbs, - Source parentSource - ) { - return switch (instructionFbs.valueType()) { - case PatioInstructionValueFbs.PatioBlockFbs -> - deserializeBlock( - (PatioBlockFbs) instructionFbs.value(new PatioBlockFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioBoolToIntFbs -> - deserializeBoolToInt( - (PatioBoolToIntFbs) instructionFbs.value(new PatioBoolToIntFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioCallFbs -> - deserializeCall( - (PatioCallFbs) instructionFbs.value(new PatioCallFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioCallPointerFbs -> - deserializeCallPointer( - (PatioCallPointerFbs) instructionFbs.value(new PatioCallPointerFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioDataPtrToIntFbs -> - deserializeDataPtrToInt( - (PatioDataPtrToIntFbs) instructionFbs.value(new PatioDataPtrToIntFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioIfFbs -> - deserializeIf( - (PatioIfFbs) instructionFbs.value(new PatioIfFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioIntAddFbs -> - deserializeIntAdd( - (PatioIntAddFbs) instructionFbs.value(new PatioIntAddFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioIntEqualsFbs -> - deserializeIntEquals( - (PatioIntEqualsFbs) instructionFbs.value(new PatioIntEqualsFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioIntNotEqualFbs -> - deserializeIntNotEqual( - (PatioIntNotEqualFbs) instructionFbs.value(new PatioIntNotEqualFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioIntSubFbs -> - deserializeIntSub( - (PatioIntSubFbs) instructionFbs.value(new PatioIntSubFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioIntToBoolFbs -> - deserializeIntToBool( - (PatioIntToBoolFbs) instructionFbs.value(new PatioIntToBoolFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioIntToDataPtrFbs -> - deserializeIntToDataPtr( - (PatioIntToDataPtrFbs) instructionFbs.value(new PatioIntToDataPtrFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioLocalStoreFbs -> - deserializeLocalStore( - (PatioLocalStoreFbs) instructionFbs.value(new PatioLocalStoreFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioLoopFbs -> - deserializeLoop( - (PatioLoopFbs) instructionFbs.value(new PatioLoopFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioLoopBreakFbs -> - deserializeLoopBreak( - (PatioLoopBreakFbs) instructionFbs.value(new PatioLoopBreakFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioLoopContinueFbs -> - deserializeLoopContinue( - (PatioLoopContinueFbs) instructionFbs.value(new PatioLoopContinueFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioMemoryLoadFbs -> - deserializeMemoryLoad( - (PatioMemoryLoadFbs) instructionFbs.value(new PatioMemoryLoadFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioMemoryStoreFbs -> - deserializeMemoryStore( - (PatioMemoryStoreFbs) instructionFbs.value(new PatioMemoryStoreFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioReturnFbs -> - deserializeReturn( - (PatioReturnFbs) instructionFbs.value(new PatioReturnFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioSwitchFbs -> - deserializeSwitch( - (PatioSwitchFbs) instructionFbs.value(new PatioSwitchFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioThrowFbs -> - deserializeThrow( - (PatioThrowFbs) instructionFbs.value(new PatioThrowFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioTryFbs -> - deserializeTry( - (PatioTryFbs) instructionFbs.value(new PatioTryFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioUnreachableFbs -> - deserializeUnreachable( - (PatioUnreachableFbs) instructionFbs.value(new PatioUnreachableFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioVarLoadFbs -> - deserializeVarLoad( - (PatioVarLoadFbs) instructionFbs.value(new PatioVarLoadFbs()), - parentSource - ); - - case PatioInstructionValueFbs.PatioVarStoreFbs -> - deserializeVarStore( - (PatioVarStoreFbs) instructionFbs.value(new PatioVarStoreFbs()), - parentSource - ); - - default -> - throw new UnsupportedOperationException("TODO"); - }; - } - - public static int serializeBlock( - FlatBufferBuilder builder, - PatioBlock instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - - var bodyOffsetsFbs = instruction.body().stream() - .mapToInt(bodyInstruction -> serializeInstruction(builder, bodyInstruction, instruction.source())) - .toArray(); - var bodyVectorFbs = PatioBlockFbs.createBodyVector(builder, bodyOffsetsFbs); - - var resultsOffsetsFbs = instruction.results().stream() - .mapToInt(result -> serializeOperand(builder, result)) - .toArray(); - var resultsVectorFbs = PatioBlockFbs.createResultsVector(builder, resultsOffsetsFbs); - - PatioBlockFbs.startPatioBlockFbs(builder); - PatioBlockFbs.addBody(builder, bodyVectorFbs); - PatioBlockFbs.addResults(builder, resultsVectorFbs); - PatioBlockFbs.addSource(builder, sourceFbs); - return PatioBlockFbs.endPatioBlockFbs(builder); - } - - private static PatioBlock deserializeBlock(PatioBlockFbs instructionFbs, Source parentSource) { - var source = SourceToFlatbuffers.deserializeSource(instructionFbs.source(), parentSource); - - var body = deserializeVector( - instructionFbs::body, - instructionFbs.bodyLength(), - bodyInstructionFbs -> deserializeInstruction(bodyInstructionFbs, source) - ); - - var results = deserializeVector( - instructionFbs::results, - instructionFbs.resultsLength(), - resultFbs -> deserializeOperand(resultFbs) - ); - - return new PatioBlock( - body, - results, - source - ); - } - - public static int serializeBoolToInt( - FlatBufferBuilder builder, - PatioBoolToInt instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - var destinationFbs = serializeLocalRef(builder, instruction.destination()); - var valueFbs = serializeOperand(builder, instruction.value()); - - PatioBoolToIntFbs.startPatioBoolToIntFbs(builder); - PatioBoolToIntFbs.addSource(builder, sourceFbs); - PatioBoolToIntFbs.addDestination(builder, destinationFbs); - PatioBoolToIntFbs.addValue(builder, valueFbs); - return PatioBoolToIntFbs.endPatioBoolToIntFbs(builder); - } - - private static PatioBoolToInt deserializeBoolToInt( - PatioBoolToIntFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource(instructionFbs.source(), parentSource); - - var destination = deserializeLocalRef(instructionFbs.destination()); - var value = deserializeOperand(instructionFbs.value()); - - return new PatioBoolToInt(destination, value, source); - } - - public static int serializeCall( - FlatBufferBuilder builder, - PatioCall instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - - var destinationsOffsetsFbs = instruction.destinations().stream() - .mapToInt(destination -> serializeLocalRef(builder, destination)) - .toArray(); - var destinationsVectorFbs = PatioCallFbs.createDestinationsVector(builder, destinationsOffsetsFbs); - - var functionNameFbs = builder.createString(instruction.functionName()); - - var argsOffsetsFbs = instruction.args().stream() - .mapToInt(arg -> serializeOperand(builder, arg)) - .toArray(); - var argsVectorFbs = PatioCallFbs.createArgsVector(builder, argsOffsetsFbs); - - PatioCallFbs.startPatioCallFbs(builder); - PatioCallFbs.addSource(builder, sourceFbs); - PatioCallFbs.addDestinations(builder, destinationsVectorFbs); - PatioCallFbs.addFunctionName(builder, functionNameFbs); - PatioCallFbs.addArgs(builder, argsVectorFbs); - return PatioCallFbs.endPatioCallFbs(builder); - } - - private static PatioCall deserializeCall( - PatioCallFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource(instructionFbs.source(), parentSource); - - var destinations = deserializeVector( - instructionFbs::destinations, - instructionFbs.destinationsLength(), - PatioToFlatbuffers::deserializeLocalRef - ); - - var functionName = instructionFbs.functionName(); - - var args = deserializeVector( - instructionFbs::args, - instructionFbs.argsLength(), - argFbs -> deserializeOperand(argFbs) - ); - - return new PatioCall(destinations, functionName, args, source); - } - - public static int serializeCallPointer( - FlatBufferBuilder builder, - PatioCallPointer instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - - var destinationsOffsetsFbs = instruction.destinations().stream() - .mapToInt(destination -> serializeLocalRef(builder, destination)) - .toArray(); - var destinationsVectorFbs = PatioCallFbs.createDestinationsVector(builder, destinationsOffsetsFbs); - - var functionPointerFbs = serializeOperand(builder, instruction.functionPointer()); - - var argsOffsetsFbs = instruction.args().stream() - .mapToInt(arg -> serializeOperand(builder, arg)) - .toArray(); - var argsVectorFbs = PatioCallPointerFbs.createArgsVector(builder, argsOffsetsFbs); - - PatioCallPointerFbs.startPatioCallPointerFbs(builder); - PatioCallPointerFbs.addSource(builder, sourceFbs); - PatioCallPointerFbs.addDestinations(builder, destinationsVectorFbs); - PatioCallPointerFbs.addFunctionPointer(builder, functionPointerFbs); - PatioCallPointerFbs.addArgs(builder, argsVectorFbs); - return PatioCallPointerFbs.endPatioCallPointerFbs(builder); - } - - private static PatioCallPointer deserializeCallPointer( - PatioCallPointerFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource(instructionFbs.source(), parentSource); - - var destinations = deserializeVector( - instructionFbs::destinations, - instructionFbs.destinationsLength(), - PatioToFlatbuffers::deserializeLocalRef - ); - - var functionPointer = deserializeOperand(instructionFbs.functionPointer()); - - var args = deserializeVector( - instructionFbs::args, - instructionFbs.argsLength(), - argFbs -> deserializeOperand(argFbs) - ); - - return new PatioCallPointer(destinations, functionPointer, args, source); - } - - public static int serializeDataPtrToInt( - FlatBufferBuilder builder, - PatioDataPtrToInt instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - var destinationFbs = serializeLocalRef(builder, instruction.destination()); - var valueFbs = serializeOperand(builder, instruction.value()); - - PatioDataPtrToIntFbs.startPatioDataPtrToIntFbs(builder); - PatioDataPtrToIntFbs.addSource(builder, sourceFbs); - PatioDataPtrToIntFbs.addDestination(builder, destinationFbs); - PatioDataPtrToIntFbs.addValue(builder, valueFbs); - return PatioDataPtrToIntFbs.endPatioDataPtrToIntFbs(builder); - } - - private static PatioDataPtrToInt deserializeDataPtrToInt( - PatioDataPtrToIntFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource(instructionFbs.source(), parentSource); - - var destination = deserializeLocalRef(instructionFbs.destination()); - var value = deserializeOperand(instructionFbs.value()); - - return new PatioDataPtrToInt(destination, value, source); - } - - public static int serializeIf( - FlatBufferBuilder builder, - PatioIf instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - - var destinationsOffsetsFbs = instruction.destinations().stream() - .mapToInt(destination -> serializeLocalRef(builder, destination)) - .toArray(); - var destinationsVectorFbs = PatioIfFbs.createDestinationsVector(builder, destinationsOffsetsFbs); - - var conditionFbs = serializeOperand(builder, instruction.condition()); - - var trueBody = serializeBlock(builder, instruction.trueBody(), instruction.source()); - var falseBody = serializeBlock(builder, instruction.falseBody(), instruction.source()); - - PatioIfFbs.startPatioIfFbs(builder); - PatioIfFbs.addSource(builder, sourceFbs); - PatioIfFbs.addDestinations(builder, destinationsVectorFbs); - PatioIfFbs.addCondition(builder, conditionFbs); - PatioIfFbs.addTrueBody(builder, trueBody); - PatioIfFbs.addFalseBody(builder, falseBody); - return PatioIfFbs.endPatioIfFbs(builder); - } - - private static PatioIf deserializeIf( - PatioIfFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource(instructionFbs.source(), parentSource); - - var destinations = deserializeVector( - instructionFbs::destinations, - instructionFbs.destinationsLength(), - PatioToFlatbuffers::deserializeLocalRef - ); - var condition = deserializeOperand(instructionFbs.condition()); - var trueBody = deserializeBlock(instructionFbs.trueBody(), source); - var falseBody = deserializeBlock(instructionFbs.falseBody(), source); - - return new PatioIf(destinations, condition, trueBody, falseBody, source); - } - - public static int serializeIntAdd( - FlatBufferBuilder builder, - PatioIntAdd instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - var destinationFbs = serializeLocalRef(builder, instruction.destination()); - var leftFbs = serializeOperand(builder, instruction.left()); - var rightFbs = serializeOperand(builder, instruction.right()); - - PatioIntAddFbs.startPatioIntAddFbs(builder); - PatioIntAddFbs.addSource(builder, sourceFbs); - PatioIntAddFbs.addDestination(builder, destinationFbs); - PatioIntAddFbs.addLeft(builder, leftFbs); - PatioIntAddFbs.addRight(builder, rightFbs); - return PatioIntAddFbs.endPatioIntAddFbs(builder); - } - - private static PatioIntAdd deserializeIntAdd( - PatioIntAddFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource(instructionFbs.source(), parentSource); - - var destination = deserializeLocalRef(instructionFbs.destination()); - var left = deserializeOperand(instructionFbs.left()); - var right = deserializeOperand(instructionFbs.right()); - - return new PatioIntAdd(destination, left, right, source); - } - - public static int serializeIntEquals( - FlatBufferBuilder builder, - PatioIntEquals instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - var destinationFbs = serializeLocalRef(builder, instruction.destination()); - var leftFbs = serializeOperand(builder, instruction.left()); - var rightFbs = serializeOperand(builder, instruction.right()); - - PatioIntEqualsFbs.startPatioIntEqualsFbs(builder); - PatioIntEqualsFbs.addSource(builder, sourceFbs); - PatioIntEqualsFbs.addDestination(builder, destinationFbs); - PatioIntEqualsFbs.addLeft(builder, leftFbs); - PatioIntEqualsFbs.addRight(builder, rightFbs); - return PatioIntEqualsFbs.endPatioIntEqualsFbs(builder); - } - - private static PatioIntEquals deserializeIntEquals( - PatioIntEqualsFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource(instructionFbs.source(), parentSource); - - var destination = deserializeLocalRef(instructionFbs.destination()); - var left = deserializeOperand(instructionFbs.left()); - var right = deserializeOperand(instructionFbs.right()); - - return new PatioIntEquals(destination, left, right, source); - } - - public static int serializeIntNotEqual( - FlatBufferBuilder builder, - PatioIntNotEqual instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - var destinationFbs = serializeLocalRef(builder, instruction.destination()); - var leftFbs = serializeOperand(builder, instruction.left()); - var rightFbs = serializeOperand(builder, instruction.right()); - - PatioIntNotEqualFbs.startPatioIntNotEqualFbs(builder); - PatioIntNotEqualFbs.addSource(builder, sourceFbs); - PatioIntNotEqualFbs.addDestination(builder, destinationFbs); - PatioIntNotEqualFbs.addLeft(builder, leftFbs); - PatioIntNotEqualFbs.addRight(builder, rightFbs); - return PatioIntNotEqualFbs.endPatioIntNotEqualFbs(builder); - } - - private static PatioIntNotEqual deserializeIntNotEqual( - PatioIntNotEqualFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource(instructionFbs.source(), parentSource); - - var destination = deserializeLocalRef(instructionFbs.destination()); - var left = deserializeOperand(instructionFbs.left()); - var right = deserializeOperand(instructionFbs.right()); - - return new PatioIntNotEqual(destination, left, right, source); - } - - public static int serializeIntSub( - FlatBufferBuilder builder, - PatioIntSub instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - var destinationFbs = serializeLocalRef(builder, instruction.destination()); - var leftFbs = serializeOperand(builder, instruction.left()); - var rightFbs = serializeOperand(builder, instruction.right()); - - PatioIntSubFbs.startPatioIntSubFbs(builder); - PatioIntSubFbs.addSource(builder, sourceFbs); - PatioIntSubFbs.addDestination(builder, destinationFbs); - PatioIntSubFbs.addLeft(builder, leftFbs); - PatioIntSubFbs.addRight(builder, rightFbs); - return PatioIntSubFbs.endPatioIntSubFbs(builder); - } - - private static PatioIntSub deserializeIntSub( - PatioIntSubFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource(instructionFbs.source(), parentSource); - - var destination = deserializeLocalRef(instructionFbs.destination()); - var left = deserializeOperand(instructionFbs.left()); - var right = deserializeOperand(instructionFbs.right()); - - return new PatioIntSub(destination, left, right, source); - } - - public static int serializeIntToBool( - FlatBufferBuilder builder, - PatioIntToBool instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - var destinationFbs = serializeLocalRef(builder, instruction.destination()); - var valueFbs = serializeOperand(builder, instruction.value()); - - PatioIntToBoolFbs.startPatioIntToBoolFbs(builder); - PatioIntToBoolFbs.addSource(builder, sourceFbs); - PatioIntToBoolFbs.addDestination(builder, destinationFbs); - PatioIntToBoolFbs.addValue(builder, valueFbs); - return PatioIntToBoolFbs.endPatioIntToBoolFbs(builder); - } - - private static PatioIntToBool deserializeIntToBool( - PatioIntToBoolFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource(instructionFbs.source(), parentSource); - - var destination = deserializeLocalRef(instructionFbs.destination()); - var value = deserializeOperand(instructionFbs.value()); - - return new PatioIntToBool(destination, value, source); - } - - public static int serializeIntToDataPtr( - FlatBufferBuilder builder, - PatioIntToDataPtr instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - var destinationFbs = serializeLocalRef(builder, instruction.destination()); - var valueFbs = serializeOperand(builder, instruction.value()); - - PatioIntToDataPtrFbs.startPatioIntToDataPtrFbs(builder); - PatioIntToDataPtrFbs.addSource(builder, sourceFbs); - PatioIntToDataPtrFbs.addDestination(builder, destinationFbs); - PatioIntToDataPtrFbs.addValue(builder, valueFbs); - return PatioIntToDataPtrFbs.endPatioIntToDataPtrFbs(builder); - } - - private static PatioIntToDataPtr deserializeIntToDataPtr( - PatioIntToDataPtrFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource(instructionFbs.source(), parentSource); - - var destination = deserializeLocalRef(instructionFbs.destination()); - var value = deserializeOperand(instructionFbs.value()); - - return new PatioIntToDataPtr(destination, value, source); - } - - public static int serializeLocalStore( - FlatBufferBuilder builder, - PatioLocalStore instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - var destinationFbs = serializeLocalRef(builder, instruction.destination()); - var valueFbs = serializeOperand(builder, instruction.value()); - - PatioLocalStoreFbs.startPatioLocalStoreFbs(builder); - PatioLocalStoreFbs.addSource(builder, sourceFbs); - PatioLocalStoreFbs.addDestination(builder, destinationFbs); - PatioLocalStoreFbs.addValue(builder, valueFbs); - return PatioLocalStoreFbs.endPatioLocalStoreFbs(builder); - } - - private static PatioLocalStore deserializeLocalStore( - PatioLocalStoreFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource(instructionFbs.source(), parentSource); - - var destination = deserializeLocalRef(instructionFbs.destination()); - var value = deserializeOperand(instructionFbs.value()); - - return new PatioLocalStore(destination, value, source); - } - - public static int serializeLoopBreak( - FlatBufferBuilder builder, - PatioLoopBreak instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - - PatioLoopBreakFbs.startPatioLoopBreakFbs(builder); - PatioLoopBreakFbs.addSource(builder, sourceFbs); - return PatioLoopBreakFbs.endPatioLoopBreakFbs(builder); - } - - private static PatioLoopBreak deserializeLoopBreak( - PatioLoopBreakFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource(instructionFbs.source(), parentSource); - - return new PatioLoopBreak(source); - } - - public static int serializeLoop( - FlatBufferBuilder builder, - PatioLoop instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - - var bodyOffsetsFbs = instruction.body().stream() - .mapToInt(bodyInstruction -> serializeInstruction(builder, bodyInstruction, instruction.source())) - .toArray(); - var bodyVectorFbs = PatioLoopFbs.createBodyVector(builder, bodyOffsetsFbs); - - PatioLoopFbs.startPatioLoopFbs(builder); - PatioLoopFbs.addSource(builder, sourceFbs); - PatioLoopFbs.addBody(builder, bodyVectorFbs); - return PatioLoopFbs.endPatioLoopFbs(builder); - } - - private static PatioLoop deserializeLoop( - PatioLoopFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource( - instructionFbs.source(), - parentSource - ); - - var body = deserializeVector( - instructionFbs::body, - instructionFbs.bodyLength(), - bodyInstructionFbs -> deserializeInstruction(bodyInstructionFbs, source) - ); - - return new PatioLoop(body, source); - } - - public static int serializeLoopContinue( - FlatBufferBuilder builder, - PatioLoopContinue instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - - PatioLoopContinueFbs.startPatioLoopContinueFbs(builder); - PatioLoopContinueFbs.addSource(builder, sourceFbs); - return PatioLoopContinueFbs.endPatioLoopContinueFbs(builder); - } - - private static PatioLoopContinue deserializeLoopContinue( - PatioLoopContinueFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource(instructionFbs.source(), parentSource); - - return new PatioLoopContinue(source); - } - - public static int serializeMemoryLoad( - FlatBufferBuilder builder, - PatioMemoryLoad instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - - var destinationFbs = serializeLocalRef(builder, instruction.destination()); - var pointerFbs = serializeOperand(builder, instruction.pointer()); - var layoutFbs = serializeDataLayout(builder, instruction.layout()); - var elementOffsetsFb = PatioMemoryLoadFbs.createElementOffsetsVector( - builder, - serializeListOfInts(instruction.elementOffsets()) - ); - - PatioMemoryLoadFbs.startPatioMemoryLoadFbs(builder); - PatioMemoryLoadFbs.addSource(builder, sourceFbs); - PatioMemoryLoadFbs.addDestination(builder, destinationFbs); - PatioMemoryLoadFbs.addPointer(builder, pointerFbs); - PatioMemoryLoadFbs.addLayout(builder, layoutFbs); - PatioMemoryLoadFbs.addElementOffsets(builder, elementOffsetsFb); - return PatioMemoryLoadFbs.endPatioMemoryLoadFbs(builder); - } - - private static PatioMemoryLoad deserializeMemoryLoad( - PatioMemoryLoadFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource(instructionFbs.source(), parentSource); - - var destination = deserializeLocalRef(instructionFbs.destination()); - var pointer = deserializeOperand(instructionFbs.pointer()); - var layout = deserializeDataLayout(instructionFbs.layout()); - var elementOffsets = deserializeListOfInts(instructionFbs.elementOffsetsVector()); - - return new PatioMemoryLoad(destination, pointer, layout, elementOffsets, source); - } - - public static int serializeMemoryStore( - FlatBufferBuilder builder, - PatioMemoryStore instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - - var pointerFbs = serializeOperand(builder, instruction.pointer()); - var layoutFbs = serializeDataLayout(builder, instruction.layout()); - var elementOffsetsFbs = PatioMemoryStoreFbs.createElementOffsetsVector( - builder, - serializeListOfInts(instruction.elementOffsets()) - ); - var valueFbs = serializeOperand(builder, instruction.value()); - - PatioMemoryStoreFbs.startPatioMemoryStoreFbs(builder); - PatioMemoryStoreFbs.addSource(builder, sourceFbs); - PatioMemoryStoreFbs.addPointer(builder, pointerFbs); - PatioMemoryStoreFbs.addLayout(builder, layoutFbs); - PatioMemoryStoreFbs.addElementOffsets(builder, elementOffsetsFbs); - PatioMemoryStoreFbs.addValue(builder, valueFbs); - return PatioMemoryStoreFbs.endPatioMemoryStoreFbs(builder); - } - - private static PatioMemoryStore deserializeMemoryStore( - PatioMemoryStoreFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource(instructionFbs.source(), parentSource); - - var pointer = deserializeOperand(instructionFbs.pointer()); - var layout = deserializeDataLayout(instructionFbs.layout()); - var elementOffsets = deserializeListOfInts(instructionFbs.elementOffsetsVector()); - var value = deserializeOperand(instructionFbs.value()); - - return new PatioMemoryStore(pointer, layout, elementOffsets, value, source); - } - - public static int serializeReturn( - FlatBufferBuilder builder, - PatioReturn instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - - var valuesOffsetsFbs = instruction.values().stream() - .mapToInt(value -> serializeOperand(builder, value)) - .toArray(); - var valuesVectorFbs = PatioReturnFbs.createValuesVector(builder, valuesOffsetsFbs); - - PatioReturnFbs.startPatioReturnFbs(builder); - PatioReturnFbs.addSource(builder, sourceFbs); - PatioReturnFbs.addValues(builder, valuesVectorFbs); - return PatioReturnFbs.endPatioReturnFbs(builder); - } - - private static PatioReturn deserializeReturn( - PatioReturnFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource( - instructionFbs.source(), - parentSource - ); - - var values = deserializeVector( - instructionFbs::values, - instructionFbs.valuesLength(), - PatioToFlatbuffers::deserializeOperand - ); - - return new PatioReturn(values, source); - } - - public static int serializeSwitch( - FlatBufferBuilder builder, - PatioSwitch instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - - var destinationsOffsetsFbs = instruction.destinations().stream() - .mapToInt(destination -> serializeLocalRef(builder, destination)) - .toArray(); - var destinationsVectorFbs = PatioSwitchFbs.createDestinationsVector(builder, destinationsOffsetsFbs); - - var valueFbs = serializeOperand(builder, instruction.value()); - - var casesOffsetsFbs = instruction.cases().stream() - .mapToInt(case_ -> serializeSwitchCase(builder, case_, instruction.source())) - .toArray(); - var casesVectorFbs = PatioSwitchFbs.createCasesVector(builder, casesOffsetsFbs); - - var defaultBodyFbs = serializeBlock(builder, instruction.defaultBody(), instruction.source()); - - PatioSwitchFbs.startPatioSwitchFbs(builder); - PatioSwitchFbs.addSource(builder, sourceFbs); - PatioSwitchFbs.addDestinations(builder, destinationsVectorFbs); - PatioSwitchFbs.addValue(builder, valueFbs); - PatioSwitchFbs.addCases(builder, casesVectorFbs); - PatioSwitchFbs.addDefaultBody(builder, defaultBodyFbs); - return PatioSwitchFbs.endPatioSwitchFbs(builder); - } - - private static PatioSwitch deserializeSwitch( - PatioSwitchFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource( - instructionFbs.source(), - parentSource - ); - - var destinations = deserializeVector( - instructionFbs::destinations, - instructionFbs.destinationsLength(), - PatioToFlatbuffers::deserializeLocalRef - ); - - var value = deserializeOperand(instructionFbs.value()); - - var cases = deserializeVector( - instructionFbs::cases, - instructionFbs.casesLength(), - caseFbs -> deserializeSwitchCase(caseFbs, source) - ); - - var defaultBody = deserializeBlock(instructionFbs.defaultBody(), source); - - return new PatioSwitch(destinations, value, cases, defaultBody, source); - } - - private static int serializeSwitchCase( - FlatBufferBuilder builder, - PatioSwitchCase case_, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - case_.source(), - parentSource - ); - - var bodyFbs = serializeBlock(builder, case_.body(), case_.source()); - - PatioSwitchCaseFbs.startPatioSwitchCaseFbs(builder); - PatioSwitchCaseFbs.addSource(builder, sourceFbs); - PatioSwitchCaseFbs.addValue(builder, case_.value()); - PatioSwitchCaseFbs.addBody(builder, bodyFbs); - return PatioSwitchCaseFbs.endPatioSwitchCaseFbs(builder); - } - - private static PatioSwitchCase deserializeSwitchCase( - PatioSwitchCaseFbs caseFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource( - caseFbs.source(), - parentSource - ); - - var body = deserializeBlock(caseFbs.body(), source); - - return new PatioSwitchCase((int) caseFbs.value(), body, source); - } - - public static int serializeThrow( - FlatBufferBuilder builder, - PatioThrow instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - - var exceptionTypeNameFbs = builder.createString(instruction.exceptionTypeName()); - var valueFbs = serializeOperand(builder, instruction.value()); - - PatioThrowFbs.startPatioThrowFbs(builder); - PatioThrowFbs.addSource(builder, sourceFbs); - PatioThrowFbs.addExceptionTypeName(builder, exceptionTypeNameFbs); - PatioThrowFbs.addValue(builder, valueFbs); - return PatioThrowFbs.endPatioThrowFbs(builder); - } - - private static PatioThrow deserializeThrow( - PatioThrowFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource( - instructionFbs.source(), - parentSource - ); - - var value = deserializeOperand(instructionFbs.value()); - - return new PatioThrow( - instructionFbs.exceptionTypeName(), - value, - source - ); - } - - public static int serializeTry( - FlatBufferBuilder builder, - PatioTry instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - - var destinationsOffsetsFbs = instruction.destinations().stream() - .mapToInt(destination -> serializeLocalRef(builder, destination)) - .toArray(); - var destinationsVectorFbs = PatioTryFbs.createDestinationsVector(builder, destinationsOffsetsFbs); - - var catchClausesOffsetsFbs = instruction.catchClauses().stream() - .mapToInt(catchClauseFbs -> serializeCatchClause(builder, catchClauseFbs, instruction.source())) - .toArray(); - var catchClausesVectorFbs = PatioTryFbs.createCatchClausesVector(builder, catchClausesOffsetsFbs); - - var bodyFbs = serializeBlock(builder, instruction.body(), instruction.source()); - - PatioTryFbs.startPatioTryFbs(builder); - PatioTryFbs.addSource(builder, sourceFbs); - PatioTryFbs.addDestinations(builder, destinationsVectorFbs); - PatioTryFbs.addCatchClauses(builder, catchClausesVectorFbs); - PatioTryFbs.addBody(builder, bodyFbs); - return PatioTryFbs.endPatioTryFbs(builder); - } - - private static PatioTry deserializeTry( - PatioTryFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource(instructionFbs.source(), parentSource); - - var destinations = deserializeVector( - instructionFbs::destinations, - instructionFbs.destinationsLength(), - PatioToFlatbuffers::deserializeLocalRef - ); - - var catchClauses = deserializeVector( - instructionFbs::catchClauses, - instructionFbs.catchClausesLength(), - catchClauseFbs -> deserializeCatchClause(catchClauseFbs, source) - ); - - var body = deserializeBlock(instructionFbs.body(), source); - - return new PatioTry(destinations, catchClauses, body, source); - } - - private static int serializeCatchClause( - FlatBufferBuilder builder, - PatioCatchClause catchClause, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - catchClause.source(), - parentSource - ); - - var exceptionTypeNameFbs = builder.createString(catchClause.exceptionTypeName()); - - var destinationFbs = serializeLocalRef(builder, catchClause.destination()); - - var bodyFbs = serializeBlock(builder, catchClause.body(), catchClause.source()); - - PatioCatchClauseFbs.startPatioCatchClauseFbs(builder); - PatioCatchClauseFbs.addSource(builder, sourceFbs); - PatioCatchClauseFbs.addExceptionTypeName(builder, exceptionTypeNameFbs); - PatioCatchClauseFbs.addDestination(builder, destinationFbs); - PatioCatchClauseFbs.addBody(builder, bodyFbs); - return PatioCatchClauseFbs.endPatioCatchClauseFbs(builder); - } - - private static PatioCatchClause deserializeCatchClause( - PatioCatchClauseFbs catchClauseFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource(catchClauseFbs.source(), parentSource); - - var destination = deserializeLocalRef(catchClauseFbs.destination()); - - var body = deserializeBlock(catchClauseFbs.body(), source); - - return new PatioCatchClause( - catchClauseFbs.exceptionTypeName(), - destination, - body, - source - ); - } - - public static int serializeUnreachable( - FlatBufferBuilder builder, - PatioUnreachable instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - - PatioUnreachableFbs.startPatioUnreachableFbs(builder); - PatioUnreachableFbs.addSource(builder, sourceFbs); - return PatioUnreachableFbs.endPatioUnreachableFbs(builder); - } - - private static PatioUnreachable deserializeUnreachable( - PatioUnreachableFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource(instructionFbs.source(), parentSource); - - return new PatioUnreachable(source); - } - - public static int serializeVarLoad( - FlatBufferBuilder builder, - PatioVarLoad instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - - var destinationFbs = serializeLocalRef(builder, instruction.destination()); - var varFbs = serializeLocalRef(builder, instruction.var()); - - PatioVarLoadFbs.startPatioVarLoadFbs(builder); - PatioVarLoadFbs.addSource(builder, sourceFbs); - PatioVarLoadFbs.addDestination(builder, destinationFbs); - PatioVarLoadFbs.addVar(builder, varFbs); - return PatioVarLoadFbs.endPatioVarLoadFbs(builder); - } - - private static PatioVarLoad deserializeVarLoad( - PatioVarLoadFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource( - instructionFbs.source(), - parentSource - ); - - var destination = deserializeLocalRef(instructionFbs.destination()); - - var var = deserializeLocalRef(instructionFbs.var()); - - return new PatioVarLoad(destination, var, source); - } - - public static int serializeVarStore( - FlatBufferBuilder builder, - PatioVarStore instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource - ); - - var varFbs = serializeLocalRef(builder, instruction.var()); - - var valueFbs = serializeOperand(builder, instruction.value()); - - PatioVarStoreFbs.startPatioVarStoreFbs(builder); - PatioVarStoreFbs.addSource(builder, sourceFbs); - PatioVarStoreFbs.addVar(builder, varFbs); - PatioVarStoreFbs.addValue(builder, valueFbs); - return PatioVarStoreFbs.endPatioVarStoreFbs(builder); - } - - private static PatioVarStore deserializeVarStore( - PatioVarStoreFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource( - instructionFbs.source(), - parentSource - ); - - var var = deserializeLocalRef(instructionFbs.var()); - - var value = deserializeOperand(instructionFbs.value()); - - return new PatioVarStore(var, value, source); - } - - // == Operands == - - public static int serializeOperand( - FlatBufferBuilder builder, - PatioOperand operand - ) { - return switch (operand) { - case PatioBoolConst boolConst -> { - PatioBoolConstFbs.startPatioBoolConstFbs(builder); - PatioBoolConstFbs.addValue(builder, boolConst.value()); - var boolConstFbs = PatioBoolConstFbs.endPatioBoolConstFbs(builder); - - PatioOperandFbs.startPatioOperandFbs(builder); - PatioOperandFbs.addValueType(builder, PatioOperandValueFbs.PatioBoolConstFbs); - PatioOperandFbs.addValue(builder, boolConstFbs); - yield PatioOperandFbs.endPatioOperandFbs(builder); - } - - case PatioByteConst byteConst -> { - PatioByteConstFbs.startPatioByteConstFbs(builder); - PatioByteConstFbs.addValue(builder, byteConst.value()); - var byteConstFbs = PatioByteConstFbs.endPatioByteConstFbs(builder); - - PatioOperandFbs.startPatioOperandFbs(builder); - PatioOperandFbs.addValueType(builder, PatioOperandValueFbs.PatioByteConstFbs); - PatioOperandFbs.addValue(builder, byteConstFbs); - yield PatioOperandFbs.endPatioOperandFbs(builder); - } - - case PatioDataPtrConst dataPtrConst -> { - var dataPtrValueFbs = serializeDataPtrValue(builder, dataPtrConst.value()); - - PatioDataPtrConstFbs.startPatioDataPtrConstFbs(builder); - PatioDataPtrConstFbs.addValue(builder, dataPtrValueFbs); - var dataPtrConstFbs = PatioDataPtrConstFbs.endPatioDataPtrConstFbs(builder); - - PatioOperandFbs.startPatioOperandFbs(builder); - PatioOperandFbs.addValueType(builder, PatioOperandValueFbs.PatioDataPtrConstFbs); - PatioOperandFbs.addValue(builder, dataPtrConstFbs); - yield PatioOperandFbs.endPatioOperandFbs(builder); - } - - case PatioFunctionPtrConst functionPtrConst -> { - var nameFbs = builder.createString(functionPtrConst.name()); - - PatioFunctionPtrConstFbs.startPatioFunctionPtrConstFbs(builder); - PatioFunctionPtrConstFbs.addName(builder, nameFbs); - var functionPtrConstFbs = PatioFunctionPtrConstFbs.endPatioFunctionPtrConstFbs(builder); - - PatioOperandFbs.startPatioOperandFbs(builder); - PatioOperandFbs.addValueType(builder, PatioOperandValueFbs.PatioFunctionPtrConstFbs); - PatioOperandFbs.addValue(builder, functionPtrConstFbs); - yield PatioOperandFbs.endPatioOperandFbs(builder); - } - - case PatioLocalRef localRef -> { - var localRefFbs = serializeLocalRef(builder, localRef); - - PatioOperandFbs.startPatioOperandFbs(builder); - PatioOperandFbs.addValueType(builder, PatioOperandValueFbs.PatioLocalRefFbs); - PatioOperandFbs.addValue(builder, localRefFbs); - yield PatioOperandFbs.endPatioOperandFbs(builder); - } - - case PatioIntConst intConst -> { - var intValueFbs = serializeIntValue(builder, intConst.value()); - - PatioIntConstFbs.startPatioIntConstFbs(builder); - PatioIntConstFbs.addValue(builder, intValueFbs); - var intConstFbs = PatioIntConstFbs.endPatioIntConstFbs(builder); - - PatioOperandFbs.startPatioOperandFbs(builder); - PatioOperandFbs.addValueType(builder, PatioOperandValueFbs.PatioIntConstFbs); - PatioOperandFbs.addValue(builder, intConstFbs); - yield PatioOperandFbs.endPatioOperandFbs(builder); - } - - case PatioInt32Const int32Const -> { - var intValueFbs = serializeIntValue(builder, int32Const.value()); - - PatioInt32ConstFbs.startPatioInt32ConstFbs(builder); - PatioInt32ConstFbs.addValue(builder, intValueFbs); - var int32ConstFbs = PatioInt32ConstFbs.endPatioInt32ConstFbs(builder); - - PatioOperandFbs.startPatioOperandFbs(builder); - PatioOperandFbs.addValueType(builder, PatioOperandValueFbs.PatioInt32ConstFbs); - PatioOperandFbs.addValue(builder, int32ConstFbs); - yield PatioOperandFbs.endPatioOperandFbs(builder); - } - }; - } - - public static PatioOperand deserializeOperand(PatioOperandFbs operandFbs) { - return switch (operandFbs.valueType()) { - case PatioOperandValueFbs.PatioBoolConstFbs -> { - var boolConstFbs = (PatioBoolConstFbs) operandFbs.value(new PatioBoolConstFbs()); - - yield new PatioBoolConst(boolConstFbs.value()); - } - - case PatioOperandValueFbs.PatioByteConstFbs -> { - var byteConstFbs = (PatioByteConstFbs) operandFbs.value(new PatioByteConstFbs()); - - yield new PatioByteConst((byte) byteConstFbs.value()); - } - - case PatioOperandValueFbs.PatioDataPtrConstFbs -> { - var dataPtrConstFbs = (PatioDataPtrConstFbs) operandFbs.value(new PatioDataPtrConstFbs()); - - var dataPtrValue = deserializeDataPtrValue(dataPtrConstFbs.value()); - - yield new PatioDataPtrConst(dataPtrValue); - } - - case PatioOperandValueFbs.PatioFunctionPtrConstFbs -> { - var functionPtrConstFbs = (PatioFunctionPtrConstFbs) operandFbs.value(new PatioFunctionPtrConstFbs()); - - yield new PatioFunctionPtrConst(functionPtrConstFbs.name()); - } - - case PatioOperandValueFbs.PatioIntConstFbs -> { - var intConstFbs = (PatioIntConstFbs) operandFbs.value(new PatioIntConstFbs()); - - var intValue = deserializeIntValue(intConstFbs.value()); - - yield new PatioIntConst(intValue); - } - - case PatioOperandValueFbs.PatioInt32ConstFbs -> { - var int32ConstFbs = (PatioInt32ConstFbs) operandFbs.value(new PatioInt32ConstFbs()); - - var intValue = deserializeIntValue(int32ConstFbs.value()); - - yield new PatioInt32Const(intValue); - } - - case PatioOperandValueFbs.PatioLocalRefFbs -> { - var localRefFbs = (PatioLocalRefFbs) operandFbs.value(new PatioLocalRefFbs()); - - yield deserializeLocalRef(localRefFbs); - } - - default -> - throw new UnsupportedOperationException("TODO"); - }; - } - - private static int serializeLocalRef(FlatBufferBuilder builder, PatioLocalRef localRef) { - var nameFbs = builder.createString(localRef.name()); - - PatioLocalRefFbs.startPatioLocalRefFbs(builder); - PatioLocalRefFbs.addName(builder, nameFbs); - return PatioLocalRefFbs.endPatioLocalRefFbs(builder); - } - - private static PatioLocalRef deserializeLocalRef(PatioLocalRefFbs localRefFbs) { - return new PatioLocalRef(localRefFbs.name()); - } - - // == Data ptr values == - - public static int serializeDataPtrValue( - FlatBufferBuilder builder, - PatioDataPtrValue value - ) { - switch (value) { - case PatioDataPtrValueDataElement dataElement -> { - var nameFbs = builder.createString(dataElement.name()); - - var dataElementFbs = PatioDataPtrValueDataElementFbs - .createPatioDataPtrValueDataElementFbs(builder, nameFbs); - - return PatioDataPtrValueFbs.createPatioDataPtrValueFbs( - builder, - PatioDataPtrValueValueFbs.PatioDataPtrValueDataElementFbs, - dataElementFbs - ); - } - - case PatioDataPtrValueNull _ -> { - PatioDataPtrValueNullFbs.startPatioDataPtrValueNullFbs(builder); - var nullFbs = PatioDataPtrValueNullFbs.endPatioDataPtrValueNullFbs(builder); - - return PatioDataPtrValueFbs.createPatioDataPtrValueFbs( - builder, - PatioDataPtrValueValueFbs.PatioDataPtrValueNullFbs, - nullFbs - ); - } - } - } - - public static PatioDataPtrValue deserializeDataPtrValue(PatioDataPtrValueFbs valueFbs) { - return switch (valueFbs.valueType()) { - case PatioDataPtrValueValueFbs.PatioDataPtrValueDataElementFbs -> { - var dataElementFbs = (PatioDataPtrValueDataElementFbs) valueFbs.value(new PatioDataPtrValueDataElementFbs()); - yield new PatioDataPtrValueDataElement(dataElementFbs.name()); - } - - case PatioDataPtrValueValueFbs.PatioDataPtrValueNullFbs -> - new PatioDataPtrValueNull(); - - default -> - throw new UnsupportedOperationException("TODO"); - }; - } - - // == Int values == - - public static int serializeIntValue(FlatBufferBuilder builder, PatioIntValue value) { - return switch (value) { - case PatioIntValueByteOffsetOf byteOffsetOf -> { - var layoutFbs = serializeDataLayout(builder, byteOffsetOf.layout()); - var elementOffsetsFbs = PatioIntValueByteOffsetOfFbs.createElementOffsetsVector( - builder, - serializeListOfInts(byteOffsetOf.elementOffsets()) - ); - - var byteOffsetOfFbs = PatioIntValueByteOffsetOfFbs.createPatioIntValueByteOffsetOfFbs( - builder, - layoutFbs, - elementOffsetsFbs - ); - - PatioIntValueFbs.startPatioIntValueFbs(builder); - PatioIntValueFbs.addValueType(builder, PatioIntValueValueFbs.PatioIntValueByteOffsetOfFbs); - PatioIntValueFbs.addValue(builder, byteOffsetOfFbs); - yield PatioIntValueFbs.endPatioIntValueFbs(builder); - } - - case PatioIntValueByteSizeOf byteSizeOf -> { - var layoutFbs = serializeDataLayout(builder, byteSizeOf.layout()); - - var byteSizeOfFbs = PatioIntValueByteSizeOfFbs.createPatioIntValueByteSizeOfFbs(builder, layoutFbs); - - PatioIntValueFbs.startPatioIntValueFbs(builder); - PatioIntValueFbs.addValueType(builder, PatioIntValueValueFbs.PatioIntValueByteSizeOfFbs); - PatioIntValueFbs.addValue(builder, byteSizeOfFbs); - yield PatioIntValueFbs.endPatioIntValueFbs(builder); - } - - case PatioIntValueLiteral literal -> { - var literalFbs = PatioIntValueLiteralFbs.createPatioIntValueLiteralFbs(builder, literal.value()); - - PatioIntValueFbs.startPatioIntValueFbs(builder); - PatioIntValueFbs.addValueType(builder, PatioIntValueValueFbs.PatioIntValueLiteralFbs); - PatioIntValueFbs.addValue(builder, literalFbs); - yield PatioIntValueFbs.endPatioIntValueFbs(builder); - } - }; - } - - public static PatioIntValue deserializeIntValue(PatioIntValueFbs valueFbs) { - return switch (valueFbs.valueType()) { - case PatioIntValueValueFbs.PatioIntValueByteOffsetOfFbs -> { - var byteOffsetOfFbs = (PatioIntValueByteOffsetOfFbs) valueFbs.value(new PatioIntValueByteOffsetOfFbs()); - var layout = deserializeDataLayout(byteOffsetOfFbs.layout()); - var elementOffsets = deserializeListOfInts(byteOffsetOfFbs.elementOffsetsVector()); - yield new PatioIntValueByteOffsetOf(layout, elementOffsets); - } - - case PatioIntValueValueFbs.PatioIntValueByteSizeOfFbs -> { - var byteSizeOfFbs = (PatioIntValueByteSizeOfFbs) valueFbs.value(new PatioIntValueByteSizeOfFbs()); - var layout = deserializeDataLayout(byteSizeOfFbs.layout()); - yield new PatioIntValueByteSizeOf(layout); - } - - case PatioIntValueValueFbs.PatioIntValueLiteralFbs -> { - var literalFbs = (PatioIntValueLiteralFbs) valueFbs.value(new PatioIntValueLiteralFbs()); - yield new PatioIntValueLiteral(literalFbs.value()); - } - - default -> - throw new UnsupportedOperationException("TODO"); - }; - } - - // == Types == - - public static int serializeType( - FlatBufferBuilder builder, - PatioType type - ) { - return switch (type) { - case PatioBoolType _ -> { - PatioBoolTypeFbs.startPatioBoolTypeFbs(builder); - var boolTypeFbs = PatioBoolTypeFbs.endPatioBoolTypeFbs(builder); - - PatioTypeFbs.startPatioTypeFbs(builder); - PatioTypeFbs.addValueType(builder, PatioTypeValueFbs.PatioBoolTypeFbs); - PatioTypeFbs.addValue(builder, boolTypeFbs); - yield PatioTypeFbs.endPatioTypeFbs(builder); - } - - case PatioByteType _ -> { - PatioByteTypeFbs.startPatioByteTypeFbs(builder); - var byteTypeFbs = PatioByteTypeFbs.endPatioByteTypeFbs(builder); - - PatioTypeFbs.startPatioTypeFbs(builder); - PatioTypeFbs.addValueType(builder, PatioTypeValueFbs.PatioByteTypeFbs); - PatioTypeFbs.addValue(builder, byteTypeFbs); - yield PatioTypeFbs.endPatioTypeFbs(builder); - } - - case PatioDataPtrType _ -> { - PatioDataPtrTypeFbs.startPatioDataPtrTypeFbs(builder); - var dataPtrTypeFbs = PatioDataPtrTypeFbs.endPatioDataPtrTypeFbs(builder); - - PatioTypeFbs.startPatioTypeFbs(builder); - PatioTypeFbs.addValueType(builder, PatioTypeValueFbs.PatioDataPtrTypeFbs); - PatioTypeFbs.addValue(builder, dataPtrTypeFbs); - yield PatioTypeFbs.endPatioTypeFbs(builder); - } - - case PatioFunctionPtrType _ -> { - PatioFunctionPtrTypeFbs.startPatioFunctionPtrTypeFbs(builder); - var functionPtrTypeFbs = PatioFunctionPtrTypeFbs.endPatioFunctionPtrTypeFbs(builder); - - PatioTypeFbs.startPatioTypeFbs(builder); - PatioTypeFbs.addValueType(builder, PatioTypeValueFbs.PatioFunctionPtrTypeFbs); - PatioTypeFbs.addValue(builder, functionPtrTypeFbs); - yield PatioTypeFbs.endPatioTypeFbs(builder); - } - - case PatioIntType _ -> { - PatioIntTypeFbs.startPatioIntTypeFbs(builder); - var intTypeFbs = PatioIntTypeFbs.endPatioIntTypeFbs(builder); - - PatioTypeFbs.startPatioTypeFbs(builder); - PatioTypeFbs.addValueType(builder, PatioTypeValueFbs.PatioIntTypeFbs); - PatioTypeFbs.addValue(builder, intTypeFbs); - yield PatioTypeFbs.endPatioTypeFbs(builder); - } - - case PatioInt32Type _ -> { - PatioInt32TypeFbs.startPatioInt32TypeFbs(builder); - var int32TypeFbs = PatioInt32TypeFbs.endPatioInt32TypeFbs(builder); - - PatioTypeFbs.startPatioTypeFbs(builder); - PatioTypeFbs.addValueType(builder, PatioTypeValueFbs.PatioInt32TypeFbs); - PatioTypeFbs.addValue(builder, int32TypeFbs); - yield PatioTypeFbs.endPatioTypeFbs(builder); - } - }; - } - - public static PatioType deserializeType(PatioTypeFbs typeFbs) { - return switch (typeFbs.valueType()) { - case PatioTypeValueFbs.PatioBoolTypeFbs -> - PatioBoolType.INSTANCE; - - case PatioTypeValueFbs.PatioByteTypeFbs -> - PatioByteType.INSTANCE; - - case PatioTypeValueFbs.PatioDataPtrTypeFbs -> - PatioDataPtrType.INSTANCE; - - case PatioTypeValueFbs.PatioFunctionPtrTypeFbs -> - PatioFunctionPtrType.INSTANCE; - - case PatioTypeValueFbs.PatioIntTypeFbs -> - PatioIntType.INSTANCE; - - case PatioTypeValueFbs.PatioInt32TypeFbs -> - PatioInt32Type.INSTANCE; - - default -> - throw new UnsupportedOperationException("TODO"); - }; - } - - // == Data layouts == - - public static int serializeDataLayout( - FlatBufferBuilder builder, - PatioDataLayout layout - ) { - return switch (layout) { - case PatioDataLayoutArray array -> { - var elementFbs = serializeDataLayout(builder, array.element()); - - PatioDataLayoutArrayFbs.startPatioDataLayoutArrayFbs(builder); - PatioDataLayoutArrayFbs.addElement(builder, elementFbs); - PatioDataLayoutArrayFbs.addSize(builder, array.size()); - var arrayFbs = PatioDataLayoutArrayFbs.endPatioDataLayoutArrayFbs(builder); - - PatioDataLayoutFbs.startPatioDataLayoutFbs(builder); - PatioDataLayoutFbs.addValueType(builder, PatioDataLayoutValueFbs.PatioDataLayoutArrayFbs); - PatioDataLayoutFbs.addValue(builder, arrayFbs); - yield PatioDataLayoutFbs.endPatioDataLayoutFbs(builder); - } - - case PatioDataLayoutBool _ -> { - PatioDataLayoutBoolFbs.startPatioDataLayoutBoolFbs(builder); - var boolFbs = PatioDataLayoutBoolFbs.endPatioDataLayoutBoolFbs(builder); - - PatioDataLayoutFbs.startPatioDataLayoutFbs(builder); - PatioDataLayoutFbs.addValueType(builder, PatioDataLayoutValueFbs.PatioDataLayoutBoolFbs); - PatioDataLayoutFbs.addValue(builder, boolFbs); - yield PatioDataLayoutFbs.endPatioDataLayoutFbs(builder); - } - - case PatioDataLayoutByte _ -> { - PatioDataLayoutByteFbs.startPatioDataLayoutByteFbs(builder); - var byteFbs = PatioDataLayoutByteFbs.endPatioDataLayoutByteFbs(builder); - - PatioDataLayoutFbs.startPatioDataLayoutFbs(builder); - PatioDataLayoutFbs.addValueType(builder, PatioDataLayoutValueFbs.PatioDataLayoutByteFbs); - PatioDataLayoutFbs.addValue(builder, byteFbs); - yield PatioDataLayoutFbs.endPatioDataLayoutFbs(builder); - } - - case PatioDataLayoutDataPtr _ -> { - PatioDataLayoutDataPtrFbs.startPatioDataLayoutDataPtrFbs(builder); - var dataPtrFbs = PatioDataLayoutDataPtrFbs.endPatioDataLayoutDataPtrFbs(builder); - - PatioDataLayoutFbs.startPatioDataLayoutFbs(builder); - PatioDataLayoutFbs.addValueType(builder, PatioDataLayoutValueFbs.PatioDataLayoutDataPtrFbs); - PatioDataLayoutFbs.addValue(builder, dataPtrFbs); - yield PatioDataLayoutFbs.endPatioDataLayoutFbs(builder); - } - - case PatioDataLayoutFunctionPtr _ -> { - PatioDataLayoutFunctionPtrFbs.startPatioDataLayoutFunctionPtrFbs(builder); - var functionPtrFbs = PatioDataLayoutFunctionPtrFbs.endPatioDataLayoutFunctionPtrFbs(builder); - - PatioDataLayoutFbs.startPatioDataLayoutFbs(builder); - PatioDataLayoutFbs.addValueType(builder, PatioDataLayoutValueFbs.PatioDataLayoutFunctionPtrFbs); - PatioDataLayoutFbs.addValue(builder, functionPtrFbs); - yield PatioDataLayoutFbs.endPatioDataLayoutFbs(builder); - } - - case PatioDataLayoutInt _ -> { - PatioDataLayoutIntFbs.startPatioDataLayoutIntFbs(builder); - var intFbs = PatioDataLayoutIntFbs.endPatioDataLayoutIntFbs(builder); - - PatioDataLayoutFbs.startPatioDataLayoutFbs(builder); - PatioDataLayoutFbs.addValueType(builder, PatioDataLayoutValueFbs.PatioDataLayoutIntFbs); - PatioDataLayoutFbs.addValue(builder, intFbs); - yield PatioDataLayoutFbs.endPatioDataLayoutFbs(builder); - } - - case PatioDataLayoutInt32 _ -> { - PatioDataLayoutInt32Fbs.startPatioDataLayoutInt32Fbs(builder); - var int32Fbs = PatioDataLayoutInt32Fbs.endPatioDataLayoutInt32Fbs(builder); - - PatioDataLayoutFbs.startPatioDataLayoutFbs(builder); - PatioDataLayoutFbs.addValueType(builder, PatioDataLayoutValueFbs.PatioDataLayoutInt32Fbs); - PatioDataLayoutFbs.addValue(builder, int32Fbs); - yield PatioDataLayoutFbs.endPatioDataLayoutFbs(builder); - } - - case PatioDataLayoutStruct struct -> { - var elementsOffsetsFbs = struct.elements().stream() - .mapToInt(element -> serializeDataLayout(builder, element)) - .toArray(); - var elementsVectorFbs = PatioDataLayoutStructFbs.createElementsVector(builder, elementsOffsetsFbs); - - var structFbs = PatioDataLayoutStructFbs.createPatioDataLayoutStructFbs(builder, elementsVectorFbs); - - PatioDataLayoutFbs.startPatioDataLayoutFbs(builder); - PatioDataLayoutFbs.addValueType(builder, PatioDataLayoutValueFbs.PatioDataLayoutStructFbs); - PatioDataLayoutFbs.addValue(builder, structFbs); - yield PatioDataLayoutFbs.endPatioDataLayoutFbs(builder); - } - }; - } - - public static PatioDataLayout deserializeDataLayout(PatioDataLayoutFbs layoutFbs) { - return switch (layoutFbs.valueType()) { - case PatioDataLayoutValueFbs.PatioDataLayoutArrayFbs -> { - var arrayFbs = (PatioDataLayoutArrayFbs) layoutFbs.value(new PatioDataLayoutArrayFbs()); - var element = deserializeDataLayout(arrayFbs.element()); - var size = (int) arrayFbs.size(); - yield new PatioDataLayoutArray(element, size); - } - - case PatioDataLayoutValueFbs.PatioDataLayoutBoolFbs -> - PatioDataLayoutBool.INSTANCE; - - case PatioDataLayoutValueFbs.PatioDataLayoutByteFbs -> - PatioDataLayoutByte.INSTANCE; - - case PatioDataLayoutValueFbs.PatioDataLayoutDataPtrFbs -> - PatioDataLayoutDataPtr.INSTANCE; - - case PatioDataLayoutValueFbs.PatioDataLayoutFunctionPtrFbs -> - PatioDataLayoutFunctionPtr.INSTANCE; - - case PatioDataLayoutValueFbs.PatioDataLayoutIntFbs -> - PatioDataLayoutInt.INSTANCE; - - case PatioDataLayoutValueFbs.PatioDataLayoutInt32Fbs -> - PatioDataLayoutInt32.INSTANCE; - - case PatioDataLayoutValueFbs.PatioDataLayoutStructFbs -> { - var structFbs = (PatioDataLayoutStructFbs) layoutFbs.value(new PatioDataLayoutStructFbs()); - var elements = deserializeVector( - structFbs::elements, - structFbs.elementsLength(), - PatioToFlatbuffers::deserializeDataLayout - ); - yield new PatioDataLayoutStruct(elements); - } - - default -> - throw new UnsupportedOperationException("TODO"); - }; - } - - // == Data values == - - public static int serializeDataValue(FlatBufferBuilder builder, PatioDataValue value) { - return switch (value) { - case PatioDataValueArray array -> { - var elementLayoutFbs = serializeDataLayout(builder, array.elementLayout()); - - var elementsOffsetsFbs = array.elements().stream() - .mapToInt(element -> serializeDataValue(builder, element)) - .toArray(); - var elementsVectorFbs = PatioDataValueArrayFbs.createElementsVector(builder, elementsOffsetsFbs); - - PatioDataValueArrayFbs.startPatioDataValueArrayFbs(builder); - PatioDataValueArrayFbs.addElementLayout(builder, elementLayoutFbs); - PatioDataValueArrayFbs.addElements(builder, elementsVectorFbs); - var arrayFbs = PatioDataValueArrayFbs.endPatioDataValueArrayFbs(builder); - - PatioDataValueFbs.startPatioDataValueFbs(builder); - PatioDataValueFbs.addValueType(builder, PatioDataValueValueFbs.PatioDataValueArrayFbs); - PatioDataValueFbs.addValue(builder, arrayFbs); - yield PatioDataValueFbs.endPatioDataValueFbs(builder); - } - - case PatioDataValueBool bool -> { - PatioDataValueBoolFbs.startPatioDataValueBoolFbs(builder); - PatioDataValueBoolFbs.addValue(builder, bool.value()); - var boolFbs = PatioDataValueBoolFbs.endPatioDataValueBoolFbs(builder); - - PatioDataValueFbs.startPatioDataValueFbs(builder); - PatioDataValueFbs.addValueType(builder, PatioDataValueValueFbs.PatioDataValueBoolFbs); - PatioDataValueFbs.addValue(builder, boolFbs); - yield PatioDataValueFbs.endPatioDataValueFbs(builder); - } - - case PatioDataValueByte byte_ -> { - PatioDataValueByteFbs.startPatioDataValueByteFbs(builder); - PatioDataValueByteFbs.addValue(builder, byte_.value()); - var byteFbs = PatioDataValueByteFbs.endPatioDataValueByteFbs(builder); - - PatioDataValueFbs.startPatioDataValueFbs(builder); - PatioDataValueFbs.addValueType(builder, PatioDataValueValueFbs.PatioDataValueByteFbs); - PatioDataValueFbs.addValue(builder, byteFbs); - yield PatioDataValueFbs.endPatioDataValueFbs(builder); - } - - case PatioDataValueDataPtr dataPtr -> { - var dataPtrValueFbs = serializeDataPtrValue(builder, dataPtr.value()); - - PatioDataValueDataPtrFbs.startPatioDataValueDataPtrFbs(builder); - PatioDataValueDataPtrFbs.addValue(builder, dataPtrValueFbs); - var dataPtrFbs = PatioDataValueDataPtrFbs.endPatioDataValueDataPtrFbs(builder); - - PatioDataValueFbs.startPatioDataValueFbs(builder); - PatioDataValueFbs.addValueType(builder, PatioDataValueValueFbs.PatioDataValueDataPtrFbs); - PatioDataValueFbs.addValue(builder, dataPtrFbs); - yield PatioDataValueFbs.endPatioDataValueFbs(builder); - } - - case PatioDataValueInt int_ -> { - var intValueFbs = serializeIntValue(builder, int_.value()); - - PatioDataValueIntFbs.startPatioDataValueIntFbs(builder); - PatioDataValueIntFbs.addValue(builder, intValueFbs); - var intFbs = PatioDataValueIntFbs.endPatioDataValueIntFbs(builder); - - PatioDataValueFbs.startPatioDataValueFbs(builder); - PatioDataValueFbs.addValueType(builder, PatioDataValueValueFbs.PatioDataValueIntFbs); - PatioDataValueFbs.addValue(builder, intFbs); - yield PatioDataValueFbs.endPatioDataValueFbs(builder); - } - - case PatioDataValueInt32 int32 -> { - var intValueFbs = serializeIntValue(builder, int32.value()); - - PatioDataValueInt32Fbs.startPatioDataValueInt32Fbs(builder); - PatioDataValueInt32Fbs.addValue(builder, intValueFbs); - var int32Fbs = PatioDataValueInt32Fbs.endPatioDataValueInt32Fbs(builder); - - PatioDataValueFbs.startPatioDataValueFbs(builder); - PatioDataValueFbs.addValueType(builder, PatioDataValueValueFbs.PatioDataValueInt32Fbs); - PatioDataValueFbs.addValue(builder, int32Fbs); - yield PatioDataValueFbs.endPatioDataValueFbs(builder); - } - - case PatioDataValueStruct struct -> { - var elementsOffsetsFbs = struct.elements().stream() - .mapToInt(element -> serializeDataValue(builder, element)) - .toArray(); - var elementsVectorFbs = PatioDataValueStructFbs.createElementsVector(builder, elementsOffsetsFbs); - - PatioDataValueStructFbs.startPatioDataValueStructFbs(builder); - PatioDataValueStructFbs.addElements(builder, elementsVectorFbs); - var structFbs = PatioDataValueStructFbs.endPatioDataValueStructFbs(builder); - - PatioDataValueFbs.startPatioDataValueFbs(builder); - PatioDataValueFbs.addValueType(builder, PatioDataValueValueFbs.PatioDataValueStructFbs); - PatioDataValueFbs.addValue(builder, structFbs); - yield PatioDataValueFbs.endPatioDataValueFbs(builder); - } - }; - } - - public static PatioDataValue deserializeDataValue(PatioDataValueFbs valueFbs) { - return switch (valueFbs.valueType()) { - case PatioDataValueValueFbs.PatioDataValueArrayFbs -> { - var arrayFbs = (PatioDataValueArrayFbs) valueFbs.value(new PatioDataValueArrayFbs()); - - var elementLayout = deserializeDataLayout(arrayFbs.elementLayout()); - - var elements = deserializeVector( - arrayFbs::elements, - arrayFbs.elementsLength(), - PatioToFlatbuffers::deserializeDataValue - ); - - yield new PatioDataValueArray(elementLayout, elements); - } - - case PatioDataValueValueFbs.PatioDataValueBoolFbs -> { - var boolFbs = (PatioDataValueBoolFbs) valueFbs.value(new PatioDataValueBoolFbs()); - - yield new PatioDataValueBool(boolFbs.value()); - } - - case PatioDataValueValueFbs.PatioDataValueByteFbs -> { - var byteFbs = (PatioDataValueByteFbs) valueFbs.value(new PatioDataValueByteFbs()); - - yield new PatioDataValueByte((byte) byteFbs.value()); - } - - case PatioDataValueValueFbs.PatioDataValueDataPtrFbs -> { - var dataPtrFbs = (PatioDataValueDataPtrFbs) valueFbs.value(new PatioDataValueDataPtrFbs()); - - var value = deserializeDataPtrValue(dataPtrFbs.value()); - - yield new PatioDataValueDataPtr(value); - } - - case PatioDataValueValueFbs.PatioDataValueIntFbs -> { - var intFbs = (PatioDataValueIntFbs) valueFbs.value(new PatioDataValueIntFbs()); - - var value = deserializeIntValue(intFbs.value()); - - yield new PatioDataValueInt(value); - } - - case PatioDataValueValueFbs.PatioDataValueInt32Fbs -> { - var int32Fbs = (PatioDataValueInt32Fbs) valueFbs.value(new PatioDataValueInt32Fbs()); - - var value = deserializeIntValue(int32Fbs.value()); - - yield new PatioDataValueInt32(value); - } - - case PatioDataValueValueFbs.PatioDataValueStructFbs -> { - var structFbs = (PatioDataValueStructFbs) valueFbs.value(new PatioDataValueStructFbs()); - - var elements = deserializeVector( - structFbs::elements, - structFbs.elementsLength(), - PatioToFlatbuffers::deserializeDataValue - ); - - yield new PatioDataValueStruct(elements); - } - - default -> - throw new UnsupportedOperationException("TODO"); - }; - } - - // == Flatbuffers == - - private static <T, R> List<R> deserializeVector( - Function<Integer, T> get, - int length, - Function<T, R> deserializeElement - ) { - var result = new ArrayList<R>(); - for (var index = 0; index < length; index++) { - var elementFbs = get.apply(index); - var element = deserializeElement.apply(elementFbs); - result.add(element); - } - return result; - } - - private static long[] serializeListOfInts(List<Integer> list) { - var array = new long[list.size()]; - for (var index = 0; index < list.size(); index++) { - array[index] = list.get(index); - } - return array; - } - - private static List<Integer> deserializeListOfInts(IntVector vector) { - var result = new ArrayList<Integer>(); - for (var index = 0; index < vector.length(); index++) { - result.add(vector.get(index)); - } - return result; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/serialization/PatioToTransient0.java b/src/main/java/org/shedlang/compiler/patio/serialization/PatioToTransient0.java new file mode 100644 index 00000000..666100dc --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/serialization/PatioToTransient0.java @@ -0,0 +1,141 @@ +package org.shedlang.compiler.patio.serialization; + +import org.shedlang.compiler.patio.PatioCompilationUnit; +import org.shedlang.compiler.patio.PatioCompilationUnitElement; +import org.shedlang.compiler.patio.instructions.PatioInstruction; +import org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands; +import org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio; +import org.shedlang.compiler.patio.types.PatioDataLayout; +import org.shedlang.compiler.patio.types.PatioDataValue; +import org.shedlang.compiler.patio.types.PatioType; +import org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types; +import org.shedlang.compiler.patio.values.PatioDataPtrValue; +import org.shedlang.compiler.patio.values.PatioIntValue; +import org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.HashMap; + +public class PatioToTransient0 { + public static void serializeCompilationUnit( + PatioCompilationUnit value, + OutputStream outputStream + ) throws IOException { + HobgoblinTransient0Patio.encodePatioCompilationUnit(value, outputStream, new HashMap<>()); + } + + public static PatioCompilationUnit deserializeCompilationUnit( + InputStream inputStream + ) throws IOException { + return HobgoblinTransient0Patio.decodePatioCompilationUnit(inputStream, new ArrayList<>()); + } + + static void serializeCompilationUnitElement( + PatioCompilationUnitElement value, + OutputStream outputStream + ) throws IOException { + HobgoblinTransient0Patio.encodePatioCompilationUnitElement(value, outputStream, new HashMap<>()); + } + + static PatioCompilationUnitElement deserializeCompilationUnitElement( + InputStream inputStream + ) throws IOException { + return HobgoblinTransient0Patio.decodePatioCompilationUnitElement(inputStream, new ArrayList<>()); + } + + static void serializeInstruction( + PatioInstruction value, + OutputStream outputStream + ) throws IOException { + HobgoblinTransient0Instructions.encodePatioInstruction(value, outputStream, new HashMap<>()); + } + + static PatioInstruction deserializeInstruction( + InputStream inputStream + ) throws IOException { + return HobgoblinTransient0Instructions.decodePatioInstruction(inputStream, new ArrayList<>()); + } + + static void serializeOperand( + PatioOperand value, + OutputStream outputStream + ) throws IOException { + HobgoblinTransient0Operands.encodePatioOperand(value, outputStream, new HashMap<>()); + } + + static PatioOperand deserializeOperand( + InputStream inputStream + ) throws IOException { + return HobgoblinTransient0Operands.decodePatioOperand(inputStream, new ArrayList<>()); + } + + static void serializeDataPtrValue( + PatioDataPtrValue value, + OutputStream outputStream + ) throws IOException { + HobgoblinTransient0Values.encodePatioDataPtrValue(value, outputStream, new HashMap<>()); + } + + static PatioDataPtrValue deserializeDataPtrValue( + InputStream inputStream + ) throws IOException { + return HobgoblinTransient0Values.decodePatioDataPtrValue(inputStream, new ArrayList<>()); + } + + static void serializeIntValue( + PatioIntValue value, + OutputStream outputStream + ) throws IOException { + HobgoblinTransient0Values.encodePatioIntValue(value, outputStream, new HashMap<>()); + } + + static PatioIntValue deserializeIntValue( + InputStream inputStream + ) throws IOException { + return HobgoblinTransient0Values.decodePatioIntValue(inputStream, new ArrayList<>()); + } + + static void serializeType( + PatioType value, + OutputStream outputStream + ) throws IOException { + HobgoblinTransient0Types.encodePatioType(value, outputStream, new HashMap<>()); + } + + static PatioType deserializeType( + InputStream inputStream + ) throws IOException { + return HobgoblinTransient0Types.decodePatioType(inputStream, new ArrayList<>()); + } + + static void serializeDataLayout( + PatioDataLayout value, + OutputStream outputStream + ) throws IOException { + HobgoblinTransient0Types.encodePatioDataLayout(value, outputStream, new HashMap<>()); + } + + static PatioDataLayout deserializeDataLayout( + InputStream inputStream + ) throws IOException { + return HobgoblinTransient0Types.decodePatioDataLayout(inputStream, new ArrayList<>()); + } + + static void serializeDataValue( + PatioDataValue value, + OutputStream outputStream + ) throws IOException { + HobgoblinTransient0Types.encodePatioDataValue(value, outputStream, new HashMap<>()); + } + + static PatioDataValue deserializeDataValue( + InputStream inputStream + ) throws IOException { + return HobgoblinTransient0Types.decodePatioDataValue(inputStream, new ArrayList<>()); + } +} diff --git a/src/main/java/org/shedlang/compiler/sources/serialization/SourceToFlatbuffers.java b/src/main/java/org/shedlang/compiler/sources/serialization/SourceToFlatbuffers.java deleted file mode 100644 index 7c1bb074..00000000 --- a/src/main/java/org/shedlang/compiler/sources/serialization/SourceToFlatbuffers.java +++ /dev/null @@ -1,141 +0,0 @@ -package org.shedlang.compiler.sources.serialization; - -import com.google.flatbuffers.FlatBufferBuilder; -import org.shedlang.compiler.sources.*; -import org.shedlang.compiler.sources.flatbuffers.*; -import org.zwobble.sourcetext.SourcePosition; -import org.zwobble.sourcetext.SourceRange; -import org.zwobble.sourcetext.SourceText; - -import java.util.Optional; - -public class SourceToFlatbuffers { - private SourceToFlatbuffers() { - } - - public static int serializeSource( - FlatBufferBuilder builder, - Source source, - Source parentSource - ) { - return serializeSource(builder, source, Optional.of(parentSource)); - } - - public static int serializeSource( - FlatBufferBuilder builder, - Source source, - Optional<Source> parentSource - ) { - switch (source) { - case NullSource nullSource -> { - NullSourceFbs.startNullSourceFbs(builder); - var nullSourceFbs = NullSourceFbs.endNullSourceFbs(builder); - - SourceFbs.startSourceFbs(builder); - SourceFbs.addValueType(builder, SourceValueFbs.NullSourceFbs); - SourceFbs.addValue(builder, nullSourceFbs); - return SourceFbs.endSourceFbs(builder); - } - case RuntimeSource runtimeSource -> { - RuntimeSourceFbs.startRuntimeSourceFbs(builder); - var runtimeSourceFbs = RuntimeSourceFbs.endRuntimeSourceFbs(builder); - - SourceFbs.startSourceFbs(builder); - SourceFbs.addValueType(builder, SourceValueFbs.RuntimeSourceFbs); - SourceFbs.addValue(builder, runtimeSourceFbs); - return SourceFbs.endSourceFbs(builder); - } - case FileFragmentSource fileFragmentSource -> { - var fileFragmentSourceFbs = serializeFileFragmentSource(builder, fileFragmentSource, parentSource); - - SourceFbs.startSourceFbs(builder); - SourceFbs.addValueType(builder, SourceValueFbs.FileFragmentSourceFbs); - SourceFbs.addValue( - builder, - fileFragmentSourceFbs - ); - return SourceFbs.endSourceFbs(builder); - } - default -> { - throw new UnsupportedOperationException("Unhandled source: " + source); - } - } - } - - public static Source deserializeSource( - SourceFbs sourceFbs, - Source parentSource - ) { - return deserializeSource(sourceFbs, Optional.of(parentSource)); - } - - public static Source deserializeSource( - SourceFbs sourceFbs, - Optional<Source> parentSource - ) { - return switch (sourceFbs.valueType()) { - case SourceValueFbs.NullSourceFbs -> - Sources.NULL; - - case SourceValueFbs.RuntimeSourceFbs -> - Sources.RUNTIME; - - case SourceValueFbs.FileFragmentSourceFbs -> - deserializeFileFragmentSource( - (FileFragmentSourceFbs) sourceFbs.value(new FileFragmentSourceFbs()), - parentSource - ); - - default -> { - throw new UnsupportedOperationException("TODO"); - } - }; - } - - private static int serializeFileFragmentSource( - FlatBufferBuilder builder, - FileFragmentSource source, - Optional<Source> parentSource - ) { - var sourceTextName = source.sourceRange().sourceText().name(); - if (!( - parentSource.isPresent() && - parentSource.get() instanceof FileFragmentSource( - SourceRange parentSourceRange) && - parentSourceRange.sourceText().name().equals(sourceTextName) - )) { - var sourceTextNameFbs = builder.createString(sourceTextName); - var sourceTextContentsFbs = builder.createString(source.sourceRange().sourceText().charSequence()); - var sourceTextFbs = SourceTextFbs.createSourceTextFbs(builder, sourceTextNameFbs, sourceTextContentsFbs); - FileFragmentSourceFbs.startFileFragmentSourceFbs(builder); - FileFragmentSourceFbs.addSourceText(builder, sourceTextFbs); - } else { - FileFragmentSourceFbs.startFileFragmentSourceFbs(builder); - } - - FileFragmentSourceFbs.addStartCharacterIndex(builder, source.sourceRange().start().characterIndex()); - FileFragmentSourceFbs.addEndCharacterIndex(builder, source.sourceRange().end().characterIndex()); - - return FileFragmentSourceFbs.endFileFragmentSourceFbs(builder); - } - - private static FileFragmentSource deserializeFileFragmentSource( - FileFragmentSourceFbs sourceFbs, - Optional<Source> parentSource - ) { - SourceText sourceText; - if (sourceFbs.sourceText() != null) { - sourceText = SourceText.fromString( - sourceFbs.sourceText().name(), - sourceFbs.sourceText().contents() - ); - } else { - // TODO: handle missing parent - sourceText = ((FileFragmentSource) parentSource.orElseThrow()).sourceRange().sourceText(); - } - - var start = new SourcePosition(sourceText, (int) sourceFbs.startCharacterIndex()); - var end = new SourcePosition(sourceText, (int) sourceFbs.endCharacterIndex()); - return new FileFragmentSource(new SourceRange(sourceText, start, end)); - } -} diff --git a/src/test/java/org/shedlang/compiler/patio/serialization/PatioSerializationTests.java b/src/test/java/org/shedlang/compiler/patio/serialization/PatioSerializationTests.java index 2f2990bb..ae554bb8 100644 --- a/src/test/java/org/shedlang/compiler/patio/serialization/PatioSerializationTests.java +++ b/src/test/java/org/shedlang/compiler/patio/serialization/PatioSerializationTests.java @@ -8,9 +8,8 @@ import org.shedlang.compiler.patio.operands.PatioOperand; import org.shedlang.compiler.patio.types.*; import org.shedlang.compiler.patio.values.PatioDataPtrValue; import org.shedlang.compiler.patio.values.PatioIntValue; -import org.shedlang.compiler.sources.Source; -import org.shedlang.compiler.sources.Sources; +import java.io.IOException; import java.util.List; import java.util.Optional; @@ -21,11 +20,11 @@ public abstract class PatioSerializationTests { // == Compilation unit == - protected abstract PatioCompilationUnit deserializeCompilationUnit(byte[] buffer); - protected abstract byte[] serializeCompilationUnit(PatioCompilationUnit value); + protected abstract PatioCompilationUnit deserializeCompilationUnit(byte[] buffer) throws IOException; + protected abstract byte[] serializeCompilationUnit(PatioCompilationUnit value) throws IOException; @Test - public void canSerializeCompilationUnit() { + public void canSerializeCompilationUnit() throws IOException { var element = PatioFunctionDefinition.builder() .withName("f") .build(); @@ -40,11 +39,11 @@ public abstract class PatioSerializationTests { // == Compilation unit elements == - protected abstract PatioCompilationUnitElement deserializeCompilationUnitElement(byte[] buffer, Source parentSource); - protected abstract byte[] serializeCompilationUnitElement(PatioCompilationUnitElement value, Source parentSource); + protected abstract PatioCompilationUnitElement deserializeCompilationUnitElement(byte[] buffer) throws IOException; + protected abstract byte[] serializeCompilationUnitElement(PatioCompilationUnitElement value) throws IOException; @Test - public void canSerializeDataElementImmutableDefinition() { + public void canSerializeDataElementImmutableDefinition() throws IOException { var element = Patio.dataElementImmutableDefinition( "x", PatioVisibility.PRIVATE, @@ -55,30 +54,28 @@ public abstract class PatioSerializationTests { ); var deserializedElement = deserializeCompilationUnitElement( - serializeCompilationUnitElement(element, Sources.NULL), - Sources.NULL + serializeCompilationUnitElement(element) ); assertThat(deserializedElement, equalTo(element)); } @Test - public void canSerializeDataElementMutableDeclaration() { + public void canSerializeDataElementMutableDeclaration() throws IOException { var element = Patio.dataElementMutableDeclaration( "x", PatioDataLayouts.INT ); var deserializedElement = deserializeCompilationUnitElement( - serializeCompilationUnitElement(element, Sources.NULL), - Sources.NULL + serializeCompilationUnitElement(element) ); assertThat(deserializedElement, equalTo(element)); } @Test - public void canSerializeDataElementMutableDefinition() { + public void canSerializeDataElementMutableDefinition() throws IOException { var element = Patio.dataElementMutableDefinition( "x", PatioVisibility.PRIVATE, @@ -86,27 +83,25 @@ public abstract class PatioSerializationTests { ); var deserializedElement = deserializeCompilationUnitElement( - serializeCompilationUnitElement(element, Sources.NULL), - Sources.NULL + serializeCompilationUnitElement(element) ); assertThat(deserializedElement, equalTo(element)); } @Test - public void canSerializeExceptionTypeDefinition() { + public void canSerializeExceptionTypeDefinition() throws IOException { var element = Patio.exceptionTypeDefinition("Error", PatioTypes.INT); var deserializedElement = deserializeCompilationUnitElement( - serializeCompilationUnitElement(element, Sources.NULL), - Sources.NULL + serializeCompilationUnitElement(element) ); assertThat(deserializedElement, equalTo(element)); } @Test - public void canSerializeFunctionDeclaration() { + public void canSerializeFunctionDeclaration() throws IOException { var element = PatioFunctionDeclaration.builder() .withName("f") .addParam(Patio.param("param1", PatioTypes.INT)) @@ -115,15 +110,14 @@ public abstract class PatioSerializationTests { .build(); var deserializedElement = deserializeCompilationUnitElement( - serializeCompilationUnitElement(element, Sources.NULL), - Sources.NULL + serializeCompilationUnitElement(element) ); assertThat(deserializedElement, equalTo(element)); } @Test - public void canSerializeFunctionDefinition() { + public void canSerializeFunctionDefinition() throws IOException { var element = PatioFunctionDefinition.builder() .withName("f") .withVisibility(PatioVisibility.PRIVATE) @@ -136,8 +130,7 @@ public abstract class PatioSerializationTests { .build(); var deserializedElement = deserializeCompilationUnitElement( - serializeCompilationUnitElement(element, Sources.NULL), - Sources.NULL + serializeCompilationUnitElement(element) ); assertThat(deserializedElement, equalTo(element)); @@ -145,11 +138,11 @@ public abstract class PatioSerializationTests { // == Instructions == - protected abstract PatioInstruction deserializeInstruction(byte[] buffer, Source parentSource); - protected abstract byte[] serializeInstruction(PatioInstruction value, Source parentSource); + protected abstract PatioInstruction deserializeInstruction(byte[] buffer) throws IOException; + protected abstract byte[] serializeInstruction(PatioInstruction value) throws IOException; @Test - public void canSerializeBlock() { + public void canSerializeBlock() throws IOException { var instruction = Patio.block( List.of( Patio.localStore(Patio.localRef("x1"), Patio.intConst(1)), @@ -162,27 +155,25 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeBoolToInt() { + public void canSerializeBoolToInt() throws IOException { var instruction = Patio.boolToInt(Patio.localRef("destination"), Patio.localRef("value")); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeCallWithoutDestination() { + public void canSerializeCallWithoutDestination() throws IOException { var instruction = Patio.call( Optional.empty(), "f", @@ -190,15 +181,14 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeCallWithDestination() { + public void canSerializeCallWithDestination() throws IOException { var instruction = Patio.call( Optional.of(Patio.localRef("destination")), "f", @@ -206,15 +196,14 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeCallPointer() { + public void canSerializeCallPointer() throws IOException { var instruction = Patio.callPointer( Patio.localRef("destination"), Patio.localRef("f"), @@ -222,27 +211,25 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeDataPtrToInt() { + public void canSerializeDataPtrToInt() throws IOException { var instruction = Patio.dataPtrToInt(Patio.localRef("destination"), Patio.localRef("value")); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeIf() { + public void canSerializeIf() throws IOException { var instruction = Patio.if_( List.of( Patio.localRef("x"), @@ -272,15 +259,14 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeIntAdd() { + public void canSerializeIntAdd() throws IOException { var instruction = Patio.intAdd( Patio.localRef("destination"), Patio.localRef("left"), @@ -288,15 +274,14 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeIntEquals() { + public void canSerializeIntEquals() throws IOException { var instruction = Patio.intEquals( Patio.localRef("destination"), Patio.localRef("left"), @@ -304,15 +289,14 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeIntNotEqual() { + public void canSerializeIntNotEqual() throws IOException { var instruction = Patio.intNotEqual( Patio.localRef("destination"), Patio.localRef("left"), @@ -320,15 +304,14 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeIntSub() { + public void canSerializeIntSub() throws IOException { var instruction = Patio.intSub( Patio.localRef("destination"), Patio.localRef("left"), @@ -336,57 +319,53 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeIntToBool() { + public void canSerializeIntToBool() throws IOException { var instruction = Patio.intToBool(Patio.localRef("destination"), Patio.localRef("value")); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeIntToDataPtr() { + public void canSerializeIntToDataPtr() throws IOException { var instruction = Patio.intToDataPtr( Patio.localRef("destination"), Patio.localRef("value") ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeLocalStore() { + public void canSerializeLocalStore() throws IOException { var instruction = Patio.localStore( Patio.localRef("destination"), Patio.localRef("x") ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeLoop() { + public void canSerializeLoop() throws IOException { var instruction = Patio.loop( List.of( Patio.localStore(Patio.localRef("x"), Patio.intConst(1)) @@ -394,39 +373,36 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeLoopBreak() { + public void canSerializeLoopBreak() throws IOException { var instruction = Patio.loopBreak(); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeLoopContinue() { + public void canSerializeLoopContinue() throws IOException { var instruction = Patio.loopContinue(); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeMemoryLoad() { + public void canSerializeMemoryLoad() throws IOException { var instruction = Patio.memoryLoad( Patio.localRef("destination"), Patio.localRef("pointer"), @@ -435,15 +411,14 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeMemoryStore() { + public void canSerializeMemoryStore() throws IOException { var instruction = Patio.memoryStore( Patio.localRef("pointer"), PatioDataLayouts.struct(List.of(PatioDataLayouts.INT, PatioDataLayouts.INT, PatioDataLayouts.BYTE)), @@ -452,39 +427,36 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeReturn() { + public void canSerializeReturn() throws IOException { var instruction = Patio.return_(Patio.localRef("value")); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeReturnVoid() { + public void canSerializeReturnVoid() throws IOException { var instruction = Patio.returnVoid(); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeSwitch() { + public void canSerializeSwitch() throws IOException { var instruction = Patio.switch_( List.of( Patio.localRef("x"), @@ -532,27 +504,25 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeThrow() { + public void canSerializeThrow() throws IOException { var instruction = Patio.throw_("Error", Patio.localRef("value")); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeTry() { + public void canSerializeTry() throws IOException { var instruction = Patio.try_( List.of(Patio.localRef("x"), Patio.localRef("y")), List.of( @@ -589,50 +559,46 @@ public abstract class PatioSerializationTests { ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeUnreachable() { + public void canSerializeUnreachable() throws IOException { var instruction = Patio.unreachable(); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeVarLoad() { + public void canSerializeVarLoad() throws IOException { var instruction = Patio.varLoad( Patio.localRef("destination"), Patio.localRef("v") ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); } @Test - public void canSerializeVarStore() { + public void canSerializeVarStore() throws IOException { var instruction = Patio.varStore( Patio.localRef("destination"), Patio.localRef("value") ); var deserializedInstruction = deserializeInstruction( - serializeInstruction(instruction, Sources.NULL), - Sources.NULL + serializeInstruction(instruction) ); assertThat(deserializedInstruction, equalTo(instruction)); @@ -640,11 +606,11 @@ public abstract class PatioSerializationTests { // == Operands == - protected abstract PatioOperand deserializeOperand(byte[] buffer); - protected abstract byte[] serializeOperand(PatioOperand value); + protected abstract PatioOperand deserializeOperand(byte[] buffer) throws IOException; + protected abstract byte[] serializeOperand(PatioOperand value) throws IOException; @Test - public void canSerializeBoolConst() { + public void canSerializeBoolConst() throws IOException { var operand = Patio.boolConst(true); var deserializedOperand = deserializeOperand( @@ -655,7 +621,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeByteConst() { + public void canSerializeByteConst() throws IOException { var operand = Patio.byteConst((byte) 42); var deserializedOperand = deserializeOperand( @@ -666,7 +632,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataPtrConst() { + public void canSerializeDataPtrConst() throws IOException { var operand = Patio.dataPtrConst("x"); var deserializedOperand = deserializeOperand( @@ -677,7 +643,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeFunctionPtrConst() { + public void canSerializeFunctionPtrConst() throws IOException { var operand = Patio.functionPtrConst("x"); var deserializedOperand = deserializeOperand( @@ -688,7 +654,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeIntConst() { + public void canSerializeIntConst() throws IOException { var operand = Patio.intConst(42); var deserializedOperand = deserializeOperand( @@ -699,7 +665,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeInt32Const() { + public void canSerializeInt32Const() throws IOException { var operand = Patio.int32Const(42); var deserializedOperand = deserializeOperand( @@ -710,7 +676,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeLocalRef() { + public void canSerializeLocalRef() throws IOException { var operand = Patio.localRef("x"); var deserializedOperand = deserializeOperand( @@ -722,11 +688,11 @@ public abstract class PatioSerializationTests { // == Data ptr values == - protected abstract PatioDataPtrValue deserializeDataPtrValue(byte[] buffer); - protected abstract byte[] serializeDataPtrValue(PatioDataPtrValue value); + protected abstract PatioDataPtrValue deserializeDataPtrValue(byte[] buffer) throws IOException; + protected abstract byte[] serializeDataPtrValue(PatioDataPtrValue value) throws IOException; @Test - public void canSerializeDataPtrValueDataElement() { + public void canSerializeDataPtrValueDataElement() throws IOException { var dataPtrValue = Patio.dataPtrValueDataElement("string"); var deserializedDataPtrValue = deserializeDataPtrValue( @@ -737,7 +703,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataPtrValueNull() { + public void canSerializeDataPtrValueNull() throws IOException { var dataPtrValue = Patio.dataPtrValueNull(); var deserializedDataPtrValue = deserializeDataPtrValue( @@ -749,11 +715,11 @@ public abstract class PatioSerializationTests { // == Int values == - protected abstract PatioIntValue deserializeIntValue(byte[] buffer); - protected abstract byte[] serializeIntValue(PatioIntValue value); + protected abstract PatioIntValue deserializeIntValue(byte[] buffer) throws IOException; + protected abstract byte[] serializeIntValue(PatioIntValue value) throws IOException; @Test - public void canSerializeIntValueByteOffsetOf() { + public void canSerializeIntValueByteOffsetOf() throws IOException { var intValue = Patio.intValueByteOffsetOf( PatioDataLayouts.struct(List.of( PatioDataLayouts.INT, @@ -770,7 +736,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeIntValueByteSizeOf() { + public void canSerializeIntValueByteSizeOf() throws IOException { var intValue = Patio.intValueByteSizeOf( PatioDataLayouts.struct(List.of( PatioDataLayouts.INT, @@ -786,7 +752,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeIntValueLiteral() { + public void canSerializeIntValueLiteral() throws IOException { var intValue = Patio.intValueLiteral(42); var deserializedIntValue = deserializeIntValue( @@ -798,11 +764,11 @@ public abstract class PatioSerializationTests { // == Types == - protected abstract PatioType deserializeType(byte[] buffer); - protected abstract byte[] serializeType(PatioType value); + protected abstract PatioType deserializeType(byte[] buffer) throws IOException; + protected abstract byte[] serializeType(PatioType value) throws IOException; @Test - public void canSerializeBoolType() { + public void canSerializeBoolType() throws IOException { var type = PatioTypes.BOOL; var deserializedType = deserializeType( @@ -813,7 +779,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeByteType() { + public void canSerializeByteType() throws IOException { var type = PatioTypes.BYTE; var deserializedType = deserializeType( @@ -824,7 +790,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataPtrType() { + public void canSerializeDataPtrType() throws IOException { var type = PatioTypes.DATA_PTR; var deserializedType = deserializeType( @@ -835,7 +801,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeFunctionPtrType() { + public void canSerializeFunctionPtrType() throws IOException { var type = PatioTypes.FUNCTION_PTR; var deserializedType = deserializeType( @@ -846,7 +812,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeIntType() { + public void canSerializeIntType() throws IOException { var type = PatioTypes.INT; var deserializedType = deserializeType( @@ -857,7 +823,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeInt32Type() { + public void canSerializeInt32Type() throws IOException { var type = PatioTypes.INT32; var deserializedType = deserializeType( @@ -869,11 +835,11 @@ public abstract class PatioSerializationTests { // == Data layouts == - protected abstract PatioDataLayout deserializeDataLayout(byte[] buffer); - protected abstract byte[] serializeDataLayout(PatioDataLayout value); + protected abstract PatioDataLayout deserializeDataLayout(byte[] buffer) throws IOException; + protected abstract byte[] serializeDataLayout(PatioDataLayout value) throws IOException; @Test - public void canSerializeDataLayoutArray() { + public void canSerializeDataLayoutArray() throws IOException { var layout = PatioDataLayouts.array(PatioDataLayouts.INT, 4); var deserializedLayout = deserializeDataLayout( @@ -884,7 +850,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataLayoutBool() { + public void canSerializeDataLayoutBool() throws IOException { var layout = PatioDataLayouts.BOOL; var deserializedLayout = deserializeDataLayout( @@ -895,7 +861,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataLayoutByte() { + public void canSerializeDataLayoutByte() throws IOException { var layout = PatioDataLayouts.BYTE; var deserializedLayout = deserializeDataLayout( @@ -906,7 +872,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataLayoutDataPtr() { + public void canSerializeDataLayoutDataPtr() throws IOException { var layout = PatioDataLayouts.DATA_PTR; var deserializedLayout = deserializeDataLayout( @@ -917,7 +883,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataLayoutFunctionPtr() { + public void canSerializeDataLayoutFunctionPtr() throws IOException { var layout = PatioDataLayouts.FUNCTION_PTR; var deserializedLayout = deserializeDataLayout( @@ -928,7 +894,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataLayoutInt() { + public void canSerializeDataLayoutInt() throws IOException { var layout = PatioDataLayouts.INT; var deserializedLayout = deserializeDataLayout( @@ -939,7 +905,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataLayoutInt32() { + public void canSerializeDataLayoutInt32() throws IOException { var layout = PatioDataLayouts.INT32; var deserializedLayout = deserializeDataLayout( @@ -950,7 +916,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataLayoutStruct() { + public void canSerializeDataLayoutStruct() throws IOException { var layout = PatioDataLayouts.struct(List.of(PatioDataLayouts.INT, PatioDataLayouts.INT, PatioDataLayouts.BYTE)); var deserializedLayout = deserializeDataLayout( @@ -962,12 +928,11 @@ public abstract class PatioSerializationTests { // == Data values == - protected abstract PatioDataValue deserializeDataValue(byte[] buffer); - protected abstract byte[] serializeDataValue(PatioDataValue value); - + protected abstract PatioDataValue deserializeDataValue(byte[] buffer) throws IOException; + protected abstract byte[] serializeDataValue(PatioDataValue value) throws IOException; @Test - public void canSerializeDataValueArray() { + public void canSerializeDataValueArray() throws IOException { var value = PatioDataValues.array( PatioDataLayouts.BYTE, List.of( @@ -985,7 +950,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataValueBool() { + public void canSerializeDataValueBool() throws IOException { var value = PatioDataValues.bool(true); var deserializedValue = deserializeDataValue( @@ -996,7 +961,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataValueByte() { + public void canSerializeDataValueByte() throws IOException { var value = PatioDataValues.byte_(0xc8); var deserializedValue = deserializeDataValue( @@ -1007,7 +972,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataValueDataPtr() { + public void canSerializeDataValueDataPtr() throws IOException { var value = PatioDataValues.dataPtrNull(); var deserializedValue = deserializeDataValue( @@ -1018,7 +983,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataValueInt() { + public void canSerializeDataValueInt() throws IOException { var value = PatioDataValues.int_(42); var deserializedValue = deserializeDataValue( @@ -1029,7 +994,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataValueInt32() { + public void canSerializeDataValueInt32() throws IOException { var value = PatioDataValues.int32(42); var deserializedValue = deserializeDataValue( @@ -1040,7 +1005,7 @@ public abstract class PatioSerializationTests { } @Test - public void canSerializeDataValueStruct() { + public void canSerializeDataValueStruct() throws IOException { var value = PatioDataValues.struct(List.of( PatioDataValues.byte_(0x01), PatioDataValues.byte_(0x02), diff --git a/src/test/java/org/shedlang/compiler/patio/serialization/PatioToFlatbuffersTests.java b/src/test/java/org/shedlang/compiler/patio/serialization/PatioToFlatbuffersTests.java deleted file mode 100644 index 9ff08678..00000000 --- a/src/test/java/org/shedlang/compiler/patio/serialization/PatioToFlatbuffersTests.java +++ /dev/null @@ -1,144 +0,0 @@ -package org.shedlang.compiler.patio.serialization; - -import com.google.flatbuffers.FlatBufferBuilder; -import org.shedlang.compiler.patio.PatioCompilationUnit; -import org.shedlang.compiler.patio.PatioCompilationUnitElement; -import org.shedlang.compiler.patio.flatbuffers.*; -import org.shedlang.compiler.patio.instructions.PatioInstruction; -import org.shedlang.compiler.patio.operands.PatioOperand; -import org.shedlang.compiler.patio.types.PatioDataLayout; -import org.shedlang.compiler.patio.types.PatioDataValue; -import org.shedlang.compiler.patio.types.PatioType; -import org.shedlang.compiler.patio.values.PatioDataPtrValue; -import org.shedlang.compiler.patio.values.PatioIntValue; -import org.shedlang.compiler.sources.Source; - -import java.nio.ByteBuffer; - -public class PatioToFlatbuffersTests extends PatioSerializationTests { - @Override - protected byte[] serializeCompilationUnit(PatioCompilationUnit value) { - var builder = new FlatBufferBuilder(); - var valueFbs = PatioToFlatbuffers.serializeCompilationUnit(builder, value); - builder.finish(valueFbs); - return builder.sizedByteArray(); - } - - @Override - protected PatioCompilationUnit deserializeCompilationUnit(byte[] buffer) { - var valueFbs = PatioCompilationUnitFbs.getRootAsPatioCompilationUnitFbs(ByteBuffer.wrap(buffer)); - return PatioToFlatbuffers.deserializeCompilationUnit(valueFbs); - } - - @Override - protected byte[] serializeCompilationUnitElement(PatioCompilationUnitElement value, Source parentSource) { - var builder = new FlatBufferBuilder(); - var valueFbs = PatioToFlatbuffers.serializeCompilationUnitElement(builder, value, parentSource); - builder.finish(valueFbs); - return builder.sizedByteArray(); - } - - @Override - protected PatioCompilationUnitElement deserializeCompilationUnitElement(byte[] buffer, Source parentSource) { - var valueFbs = PatioCompilationUnitElementFbs.getRootAsPatioCompilationUnitElementFbs(ByteBuffer.wrap(buffer)); - return PatioToFlatbuffers.deserializeCompilationUnitElement(valueFbs, parentSource); - } - - @Override - protected byte[] serializeInstruction(PatioInstruction value, Source parentSource) { - var builder = new FlatBufferBuilder(); - var valueFbs = PatioToFlatbuffers.serializeInstruction(builder, value, parentSource); - builder.finish(valueFbs); - return builder.sizedByteArray(); - } - - @Override - protected PatioInstruction deserializeInstruction(byte[] buffer, Source parentSource) { - var valueFbs = PatioInstructionFbs.getRootAsPatioInstructionFbs(ByteBuffer.wrap(buffer)); - return PatioToFlatbuffers.deserializeInstruction(valueFbs, parentSource); - } - - @Override - protected byte[] serializeOperand(PatioOperand value) { - var builder = new FlatBufferBuilder(); - var valueFbs = PatioToFlatbuffers.serializeOperand(builder, value); - builder.finish(valueFbs); - return builder.sizedByteArray(); - } - - @Override - protected PatioOperand deserializeOperand(byte[] buffer) { - var valueFbs = PatioOperandFbs.getRootAsPatioOperandFbs(ByteBuffer.wrap(buffer)); - return PatioToFlatbuffers.deserializeOperand(valueFbs); - } - - @Override - protected byte[] serializeDataPtrValue(PatioDataPtrValue value) { - var builder = new FlatBufferBuilder(); - var valueFbs = PatioToFlatbuffers.serializeDataPtrValue(builder, value); - builder.finish(valueFbs); - return builder.sizedByteArray(); - } - - @Override - protected PatioDataPtrValue deserializeDataPtrValue(byte[] buffer) { - var valueFbs = PatioDataPtrValueFbs.getRootAsPatioDataPtrValueFbs(ByteBuffer.wrap(buffer)); - return PatioToFlatbuffers.deserializeDataPtrValue(valueFbs); - } - - @Override - protected byte[] serializeIntValue(PatioIntValue value) { - var builder = new FlatBufferBuilder(); - var valueFbs = PatioToFlatbuffers.serializeIntValue(builder, value); - builder.finish(valueFbs); - return builder.sizedByteArray(); - } - - @Override - protected PatioIntValue deserializeIntValue(byte[] buffer) { - var valueFbs = PatioIntValueFbs.getRootAsPatioIntValueFbs(ByteBuffer.wrap(buffer)); - return PatioToFlatbuffers.deserializeIntValue(valueFbs); - } - - @Override - protected byte[] serializeType(PatioType value) { - var builder = new FlatBufferBuilder(); - var valueFbs = PatioToFlatbuffers.serializeType(builder, value); - builder.finish(valueFbs); - return builder.sizedByteArray(); - } - - @Override - protected PatioType deserializeType(byte[] buffer) { - var valueFbs = PatioTypeFbs.getRootAsPatioTypeFbs(ByteBuffer.wrap(buffer)); - return PatioToFlatbuffers.deserializeType(valueFbs); - } - - @Override - protected byte[] serializeDataLayout(PatioDataLayout value) { - var builder = new FlatBufferBuilder(); - var valueFbs = PatioToFlatbuffers.serializeDataLayout(builder, value); - builder.finish(valueFbs); - return builder.sizedByteArray(); - } - - @Override - protected PatioDataLayout deserializeDataLayout(byte[] buffer) { - var valueFbs = PatioDataLayoutFbs.getRootAsPatioDataLayoutFbs(ByteBuffer.wrap(buffer)); - return PatioToFlatbuffers.deserializeDataLayout(valueFbs); - } - - @Override - protected byte[] serializeDataValue(PatioDataValue value) { - var builder = new FlatBufferBuilder(); - var valueFbs = PatioToFlatbuffers.serializeDataValue(builder, value); - builder.finish(valueFbs); - return builder.sizedByteArray(); - } - - @Override - protected PatioDataValue deserializeDataValue(byte[] buffer) { - var valueFbs = PatioDataValueFbs.getRootAsPatioDataValueFbs(ByteBuffer.wrap(buffer)); - return PatioToFlatbuffers.deserializeDataValue(valueFbs); - } -} diff --git a/src/test/java/org/shedlang/compiler/patio/serialization/PatioToTransient0Tests.java b/src/test/java/org/shedlang/compiler/patio/serialization/PatioToTransient0Tests.java new file mode 100644 index 00000000..34d54ca2 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/patio/serialization/PatioToTransient0Tests.java @@ -0,0 +1,125 @@ +package org.shedlang.compiler.patio.serialization; + +import org.shedlang.compiler.patio.PatioCompilationUnit; +import org.shedlang.compiler.patio.PatioCompilationUnitElement; +import org.shedlang.compiler.patio.instructions.PatioInstruction; +import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.patio.types.PatioDataLayout; +import org.shedlang.compiler.patio.types.PatioDataValue; +import org.shedlang.compiler.patio.types.PatioType; +import org.shedlang.compiler.patio.values.PatioDataPtrValue; +import org.shedlang.compiler.patio.values.PatioIntValue; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +public class PatioToTransient0Tests extends PatioSerializationTests { + @Override + protected byte[] serializeCompilationUnit(PatioCompilationUnit value) throws IOException { + var outputStream = new ByteArrayOutputStream(); + PatioToTransient0.serializeCompilationUnit(value, outputStream); + return outputStream.toByteArray(); + } + + @Override + protected PatioCompilationUnit deserializeCompilationUnit(byte[] buffer) throws IOException { + return PatioToTransient0.deserializeCompilationUnit(new ByteArrayInputStream(buffer)); + } + + @Override + protected byte[] serializeCompilationUnitElement(PatioCompilationUnitElement value) throws IOException { + var outputStream = new ByteArrayOutputStream(); + PatioToTransient0.serializeCompilationUnitElement(value, outputStream); + return outputStream.toByteArray(); + } + + @Override + protected PatioCompilationUnitElement deserializeCompilationUnitElement(byte[] buffer) throws IOException { + return PatioToTransient0.deserializeCompilationUnitElement(new ByteArrayInputStream(buffer)); + } + + @Override + protected byte[] serializeInstruction(PatioInstruction value) throws IOException { + var outputStream = new ByteArrayOutputStream(); + PatioToTransient0.serializeInstruction(value, outputStream); + return outputStream.toByteArray(); + } + + @Override + protected PatioInstruction deserializeInstruction(byte[] buffer) throws IOException { + return PatioToTransient0.deserializeInstruction(new ByteArrayInputStream(buffer)); + } + + @Override + protected byte[] serializeOperand(PatioOperand value) throws IOException { + var outputStream = new ByteArrayOutputStream(); + PatioToTransient0.serializeOperand(value, outputStream); + return outputStream.toByteArray(); + } + + @Override + protected PatioOperand deserializeOperand(byte[] buffer) throws IOException { + return PatioToTransient0.deserializeOperand(new ByteArrayInputStream(buffer)); + } + + @Override + protected byte[] serializeDataPtrValue(PatioDataPtrValue value) throws IOException { + var outputStream = new ByteArrayOutputStream(); + PatioToTransient0.serializeDataPtrValue(value, outputStream); + return outputStream.toByteArray(); + } + + @Override + protected PatioDataPtrValue deserializeDataPtrValue(byte[] buffer) throws IOException { + return PatioToTransient0.deserializeDataPtrValue(new ByteArrayInputStream(buffer)); + } + + @Override + protected byte[] serializeIntValue(PatioIntValue value) throws IOException { + var outputStream = new ByteArrayOutputStream(); + PatioToTransient0.serializeIntValue(value, outputStream); + return outputStream.toByteArray(); + } + + @Override + protected PatioIntValue deserializeIntValue(byte[] buffer) throws IOException { + return PatioToTransient0.deserializeIntValue(new ByteArrayInputStream(buffer)); + } + + @Override + protected byte[] serializeType(PatioType value) throws IOException { + var outputStream = new ByteArrayOutputStream(); + PatioToTransient0.serializeType(value, outputStream); + return outputStream.toByteArray(); + } + + @Override + protected PatioType deserializeType(byte[] buffer) throws IOException { + return PatioToTransient0.deserializeType(new ByteArrayInputStream(buffer)); + } + + @Override + protected byte[] serializeDataLayout(PatioDataLayout value) throws IOException { + var outputStream = new ByteArrayOutputStream(); + PatioToTransient0.serializeDataLayout(value, outputStream); + return outputStream.toByteArray(); + } + + @Override + protected PatioDataLayout deserializeDataLayout(byte[] buffer) throws IOException { + return PatioToTransient0.deserializeDataLayout(new ByteArrayInputStream(buffer)); + } + + @Override + protected byte[] serializeDataValue(PatioDataValue value) throws IOException { + var outputStream = new ByteArrayOutputStream(); + PatioToTransient0.serializeDataValue(value, outputStream); + return outputStream.toByteArray(); + } + + @Override + protected PatioDataValue deserializeDataValue(byte[] buffer) throws IOException { + return PatioToTransient0.deserializeDataValue(new ByteArrayInputStream(buffer)); + } +} diff --git a/src/test/java/org/shedlang/compiler/sources/SourceSerializationTests.java b/src/test/java/org/shedlang/compiler/sources/SourceSerializationTests.java deleted file mode 100644 index cf54479a..00000000 --- a/src/test/java/org/shedlang/compiler/sources/SourceSerializationTests.java +++ /dev/null @@ -1,104 +0,0 @@ -package org.shedlang.compiler.sources; - -import org.junit.jupiter.api.Test; -import org.zwobble.sourcetext.SourcePosition; -import org.zwobble.sourcetext.SourceRange; -import org.zwobble.sourcetext.SourceText; - -import java.util.Optional; -import java.util.function.BiFunction; - -import static org.zwobble.precisely.AssertThat.assertThat; -import static org.zwobble.precisely.Matchers.equalTo; - -public abstract class SourceSerializationTests { - private final BiFunction<Source, Optional<Source>, byte[]> serialize; - private final BiFunction<byte[], Optional<Source>, Source> deserialize; - - public SourceSerializationTests( - BiFunction<Source, Optional<Source>, byte[]> serialize, - BiFunction<byte[], Optional<Source>, Source> deserialize - ) { - this.serialize = serialize; - this.deserialize = deserialize; - } - - private byte[] serializeSource( - Source source, - Optional<Source> parentSource - ) { - return this.serialize.apply(source, parentSource); - } - - private Source deserializeSource( - byte[] serializedSource, - Optional<Source> parentSource - ) { - return this.deserialize.apply(serializedSource, parentSource); - } - - @Test - public void canSerializeNullSource() { - var source = Sources.NULL; - - var deserializedSource = deserializeSource( - serializeSource(source, Optional.empty()), - Optional.empty() - ); - - assertThat(deserializedSource, equalTo(source)); - } - - @Test - public void canSerializeRuntimeSource() { - var source = Sources.RUNTIME; - - var deserializedSource = deserializeSource( - serializeSource(source, Optional.empty()), - Optional.empty() - ); - - assertThat(deserializedSource, equalTo(source)); - } - - @Test - public void whenFileFragmentSourceHasNoParentThenSourceTextIsPreserved() { - var sourceText = SourceText.fromString("a/b", "<contents>"); - var source = new FileFragmentSource(new SourceRange( - sourceText, - new SourcePosition(sourceText, 2), - new SourcePosition(sourceText, 5) - )); - - var deserializedSource = deserializeSource( - serializeSource(source, Optional.empty()), - Optional.empty() - ); - - assertThat(deserializedSource.describe(), equalTo(source.describe())); - } - - @Test - public void whenFileFragmentSourceNoExplicitSourceTextThenSourceTextFromParentIsReused() { - var sourceText = SourceText.fromString("a/b", "<contents>"); - var sourceRange = new SourceRange( - sourceText, - new SourcePosition(sourceText, 2), - new SourcePosition(sourceText, 5) - ); - var source = new FileFragmentSource(sourceRange); - var parentSource = new FileFragmentSource(new SourceRange( - sourceText, - new SourcePosition(sourceText, 0), - new SourcePosition(sourceText, 10) - )); - - var deserializedSource = (FileFragmentSource) deserializeSource( - serializeSource(source, Optional.of(parentSource)), - Optional.of(parentSource) - ); - - assertThat(deserializedSource.describe(), equalTo(source.describe())); - assertThat(deserializedSource.sourceRange().sourceText() == sourceText, equalTo(true)); - } -} diff --git a/src/test/java/org/shedlang/compiler/sources/serialization/SourceToFlatbuffersTests.java b/src/test/java/org/shedlang/compiler/sources/serialization/SourceToFlatbuffersTests.java deleted file mode 100644 index 731c302d..00000000 --- a/src/test/java/org/shedlang/compiler/sources/serialization/SourceToFlatbuffersTests.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.shedlang.compiler.sources.serialization; - -import com.google.flatbuffers.FlatBufferBuilder; -import org.shedlang.compiler.sources.SourceSerializationTests; -import org.shedlang.compiler.sources.flatbuffers.SourceFbs; - -import java.nio.ByteBuffer; - -public class SourceToFlatbuffersTests extends SourceSerializationTests { - public SourceToFlatbuffersTests() { - super( - (source, parentSource) -> { - var builder = new FlatBufferBuilder(); - var sourceFbs = SourceToFlatbuffers.serializeSource(builder, source, parentSource); - builder.finish(sourceFbs); - return builder.sizedByteArray(); - }, - - (serializedSource, parentSource) -> { - var sourceFbs = SourceFbs.getRootAsSourceFbs(ByteBuffer.wrap(serializedSource)); - return SourceToFlatbuffers.deserializeSource(sourceFbs, parentSource); - } - ); - } -} diff --git a/src/transient-0/java/org/shedlang/compiler/patio/instructions/transient0/HobgoblinTransient0Instructions.java b/src/transient-0/java/org/shedlang/compiler/patio/instructions/transient0/HobgoblinTransient0Instructions.java new file mode 100644 index 00000000..bf74f430 --- /dev/null +++ b/src/transient-0/java/org/shedlang/compiler/patio/instructions/transient0/HobgoblinTransient0Instructions.java @@ -0,0 +1,712 @@ +// Generated by hobgoblin. + +package org.shedlang.compiler.patio.instructions.transient0; + +// Custom area start: org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions imports +// Custom area end: org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions imports + +public final class HobgoblinTransient0Instructions { + public static void encodePatioInstruction(org.shedlang.compiler.patio.instructions.PatioInstruction value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + switch (value) { + case org.shedlang.compiler.patio.instructions.PatioBlock value$0 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(0, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioBlock(value$0, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioBoolToInt value$1 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(1, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioBoolToInt(value$1, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioCall value$2 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(2, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioCall(value$2, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioCallPointer value$3 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(3, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioCallPointer(value$3, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioDataPtrToInt value$4 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(4, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioDataPtrToInt(value$4, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioIf value$5 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(5, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioIf(value$5, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioIntAdd value$6 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(6, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioIntAdd(value$6, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioIntEquals value$7 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(7, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioIntEquals(value$7, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioIntNotEqual value$8 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(8, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioIntNotEqual(value$8, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioIntSub value$9 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(9, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioIntSub(value$9, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioIntToBool value$10 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(10, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioIntToBool(value$10, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioIntToDataPtr value$11 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(11, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioIntToDataPtr(value$11, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioLocalStore value$12 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(12, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioLocalStore(value$12, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioLoop value$13 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(13, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioLoop(value$13, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioLoopBreak value$14 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(14, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioLoopBreak(value$14, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioLoopContinue value$15 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(15, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioLoopContinue(value$15, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioMemoryLoad value$16 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(16, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioMemoryLoad(value$16, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioMemoryStore value$17 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(17, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioMemoryStore(value$17, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioReturn value$18 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(18, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioReturn(value$18, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioSwitch value$19 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(19, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioSwitch(value$19, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioThrow value$20 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(20, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioThrow(value$20, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioTry value$21 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(21, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioTry(value$21, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioUnreachable value$22 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(22, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioUnreachable(value$22, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioVarLoad value$23 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(23, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioVarLoad(value$23, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.instructions.PatioVarStore value$24 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(24, outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioVarStore(value$24, outputStream, sharedValues); + } + } + } + + public static org.shedlang.compiler.patio.instructions.PatioInstruction decodePatioInstruction(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var variantTag = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); + switch (variantTag) { + case 0 -> { + var value$0 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioBlock(inputStream, sharedValues); + return value$0; + } + case 1 -> { + var value$1 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioBoolToInt(inputStream, sharedValues); + return value$1; + } + case 2 -> { + var value$2 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioCall(inputStream, sharedValues); + return value$2; + } + case 3 -> { + var value$3 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioCallPointer(inputStream, sharedValues); + return value$3; + } + case 4 -> { + var value$4 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioDataPtrToInt(inputStream, sharedValues); + return value$4; + } + case 5 -> { + var value$5 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioIf(inputStream, sharedValues); + return value$5; + } + case 6 -> { + var value$6 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioIntAdd(inputStream, sharedValues); + return value$6; + } + case 7 -> { + var value$7 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioIntEquals(inputStream, sharedValues); + return value$7; + } + case 8 -> { + var value$8 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioIntNotEqual(inputStream, sharedValues); + return value$8; + } + case 9 -> { + var value$9 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioIntSub(inputStream, sharedValues); + return value$9; + } + case 10 -> { + var value$10 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioIntToBool(inputStream, sharedValues); + return value$10; + } + case 11 -> { + var value$11 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioIntToDataPtr(inputStream, sharedValues); + return value$11; + } + case 12 -> { + var value$12 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioLocalStore(inputStream, sharedValues); + return value$12; + } + case 13 -> { + var value$13 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioLoop(inputStream, sharedValues); + return value$13; + } + case 14 -> { + var value$14 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioLoopBreak(inputStream, sharedValues); + return value$14; + } + case 15 -> { + var value$15 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioLoopContinue(inputStream, sharedValues); + return value$15; + } + case 16 -> { + var value$16 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioMemoryLoad(inputStream, sharedValues); + return value$16; + } + case 17 -> { + var value$17 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioMemoryStore(inputStream, sharedValues); + return value$17; + } + case 18 -> { + var value$18 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioReturn(inputStream, sharedValues); + return value$18; + } + case 19 -> { + var value$19 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioSwitch(inputStream, sharedValues); + return value$19; + } + case 20 -> { + var value$20 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioThrow(inputStream, sharedValues); + return value$20; + } + case 21 -> { + var value$21 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioTry(inputStream, sharedValues); + return value$21; + } + case 22 -> { + var value$22 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioUnreachable(inputStream, sharedValues); + return value$22; + } + case 23 -> { + var value$23 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioVarLoad(inputStream, sharedValues); + return value$23; + } + case 24 -> { + var value$24 = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioVarStore(inputStream, sharedValues); + return value$24; + } + default -> { + throw new java.lang.RuntimeException("unexpected patio/instructions.PatioInstruction variant tag: " + variantTag); + } + } + } + + public static void encodePatioBlock(org.shedlang.compiler.patio.instructions.PatioBlock value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.body().size(), outputStream, sharedValues); + for (var element : value.body()) { + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioInstruction(element, outputStream, sharedValues); + } + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.results().size(), outputStream, sharedValues); + for (var element : value.results()) { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(element, outputStream, sharedValues); + } + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioBlock decodePatioBlock(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var body$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var body = new java.util.ArrayList<org.shedlang.compiler.patio.instructions.PatioInstruction>((int) body$size); + for (long body$index = 0; body$index < body$size; body$index++) { + var body$element = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioInstruction(inputStream, sharedValues); + body.add(body$element); + } + var results$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var results = new java.util.ArrayList<org.shedlang.compiler.patio.operands.PatioOperand>((int) results$size); + for (long results$index = 0; results$index < results$size; results$index++) { + var results$element = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + results.add(results$element); + } + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioBlock(body, results, source); + } + + public static void encodePatioBoolToInt(org.shedlang.compiler.patio.instructions.PatioBoolToInt value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioLocalRef(value.destination(), outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(value.value(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioBoolToInt decodePatioBoolToInt(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var destination = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioLocalRef(inputStream, sharedValues); + var value = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioBoolToInt(destination, value, source); + } + + public static void encodePatioCall(org.shedlang.compiler.patio.instructions.PatioCall value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.destinations().size(), outputStream, sharedValues); + for (var element : value.destinations()) { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioLocalRef(element, outputStream, sharedValues); + } + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeString(value.functionName(), outputStream, sharedValues); + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.args().size(), outputStream, sharedValues); + for (var element : value.args()) { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(element, outputStream, sharedValues); + } + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioCall decodePatioCall(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var destinations$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var destinations = new java.util.ArrayList<org.shedlang.compiler.patio.operands.PatioLocalRef>((int) destinations$size); + for (long destinations$index = 0; destinations$index < destinations$size; destinations$index++) { + var destinations$element = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioLocalRef(inputStream, sharedValues); + destinations.add(destinations$element); + } + var functionName = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeString(inputStream, sharedValues); + var args$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var args = new java.util.ArrayList<org.shedlang.compiler.patio.operands.PatioOperand>((int) args$size); + for (long args$index = 0; args$index < args$size; args$index++) { + var args$element = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + args.add(args$element); + } + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioCall(destinations, functionName, args, source); + } + + public static void encodePatioCallPointer(org.shedlang.compiler.patio.instructions.PatioCallPointer value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.destinations().size(), outputStream, sharedValues); + for (var element : value.destinations()) { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioLocalRef(element, outputStream, sharedValues); + } + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(value.functionPointer(), outputStream, sharedValues); + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.args().size(), outputStream, sharedValues); + for (var element : value.args()) { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(element, outputStream, sharedValues); + } + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioCallPointer decodePatioCallPointer(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var destinations$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var destinations = new java.util.ArrayList<org.shedlang.compiler.patio.operands.PatioLocalRef>((int) destinations$size); + for (long destinations$index = 0; destinations$index < destinations$size; destinations$index++) { + var destinations$element = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioLocalRef(inputStream, sharedValues); + destinations.add(destinations$element); + } + var functionPointer = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + var args$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var args = new java.util.ArrayList<org.shedlang.compiler.patio.operands.PatioOperand>((int) args$size); + for (long args$index = 0; args$index < args$size; args$index++) { + var args$element = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + args.add(args$element); + } + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioCallPointer(destinations, functionPointer, args, source); + } + + public static void encodePatioDataPtrToInt(org.shedlang.compiler.patio.instructions.PatioDataPtrToInt value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioLocalRef(value.destination(), outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(value.value(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioDataPtrToInt decodePatioDataPtrToInt(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var destination = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioLocalRef(inputStream, sharedValues); + var value = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioDataPtrToInt(destination, value, source); + } + + public static void encodePatioIf(org.shedlang.compiler.patio.instructions.PatioIf value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.destinations().size(), outputStream, sharedValues); + for (var element : value.destinations()) { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioLocalRef(element, outputStream, sharedValues); + } + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(value.condition(), outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioBlock(value.trueBody(), outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioBlock(value.falseBody(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioIf decodePatioIf(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var destinations$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var destinations = new java.util.ArrayList<org.shedlang.compiler.patio.operands.PatioLocalRef>((int) destinations$size); + for (long destinations$index = 0; destinations$index < destinations$size; destinations$index++) { + var destinations$element = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioLocalRef(inputStream, sharedValues); + destinations.add(destinations$element); + } + var condition = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + var trueBody = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioBlock(inputStream, sharedValues); + var falseBody = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioBlock(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioIf(destinations, condition, trueBody, falseBody, source); + } + + public static void encodePatioIntAdd(org.shedlang.compiler.patio.instructions.PatioIntAdd value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioLocalRef(value.destination(), outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(value.left(), outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(value.right(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioIntAdd decodePatioIntAdd(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var destination = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioLocalRef(inputStream, sharedValues); + var left = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + var right = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioIntAdd(destination, left, right, source); + } + + public static void encodePatioIntEquals(org.shedlang.compiler.patio.instructions.PatioIntEquals value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioLocalRef(value.destination(), outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(value.left(), outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(value.right(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioIntEquals decodePatioIntEquals(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var destination = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioLocalRef(inputStream, sharedValues); + var left = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + var right = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioIntEquals(destination, left, right, source); + } + + public static void encodePatioIntNotEqual(org.shedlang.compiler.patio.instructions.PatioIntNotEqual value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioLocalRef(value.destination(), outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(value.left(), outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(value.right(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioIntNotEqual decodePatioIntNotEqual(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var destination = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioLocalRef(inputStream, sharedValues); + var left = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + var right = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioIntNotEqual(destination, left, right, source); + } + + public static void encodePatioIntSub(org.shedlang.compiler.patio.instructions.PatioIntSub value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioLocalRef(value.destination(), outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(value.left(), outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(value.right(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioIntSub decodePatioIntSub(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var destination = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioLocalRef(inputStream, sharedValues); + var left = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + var right = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioIntSub(destination, left, right, source); + } + + public static void encodePatioIntToBool(org.shedlang.compiler.patio.instructions.PatioIntToBool value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioLocalRef(value.destination(), outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(value.value(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioIntToBool decodePatioIntToBool(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var destination = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioLocalRef(inputStream, sharedValues); + var value = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioIntToBool(destination, value, source); + } + + public static void encodePatioIntToDataPtr(org.shedlang.compiler.patio.instructions.PatioIntToDataPtr value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioLocalRef(value.destination(), outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(value.value(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioIntToDataPtr decodePatioIntToDataPtr(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var destination = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioLocalRef(inputStream, sharedValues); + var value = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioIntToDataPtr(destination, value, source); + } + + public static void encodePatioLocalStore(org.shedlang.compiler.patio.instructions.PatioLocalStore value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioLocalRef(value.destination(), outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(value.value(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioLocalStore decodePatioLocalStore(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var destination = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioLocalRef(inputStream, sharedValues); + var value = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioLocalStore(destination, value, source); + } + + public static void encodePatioLoop(org.shedlang.compiler.patio.instructions.PatioLoop value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.body().size(), outputStream, sharedValues); + for (var element : value.body()) { + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioInstruction(element, outputStream, sharedValues); + } + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioLoop decodePatioLoop(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var body$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var body = new java.util.ArrayList<org.shedlang.compiler.patio.instructions.PatioInstruction>((int) body$size); + for (long body$index = 0; body$index < body$size; body$index++) { + var body$element = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioInstruction(inputStream, sharedValues); + body.add(body$element); + } + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioLoop(body, source); + } + + public static void encodePatioLoopBreak(org.shedlang.compiler.patio.instructions.PatioLoopBreak value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioLoopBreak decodePatioLoopBreak(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioLoopBreak(source); + } + + public static void encodePatioLoopContinue(org.shedlang.compiler.patio.instructions.PatioLoopContinue value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioLoopContinue decodePatioLoopContinue(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioLoopContinue(source); + } + + public static void encodePatioMemoryLoad(org.shedlang.compiler.patio.instructions.PatioMemoryLoad value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioLocalRef(value.destination(), outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(value.pointer(), outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataLayout(value.layout(), outputStream, sharedValues); + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.elementOffsets().size(), outputStream, sharedValues); + for (var element : value.elementOffsets()) { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(element, outputStream, sharedValues); + } + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioMemoryLoad decodePatioMemoryLoad(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var destination = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioLocalRef(inputStream, sharedValues); + var pointer = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + var layout = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataLayout(inputStream, sharedValues); + var elementOffsets$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var elementOffsets = new java.util.ArrayList<java.lang.Integer>((int) elementOffsets$size); + for (long elementOffsets$index = 0; elementOffsets$index < elementOffsets$size; elementOffsets$index++) { + var elementOffsets$element = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); + elementOffsets.add(elementOffsets$element); + } + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioMemoryLoad(destination, pointer, layout, elementOffsets, source); + } + + public static void encodePatioMemoryStore(org.shedlang.compiler.patio.instructions.PatioMemoryStore value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(value.pointer(), outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataLayout(value.layout(), outputStream, sharedValues); + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.elementOffsets().size(), outputStream, sharedValues); + for (var element : value.elementOffsets()) { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(element, outputStream, sharedValues); + } + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(value.value(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioMemoryStore decodePatioMemoryStore(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var pointer = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + var layout = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataLayout(inputStream, sharedValues); + var elementOffsets$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var elementOffsets = new java.util.ArrayList<java.lang.Integer>((int) elementOffsets$size); + for (long elementOffsets$index = 0; elementOffsets$index < elementOffsets$size; elementOffsets$index++) { + var elementOffsets$element = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); + elementOffsets.add(elementOffsets$element); + } + var value = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioMemoryStore(pointer, layout, elementOffsets, value, source); + } + + public static void encodePatioReturn(org.shedlang.compiler.patio.instructions.PatioReturn value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.values().size(), outputStream, sharedValues); + for (var element : value.values()) { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(element, outputStream, sharedValues); + } + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioReturn decodePatioReturn(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var values$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var values = new java.util.ArrayList<org.shedlang.compiler.patio.operands.PatioOperand>((int) values$size); + for (long values$index = 0; values$index < values$size; values$index++) { + var values$element = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + values.add(values$element); + } + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioReturn(values, source); + } + + public static void encodePatioSwitch(org.shedlang.compiler.patio.instructions.PatioSwitch value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.destinations().size(), outputStream, sharedValues); + for (var element : value.destinations()) { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioLocalRef(element, outputStream, sharedValues); + } + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(value.value(), outputStream, sharedValues); + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.cases().size(), outputStream, sharedValues); + for (var element : value.cases()) { + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioSwitchCase(element, outputStream, sharedValues); + } + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioBlock(value.defaultBody(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioSwitch decodePatioSwitch(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var destinations$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var destinations = new java.util.ArrayList<org.shedlang.compiler.patio.operands.PatioLocalRef>((int) destinations$size); + for (long destinations$index = 0; destinations$index < destinations$size; destinations$index++) { + var destinations$element = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioLocalRef(inputStream, sharedValues); + destinations.add(destinations$element); + } + var value = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + var cases$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var cases = new java.util.ArrayList<org.shedlang.compiler.patio.instructions.PatioSwitchCase>((int) cases$size); + for (long cases$index = 0; cases$index < cases$size; cases$index++) { + var cases$element = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioSwitchCase(inputStream, sharedValues); + cases.add(cases$element); + } + var defaultBody = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioBlock(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioSwitch(destinations, value, cases, defaultBody, source); + } + + public static void encodePatioSwitchCase(org.shedlang.compiler.patio.instructions.PatioSwitchCase value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(value.value(), outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioBlock(value.body(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioSwitchCase decodePatioSwitchCase(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var value = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); + var body = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioBlock(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioSwitchCase(value, body, source); + } + + public static void encodePatioThrow(org.shedlang.compiler.patio.instructions.PatioThrow value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeString(value.exceptionTypeName(), outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(value.value(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioThrow decodePatioThrow(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var exceptionTypeName = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeString(inputStream, sharedValues); + var value = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioThrow(exceptionTypeName, value, source); + } + + public static void encodePatioTry(org.shedlang.compiler.patio.instructions.PatioTry value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.destinations().size(), outputStream, sharedValues); + for (var element : value.destinations()) { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioLocalRef(element, outputStream, sharedValues); + } + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.catchClauses().size(), outputStream, sharedValues); + for (var element : value.catchClauses()) { + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioCatchClause(element, outputStream, sharedValues); + } + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioBlock(value.body(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioTry decodePatioTry(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var destinations$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var destinations = new java.util.ArrayList<org.shedlang.compiler.patio.operands.PatioLocalRef>((int) destinations$size); + for (long destinations$index = 0; destinations$index < destinations$size; destinations$index++) { + var destinations$element = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioLocalRef(inputStream, sharedValues); + destinations.add(destinations$element); + } + var catchClauses$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var catchClauses = new java.util.ArrayList<org.shedlang.compiler.patio.instructions.PatioCatchClause>((int) catchClauses$size); + for (long catchClauses$index = 0; catchClauses$index < catchClauses$size; catchClauses$index++) { + var catchClauses$element = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioCatchClause(inputStream, sharedValues); + catchClauses.add(catchClauses$element); + } + var body = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioBlock(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioTry(destinations, catchClauses, body, source); + } + + public static void encodePatioCatchClause(org.shedlang.compiler.patio.instructions.PatioCatchClause value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeString(value.exceptionTypeName(), outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioLocalRef(value.destination(), outputStream, sharedValues); + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioBlock(value.body(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioCatchClause decodePatioCatchClause(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var exceptionTypeName = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeString(inputStream, sharedValues); + var destination = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioLocalRef(inputStream, sharedValues); + var body = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioBlock(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioCatchClause(exceptionTypeName, destination, body, source); + } + + public static void encodePatioUnreachable(org.shedlang.compiler.patio.instructions.PatioUnreachable value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioUnreachable decodePatioUnreachable(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioUnreachable(source); + } + + public static void encodePatioVarLoad(org.shedlang.compiler.patio.instructions.PatioVarLoad value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioLocalRef(value.destination(), outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioLocalRef(value.var(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioVarLoad decodePatioVarLoad(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var destination = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioLocalRef(inputStream, sharedValues); + var var = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioLocalRef(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioVarLoad(destination, var, source); + } + + public static void encodePatioVarStore(org.shedlang.compiler.patio.instructions.PatioVarStore value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioLocalRef(value.var(), outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioOperand(value.value(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.instructions.PatioVarStore decodePatioVarStore(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var var = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioLocalRef(inputStream, sharedValues); + var value = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioOperand(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.instructions.PatioVarStore(var, value, source); + } + + // Custom area start: org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions body + // Custom area end: org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions body +} diff --git a/src/transient-0/java/org/shedlang/compiler/patio/operands/transient0/HobgoblinTransient0Operands.java b/src/transient-0/java/org/shedlang/compiler/patio/operands/transient0/HobgoblinTransient0Operands.java new file mode 100644 index 00000000..6ef7b90f --- /dev/null +++ b/src/transient-0/java/org/shedlang/compiler/patio/operands/transient0/HobgoblinTransient0Operands.java @@ -0,0 +1,144 @@ +// Generated by hobgoblin. + +package org.shedlang.compiler.patio.operands.transient0; + +// Custom area start: org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands imports +// Custom area end: org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands imports + +public final class HobgoblinTransient0Operands { + public static void encodePatioOperand(org.shedlang.compiler.patio.operands.PatioOperand value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + switch (value) { + case org.shedlang.compiler.patio.operands.PatioLocalRef value$0 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(0, outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioLocalRef(value$0, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.operands.PatioBoolConst value$1 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(1, outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioBoolConst(value$1, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.operands.PatioByteConst value$2 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(2, outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioByteConst(value$2, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.operands.PatioDataPtrConst value$3 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(3, outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioDataPtrConst(value$3, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.operands.PatioFunctionPtrConst value$4 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(4, outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioFunctionPtrConst(value$4, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.operands.PatioInt32Const value$5 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(5, outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioInt32Const(value$5, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.operands.PatioIntConst value$6 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(6, outputStream, sharedValues); + org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.encodePatioIntConst(value$6, outputStream, sharedValues); + } + } + } + + public static org.shedlang.compiler.patio.operands.PatioOperand decodePatioOperand(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var variantTag = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); + switch (variantTag) { + case 0 -> { + var value$0 = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioLocalRef(inputStream, sharedValues); + return value$0; + } + case 1 -> { + var value$1 = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioBoolConst(inputStream, sharedValues); + return value$1; + } + case 2 -> { + var value$2 = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioByteConst(inputStream, sharedValues); + return value$2; + } + case 3 -> { + var value$3 = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioDataPtrConst(inputStream, sharedValues); + return value$3; + } + case 4 -> { + var value$4 = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioFunctionPtrConst(inputStream, sharedValues); + return value$4; + } + case 5 -> { + var value$5 = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioInt32Const(inputStream, sharedValues); + return value$5; + } + case 6 -> { + var value$6 = org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands.decodePatioIntConst(inputStream, sharedValues); + return value$6; + } + default -> { + throw new java.lang.RuntimeException("unexpected patio/operands.PatioOperand variant tag: " + variantTag); + } + } + } + + public static void encodePatioLocalRef(org.shedlang.compiler.patio.operands.PatioLocalRef value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeString(value.name(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.operands.PatioLocalRef decodePatioLocalRef(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var name = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeString(inputStream, sharedValues); + return new org.shedlang.compiler.patio.operands.PatioLocalRef(name); + } + + public static void encodePatioBoolConst(org.shedlang.compiler.patio.operands.PatioBoolConst value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeBool(value.value(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.operands.PatioBoolConst decodePatioBoolConst(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var value = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeBool(inputStream, sharedValues); + return new org.shedlang.compiler.patio.operands.PatioBoolConst(value); + } + + public static void encodePatioByteConst(org.shedlang.compiler.patio.operands.PatioByteConst value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt8(value.value(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.operands.PatioByteConst decodePatioByteConst(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var value = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt8(inputStream, sharedValues); + return new org.shedlang.compiler.patio.operands.PatioByteConst(value); + } + + public static void encodePatioDataPtrConst(org.shedlang.compiler.patio.operands.PatioDataPtrConst value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.encodePatioDataPtrValue(value.value(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.operands.PatioDataPtrConst decodePatioDataPtrConst(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var value = org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.decodePatioDataPtrValue(inputStream, sharedValues); + return new org.shedlang.compiler.patio.operands.PatioDataPtrConst(value); + } + + public static void encodePatioFunctionPtrConst(org.shedlang.compiler.patio.operands.PatioFunctionPtrConst value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeString(value.name(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.operands.PatioFunctionPtrConst decodePatioFunctionPtrConst(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var name = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeString(inputStream, sharedValues); + return new org.shedlang.compiler.patio.operands.PatioFunctionPtrConst(name); + } + + public static void encodePatioInt32Const(org.shedlang.compiler.patio.operands.PatioInt32Const value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.encodePatioIntValue(value.value(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.operands.PatioInt32Const decodePatioInt32Const(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var value = org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.decodePatioIntValue(inputStream, sharedValues); + return new org.shedlang.compiler.patio.operands.PatioInt32Const(value); + } + + public static void encodePatioIntConst(org.shedlang.compiler.patio.operands.PatioIntConst value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.encodePatioIntValue(value.value(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.operands.PatioIntConst decodePatioIntConst(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var value = org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.decodePatioIntValue(inputStream, sharedValues); + return new org.shedlang.compiler.patio.operands.PatioIntConst(value); + } + + // Custom area start: org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands body + // Custom area end: org.shedlang.compiler.patio.operands.transient0.HobgoblinTransient0Operands body +} diff --git a/src/transient-0/java/org/shedlang/compiler/patio/transient0/HobgoblinTransient0Patio.java b/src/transient-0/java/org/shedlang/compiler/patio/transient0/HobgoblinTransient0Patio.java new file mode 100644 index 00000000..77b4f6d6 --- /dev/null +++ b/src/transient-0/java/org/shedlang/compiler/patio/transient0/HobgoblinTransient0Patio.java @@ -0,0 +1,257 @@ +// Generated by hobgoblin. + +package org.shedlang.compiler.patio.transient0; + +// Custom area start: org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio imports +// Custom area end: org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio imports + +public final class HobgoblinTransient0Patio { + public static void encodePatioCompilationUnit(org.shedlang.compiler.patio.PatioCompilationUnit value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.elements().size(), outputStream, sharedValues); + for (var element : value.elements()) { + org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.encodePatioCompilationUnitElement(element, outputStream, sharedValues); + } + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.PatioCompilationUnit decodePatioCompilationUnit(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var elements$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var elements = new java.util.ArrayList<org.shedlang.compiler.patio.PatioCompilationUnitElement>((int) elements$size); + for (long elements$index = 0; elements$index < elements$size; elements$index++) { + var elements$element = org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.decodePatioCompilationUnitElement(inputStream, sharedValues); + elements.add(elements$element); + } + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.PatioCompilationUnit(elements, source); + } + + public static void encodePatioCompilationUnitElement(org.shedlang.compiler.patio.PatioCompilationUnitElement value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + switch (value) { + case org.shedlang.compiler.patio.PatioDataElementImmutableDefinition value$0 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(0, outputStream, sharedValues); + org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.encodePatioDataElementImmutableDefinition(value$0, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.PatioDataElementMutableDeclaration value$1 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(1, outputStream, sharedValues); + org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.encodePatioDataElementMutableDeclaration(value$1, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.PatioDataElementMutableDefinition value$2 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(2, outputStream, sharedValues); + org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.encodePatioDataElementMutableDefinition(value$2, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.PatioExceptionTypeDefinition value$3 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(3, outputStream, sharedValues); + org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.encodePatioExceptionTypeDefinition(value$3, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.PatioFunctionDeclaration value$4 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(4, outputStream, sharedValues); + org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.encodePatioFunctionDeclaration(value$4, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.PatioFunctionDefinition value$5 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(5, outputStream, sharedValues); + org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.encodePatioFunctionDefinition(value$5, outputStream, sharedValues); + } + } + } + + public static org.shedlang.compiler.patio.PatioCompilationUnitElement decodePatioCompilationUnitElement(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var variantTag = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); + switch (variantTag) { + case 0 -> { + var value$0 = org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.decodePatioDataElementImmutableDefinition(inputStream, sharedValues); + return value$0; + } + case 1 -> { + var value$1 = org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.decodePatioDataElementMutableDeclaration(inputStream, sharedValues); + return value$1; + } + case 2 -> { + var value$2 = org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.decodePatioDataElementMutableDefinition(inputStream, sharedValues); + return value$2; + } + case 3 -> { + var value$3 = org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.decodePatioExceptionTypeDefinition(inputStream, sharedValues); + return value$3; + } + case 4 -> { + var value$4 = org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.decodePatioFunctionDeclaration(inputStream, sharedValues); + return value$4; + } + case 5 -> { + var value$5 = org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.decodePatioFunctionDefinition(inputStream, sharedValues); + return value$5; + } + default -> { + throw new java.lang.RuntimeException("unexpected patio.PatioCompilationUnitElement variant tag: " + variantTag); + } + } + } + + public static void encodePatioDataElementImmutableDefinition(org.shedlang.compiler.patio.PatioDataElementImmutableDefinition value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeString(value.name(), outputStream, sharedValues); + org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.encodePatioVisibility(value.visibility(), outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataValue(value.value(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.PatioDataElementImmutableDefinition decodePatioDataElementImmutableDefinition(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var name = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeString(inputStream, sharedValues); + var visibility = org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.decodePatioVisibility(inputStream, sharedValues); + var value = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataValue(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.PatioDataElementImmutableDefinition(name, visibility, value, source); + } + + public static void encodePatioDataElementMutableDeclaration(org.shedlang.compiler.patio.PatioDataElementMutableDeclaration value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeString(value.name(), outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataLayout(value.layout(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.PatioDataElementMutableDeclaration decodePatioDataElementMutableDeclaration(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var name = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeString(inputStream, sharedValues); + var layout = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataLayout(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.PatioDataElementMutableDeclaration(name, layout, source); + } + + public static void encodePatioDataElementMutableDefinition(org.shedlang.compiler.patio.PatioDataElementMutableDefinition value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeString(value.name(), outputStream, sharedValues); + org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.encodePatioVisibility(value.visibility(), outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataValue(value.initialValue(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.PatioDataElementMutableDefinition decodePatioDataElementMutableDefinition(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var name = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeString(inputStream, sharedValues); + var visibility = org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.decodePatioVisibility(inputStream, sharedValues); + var initialValue = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataValue(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.PatioDataElementMutableDefinition(name, visibility, initialValue, source); + } + + public static void encodePatioExceptionTypeDefinition(org.shedlang.compiler.patio.PatioExceptionTypeDefinition value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeString(value.name(), outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioType(value.valueType(), outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.PatioExceptionTypeDefinition decodePatioExceptionTypeDefinition(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var name = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeString(inputStream, sharedValues); + var valueType = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioType(inputStream, sharedValues); + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.PatioExceptionTypeDefinition(name, valueType, source); + } + + public static void encodePatioFunctionDeclaration(org.shedlang.compiler.patio.PatioFunctionDeclaration value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeString(value.name(), outputStream, sharedValues); + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.params().size(), outputStream, sharedValues); + for (var element : value.params()) { + org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.encodePatioLocal(element, outputStream, sharedValues); + } + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.returnTypes().size(), outputStream, sharedValues); + for (var element : value.returnTypes()) { + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioType(element, outputStream, sharedValues); + } + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.PatioFunctionDeclaration decodePatioFunctionDeclaration(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var name = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeString(inputStream, sharedValues); + var params$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var params = new java.util.ArrayList<org.shedlang.compiler.patio.PatioLocal>((int) params$size); + for (long params$index = 0; params$index < params$size; params$index++) { + var params$element = org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.decodePatioLocal(inputStream, sharedValues); + params.add(params$element); + } + var returnTypes$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var returnTypes = new java.util.ArrayList<org.shedlang.compiler.patio.types.PatioType>((int) returnTypes$size); + for (long returnTypes$index = 0; returnTypes$index < returnTypes$size; returnTypes$index++) { + var returnTypes$element = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioType(inputStream, sharedValues); + returnTypes.add(returnTypes$element); + } + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.PatioFunctionDeclaration(name, params, returnTypes, source); + } + + public static void encodePatioFunctionDefinition(org.shedlang.compiler.patio.PatioFunctionDefinition value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeString(value.name(), outputStream, sharedValues); + org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.encodePatioVisibility(value.visibility(), outputStream, sharedValues); + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.locals().size(), outputStream, sharedValues); + for (var element : value.locals()) { + org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.encodePatioLocal(element, outputStream, sharedValues); + } + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.returnTypes().size(), outputStream, sharedValues); + for (var element : value.returnTypes()) { + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioType(element, outputStream, sharedValues); + } + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.body().size(), outputStream, sharedValues); + for (var element : value.body()) { + org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.encodePatioInstruction(element, outputStream, sharedValues); + } + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeSource(value.source(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.PatioFunctionDefinition decodePatioFunctionDefinition(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var name = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeString(inputStream, sharedValues); + var visibility = org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.decodePatioVisibility(inputStream, sharedValues); + var locals$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var locals = new java.util.ArrayList<org.shedlang.compiler.patio.PatioLocal>((int) locals$size); + for (long locals$index = 0; locals$index < locals$size; locals$index++) { + var locals$element = org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.decodePatioLocal(inputStream, sharedValues); + locals.add(locals$element); + } + var returnTypes$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var returnTypes = new java.util.ArrayList<org.shedlang.compiler.patio.types.PatioType>((int) returnTypes$size); + for (long returnTypes$index = 0; returnTypes$index < returnTypes$size; returnTypes$index++) { + var returnTypes$element = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioType(inputStream, sharedValues); + returnTypes.add(returnTypes$element); + } + var body$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var body = new java.util.ArrayList<org.shedlang.compiler.patio.instructions.PatioInstruction>((int) body$size); + for (long body$index = 0; body$index < body$size; body$index++) { + var body$element = org.shedlang.compiler.patio.instructions.transient0.HobgoblinTransient0Instructions.decodePatioInstruction(inputStream, sharedValues); + body.add(body$element); + } + var source = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeSource(inputStream, sharedValues); + return new org.shedlang.compiler.patio.PatioFunctionDefinition(name, visibility, locals, returnTypes, body, source); + } + + public static void encodePatioVisibility(org.shedlang.compiler.patio.PatioVisibility value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(value.ordinal(), outputStream, sharedValues); + } + + private static final org.shedlang.compiler.patio.PatioVisibility[] PatioVisibility$values = org.shedlang.compiler.patio.PatioVisibility.values(); + + public static org.shedlang.compiler.patio.PatioVisibility decodePatioVisibility(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var ordinal = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); + return PatioVisibility$values[ordinal]; + } + + public static void encodePatioLocal(org.shedlang.compiler.patio.PatioLocal value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeString(value.name(), outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioType(value.type(), outputStream, sharedValues); + org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.encodePatioLocalType(value.localType(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.PatioLocal decodePatioLocal(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var name = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeString(inputStream, sharedValues); + var type = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioType(inputStream, sharedValues); + var localType = org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio.decodePatioLocalType(inputStream, sharedValues); + return new org.shedlang.compiler.patio.PatioLocal(name, type, localType); + } + + public static void encodePatioLocalType(org.shedlang.compiler.patio.PatioLocalType value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(value.ordinal(), outputStream, sharedValues); + } + + private static final org.shedlang.compiler.patio.PatioLocalType[] PatioLocalType$values = org.shedlang.compiler.patio.PatioLocalType.values(); + + public static org.shedlang.compiler.patio.PatioLocalType decodePatioLocalType(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var ordinal = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); + return PatioLocalType$values[ordinal]; + } + + // Custom area start: org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio body + // Custom area end: org.shedlang.compiler.patio.transient0.HobgoblinTransient0Patio body +} diff --git a/src/transient-0/java/org/shedlang/compiler/patio/types/transient0/HobgoblinTransient0Types.java b/src/transient-0/java/org/shedlang/compiler/patio/types/transient0/HobgoblinTransient0Types.java new file mode 100644 index 00000000..efc0b55f --- /dev/null +++ b/src/transient-0/java/org/shedlang/compiler/patio/types/transient0/HobgoblinTransient0Types.java @@ -0,0 +1,414 @@ +// Generated by hobgoblin. + +package org.shedlang.compiler.patio.types.transient0; + +// Custom area start: org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types imports +// Custom area end: org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types imports + +public final class HobgoblinTransient0Types { + public static void encodePatioType(org.shedlang.compiler.patio.types.PatioType value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + switch (value) { + case org.shedlang.compiler.patio.types.PatioBoolType value$0 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(0, outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioBoolType(value$0, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.types.PatioByteType value$1 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(1, outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioByteType(value$1, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.types.PatioDataPtrType value$2 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(2, outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataPtrType(value$2, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.types.PatioFunctionPtrType value$3 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(3, outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioFunctionPtrType(value$3, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.types.PatioInt32Type value$4 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(4, outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioInt32Type(value$4, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.types.PatioIntType value$5 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(5, outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioIntType(value$5, outputStream, sharedValues); + } + } + } + + public static org.shedlang.compiler.patio.types.PatioType decodePatioType(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var variantTag = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); + switch (variantTag) { + case 0 -> { + var value$0 = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioBoolType(inputStream, sharedValues); + return value$0; + } + case 1 -> { + var value$1 = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioByteType(inputStream, sharedValues); + return value$1; + } + case 2 -> { + var value$2 = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataPtrType(inputStream, sharedValues); + return value$2; + } + case 3 -> { + var value$3 = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioFunctionPtrType(inputStream, sharedValues); + return value$3; + } + case 4 -> { + var value$4 = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioInt32Type(inputStream, sharedValues); + return value$4; + } + case 5 -> { + var value$5 = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioIntType(inputStream, sharedValues); + return value$5; + } + default -> { + throw new java.lang.RuntimeException("unexpected patio/types.PatioType variant tag: " + variantTag); + } + } + } + + public static void encodePatioBoolType(org.shedlang.compiler.patio.types.PatioBoolType value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + } + + public static org.shedlang.compiler.patio.types.PatioBoolType decodePatioBoolType(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + return org.shedlang.compiler.patio.types.PatioBoolType.INSTANCE; + } + + public static void encodePatioByteType(org.shedlang.compiler.patio.types.PatioByteType value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + } + + public static org.shedlang.compiler.patio.types.PatioByteType decodePatioByteType(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + return org.shedlang.compiler.patio.types.PatioByteType.INSTANCE; + } + + public static void encodePatioDataPtrType(org.shedlang.compiler.patio.types.PatioDataPtrType value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + } + + public static org.shedlang.compiler.patio.types.PatioDataPtrType decodePatioDataPtrType(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + return org.shedlang.compiler.patio.types.PatioDataPtrType.INSTANCE; + } + + public static void encodePatioFunctionPtrType(org.shedlang.compiler.patio.types.PatioFunctionPtrType value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + } + + public static org.shedlang.compiler.patio.types.PatioFunctionPtrType decodePatioFunctionPtrType(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + return org.shedlang.compiler.patio.types.PatioFunctionPtrType.INSTANCE; + } + + public static void encodePatioInt32Type(org.shedlang.compiler.patio.types.PatioInt32Type value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + } + + public static org.shedlang.compiler.patio.types.PatioInt32Type decodePatioInt32Type(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + return org.shedlang.compiler.patio.types.PatioInt32Type.INSTANCE; + } + + public static void encodePatioIntType(org.shedlang.compiler.patio.types.PatioIntType value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + } + + public static org.shedlang.compiler.patio.types.PatioIntType decodePatioIntType(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + return org.shedlang.compiler.patio.types.PatioIntType.INSTANCE; + } + + public static void encodePatioDataLayout(org.shedlang.compiler.patio.types.PatioDataLayout value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + switch (value) { + case org.shedlang.compiler.patio.types.PatioDataLayoutArray value$0 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(0, outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataLayoutArray(value$0, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.types.PatioDataLayoutBool value$1 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(1, outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataLayoutBool(value$1, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.types.PatioDataLayoutByte value$2 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(2, outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataLayoutByte(value$2, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.types.PatioDataLayoutDataPtr value$3 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(3, outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataLayoutDataPtr(value$3, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.types.PatioDataLayoutFunctionPtr value$4 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(4, outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataLayoutFunctionPtr(value$4, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.types.PatioDataLayoutInt value$5 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(5, outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataLayoutInt(value$5, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.types.PatioDataLayoutInt32 value$6 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(6, outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataLayoutInt32(value$6, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.types.PatioDataLayoutStruct value$7 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(7, outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataLayoutStruct(value$7, outputStream, sharedValues); + } + } + } + + public static org.shedlang.compiler.patio.types.PatioDataLayout decodePatioDataLayout(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var variantTag = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); + switch (variantTag) { + case 0 -> { + var value$0 = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataLayoutArray(inputStream, sharedValues); + return value$0; + } + case 1 -> { + var value$1 = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataLayoutBool(inputStream, sharedValues); + return value$1; + } + case 2 -> { + var value$2 = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataLayoutByte(inputStream, sharedValues); + return value$2; + } + case 3 -> { + var value$3 = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataLayoutDataPtr(inputStream, sharedValues); + return value$3; + } + case 4 -> { + var value$4 = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataLayoutFunctionPtr(inputStream, sharedValues); + return value$4; + } + case 5 -> { + var value$5 = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataLayoutInt(inputStream, sharedValues); + return value$5; + } + case 6 -> { + var value$6 = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataLayoutInt32(inputStream, sharedValues); + return value$6; + } + case 7 -> { + var value$7 = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataLayoutStruct(inputStream, sharedValues); + return value$7; + } + default -> { + throw new java.lang.RuntimeException("unexpected patio/types.PatioDataLayout variant tag: " + variantTag); + } + } + } + + public static void encodePatioDataLayoutArray(org.shedlang.compiler.patio.types.PatioDataLayoutArray value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataLayout(value.element(), outputStream, sharedValues); + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(value.size(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.types.PatioDataLayoutArray decodePatioDataLayoutArray(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var element = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataLayout(inputStream, sharedValues); + var size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); + return new org.shedlang.compiler.patio.types.PatioDataLayoutArray(element, size); + } + + public static void encodePatioDataLayoutBool(org.shedlang.compiler.patio.types.PatioDataLayoutBool value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + } + + public static org.shedlang.compiler.patio.types.PatioDataLayoutBool decodePatioDataLayoutBool(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + return org.shedlang.compiler.patio.types.PatioDataLayoutBool.INSTANCE; + } + + public static void encodePatioDataLayoutByte(org.shedlang.compiler.patio.types.PatioDataLayoutByte value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + } + + public static org.shedlang.compiler.patio.types.PatioDataLayoutByte decodePatioDataLayoutByte(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + return org.shedlang.compiler.patio.types.PatioDataLayoutByte.INSTANCE; + } + + public static void encodePatioDataLayoutDataPtr(org.shedlang.compiler.patio.types.PatioDataLayoutDataPtr value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + } + + public static org.shedlang.compiler.patio.types.PatioDataLayoutDataPtr decodePatioDataLayoutDataPtr(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + return org.shedlang.compiler.patio.types.PatioDataLayoutDataPtr.INSTANCE; + } + + public static void encodePatioDataLayoutFunctionPtr(org.shedlang.compiler.patio.types.PatioDataLayoutFunctionPtr value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + } + + public static org.shedlang.compiler.patio.types.PatioDataLayoutFunctionPtr decodePatioDataLayoutFunctionPtr(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + return org.shedlang.compiler.patio.types.PatioDataLayoutFunctionPtr.INSTANCE; + } + + public static void encodePatioDataLayoutInt(org.shedlang.compiler.patio.types.PatioDataLayoutInt value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + } + + public static org.shedlang.compiler.patio.types.PatioDataLayoutInt decodePatioDataLayoutInt(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + return org.shedlang.compiler.patio.types.PatioDataLayoutInt.INSTANCE; + } + + public static void encodePatioDataLayoutInt32(org.shedlang.compiler.patio.types.PatioDataLayoutInt32 value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + } + + public static org.shedlang.compiler.patio.types.PatioDataLayoutInt32 decodePatioDataLayoutInt32(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + return org.shedlang.compiler.patio.types.PatioDataLayoutInt32.INSTANCE; + } + + public static void encodePatioDataLayoutStruct(org.shedlang.compiler.patio.types.PatioDataLayoutStruct value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.elements().size(), outputStream, sharedValues); + for (var element : value.elements()) { + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataLayout(element, outputStream, sharedValues); + } + } + + public static org.shedlang.compiler.patio.types.PatioDataLayoutStruct decodePatioDataLayoutStruct(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var elements$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var elements = new java.util.ArrayList<org.shedlang.compiler.patio.types.PatioDataLayout>((int) elements$size); + for (long elements$index = 0; elements$index < elements$size; elements$index++) { + var elements$element = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataLayout(inputStream, sharedValues); + elements.add(elements$element); + } + return new org.shedlang.compiler.patio.types.PatioDataLayoutStruct(elements); + } + + public static void encodePatioDataValue(org.shedlang.compiler.patio.types.PatioDataValue value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + switch (value) { + case org.shedlang.compiler.patio.types.PatioDataValueArray value$0 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(0, outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataValueArray(value$0, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.types.PatioDataValueBool value$1 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(1, outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataValueBool(value$1, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.types.PatioDataValueByte value$2 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(2, outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataValueByte(value$2, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.types.PatioDataValueDataPtr value$3 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(3, outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataValueDataPtr(value$3, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.types.PatioDataValueInt value$4 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(4, outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataValueInt(value$4, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.types.PatioDataValueInt32 value$5 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(5, outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataValueInt32(value$5, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.types.PatioDataValueStruct value$6 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(6, outputStream, sharedValues); + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataValueStruct(value$6, outputStream, sharedValues); + } + } + } + + public static org.shedlang.compiler.patio.types.PatioDataValue decodePatioDataValue(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var variantTag = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); + switch (variantTag) { + case 0 -> { + var value$0 = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataValueArray(inputStream, sharedValues); + return value$0; + } + case 1 -> { + var value$1 = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataValueBool(inputStream, sharedValues); + return value$1; + } + case 2 -> { + var value$2 = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataValueByte(inputStream, sharedValues); + return value$2; + } + case 3 -> { + var value$3 = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataValueDataPtr(inputStream, sharedValues); + return value$3; + } + case 4 -> { + var value$4 = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataValueInt(inputStream, sharedValues); + return value$4; + } + case 5 -> { + var value$5 = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataValueInt32(inputStream, sharedValues); + return value$5; + } + case 6 -> { + var value$6 = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataValueStruct(inputStream, sharedValues); + return value$6; + } + default -> { + throw new java.lang.RuntimeException("unexpected patio/types.PatioDataValue variant tag: " + variantTag); + } + } + } + + public static void encodePatioDataValueArray(org.shedlang.compiler.patio.types.PatioDataValueArray value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataLayout(value.elementLayout(), outputStream, sharedValues); + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.elements().size(), outputStream, sharedValues); + for (var element : value.elements()) { + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataValue(element, outputStream, sharedValues); + } + } + + public static org.shedlang.compiler.patio.types.PatioDataValueArray decodePatioDataValueArray(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var elementLayout = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataLayout(inputStream, sharedValues); + var elements$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var elements = new java.util.ArrayList<org.shedlang.compiler.patio.types.PatioDataValue>((int) elements$size); + for (long elements$index = 0; elements$index < elements$size; elements$index++) { + var elements$element = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataValue(inputStream, sharedValues); + elements.add(elements$element); + } + return new org.shedlang.compiler.patio.types.PatioDataValueArray(elementLayout, elements); + } + + public static void encodePatioDataValueBool(org.shedlang.compiler.patio.types.PatioDataValueBool value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeBool(value.value(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.types.PatioDataValueBool decodePatioDataValueBool(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var value = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeBool(inputStream, sharedValues); + return new org.shedlang.compiler.patio.types.PatioDataValueBool(value); + } + + public static void encodePatioDataValueByte(org.shedlang.compiler.patio.types.PatioDataValueByte value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt8(value.value(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.types.PatioDataValueByte decodePatioDataValueByte(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var value = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt8(inputStream, sharedValues); + return new org.shedlang.compiler.patio.types.PatioDataValueByte(value); + } + + public static void encodePatioDataValueDataPtr(org.shedlang.compiler.patio.types.PatioDataValueDataPtr value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.encodePatioDataPtrValue(value.value(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.types.PatioDataValueDataPtr decodePatioDataValueDataPtr(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var value = org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.decodePatioDataPtrValue(inputStream, sharedValues); + return new org.shedlang.compiler.patio.types.PatioDataValueDataPtr(value); + } + + public static void encodePatioDataValueInt(org.shedlang.compiler.patio.types.PatioDataValueInt value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.encodePatioIntValue(value.value(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.types.PatioDataValueInt decodePatioDataValueInt(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var value = org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.decodePatioIntValue(inputStream, sharedValues); + return new org.shedlang.compiler.patio.types.PatioDataValueInt(value); + } + + public static void encodePatioDataValueInt32(org.shedlang.compiler.patio.types.PatioDataValueInt32 value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.encodePatioIntValue(value.value(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.types.PatioDataValueInt32 decodePatioDataValueInt32(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var value = org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.decodePatioIntValue(inputStream, sharedValues); + return new org.shedlang.compiler.patio.types.PatioDataValueInt32(value); + } + + public static void encodePatioDataValueStruct(org.shedlang.compiler.patio.types.PatioDataValueStruct value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.elements().size(), outputStream, sharedValues); + for (var element : value.elements()) { + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataValue(element, outputStream, sharedValues); + } + } + + public static org.shedlang.compiler.patio.types.PatioDataValueStruct decodePatioDataValueStruct(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var elements$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var elements = new java.util.ArrayList<org.shedlang.compiler.patio.types.PatioDataValue>((int) elements$size); + for (long elements$index = 0; elements$index < elements$size; elements$index++) { + var elements$element = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataValue(inputStream, sharedValues); + elements.add(elements$element); + } + return new org.shedlang.compiler.patio.types.PatioDataValueStruct(elements); + } + + // Custom area start: org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types body + // Custom area end: org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types body +} diff --git a/src/transient-0/java/org/shedlang/compiler/patio/values/transient0/HobgoblinTransient0Values.java b/src/transient-0/java/org/shedlang/compiler/patio/values/transient0/HobgoblinTransient0Values.java new file mode 100644 index 00000000..05523dc2 --- /dev/null +++ b/src/transient-0/java/org/shedlang/compiler/patio/values/transient0/HobgoblinTransient0Values.java @@ -0,0 +1,132 @@ +// Generated by hobgoblin. + +package org.shedlang.compiler.patio.values.transient0; + +// Custom area start: org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values imports +// Custom area end: org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values imports + +public final class HobgoblinTransient0Values { + public static void encodePatioDataPtrValue(org.shedlang.compiler.patio.values.PatioDataPtrValue value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + switch (value) { + case org.shedlang.compiler.patio.values.PatioDataPtrValueDataElement value$0 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(0, outputStream, sharedValues); + org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.encodePatioDataPtrValueDataElement(value$0, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.values.PatioDataPtrValueNull value$1 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(1, outputStream, sharedValues); + org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.encodePatioDataPtrValueNull(value$1, outputStream, sharedValues); + } + } + } + + public static org.shedlang.compiler.patio.values.PatioDataPtrValue decodePatioDataPtrValue(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var variantTag = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); + switch (variantTag) { + case 0 -> { + var value$0 = org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.decodePatioDataPtrValueDataElement(inputStream, sharedValues); + return value$0; + } + case 1 -> { + var value$1 = org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.decodePatioDataPtrValueNull(inputStream, sharedValues); + return value$1; + } + default -> { + throw new java.lang.RuntimeException("unexpected patio/values.PatioDataPtrValue variant tag: " + variantTag); + } + } + } + + public static void encodePatioDataPtrValueDataElement(org.shedlang.compiler.patio.values.PatioDataPtrValueDataElement value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeString(value.name(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.values.PatioDataPtrValueDataElement decodePatioDataPtrValueDataElement(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var name = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeString(inputStream, sharedValues); + return new org.shedlang.compiler.patio.values.PatioDataPtrValueDataElement(name); + } + + public static void encodePatioDataPtrValueNull(org.shedlang.compiler.patio.values.PatioDataPtrValueNull value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + } + + public static org.shedlang.compiler.patio.values.PatioDataPtrValueNull decodePatioDataPtrValueNull(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + return new org.shedlang.compiler.patio.values.PatioDataPtrValueNull(); + } + + public static void encodePatioIntValue(org.shedlang.compiler.patio.values.PatioIntValue value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + switch (value) { + case org.shedlang.compiler.patio.values.PatioIntValueByteOffsetOf value$0 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(0, outputStream, sharedValues); + org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.encodePatioIntValueByteOffsetOf(value$0, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.values.PatioIntValueByteSizeOf value$1 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(1, outputStream, sharedValues); + org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.encodePatioIntValueByteSizeOf(value$1, outputStream, sharedValues); + } + case org.shedlang.compiler.patio.values.PatioIntValueLiteral value$2 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(2, outputStream, sharedValues); + org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.encodePatioIntValueLiteral(value$2, outputStream, sharedValues); + } + } + } + + public static org.shedlang.compiler.patio.values.PatioIntValue decodePatioIntValue(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var variantTag = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); + switch (variantTag) { + case 0 -> { + var value$0 = org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.decodePatioIntValueByteOffsetOf(inputStream, sharedValues); + return value$0; + } + case 1 -> { + var value$1 = org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.decodePatioIntValueByteSizeOf(inputStream, sharedValues); + return value$1; + } + case 2 -> { + var value$2 = org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values.decodePatioIntValueLiteral(inputStream, sharedValues); + return value$2; + } + default -> { + throw new java.lang.RuntimeException("unexpected patio/values.PatioIntValue variant tag: " + variantTag); + } + } + } + + public static void encodePatioIntValueByteOffsetOf(org.shedlang.compiler.patio.values.PatioIntValueByteOffsetOf value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataLayout(value.layout(), outputStream, sharedValues); + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.elementOffsets().size(), outputStream, sharedValues); + for (var element : value.elementOffsets()) { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(element, outputStream, sharedValues); + } + } + + public static org.shedlang.compiler.patio.values.PatioIntValueByteOffsetOf decodePatioIntValueByteOffsetOf(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var layout = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataLayout(inputStream, sharedValues); + var elementOffsets$size = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var elementOffsets = new java.util.ArrayList<java.lang.Integer>((int) elementOffsets$size); + for (long elementOffsets$index = 0; elementOffsets$index < elementOffsets$size; elementOffsets$index++) { + var elementOffsets$element = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); + elementOffsets.add(elementOffsets$element); + } + return new org.shedlang.compiler.patio.values.PatioIntValueByteOffsetOf(layout, elementOffsets); + } + + public static void encodePatioIntValueByteSizeOf(org.shedlang.compiler.patio.values.PatioIntValueByteSizeOf value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.encodePatioDataLayout(value.layout(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.values.PatioIntValueByteSizeOf decodePatioIntValueByteSizeOf(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var layout = org.shedlang.compiler.patio.types.transient0.HobgoblinTransient0Types.decodePatioDataLayout(inputStream, sharedValues); + return new org.shedlang.compiler.patio.values.PatioIntValueByteSizeOf(layout); + } + + public static void encodePatioIntValueLiteral(org.shedlang.compiler.patio.values.PatioIntValueLiteral value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(value.value(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.patio.values.PatioIntValueLiteral decodePatioIntValueLiteral(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var value = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); + return new org.shedlang.compiler.patio.values.PatioIntValueLiteral(value); + } + + // Custom area start: org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values body + // Custom area end: org.shedlang.compiler.patio.values.transient0.HobgoblinTransient0Values body +} diff --git a/src/transient-0/java/org/shedlang/compiler/sources/transient0/HobgoblinTransient0Sources.java b/src/transient-0/java/org/shedlang/compiler/sources/transient0/HobgoblinTransient0Sources.java new file mode 100644 index 00000000..94af36bb --- /dev/null +++ b/src/transient-0/java/org/shedlang/compiler/sources/transient0/HobgoblinTransient0Sources.java @@ -0,0 +1,72 @@ +// Generated by hobgoblin. + +package org.shedlang.compiler.sources.transient0; + +// Custom area start: org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources imports +// Custom area end: org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources imports + +public final class HobgoblinTransient0Sources { + public static void encodeSource(org.shedlang.compiler.sources.Source value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + switch (value) { + case org.shedlang.compiler.sources.NullSource value$0 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(0, outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeNullSource(value$0, outputStream, sharedValues); + } + case org.shedlang.compiler.sources.RuntimeSource value$1 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(1, outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeRuntimeSource(value$1, outputStream, sharedValues); + } + case org.shedlang.compiler.sources.FileFragmentSource value$2 -> { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(2, outputStream, sharedValues); + org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.encodeFileFragmentSource(value$2, outputStream, sharedValues); + } + } + } + + public static org.shedlang.compiler.sources.Source decodeSource(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var variantTag = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); + switch (variantTag) { + case 0 -> { + var value$0 = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeNullSource(inputStream, sharedValues); + return value$0; + } + case 1 -> { + var value$1 = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeRuntimeSource(inputStream, sharedValues); + return value$1; + } + case 2 -> { + var value$2 = org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources.decodeFileFragmentSource(inputStream, sharedValues); + return value$2; + } + default -> { + throw new java.lang.RuntimeException("unexpected sources.Source variant tag: " + variantTag); + } + } + } + + public static void encodeNullSource(org.shedlang.compiler.sources.NullSource value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + } + + public static org.shedlang.compiler.sources.NullSource decodeNullSource(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + return org.shedlang.compiler.sources.NullSource.INSTANCE; + } + + public static void encodeRuntimeSource(org.shedlang.compiler.sources.RuntimeSource value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + } + + public static org.shedlang.compiler.sources.RuntimeSource decodeRuntimeSource(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + return org.shedlang.compiler.sources.RuntimeSource.INSTANCE; + } + + public static void encodeFileFragmentSource(org.shedlang.compiler.sources.FileFragmentSource value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + org.zwobble.sourcetext.transient0.HobgoblinTransient0Sourcetext.encodeSourceRange(value.sourceRange(), outputStream, sharedValues); + } + + public static org.shedlang.compiler.sources.FileFragmentSource decodeFileFragmentSource(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var sourceRange = org.zwobble.sourcetext.transient0.HobgoblinTransient0Sourcetext.decodeSourceRange(inputStream, sharedValues); + return new org.shedlang.compiler.sources.FileFragmentSource(sourceRange); + } + + // Custom area start: org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources body + // Custom area end: org.shedlang.compiler.sources.transient0.HobgoblinTransient0Sources body +} diff --git a/src/transient-0/java/org/shedlang/compiler/transient0/HobgoblinTransient0Builtins.java b/src/transient-0/java/org/shedlang/compiler/transient0/HobgoblinTransient0Builtins.java new file mode 100644 index 00000000..4a272077 --- /dev/null +++ b/src/transient-0/java/org/shedlang/compiler/transient0/HobgoblinTransient0Builtins.java @@ -0,0 +1,79 @@ +// Generated by hobgoblin. + +package org.shedlang.compiler.transient0; + +// Custom area start: org.shedlang.compiler.transient0.HobgoblinTransient0Builtins imports +// Custom area end: org.shedlang.compiler.transient0.HobgoblinTransient0Builtins imports + +public final class HobgoblinTransient0Builtins { + public static void encodeBool(boolean value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + outputStream.write(value ? 1 : 0); + } + + public static boolean decodeBool(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + return inputStream.read() != 0; + } + + public static void encodeInt8(byte value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + outputStream.write(value); + } + + public static byte decodeInt8(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + return (byte) inputStream.read(); + } + + public static void encodeInt32(int value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + outputStream.write(value >>> 0 & 255); + outputStream.write(value >>> 8 & 255); + outputStream.write(value >>> 16 & 255); + outputStream.write(value >>> 24 & 255); + } + + public static int decodeInt32(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + int value = 0; + value = value | inputStream.read() << 0; + value = value | inputStream.read() << 8; + value = value | inputStream.read() << 16; + value = value | inputStream.read() << 24; + return value; + } + + public static void encodeInt64(long value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + outputStream.write((int) (value >>> 0 & 255)); + outputStream.write((int) (value >>> 8 & 255)); + outputStream.write((int) (value >>> 16 & 255)); + outputStream.write((int) (value >>> 24 & 255)); + outputStream.write((int) (value >>> 32 & 255)); + outputStream.write((int) (value >>> 40 & 255)); + outputStream.write((int) (value >>> 48 & 255)); + outputStream.write((int) (value >>> 56 & 255)); + } + + public static long decodeInt64(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + long value = 0; + value = value | inputStream.read() << 0; + value = value | inputStream.read() << 8; + value = value | inputStream.read() << 16; + value = value | inputStream.read() << 24; + value = value | inputStream.read() << 32; + value = value | inputStream.read() << 40; + value = value | inputStream.read() << 48; + value = value | inputStream.read() << 56; + return value; + } + + public static void encodeString(String value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + var bytes = value.getBytes(java.nio.charset.StandardCharsets.UTF_8); + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64((long) bytes.length, outputStream, sharedValues); + outputStream.write(bytes); + } + + public static String decodeString(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var bytesLength = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + var bytes = inputStream.readNBytes((int) bytesLength); + return new String(bytes, java.nio.charset.StandardCharsets.UTF_8); + } + + // Custom area start: org.shedlang.compiler.transient0.HobgoblinTransient0Builtins body + // Custom area end: org.shedlang.compiler.transient0.HobgoblinTransient0Builtins body +} diff --git a/src/transient-0/java/org/shedlang/compiler/transient0/HobgoblinTransient0TaggedSharedValue.java b/src/transient-0/java/org/shedlang/compiler/transient0/HobgoblinTransient0TaggedSharedValue.java new file mode 100644 index 00000000..d918276f --- /dev/null +++ b/src/transient-0/java/org/shedlang/compiler/transient0/HobgoblinTransient0TaggedSharedValue.java @@ -0,0 +1,22 @@ +// Generated by hobgoblin. + +package org.shedlang.compiler.transient0; + +// Custom area start: org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue imports +// Custom area end: org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue imports + +public record HobgoblinTransient0TaggedSharedValue( + long typeId, + java.lang.Object value +) { + public boolean equals(java.lang.Object other) { + return other instanceof org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue otherSharedValue && this.typeId == otherSharedValue.typeId && this.value == otherSharedValue.value; + } + + public int hashCode() { + return 37 * (37 * 17 + java.lang.Long.hashCode(this.typeId)) + java.lang.System.identityHashCode(this.value); + } + + // Custom area start: org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue body + // Custom area end: org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue body +} diff --git a/src/transient-0/java/org/zwobble/sourcetext/transient0/HobgoblinTransient0Sourcetext.java b/src/transient-0/java/org/zwobble/sourcetext/transient0/HobgoblinTransient0Sourcetext.java new file mode 100644 index 00000000..75b369ae --- /dev/null +++ b/src/transient-0/java/org/zwobble/sourcetext/transient0/HobgoblinTransient0Sourcetext.java @@ -0,0 +1,95 @@ +// Generated by hobgoblin. + +package org.zwobble.sourcetext.transient0; + +// Custom area start: org.zwobble.sourcetext.transient0.HobgoblinTransient0Sourcetext imports +import org.shedlang.compiler.transient0.HobgoblinTransient0Builtins; +import org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue; +import org.zwobble.sourcetext.SourceText; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.List; +import java.util.Map; +// Custom area end: org.zwobble.sourcetext.transient0.HobgoblinTransient0Sourcetext imports + +public final class HobgoblinTransient0Sourcetext { + public static void encodeSourceRange(org.zwobble.sourcetext.SourceRange value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + { + var existingId = sharedValues.get(new org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue(0, value.sourceText())); + if (existingId != null) { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64(existingId, outputStream, sharedValues); + } else { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64(sharedValues.size(), outputStream, sharedValues); + sharedValues.put(new org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue(0, value.sourceText()), (long) sharedValues.size()); + org.zwobble.sourcetext.transient0.HobgoblinTransient0Sourcetext.encodeSourceText(value.sourceText(), outputStream, sharedValues); + } + } + org.zwobble.sourcetext.transient0.HobgoblinTransient0Sourcetext.encodeSourcePosition(value.start(), outputStream, sharedValues); + org.zwobble.sourcetext.transient0.HobgoblinTransient0Sourcetext.encodeSourcePosition(value.end(), outputStream, sharedValues); + } + + public static org.zwobble.sourcetext.SourceRange decodeSourceRange(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var sourceText$id = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + org.zwobble.sourcetext.SourceText sourceText; + if (sourceText$id < sharedValues.size()) { + sourceText = (org.zwobble.sourcetext.SourceText) sharedValues.get((int) sourceText$id); + } else { + var sourceText$decodedValue = org.zwobble.sourcetext.transient0.HobgoblinTransient0Sourcetext.decodeSourceText(inputStream, sharedValues); + sharedValues.add(sourceText$decodedValue); + sourceText = sourceText$decodedValue; + } + var start = org.zwobble.sourcetext.transient0.HobgoblinTransient0Sourcetext.decodeSourcePosition(inputStream, sharedValues); + var end = org.zwobble.sourcetext.transient0.HobgoblinTransient0Sourcetext.decodeSourcePosition(inputStream, sharedValues); + return new org.zwobble.sourcetext.SourceRange(sourceText, start, end); + } + + public static void encodeSourcePosition(org.zwobble.sourcetext.SourcePosition value, java.io.OutputStream outputStream, java.util.Map<org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { + { + var existingId = sharedValues.get(new org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue(0, value.sourceText())); + if (existingId != null) { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64(existingId, outputStream, sharedValues); + } else { + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt64(sharedValues.size(), outputStream, sharedValues); + sharedValues.put(new org.shedlang.compiler.transient0.HobgoblinTransient0TaggedSharedValue(0, value.sourceText()), (long) sharedValues.size()); + org.zwobble.sourcetext.transient0.HobgoblinTransient0Sourcetext.encodeSourceText(value.sourceText(), outputStream, sharedValues); + } + } + org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.encodeInt32(value.characterIndex(), outputStream, sharedValues); + } + + public static org.zwobble.sourcetext.SourcePosition decodeSourcePosition(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { + var sourceText$id = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); + org.zwobble.sourcetext.SourceText sourceText; + if (sourceText$id < sharedValues.size()) { + sourceText = (org.zwobble.sourcetext.SourceText) sharedValues.get((int) sourceText$id); + } else { + var sourceText$decodedValue = org.zwobble.sourcetext.transient0.HobgoblinTransient0Sourcetext.decodeSourceText(inputStream, sharedValues); + sharedValues.add(sourceText$decodedValue); + sourceText = sourceText$decodedValue; + } + var characterIndex = org.shedlang.compiler.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); + return new org.zwobble.sourcetext.SourcePosition(sourceText, characterIndex); + } + + // Custom area start: org.zwobble.sourcetext.transient0.HobgoblinTransient0Sourcetext body + private static void encodeSourceText( + SourceText sourceText, + OutputStream outputStream, + Map<HobgoblinTransient0TaggedSharedValue, Long> sharedValues + ) throws IOException { + HobgoblinTransient0Builtins.encodeString(sourceText.name(), outputStream, sharedValues); + HobgoblinTransient0Builtins.encodeString(sourceText.charSequence().toString(), outputStream, sharedValues); + } + + private static SourceText decodeSourceText( + InputStream inputStream, + List<Object> sharedValues + ) throws IOException { + var name = HobgoblinTransient0Builtins.decodeString(inputStream, sharedValues); + var contents = HobgoblinTransient0Builtins.decodeString(inputStream, sharedValues); + return SourceText.fromString(name, contents); + } + // Custom area end: org.zwobble.sourcetext.transient0.HobgoblinTransient0Sourcetext body +} |
