diff options
67 files changed, 324 insertions, 436 deletions
diff --git a/flatbuffers/patio.fbs b/flatbuffers/patio.fbs index c0066ac3..b2378a32 100644 --- a/flatbuffers/patio.fbs +++ b/flatbuffers/patio.fbs @@ -143,7 +143,6 @@ union PatioTypeValue { PatioFunctionPtrType, PatioIntType, PatioInt32Type, - PatioVoidType, } table PatioType { @@ -168,9 +167,6 @@ table PatioIntType { table PatioInt32Type { } -table PatioVoidType { -} - // == Operands == union PatioOperandValue { @@ -237,7 +233,6 @@ union PatioInstructionValue { PatioMemoryLoad, PatioMemoryStore, PatioReturn, - PatioReturnVoid, PatioSwitch, PatioThrow, PatioTry, @@ -367,11 +362,7 @@ table PatioMemoryStore { table PatioReturn { source:Sources.Source (required); - value:PatioOperand (required); -} - -table PatioReturnVoid { - source:Sources.Source (required); + values:[PatioOperand] (required); } table PatioSwitch { @@ -490,7 +481,7 @@ table PatioFunctionDeclaration { source:Sources.Source (required); name:string (required); params:[PatioLocal] (required); - return_type:PatioType (required); + return_types:[PatioType] (required); } table PatioFunctionDefinition { @@ -498,7 +489,7 @@ table PatioFunctionDefinition { name:string (required); visibility:PatioVisibility; locals:[PatioLocal] (required); - return_type:PatioType (required); + return_types:[PatioType] (required); body:[PatioInstruction] (required); } diff --git a/patio-to-cranelift/src/codegen/mod.rs b/patio-to-cranelift/src/codegen/mod.rs index bfa9a82a..97414753 100644 --- a/patio-to-cranelift/src/codegen/mod.rs +++ b/patio-to-cranelift/src/codegen/mod.rs @@ -19,8 +19,8 @@ use crate::{ PatioBlock, PatioBoolToInt, PatioCall, PatioCallPointer, PatioDataPtrToInt, PatioIf, PatioInstruction, PatioIntAdd, PatioIntEquals, PatioIntNotEqual, PatioIntSub, PatioIntToBool, PatioIntToDataPtr, PatioLocalStore, PatioLoop, PatioLoopBreak, - PatioLoopContinue, PatioMemoryLoad, PatioMemoryStore, PatioReturn, PatioReturnVoid, - PatioSwitch, PatioUnreachable, PatioVarLoad, PatioVarStore, + PatioLoopContinue, PatioMemoryLoad, PatioMemoryStore, PatioReturn, PatioSwitch, + PatioUnreachable, PatioVarLoad, PatioVarStore, }, operands::{PatioLocalRef, PatioOperand}, types::PatioType, @@ -200,7 +200,7 @@ fn declare_function_declaration( ) { let cranelift_signature = cranelift_signature( function_declaration.params.iter(), - function_declaration.return_type, + function_declaration.return_types.iter(), &context.target_triple, ); @@ -216,8 +216,8 @@ fn declare_function_definition( context: &mut CompilerContext, ) { let cranelift_signature = cranelift_signature( - function_definition.locals.iter().map(Into::into), - function_definition.return_type, + function_definition.locals.iter(), + function_definition.return_types.iter(), &context.target_triple, ); @@ -235,8 +235,8 @@ fn define_function_definition( context: &mut CompilerContext, ) { let cranelift_signature = cranelift_signature( - function_definition.locals.iter().map(Into::into), - function_definition.return_type, + function_definition.locals.iter(), + function_definition.return_types.iter(), &context.target_triple, ); @@ -360,10 +360,6 @@ fn compile_instruction(instruction: &PatioInstruction, context: &mut CompilerFun compile_return(return_, context); } - PatioInstruction::ReturnVoid(return_void) => { - compile_return_void(return_void, context); - } - PatioInstruction::Switch(switch) => { compile_switch(switch, context); } @@ -682,13 +678,13 @@ fn compile_memory_store( } fn compile_return(return_: &PatioReturn, context: &mut CompilerFunctionContext<'_>) { - let cranelift_value = compile_operand(&return_.value, context); - - context.function_builder.ins().return_(&[cranelift_value]); -} + let cranelift_values: Vec<_> = return_ + .values + .iter() + .map(|value| compile_operand(value, context)) + .collect(); -fn compile_return_void(_return_void: &PatioReturnVoid, context: &mut CompilerFunctionContext<'_>) { - context.function_builder.ins().return_(&[]); + context.function_builder.ins().return_(&cranelift_values); } fn compile_switch(switch: &PatioSwitch, context: &mut CompilerFunctionContext<'_>) { @@ -886,7 +882,7 @@ fn new_cranelift_signature() -> cranelift::prelude::Signature { fn cranelift_signature<'a>( locals: impl Iterator<Item = &'a PatioLocal>, - return_type: PatioType, + return_types: impl Iterator<Item = &'a PatioType>, target_triple: &target_lexicon::Triple, ) -> cranelift::prelude::Signature { let mut signature = new_cranelift_signature(); @@ -899,9 +895,9 @@ fn cranelift_signature<'a>( } } - if return_type != PatioType::Void { + 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); } diff --git a/patio-to-cranelift/src/codegen/types.rs b/patio-to-cranelift/src/codegen/types.rs index 38cc6b2e..21833f3f 100644 --- a/patio-to-cranelift/src/codegen/types.rs +++ b/patio-to-cranelift/src/codegen/types.rs @@ -16,8 +16,6 @@ pub(crate) fn patio_type_to_cranelift_type( PatioType::Int => cranelift_int_type(target_triple), PatioType::Int32 => CRANELIFT_INT_32_TYPE, - - PatioType::Void => todo!(), } } diff --git a/patio-to-cranelift/src/patio/compilation_unit.rs b/patio-to-cranelift/src/patio/compilation_unit.rs index ecf80558..af8b4d3f 100644 --- a/patio-to-cranelift/src/patio/compilation_unit.rs +++ b/patio-to-cranelift/src/patio/compilation_unit.rs @@ -36,14 +36,14 @@ pub(crate) struct PatioDataElementMutableDeclaration { pub(crate) struct PatioFunctionDeclaration { pub(crate) name: String, pub(crate) params: Vec<PatioLocal>, - pub(crate) return_type: PatioType, + 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_type: PatioType, + pub(crate) return_types: Vec<PatioType>, pub(crate) body: Vec<PatioInstruction>, } diff --git a/patio-to-cranelift/src/patio/flatbuffers.rs b/patio-to-cranelift/src/patio/flatbuffers.rs index 5622259a..35226614 100644 --- a/patio-to-cranelift/src/patio/flatbuffers.rs +++ b/patio-to-cranelift/src/patio/flatbuffers.rs @@ -10,8 +10,8 @@ use crate::{ PatioBlock, PatioBoolToInt, PatioCall, PatioCallPointer, PatioDataPtrToInt, PatioIf, PatioInstruction, PatioIntAdd, PatioIntEquals, PatioIntNotEqual, PatioIntSub, PatioIntToBool, PatioIntToDataPtr, PatioLocalStore, PatioLoop, PatioLoopBreak, - PatioLoopContinue, PatioMemoryLoad, PatioMemoryStore, PatioReturn, PatioReturnVoid, - PatioSwitch, PatioSwitchCase, PatioUnreachable, PatioVarLoad, PatioVarStore, + PatioLoopContinue, PatioMemoryLoad, PatioMemoryStore, PatioReturn, PatioSwitch, + PatioSwitchCase, PatioUnreachable, PatioVarLoad, PatioVarStore, }, operands::{PatioLocalRef, PatioOperand}, types::{PatioDataLayout, PatioType}, @@ -77,7 +77,7 @@ impl From<patio_generated::patio::PatioCompilationUnitElement<'_>> for PatioComp .iter() .map(Into::into) .collect(), - return_type: function_declaration.return_type().into(), + return_types: function_declaration.return_types().iter().map(Into::into).collect(), }) } @@ -92,7 +92,7 @@ impl From<patio_generated::patio::PatioCompilationUnitElement<'_>> for PatioComp .iter() .map(Into::into) .collect(), - return_type: function_definition.return_type().into(), + return_types: function_definition.return_types().iter().map(Into::into).collect(), body: function_definition.body().iter().map(Into::into).collect(), }) } @@ -314,14 +314,10 @@ impl From<patio_generated::patio::PatioInstruction<'_>> for PatioInstruction { let return_ = value.value_as_patio_return().unwrap(); Self::Return(PatioReturn { - value: return_.value().into(), + values: return_.values().iter().map(Into::into).collect(), }) } - patio_generated::patio::PatioInstructionValue::PatioReturnVoid => { - Self::ReturnVoid(PatioReturnVoid) - } - patio_generated::patio::PatioInstructionValue::PatioSwitch => { let switch = value.value_as_patio_switch().unwrap(); @@ -509,7 +505,6 @@ impl From<patio_generated::patio::PatioType<'_>> for PatioType { PatioTypeValue::PatioFunctionPtrType => Self::FunctionPtr, PatioTypeValue::PatioIntType => Self::Int, PatioTypeValue::PatioInt32Type => Self::Int32, - PatioTypeValue::PatioVoidType => Self::Void, type_type => { todo!( diff --git a/patio-to-cranelift/src/patio/instructions.rs b/patio-to-cranelift/src/patio/instructions.rs index af354117..804ee93d 100644 --- a/patio-to-cranelift/src/patio/instructions.rs +++ b/patio-to-cranelift/src/patio/instructions.rs @@ -23,7 +23,6 @@ pub(crate) enum PatioInstruction { MemoryLoad(PatioMemoryLoad), MemoryStore(PatioMemoryStore), Return(PatioReturn), - ReturnVoid(PatioReturnVoid), Switch(PatioSwitch), Unreachable(PatioUnreachable), VarLoad(PatioVarLoad), @@ -126,11 +125,9 @@ pub(crate) struct PatioMemoryStore { } pub(crate) struct PatioReturn { - pub(crate) value: PatioOperand, + pub(crate) values: Vec<PatioOperand>, } -pub(crate) struct PatioReturnVoid; - pub(crate) struct PatioSwitch { pub(crate) destinations: Vec<PatioLocalRef>, pub(crate) value: PatioOperand, diff --git a/patio-to-cranelift/src/patio/types.rs b/patio-to-cranelift/src/patio/types.rs index c513ed4e..49bce09a 100644 --- a/patio-to-cranelift/src/patio/types.rs +++ b/patio-to-cranelift/src/patio/types.rs @@ -6,7 +6,6 @@ pub(crate) enum PatioType { FunctionPtr, Int, Int32, - Void, } #[derive(Clone, Debug, PartialEq)] diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDeclareNativeFunctionTests]/[method:canDeclareNativeFunction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDeclareNativeFunctionTests]/[method:canDeclareNativeFunction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 79bf224b..9c0b8a8a 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDeclareNativeFunctionTests]/[method:canDeclareNativeFunction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDeclareNativeFunctionTests]/[method:canDeclareNativeFunction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,13 +4,13 @@ Compilation unit elements: function-decl "shed__runtime__namespace__Example__Project__f" params=((param "p1" int) (param "p2" int) (param "n1" int) (param "n2" int)) - return-type=int + return-types=(int) ) ( function-decl "shed__runtime__gc_alloc" params=((param "size" int) (param "runtime_type_tag" int32)) - return-type=data-ptr + return-types=(data-ptr) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineEffectTests]/[method:canGenerateCodeForDefineEffect(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineEffectTests]/[method:canGenerateCodeForDefineEffect(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 886829fb..bdfe2eb4 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineEffectTests]/[method:canGenerateCodeForDefineEffect(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineEffectTests]/[method:canGenerateCodeForDefineEffect(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -5,26 +5,26 @@ Compilation unit elements: function-decl "shed__runtime__gc_alloc" params=((param "size" int) (param "runtime_type_tag" int32)) - return-type=data-ptr + return-types=(data-ptr) ) ( function-decl "shed__runtime__gc_get_root_stack_index" params=() - return-type=int + return-types=(int) ) ( function-decl "shed__runtime__effects_find_handler_method" params=((param "effectTag" int) (param "methodIndex" int)) - return-type=int + return-types=(int) ) ( function "shed__function__read__0" visibility=private locals=((param "closurePointer__0" data-ptr) (param "local__fence" int) (val "gcRootStackIndex__0" int) (val "effectHandlerMethod__0" int) (val "tmp__0" int) (val "closurePointer__1" data-ptr) (val "callFunctionPointer__0" function-ptr)) - return-type=int + return-types=(int) body=( (call (local "gcRootStackIndex__0") "shed__runtime__gc_get_root_stack_index" ()) (call (local "effectHandlerMethod__0") "shed__runtime__effects_find_handler_method" ((int-const 3) (int-const 0))) @@ -37,7 +37,7 @@ Compilation unit elements: element-offsets=(1 0) ) (call-pointer (local "tmp__0") (local "callFunctionPointer__0") ((local "closurePointer__1") (local "local__fence"))) - (return (local "tmp__0")) + (return ((local "tmp__0"))) ) ) ( @@ -45,7 +45,7 @@ Compilation unit elements: "shed__function__write__0" visibility=private locals=((param "closurePointer__0" data-ptr) (param "local__arg0" int) (val "gcRootStackIndex__0" int) (val "effectHandlerMethod__0" int) (val "tmp__0" int) (val "closurePointer__1" data-ptr) (val "callFunctionPointer__0" function-ptr)) - return-type=int + return-types=(int) body=( (call (local "gcRootStackIndex__0") "shed__runtime__gc_get_root_stack_index" ()) (call (local "effectHandlerMethod__0") "shed__runtime__effects_find_handler_method" ((int-const 3) (int-const 1))) @@ -58,7 +58,7 @@ Compilation unit elements: element-offsets=(1 0) ) (call-pointer (local "tmp__0") (local "callFunctionPointer__0") ((local "closurePointer__1") (local "local__arg0"))) - (return (local "tmp__0")) + (return ((local "tmp__0"))) ) ) diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:canCaptureFreeVariablesThatAreSetAfterDefinition(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:canCaptureFreeVariablesThatAreSetAfterDefinition(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 875a787c..9c851cca 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:canCaptureFreeVariablesThatAreSetAfterDefinition(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:canCaptureFreeVariablesThatAreSetAfterDefinition(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,26 +4,26 @@ Compilation unit elements: function-decl "shed__runtime__gc_get_root_stack_index" params=() - return-type=int + return-types=(int) ) ( function-decl "shed__runtime__gc_set_root_stack_index" params=((param "gc_root_stack_index" int)) - return-type=void + return-types=() ) ( function-decl "shed__runtime__gc_push_root" params=((param "gc_root" int)) - return-type=void + return-types=() ) ( function "shed__function__f__0" visibility=private locals=((param "closurePointer__0" data-ptr) (val "local__a" int) (val "local__b" int) (val "gcRootStackIndex__0" int)) - return-type=int + return-types=(int) body=( ( memory-load @@ -42,14 +42,14 @@ Compilation unit elements: (call (local "gcRootStackIndex__0") "shed__runtime__gc_get_root_stack_index" ()) (call _ "shed__runtime__gc_set_root_stack_index" ((local "gcRootStackIndex__0"))) (call _ "shed__runtime__gc_push_root" ((local "local__a"))) - (return (local "local__a")) + (return ((local "local__a"))) ) ) ( function-decl "shed__runtime__gc_alloc" params=((param "size" int) (param "runtime_type_tag" int32)) - return-type=data-ptr + return-types=(data-ptr) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:canDefineMinimalFunction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:canDefineMinimalFunction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index f6264ebf..1fabfacf 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:canDefineMinimalFunction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:canDefineMinimalFunction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,39 +4,39 @@ Compilation unit elements: function-decl "shed__runtime__gc_get_root_stack_index" params=() - return-type=int + return-types=(int) ) ( function-decl "shed__runtime__gc_set_root_stack_index" params=((param "gc_root_stack_index" int)) - return-type=void + return-types=() ) ( function-decl "shed__runtime__gc_push_root" params=((param "gc_root" int)) - return-type=void + return-types=() ) ( function "shed__function__f__0" visibility=private locals=((param "closurePointer__0" data-ptr) (val "gcRootStackIndex__0" int) (val "tmp__0" int)) - return-type=int + return-types=(int) body=( (call (local "gcRootStackIndex__0") "shed__runtime__gc_get_root_stack_index" ()) (local-store (local "tmp__0") (int-const 0)) (call _ "shed__runtime__gc_set_root_stack_index" ((local "gcRootStackIndex__0"))) (call _ "shed__runtime__gc_push_root" ((local "tmp__0"))) - (return (local "tmp__0")) + (return ((local "tmp__0"))) ) ) ( function-decl "shed__runtime__gc_alloc" params=((param "size" int) (param "runtime_type_tag" int32)) - return-type=data-ptr + return-types=(data-ptr) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:effectHandlerMethodSwapsEffectHandlerInBody(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:effectHandlerMethodSwapsEffectHandlerInBody(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 7d1e48a9..3c464dad 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:effectHandlerMethodSwapsEffectHandlerInBody(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:effectHandlerMethodSwapsEffectHandlerInBody(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,38 +4,38 @@ Compilation unit elements: function-decl "shed__runtime__effects_get_handler" params=() - return-type=data-ptr + return-types=(data-ptr) ) ( function-decl "shed__runtime__effects_set_handler" params=((param "effectHandler" data-ptr)) - return-type=void + return-types=() ) ( function-decl "shed__runtime__gc_get_root_stack_index" params=() - return-type=int + return-types=(int) ) ( function-decl "shed__runtime__gc_set_root_stack_index" params=((param "gc_root_stack_index" int)) - return-type=void + return-types=() ) ( function-decl "shed__runtime__gc_push_root" params=((param "gc_root" int)) - return-type=void + return-types=() ) ( function "shed__effectHandlerMethod__f__0" visibility=private locals=((param "closurePointer__0" data-ptr) (val "gcRootStackIndex__0" int) (val "effectHandler__0" data-ptr) (val "effectHandler__1" data-ptr) (val "tmp__0" int)) - return-type=int + return-types=(int) body=( (call (local "gcRootStackIndex__0") "shed__runtime__gc_get_root_stack_index" ()) (call (local "effectHandler__0") "shed__runtime__effects_get_handler" ()) @@ -51,14 +51,14 @@ Compilation unit elements: (call _ "shed__runtime__gc_set_root_stack_index" ((local "gcRootStackIndex__0"))) (call _ "shed__runtime__gc_push_root" ((local "tmp__0"))) (call _ "shed__runtime__effects_set_handler" ((local "effectHandler__0"))) - (return (local "tmp__0")) + (return ((local "tmp__0"))) ) ) ( function-decl "shed__runtime__gc_alloc" params=((param "size" int) (param "runtime_type_tag" int32)) - return-type=data-ptr + return-types=(data-ptr) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:immutableFreeVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:immutableFreeVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 5bac2752..23c66251 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:immutableFreeVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:immutableFreeVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,26 +4,26 @@ Compilation unit elements: function-decl "shed__runtime__gc_get_root_stack_index" params=() - return-type=int + return-types=(int) ) ( function-decl "shed__runtime__gc_set_root_stack_index" params=((param "gc_root_stack_index" int)) - return-type=void + return-types=() ) ( function-decl "shed__runtime__gc_push_root" params=((param "gc_root" int)) - return-type=void + return-types=() ) ( function "shed__function__f__0" visibility=private locals=((param "closurePointer__0" data-ptr) (val "local__a" int) (val "local__b" int) (val "gcRootStackIndex__0" int)) - return-type=int + return-types=(int) body=( ( memory-load @@ -42,14 +42,14 @@ Compilation unit elements: (call (local "gcRootStackIndex__0") "shed__runtime__gc_get_root_stack_index" ()) (call _ "shed__runtime__gc_set_root_stack_index" ((local "gcRootStackIndex__0"))) (call _ "shed__runtime__gc_push_root" ((local "local__a"))) - (return (local "local__a")) + (return ((local "local__a"))) ) ) ( function-decl "shed__runtime__gc_alloc" params=((param "size" int) (param "runtime_type_tag" int32)) - return-type=data-ptr + return-types=(data-ptr) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:pointersToFreeMutableVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:pointersToFreeMutableVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 43e193ad..4cdda701 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:pointersToFreeMutableVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:pointersToFreeMutableVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,26 +4,26 @@ Compilation unit elements: function-decl "shed__runtime__gc_get_root_stack_index" params=() - return-type=int + return-types=(int) ) ( function-decl "shed__runtime__gc_set_root_stack_index" params=((param "gc_root_stack_index" int)) - return-type=void + return-types=() ) ( function-decl "shed__runtime__gc_push_root" params=((param "gc_root" int)) - return-type=void + return-types=() ) ( function "shed__function__f__0" visibility=private locals=((param "closurePointer__0" data-ptr) (val "local__a" data-ptr) (val "local__b" data-ptr) (val "gcRootStackIndex__0" int)) - return-type=int + return-types=(int) body=( ( memory-load @@ -42,14 +42,14 @@ Compilation unit elements: (call (local "gcRootStackIndex__0") "shed__runtime__gc_get_root_stack_index" ()) (call _ "shed__runtime__gc_set_root_stack_index" ((local "gcRootStackIndex__0"))) (call _ "shed__runtime__gc_push_root" ((local "local__a"))) - (return (local "local__a")) + (return ((local "local__a"))) ) ) ( function-decl "shed__runtime__gc_alloc" params=((param "size" int) (param "runtime_type_tag" int32)) - return-type=data-ptr + return-types=(data-ptr) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index d58100c6..8adc1386 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,32 +4,32 @@ Compilation unit elements: function-decl "shed__runtime__gc_get_root_stack_index" params=() - return-type=int + return-types=(int) ) ( function-decl "shed__runtime__int_add" params=((param "left" int) (param "right" int)) - return-type=int + return-types=(int) ) ( function-decl "shed__runtime__gc_set_root_stack_index" params=((param "gc_root_stack_index" int)) - return-type=void + return-types=() ) ( function-decl "shed__runtime__gc_push_root" params=((param "gc_root" int)) - return-type=void + return-types=() ) ( function "shed__function__f__0" visibility=private locals=((param "closurePointer__0" data-ptr) (param "local__param1" int) (param "local__param2" int) (param "local__paramA" int) (param "local__paramB" int) (param "local__paramC" int) (val "local__a" int) (val "local__b" int) (val "gcRootStackIndex__0" int) (val "binaryOpResult__0" int) (val "binaryOpResult__1" int)) - return-type=int + return-types=(int) body=( ( memory-load @@ -50,14 +50,14 @@ Compilation unit elements: (call (local "binaryOpResult__1") "shed__runtime__int_add" ((local "binaryOpResult__0") (local "local__paramA"))) (call _ "shed__runtime__gc_set_root_stack_index" ((local "gcRootStackIndex__0"))) (call _ "shed__runtime__gc_push_root" ((local "binaryOpResult__1"))) - (return (local "binaryOpResult__1")) + (return ((local "binaryOpResult__1"))) ) ) ( function-decl "shed__runtime__gc_alloc" params=((param "size" int) (param "runtime_type_tag" int32)) - return-type=data-ptr + return-types=(data-ptr) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineStructTests]/[method:canGenerateCodeForDefineStructNonPositional(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineStructTests]/[method:canGenerateCodeForDefineStructNonPositional(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index aadd8bae..719174fd 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineStructTests]/[method:canGenerateCodeForDefineStructNonPositional(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineStructTests]/[method:canGenerateCodeForDefineStructNonPositional(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,20 +4,20 @@ Compilation unit elements: function-decl "shed__runtime__gc_get_root_stack_index" params=() - return-type=int + return-types=(int) ) ( function-decl "shed__runtime__gc_alloc" params=((param "size" int) (param "runtime_type_tag" int32)) - return-type=data-ptr + return-types=(data-ptr) ) ( function "shed__function__User__0" visibility=private locals=((param "closurePointer__0" data-ptr) (param "local__isActive" int) (param "local__name" int) (val "gcRootStackIndex__0" int) (val "structValuePointer__0" data-ptr) (val "structValue__0" int)) - return-type=int + return-types=(int) body=( (call (local "gcRootStackIndex__0") "shed__runtime__gc_get_root_stack_index" ()) (call (local "structValuePointer__0") "shed__runtime__gc_alloc" ((int-const (byte-size-of (struct ((struct (data-ptr int32 int32)) (struct (int int)))))) (int32-const 3))) @@ -57,7 +57,7 @@ Compilation unit elements: value=(local "local__isActive") ) (data-ptr-to-int (local "structValue__0") (local "structValuePointer__0")) - (return (local "structValue__0")) + (return ((local "structValue__0"))) ) ) diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineStructTests]/[method:canGenerateCodeForDefineStructPositional(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineStructTests]/[method:canGenerateCodeForDefineStructPositional(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 66fb05e3..2583eee5 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineStructTests]/[method:canGenerateCodeForDefineStructPositional(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineStructTests]/[method:canGenerateCodeForDefineStructPositional(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,20 +4,20 @@ Compilation unit elements: function-decl "shed__runtime__gc_get_root_stack_index" params=() - return-type=int + return-types=(int) ) ( function-decl "shed__runtime__gc_alloc" params=((param "size" int) (param "runtime_type_tag" int32)) - return-type=data-ptr + return-types=(data-ptr) ) ( function "shed__function__User__0" visibility=private locals=((param "closurePointer__0" data-ptr) (param "local__name" int) (param "local__isActive" int) (val "gcRootStackIndex__0" int) (val "structValuePointer__0" data-ptr) (val "structValue__0" int)) - return-type=int + return-types=(int) body=( (call (local "gcRootStackIndex__0") "shed__runtime__gc_get_root_stack_index" ()) (call (local "structValuePointer__0") "shed__runtime__gc_alloc" ((int-const (byte-size-of (struct ((struct (data-ptr int32 int32)) (struct (int int)))))) (int32-const 3))) @@ -57,7 +57,7 @@ Compilation unit elements: value=(local "local__isActive") ) (data-ptr-to-int (local "structValue__0") (local "structValuePointer__0")) - (return (local "structValue__0")) + (return ((local "structValue__0"))) ) ) diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIfTests]/[method:canGenerateCodeForIfWithMultipleResults(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIfTests]/[method:canGenerateCodeForIfWithMultipleResults(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 83e422da..1fd4b1ff 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIfTests]/[method:canGenerateCodeForIfWithMultipleResults(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIfTests]/[method:canGenerateCodeForIfWithMultipleResults(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,7 +4,7 @@ Compilation unit elements: function-decl "shed__runtime__int_create" params=((param "value" int)) - return-type=int + return-types=(int) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIfTests]/[method:canGenerateCodeForIfWithNoResults(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIfTests]/[method:canGenerateCodeForIfWithNoResults(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 7073d213..2e088c7d 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIfTests]/[method:canGenerateCodeForIfWithNoResults(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIfTests]/[method:canGenerateCodeForIfWithNoResults(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,7 +4,7 @@ Compilation unit elements: function-decl "shed__runtime__int_create" params=((param "value" int)) - return-type=int + return-types=(int) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIfTests]/[method:canGenerateCodeForIfWithSingleResult(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIfTests]/[method:canGenerateCodeForIfWithSingleResult(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index a07c0caa..4cb1115a 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIfTests]/[method:canGenerateCodeForIfWithSingleResult(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIfTests]/[method:canGenerateCodeForIfWithSingleResult(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,13 +4,13 @@ Compilation unit elements: function-decl "shed__runtime__int_create" params=((param "value" int)) - return-type=int + return-types=(int) ) ( function-decl "shed__runtime__int_add" params=((param "left" int) (param "right" int)) - return-type=int + return-types=(int) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntAddTests]/[method:canGenerateCodeForIntAdd(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntAddTests]/[method:canGenerateCodeForIntAdd(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 7a188f28..84a9c810 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntAddTests]/[method:canGenerateCodeForIntAdd(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntAddTests]/[method:canGenerateCodeForIntAdd(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,7 +4,7 @@ Compilation unit elements: function-decl "shed__runtime__int_add" params=((param "left" int) (param "right" int)) - return-type=int + return-types=(int) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntEqualsTests]/[method:canGenerateCodeForIntEquals(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntEqualsTests]/[method:canGenerateCodeForIntEquals(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 5bbbded1..0b72a103 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntEqualsTests]/[method:canGenerateCodeForIntEquals(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntEqualsTests]/[method:canGenerateCodeForIntEquals(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,7 +4,7 @@ Compilation unit elements: function-decl "shed__runtime__int_equals" params=((param "left" int) (param "right" int)) - return-type=bool + return-types=(bool) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntGreaterThanOrEqualTests]/[method:canGenerateCodeForIntGreaterThanOrEqual(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntGreaterThanOrEqualTests]/[method:canGenerateCodeForIntGreaterThanOrEqual(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 616d0d6b..ffb1e042 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntGreaterThanOrEqualTests]/[method:canGenerateCodeForIntGreaterThanOrEqual(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntGreaterThanOrEqualTests]/[method:canGenerateCodeForIntGreaterThanOrEqual(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,7 +4,7 @@ Compilation unit elements: function-decl "shed__runtime__int_greater_than_or_equal" params=((param "left" int) (param "right" int)) - return-type=bool + return-types=(bool) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntGreaterThanTests]/[method:canGenerateCodeForIntGreaterThan(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntGreaterThanTests]/[method:canGenerateCodeForIntGreaterThan(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 4c0fe93a..6b9eed27 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntGreaterThanTests]/[method:canGenerateCodeForIntGreaterThan(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntGreaterThanTests]/[method:canGenerateCodeForIntGreaterThan(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,7 +4,7 @@ Compilation unit elements: function-decl "shed__runtime__int_greater_than" params=((param "left" int) (param "right" int)) - return-type=bool + return-types=(bool) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntLessThanOrEqualTests]/[method:canGenerateCodeForIntLessThanOrEqual(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntLessThanOrEqualTests]/[method:canGenerateCodeForIntLessThanOrEqual(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index bd01299e..ae559ced 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntLessThanOrEqualTests]/[method:canGenerateCodeForIntLessThanOrEqual(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntLessThanOrEqualTests]/[method:canGenerateCodeForIntLessThanOrEqual(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,7 +4,7 @@ Compilation unit elements: function-decl "shed__runtime__int_less_than_or_equal" params=((param "left" int) (param "right" int)) - return-type=bool + return-types=(bool) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntLessThanTests]/[method:canGenerateCodeForIntLessThan(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntLessThanTests]/[method:canGenerateCodeForIntLessThan(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 7bf55bf5..e637488d 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntLessThanTests]/[method:canGenerateCodeForIntLessThan(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntLessThanTests]/[method:canGenerateCodeForIntLessThan(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,7 +4,7 @@ Compilation unit elements: function-decl "shed__runtime__int_less_than" params=((param "left" int) (param "right" int)) - return-type=bool + return-types=(bool) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntMultiplyTests]/[method:canGenerateCodeForIntMultiply(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntMultiplyTests]/[method:canGenerateCodeForIntMultiply(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 44fa9815..77fb1e52 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntMultiplyTests]/[method:canGenerateCodeForIntMultiply(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntMultiplyTests]/[method:canGenerateCodeForIntMultiply(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,7 +4,7 @@ Compilation unit elements: function-decl "shed__runtime__int_multiply" params=((param "left" int) (param "right" int)) - return-type=int + return-types=(int) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntNotEqualTests]/[method:canGenerateCodeForIntNotEqual(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntNotEqualTests]/[method:canGenerateCodeForIntNotEqual(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 6fa1e30b..3319da54 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntNotEqualTests]/[method:canGenerateCodeForIntNotEqual(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntNotEqualTests]/[method:canGenerateCodeForIntNotEqual(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,7 +4,7 @@ Compilation unit elements: function-decl "shed__runtime__int_not_equal" params=((param "left" int) (param "right" int)) - return-type=bool + return-types=(bool) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntSubTests]/[method:canGenerateCodeForIntSub(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntSubTests]/[method:canGenerateCodeForIntSub(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index f34f9280..4649ab01 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntSubTests]/[method:canGenerateCodeForIntSub(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioIntSubTests]/[method:canGenerateCodeForIntSub(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,7 +4,7 @@ Compilation unit elements: function-decl "shed__runtime__int_sub" params=((param "left" int) (param "right" int)) - return-type=int + return-types=(int) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioLoopTests]/[method:canGenerateCodeForLoop(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioLoopTests]/[method:canGenerateCodeForLoop(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index edce67ab..65a0f11c 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioLoopTests]/[method:canGenerateCodeForLoop(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioLoopTests]/[method:canGenerateCodeForLoop(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,7 +4,7 @@ Compilation unit elements: function-decl "shed__runtime__int_create" params=((param "value" int)) - return-type=int + return-types=(int) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioNamespaceImportTests]/[method:canGenerateCodeForNamespaceImport(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioNamespaceImportTests]/[method:canGenerateCodeForNamespaceImport(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 28c8ed80..6331c0e1 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioNamespaceImportTests]/[method:canGenerateCodeForNamespaceImport(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioNamespaceImportTests]/[method:canGenerateCodeForNamespaceImport(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,7 +4,7 @@ Compilation unit elements: function-decl "shed__namespaceImport__Example_Project" params=() - return-type=int + return-types=(int) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioNamespaceTests]/[method:canDefineNamespace(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioNamespaceTests]/[method:canDefineNamespace(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 76460b4b..26b793e7 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioNamespaceTests]/[method:canDefineNamespace(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioNamespaceTests]/[method:canDefineNamespace(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -5,38 +5,38 @@ function-decl "shed__runtime__gc_alloc" params=((param "size" int) (param "runtime_type_tag" int32)) - return-type=data-ptr + return-types=(data-ptr) ) ( function-decl "shed__runtime__gc_get_root_stack_index" params=() - return-type=int + return-types=(int) ) ( function-decl "shed__runtime__gc_set_root_stack_index" params=((param "gc_root_stack_index" int)) - return-type=void + return-types=() ) ( function-decl "shed__runtime__gc_push_root" params=((param "gc_root" int)) - return-type=void + return-types=() ) ( function "shed__function__f__0" visibility=private locals=((param "closurePointer__0" data-ptr) (val "gcRootStackIndex__0" int) (val "tmp__0" int)) - return-type=int + return-types=(int) body=( (call (local "gcRootStackIndex__0") "shed__runtime__gc_get_root_stack_index" ()) (local-store (local "tmp__0") (int-const 0)) (call _ "shed__runtime__gc_set_root_stack_index" ((local "gcRootStackIndex__0"))) (call _ "shed__runtime__gc_push_root" ((local "tmp__0"))) - (return (local "tmp__0")) + (return ((local "tmp__0"))) ) ) ( @@ -44,7 +44,7 @@ "shed__namespaceInit__An_Example" visibility=private locals=((val "namespaceValue__0" data-ptr) (val "closure__f__0" int) (val "closurePointer__f__0" data-ptr)) - return-type=void + return-types=() body=( (call (local "namespaceValue__0") "shed__runtime__gc_alloc" ((int-const (byte-size-of (struct ((struct (data-ptr int32 int32)) (struct (int int)))))) (int32-const 3))) ( @@ -84,7 +84,7 @@ element-offsets=() value=(bool-const true) ) - (return-void) + (return ()) ) ) ( @@ -92,7 +92,7 @@ "shed__namespaceImport__An_Example" visibility=public locals=((val "tmp__0" bool) (val "namespacePointer__0" int) (val "namespaceValue__0" int)) - return-type=int + return-types=(int) body=( ( memory-load @@ -127,7 +127,7 @@ element-offsets=() ) (data-ptr-to-int (local "namespaceValue__0") (local "namespacePointer__0")) - (return (local "namespaceValue__0")) + (return ((local "namespaceValue__0"))) ) ) )
\ No newline at end of file diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioPushIntTests]/[method:pushIntInstructionGeneratesIntGetInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioPushIntTests]/[method:pushIntInstructionGeneratesIntGetInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 680f7db8..70be4ab4 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioPushIntTests]/[method:pushIntInstructionGeneratesIntGetInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioPushIntTests]/[method:pushIntInstructionGeneratesIntGetInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,7 +4,7 @@ Compilation unit elements: function-decl "shed__runtime__int_create" params=((param "value" int)) - return-type=int + return-types=(int) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioResumeTests]/[method:resumeInstructionGeneratesResumeInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioResumeTests]/[method:resumeInstructionGeneratesResumeInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index ccf83153..643d2466 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioResumeTests]/[method:resumeInstructionGeneratesResumeInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioResumeTests]/[method:resumeInstructionGeneratesResumeInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,13 +4,13 @@ Compilation unit elements: function-decl "shed__runtime__gc_set_root_stack_index" params=((param "gc_root_stack_index" int)) - return-type=void + return-types=() ) ( function-decl "shed__runtime__gc_push_root" params=((param "gc_root" int)) - return-type=void + return-types=() ) Locals: @@ -21,7 +21,7 @@ Instructions: (call _ "shed__runtime__gc_set_root_stack_index" ((local "gc_root_stack_index"))) (call _ "shed__runtime__gc_push_root" ((local "b"))) (call _ "shed__runtime__effects_set_handler" ((local "effect_handler"))) - (return (local "b")) + (return ((local "b"))) ) Temporary stack: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioReturnTests]/[method:returnInstructionGeneratesReturnInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioReturnTests]/[method:returnInstructionGeneratesReturnInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index ecd225eb..69abd5ce 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioReturnTests]/[method:returnInstructionGeneratesReturnInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioReturnTests]/[method:returnInstructionGeneratesReturnInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,13 +4,13 @@ Compilation unit elements: function-decl "shed__runtime__gc_set_root_stack_index" params=((param "gc_root_stack_index" int)) - return-type=void + return-types=() ) ( function-decl "shed__runtime__gc_push_root" params=((param "gc_root" int)) - return-type=void + return-types=() ) Locals: @@ -20,7 +20,7 @@ Instructions: ( (call _ "shed__runtime__gc_set_root_stack_index" ((local "gc_root_stack_index"))) (call _ "shed__runtime__gc_push_root" ((local "b"))) - (return (local "b")) + (return ((local "b"))) ) Temporary stack: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioStringAddTests]/[method:canGenerateCodeForStringAdd(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioStringAddTests]/[method:canGenerateCodeForStringAdd(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index d5f76603..bf98e176 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioStringAddTests]/[method:canGenerateCodeForStringAdd(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioStringAddTests]/[method:canGenerateCodeForStringAdd(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,7 +4,7 @@ Compilation unit elements: function-decl "shed__runtime__string_add" params=((param "left" int) (param "right" int)) - return-type=int + return-types=(int) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioSwitchTests]/[method:canGenerateCodeForSwitchWithSingleResult(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioSwitchTests]/[method:canGenerateCodeForSwitchWithSingleResult(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index d7367a3f..23349aad 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioSwitchTests]/[method:canGenerateCodeForSwitchWithSingleResult(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioSwitchTests]/[method:canGenerateCodeForSwitchWithSingleResult(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,13 +4,13 @@ Compilation unit elements: function-decl "shed__runtime__int_create" params=((param "value" int)) - return-type=int + return-types=(int) ) ( function-decl "shed__runtime__int_add" params=((param "left" int) (param "right" int)) - return-type=int + return-types=(int) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioTryTests]/[method:canGenerateCodeForTry(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioTryTests]/[method:canGenerateCodeForTry(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index c14f9340..a25edbc3 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioTryTests]/[method:canGenerateCodeForTry(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioTryTests]/[method:canGenerateCodeForTry(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,25 +4,25 @@ Compilation unit elements: function-decl "shed__runtime__effects_push_handler" params=((param "effectHandler" data-ptr)) - return-type=void + return-types=() ) ( function-decl "shed__runtime__effects_pop_handler" params=() - return-type=void + return-types=() ) ( function-decl "shed__runtime__gc_alloc" params=((param "size" int) (param "runtime_type_tag" int32)) - return-type=data-ptr + return-types=(data-ptr) ) ( function-decl "shed__runtime__int_create" params=((param "value" int)) - return-type=int + return-types=(int) ) Locals: diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioTryTests]/[method:effectHandlerIsPoppedBeforeReturn(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioTryTests]/[method:effectHandlerIsPoppedBeforeReturn(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 8cb8b8bc..55e692fe 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioTryTests]/[method:effectHandlerIsPoppedBeforeReturn(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioTryTests]/[method:effectHandlerIsPoppedBeforeReturn(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,37 +4,37 @@ Compilation unit elements: function-decl "shed__runtime__effects_push_handler" params=((param "effectHandler" data-ptr)) - return-type=void + return-types=() ) ( function-decl "shed__runtime__effects_pop_handler" params=() - return-type=void + return-types=() ) ( function-decl "shed__runtime__gc_alloc" params=((param "size" int) (param "runtime_type_tag" int32)) - return-type=data-ptr + return-types=(data-ptr) ) ( function-decl "shed__runtime__int_create" params=((param "value" int)) - return-type=int + return-types=(int) ) ( function-decl "shed__runtime__gc_set_root_stack_index" params=((param "gc_root_stack_index" int)) - return-type=void + return-types=() ) ( function-decl "shed__runtime__gc_push_root" params=((param "gc_root" int)) - return-type=void + return-types=() ) Locals: @@ -85,7 +85,7 @@ Instructions: (call _ "shed__runtime__effects_pop_handler" ()) (call _ "shed__runtime__gc_set_root_stack_index" ((local "gcRootStackIndex"))) (call _ "shed__runtime__gc_push_root" ((local "int__0"))) - (return (local "int__0")) + (return ((local "int__0"))) (call _ "shed__runtime__effects_pop_handler" ()) ) results=() diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioTupleCreateTests]/[method:canGenerateCodeForTupleCreate(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioTupleCreateTests]/[method:canGenerateCodeForTupleCreate(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 9ac22878..0a732971 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioTupleCreateTests]/[method:canGenerateCodeForTupleCreate(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioTupleCreateTests]/[method:canGenerateCodeForTupleCreate(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -4,7 +4,7 @@ Compilation unit elements: function-decl "shed__runtime__gc_alloc" params=((param "size" int) (param "runtime_type_tag" int32)) - return-type=data-ptr + return-types=(data-ptr) ) Locals: diff --git a/src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvm.java b/src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvm.java index 3dfae913..937e23ca 100644 --- a/src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvm.java +++ b/src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvm.java @@ -130,8 +130,8 @@ public class PatioToLlvm { case PatioFunctionDeclaration patioFunctionDeclaration -> { context = context.addFunctionNameToReturnType( patioFunctionDeclaration.name(), - patioTypeToLlvmType( - patioFunctionDeclaration.returnType(), + patioReturnTypesToLlvmType( + patioFunctionDeclaration.returnTypes(), globalContext.target() ) ); @@ -145,8 +145,8 @@ public class PatioToLlvm { case PatioFunctionDefinition patioFunctionDefinition -> { context = context.addFunctionNameToReturnType( patioFunctionDefinition.name(), - patioTypeToLlvmType( - patioFunctionDefinition.returnType(), + patioReturnTypesToLlvmType( + patioFunctionDefinition.returnTypes(), globalContext.target() ) ); @@ -250,8 +250,8 @@ public class PatioToLlvm { ) { return context.addTopLevelEntity(new LlvmFunctionDeclaration( patioFunctionDeclaration.name(), - patioTypeToLlvmType( - patioFunctionDeclaration.returnType(), + patioReturnTypesToLlvmType( + patioFunctionDeclaration.returnTypes(), context.target() ), patioFunctionDeclaration.params().stream() @@ -293,8 +293,8 @@ public class PatioToLlvm { return moduleContext.addTopLevelEntity(new LlvmFunctionDefinition( patioFunctionDefinition.name(), - patioTypeToLlvmType( - patioFunctionDefinition.returnType(), + patioReturnTypesToLlvmType( + patioFunctionDefinition.returnTypes(), target ), StreamSupport.stream(patioFunctionDefinition.params().spliterator(), false) @@ -616,14 +616,19 @@ public class PatioToLlvm { yield context; } - case PatioReturn patioReturn -> - context.addTerminatorInstruction(new LlvmReturn( - patioOperandToLlvmType(patioReturn.value(), context), - patioOperandToLlvmOperand(patioReturn.value(), context) - )); + case PatioReturn patioReturn -> { + var llvmReturnType = patioReturnOperandsToLlvmType(patioReturn.values(), context); - case PatioReturnVoid patioReturnVoid -> - context.addTerminatorInstruction(new LlvmReturnVoid()); + if (llvmReturnType == LlvmTypes.VOID) { + yield context.addTerminatorInstruction(new LlvmReturnVoid()); + } else { + var llvmReturnOperand = patioReturnOperandsToLlvmOperand(patioReturn.values(), context); + yield context.addTerminatorInstruction(new LlvmReturn( + llvmReturnType, + llvmReturnOperand + )); + } + } case PatioSwitch patioSwitch -> { var switchDefaultStartLabelResult = context.allocateLocalName( @@ -1069,6 +1074,17 @@ public class PatioToLlvm { ); } + private static LlvmType patioReturnOperandsToLlvmType( + List<PatioOperand> patioOperands, + PatioToLlvmFunctionContext context + ) { + var llvmTypes = patioOperands.stream() + .map(patioOperand -> patioOperandToLlvmType(patioOperand, context)) + .toList(); + + return mergeLlvmReturnTypes(llvmTypes); + } + private static LlvmType patioOperandToLlvmType( PatioOperand patioOperand, PatioToLlvmFunctionContext context @@ -1082,6 +1098,21 @@ public class PatioToLlvm { }; } + private static LlvmOperand patioReturnOperandsToLlvmOperand( + List<PatioOperand> patioReturnOperands, + PatioToLlvmFunctionContext context + ) { + if (patioReturnOperands.size() == 1) { + return patioOperandToLlvmOperand(patioReturnOperands.get(0), context); + } else { + return new LlvmOperandStructure( + patioReturnOperands.stream() + .map(patioReturnOperand -> patioOperandToLlvmTypedOperand(patioReturnOperand, context)) + .toList() + ); + } + } + private static LlvmOperand patioOperandToLlvmOperand( PatioOperand patioOperand, PatioToLlvmFunctionContext context @@ -1156,6 +1187,26 @@ public class PatioToLlvm { }; } + private static LlvmType patioReturnTypesToLlvmType( + List<PatioType> patioReturnTypes, + LlvmTarget target + ) { + var llvmReturnTypes = patioReturnTypes.stream() + .map(patioReturnType -> patioTypeToLlvmType(patioReturnType, target)) + .toList(); + return mergeLlvmReturnTypes(llvmReturnTypes); + } + + private static LlvmType mergeLlvmReturnTypes(List<LlvmType> returnTypes) { + if (returnTypes.size() == 0) { + return LlvmTypes.VOID; + } else if (returnTypes.size() == 1) { + return returnTypes.get(0); + } else { + return LlvmTypes.structure(returnTypes); + } + } + private static LlvmType patioTypeToLlvmType( PatioType patioType, LlvmTarget target @@ -1178,9 +1229,6 @@ public class PatioToLlvm { case PatioInt32Type patioInt32Type -> LlvmTypes.INT_32; - - case PatioVoidType patioVoidType -> - LlvmTypes.VOID; }; } diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java b/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java index ed416976..8fdcc53e 100644 --- a/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java +++ b/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java @@ -67,10 +67,9 @@ public class PatioToWasm { patioFunctionDeclaration.params().stream() .map(param -> patioTypeToWasmValueType(param.type(), target)) .toList(), - patioTypeToWasmResultTypes( - patioFunctionDeclaration.returnType(), - target - ) + patioFunctionDeclaration.returnTypes().stream() + .map(returnType -> patioTypeToWasmValueType(returnType, target)) + .toList() ); module = module.addImport(new WasmImport( @@ -104,10 +103,9 @@ public class PatioToWasm { } } - var wasmResultTypes = patioTypeToWasmResultTypes( - patioFunctionDefinition.returnType(), - target - ); + var wasmResultTypes = patioFunctionDefinition.returnTypes().stream() + .map(returnType -> patioTypeToWasmValueType(returnType, target)) + .toList(); var context = generateInstructions( patioFunctionDefinition.body(), @@ -341,16 +339,15 @@ public class PatioToWasm { } case PatioReturn patioReturn -> { - context = generateOperand(patioReturn.value(), context); + for (var value : patioReturn.values()) { + context = generateOperand(value, context); + } context = context.addInstruction(new WasmReturn()); yield context; } - case PatioReturnVoid patioReturnVoid -> - context.addInstruction(new WasmReturn()); - case PatioSwitch patioSwitch -> { // TODO: use br_table? @@ -793,20 +790,9 @@ public class PatioToWasm { target.patioIntType(); case PatioInt32Type patioInt32Type -> WasmValueType.I32; - case PatioVoidType patioVoidType -> - throw new IllegalArgumentException("Cannot have void values"); }; } - private static List<WasmValueType> patioTypeToWasmResultTypes( - PatioType type, - WasmTarget target - ) { - return type instanceof PatioVoidType - ? List.of() - : List.of(patioTypeToWasmValueType(type, target)); - } - private static WasmInstruction wasmIntConst(WasmValueType wasmValueType, int value) { return switch (wasmValueType) { case WasmValueType.Number number -> { diff --git a/src/main/java/org/shedlang/compiler/patio/PatioFunctionDeclaration.java b/src/main/java/org/shedlang/compiler/patio/PatioFunctionDeclaration.java index 8b9b29ae..18241108 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioFunctionDeclaration.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioFunctionDeclaration.java @@ -2,7 +2,6 @@ package org.shedlang.compiler.patio; import org.pcollections.PVector; import org.shedlang.compiler.patio.types.PatioType; -import org.shedlang.compiler.patio.types.PatioTypes; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.sources.Sources; import org.shedlang.compiler.util.P; @@ -12,27 +11,27 @@ import java.util.List; public record PatioFunctionDeclaration( String name, List<PatioLocal> params, - PatioType returnType, + List<PatioType> returnTypes, Source source ) implements PatioCompilationUnitElement { public static Builder builder() { return new Builder( "f", P.vector(), - PatioTypes.INT + P.vector() ); } public record Builder( String name, PVector<PatioLocal> params, - PatioType returnType + PVector<PatioType> returnTypes ) { public Builder withName(String name) { return new Builder( name, this.params, - this.returnType + this.returnTypes ); } @@ -40,15 +39,15 @@ public record PatioFunctionDeclaration( return new Builder( this.name, this.params.plus(param), - this.returnType + this.returnTypes ); } - public Builder withReturnType(PatioType returnType) { + public Builder addReturnType(PatioType returnType) { return new Builder( this.name, this.params, - returnType + this.returnTypes.plus(returnType) ); } @@ -56,7 +55,7 @@ public record PatioFunctionDeclaration( return new PatioFunctionDeclaration( this.name, this.params, - this.returnType, + this.returnTypes, Sources.NULL ); } diff --git a/src/main/java/org/shedlang/compiler/patio/PatioFunctionDefinition.java b/src/main/java/org/shedlang/compiler/patio/PatioFunctionDefinition.java index 2cf0f4aa..366ac6d3 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioFunctionDefinition.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioFunctionDefinition.java @@ -3,7 +3,6 @@ package org.shedlang.compiler.patio; import org.pcollections.PVector; import org.shedlang.compiler.patio.instructions.PatioInstruction; import org.shedlang.compiler.patio.types.PatioType; -import org.shedlang.compiler.patio.types.PatioTypes; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.sources.Sources; import org.shedlang.compiler.util.P; @@ -14,7 +13,7 @@ public record PatioFunctionDefinition( String name, PatioVisibility visibility, List<PatioLocal> locals, - PatioType returnType, + List<PatioType> returnTypes, List<PatioInstruction> body, Source source ) implements PatioCompilationUnitElement { @@ -29,7 +28,7 @@ public record PatioFunctionDefinition( "f", PatioVisibility.PRIVATE, P.vector(), - PatioTypes.INT, + P.vector(), P.vector() ); } @@ -38,7 +37,7 @@ public record PatioFunctionDefinition( String name, PatioVisibility visibility, PVector<PatioLocal> locals, - PatioType returnType, + PVector<PatioType> returnTypes, PVector<PatioInstruction> body ) { public Builder withName(String name) { @@ -46,7 +45,7 @@ public record PatioFunctionDefinition( name, this.visibility, this.locals, - this.returnType, + this.returnTypes, this.body ); } @@ -56,7 +55,7 @@ public record PatioFunctionDefinition( this.name, visibility, this.locals, - this.returnType, + this.returnTypes, this.body ); } @@ -66,7 +65,7 @@ public record PatioFunctionDefinition( this.name, this.visibility, this.locals.plus(local), - this.returnType, + this.returnTypes, this.body ); } @@ -76,17 +75,17 @@ public record PatioFunctionDefinition( this.name, this.visibility, this.locals, - this.returnType, + this.returnTypes, this.body.plus(instruction) ); } - public Builder withReturnType(PatioType returnType) { + public Builder addReturnType(PatioType returnType) { return new Builder( this.name, this.visibility, this.locals, - returnType, + this.returnTypes.plus(returnType), this.body ); } @@ -96,7 +95,7 @@ public record PatioFunctionDefinition( this.name, this.visibility, this.locals, - this.returnType, + this.returnTypes, this.body, Sources.NULL ); diff --git a/src/main/java/org/shedlang/compiler/patio/PatioSerializer.java b/src/main/java/org/shedlang/compiler/patio/PatioSerializer.java index d324c5e8..5312ba7f 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioSerializer.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioSerializer.java @@ -134,7 +134,11 @@ public class PatioSerializer { .map(param -> localToTree(param)) .toList() )), - treeNamed("return-type", typeToTree(functionDeclaration.returnType())) + treeNamed("return-types", treeList( + functionDeclaration.returnTypes().stream() + .map(returnType -> typeToTree(returnType)) + .toList() + )) ); case PatioFunctionDefinition functionDefinition -> @@ -147,7 +151,11 @@ public class PatioSerializer { .map(local -> localToTree(local)) .toList() )), - treeNamed("return-type", typeToTree(functionDefinition.returnType())), + treeNamed("return-types", treeList( + functionDefinition.returnTypes().stream() + .map(returnType -> typeToTree(returnType)) + .toList() + )), treeNamed("body", instructionsToTree(functionDefinition.body())) ); }; @@ -296,12 +304,7 @@ public class PatioSerializer { case PatioReturn return_ -> treeList( treeIdentifier("return"), - operandToTree(return_.value()) - ); - - case PatioReturnVoid returnVoid -> - treeList( - treeIdentifier("return-void") + operandsToTree(return_.values()) ); case PatioSwitch switch_ -> @@ -458,9 +461,6 @@ public class PatioSerializer { case PatioInt32Type int32Type -> treeIdentifier("int32"); - - case PatioVoidType voidType -> - treeIdentifier("void"); }; } diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioInstruction.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioInstruction.java index 00e30fe6..25c45200 100644 --- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioInstruction.java +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioInstruction.java @@ -2,7 +2,7 @@ package org.shedlang.compiler.patio.instructions; import org.shedlang.compiler.sources.Source; -public sealed interface PatioInstruction permits PatioBlock, PatioBoolToInt, PatioCall, PatioCallPointer, PatioDataPtrToInt, PatioIf, PatioIntAdd, PatioIntEquals, PatioIntNotEqual, PatioIntSub, PatioIntToBool, PatioIntToDataPtr, PatioLocalStore, PatioLoop, PatioLoopBreak, PatioLoopContinue, PatioMemoryLoad, PatioMemoryStore, PatioReturn, PatioReturnVoid, PatioSwitch, PatioThrow, PatioTry, PatioUnreachable, PatioVarLoad, PatioVarStore { +public sealed interface PatioInstruction permits 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 { boolean isBlockTerminator(); Source source(); } diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioReturn.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioReturn.java index fcf84f51..c7cfbead 100644 --- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioReturn.java +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioReturn.java @@ -3,10 +3,12 @@ package org.shedlang.compiler.patio.instructions; import org.shedlang.compiler.patio.operands.PatioOperand; import org.shedlang.compiler.sources.Source; +import java.util.List; + /** - * Return with the given value from the current function. + * Return with the given values from the current function. */ -public record PatioReturn(PatioOperand value, Source source) implements PatioInstruction { +public record PatioReturn(List<PatioOperand> values, Source source) implements PatioInstruction { @Override public boolean isBlockTerminator() { return true; diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioReturnVoid.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioReturnVoid.java deleted file mode 100644 index b4a8ef3e..00000000 --- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioReturnVoid.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.shedlang.compiler.patio.instructions; - -import org.shedlang.compiler.sources.Source; - -/** - * Return with no value from the current function. - */ -public record PatioReturnVoid(Source source) implements PatioInstruction { - @Override - public boolean isBlockTerminator() { - return true; - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/serialization/PatioToFlatbuffers.java b/src/main/java/org/shedlang/compiler/patio/serialization/PatioToFlatbuffers.java index 870c8204..1d15843b 100644 --- a/src/main/java/org/shedlang/compiler/patio/serialization/PatioToFlatbuffers.java +++ b/src/main/java/org/shedlang/compiler/patio/serialization/PatioToFlatbuffers.java @@ -364,13 +364,16 @@ public class PatioToFlatbuffers { .toArray(); var paramsVectorFbs = PatioFunctionDeclarationFbs.createParamsVector(builder, paramsOffsetsFbs); - var returnTypeFbs = serializeType(builder, functionDeclaration.returnType()); + 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.addReturnType(builder, returnTypeFbs); + PatioFunctionDeclarationFbs.addReturnTypes(builder, returnTypesVectorFbs); return PatioFunctionDeclarationFbs.endPatioFunctionDeclarationFbs(builder); } @@ -389,9 +392,13 @@ public class PatioToFlatbuffers { functionDeclarationFbs.paramsLength(), PatioToFlatbuffers::deserializeLocal ); - var returnType = deserializeType(functionDeclarationFbs.returnType()); + var returnTypes = deserializeVector( + functionDeclarationFbs::returnTypes, + functionDeclarationFbs.returnTypesLength(), + PatioToFlatbuffers::deserializeType + ); - return new PatioFunctionDeclaration(name, params, returnType, source); + return new PatioFunctionDeclaration(name, params, returnTypes, source); } private static int serializeFunctionDefinition( @@ -414,7 +421,10 @@ public class PatioToFlatbuffers { .toArray(); var localsVectorFbs = PatioFunctionDefinitionFbs.createLocalsVector(builder, localsOffsetsFbs); - var returnTypeFbs = serializeType(builder, functionDefinition.returnType()); + 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())) @@ -429,7 +439,7 @@ public class PatioToFlatbuffers { visibilityFbs ); PatioFunctionDefinitionFbs.addLocals(builder, localsVectorFbs); - PatioFunctionDefinitionFbs.addReturnType(builder, returnTypeFbs); + PatioFunctionDefinitionFbs.addReturnTypes(builder, returnTypesVectorFbs); PatioFunctionDefinitionFbs.addBody(builder, bodyVectorFbs); return PatioFunctionDefinitionFbs.endPatioFunctionDefinitionFbs(builder); } @@ -450,14 +460,18 @@ public class PatioToFlatbuffers { functionDefinitionFbs.localsLength(), PatioToFlatbuffers::deserializeLocal ); - var returnType = deserializeType(functionDefinitionFbs.returnType()); + 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, returnType, body, source); + return new PatioFunctionDefinition(name, visibility, locals, returnTypes, body, source); } // == Visibility == @@ -715,15 +729,6 @@ public class PatioToFlatbuffers { yield PatioInstructionFbs.endPatioInstructionFbs(builder); } - case PatioReturnVoid returnVoid -> { - var returnVoidFbs = serializeReturnVoid(builder, returnVoid, parentSource); - - PatioInstructionFbs.startPatioInstructionFbs(builder); - PatioInstructionFbs.addValueType(builder, PatioInstructionValueFbs.PatioReturnVoidFbs); - PatioInstructionFbs.addValue(builder, returnVoidFbs); - yield PatioInstructionFbs.endPatioInstructionFbs(builder); - } - case PatioSwitch switch_ -> { var switchFbs = serializeSwitch(builder, switch_, parentSource); @@ -899,12 +904,6 @@ public class PatioToFlatbuffers { parentSource ); - case PatioInstructionValueFbs.PatioReturnVoidFbs -> - deserializeReturnVoid( - (PatioReturnVoidFbs) instructionFbs.value(new PatioReturnVoidFbs()), - parentSource - ); - case PatioInstructionValueFbs.PatioSwitchFbs -> deserializeSwitch( (PatioSwitchFbs) instructionFbs.value(new PatioSwitchFbs()), @@ -1627,11 +1626,14 @@ public class PatioToFlatbuffers { parentSource ); - var valueFbs = serializeOperand(builder, instruction.value()); + 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.addValue(builder, valueFbs); + PatioReturnFbs.addValues(builder, valuesVectorFbs); return PatioReturnFbs.endPatioReturnFbs(builder); } @@ -1644,34 +1646,13 @@ public class PatioToFlatbuffers { parentSource ); - var value = deserializeOperand(instructionFbs.value()); - - return new PatioReturn(value, source); - } - - public static int serializeReturnVoid( - FlatBufferBuilder builder, - PatioReturnVoid instruction, - Source parentSource - ) { - var sourceFbs = SourceToFlatbuffers.serializeSource( - builder, - instruction.source(), - parentSource + var values = deserializeVector( + instructionFbs::values, + instructionFbs.valuesLength(), + PatioToFlatbuffers::deserializeOperand ); - PatioReturnVoidFbs.startPatioReturnVoidFbs(builder); - PatioReturnVoidFbs.addSource(builder, sourceFbs); - return PatioReturnVoidFbs.endPatioReturnVoidFbs(builder); - } - - private static PatioReturnVoid deserializeReturnVoid( - PatioReturnVoidFbs instructionFbs, - Source parentSource - ) { - var source = SourceToFlatbuffers.deserializeSource(instructionFbs.source(), parentSource); - - return new PatioReturnVoid(source); + return new PatioReturn(values, source); } public static int serializeSwitch( @@ -2349,16 +2330,6 @@ public class PatioToFlatbuffers { PatioTypeFbs.addValue(builder, int32TypeFbs); yield PatioTypeFbs.endPatioTypeFbs(builder); } - - case PatioVoidType _ -> { - PatioVoidTypeFbs.startPatioVoidTypeFbs(builder); - var voidTypeFbs = PatioVoidTypeFbs.endPatioVoidTypeFbs(builder); - - PatioTypeFbs.startPatioTypeFbs(builder); - PatioTypeFbs.addValueType(builder, PatioTypeValueFbs.PatioVoidTypeFbs); - PatioTypeFbs.addValue(builder, voidTypeFbs); - yield PatioTypeFbs.endPatioTypeFbs(builder); - } }; } @@ -2382,9 +2353,6 @@ public class PatioToFlatbuffers { case PatioTypeValueFbs.PatioInt32TypeFbs -> PatioInt32Type.INSTANCE; - case PatioTypeValueFbs.PatioVoidTypeFbs -> - PatioVoidType.INSTANCE; - default -> throw new UnsupportedOperationException("TODO"); }; diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayouts.java b/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayouts.java index 53e8d0d3..357da6c3 100644 --- a/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayouts.java +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioDataLayouts.java @@ -40,9 +40,6 @@ public class PatioDataLayouts { case PatioInt32Type patioInt32Type -> INT32; - - case PatioVoidType patioVoidType -> - throw new UnsupportedOperationException("TODO"); }; } } diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioType.java b/src/main/java/org/shedlang/compiler/patio/types/PatioType.java index 218672da..5ff98153 100644 --- a/src/main/java/org/shedlang/compiler/patio/types/PatioType.java +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioType.java @@ -1,4 +1,4 @@ package org.shedlang.compiler.patio.types; -public sealed interface PatioType permits PatioBoolType, PatioByteType, PatioDataPtrType, PatioFunctionPtrType, PatioInt32Type, PatioIntType, PatioVoidType { +public sealed interface PatioType permits PatioBoolType, PatioByteType, PatioDataPtrType, PatioFunctionPtrType, PatioInt32Type, PatioIntType { } diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioTypes.java b/src/main/java/org/shedlang/compiler/patio/types/PatioTypes.java index 4b6279d0..184ddf4a 100644 --- a/src/main/java/org/shedlang/compiler/patio/types/PatioTypes.java +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioTypes.java @@ -10,5 +10,4 @@ public class PatioTypes { public static final PatioFunctionPtrType FUNCTION_PTR = PatioFunctionPtrType.INSTANCE; public static final PatioIntType INT = PatioIntType.INSTANCE; public static final PatioInt32Type INT32 = PatioInt32Type.INSTANCE; - public static final PatioVoidType VOID = PatioVoidType.INSTANCE; } diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioVoidType.java b/src/main/java/org/shedlang/compiler/patio/types/PatioVoidType.java deleted file mode 100644 index 2075a03c..00000000 --- a/src/main/java/org/shedlang/compiler/patio/types/PatioVoidType.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.shedlang.compiler.patio.types; - -public record PatioVoidType() implements PatioType { - public static final PatioVoidType INSTANCE = new PatioVoidType(); -} diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java index 3f0c752d..88d56cf6 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java @@ -44,7 +44,7 @@ public class ShidToPatio { context = context.createFunction( mainFunctionName, PatioVisibility.PRIVATE, - PatioTypes.INT, + List.of(PatioTypes.INT), source, mainContext -> { mainContext = ShidToPatioGc.init(source, mainContext); @@ -101,7 +101,7 @@ public class ShidToPatio { mainContext = ShidToPatioGc.clear(source, mainContext); mainContext = mainContext.addInstruction( - new PatioReturn(exitCode, source) + new PatioReturn(List.of(exitCode), source) ); return mainContext; @@ -779,7 +779,7 @@ public class ShidToPatio { context ); - yield context.addInstruction(new PatioReturn(value, return_.source())); + yield context.addInstruction(new PatioReturn(List.of(value), return_.source())); } case ShidStringAdd stringAdd -> diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioClosures.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioClosures.java index f93b2844..7a814649 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioClosures.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioClosures.java @@ -140,7 +140,7 @@ class ShidToPatioClosures { context = fullNameResult.context(); var bodyContextParent = context; - context = context.createFunction(fullName, PatioVisibility.PRIVATE, ShidToPatioTypes.VALUE_TYPE, source, bodyContext -> { + context = context.createFunction(fullName, PatioVisibility.PRIVATE, List.of(ShidToPatioTypes.VALUE_TYPE), source, bodyContext -> { var closurePointerResult = bodyContext.allocateParam( ShidToPatioLocalSpace.CLOSURE_POINTER, ShidToPatioClosures.CLOSURE_POINTER_TYPE @@ -201,7 +201,7 @@ class ShidToPatioClosures { generateShidParamList(positionalParams, namedParams).stream() .map(param -> PatioLocal.param(param.name(), ShidToPatioTypes.VALUE_TYPE)) .toList(), - ShidToPatioTypes.VALUE_TYPE, + List.of(ShidToPatioTypes.VALUE_TYPE), source )); diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioContext.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioContext.java index 87e5ff61..5f1025a3 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioContext.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioContext.java @@ -826,7 +826,7 @@ public record ShidToPatioContext( public ShidToPatioContext createFunction( String name, PatioVisibility visibility, - PatioType returnType, + List<PatioType> returnTypes, Source source, Function<ShidToPatioContext, ShidToPatioContext> createBody ) { @@ -847,7 +847,7 @@ public record ShidToPatioContext( name, visibility, locals, - returnType, + returnTypes, bodyContext.functionContext.instructions, source )), diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioEffects.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioEffects.java index a41ef9c7..6a3a519a 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioEffects.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioEffects.java @@ -130,21 +130,21 @@ public class ShidToPatioEffects { PatioLocal.param("effectTag", EFFECT_TAG_TYPE), PatioLocal.param("methodIndex", EFFECT_METHOD_INDEX_TYPE) ), - EFFECT_HANDLER_METHOD_TYPE, + List.of(EFFECT_HANDLER_METHOD_TYPE), Sources.RUNTIME ); private static final PatioFunctionDeclaration GET_HANDLER_DECLARATION = new PatioFunctionDeclaration( "shed__runtime__effects_get_handler", List.of(), - EFFECT_HANDLER_TYPE, + List.of(EFFECT_HANDLER_TYPE), Sources.RUNTIME ); private static final PatioFunctionDeclaration SET_HANDLER_DECLARATION = new PatioFunctionDeclaration( "shed__runtime__effects_set_handler", List.of(PatioLocal.param("effectHandler", EFFECT_HANDLER_TYPE)), - PatioTypes.VOID, + List.of(), Sources.RUNTIME ); @@ -153,14 +153,14 @@ public class ShidToPatioEffects { List.of( PatioLocal.param("effectHandler", EFFECT_HANDLER_TYPE) ), - PatioTypes.VOID, + List.of(), Sources.RUNTIME ); private static final PatioFunctionDeclaration POP_HANDLER_DECLARATION = new PatioFunctionDeclaration( "shed__runtime__effects_pop_handler", List.of(), - PatioTypes.VOID, + List.of(), Sources.RUNTIME ); @@ -264,7 +264,7 @@ public class ShidToPatioEffects { bodyContext ); - bodyContext = bodyContext.addInstruction(new PatioReturn(returnValue, source)); + bodyContext = bodyContext.addInstruction(new PatioReturn(List.of(returnValue), source)); return bodyContext; }, @@ -519,7 +519,7 @@ public class ShidToPatioEffects { source )); - context = context.addInstruction(new PatioReturn(value, source)); + context = context.addInstruction(new PatioReturn(List.of(value), source)); return context; } diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioGc.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioGc.java index 39ff3ce5..65403036 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioGc.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioGc.java @@ -64,7 +64,7 @@ public class ShidToPatioGc { private static final PatioFunctionDeclaration GET_GC_ROOT_STACK_INDEX = new PatioFunctionDeclaration( "shed__runtime__gc_get_root_stack_index", List.of(), - GC_ROOT_STACK_INDEX_TYPE, + List.of(GC_ROOT_STACK_INDEX_TYPE), Sources.RUNTIME ); @@ -86,7 +86,7 @@ public class ShidToPatioGc { private static final PatioFunctionDeclaration SET_GC_ROOT_STACK_INDEX = new PatioFunctionDeclaration( "shed__runtime__gc_set_root_stack_index", List.of(PatioLocal.param("gc_root_stack_index", GC_ROOT_STACK_INDEX_TYPE)), - PatioTypes.VOID, + List.of(), Sources.RUNTIME ); @@ -108,7 +108,7 @@ public class ShidToPatioGc { private static final PatioFunctionDeclaration PUSH_GC_ROOT = new PatioFunctionDeclaration( "shed__runtime__gc_push_root", List.of(PatioLocal.param("gc_root", ShidToPatioTypes.VALUE_TYPE)), - PatioTypes.VOID, + List.of(), Sources.RUNTIME ); @@ -132,7 +132,7 @@ public class ShidToPatioGc { private static final PatioFunctionDeclaration INIT = new PatioFunctionDeclaration( "shed__runtime__gc_init", List.of(), - PatioTypes.VOID, + List.of(), Sources.RUNTIME ); @@ -158,7 +158,7 @@ public class ShidToPatioGc { PatioLocal.param("size", PatioTypes.INT), PatioLocal.param("runtime_type_tag", PatioTypes.INT32) ), - PatioTypes.DATA_PTR, + List.of(PatioTypes.DATA_PTR), Sources.RUNTIME ); @@ -220,7 +220,7 @@ public class ShidToPatioGc { private static final PatioFunctionDeclaration COLLECT = new PatioFunctionDeclaration( "shed__runtime__gc_collect", List.of(), - PatioTypes.VOID, + List.of(), Sources.RUNTIME ); @@ -282,7 +282,7 @@ public class ShidToPatioGc { private static final PatioFunctionDeclaration CLEAR = new PatioFunctionDeclaration( "shed__runtime__gc_clear", List.of(), - PatioTypes.VOID, + List.of(), Sources.RUNTIME ); diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioInts.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioInts.java index 7d9e97c8..5a73eb2e 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioInts.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioInts.java @@ -21,7 +21,7 @@ public class ShidToPatioInts { List.of( PatioLocal.param("value", PatioTypes.INT) ), - ShidToPatioTypes.VALUE_TYPE, + List.of(ShidToPatioTypes.VALUE_TYPE), Sources.RUNTIME ); @@ -31,7 +31,7 @@ public class ShidToPatioInts { PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE), PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE) ), - ShidToPatioTypes.VALUE_TYPE, + List.of(ShidToPatioTypes.VALUE_TYPE), Sources.RUNTIME ); @@ -41,7 +41,7 @@ public class ShidToPatioInts { PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE), PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE) ), - ShidToPatioTypes.VALUE_TYPE, + List.of(ShidToPatioTypes.VALUE_TYPE), Sources.RUNTIME ); @@ -51,7 +51,7 @@ public class ShidToPatioInts { PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE), PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE) ), - ShidToPatioTypes.VALUE_TYPE, + List.of(ShidToPatioTypes.VALUE_TYPE), Sources.RUNTIME ); @@ -61,7 +61,7 @@ public class ShidToPatioInts { PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE), PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE) ), - PatioTypes.BOOL, + List.of(PatioTypes.BOOL), Sources.RUNTIME ); @@ -71,7 +71,7 @@ public class ShidToPatioInts { PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE), PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE) ), - PatioTypes.BOOL, + List.of(PatioTypes.BOOL), Sources.RUNTIME ); @@ -81,7 +81,7 @@ public class ShidToPatioInts { PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE), PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE) ), - PatioTypes.BOOL, + List.of(PatioTypes.BOOL), Sources.RUNTIME ); @@ -91,7 +91,7 @@ public class ShidToPatioInts { PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE), PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE) ), - PatioTypes.BOOL, + List.of(PatioTypes.BOOL), Sources.RUNTIME ); @@ -101,7 +101,7 @@ public class ShidToPatioInts { PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE), PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE) ), - PatioTypes.BOOL, + List.of(PatioTypes.BOOL), Sources.RUNTIME ); @@ -111,7 +111,7 @@ public class ShidToPatioInts { PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE), PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE) ), - PatioTypes.BOOL, + List.of(PatioTypes.BOOL), Sources.RUNTIME ); diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioNamespaces.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioNamespaces.java index 0ceafc56..e32a760b 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioNamespaces.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioNamespaces.java @@ -83,7 +83,7 @@ public class ShidToPatioNamespaces { context = context.createFunction( globalNameNamespaceInit(namespaceName), PatioVisibility.PRIVATE, - PatioTypes.VOID, + List.of(), source, initContext -> { var namespaceValueResult = initContext.allocateVal( @@ -118,7 +118,7 @@ public class ShidToPatioNamespaces { source )); - initContext = initContext.addInstruction(new PatioReturnVoid(source)); + initContext = initContext.addInstruction(new PatioReturn(List.of(), source)); return initContext; } @@ -127,7 +127,7 @@ public class ShidToPatioNamespaces { context = context.createFunction( globalNameNamespaceImport(namespaceName), PatioVisibility.PUBLIC, - NAMESPACE_VALUE_TYPE, + List.of(NAMESPACE_VALUE_TYPE), source, importContext -> { var isInitedResult = importContext.allocateVal( @@ -197,7 +197,7 @@ public class ShidToPatioNamespaces { )); importContext = importContext.addInstruction(new PatioReturn( - namespaceValue, + List.of(namespaceValue), source )); @@ -217,7 +217,7 @@ public class ShidToPatioNamespaces { context = context.addCompilationUnitElement(new PatioFunctionDeclaration( globalNameNamespaceImport(namespaceName), List.of(), - NAMESPACE_VALUE_TYPE, + List.of(NAMESPACE_VALUE_TYPE), source )); diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioStrings.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioStrings.java index 1bf51582..b4b64cf2 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioStrings.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioStrings.java @@ -27,7 +27,7 @@ public class ShidToPatioStrings { PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE), PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE) ), - ShidToPatioTypes.VALUE_TYPE, + List.of(ShidToPatioTypes.VALUE_TYPE), Sources.RUNTIME ); diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioStructs.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioStructs.java index 4996b89b..5358a944 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioStructs.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioStructs.java @@ -147,7 +147,7 @@ public class ShidToPatioStructs { source )); - bodyContext = bodyContext.addInstruction(new PatioReturn(value, source)); + bodyContext = bodyContext.addInstruction(new PatioReturn(List.of(value), source)); return bodyContext; }, diff --git a/src/test/java/org/shedlang/compiler/backends/cranelift/PatioToCraneliftAmd64Tests.java b/src/test/java/org/shedlang/compiler/backends/cranelift/PatioToCraneliftAmd64Tests.java index 3d258e0f..f8814ba7 100644 --- a/src/test/java/org/shedlang/compiler/backends/cranelift/PatioToCraneliftAmd64Tests.java +++ b/src/test/java/org/shedlang/compiler/backends/cranelift/PatioToCraneliftAmd64Tests.java @@ -29,7 +29,7 @@ public class PatioToCraneliftAmd64Tests extends PatioExampleTests { "main", PatioVisibility.PUBLIC, List.of(), - PatioTypes.INT32, + List.of(PatioTypes.INT32), List.of( Patio.call( Optional.empty(), diff --git a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java index 8267a13a..eed0e9f3 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java @@ -26,7 +26,6 @@ public abstract class PatioExampleTests { public void intConstCreatesConstantIntValue() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addBodyInstruction(emitInt(Patio.intConst(42))) .addBodyInstruction(Patio.returnVoid()) .build(); @@ -45,7 +44,6 @@ public abstract class PatioExampleTests { public void localsAreStoredByName() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(PatioLocal.val("a", PatioTypes.INT)) .addLocal(PatioLocal.val("b", PatioTypes.INT)) .addBodyInstruction(Patio.localStore(Patio.localRef("a"), Patio.intConst(42))) @@ -76,7 +74,6 @@ public abstract class PatioExampleTests { ); var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.INT)) .addBodyInstruction(Patio.memoryLoad( Patio.localRef("x"), @@ -115,7 +112,6 @@ public abstract class PatioExampleTests { ); var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.INT)) .addBodyInstruction(Patio.memoryLoad( Patio.localRef("x"), @@ -152,7 +148,6 @@ public abstract class PatioExampleTests { ); var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.INT)) .addBodyInstruction(Patio.memoryStore( Patio.dataPtrConst("answer"), @@ -192,7 +187,6 @@ public abstract class PatioExampleTests { ); var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.INT)) .addBodyInstruction(Patio.memoryLoad( Patio.localRef("x"), @@ -226,7 +220,6 @@ public abstract class PatioExampleTests { Patio.localRef("x"), Patio.dataPtrConst(Patio.dataPtrValueNull()) )) - .withReturnType(PatioTypes.VOID) .addBodyInstruction(Patio.returnVoid()) .build(); var patio = Patio.compilationUnit(List.of( @@ -248,7 +241,6 @@ public abstract class PatioExampleTests { ); var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.INT)) .addLocal(Patio.val("ptr_int", PatioTypes.INT)) .addLocal(Patio.val("ptr", PatioTypes.DATA_PTR)) @@ -281,7 +273,6 @@ public abstract class PatioExampleTests { public void blockSingleResult() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.INT)) .addBodyInstruction(Patio.block( List.of( @@ -308,7 +299,6 @@ public abstract class PatioExampleTests { public void blockMultipleResults() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.INT)) .addLocal(Patio.val("y", PatioTypes.INT)) .addBodyInstruction(Patio.block( @@ -342,7 +332,6 @@ public abstract class PatioExampleTests { public void ifCanHaveOneResult() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.INT)) .addBodyInstruction(Patio.if_( List.of(Patio.localRef("x")), @@ -366,7 +355,6 @@ public abstract class PatioExampleTests { public void ifCanHaveMultipleResults() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.INT)) .addLocal(Patio.val("y", PatioTypes.INT)) .addBodyInstruction(Patio.if_( @@ -393,7 +381,6 @@ public abstract class PatioExampleTests { public void loopRunsUntilEndIsReachedWithoutContinue() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("c", PatioTypes.BOOL)) .addLocal(Patio.var("x_var", PatioTypes.INT)) .addLocal(Patio.val("x_current", PatioTypes.INT)) @@ -428,7 +415,6 @@ public abstract class PatioExampleTests { public void loopCanExitEarlyWithBreak() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("c", PatioTypes.BOOL)) .addLocal(Patio.var("x_var", PatioTypes.INT)) .addLocal(Patio.val("x_current", PatioTypes.INT)) @@ -464,7 +450,6 @@ public abstract class PatioExampleTests { public void boolToIntToBoolIsIdentityForFalse() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.BOOL)) .addLocal(Patio.val("y", PatioTypes.INT)) .addLocal(Patio.val("z", PatioTypes.BOOL)) @@ -503,7 +488,6 @@ public abstract class PatioExampleTests { public void boolToIntToBoolIsIdentityForTrue() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.BOOL)) .addLocal(Patio.val("y", PatioTypes.INT)) .addLocal(Patio.val("z", PatioTypes.BOOL)) @@ -542,7 +526,6 @@ public abstract class PatioExampleTests { public void intAdd() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.INT)) .addLocal(Patio.val("y", PatioTypes.INT)) .addLocal(Patio.val("z", PatioTypes.INT)) @@ -584,7 +567,6 @@ public abstract class PatioExampleTests { ) throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.INT)) .addLocal(Patio.val("y", PatioTypes.INT)) .addLocal(Patio.val("z_bool", PatioTypes.BOOL)) @@ -631,7 +613,6 @@ public abstract class PatioExampleTests { ) throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.INT)) .addLocal(Patio.val("y", PatioTypes.INT)) .addLocal(Patio.val("z_bool", PatioTypes.BOOL)) @@ -669,7 +650,6 @@ public abstract class PatioExampleTests { public void intSub() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.INT)) .addLocal(Patio.val("y", PatioTypes.INT)) .addLocal(Patio.val("z", PatioTypes.INT)) @@ -702,7 +682,6 @@ public abstract class PatioExampleTests { public void switchWithUnreachableDefault() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.INT)) .addLocal(Patio.val("x1", PatioTypes.INT)) .addLocal(Patio.val("x2", PatioTypes.INT)) @@ -750,7 +729,6 @@ public abstract class PatioExampleTests { public void switchWithReachableDefault() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.INT)) .addLocal(Patio.val("x1", PatioTypes.INT)) .addLocal(Patio.val("x2", PatioTypes.INT)) @@ -791,13 +769,12 @@ public abstract class PatioExampleTests { public void canCallFunctionWithoutArgsDefinedInModule() throws IOException, InterruptedException { var calledFunction = PatioFunctionDefinition.builder() .withName("get") - .withReturnType(PatioTypes.INT) + .addReturnType(PatioTypes.INT) .addBodyInstruction(Patio.return_(Patio.intConst(42))) .build(); var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.INT)) .addBodyInstruction(Patio.call( Optional.of(Patio.localRef("x")), @@ -821,13 +798,12 @@ public abstract class PatioExampleTests { var calledFunction = PatioFunctionDefinition.builder() .withName("identity") .addLocal(PatioLocal.param("x", PatioTypes.INT)) - .withReturnType(PatioTypes.INT) + .addReturnType(PatioTypes.INT) .addBodyInstruction(Patio.return_(Patio.localRef("x"))) .build(); var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.INT)) .addBodyInstruction(Patio.call( Optional.of(Patio.localRef("x")), @@ -850,13 +826,12 @@ public abstract class PatioExampleTests { public void canCallPointerToFunctionDefinedInModule() throws IOException, InterruptedException { var calledFunction = PatioFunctionDefinition.builder() .withName("get") - .withReturnType(PatioTypes.INT) + .addReturnType(PatioTypes.INT) .addBodyInstruction(Patio.return_(Patio.intConst(42))) .build(); var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.INT)) .addBodyInstruction(Patio.callPointer( Patio.localRef("x"), @@ -879,7 +854,6 @@ public abstract class PatioExampleTests { public void whenExceptionIsNotThrownThenTryReturnsFromBody() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("r1", PatioTypes.INT)) .addLocal(Patio.val("r2", PatioTypes.INT)) .addLocal(Patio.val("e1", PatioTypes.INT)) @@ -920,7 +894,6 @@ public abstract class PatioExampleTests { public void whenExceptionIsThrownThenFirstMatchingExceptionHandlerIsUsed() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("r1", PatioTypes.INT)) .addLocal(Patio.val("r2", PatioTypes.INT)) .addLocal(Patio.val("e1", PatioTypes.INT)) @@ -981,7 +954,6 @@ public abstract class PatioExampleTests { public void multipleCatchClausesCanBeAttachedToSameTry() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("r1", PatioTypes.INT)) .addLocal(Patio.val("r2", PatioTypes.INT)) .addLocal(Patio.val("e1", PatioTypes.INT)) @@ -1033,7 +1005,6 @@ public abstract class PatioExampleTests { public void whenExceptionIsThrownThenExceptionHandlerForOtherExceptionsIsIgnored() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("r1", PatioTypes.INT)) .addLocal(Patio.val("r2", PatioTypes.INT)) .addLocal(Patio.val("e1", PatioTypes.INT)) @@ -1095,7 +1066,6 @@ public abstract class PatioExampleTests { public void catchClauseCanThrow() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("r1", PatioTypes.INT)) .addLocal(Patio.val("r2", PatioTypes.INT)) .addLocal(Patio.val("e1", PatioTypes.INT)) @@ -1158,7 +1128,6 @@ public abstract class PatioExampleTests { public void exceptionHandlerIsDiscardedAfterTry() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("r1", PatioTypes.INT)) .addLocal(Patio.val("r2", PatioTypes.INT)) .addLocal(Patio.val("e1", PatioTypes.INT)) @@ -1218,7 +1187,6 @@ public abstract class PatioExampleTests { public void thrownValueIsPassedToCatchClause() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("r", PatioTypes.INT)) .addLocal(Patio.val("e", PatioTypes.INT)) .addBodyInstruction(Patio.try_( @@ -1259,7 +1227,6 @@ public abstract class PatioExampleTests { public void tryCanHaveMultipleResults() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("r1", PatioTypes.INT)) .addLocal(Patio.val("r2", PatioTypes.INT)) .addLocal(Patio.val("e1", PatioTypes.INT)) @@ -1302,7 +1269,6 @@ public abstract class PatioExampleTests { public void vars() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.var("x", PatioTypes.INT)) .addLocal(Patio.val("y", PatioTypes.INT)) .addLocal(Patio.val("z", PatioTypes.INT)) @@ -1344,7 +1310,6 @@ public abstract class PatioExampleTests { public void canGetByteOffsetOf() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.INT)) .addBodyInstruction(Patio.localStore( Patio.localRef("x"), @@ -1383,7 +1348,6 @@ public abstract class PatioExampleTests { public void canGetByteSizeOf() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) - .withReturnType(PatioTypes.VOID) .addLocal(Patio.val("x", PatioTypes.INT)) .addBodyInstruction(Patio.localStore( Patio.localRef("x"), @@ -1432,7 +1396,6 @@ public abstract class PatioExampleTests { var emitIntDeclaration = PatioFunctionDeclaration.builder() .withName("patio__test__emit_int") .addParam(PatioLocal.param("value", PatioTypes.INT)) - .withReturnType(PatioTypes.VOID) .build(); var result = executeCompilationUnit(new PatioCompilationUnit( diff --git a/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java b/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java index 5cf44a1a..76b336ea 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java @@ -19,7 +19,6 @@ public class PatioSerializerTests { public void canSerializeCompilationUnit() { var element = PatioFunctionDefinition.builder() .withName("f") - .withReturnType(PatioTypes.VOID) .build(); var compilationUnit = Patio.compilationUnit(List.of(element)); @@ -32,7 +31,7 @@ public class PatioSerializerTests { "f" visibility=private locals=() - return-type=void + return-types=() body=( ) ) @@ -106,7 +105,7 @@ public class PatioSerializerTests { .withName("f") .addParam(Patio.param("param1", PatioTypes.INT)) .addParam(Patio.param("param2", PatioTypes.DATA_PTR)) - .withReturnType(PatioTypes.VOID) + .addReturnType(PatioTypes.INT32) .build(); var string = PatioTesting.serializeCompilationUnitElement(element); @@ -116,7 +115,7 @@ public class PatioSerializerTests { function-decl "f" params=((param "param1" int) (param "param2" data-ptr)) - return-type=void + return-types=(int32) )""" )); } @@ -130,7 +129,7 @@ public class PatioSerializerTests { .addLocal(Patio.param("param2", PatioTypes.DATA_PTR)) .addLocal(Patio.val("local1", PatioTypes.FUNCTION_PTR)) .addLocal(Patio.val("local2", PatioTypes.INT)) - .withReturnType(PatioTypes.VOID) + .addReturnType(PatioTypes.INT32) .addBodyInstruction(Patio.localStore(Patio.localRef("local2"), Patio.intConst(2))) .build(); @@ -142,7 +141,7 @@ public class PatioSerializerTests { "f" visibility=private locals=((param "param1" int) (param "param2" data-ptr) (val "local1" function-ptr) (val "local2" int)) - return-type=void + return-types=(int32) body=( (local-store (local "local2") (int-const 2)) ) @@ -479,16 +478,7 @@ public class PatioSerializerTests { var string = PatioTesting.serializeInstruction(instruction); - assertThat(string, equalTo("(return (local \"value\"))")); - } - - @Test - public void canSerializeReturnVoid() { - var instruction = Patio.returnVoid(); - - var string = PatioTesting.serializeInstruction(instruction); - - assertThat(string, equalTo("(return-void)")); + assertThat(string, equalTo("(return ((local \"value\")))")); } @Test @@ -889,15 +879,6 @@ public class PatioSerializerTests { assertThat(string, equalTo("int32")); } - @Test - public void canSerializeVoidType() { - var type = PatioTypes.VOID; - - var string = PatioTesting.serializeType(type); - - assertThat(string, equalTo("void")); - } - // == Data layouts == @Test diff --git a/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java b/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java index 5bdd24df..0c0de429 100644 --- a/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java +++ b/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java @@ -299,11 +299,11 @@ public class Patio { } public static PatioInstruction return_(PatioOperand value) { - return new PatioReturn(value, Sources.NULL); + return new PatioReturn(List.of(value), Sources.NULL); } public static PatioInstruction returnVoid() { - return new PatioReturnVoid(Sources.NULL); + return new PatioReturn(List.of(), Sources.NULL); } public static PatioInstruction switch_( 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 be71c7ce..2f2990bb 100644 --- a/src/test/java/org/shedlang/compiler/patio/serialization/PatioSerializationTests.java +++ b/src/test/java/org/shedlang/compiler/patio/serialization/PatioSerializationTests.java @@ -28,7 +28,6 @@ public abstract class PatioSerializationTests { public void canSerializeCompilationUnit() { var element = PatioFunctionDefinition.builder() .withName("f") - .withReturnType(PatioTypes.VOID) .build(); var compilationUnit = Patio.compilationUnit(List.of(element)); @@ -112,7 +111,7 @@ public abstract class PatioSerializationTests { .withName("f") .addParam(Patio.param("param1", PatioTypes.INT)) .addParam(Patio.param("param2", PatioTypes.DATA_PTR)) - .withReturnType(PatioTypes.VOID) + .addReturnType(PatioTypes.INT32) .build(); var deserializedElement = deserializeCompilationUnitElement( @@ -132,7 +131,7 @@ public abstract class PatioSerializationTests { .addLocal(Patio.param("param2", PatioTypes.DATA_PTR)) .addLocal(Patio.val("local1", PatioTypes.FUNCTION_PTR)) .addLocal(Patio.val("local2", PatioTypes.INT)) - .withReturnType(PatioTypes.VOID) + .addReturnType(PatioTypes.INT32) .addBodyInstruction(Patio.localStore(Patio.localRef("local2"), Patio.intConst(2))) .build(); @@ -868,17 +867,6 @@ public abstract class PatioSerializationTests { assertThat(deserializedType, equalTo(type)); } - @Test - public void canSerializeVoidType() { - var type = PatioTypes.VOID; - - var deserializedType = deserializeType( - serializeType(type) - ); - - assertThat(deserializedType, equalTo(type)); - } - // == Data layouts == protected abstract PatioDataLayout deserializeDataLayout(byte[] buffer); |
