kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

commit 8fb0cbbf0d0cd9cd03e25e9de96c8edfa3576a56
parent 88093f7a2ed4025863be2de9409e7f42934cedee
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Wed, 20 May 2026 13:28:10 -0700

test/toy: wrap i64 main with i32 thunk; drop -Wno-main-return-type

Every cases/*.toy fixture had `fn main(): i64`, which the C target
emits as `int64_t main(void)` — accepted only under
-Wno-main-return-type. Switch to a uniform pattern:

  fn __user_main(): i64 { <original body> }
  fn main(): i32 { return __user_main() as i32; }

The wrapper is mechanical, sidesteps toy's lack of implicit i64→i32
narrowing at return, and works for every body shape (including
control-expression returns and tail calls). Native exit codes are
unchanged (the OS takes the low byte either way).

Path-C host-cc invocation now runs under -Wall -Wextra -Werror with
no relax flags. 124/124 path-C toy cases pass; full suite still
610/610.

Diffstat:
Mtest/toy/cases/01_return_const.toy | 4+++-
Mtest/toy/cases/02_arith_precedence.toy | 4+++-
Mtest/toy/cases/03_bitwise_shift.toy | 4+++-
Mtest/toy/cases/04_cmp_values.toy | 4+++-
Mtest/toy/cases/05_if_else.toy | 4+++-
Mtest/toy/cases/06_while_sum.toy | 4+++-
Mtest/toy/cases/07_break_continue.toy | 4+++-
Mtest/toy/cases/08_recursion_fib.toy | 4+++-
Mtest/toy/cases/09_function_params.toy | 4+++-
Mtest/toy/cases/100_record_data_relocation.toy | 4+++-
Mtest/toy/cases/101_extern_threadlocal_decls.toy | 4+++-
Mtest/toy/cases/102_typed_asm_operands.toy | 4+++-
Mtest/toy/cases/103_return_control_expressions.toy | 4+++-
Mtest/toy/cases/104_typed_asm_clobber_abi.toy | 4+++-
Mtest/toy/cases/105_typed_asm_record_outputs.toy | 4+++-
Mtest/toy/cases/106_forward_record_pointer_field_access.toy | 4+++-
Mtest/toy/cases/107_forward_record_pointer_field_store_call.toy | 4+++-
Mtest/toy/cases/108_typed_asm_named_inputs.toy | 4+++-
Mtest/toy/cases/109_typed_asm_omitted_groups.toy | 4+++-
Mtest/toy/cases/10_pointer_addr_deref.toy | 4+++-
Mtest/toy/cases/110_typed_asm_named_outputs.toy | 4+++-
Mtest/toy/cases/111_many_function_params.toy | 4+++-
Mtest/toy/cases/112_many_function_type_params.toy | 4+++-
Mtest/toy/cases/113_many_record_fields.toy | 4+++-
Mtest/toy/cases/114_many_tuple_fields.toy | 4+++-
Mtest/toy/cases/115_many_anonymous_record_fields.toy | 4+++-
Mtest/toy/cases/116_many_global_record_fields.toy | 4+++-
Mtest/toy/cases/117_forward_record_pointer_cast_source.toy | 4+++-
Mtest/toy/cases/117_many_enum_values.toy | 4+++-
Mtest/toy/cases/118_decl_extra_attrs.toy | 4+++-
Mtest/toy/cases/118_many_enum_switch_values.toy | 4+++-
Mtest/toy/cases/119_static_labeladdr_data.toy | 4+++-
Mtest/toy/cases/119_switch_strategy_hints.toy | 4+++-
Mtest/toy/cases/11_global_mutation.toy | 4+++-
Mtest/toy/cases/120_data_symdiff.toy | 4+++-
Mtest/toy/cases/121_dynamic_memory_builtin.toy | 4+++-
Mtest/toy/cases/122_data_entsize.toy | 4+++-
Mtest/toy/cases/123_spec_demo.toy | 4+++-
Mtest/toy/cases/124_slices.toy | 4+++-
Mtest/toy/cases/12_short_circuit_and_skip.toy | 4+++-
Mtest/toy/cases/13_short_circuit_or_skip.toy | 4+++-
Mtest/toy/cases/14_pointer_param.toy | 4+++-
Mtest/toy/cases/15_cg_api_types_bytes_globals.toy | 4+++-
Mtest/toy/cases/16_cg_api_memory_index.toy | 4+++-
Mtest/toy/cases/17_cg_api_atomics_intrinsics.toy | 4+++-
Mtest/toy/cases/18_cg_api_field_tail.toy | 4+++-
Mtest/toy/cases/19_cg_api_variadic_asm.toy | 4+++-
Mtest/toy/cases/20_cg_api_inline_asm_full.toy | 4+++-
Mtest/toy/cases/21_cg_api_scalar_type_queries.toy | 4+++-
Mtest/toy/cases/22_cg_api_typed_atomics_bits.toy | 4+++-
Mtest/toy/cases/23_cg_api_typed_varargs.toy | 4+++-
Mtest/toy/cases/24_tail_arg_permute.toy | 4+++-
Mtest/toy/cases/25_tail_many_stack_args.toy | 4+++-
Mtest/toy/cases/26_tail_live_pressure.toy | 4+++-
Mtest/toy/cases/27_tail_mixed_int_fp.toy | 4+++-
Mtest/toy/cases/28_tail_chain.toy | 4+++-
Mtest/toy/cases/29_tail_cross_arch_stack.toy | 4+++-
Mtest/toy/cases/30_tail_indirect_wanted.toy | 4+++-
Mtest/toy/cases/31_fn_pointer_call.toy | 4+++-
Mtest/toy/cases/32_inference_null_postfix.toy | 4+++-
Mtest/toy/cases/33_array_literal_index.toy | 4+++-
Mtest/toy/cases/34_record_literal_field.toy | 4+++-
Mtest/toy/cases/35_string_global_data.toy | 4+++-
Mtest/toy/cases/36_tuple_record_literal.toy | 4+++-
Mtest/toy/cases/37_enum_dot_constant.toy | 4+++-
Mtest/toy/cases/38_declarations_alias_extern.toy | 4+++-
Mtest/toy/cases/39_pointer_to_array_index.toy | 4+++-
Mtest/toy/cases/40_alloca_memmove.toy | 4+++-
Mtest/toy/cases/41_if_expression.toy | 4+++-
Mtest/toy/cases/42_switch_expression.toy | 4+++-
Mtest/toy/cases/43_while_expression_break.toy | 4+++-
Mtest/toy/cases/44_attribute_syntax.toy | 4+++-
Mtest/toy/cases/45_qual_addrspace_types.toy | 4+++-
Mtest/toy/cases/46_static_local.toy | 4+++-
Mtest/toy/cases/47_target_arch_switch.toy | 4+++-
Mtest/toy/cases/48_supports_callconv.toy | 4+++-
Mtest/toy/cases/49_typed_asm_void.toy | 4+++-
Mtest/toy/cases/50_switch_statement.toy | 4+++-
Mtest/toy/cases/51_labeladdr_goto.toy | 4+++-
Mtest/toy/cases/52_global_array_data.toy | 4+++-
Mtest/toy/cases/53_conversion_builtins.toy | 4+++-
Mtest/toy/cases/54_scalar_intrinsics.toy | 4+++-
Mtest/toy/cases/55_block_scope_shadow.toy | 4+++-
Mtest/toy/cases/56_i128_scalar.toy | 4+++-
Mtest/toy/cases/57_string_escapes.toy | 4+++-
Mtest/toy/cases/58_overflow_record.toy | 4+++-
Mtest/toy/cases/59_atomic_cmpxchg_record.toy | 4+++-
Mtest/toy/cases/60_atomic_queries.toy | 4+++-
Mtest/toy/cases/61_labeled_loop.toy | 4+++-
Mtest/toy/cases/62_decl_data_attrs.toy | 4+++-
Mtest/toy/cases/63_memory_flags.toy | 4+++-
Mtest/toy/cases/64_target_feature_queries.toy | 4+++-
Mtest/toy/cases/65_rounding_conversions.toy | 4+++-
Mtest/toy/cases/66_anonymous_record_type.toy | 4+++-
Mtest/toy/cases/67_abi_attrs.toy | 4+++-
Mtest/toy/cases/68_field_attrs.toy | 4+++-
Mtest/toy/cases/69_if_value_block_statements.toy | 4+++-
Mtest/toy/cases/70_labeled_switch_break.toy | 4+++-
Mtest/toy/cases/71_forward_records.toy | 4+++-
Mtest/toy/cases/72_global_record_data.toy | 4+++-
Mtest/toy/cases/73_atomic_access_group.toy | 4+++-
Mtest/toy/cases/74_atomic_rmw_access.toy | 4+++-
Mtest/toy/cases/75_atomic_cmpxchg_access.toy | 4+++-
Mtest/toy/cases/76_atomic_query_access.toy | 4+++-
Mtest/toy/cases/77_atomic_keyword_ops.toy | 4+++-
Mtest/toy/cases/78_null_expected_pointer.toy | 4+++-
Mtest/toy/cases/79_enum_argument_context.toy | 4+++-
Mtest/toy/cases/80_enum_switch_labels.toy | 4+++-
Mtest/toy/cases/81_global_float_data.toy | 4+++-
Mtest/toy/cases/82_unreachable_builtin.toy | 4+++-
Mtest/toy/cases/83_pointer_field_access.toy | 4+++-
Mtest/toy/cases/84_field_assignment.toy | 4+++-
Mtest/toy/cases/85_packed_record_attr.toy | 4+++-
Mtest/toy/cases/86_address_of_field.toy | 4+++-
Mtest/toy/cases/87_expect_preserves_type.toy | 4+++-
Mtest/toy/cases/88_scalar_intrinsic_preserves_type.toy | 4+++-
Mtest/toy/cases/89_labeled_while_expression.toy | 4+++-
Mtest/toy/cases/90_continue_through_switch.toy | 4+++-
Mtest/toy/cases/91_exhaustive_enum_switch_expression.toy | 4+++-
Mtest/toy/cases/92_parenthesized_precedence_islands.toy | 4+++-
Mtest/toy/cases/93_data_pad_align.toy | 4+++-
Mtest/toy/cases/94_restrict_pointer_type.toy | 4+++-
Mtest/toy/cases/95_static_local_string_data.toy | 4+++-
Mtest/toy/cases/96_data_relocations.toy | 4+++-
Mtest/toy/cases/97_let_pointer_pointee_assignment.toy | 4+++-
Mtest/toy/cases/98_tuple_offsetof.toy | 4+++-
Mtest/toy/cases/99_global_tuple_data.toy | 4+++-
Mtest/toy/run.sh | 13++++++-------
128 files changed, 387 insertions(+), 134 deletions(-)

diff --git a/test/toy/cases/01_return_const.toy b/test/toy/cases/01_return_const.toy @@ -1,3 +1,5 @@ -fn main(): i64 { +fn __user_main(): i64 { return 7; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/02_arith_precedence.toy b/test/toy/cases/02_arith_precedence.toy @@ -1,3 +1,5 @@ -fn main(): i64 { +fn __user_main(): i64 { return 1 + 2 * 3 - 4 / 2 + 5 % 3; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/03_bitwise_shift.toy b/test/toy/cases/03_bitwise_shift.toy @@ -1,3 +1,5 @@ -fn main(): i64 { +fn __user_main(): i64 { return ((5 & 3) | (8 >> 1)) ^ (1 << 3); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/04_cmp_values.toy b/test/toy/cases/04_cmp_values.toy @@ -1,3 +1,5 @@ -fn main(): i64 { +fn __user_main(): i64 { return (1 < 2) + (2 <= 2) * 2 + (3 > 4) * 4 + (5 != 6) * 8; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/05_if_else.toy b/test/toy/cases/05_if_else.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { var x: i64 = 3; if x > 2 { x = x + 4; @@ -7,3 +7,5 @@ fn main(): i64 { } return x; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/06_while_sum.toy b/test/toy/cases/06_while_sum.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { var i: i64 = 0; var s: i64 = 0; while i < 6 { @@ -7,3 +7,5 @@ fn main(): i64 { } return s; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/07_break_continue.toy b/test/toy/cases/07_break_continue.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { var i: i64 = 0; var s: i64 = 0; while i < 10 { @@ -13,3 +13,5 @@ fn main(): i64 { } return s; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/08_recursion_fib.toy b/test/toy/cases/08_recursion_fib.toy @@ -5,6 +5,8 @@ fn fib(n: i64): i64 { return fib(n - 1) + fib(n - 2); } -fn main(): i64 { +fn __user_main(): i64 { return fib(7); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/09_function_params.toy b/test/toy/cases/09_function_params.toy @@ -2,6 +2,8 @@ fn mix(a: i64, b: i64, c: i64): i64 { return a * 10 + b * 3 - c; } -fn main(): i64 { +fn __user_main(): i64 { return mix(4, 5, 6); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/100_record_data_relocation.toy b/test/toy/cases/100_record_data_relocation.toy @@ -6,6 +6,8 @@ record RelRec { pub let target_value: i32 = 42; pub let rec: RelRec = RelRec { off: @pcrel(target_value, 0), tag: 7 }; -fn main(): i64 { +fn __user_main(): i64 { return 42; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/101_extern_threadlocal_decls.toy b/test/toy/cases/101_extern_threadlocal_decls.toy @@ -1,6 +1,8 @@ extern let ro_table: *u8; extern var @[.threadlocal, .tls_model(.local_exec)] errno_tls: i32; -fn main(): i64 { +fn __user_main(): i64 { return 42; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/102_typed_asm_operands.toy b/test/toy/cases/102_typed_asm_operands.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { let value: i64 = @asm<i64>( "", outputs(inout("+r", 42)), @@ -9,3 +9,5 @@ fn main(): i64 { @asm<void>("", outputs(), inputs(in("r", 19), in("r", 23))); return value; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/103_return_control_expressions.toy b/test/toy/cases/103_return_control_expressions.toy @@ -30,6 +30,8 @@ fn from_while(): i64 { }; } -fn main(): i64 { +fn __user_main(): i64 { return from_if(1) + from_switch(1) + from_while(); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/104_typed_asm_clobber_abi.toy b/test/toy/cases/104_typed_asm_clobber_abi.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { @asm<void>( "", outputs(), @@ -8,3 +8,5 @@ fn main(): i64 { ); return 42; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/105_typed_asm_record_outputs.toy b/test/toy/cases/105_typed_asm_record_outputs.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { return @asm<record { lo: i64, hi: i64 }>( "", outputs(inout("+r", 20), inout("+r", 22)), @@ -7,3 +7,5 @@ fn main(): i64 { flags(.volatile) ).hi; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/106_forward_record_pointer_field_access.toy b/test/toy/cases/106_forward_record_pointer_field_access.toy @@ -9,8 +9,10 @@ record B { value: i64, } -fn main(): i64 { +fn __user_main(): i64 { let b: B = B { value: 42 }; let a: A = A { b: &b }; return a.b.value; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/107_forward_record_pointer_field_store_call.toy b/test/toy/cases/107_forward_record_pointer_field_store_call.toy @@ -13,9 +13,11 @@ fn read_b(b: *B): i64 { return b.value; } -fn main(): i64 { +fn __user_main(): i64 { let b: B = B { value: 42 }; var a: A = A {}; a.b = &b; return read_b(a.b); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/108_typed_asm_named_inputs.toy b/test/toy/cases/108_typed_asm_named_inputs.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { @asm<void>( "", outputs(), @@ -8,3 +8,5 @@ fn main(): i64 { ); return 42; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/109_typed_asm_omitted_groups.toy b/test/toy/cases/109_typed_asm_omitted_groups.toy @@ -1,4 +1,6 @@ -fn main(): i64 { +fn __user_main(): i64 { @asm<void>("", outputs()); return 0; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/10_pointer_addr_deref.toy b/test/toy/cases/10_pointer_addr_deref.toy @@ -1,5 +1,7 @@ -fn main(): i64 { +fn __user_main(): i64 { let x: i64 = 21; let p: *i64 = &x; return p.* + 1; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/110_typed_asm_named_outputs.toy b/test/toy/cases/110_typed_asm_named_outputs.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { let pair = @asm<record { lo: i64, hi: i64 }>( "", outputs(hi = inout("+r", 20), lo = inout("+r", 22)) @@ -6,3 +6,5 @@ fn main(): i64 { @asm<void>("", outputs(), inputs(in("r", pair.lo), in("r", pair.hi))); return 0; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/111_many_function_params.toy b/test/toy/cases/111_many_function_params.toy @@ -8,7 +8,9 @@ fn sum18( a12 + a13 + a14 + a15 + a16 + a17; } -fn main(): i64 { +fn __user_main(): i64 { return sum18(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/112_many_function_type_params.toy b/test/toy/cases/112_many_function_type_params.toy @@ -8,7 +8,7 @@ fn sum18( a12 + a13 + a14 + a15 + a16 + a17; } -fn main(): i64 { +fn __user_main(): i64 { let fp: *fn( i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, @@ -17,3 +17,5 @@ fn main(): i64 { return fp(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/113_many_record_fields.toy b/test/toy/cases/113_many_record_fields.toy @@ -4,7 +4,7 @@ record Many { f12: i64, f13: i64, f14: i64, f15: i64, f16: i64, f17: i64, } -fn main(): i64 { +fn __user_main(): i64 { let m: Many = Many { f0: 1, f1: 2, f2: 3, f3: 4, f4: 5, f5: 6, f6: 7, f7: 8, f8: 9, f9: 10, f10: 11, f11: 12, @@ -12,3 +12,5 @@ fn main(): i64 { }; return m.f17; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/114_many_tuple_fields.toy b/test/toy/cases/114_many_tuple_fields.toy @@ -4,7 +4,7 @@ tuple ManyTuple { i64, i64, i64, i64, i64, i64, } -fn main(): i64 { +fn __user_main(): i64 { let t: ManyTuple = ManyTuple { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, @@ -12,3 +12,5 @@ fn main(): i64 { }; return t.17; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/115_many_anonymous_record_fields.toy b/test/toy/cases/115_many_anonymous_record_fields.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { let r: record { f0: i64, f1: i64, f2: i64, f3: i64, f4: i64, f5: i64, f6: i64, f7: i64, f8: i64, f9: i64, f10: i64, f11: i64, @@ -10,3 +10,5 @@ fn main(): i64 { }; return r.f17; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/116_many_global_record_fields.toy b/test/toy/cases/116_many_global_record_fields.toy @@ -10,6 +10,8 @@ let global_many: ManyGlobal = ManyGlobal { f12: 13, f13: 14, f14: 15, f15: 16, f16: 17, f17: 18, }; -fn main(): i64 { +fn __user_main(): i64 { return global_many.f17; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/117_forward_record_pointer_cast_source.toy b/test/toy/cases/117_forward_record_pointer_cast_source.toy @@ -5,8 +5,10 @@ fn takes_a(p: *A): i64 { return p == NULL as *A; } -fn main(): i64 { +fn __user_main(): i64 { let b: *B = NULL as *B; let a: *A = @bitcast<*A>(b); return takes_a(a) - 1; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/117_many_enum_values.toy b/test/toy/cases/117_many_enum_values.toy @@ -7,7 +7,9 @@ enum Big: i64 { .v30 = 30, .v31 = 31, .v32 = 32, .v33 = 33, } -fn main(): i64 { +fn __user_main(): i64 { let b: Big = .v33; return b as i64; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/118_decl_extra_attrs.toy b/test/toy/cases/118_decl_extra_attrs.toy @@ -21,6 +21,8 @@ extern var @[.threadlocal, .tls_model(.general_dynamic)] tls_general_dynamic: i3 pub let @[.section(".rodata.toy.merge"), .retain, .merge, .strings, .entsize(1)] merged_string: [4]i8 = "toy\0"; -fn main(): i64 { +fn __user_main(): i64 { return (merged_string[0] as i64) - 116; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/118_many_enum_switch_values.toy b/test/toy/cases/118_many_enum_switch_values.toy @@ -18,6 +18,8 @@ fn pick(b: BigSwitch): i64 { }; } -fn main(): i64 { +fn __user_main(): i64 { return pick(.v33); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/119_static_labeladdr_data.toy b/test/toy/cases/119_static_labeladdr_data.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { label zero; label one; @@ -15,3 +15,5 @@ zero: one: return 0; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/119_switch_strategy_hints.toy b/test/toy/cases/119_switch_strategy_hints.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { var out: i64 = 0; switch @[.branch_chain, .jump_table] 1 { 0 { @@ -10,3 +10,5 @@ fn main(): i64 { } return out; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/11_global_mutation.toy b/test/toy/cases/11_global_mutation.toy @@ -1,6 +1,8 @@ var g: i64; -fn main(): i64 { +fn __user_main(): i64 { g = 4; return g + 2; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/120_data_symdiff.toy b/test/toy/cases/120_data_symdiff.toy @@ -3,6 +3,8 @@ pub let symdiff_end: i64 = 0; pub let array_diff: [1]i64 = [@symdiff(symdiff_end, symdiff_start, 0)]; -fn main(): i64 { +fn __user_main(): i64 { return 0; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/121_dynamic_memory_builtin.toy b/test/toy/cases/121_dynamic_memory_builtin.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { let src: *i64 = @alloca<i64>(2, 8); let dst: *i64 = @alloca<i64>(2, 8); let n: i64 = 16; @@ -15,3 +15,5 @@ fn main(): i64 { return dst[0] + src[1]; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/122_data_entsize.toy b/test/toy/cases/122_data_entsize.toy @@ -2,6 +2,8 @@ pub let @[.section(".rodata.cfree.merge"), .align(1), .readonly, .merge, .strings, .entsize(1)] merge_string: [4]u8 = "toy\0"; -fn main(): i64 { +fn __user_main(): i64 { return 0; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/123_spec_demo.toy b/test/toy/cases/123_spec_demo.toy @@ -301,7 +301,7 @@ done: return out; } -fn main(): Word { +fn __user_main(): Word { let fp: *Fn1 = &add1; var local_pair: Pair = Pair { a: 12, b: 30 }; var node: Node = Node { value: 8 }; @@ -374,3 +374,5 @@ fn main(): Word { return 42; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/124_slices.toy b/test/toy/cases/124_slices.toy @@ -2,7 +2,7 @@ fn sum(xs: []i64): i64 { return xs[0] + xs[1] + xs.len; } -fn main(): i64 { +fn __user_main(): i64 { var xs: [5]i64 = [10, 20, 30, 40, 50]; let sl_tail: []i64 = xs[1:4]; let mid: []i64 = sl_tail[1:3]; @@ -11,3 +11,5 @@ fn main(): i64 { moving = mid; return sum(moving) + sl_tail.ptr[2] - 10; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/12_short_circuit_and_skip.toy b/test/toy/cases/12_short_circuit_and_skip.toy @@ -5,9 +5,11 @@ fn set_g(): i64 { return 1; } -fn main(): i64 { +fn __user_main(): i64 { if 0 and set_g() { g = 5; } return g; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/13_short_circuit_or_skip.toy b/test/toy/cases/13_short_circuit_or_skip.toy @@ -5,9 +5,11 @@ fn set_g(): i64 { return 1; } -fn main(): i64 { +fn __user_main(): i64 { if 1 or set_g() { g = g + 0; } return g; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/14_pointer_param.toy b/test/toy/cases/14_pointer_param.toy @@ -2,7 +2,9 @@ fn read(p: *i64): i64 { return p.*; } -fn main(): i64 { +fn __user_main(): i64 { let x: i64 = 33; return read(&x); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/15_cg_api_types_bytes_globals.toy b/test/toy/cases/15_cg_api_types_bytes_globals.toy @@ -1,6 +1,8 @@ let g: i64 = 5; var gp: *i64 = &g; -fn main(): i64 { +fn __user_main(): i64 { return 40 + 42 + g + gp.*; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/16_cg_api_memory_index.toy b/test/toy/cases/16_cg_api_memory_index.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { var a: i64 = 0; var b: i64 = 0; let p: *i64 = &a; @@ -9,3 +9,5 @@ fn main(): i64 { @memcpy(q, p, 8, 8); return q[0]; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/17_cg_api_atomics_intrinsics.toy b/test/toy/cases/17_cg_api_atomics_intrinsics.toy @@ -1,7 +1,9 @@ -fn main(): i64 { +fn __user_main(): i64 { var x: i64 = 0; @atomic_store<i64>(&x, 40, .seq_cst); @atomic_rmw<i64>(.add, &x, 2, .seq_cst); @atomic_fence(.seq_cst); return @atomic_load<i64>(&x, .seq_cst); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/18_cg_api_field_tail.toy b/test/toy/cases/18_cg_api_field_tail.toy @@ -11,9 +11,11 @@ fn id(x: i64): i64 { return tail id2(x); } -fn main(): i64 { +fn __user_main(): i64 { var p: FieldPair = FieldPair {}; p.b = 42; @asm<void>("", outputs(), inputs()); return p.b + id(0); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/19_cg_api_variadic_asm.toy b/test/toy/cases/19_cg_api_variadic_asm.toy @@ -17,7 +17,7 @@ fn sum_first(n: i64, ...): i64 { return s + first; } -fn main(): i64 { +fn __user_main(): i64 { var v: i64 = @asm<i64>( "", outputs(inout("+r", 42)), @@ -31,3 +31,5 @@ fn main(): i64 { s = sum_first(3, 5, 6, 7); return s + v; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/20_cg_api_inline_asm_full.toy b/test/toy/cases/20_cg_api_inline_asm_full.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { let slot: i64 = 31; var imm: i64 = @asm<i64>( @@ -51,3 +51,5 @@ fn main(): i64 { return imm + mem + inout + early + memory + clobber; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/21_cg_api_scalar_type_queries.toy b/test/toy/cases/21_cg_api_scalar_type_queries.toy @@ -7,10 +7,12 @@ fn half(x: f64): f64 { return x / 2.0; } -fn main(): i64 { +fn __user_main(): i64 { let small: i32 = 42 as i32; let wide: i64 = small as i64; let f: f64 = half(9.0); return wide + (f as i64) + @sizeof<i16>() + @alignof<i64>() + @sizeof<[3]i32>() + @offsetof<Pair>(b); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/22_cg_api_typed_atomics_bits.toy b/test/toy/cases/22_cg_api_typed_atomics_bits.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { var x: i64 = 0; @atomic_store<i64>(&x, 10, .seq_cst); let prev: i64 = @atomic_rmw<i64>(.add, &x, 5, .seq_cst); @@ -6,3 +6,5 @@ fn main(): i64 { @atomic_fence(.seq_cst); return prev + now + @bitget(@bitset(0, 3, 4, 4), 4, 4); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/23_cg_api_typed_varargs.toy b/test/toy/cases/23_cg_api_typed_varargs.toy @@ -6,6 +6,8 @@ fn pick(n: i64, ...): i64 { return first + n; } -fn main(): i64 { +fn __user_main(): i64 { return pick(4, 38); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/24_tail_arg_permute.toy b/test/toy/cases/24_tail_arg_permute.toy @@ -6,6 +6,8 @@ fn caller(x: i64, y: i64, z: i64): i64 { return tail target(z, x, y); } -fn main(): i64 { +fn __user_main(): i64 { return caller(3, 5, 7); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/25_tail_many_stack_args.toy b/test/toy/cases/25_tail_many_stack_args.toy @@ -9,6 +9,8 @@ fn caller(a: i64, b: i64, c: i64, d: i64, e: i64, return tail target(j, i, h, g, f, e, d, c, b, a); } -fn main(): i64 { +fn __user_main(): i64 { return caller(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/26_tail_live_pressure.toy b/test/toy/cases/26_tail_live_pressure.toy @@ -16,6 +16,8 @@ fn pressure(x: i64): i64 { return tail sink(h, f, d, b, g, e, c, a); } -fn main(): i64 { +fn __user_main(): i64 { return pressure(1); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/27_tail_mixed_int_fp.toy b/test/toy/cases/27_tail_mixed_int_fp.toy @@ -6,6 +6,8 @@ fn caller(x: i64, y: f64, z: i64, w: f64): i64 { return tail target(z, w, x, y); } -fn main(): i64 { +fn __user_main(): i64 { return caller(3, 5.0, 7, 11.0); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/28_tail_chain.toy b/test/toy/cases/28_tail_chain.toy @@ -10,6 +10,8 @@ fn f(a: i64, b: i64, c: i64): i64 { return tail g(b, c, a); } -fn main(): i64 { +fn __user_main(): i64 { return f(2, 5, 9); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/29_tail_cross_arch_stack.toy b/test/toy/cases/29_tail_cross_arch_stack.toy @@ -9,6 +9,8 @@ fn caller(a: i64, b: i64, c: i64, d: i64, e: i64, f: i64, return tail target(l, k, j, i, h, g, f, e, d, c, b, a); } -fn main(): i64 { +fn __user_main(): i64 { return caller(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/30_tail_indirect_wanted.toy b/test/toy/cases/30_tail_indirect_wanted.toy @@ -6,6 +6,8 @@ fn apply(fp: *fn(i64): i64, x: i64): i64 { return tail fp(x); } -fn main(): i64 { +fn __user_main(): i64 { return apply(add1, 41); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/31_fn_pointer_call.toy b/test/toy/cases/31_fn_pointer_call.toy @@ -2,8 +2,10 @@ fn add2(x: i64): i64 { return x + 2; } -fn main(): i64 { +fn __user_main(): i64 { let fp: *fn(i64): i64 = add2; let fp2: *fn(i64): i64 = &add2; return fp(20) + fp2(20); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/32_inference_null_postfix.toy b/test/toy/cases/32_inference_null_postfix.toy @@ -2,7 +2,7 @@ fn id(x: i64): i64 { return x; } -fn main(): i64 { +fn __user_main(): i64 { let x = id(40); var y = id(1); y = y + 1; @@ -12,3 +12,5 @@ fn main(): i64 { } return 0; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/33_array_literal_index.toy b/test/toy/cases/33_array_literal_index.toy @@ -1,4 +1,6 @@ -fn main(): i64 { +fn __user_main(): i64 { let xs: [4]i64 = [1, 2]; return xs[0] + xs[1] + xs[2] + xs[3] + 39; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/34_record_literal_field.toy b/test/toy/cases/34_record_literal_field.toy @@ -3,7 +3,9 @@ record Point { y: i64, } -fn main(): i64 { +fn __user_main(): i64 { let p: Point = Point { x: 40 }; return p.x + p.y + 2; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/35_string_global_data.toy b/test/toy/cases/35_string_global_data.toy @@ -1,5 +1,7 @@ pub let msg: [6]u8 = "hello\0"; -fn main(): i64 { +fn __user_main(): i64 { return msg[0] as i64 - 62; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/36_tuple_record_literal.toy b/test/toy/cases/36_tuple_record_literal.toy @@ -3,7 +3,9 @@ tuple Pair2 { i64, } -fn main(): i64 { +fn __user_main(): i64 { let p: Pair2 = Pair2 { 40, 2 }; return p.0 + p.1; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/37_enum_dot_constant.toy b/test/toy/cases/37_enum_dot_constant.toy @@ -4,8 +4,10 @@ enum Color: i64 { .blue = 2, } -fn main(): i64 { +fn __user_main(): i64 { let g: Color = .green; let b: Color = .blue; return (g as i64) + (b as i64); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/38_declarations_alias_extern.toy b/test/toy/cases/38_declarations_alias_extern.toy @@ -9,7 +9,9 @@ fn add(a: Word, b: Word): Word { pub alias exported_add = add; -fn main(): i64 { +fn __user_main(): i64 { let x: Word = 40; return add(x, 2); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/39_pointer_to_array_index.toy b/test/toy/cases/39_pointer_to_array_index.toy @@ -1,5 +1,7 @@ -fn main(): i64 { +fn __user_main(): i64 { var xs: [2]i64 = [40, 2]; let p: *[2]i64 = &xs; return p[0] + p[1]; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/40_alloca_memmove.toy b/test/toy/cases/40_alloca_memmove.toy @@ -1,7 +1,9 @@ -fn main(): i64 { +fn __user_main(): i64 { let src: *i64 = @alloca<i64>(1, 8); let dst: *i64 = @alloca<i64>(1, 8); src[0] = 42; @memmove(dst, src, 8, 8); return dst[0]; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/41_if_expression.toy b/test/toy/cases/41_if_expression.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { let x: i64 = if 1 { 40 } else { @@ -6,3 +6,5 @@ fn main(): i64 { }; return x + 2; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/42_switch_expression.toy b/test/toy/cases/42_switch_expression.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { let tag: i64 = 2; let value: i64 = switch tag { 0 { @@ -13,3 +13,5 @@ fn main(): i64 { }; return value + 2; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/43_while_expression_break.toy b/test/toy/cases/43_while_expression_break.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { var i: i64 = 0; let found: i64 = while<i64> i < 5 { if i == 3 { @@ -11,3 +11,5 @@ fn main(): i64 { }; return found + 39; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/44_attribute_syntax.toy b/test/toy/cases/44_attribute_syntax.toy @@ -1,5 +1,7 @@ pub fn @[.hot, .section(".text.hot")] -main(): i64 { +__user_main(): i64 { var @[.static] id: i64 = 40; return id + 2; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/45_qual_addrspace_types.toy b/test/toy/cases/45_qual_addrspace_types.toy @@ -1,5 +1,7 @@ -fn main(): i64 { +fn __user_main(): i64 { var x: i64 = 42; let p: *addrspace(0) const i64 = &x; return p.*; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/46_static_local.toy b/test/toy/cases/46_static_local.toy @@ -4,6 +4,8 @@ fn next_id(): i64 { return id; } -fn main(): i64 { +fn __user_main(): i64 { return next_id() + next_id(); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/47_target_arch_switch.toy b/test/toy/cases/47_target_arch_switch.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { let value: i64 = switch @target_arch() { .arm64 { 40 @@ -15,3 +15,5 @@ fn main(): i64 { }; return value + 2; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/48_supports_callconv.toy b/test/toy/cases/48_supports_callconv.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { let value: i64 = if @supports_callconv(.target_c) { 40 } else { @@ -6,3 +6,5 @@ fn main(): i64 { }; return value + 2; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/49_typed_asm_void.toy b/test/toy/cases/49_typed_asm_void.toy @@ -1,4 +1,6 @@ -fn main(): i64 { +fn __user_main(): i64 { @asm<void>("", outputs(), inputs()); return 42; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/50_switch_statement.toy b/test/toy/cases/50_switch_statement.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { var value: i64 = 0; switch 2 { 1 { @@ -13,3 +13,5 @@ fn main(): i64 { } return value; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/51_labeladdr_goto.toy b/test/toy/cases/51_labeladdr_goto.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { label done; let target: *void = @labeladdr(done); goto *target within (done); @@ -6,3 +6,5 @@ fn main(): i64 { done: return 42; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/52_global_array_data.toy b/test/toy/cases/52_global_array_data.toy @@ -1,5 +1,7 @@ pub let table: [2]i64 = [40, 2]; -fn main(): i64 { +fn __user_main(): i64 { return table[0] + table[1]; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/53_conversion_builtins.toy b/test/toy/cases/53_conversion_builtins.toy @@ -1,7 +1,9 @@ -fn main(): i64 { +fn __user_main(): i64 { let p: *i64 = @int_to_ptr<*i64>(0); if p == NULL as *i64 { return @zext<i64>(42 as i32); } return 0; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/54_scalar_intrinsics.toy b/test/toy/cases/54_scalar_intrinsics.toy @@ -1,6 +1,8 @@ -fn main(): i64 { +fn __user_main(): i64 { var x: i64 = 1; let p: *i64 = @assume_aligned<*i64>(&x, 8); @prefetch(p); return @fma(6.0, 7.0, 0.0) as i64; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/55_block_scope_shadow.toy b/test/toy/cases/55_block_scope_shadow.toy @@ -1,7 +1,9 @@ -fn main(): i64 { +fn __user_main(): i64 { let x: i64 = 40; { let x: i64 = 1; } return x + 2; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/56_i128_scalar.toy b/test/toy/cases/56_i128_scalar.toy @@ -1,3 +1,5 @@ -fn main(): i64 { +fn __user_main(): i64 { return @sizeof<i128>() + 26; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/57_string_escapes.toy b/test/toy/cases/57_string_escapes.toy @@ -1,5 +1,7 @@ pub let data: [4]u8 = "\x28\x0a\t\0"; -fn main(): i64 { +fn __user_main(): i64 { return (data[0] as i64) + 2; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/58_overflow_record.toy b/test/toy/cases/58_overflow_record.toy @@ -1,3 +1,5 @@ -fn main(): i64 { +fn __user_main(): i64 { return @add_overflow<i64>(40, 2).value; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/59_atomic_cmpxchg_record.toy b/test/toy/cases/59_atomic_cmpxchg_record.toy @@ -1,5 +1,7 @@ -fn main(): i64 { +fn __user_main(): i64 { var x: i64 = 40; let ok: bool = @atomic_cmpxchg<i64>(&x, 40, 42, .seq_cst, .relaxed, .strong).ok; return x - ((ok as i64) - 1); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/60_atomic_queries.toy b/test/toy/cases/60_atomic_queries.toy @@ -1,6 +1,8 @@ -fn main(): i64 { +fn __user_main(): i64 { if @atomic_is_legal<i64>(.seq_cst) and @atomic_is_lock_free<i64>() { return 42; } return 0; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/61_labeled_loop.toy b/test/toy/cases/61_labeled_loop.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { var i: i64 = 0; outer: while i < 10 { i = i + 1; @@ -8,3 +8,5 @@ outer: while i < 10 { } return i + 41; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/62_decl_data_attrs.toy b/test/toy/cases/62_decl_data_attrs.toy @@ -11,7 +11,9 @@ pub var @[.common, .align(8)] tentative: i64; pub alias @[.bind(.weak), .visibility(.hidden)] decorated_alias = decorated; -fn main(): i64 { +fn __user_main(): i64 { tentative = table[0] + table[1]; return decorated(tentative); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/63_memory_flags.toy b/test/toy/cases/63_memory_flags.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { let src: *i64 = @alloca<i64>(4, 8); let dst: *i64 = @alloca<i64>(4, 8); src[0] = 1; @@ -9,3 +9,5 @@ fn main(): i64 { @memset(&dst[1], 0, 8, 8, .invariant); return dst[0] + dst[1] + dst[2] + dst[3]; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/64_target_feature_queries.toy b/test/toy/cases/64_target_feature_queries.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { let weak_ok: bool = @supports_symbol_feature(.weak); let common_ok: bool = @supports_symbol_feature(.common); let strict: bool = @has_backend_feature(.strict_alignment); @@ -9,3 +9,5 @@ fn main(): i64 { } return 1; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/65_rounding_conversions.toy b/test/toy/cases/65_rounding_conversions.toy @@ -1,7 +1,9 @@ -fn main(): i64 { +fn __user_main(): i64 { let a: f64 = @sint_to_float<f64>(40, .default); let b: f64 = @uint_to_float<f64>(2, .nearest_even); let c: i64 = @float_to_sint<i64>(a + b + 0.75, .toward_zero); let d: u64 = @float_to_uint<u64>(0.9, .down); return c + d; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/66_anonymous_record_type.toy b/test/toy/cases/66_anonymous_record_type.toy @@ -1,4 +1,6 @@ -fn main(): i64 { +fn __user_main(): i64 { let r: record { a: i64, b: i64 } = { a: 40, b: 2 }; return r.a + r.b; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/67_abi_attrs.toy b/test/toy/cases/67_abi_attrs.toy @@ -2,8 +2,10 @@ fn load_first(p @[.nonnull, .readonly, .align(8), .dereferenceable(8)]: *i64): i return p[0]; } -fn main(): i64 { +fn __user_main(): i64 { let p: *i64 = @alloca<i64>(1, 8); p[0] = 42; return load_first(p); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/68_field_attrs.toy b/test/toy/cases/68_field_attrs.toy @@ -3,9 +3,11 @@ record Padded { y: i64, } -fn main(): i64 { +fn __user_main(): i64 { if @alignof<Padded>() >= 16 { return 42; } return 1; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/69_if_value_block_statements.toy b/test/toy/cases/69_if_value_block_statements.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { let x: i64 = if 1 { let base = 40; base + 2 @@ -8,3 +8,5 @@ fn main(): i64 { }; return x; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/70_labeled_switch_break.toy b/test/toy/cases/70_labeled_switch_break.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { var x: i64 = 1; outer: switch 0 { 0 { @@ -12,3 +12,5 @@ outer: switch 0 { } return x; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/71_forward_records.toy b/test/toy/cases/71_forward_records.toy @@ -11,8 +11,10 @@ record B { value: i64, } -fn main(): i64 { +fn __user_main(): i64 { let a: A = A { value: 40 }; let b: B = B { a: &a, value: 2 }; return a.value + b.value; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/72_global_record_data.toy b/test/toy/cases/72_global_record_data.toy @@ -5,6 +5,8 @@ record GPair { pub let gp: GPair = GPair { a: 40, b: 2 }; -fn main(): i64 { +fn __user_main(): i64 { return gp.a + gp.b; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/73_atomic_access_group.toy b/test/toy/cases/73_atomic_access_group.toy @@ -1,5 +1,7 @@ -fn main(): i64 { +fn __user_main(): i64 { var x: i64 = 0; @atomic_store<i64>(&x, 42, .seq_cst, access(.align(8), .volatile)); return @atomic_load<i64>(&x, .seq_cst, access(.align(8), .volatile)); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/74_atomic_rmw_access.toy b/test/toy/cases/74_atomic_rmw_access.toy @@ -1,5 +1,7 @@ -fn main(): i64 { +fn __user_main(): i64 { var x: i64 = 40; let old: i64 = @atomic_rmw<i64>(.add, &x, 2, .seq_cst, access(.align(8))); return x + old - 40; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/75_atomic_cmpxchg_access.toy b/test/toy/cases/75_atomic_cmpxchg_access.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { var x: i64 = 1; let r = @atomic_cmpxchg<i64>(&x, 1, 42, .seq_cst, .seq_cst, .strong, access(.align(8))); if r.ok { @@ -6,3 +6,5 @@ fn main(): i64 { } return 1; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/76_atomic_query_access.toy b/test/toy/cases/76_atomic_query_access.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { let legal: bool = @atomic_is_legal<i64>(.seq_cst, access(.align(8))); let lock_free: bool = @atomic_is_lock_free<i64>(access(.align(8))); if (legal or !legal) and (lock_free or !lock_free) { @@ -6,3 +6,5 @@ fn main(): i64 { } return 1; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/77_atomic_keyword_ops.toy b/test/toy/cases/77_atomic_keyword_ops.toy @@ -1,5 +1,7 @@ -fn main(): i64 { +fn __user_main(): i64 { var x: i64 = 47; @atomic_rmw<i64>(.and, &x, 42, .seq_cst); return x; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/78_null_expected_pointer.toy b/test/toy/cases/78_null_expected_pointer.toy @@ -1,7 +1,9 @@ -fn main(): i64 { +fn __user_main(): i64 { let p: *i64 = NULL; if p == NULL as *i64 { return 42; } return 1; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/79_enum_argument_context.toy b/test/toy/cases/79_enum_argument_context.toy @@ -6,6 +6,8 @@ fn value(x: Answer): i64 { return x as i64; } -fn main(): i64 { +fn __user_main(): i64 { return value(.ok); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/80_enum_switch_labels.toy b/test/toy/cases/80_enum_switch_labels.toy @@ -3,7 +3,7 @@ enum Choice: i64 { .other = 8, } -fn main(): i64 { +fn __user_main(): i64 { let c: Choice = .answer; switch c { .answer { @@ -14,3 +14,5 @@ fn main(): i64 { } } } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/81_global_float_data.toy b/test/toy/cases/81_global_float_data.toy @@ -1,5 +1,7 @@ pub let f: f64 = 42.0; -fn main(): i64 { +fn __user_main(): i64 { return f as i64; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/82_unreachable_builtin.toy b/test/toy/cases/82_unreachable_builtin.toy @@ -1,7 +1,9 @@ -fn main(): i64 { +fn __user_main(): i64 { if 1 { return 42; } @unreachable(); return 1; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/83_pointer_field_access.toy b/test/toy/cases/83_pointer_field_access.toy @@ -2,8 +2,10 @@ record Box { value: i64, } -fn main(): i64 { +fn __user_main(): i64 { let b: Box = Box { value: 42 }; let p: *Box = &b; return p.value; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/84_field_assignment.toy b/test/toy/cases/84_field_assignment.toy @@ -2,8 +2,10 @@ record Cell { value: i64, } -fn main(): i64 { +fn __user_main(): i64 { var c: Cell = Cell { value: 1 }; c.value = 42; return c.value; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/85_packed_record_attr.toy b/test/toy/cases/85_packed_record_attr.toy @@ -3,6 +3,8 @@ record @[.packed] Packed { b: i64, } -fn main(): i64 { +fn __user_main(): i64 { return @offsetof<Packed>(b) + 41; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/86_address_of_field.toy b/test/toy/cases/86_address_of_field.toy @@ -2,8 +2,10 @@ record Cell2 { value: i64, } -fn main(): i64 { +fn __user_main(): i64 { var c: Cell2 = Cell2 { value: 42 }; let p: *i64 = &c.value; return p[0]; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/87_expect_preserves_type.toy b/test/toy/cases/87_expect_preserves_type.toy @@ -1,4 +1,6 @@ -fn main(): i64 { +fn __user_main(): i64 { let x: i32 = @expect(42 as i32, 42 as i32); return x as i64; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/88_scalar_intrinsic_preserves_type.toy b/test/toy/cases/88_scalar_intrinsic_preserves_type.toy @@ -1,5 +1,7 @@ -fn main(): i64 { +fn __user_main(): i64 { let x: i32 = @popcount(7 as i32); let y: i32 = @bswap(0 as i32); return (x + y) as i64 + 39; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/89_labeled_while_expression.toy b/test/toy/cases/89_labeled_while_expression.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { var i: i64 = 0; let found: i64 = outer: while<i64> i < 10 { i = i + 1; @@ -11,3 +11,5 @@ fn main(): i64 { }; return found; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/90_continue_through_switch.toy b/test/toy/cases/90_continue_through_switch.toy @@ -1,4 +1,4 @@ -fn main(): i64 { +fn __user_main(): i64 { var i: i64 = 0; var sum: i64 = 0; while i < 5 { @@ -14,3 +14,5 @@ fn main(): i64 { } return sum; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/91_exhaustive_enum_switch_expression.toy b/test/toy/cases/91_exhaustive_enum_switch_expression.toy @@ -4,7 +4,7 @@ enum Color: i64 { .blue = 3, } -fn main(): i64 { +fn __user_main(): i64 { let c: Color = .green; let value: i64 = switch c { .red { @@ -19,3 +19,5 @@ fn main(): i64 { }; return value; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/92_parenthesized_precedence_islands.toy b/test/toy/cases/92_parenthesized_precedence_islands.toy @@ -1,3 +1,5 @@ -fn main(): i64 { +fn __user_main(): i64 { return (1 + 2) << 3; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/93_data_pad_align.toy b/test/toy/cases/93_data_pad_align.toy @@ -1,6 +1,8 @@ pub let data: [6]u8 = [1, @pad(2, 7), 4, @align(2), 5]; -fn main(): i64 { +fn __user_main(): i64 { return (data[0] as i64) + (data[1] as i64) + (data[2] as i64) + (data[3] as i64) + (data[4] as i64) + (data[5] as i64); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/94_restrict_pointer_type.toy b/test/toy/cases/94_restrict_pointer_type.toy @@ -1,5 +1,7 @@ -fn main(): i64 { +fn __user_main(): i64 { var x: i64 = 41; let p: restrict *i64 = &x; return p.* + 1; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/95_static_local_string_data.toy b/test/toy/cases/95_static_local_string_data.toy @@ -4,6 +4,8 @@ fn read_data(): i64 { (data[3] as i64); } -fn main(): i64 { +fn __user_main(): i64 { return read_data(); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/96_data_relocations.toy b/test/toy/cases/96_data_relocations.toy @@ -3,6 +3,8 @@ pub let after: i32 = 2; pub let rels: [2]i32 = [@pcrel(after, 0), 7]; -fn main(): i64 { +fn __user_main(): i64 { return 42; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/97_let_pointer_pointee_assignment.toy b/test/toy/cases/97_let_pointer_pointee_assignment.toy @@ -1,6 +1,8 @@ -fn main(): i64 { +fn __user_main(): i64 { var x: i64 = 1; let p: *i64 = &x; p.* = 42; return x; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/98_tuple_offsetof.toy b/test/toy/cases/98_tuple_offsetof.toy @@ -3,6 +3,8 @@ tuple Pair64 { i64, } -fn main(): i64 { +fn __user_main(): i64 { return @offsetof<Pair64>(1); } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/cases/99_global_tuple_data.toy b/test/toy/cases/99_global_tuple_data.toy @@ -5,6 +5,8 @@ tuple GPair { pub let gp: GPair = GPair { 40, 2 }; -fn main(): i64 { +fn __user_main(): i64 { return gp.0 + gp.1; } + +fn main(): i32 { return __user_main() as i32; } diff --git a/test/toy/run.sh b/test/toy/run.sh @@ -9,8 +9,8 @@ # --emit=c C-source backend driven by a non-C frontend (validates that # the CGTarget seam is frontend-agnostic). Phased-rollout panics from # the C target report as SKIP. Host cc runs under -# -Wall -Wextra -Werror with -Wno-main-return-type (toy's main returns -# i64, and `int64_t main` would otherwise fire -Wmain-return-type). +# -Wall -Wextra -Werror; fixtures wrap their i64 main in a small i32 +# thunk so the emitted `int32_t main(void)` satisfies the standard. # # Sidecars: # <name>.expected expected process exit code, default 0 @@ -335,11 +335,10 @@ run_case_emit_c() { sed 's/^/ | /' "$emit_err" return fi - # Toy's main returns i64; modern clang under -std=c11 makes that a - # hard error ("'main' must return 'int'"). The emitted C only needs - # the stdint typedefs, so we compile under -std=gnu99 + the relax - # flag — gnu99's main-return-type check is a warning, not an error. - if ! $HOST_CC -std=gnu99 -Wall -Wextra -Werror -Wno-main-return-type "$out_c" -o "$out_bin" \ + # Fixtures wrap their i64 main in an `fn main(): i32` thunk so the + # emitted `int32_t main(void)` satisfies the host C compiler's + # main-return-type check. + if ! $HOST_CC -std=gnu99 -Wall -Wextra -Werror "$out_c" -o "$out_bin" \ > "$work/c.cc.out" 2> "$cc_err"; then note_fail "$label" printf ' host cc rejected emitted source\n'