├── docs └── stub.rst ├── tests ├── incomplete_template │ ├── x.znn │ └── main.znn ├── incomplete_type1 │ ├── s.znn │ └── main.znn ├── incomplete_type2 │ ├── s.znn │ └── main.znn ├── incomplete_array │ ├── x.znn │ └── main.znn ├── void_main1.znn ├── incomplete_struct_import3 │ ├── input2.znn │ └── main.znn ├── incomplete_struct_import4 │ └── input2.znn ├── import │ ├── struct2.znn │ ├── main.znn │ ├── struct1.znn │ └── print.znn ├── main.znn ├── void_main2.znn ├── import_constructor │ ├── hidden.znn │ ├── main.znn │ └── struct1.znn ├── import_public3 │ ├── fun2.znn │ ├── fun.znn │ └── main.znn ├── import_struct_conflict │ ├── struct1.znn │ ├── struct2.znn │ └── main.znn ├── import_type_alias1 │ ├── input2.znn │ ├── input3.znn │ └── main.znn ├── mixin1.znn ├── destructor_wrong_file1 │ ├── struct1.znn │ └── main.znn ├── import_public │ ├── fun2.znn │ ├── fun.znn │ └── main.znn ├── import_public2 │ ├── fun2.znn │ ├── fun.znn │ └── main.znn ├── import_public4 │ ├── fun2.znn │ ├── struct.znn │ ├── fun.znn │ └── main.znn ├── import_concept_bad1 │ ├── input2.znn │ └── main.znn ├── import_template_fun │ ├── fun2.znn │ ├── main.znn │ └── fun.znn ├── incomplete_enum2 │ ├── fun1.znn │ ├── fun2.znn │ └── main.znn ├── incomplete_enum3 │ ├── fun1.znn │ ├── fun2.znn │ └── main.znn ├── main_bad1.znn ├── discard1.znn ├── import_enum_conflict │ ├── struct1.znn │ ├── struct2.znn │ └── main.znn ├── import_methods2 │ ├── fun.znn │ ├── main.znn │ └── s1.znn ├── increment_op3.znn ├── ternary_operator1.znn ├── command_line_bad1.znn ├── enum_import │ ├── enum1.znn │ └── main.znn ├── command_line1.znn ├── import_union_conflict │ ├── struct1.znn │ ├── struct2.znn │ └── main.znn ├── non_unary_op.znn ├── non_unary_op2.znn ├── ternary_operator2.znn ├── to_string_bad1.znn ├── void_variable.znn ├── command_line_bad2.znn ├── noreturn_variable.znn ├── void_param.znn ├── countof_bad1.znn ├── countof_bad2.znn ├── default_body_bad1.znn ├── import_circular2 │ ├── fun.znn │ └── main.znn ├── incomplete_struct_import │ ├── fun.znn │ └── main.znn ├── incomplete_struct_import2 │ ├── fun.znn │ └── main.znn ├── noreturn_param.znn ├── string_interpolation_bad1.znn ├── type_alias_bad3.znn ├── concept_bad2.znn ├── lambda1.znn ├── lambda_bad_return2.znn ├── lambda_no_param1.znn ├── string3.znn ├── string_interpolation_bad2.znn ├── string_interpolation_bad3.znn ├── string_interpolation_bad4.znn ├── string_interpolation_bad5.znn ├── string_interpolation_bad6.znn ├── string_interpolation_bad8.znn ├── ternary_operator_bad1.znn ├── bad_op_arguments2.znn ├── import_vector2 │ ├── main.znn │ └── struct1.znn ├── literal_out_of_range1.znn ├── null_bad1.znn ├── static_mutable_string3.znn ├── string_interpolation_bad7.znn ├── string_interpolation_bad9.znn ├── ternary_operator_bad2.znn ├── variable_copy.znn ├── countof_bad3.znn ├── get_member_name_bad3.znn ├── if_body_declaration.znn ├── import_union │ ├── struct1.znn │ └── struct2.znn ├── lambda_bad_arg1.znn ├── long_mangling1.znn ├── bad_op_arguments.znn ├── concept_type_import1 │ ├── input2.znn │ └── main.znn ├── equality_bad1.znn ├── expected_bad1.znn ├── incomplete_enum4 │ ├── main.znn │ └── input2.znn ├── infinite_struct3.znn ├── lambda_bad_return1.znn ├── lambda_implicit_return1.znn ├── template_requirement_bad5.znn ├── template_value_param_bad6.znn ├── attribute_bad1.znn ├── bad_op_arguments3.znn ├── concept_type_value_bad1.znn ├── discard2.znn ├── enum_size_bad1.znn ├── enum_size_bad2.znn ├── escaped_escape1.znn ├── escaped_quote1.znn ├── expected_bad2.znn ├── increment_op2.znn ├── increment_op4.znn ├── lambda_bad_arg2.znn ├── lambda_capture_bad4.znn ├── lambda_double_capture1.znn ├── lambda_move_arg1.znn ├── noreturn_bad2.znn ├── static_if_bad5.znn ├── string_implicit_copy1.znn ├── ternary_operator6.znn ├── ternary_operator_bad3.znn ├── arithmetic2.znn ├── bad_template_param.znn ├── copy_function_bad1.znn ├── enum_bad5.znn ├── extern_function1.znn ├── import_vector │ ├── main.znn │ └── struct1.znn ├── increment_op1.znn ├── lambda_capture_by_ref_bad1.znn ├── lambda_double_capture2.znn ├── static_variable_bad4.znn ├── subscript6.znn ├── const_ptr_to_mut_ptr.znn ├── function_attribute_bad1.znn ├── lambda_bad_arg3.znn ├── lambda_implicit_ref_capture_bad1.znn ├── mixin_escape_char1.znn ├── named_args1.znn ├── no_copy1.znn ├── pointer_implicit_copy1.znn ├── ternary_operator4.znn ├── union2.znn ├── variadic_args_bad7.znn ├── bad_template_param_type.znn ├── duplicate_member.znn ├── infinite_struct2.znn ├── lambda_capture_by_ref1.znn ├── ranged_loop_bad1.znn ├── shadow_var1.znn ├── template_requirement1.znn ├── template_value_param_bad3.znn ├── ternary_operator3.znn ├── array_generate1.znn ├── array_negative_size.znn ├── bad_params.znn ├── bad_params2.znn ├── concept_type_import3 │ ├── input2.znn │ └── main.znn ├── destructor_bad7.znn ├── discard4.znn ├── duplicate_fun_param.znn ├── if_statement_bad1.znn ├── infinite_struct1.znn ├── lambda_capture_by_move_bad1.znn ├── lambda_double_capture_bad1.znn ├── lambda_double_capture_bad2.znn ├── method7.znn ├── move_in_loop_bad6.znn ├── optional2.znn ├── static_for_bad8.znn ├── static_if_bad2.znn ├── static_mutable_variable4.znn ├── static_mutable_variable_bad5.znn ├── static_mutable_variable_bad6.znn ├── static_variable_bad2.znn ├── template_instance_bad1.znn ├── template_requirement_bad4.znn ├── type_alias1.znn ├── type_alias_bad1.znn ├── unknown_concept.znn ├── array_bad_size.znn ├── array_literal_bad1.znn ├── compile_error_fun1.znn ├── copy_function_bad2.znn ├── copy_function_bad3.znn ├── destructor_bad1.znn ├── discard3.znn ├── enum_size_bad3.znn ├── lambda_bad_no_capture1.znn ├── lambda_implicit_return4.znn ├── move_in_ternaty_op2.znn ├── shadow_var2.znn ├── static_mutable_variable_bad4.znn ├── template_requirement_bad3.znn ├── type_variable1.znn ├── variable_decl_inside_if_bad.znn ├── variadic_args_bad2.znn ├── variadic_args_bad3.znn ├── variadic_args_bad6.znn ├── array_literal1.znn ├── attribute_bad2.znn ├── attribute_bad5.znn ├── empty_array.znn ├── import_methods │ ├── main.znn │ └── s1.znn ├── lambda_capture_bad_moved2.znn ├── long_arithmetic1.znn ├── method6.znn ├── move_bad1.znn ├── slice_implicit_copy1.znn ├── static_for_bad6.znn ├── static_if_bad3.znn ├── static_variable_bad3.znn ├── struct_default_args_bad1.znn ├── template_requirement_bad2.znn ├── type_argument1.znn ├── union3.znn ├── variadic_args_bad10.znn ├── virtual_function_bad2.znn ├── compile_error_fun2.znn ├── destructor_not_exported1.znn ├── enum_bad6.znn ├── forgot_extern.znn ├── function_type_bad1.znn ├── lambda2.znn ├── lambda_capture1.znn ├── lambda_capture_bad_moved1.znn ├── modify_function_arg.znn ├── modify_function_arg2.znn ├── move_in_array_bad.znn ├── move_in_array_bad2.znn ├── move_in_loop3.znn ├── mutable_pointer_conversion2.znn ├── static_for_bad2.znn ├── static_mutable_variable1.znn ├── static_mutable_variable_bad1.znn ├── static_variable_bad1.znn ├── string_template1.znn ├── union_member_access1.znn ├── unique_ptr.znn ├── variable_decl_inside_if_bad2.znn ├── variadic_args_bad9.znn ├── const_pointer_member.znn ├── empty_array2.znn ├── function_arg_redef.znn ├── incomplete_enum │ ├── fun2.znn │ ├── fun.znn │ └── main.znn ├── io_error1.znn ├── move_in_loop4.znn ├── move_in_loop_bad7.znn ├── optional_bad_conversion1.znn ├── shadow_var_bad1.znn ├── static_if_bad4.znn ├── template_value_param_bad2.znn ├── template_value_param_bad4.znn ├── try_op_bad2.znn ├── concept_type_templated3.znn ├── destructor_bad6.znn ├── for_loop.znn ├── function_method3.znn ├── hash_set_bad1.znn ├── import_double │ ├── struct2.znn │ ├── main.znn │ ├── print.znn │ └── struct1.znn ├── is_enum_concept_bad1.znn ├── lambda_capture_bad1.znn ├── move6.znn ├── range1.znn ├── shadow_var3.znn ├── static_if_bad1.znn ├── subscript1.znn ├── ternary_operator5.znn ├── constructor_bad1.znn ├── entry_point1.znn ├── enum_equals.znn ├── hash_map_bad1.znn ├── import_circular │ ├── struct1.znn │ └── main.znn ├── instance_context2 │ └── fun.znn ├── io_error2.znn ├── lambda10.znn ├── lambda_implicit_ref_capture1.znn ├── lambda_implicit_void2.znn ├── static_for10.znn ├── static_while_bad1.znn ├── template_value_param_bad1.znn ├── ternary_operator_static1.znn ├── union_member_access_bad2.znn ├── compile_time_array_size.znn ├── compile_time_array_size_bad2.znn ├── concept_type11.znn ├── concept_type_bad13.znn ├── concept_type_cast_bad1.znn ├── concept_type_value_bad2.znn ├── constructor7.znn ├── double_fun.znn ├── lambda_implicit_void1.znn ├── mixin3.znn ├── mut_ptr_to_const_ptr.znn ├── mutable_pointer_conversion3.znn ├── pointer_comparison_bad1.znn ├── shadow_static_var_bad1.znn ├── static_mutable_variable6.znn ├── static_mutable_variable_bad2.znn ├── static_variable1.znn ├── struct_const_member_bad1.znn ├── subscript4.znn ├── subscript5.znn ├── template_value_param3.znn ├── template_value_param4.znn ├── type_alias_bad2.znn ├── bad_operator_overload2.znn ├── break_bad.znn ├── concept_type_bad11.znn ├── concept_type_bad12.znn ├── destructor_bad3.znn ├── function_redefinition.znn ├── instance_context3 │ ├── fun.znn │ └── main.znn ├── operator_value_or2.znn ├── optional3.znn ├── static_for4.znn ├── static_for_bad1.znn ├── template_param_name_conflict.znn ├── type_name_conflict1 │ ├── fun.znn │ └── main.znn ├── concept_type_templated1.znn ├── continue_bad.znn ├── copy_function_bad4.znn ├── destructor_bad5.znn ├── get_member_name_bad1.znn ├── get_member_name_bad2.znn ├── lambda_capture_by_ref2.znn ├── lambda_implicit_ref_capture2.znn ├── mixin_bad5.znn ├── operator_value_or1.znn ├── static_for5.znn ├── static_for6.znn ├── type_comparison2.znn ├── uninitialized_var.znn ├── variadic_args_bad8.znn ├── calling_method_on_pointer.znn ├── compile_error_fun3.znn ├── constructor_bad2.znn ├── copy_function1.znn ├── destructor_bad4.znn ├── destructor_not_exported2.znn ├── entry_point_bad1.znn ├── escaped_char1.znn ├── get_alternative3.znn ├── lambda_implicit_return2.znn ├── less_than_vs_template.znn ├── member1.znn ├── move2.znn ├── move_forgot3.znn ├── move_in_loop_bad2.znn ├── move_in_loop_bad3.znn ├── noreturn_bad1.znn ├── optional1.znn ├── static_for_bad_move1.znn ├── template_overload_bad2.znn ├── template_overload_bad3.znn ├── to_string3.znn ├── bad_operator_overload1.znn ├── break1.znn ├── member2.znn ├── mixin_bad2.znn ├── mixin_bad3.znn ├── mixin_bad4.znn ├── static_for7.znn ├── variadic_args_bad15.znn ├── calling_method_on_pointer2.znn ├── compile_error_fun4.znn ├── concept_bad_arg.znn ├── concept_type9.znn ├── continue1.znn ├── destructor_requirement_bad2.znn ├── enum_range_bad1.znn ├── function_type_conflict2.znn ├── lambda_capture2.znn ├── move3.znn ├── move_in_unchecked_if1.znn ├── mutable_pointer_conversion1.znn ├── static_for_bad3.znn ├── struct3.znn ├── template_requirement_bad1.znn ├── type_comparison_bad2.znn ├── void_struct_member1.znn ├── array_negative_size2.znn ├── destructor_union_bad1.znn ├── function_type_conflict.znn ├── get_member1.znn ├── slice_subsequence1.znn ├── struct_default_args3.znn ├── template_value_param_bad5.znn ├── unchecked1.znn ├── concept_type_bad14.znn ├── get_alternative1.znn ├── get_alternative2.znn ├── lambda_ambiguous_implicit_return1.znn ├── lambda_move_in_body1.znn ├── operator_overload_bad5.znn ├── optional4.znn ├── panic_handler1.znn ├── static_for9.znn ├── template3.znn ├── template_overload_bad.znn ├── try_op_bad1.znn ├── two_constructors.znn ├── constructor1.znn ├── continue2.znn ├── function_overloading1.znn ├── function_type1.znn ├── hash_map_incomplete1.znn ├── instance_context │ ├── main.znn │ └── fun.znn ├── lambda_capture_bad5.znn ├── lambda_in_static_for1.znn ├── move_in_loop_bad5.znn ├── name_mangling2.znn ├── static_mutable_variable5.znn ├── ternary_operator_precedence1.znn ├── type_alias2.znn ├── type_comparison1.znn ├── type_comparison3.znn ├── unchecked_bad1.znn ├── attribute_bad4.znn ├── double.znn ├── extern_void_function1.znn ├── get_member2.znn ├── member3.znn ├── method4.znn ├── method5.znn ├── mixin_bad1.znn ├── move4.znn ├── mutable_slice_bad1.znn ├── pointer_comparison1.znn ├── static_for2.znn ├── static_mutable_string1.znn ├── struct_default_args2.znn ├── template_requirement2.znn ├── try_op2.znn ├── try_op3.znn ├── vector_filter1.znn ├── compile_time_array_size_bad.znn ├── lambda8.znn ├── method_overload6.znn ├── mutable_ptr_template_param.znn ├── postfix_indirection1.znn ├── public_embed.znn ├── subscript7.znn ├── array_iterator2.znn ├── enum_switch_bad1.znn ├── mixin2.znn ├── move_forgot1.znn ├── move_forgot2.znn ├── mutable_for1.znn ├── named_args_overload3.znn ├── string_to_int1.znn ├── template_expression1.znn ├── template_requirement_bad7.znn ├── transitive_requirement1 │ └── main.znn ├── type_comparison_bad1.znn ├── variadic_value_parameter1.znn ├── array2d.znn ├── constructor_template1.znn ├── lambda_capture_bad2.znn ├── move_in_loop1.znn ├── move_in_loop2.znn ├── move_in_loop7.znn ├── op_in_place.znn ├── shadow_static_var4.znn ├── static_for_bad4.znn ├── array_copy1.znn ├── concept_type_bad2.znn ├── concept_type_cast2.znn ├── destructor1.znn ├── enum_implicit_copy1.znn ├── enum_range1.znn ├── get_member3.znn ├── lambda_capture_by_copy1.znn ├── method_overload5.znn ├── move_in_loop5.znn ├── name_mangling1.znn ├── static_mutable_variable2.znn ├── string1.znn ├── template_requirement_bad6.znn ├── variadic_args_bad5.znn ├── constructor_default_bad1.znn ├── conversions1.znn ├── destructor_lambda_param1.znn ├── function_concept1.znn ├── function_type2.znn ├── lambda_capture_by_move1.znn ├── method_overload1.znn ├── move5.znn ├── move_bad2.znn ├── variadic_args_bad4.znn ├── variadic_value_parameter_bad1.znn ├── variadic_value_parameter_bad2.znn ├── destructor3.znn ├── extern_struct_instance1.znn ├── get_alternative_name_bad1.znn ├── import_methods3 │ └── main.znn ├── lambda_capture_bad6.znn ├── move_in_loop_bad.znn ├── operator_pointer_args2.znn ├── static_for3.znn ├── static_while_bad2.znn ├── concept_type_bad1.znn ├── concept_type_bad10.znn ├── concept_type_bad5.znn ├── deduce_from_concept_bad2.znn ├── destructor_requirement3.znn ├── enum_size_in_template_struct_bad1.znn ├── lambda7.znn ├── lambda_capture_by_ref3.znn ├── move_in_loop6.znn ├── operator_overload_not_equal2.znn ├── shadow_static_var1.znn ├── static_mutable_variable3.znn ├── to_string2.znn ├── variadic_args_bad1.znn ├── attribute_bad6.znn ├── concept_bad1.znn ├── constructor_default1.znn ├── destructor5.znn ├── empty_return_in_template.znn ├── enum_size_in_template_fun1.znn ├── function.znn ├── lambda_capture_bad3.znn ├── lambda_mutable_ptr1.znn ├── method_overload4.znn ├── named_args_overload4.znn ├── operator_pointer_args.znn ├── static_for_bad7.znn ├── arithmetic.znn ├── concept_type_bad3.znn ├── method_overload2.znn ├── method_overload3.znn ├── move_in_loop_bad4.znn ├── multiline_comment.znn ├── operator_overload_bad1.znn ├── ranged_loop2.znn ├── static_if1.znn ├── static_while1.znn ├── struct2.znn ├── subscript3.znn ├── subscript_template_arg.znn ├── template_expression2.znn ├── variadic_args3.znn ├── vector_transform1.znn ├── concept_type12.znn ├── lambda9.znn ├── lambda_capture_by_move2.znn ├── move_bad3.znn ├── no_copy2.znn ├── noreturn1.znn ├── static_mutable_variable_bad3.znn ├── array_transform1.znn ├── auto_equality_bad1.znn ├── countof_template_arg1.znn ├── destructor_requirement_bad1.znn ├── function_type3.znn ├── lambda_capture_by_copy2.znn ├── lambda_implicit_return3.znn ├── function_concept_bad.znn ├── implicit_conversion_to_union1.znn ├── lambda4.znn ├── move_in_expression.znn ├── named_args_overload5.znn ├── variadic_concept3.znn ├── break2.znn ├── concept_type4.znn ├── move_bad4.znn ├── move_in_if2.znn ├── static_mutable_string2.znn ├── subscript2.znn ├── switch_move_bad1.znn ├── switch_move_bad2.znn ├── template_function2.znn ├── ambigous_method.znn ├── concept_type5.znn ├── deduce_from_concept_lambda1.znn ├── lambda_capture_by_copy_bad1.znn ├── operator_pointer_args3.znn ├── switch_multiple_elems1.znn ├── template_requirement3.znn ├── try_op_bad3.znn ├── union_constructor1.znn ├── concept_type_bad4.znn ├── function_type4.znn ├── is_enum_concept1.znn ├── move1.znn ├── overload_resolution2.znn ├── type_alias4.znn ├── address_of_temporary.znn ├── enum_bad4.znn ├── has_members_bad2.znn ├── hash_map_iterator1.znn ├── implicit_conversion_to_union2.znn ├── io1.znn ├── lambda11.znn ├── lambda_capture3.znn ├── move_in_if.znn ├── operator_value_or3.znn ├── variadic_concept_bad1.znn ├── vector_iterator1.znn ├── break3.znn ├── destructor6.znn ├── switch_multiple_elems_bad3.znn └── template_requirement_bad8.znn ├── codegen_includes ├── main_body.h ├── main_body_void.h ├── array_utils.h ├── main_body_args.h └── main_body_args_void.h ├── .github └── FUNDING.yml ├── src ├── lsp.h ├── lexer.h ├── reader.h ├── parser.h ├── codegen.h ├── lambda_capture_info.cpp └── reader.cpp ├── std └── pointer.znn └── .gitignore /docs/stub.rst: -------------------------------------------------------------------------------- 1 | 2 | TBD 3 | === 4 | -------------------------------------------------------------------------------- /tests/incomplete_template/x.znn: -------------------------------------------------------------------------------- 1 | 2 | struct X {}; 3 | -------------------------------------------------------------------------------- /tests/incomplete_type1/s.znn: -------------------------------------------------------------------------------- 1 | 2 | struct S {}; 3 | -------------------------------------------------------------------------------- /tests/incomplete_type2/s.znn: -------------------------------------------------------------------------------- 1 | 2 | struct S {}; 3 | -------------------------------------------------------------------------------- /tests/incomplete_array/x.znn: -------------------------------------------------------------------------------- 1 | 2 | 3 | struct X {}; 4 | -------------------------------------------------------------------------------- /tests/void_main1.znn: -------------------------------------------------------------------------------- 1 | // 0 2 | 3 | void main() { 4 | } 5 | -------------------------------------------------------------------------------- /tests/incomplete_struct_import3/input2.znn: -------------------------------------------------------------------------------- 1 | 2 | union X { void a; }; -------------------------------------------------------------------------------- /tests/incomplete_struct_import4/input2.znn: -------------------------------------------------------------------------------- 1 | 2 | union X { void a; }; -------------------------------------------------------------------------------- /tests/import/struct2.znn: -------------------------------------------------------------------------------- 1 | 2 | struct Struct2 { 3 | int u; 4 | }; 5 | -------------------------------------------------------------------------------- /tests/main.znn: -------------------------------------------------------------------------------- 1 | // 27 2 | 3 | int main() { 4 | return 27; 5 | } 6 | -------------------------------------------------------------------------------- /tests/void_main2.znn: -------------------------------------------------------------------------------- 1 | // 0 2 | 3 | void main(string[] args) { 4 | } 5 | -------------------------------------------------------------------------------- /tests/import_constructor/hidden.znn: -------------------------------------------------------------------------------- 1 | 2 | 3 | export void hidden() { 4 | } 5 | -------------------------------------------------------------------------------- /tests/import_public3/fun2.znn: -------------------------------------------------------------------------------- 1 | 2 | export struct S2 { 3 | bool b; 4 | }; 5 | -------------------------------------------------------------------------------- /tests/import_struct_conflict/struct1.znn: -------------------------------------------------------------------------------- 1 | 2 | export struct S { 3 | }; 4 | -------------------------------------------------------------------------------- /tests/import_struct_conflict/struct2.znn: -------------------------------------------------------------------------------- 1 | 2 | export struct S { 3 | }; 4 | -------------------------------------------------------------------------------- /tests/import_type_alias1/input2.znn: -------------------------------------------------------------------------------- 1 | 2 | 3 | export import "input3.znn"; 4 | -------------------------------------------------------------------------------- /tests/mixin1.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | int main() { 4 | mixin "return 5;"; 5 | } 6 | -------------------------------------------------------------------------------- /tests/destructor_wrong_file1/struct1.znn: -------------------------------------------------------------------------------- 1 | 2 | export struct X { 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /tests/import_public/fun2.znn: -------------------------------------------------------------------------------- 1 | 2 | export int getNum2() { 3 | return 1; 4 | } 5 | -------------------------------------------------------------------------------- /tests/import_public2/fun2.znn: -------------------------------------------------------------------------------- 1 | 2 | export int getNum2() { 3 | return 1; 4 | } 5 | -------------------------------------------------------------------------------- /tests/import_public4/fun2.znn: -------------------------------------------------------------------------------- 1 | 2 | export int getNum2() { 3 | return 1; 4 | } 5 | -------------------------------------------------------------------------------- /codegen_includes/main_body.h: -------------------------------------------------------------------------------- 1 | 2 | int main() { 3 | return zenonMain(); 4 | } 5 | 6 | -------------------------------------------------------------------------------- /tests/import_concept_bad1/input2.znn: -------------------------------------------------------------------------------- 1 | 2 | concept C { 3 | void f(T*); 4 | }; 5 | -------------------------------------------------------------------------------- /tests/import_public4/struct.znn: -------------------------------------------------------------------------------- 1 | export import "fun2.znn"; 2 | 3 | struct S { 4 | }; 5 | -------------------------------------------------------------------------------- /tests/import_template_fun/fun2.znn: -------------------------------------------------------------------------------- 1 | 2 | export int getNum2() { 3 | return 1; 4 | } 5 | -------------------------------------------------------------------------------- /tests/incomplete_enum2/fun1.znn: -------------------------------------------------------------------------------- 1 | 2 | export enum E { 3 | E1, 4 | E2 5 | }; 6 | 7 | -------------------------------------------------------------------------------- /tests/incomplete_enum3/fun1.znn: -------------------------------------------------------------------------------- 1 | 2 | export enum E { 3 | E1, 4 | E2 5 | }; 6 | 7 | -------------------------------------------------------------------------------- /tests/main_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | string main() { 4 | return ""; 5 | } 6 | -------------------------------------------------------------------------------- /tests/discard1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | 1; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/import_enum_conflict/struct1.znn: -------------------------------------------------------------------------------- 1 | 2 | export enum E { 3 | ONE, 4 | TWO 5 | }; 6 | -------------------------------------------------------------------------------- /tests/import_enum_conflict/struct2.znn: -------------------------------------------------------------------------------- 1 | 2 | export enum E { 3 | ONE, 4 | TWO 5 | }; 6 | -------------------------------------------------------------------------------- /tests/import_methods2/fun.znn: -------------------------------------------------------------------------------- 1 | 2 | 3 | export int fun(int x) { 4 | return x + 1; 5 | } 6 | -------------------------------------------------------------------------------- /tests/increment_op3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | return ++5; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /tests/ternary_operator1.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | int main() { 4 | return true ? 1 : 2; 5 | } 6 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: miki151 4 | -------------------------------------------------------------------------------- /tests/command_line_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main(int x) { 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/enum_import/enum1.znn: -------------------------------------------------------------------------------- 1 | 2 | 3 | export enum E1 { 4 | V1, 5 | V2, 6 | V3 7 | }; 8 | -------------------------------------------------------------------------------- /tests/incomplete_enum3/fun2.znn: -------------------------------------------------------------------------------- 1 | 2 | export int f(E e) { 3 | switch (e) { 4 | } 5 | } 6 | 7 | -------------------------------------------------------------------------------- /codegen_includes/main_body_void.h: -------------------------------------------------------------------------------- 1 | 2 | int main() { 3 | zenonMain(); 4 | return 0; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /tests/command_line1.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | int main(string[] args) { 4 | return args.size(); 5 | } 6 | -------------------------------------------------------------------------------- /tests/import_union_conflict/struct1.znn: -------------------------------------------------------------------------------- 1 | 2 | export union V { 3 | int a; 4 | bool b; 5 | }; 6 | -------------------------------------------------------------------------------- /tests/import_union_conflict/struct2.znn: -------------------------------------------------------------------------------- 1 | 2 | export union V { 3 | int a; 4 | bool b; 5 | }; 6 | -------------------------------------------------------------------------------- /tests/non_unary_op.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | int x = 5; 5 | return *x; 6 | } 7 | -------------------------------------------------------------------------------- /tests/non_unary_op2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | int x = 5; 5 | return /x; 6 | } 7 | -------------------------------------------------------------------------------- /tests/ternary_operator2.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | int main() { 4 | return true ? 1 + 2 : 3 + 4; 5 | } 6 | -------------------------------------------------------------------------------- /tests/to_string_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | return "{123}".size(); 5 | } 6 | -------------------------------------------------------------------------------- /tests/void_variable.znn: -------------------------------------------------------------------------------- 1 | // 0 2 | 3 | int main() { 4 | void x = void_value; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/command_line_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main(string[] p, int a) { 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/noreturn_variable.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | noreturn x; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/void_param.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | void f(void) {} 4 | 5 | int main() { 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/import_public3/fun.znn: -------------------------------------------------------------------------------- 1 | import "fun2.znn"; 2 | 3 | export struct S1 { 4 | S2 s; 5 | int a; 6 | }; 7 | -------------------------------------------------------------------------------- /tests/incomplete_enum2/fun2.znn: -------------------------------------------------------------------------------- 1 | 2 | export template 3 | void f() { 4 | const e = E::E1; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /tests/countof_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const x = countof(int); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/countof_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const x = countof(foo); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/default_body_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | void f() = default; 4 | 5 | int main() { 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/import_circular2/fun.znn: -------------------------------------------------------------------------------- 1 | 2 | export import "main.znn"; 3 | 4 | export int f() { 5 | return g(); 6 | } 7 | -------------------------------------------------------------------------------- /tests/incomplete_struct_import/fun.znn: -------------------------------------------------------------------------------- 1 | 2 | struct S { 3 | }; 4 | 5 | export S getS() { 6 | return S(); 7 | } 8 | -------------------------------------------------------------------------------- /tests/incomplete_struct_import2/fun.znn: -------------------------------------------------------------------------------- 1 | 2 | struct S { 3 | }; 4 | 5 | export S getS() { 6 | return S(); 7 | } 8 | -------------------------------------------------------------------------------- /tests/noreturn_param.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | void f(noreturn) {} 4 | 5 | int main() { 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/string_interpolation_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const s = "{"; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/type_alias_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | void f() {} 4 | 5 | using f = int; 6 | 7 | void main() { 8 | } 9 | -------------------------------------------------------------------------------- /src/lsp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "stdafx.h" 4 | 5 | extern void startLsp(const vector& importDirs); 6 | -------------------------------------------------------------------------------- /tests/concept_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | concept C { 4 | }; 5 | 6 | int main() { 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/import_public/fun.znn: -------------------------------------------------------------------------------- 1 | import "fun2.znn"; 2 | 3 | export int getNum() { 4 | return getNum2() - 1; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /tests/import_type_alias1/input3.znn: -------------------------------------------------------------------------------- 1 | 2 | 3 | using type1 = int; 4 | 5 | export type1 get() { 6 | return 5; 7 | } 8 | -------------------------------------------------------------------------------- /tests/lambda1.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | int main() { 4 | const f = [] (int a) -> int { return a; }; 5 | return f(1); 6 | } 7 | -------------------------------------------------------------------------------- /tests/lambda_bad_return2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const f = [] -> int { }; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/lambda_no_param1.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | int main() { 4 | const f = [] -> int { return 1; }; 5 | return f(); 6 | } 7 | -------------------------------------------------------------------------------- /tests/string3.znn: -------------------------------------------------------------------------------- 1 | // 4 2 | 3 | 4 | int main() { 5 | mutable s = "pak"; 6 | s += 'c'; 7 | return s.size(); 8 | } 9 | -------------------------------------------------------------------------------- /tests/string_interpolation_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const s = " {"; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/string_interpolation_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const s = " { "; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/string_interpolation_bad4.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const s = "{ "; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/string_interpolation_bad5.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const s = "foo{"; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/string_interpolation_bad6.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const s = "{foo"; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/string_interpolation_bad8.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const s = "foo{}"; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/ternary_operator_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const y = 1 ? 2 : 3; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/bad_op_arguments2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | int a = 5; 5 | string s = a; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/import_public2/fun.znn: -------------------------------------------------------------------------------- 1 | export import "fun2.znn"; 2 | 3 | export int getNum() { 4 | return getNum2() - 1; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /tests/import_public4/fun.znn: -------------------------------------------------------------------------------- 1 | export import "fun2.znn"; 2 | 3 | export int getNum() { 4 | return getNum2() - 1; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /tests/import_vector2/main.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | import "struct1.znn"; 4 | 5 | int main() { 6 | return get().v[0].a; 7 | } 8 | -------------------------------------------------------------------------------- /tests/literal_out_of_range1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const a = 1000000000001; 5 | return a % 1; 6 | } 7 | -------------------------------------------------------------------------------- /tests/null_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | void f(string s) {} 4 | 5 | int main() { 6 | f(null); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/static_mutable_string3.znn: -------------------------------------------------------------------------------- 1 | // 6 2 | 3 | int main() { 4 | static mutable s = "foobar"; 5 | return size(&s); 6 | } 7 | -------------------------------------------------------------------------------- /tests/string_interpolation_bad7.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const s = "foo{foo"; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/string_interpolation_bad9.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const s = "foo{}foo"; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/ternary_operator_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const y = true ? 2 : "xyz"; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/variable_copy.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | int main() { 4 | int x = 5; 5 | mutable y = x; 6 | y = 2; 7 | return x; 8 | } 9 | -------------------------------------------------------------------------------- /tests/countof_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const y = 1; 5 | const x = countof(y); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/get_member_name_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const a = get_member_name(int, 0); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/if_body_declaration.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | if (false) 5 | int y = 5; 6 | return y; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /tests/import_union/struct1.znn: -------------------------------------------------------------------------------- 1 | export import "struct2.znn"; 2 | 3 | export union V1 { 4 | int x; 5 | bool b; 6 | }; 7 | 8 | -------------------------------------------------------------------------------- /tests/lambda_bad_arg1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const f = [] -> int { return 1; }; 5 | return f(1); 6 | } 7 | -------------------------------------------------------------------------------- /tests/long_mangling1.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | template 4 | int f() { return 2; } 5 | 6 | int main() { 7 | return f(); 8 | } 9 | -------------------------------------------------------------------------------- /tests/bad_op_arguments.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | int a = 5; 5 | string s = "dupa"; 6 | return a + s; 7 | } 8 | -------------------------------------------------------------------------------- /tests/concept_type_import1/input2.znn: -------------------------------------------------------------------------------- 1 | 2 | export concept C1 { 3 | int get(T*); 4 | void set(T mutable*, int); 5 | }; 6 | 7 | -------------------------------------------------------------------------------- /tests/equality_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | if (5 == true) 5 | return 1; 6 | else 7 | return 2; 8 | } 9 | -------------------------------------------------------------------------------- /tests/expected_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | extern int!bool f(); 4 | 5 | int main() { 6 | const a = f(); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/incomplete_enum4/main.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "input3.znn"; 4 | 5 | int main() { 6 | return enum_count(E); 7 | } 8 | -------------------------------------------------------------------------------- /tests/infinite_struct3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | X x; 5 | }; 6 | 7 | int main() { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/lambda_bad_return1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const f = [] -> int { return false; }; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/lambda_implicit_return1.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | int main() { 4 | const f = [](int a) { return a + 1; }; 5 | return f(2); 6 | } 7 | -------------------------------------------------------------------------------- /tests/template_requirement_bad5.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const s = array_repeat<-10>(1); 5 | return s[0]; 6 | } 7 | -------------------------------------------------------------------------------- /tests/template_value_param_bad6.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void f(T) {} 5 | 6 | void main() { 7 | f("a"); 8 | } -------------------------------------------------------------------------------- /tests/attribute_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | [@someattr] 4 | struct X { 5 | }; 6 | 7 | int main() { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/bad_op_arguments3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | int a = 5; 5 | string s = ""; 6 | s = a; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/concept_type_value_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "std/any.znn"; 4 | 5 | int main() { 6 | any a = 5; 7 | return 1; 8 | } 9 | -------------------------------------------------------------------------------- /tests/discard2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int f() { 4 | return 1; 5 | } 6 | 7 | int main() { 8 | f(); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/enum_size_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct S {}; 4 | 5 | int main() { 6 | const x = enum_count(S); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/enum_size_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct S {}; 4 | 5 | int main() { 6 | const x = enum_count(1); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/escaped_escape1.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | int main() { 4 | const s = "\\\\\\"; const t = "\"\\"; 5 | return s.size() + t.size(); 6 | } 7 | -------------------------------------------------------------------------------- /tests/escaped_quote1.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | int main() { 4 | const s = "\"\"\""; const t = "\"\""; 5 | return s.size() + t.size(); 6 | } 7 | -------------------------------------------------------------------------------- /tests/expected_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int!Foo f() { 4 | return 0; 5 | } 6 | 7 | int main() { 8 | return *f(); 9 | } 10 | -------------------------------------------------------------------------------- /tests/import_constructor/main.znn: -------------------------------------------------------------------------------- 1 | // 6 2 | import "struct1.znn"; 3 | 4 | int main() { 5 | const s = Struct1(5); 6 | return s.x; 7 | } 8 | -------------------------------------------------------------------------------- /tests/incomplete_enum4/input2.znn: -------------------------------------------------------------------------------- 1 | 2 | enum E { 3 | E1, E2 4 | }; 5 | 6 | export E getE() { 7 | return E::E1; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tests/increment_op2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const i = 0; 5 | ++++i; 6 | --i; 7 | return i; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tests/increment_op4.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | int main() { 4 | mutable i = 1; 5 | ++i; 6 | const j = i; 7 | return j; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tests/lambda_bad_arg2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const f = [](int a) -> int { return a; }; 5 | return f("pok"); 6 | } 7 | -------------------------------------------------------------------------------- /tests/lambda_capture_bad4.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable x = 5; 5 | const f = [x]{ x = 1;}; 6 | return x; 7 | } 8 | -------------------------------------------------------------------------------- /tests/lambda_double_capture1.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | int main() { 4 | const x = 2; 5 | return [&] { return [&] { return x; }();}(); 6 | } 7 | -------------------------------------------------------------------------------- /tests/lambda_move_arg1.znn: -------------------------------------------------------------------------------- 1 | // 6 2 | 3 | int main() { 4 | const f = [] (int index)->int { return move(index); }; 5 | return f(6); 6 | } 7 | -------------------------------------------------------------------------------- /tests/noreturn_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | noreturn f() { 4 | return; 5 | } 6 | 7 | int main() { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/static_if_bad5.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | static if (int) 5 | return 1; 6 | else 7 | return 2; 8 | } 9 | -------------------------------------------------------------------------------- /tests/string_implicit_copy1.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | int main() { 4 | const string? s = "pok"; 5 | const u = s; 6 | return u^.size(); 7 | } 8 | -------------------------------------------------------------------------------- /tests/ternary_operator6.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | int main() { 4 | const b = false; 5 | const c = false; 6 | return b ? 1 : c ? 2 : 3; 7 | } 8 | -------------------------------------------------------------------------------- /tests/ternary_operator_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable x = 2; 5 | (true ? x : 1) = 3; 6 | return x; 7 | } 8 | -------------------------------------------------------------------------------- /tests/arithmetic2.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | int main() { 4 | const a = 5; 5 | if (a < 0.123) 6 | return 1; 7 | return 2; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tests/bad_template_param.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | struct A { 5 | }; 6 | 7 | int main() { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/copy_function_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | 4 | int copy(int*) = default; 5 | 6 | 7 | int main() { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/enum_bad5.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | enum E { 4 | E1 5 | }; 6 | 7 | int main() { 8 | const e = E::X; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/extern_function1.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | import "std/math.znn"; 4 | 5 | int main() { 6 | const i = as_int(sqrt(25)); 7 | return i; 8 | } 9 | -------------------------------------------------------------------------------- /tests/import_public3/main.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | import "fun.znn"; 3 | 4 | int main() { 5 | const s = S1(S2(true), 5); 6 | return s.a; 7 | } 8 | -------------------------------------------------------------------------------- /tests/import_type_alias1/main.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | import "input2.znn"; 4 | import "input3.znn"; 5 | 6 | int main() { 7 | return get(); 8 | } 9 | -------------------------------------------------------------------------------- /tests/import_vector/main.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "struct1.znn"; 4 | 5 | int main() { 6 | const s = get(); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/incomplete_struct_import/main.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "fun.znn"; 4 | 5 | int main() { 6 | S s = getS(); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/increment_op1.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | int main() { 4 | mutable i = 0; 5 | ++i; 6 | ++i; 7 | --i; 8 | return i; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/lambda_capture_by_ref_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const x = 5; 5 | const f = [&x]{ x = 1;}; 6 | return x; 7 | } 8 | -------------------------------------------------------------------------------- /tests/lambda_double_capture2.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | int main() { 4 | mutable x = 2; 5 | return [&] { return [&] { x = 3; return x; }();}(); 6 | } 7 | -------------------------------------------------------------------------------- /tests/static_variable_bad4.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | static mutable a = 1; 5 | static mutable a = 2; 6 | return a; 7 | } 8 | -------------------------------------------------------------------------------- /tests/subscript6.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int operator[](int a) { 4 | return 0; 5 | } 6 | 7 | int main() { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/const_ptr_to_mut_ptr.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | int main() { 4 | mutable v = 5; 5 | const z = &v; 6 | int mutable* y = z; 7 | return *y; 8 | } 9 | -------------------------------------------------------------------------------- /tests/function_attribute_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | 4 | [@bogus] 5 | void f() { 6 | } 7 | 8 | int main() { 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/import_public2/main.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | import "fun.znn"; 3 | 4 | int main() { 5 | int a = getNum(); 6 | int b = getNum2(); 7 | return b; 8 | } 9 | -------------------------------------------------------------------------------- /tests/incomplete_struct_import2/main.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "fun.znn"; 4 | 5 | int main() { 6 | discard getS(); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/lambda_bad_arg3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const f = [] (int a, int a) -> int { return a; }; 5 | return f(1, 2); 6 | } 7 | -------------------------------------------------------------------------------- /tests/lambda_implicit_ref_capture_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const x = 5; 5 | const f = [&]{ x = 1;}; 6 | return x; 7 | } 8 | -------------------------------------------------------------------------------- /tests/mixin_escape_char1.znn: -------------------------------------------------------------------------------- 1 | // 6 2 | 3 | int main() { 4 | static const s = "const a = \"foobar\";"; 5 | mixin s; 6 | return a.size(); 7 | } 8 | -------------------------------------------------------------------------------- /tests/named_args1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | void f(int a, string) { 4 | } 5 | 6 | int main() { 7 | f(.a = 3); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/no_copy1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void f(T a) { 5 | T b = a; 6 | } 7 | 8 | int main() { 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/pointer_implicit_copy1.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | int main() { 4 | const x = 5; 5 | const int*? s = &x; 6 | const u = s; 7 | return **u; 8 | } 9 | -------------------------------------------------------------------------------- /tests/ternary_operator4.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | int main() { 4 | mutable x = 1; 5 | bool b = false; 6 | mutable y = b ? x : 3; 7 | return y; 8 | } 9 | -------------------------------------------------------------------------------- /tests/union2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | union V { 4 | int a; 5 | bool a; 6 | }; 7 | 8 | int main() { 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/variadic_args_bad7.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void f() { 5 | } 6 | 7 | int main() { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/bad_template_param_type.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void f() { 5 | } 6 | 7 | int main() { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/duplicate_member.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct S { 4 | int elem; 5 | int elem; 6 | }; 7 | 8 | int main() { 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/incomplete_type2/main.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "s.znn"; 4 | 5 | void g(S) { 6 | } 7 | 8 | int main() { 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/infinite_struct2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | struct X { 5 | X x; 6 | }; 7 | 8 | int main() { 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/lambda_capture_by_ref1.znn: -------------------------------------------------------------------------------- 1 | // 6 2 | 3 | int main() { 4 | mutable x = 5; 5 | const f = [&x]{ return x;}; 6 | x = 6; 7 | return f(); 8 | } 9 | -------------------------------------------------------------------------------- /tests/ranged_loop_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable sum = 0; 5 | for (it : 5) { 6 | } 7 | return 0; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tests/shadow_var1.znn: -------------------------------------------------------------------------------- 1 | // 4 2 | 3 | int main() { 4 | mutable a = 1; 5 | a += 2; 6 | [@shadow] 7 | const a = a + 1; 8 | return a; 9 | } 10 | -------------------------------------------------------------------------------- /tests/template_requirement1.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | template requires (N > 0) 4 | int f() { return N; } 5 | 6 | int main() { 7 | return f<1>(); 8 | } 9 | -------------------------------------------------------------------------------- /tests/template_value_param_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void f() { 5 | } 6 | 7 | int main() { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/ternary_operator3.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | int main() { 4 | mutable x = 0; 5 | mutable y = 0; 6 | (true ? x : y) = 3; 7 | return x + 2 * y; 8 | } 9 | -------------------------------------------------------------------------------- /tests/array_generate1.znn: -------------------------------------------------------------------------------- 1 | // 4 2 | 3 | int main() { 4 | const v = array_generate<10, int>([](int ind) -> int { return ind * 2; }); 5 | return v[2]; 6 | } 7 | -------------------------------------------------------------------------------- /tests/array_negative_size.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void f() {} 5 | 6 | int main() { 7 | f(); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/bad_params.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | int a; 5 | }; 6 | 7 | int main() { 8 | const x = X(1); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/bad_params2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int f() { 4 | return 1; 5 | } 6 | 7 | int main() { 8 | const x = f(); 9 | return x; 10 | } 11 | -------------------------------------------------------------------------------- /tests/concept_type_import3/input2.znn: -------------------------------------------------------------------------------- 1 | 2 | 3 | export template requires is_concept 4 | C* cast_to(U* u) { 5 | unchecked return u; 6 | } 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/destructor_bad7.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | }; 5 | 6 | void destruct(X x) { 7 | } 8 | 9 | int main() { 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/discard4.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | struct X { 4 | int a; 5 | }; 6 | 7 | int main() { 8 | discard get_member_type(X, 0); 9 | return 3; 10 | } 11 | -------------------------------------------------------------------------------- /tests/duplicate_fun_param.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | void f(int a, int a) { 4 | } 5 | 6 | int main() { 7 | f(1, 2); 8 | return 0; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/if_statement_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | if (true) 5 | mutable a = 5; 6 | else 7 | ++a; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/import_public/main.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | import "fun.znn"; 3 | 4 | int main() { 5 | int a = getNum(); 6 | int b = getNum2(); 7 | return b; 8 | } 9 | -------------------------------------------------------------------------------- /tests/infinite_struct1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | struct X { 5 | X> x; 6 | }; 7 | 8 | int main() { 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/lambda_capture_by_move_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable a = 5; 5 | const f = [move(a)]{ return a;}; 6 | return a; 7 | } 8 | -------------------------------------------------------------------------------- /tests/lambda_double_capture_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable x = 2; 5 | return [x] { return [&] { x = 3; return x; }();}(); 6 | } 7 | -------------------------------------------------------------------------------- /tests/lambda_double_capture_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable x = 2; 5 | return [&] { return [x] { x = 3; return x; }();}(); 6 | } 7 | -------------------------------------------------------------------------------- /tests/method7.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | void g(int x, int y) { 4 | } 5 | 6 | int main() { 7 | int x = 1; 8 | x.g(1, 2); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/move_in_loop_bad6.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable y = true; 5 | while (move(y)) { 6 | } 7 | return 0; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tests/optional2.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | int main() { 4 | mutable int? x = 5; 5 | if (x) 6 | return *x; 7 | else 8 | return 4; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/static_for_bad8.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable res = 0; 5 | static for (i = res; i < 5; ++i) { 6 | } 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/static_if_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const a = 1; 5 | static if (true) 6 | discard move(a); 7 | return move(a); 8 | } 9 | -------------------------------------------------------------------------------- /tests/static_mutable_variable4.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | int main() { 4 | static mutable a = 5; 5 | const f = [] { return a; }; 6 | ++a; 7 | return f(); 8 | } 9 | -------------------------------------------------------------------------------- /tests/static_mutable_variable_bad5.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | static mutable a = 1; 5 | const b = true; 6 | return b ? ++a : 5; 7 | } 8 | -------------------------------------------------------------------------------- /tests/static_mutable_variable_bad6.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | static mutable a = 3; 5 | mutable b = 1; 6 | a = b; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/static_variable_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X {}; 4 | 5 | int main() { 6 | static const a = get_member_name(X, 0); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/template_instance_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void f() { 5 | } 6 | 7 | int main() { 8 | f<1>(); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/template_requirement_bad4.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template requires (X) 4 | int f() { return N; } 5 | 6 | int main() { 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/type_alias1.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | using type1 = int; 4 | 5 | type1 get() { 6 | return 1; 7 | } 8 | 9 | int main() { 10 | return get(); 11 | } 12 | -------------------------------------------------------------------------------- /tests/type_alias_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | struct X { 5 | }; 6 | 7 | using double = X; 8 | 9 | void main() { 10 | } 11 | -------------------------------------------------------------------------------- /tests/unknown_concept.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template requires unknown 4 | void f(T t) { 5 | } 6 | 7 | int main() { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/array_bad_size.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | struct S { 5 | T[N] elems; 6 | }; 7 | 8 | int main() { 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/array_literal_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X {}; 4 | 5 | int main() { 6 | const x = X(); 7 | const a = {x}; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/compile_error_fun1.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | int main() { 4 | static const a = 1; 5 | static if (a == 2) 6 | compile_error("efwpok"); 7 | return 1; 8 | } 9 | -------------------------------------------------------------------------------- /tests/copy_function_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | }; 5 | 6 | X copy(int*) = default; 7 | 8 | 9 | int main() { 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/copy_function_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | }; 5 | 6 | X copy(X) = default; 7 | 8 | 9 | int main() { 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/destructor_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | }; 5 | 6 | void destruct(int* x) { 7 | } 8 | 9 | int main() { 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/discard3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct A {}; 4 | 5 | A f() { 6 | return A(); 7 | } 8 | 9 | int main() { 10 | f(); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/enum_size_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | enum E { 4 | X 5 | }; 6 | 7 | int main() { 8 | const x = enum_count(E); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/import/main.znn: -------------------------------------------------------------------------------- 1 | // 10 2 | import "struct1.znn"; 3 | 4 | 5 | int main() { 6 | Struct1 s1 = Struct1(getSecond(4, 5, 6), true); 7 | return get(&s1); 8 | } 9 | -------------------------------------------------------------------------------- /tests/import_methods2/main.znn: -------------------------------------------------------------------------------- 1 | // 7 2 | import "s1.znn"; 3 | 4 | 5 | int main() { 6 | mutable x = X(10); 7 | x.set(5); 8 | return x.get(); 9 | } 10 | -------------------------------------------------------------------------------- /tests/incomplete_enum3/main.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "fun1.znn"; 4 | import "fun2.znn"; 5 | 6 | 7 | int main() { 8 | return f(E::E1); 9 | } 10 | -------------------------------------------------------------------------------- /tests/lambda_bad_no_capture1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable value = 5; 5 | const f = [] -> int { return value; }; 6 | return f(); 7 | } 8 | -------------------------------------------------------------------------------- /tests/lambda_implicit_return4.znn: -------------------------------------------------------------------------------- 1 | // 4 2 | 3 | int main() { 4 | const f = [] (bool b, int a) { if (!b) return 0; else return a; }; 5 | return f(true, 4); 6 | } 7 | -------------------------------------------------------------------------------- /tests/move_in_ternaty_op2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const x = 4; 5 | const b = true; 6 | const r = (b ? move(x) : 4); 7 | return x; 8 | } 9 | -------------------------------------------------------------------------------- /tests/shadow_var2.znn: -------------------------------------------------------------------------------- 1 | // 4 2 | 3 | int main() { 4 | mutable a = "pok"; 5 | a += "a"; 6 | [@shadow] 7 | const a = a.size(); 8 | return a; 9 | } 10 | -------------------------------------------------------------------------------- /tests/static_mutable_variable_bad4.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | static mutable a = 1; 5 | const f = [] { ++a; }; 6 | f(); 7 | return a; 8 | } 9 | -------------------------------------------------------------------------------- /tests/template_requirement_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template requires (N + 1) 4 | int f() { return N; } 5 | 6 | int main() { 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/type_variable1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | struct X { 5 | }; 6 | 7 | int main() { 8 | const x = X; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/variable_decl_inside_if_bad.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | if (const x = 5) 5 | return 0; 6 | else 7 | return 1; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tests/variadic_args_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void eat(MyArgs my_args) { 5 | } 6 | 7 | int main() { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/variadic_args_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void eat(MyArgs... my_args) { 5 | } 6 | 7 | int main() { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/variadic_args_bad6.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void f(Args... m, int a) { 5 | } 6 | 7 | int main() { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/array_literal1.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | struct X { int a; }; 4 | 5 | int main() { 6 | const x = X(1); 7 | const a = {move(x)}; 8 | return a[0].a; 9 | } 10 | -------------------------------------------------------------------------------- /tests/attribute_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct @someattr {}; 4 | 5 | [@someattr] 6 | struct X { 7 | }; 8 | 9 | int main() { 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/attribute_bad5.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template requires has_attribute 4 | void f() { 5 | } 6 | 7 | int main() { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/empty_array.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | int main() { 4 | const a = {}; 5 | mutable sum = 1; 6 | for (x : a) 7 | sum += *x; 8 | return sum; 9 | } 10 | -------------------------------------------------------------------------------- /tests/import_circular2/main.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | import "fun.znn"; 4 | 5 | export int g() { 6 | return 1; 7 | } 8 | 9 | int main() { 10 | return f(); 11 | } 12 | -------------------------------------------------------------------------------- /tests/import_enum_conflict/main.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "struct1.znn"; 4 | import "struct2.znn"; 5 | 6 | 7 | int main() { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/import_methods/main.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | import "s1.znn"; 3 | 4 | 5 | int main() { 6 | mutable x = X(10); 7 | x.set(5); 8 | return *x.get(); 9 | } 10 | -------------------------------------------------------------------------------- /tests/lambda_capture_bad_moved2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable a = 5; 5 | const f = [a]{ const u = move(a); return a;}; 6 | return a; 7 | } 8 | -------------------------------------------------------------------------------- /tests/long_arithmetic1.znn: -------------------------------------------------------------------------------- 1 | // 7 2 | 3 | import "std/math.znn"; 4 | 5 | int main() { 6 | const a = 1000.as_long() * 1000000000 + 7; 7 | return as_int(a % 10); 8 | } 9 | -------------------------------------------------------------------------------- /tests/method6.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | void g(int x, int y) { 4 | } 5 | 6 | int main() { 7 | int x = 1; 8 | x.g(.x = 1, .y = 2); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/move_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable y = 1; 5 | if (move(y) == 1) { 6 | return y; 7 | } 8 | return 0; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/slice_implicit_copy1.znn: -------------------------------------------------------------------------------- 1 | // 4 2 | 3 | int main() { 4 | const a = {1, 2, 3, 4}; 5 | const int[]? b = a.slice(); 6 | const s = b; 7 | return (*s)[3]; 8 | } 9 | -------------------------------------------------------------------------------- /tests/static_for_bad6.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable res = 0; 5 | static for (i = 0; i < int; i += 2) 6 | res += i; 7 | return res; 8 | } 9 | -------------------------------------------------------------------------------- /tests/static_if_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const b = true; 5 | static if (b) 6 | return 1; 7 | else 8 | return 2; 9 | } 10 | -------------------------------------------------------------------------------- /tests/static_variable_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { int a;}; 4 | 5 | int main() { 6 | static const int a = get_member_name(X, 0); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/struct_default_args_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | int a; 5 | int b = 1; 6 | }; 7 | 8 | void main() { 9 | const x = X(); 10 | } 11 | -------------------------------------------------------------------------------- /tests/template_requirement_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template requires (N > 0) 4 | int f() { return N; } 5 | 6 | int main() { 7 | return f<-1>(); 8 | } 9 | -------------------------------------------------------------------------------- /tests/type_argument1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | 4 | template 5 | int f(T*) { 6 | return 1; 7 | } 8 | 9 | int main() { 10 | return f(&bool); 11 | } 12 | -------------------------------------------------------------------------------- /tests/union3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | union V { 4 | int a; 5 | bool b; 6 | }; 7 | 8 | int main() { 9 | const v = V::a(true); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/variadic_args_bad10.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void f(Args*...) { 5 | } 6 | 7 | int main() { 8 | f(1); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/virtual_function_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | }; 5 | 6 | void f(virtual X* x) { 7 | } 8 | 9 | int main() { 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/compile_error_fun2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | static const a = 1; 5 | static if (a == 1) 6 | compile_error("efwpok"); 7 | return 1; 8 | } 9 | -------------------------------------------------------------------------------- /tests/destructor_not_exported1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | export struct X { 4 | }; 5 | 6 | void destruct(X*) { 7 | } 8 | 9 | int main() { 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/destructor_wrong_file1/main.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "struct1.znn"; 4 | 5 | void destruct(X*) { 6 | } 7 | 8 | int main() { 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/enum_bad6.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | enum E { 4 | E1 5 | }; 6 | 7 | struct S { 8 | }; 9 | 10 | int main() { 11 | const e = S::X; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/forgot_extern.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | void f(); 5 | }; 6 | 7 | int main() { 8 | const x = X(); 9 | x.f(); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/function_type_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int fa(int a) { 4 | return a * 2; 5 | } 6 | 7 | int main() { 8 | const a = fa; 9 | return a(3.1); 10 | } 11 | -------------------------------------------------------------------------------- /tests/incomplete_enum2/main.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "fun1.znn"; 4 | import "fun2.znn"; 5 | 6 | 7 | int main() { 8 | f(); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/incomplete_type1/main.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "s.znn"; 4 | 5 | S g() { 6 | embed { 7 | } 8 | } 9 | 10 | int main() { 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/lambda2.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | int g() { 4 | return 2; 5 | } 6 | 7 | int main() { 8 | const f = [] (int) -> int { return g(); }; 9 | return f(1); 10 | } 11 | -------------------------------------------------------------------------------- /tests/lambda_capture1.znn: -------------------------------------------------------------------------------- 1 | // 6 2 | 3 | struct X { 4 | }; 5 | 6 | int main() { 7 | mutable x = 5; 8 | const f = [x]{ return 1 + x;}; 9 | return f(); 10 | } 11 | -------------------------------------------------------------------------------- /tests/lambda_capture_bad_moved1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable x = 5; 5 | const y = move(x); 6 | const f = [&x]{ x = 1;}; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/modify_function_arg.znn: -------------------------------------------------------------------------------- 1 | // 4 2 | 3 | void f(mutable int a) { 4 | a = 5; 5 | } 6 | 7 | int main() { 8 | int a = 4; 9 | f(a); 10 | return a; 11 | } 12 | -------------------------------------------------------------------------------- /tests/modify_function_arg2.znn: -------------------------------------------------------------------------------- 1 | // 4 2 | 3 | void f(mutable int a) { 4 | a = 5; 5 | } 6 | 7 | int main() { 8 | int a = 4; 9 | f(a); 10 | return a; 11 | } 12 | -------------------------------------------------------------------------------- /tests/move_in_array_bad.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable y = 1; 5 | discard move(y); 6 | mutable x = {y, 5}; 7 | return x[0]; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tests/move_in_array_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable y = 1; 5 | mutable x = {move(y), 5}; 6 | y = 2; 7 | return x[0]; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tests/move_in_loop3.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | int main() { 4 | mutable x = 5; 5 | while (true) { 6 | discard move(x); 7 | break; 8 | } 9 | return 1; 10 | } 11 | -------------------------------------------------------------------------------- /tests/mutable_pointer_conversion2.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | int main() { 4 | mutable int x = 5; 5 | int mutable* p = &x; 6 | int* r = p; 7 | return *r; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tests/static_for_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable res = 0; 5 | static for (i = 0; i < i + 1; i += 2) 6 | res += i; 7 | return res; 8 | } 9 | -------------------------------------------------------------------------------- /tests/static_mutable_variable1.znn: -------------------------------------------------------------------------------- 1 | // 15 2 | 3 | int main() { 4 | static mutable res = 0; 5 | static for (i = 0; i < 6; ++i) 6 | res += i; 7 | return res; 8 | } 9 | -------------------------------------------------------------------------------- /tests/static_mutable_variable_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | static mutable res = 0; 5 | for (i = 0; i < 10; ++i) 6 | ++res; 7 | return res; 8 | } 9 | -------------------------------------------------------------------------------- /tests/static_variable_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int get() { 4 | return 5; 5 | } 6 | 7 | int main() { 8 | static const a = get(); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/string_template1.znn: -------------------------------------------------------------------------------- 1 | // 7 2 | 3 | template 4 | int f() { 5 | return T.size(); 6 | } 7 | 8 | int main() { 9 | return f<"dupa...">(); 10 | } 11 | -------------------------------------------------------------------------------- /tests/union_member_access1.znn: -------------------------------------------------------------------------------- 1 | // 4 2 | 3 | union V { 4 | int a; 5 | string s; 6 | }; 7 | 8 | int main() { 9 | const v = V::a(4); 10 | return v.a; 11 | } 12 | -------------------------------------------------------------------------------- /tests/unique_ptr.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | import "std/box.znn"; 4 | 5 | int main() { 6 | mutable ptr = box(3); 7 | const ptr2 = move(ptr); 8 | return *ptr2; 9 | } 10 | -------------------------------------------------------------------------------- /tests/variable_decl_inside_if_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | if (const x = 5; x + 1) 5 | return 0; 6 | else 7 | return 1; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tests/variadic_args_bad9.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void f(Args*...) { 5 | } 6 | 7 | int main() { 8 | f(1); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/const_pointer_member.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | struct Y { 4 | int* a; 5 | }; 6 | 7 | int main() { 8 | const a = 5; 9 | const y = Y(&a); 10 | return *y.a; 11 | } 12 | -------------------------------------------------------------------------------- /tests/empty_array2.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | template 4 | T[0] get_empty() { 5 | return {}; 6 | } 7 | 8 | int main() { 9 | return get_empty().size() + 1; 10 | } 11 | -------------------------------------------------------------------------------- /tests/function_arg_redef.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | void f(int a) { 4 | int a = 5; 5 | } 6 | 7 | int main() { 8 | int a = 4; 9 | f(a); 10 | return a; 11 | } 12 | -------------------------------------------------------------------------------- /tests/incomplete_array/main.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "x.znn"; 4 | 5 | extern X[3] get(); 6 | 7 | int main() { 8 | const a = get(); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/incomplete_enum/fun2.znn: -------------------------------------------------------------------------------- 1 | 2 | import "fun.znn"; 3 | 4 | export Enum1 get(bool b) { 5 | if (b) 6 | return get1(); 7 | else 8 | return get2(); 9 | } 10 | -------------------------------------------------------------------------------- /tests/io_error1.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | import "std/io.znn"; 4 | 5 | int main() { 6 | if (const file = open_file_r("foobarfoo123")) 7 | return 1; 8 | return 2; 9 | } 10 | -------------------------------------------------------------------------------- /tests/move_in_loop4.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | int main() { 4 | mutable x = 5; 5 | while (true) { 6 | discard move(x); 7 | return 2; 8 | } 9 | return 1; 10 | } 11 | -------------------------------------------------------------------------------- /tests/move_in_loop_bad7.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable y = true; 5 | for (i = 0; i < 5 && move(y); ++i) { 6 | } 7 | return 0; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tests/optional_bad_conversion1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | T get(T? a) { 5 | embed {} 6 | } 7 | 8 | int main() { 9 | return get(null); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/shadow_var_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable a = 1; 5 | a += 2; 6 | [@shadow] 7 | const a = a; 8 | a += 2; 9 | return a; 10 | } 11 | -------------------------------------------------------------------------------- /tests/static_if_bad4.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const b = true; 5 | static if (const a = b) 6 | return 1; 7 | else 8 | return 2; 9 | } 10 | -------------------------------------------------------------------------------- /tests/template_value_param_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | }; 5 | 6 | template 7 | void f() { 8 | } 9 | 10 | int main() { 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/template_value_param_bad4.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void f() { 5 | } 6 | 7 | int main() { 8 | f(); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/try_op_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int f() { 4 | int? a = null; 5 | discard try a; 6 | return 1; 7 | } 8 | 9 | int main() { 10 | return f(); 11 | } 12 | -------------------------------------------------------------------------------- /src/lexer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "token.h" 4 | 5 | extern WithErrorLine lex(const string& input, CodeLoc initialPos, const string& eofTokenValue); 6 | -------------------------------------------------------------------------------- /tests/concept_type_templated3.znn: -------------------------------------------------------------------------------- 1 | // 4 2 | 3 | int get(invoke* i) { 4 | return i^.invoke() + 1; 5 | } 6 | 7 | int main() { 8 | return get(&[] { return 3; }); 9 | } 10 | -------------------------------------------------------------------------------- /tests/destructor_bad6.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | struct X { 5 | }; 6 | 7 | void destruct(X* x) { 8 | } 9 | 10 | int main() { 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/for_loop.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | int x = 1; 5 | int n = 6; 6 | for (int i = 0; i < n; i = i + 2); 7 | x = x + i; 8 | return x; 9 | } 10 | -------------------------------------------------------------------------------- /tests/function_method3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | void increment(int mutable* a) { 4 | *a = *a + 1; 5 | } 6 | 7 | int main() { 8 | 3.increment(); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/hash_set_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "std/hash_set.znn"; 4 | 5 | struct X {}; 6 | 7 | int main() { 8 | const a = hash_set(); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/import_double/struct2.znn: -------------------------------------------------------------------------------- 1 | export import "print.znn"; 2 | 3 | struct Struct2 { 4 | X u; 5 | }; 6 | 7 | 8 | template 9 | void f2(T t) { 10 | X x = X(1); 11 | } 12 | -------------------------------------------------------------------------------- /tests/import_public4/main.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | import "fun.znn"; 3 | import "struct.znn"; 4 | 5 | int main() { 6 | int a = getNum(); 7 | int b = getNum2(); 8 | return b; 9 | } 10 | -------------------------------------------------------------------------------- /tests/is_enum_concept_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template requires is_enum 4 | int f(E e1) { 5 | return 0; 6 | } 7 | 8 | int main() { 9 | return f(5); 10 | } 11 | -------------------------------------------------------------------------------- /tests/lambda_capture_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | }; 5 | 6 | int main() { 7 | const x = X(); 8 | const f = [x]{ return 1;}; 9 | return f(); 10 | } 11 | -------------------------------------------------------------------------------- /tests/move6.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | struct X { 4 | int value; 5 | }; 6 | 7 | int main() { 8 | const value = 5; 9 | const x = X(move(value)); 10 | return x.value; 11 | } 12 | -------------------------------------------------------------------------------- /tests/range1.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | import "std/range.znn"; 4 | 5 | 6 | int main() { 7 | mutable ret = 1; 8 | for (i : range(5, 0)) 9 | ++ret; 10 | return ret; 11 | } 12 | -------------------------------------------------------------------------------- /tests/shadow_var3.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | int main() { 4 | mutable a = "pok"; 5 | a += "a"; 6 | discard move(a); 7 | [@shadow] 8 | const a = 3; 9 | return a; 10 | } 11 | -------------------------------------------------------------------------------- /tests/static_if_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void f() { 5 | static if (B) 6 | blabla(); 7 | } 8 | 9 | int main() { 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/subscript1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct A { 4 | string s; 5 | }; 6 | 7 | int main() { 8 | const a = A("dupa"); 9 | const b = a[0]; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/ternary_operator5.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | import "std/math.znn"; 4 | 5 | int main() { 6 | bool b = false; 7 | const y = b ? 1 : 1.5; 8 | return as_int(2 * y); 9 | } 10 | -------------------------------------------------------------------------------- /tests/constructor_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct S { 4 | int a; 5 | }; 6 | 7 | S() { 8 | return S::S(1); 9 | } 10 | 11 | int main() { 12 | return S(1).a; 13 | } 14 | -------------------------------------------------------------------------------- /tests/entry_point1.znn: -------------------------------------------------------------------------------- 1 | // 4 2 | 3 | [@entry_point] 4 | int f(bool a) { 5 | return a ? 1 : 4; 6 | } 7 | 8 | int main() { 9 | embed { 10 | return f(false); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/enum_equals.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | enum E { E1, E2 }; 4 | 5 | int main() { 6 | mutable e = E::E1; 7 | if (e == E::E1) 8 | return 1; 9 | else 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/hash_map_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "std/hash_map.znn"; 4 | 5 | struct X {}; 6 | 7 | int main() { 8 | const a = hash_map(); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/import_circular/struct1.znn: -------------------------------------------------------------------------------- 1 | import "main.znn"; 2 | 3 | export int fun2() { 4 | return 2 + fun1(false); 5 | } 6 | 7 | export struct Struct1 { 8 | bool b; 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /tests/incomplete_enum/fun.znn: -------------------------------------------------------------------------------- 1 | 2 | import "enum1.znn"; 3 | 4 | export Enum1 get1() { 5 | return Enum1::E2; 6 | } 7 | 8 | export Enum1 get2() { 9 | return Enum1::E3; 10 | } 11 | -------------------------------------------------------------------------------- /tests/instance_context2/fun.znn: -------------------------------------------------------------------------------- 1 | 2 | export concept C1 { 3 | int g(T); 4 | }; 5 | 6 | export template requires C1 7 | int f(T t) { 8 | return 4 + g(move(t)); 9 | } 10 | -------------------------------------------------------------------------------- /tests/io_error2.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | import "std/io.znn"; 4 | 5 | int main() { 6 | if (const file = open_file_w("foobarfoo123/wefpok")) 7 | return 1; 8 | return 2; 9 | } 10 | -------------------------------------------------------------------------------- /tests/lambda10.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | int main() { 4 | const f = [] { 5 | const g = [] { 6 | return 3; 7 | }; 8 | return g(); 9 | }; 10 | return f(); 11 | } 12 | -------------------------------------------------------------------------------- /tests/lambda_implicit_ref_capture1.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | int main() { 4 | mutable x = 1; 5 | mutable y = 2; 6 | const f = [&] { ++x; ++y; }; 7 | f(); 8 | return y + x; 9 | } 10 | -------------------------------------------------------------------------------- /tests/lambda_implicit_void2.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | int main() { 4 | mutable a = 3; 5 | const f = [](int mutable* a) { 6 | *a = 2; 7 | }; 8 | f(&a); 9 | return a; 10 | } 11 | -------------------------------------------------------------------------------- /tests/static_for10.znn: -------------------------------------------------------------------------------- 1 | // 6 2 | 3 | int main() { 4 | mutable res = 0; 5 | static for (i = 0; i < 5; ++i) { 6 | res += i; 7 | ++i; 8 | } 9 | return res; 10 | } 11 | -------------------------------------------------------------------------------- /tests/static_while_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable res = 0; 5 | static mutable a = 0; 6 | static while (a < res) { 7 | } 8 | return res; 9 | } 10 | -------------------------------------------------------------------------------- /tests/template_value_param_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | struct S { 5 | }; 6 | 7 | int main() { 8 | const s = S(); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/ternary_operator_static1.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | int main() { 4 | static const b = true; 5 | static const y = b ? 2 : 3; 6 | const a = array_repeat(5); 7 | return a.size(); 8 | } 9 | -------------------------------------------------------------------------------- /tests/union_member_access_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | union V { 4 | int a; 5 | string s; 6 | }; 7 | 8 | int main() { 9 | const v = V::a(4); 10 | return v.foo; 11 | } 12 | -------------------------------------------------------------------------------- /tests/compile_time_array_size.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | int main() { 4 | static const num = 4; 5 | static const num2 = num + 1; 6 | const int[num2] a = {1, 2, 3, 4, 5}; 7 | return a[1]; 8 | } 9 | -------------------------------------------------------------------------------- /tests/compile_time_array_size_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable num = 4; 5 | const num2 = num + 1; 6 | const int[num2] a = {1, 2, 3, 4, 5}; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/concept_type11.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | int get(invoke* i) { 4 | return i^.invoke(); 5 | } 6 | 7 | int main() { 8 | return get(&[]{ return 2; }) + get(&[]{ return 3; }); 9 | } 10 | -------------------------------------------------------------------------------- /tests/concept_type_bad13.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int calc(invoke* f) { 4 | return 2 * f^.invoke(1); 5 | } 6 | 7 | int main() { 8 | return calc(&[] { return 1; }); 9 | } 10 | -------------------------------------------------------------------------------- /tests/concept_type_cast_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "std/any.znn"; 4 | 5 | struct X {}; 6 | 7 | int main() { 8 | const x = X(); 9 | return **(x.cast_to()); 10 | } 11 | -------------------------------------------------------------------------------- /tests/concept_type_value_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "std/any.znn"; 4 | import "std/vector.znn"; 5 | 6 | int main() { 7 | const v = vector(); 8 | return 1; 9 | } 10 | -------------------------------------------------------------------------------- /tests/constructor7.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | struct S { 4 | int x; 5 | }; 6 | 7 | S() { 8 | return S::S(1); 9 | } 10 | 11 | int main() { 12 | const s = S(); 13 | return s.x; 14 | } 15 | -------------------------------------------------------------------------------- /tests/double_fun.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int f(int x) { 4 | return x; 5 | } 6 | 7 | int f(int y) { 8 | return 2 * y; 9 | } 10 | 11 | int main() { 12 | return f(5); 13 | } 14 | -------------------------------------------------------------------------------- /tests/enum_import/main.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | import "enum1.znn"; 3 | 4 | int main() { 5 | const e = E1::V1; 6 | switch (e) { 7 | default { 8 | return 1; 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/import_concept_bad1/main.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "input2.znn"; 4 | 5 | template requires C 6 | void g() { 7 | } 8 | 9 | int main() { 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/import_struct_conflict/main.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "struct1.znn"; 4 | import "struct2.znn"; 5 | 6 | 7 | int main() { 8 | // const s = S(); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/import_union_conflict/main.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "struct1.znn"; 4 | import "struct2.znn"; 5 | 6 | 7 | int main() { 8 | // const s = S(); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/lambda_implicit_void1.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | int main() { 4 | mutable res = 0; 5 | const f = [&](int a) { 6 | res = a; 7 | }; 8 | const x = f(3); 9 | return res; 10 | } 11 | -------------------------------------------------------------------------------- /tests/mixin3.znn: -------------------------------------------------------------------------------- 1 | // 10 2 | 3 | template 4 | int fun() { 5 | return N; 6 | } 7 | 8 | int main() { 9 | static const stmt = "return fun<10>();"; 10 | mixin stmt; 11 | } 12 | -------------------------------------------------------------------------------- /tests/mut_ptr_to_const_ptr.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | void f(int mutable* v) { 4 | } 5 | 6 | int main() { 7 | const v = 5; 8 | const z = &v; 9 | f(z); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/mutable_pointer_conversion3.znn: -------------------------------------------------------------------------------- 1 | // 72 2 | 3 | int* fun(int mutable* p) { 4 | return p; 5 | } 6 | 7 | int main() { 8 | mutable a = 72; 9 | return *fun(&a); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/pointer_comparison_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | int x = 1; 5 | const y = 2.2; 6 | if (&x == &y) 7 | return 3; 8 | else 9 | return 5; 10 | } 11 | -------------------------------------------------------------------------------- /tests/shadow_static_var_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | static mutable a = 3; 5 | [@shadow] 6 | static const a = a + 1; 7 | a = a + 1; 8 | return a; 9 | } 10 | -------------------------------------------------------------------------------- /tests/static_mutable_variable6.znn: -------------------------------------------------------------------------------- 1 | // 4 2 | 3 | int main() { 4 | mutable res = 0; 5 | static mutable a = 1; 6 | res += a; 7 | a += 2; 8 | res += a; 9 | return res; 10 | } 11 | -------------------------------------------------------------------------------- /tests/static_mutable_variable_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | static mutable res = 0; 5 | const a = 1; 6 | if (a == 0) 7 | ++res; 8 | return res; 9 | } 10 | -------------------------------------------------------------------------------- /tests/static_variable1.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | import "std/math.znn"; 4 | 5 | int main() { 6 | static const double a = 1; 7 | static const b = a / 2; 8 | return as_int(b * 2); 9 | } 10 | -------------------------------------------------------------------------------- /tests/struct_const_member_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | const int a; 5 | }; 6 | 7 | int main() { 8 | mutable x = X(1); 9 | x.a = 3; 10 | return x.a; 11 | } 12 | -------------------------------------------------------------------------------- /tests/subscript4.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | }; 5 | 6 | int operator[](X x) { 7 | return 0; 8 | } 9 | 10 | int main() { 11 | const x = X(); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/subscript5.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | }; 5 | int operator[](X x) { 6 | return 0; 7 | } 8 | 9 | int main() { 10 | const x = X(); 11 | return x[0]; 12 | } 13 | -------------------------------------------------------------------------------- /tests/template_value_param3.znn: -------------------------------------------------------------------------------- 1 | // 97 2 | 3 | template 4 | int f() { 5 | embed { 6 | return int(c); 7 | } 8 | } 9 | 10 | int main() { 11 | return f<'a'>(); 12 | } 13 | -------------------------------------------------------------------------------- /tests/template_value_param4.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | template 4 | int get() { 5 | return N; 6 | } 7 | 8 | int main() { 9 | static mutable a = 3; 10 | return get<(a)>(); 11 | } 12 | -------------------------------------------------------------------------------- /tests/type_alias_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | using int32 = int; 4 | 5 | template 6 | struct X { 7 | T elem; 8 | }; 9 | 10 | using X32 = X; 11 | 12 | void main() { 13 | } 14 | -------------------------------------------------------------------------------- /tests/bad_operator_overload2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int operator + (int a, bool b) { 4 | return a; 5 | } 6 | 7 | int main() { 8 | const x = 5 + false; 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/break_bad.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | void f() { 4 | if (true) 5 | break; 6 | } 7 | 8 | int main() { 9 | for (i = 0; i < 10; ++i) 10 | f(); 11 | return 0; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tests/concept_type_bad11.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int calc(invoke* f) { 4 | return 2 * f^.invoke(); 5 | } 6 | 7 | int main() { 8 | return calc(&[] (int a) { return 1; }); 9 | } 10 | -------------------------------------------------------------------------------- /tests/concept_type_bad12.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int calc(invoke* f) { 4 | return 2 * f^.invoke(1); 5 | } 6 | 7 | int main() { 8 | return calc(&[] { return 1; }); 9 | } 10 | -------------------------------------------------------------------------------- /tests/destructor_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | }; 5 | 6 | void destruct(X* x) { 7 | } 8 | 9 | void destruct(X* x) { 10 | } 11 | 12 | int main() { 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/function_redefinition.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void f() { 5 | } 6 | 7 | template 8 | void f() { 9 | } 10 | 11 | int main() { 12 | return 0; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /tests/import_double/main.znn: -------------------------------------------------------------------------------- 1 | // 10 2 | import "struct1.znn"; 3 | import "struct2.znn"; 4 | 5 | 6 | 7 | int main() { 8 | Struct1 s1 = Struct1(X(5), true); 9 | return get(&s1); 10 | } 11 | -------------------------------------------------------------------------------- /tests/instance_context3/fun.znn: -------------------------------------------------------------------------------- 1 | 2 | 3 | export template 4 | int get_for(T*) { 5 | return 1; 6 | } 7 | 8 | export template 9 | int get(T* t) { 10 | return get_for(t); 11 | } 12 | -------------------------------------------------------------------------------- /tests/operator_value_or2.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | struct X { 4 | int v; 5 | }; 6 | 7 | int main() { 8 | const X? x = null; 9 | const res = move(x) ?? X(1); 10 | return res.v; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /tests/optional3.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | int getOr5(int? a) { 4 | if (a) 5 | return *a; 6 | else 7 | return 5; 8 | } 9 | 10 | int main() { 11 | return getOr5(null); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tests/static_for4.znn: -------------------------------------------------------------------------------- 1 | // 10 2 | 3 | int main() { 4 | mutable res = 0; 5 | static for (i = 0; i < 5; ++i) 6 | static for (j = 0; j < i; ++j) 7 | ++res; 8 | return res; 9 | } 10 | -------------------------------------------------------------------------------- /tests/static_for_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable res = 0; 5 | mutable x = 5; 6 | static for (i = 0; i < x; i += 2) 7 | res += i; 8 | return res; 9 | } 10 | -------------------------------------------------------------------------------- /tests/template_param_name_conflict.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct A { 4 | }; 5 | 6 | template 7 | void f(A a) { 8 | } 9 | 10 | int main() { 11 | f(1); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/type_name_conflict1/fun.znn: -------------------------------------------------------------------------------- 1 | 2 | export template 3 | int get_imp(T*) { 4 | return 2; 5 | } 6 | 7 | export template 8 | int get(T123* t) { 9 | return get_imp(t); 10 | } 11 | -------------------------------------------------------------------------------- /tests/concept_type_templated1.znn: -------------------------------------------------------------------------------- 1 | // 8 2 | 3 | int calc(invoke* f) { 4 | return 2 * f^.invoke(3); 5 | } 6 | 7 | int main() { 8 | return calc(&[] (int a) { return a + 1; }); 9 | } 10 | -------------------------------------------------------------------------------- /tests/continue_bad.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | void f() { 4 | if (true) 5 | continue; 6 | } 7 | 8 | int main() { 9 | for (i = 0; i < 10; ++i) 10 | f(); 11 | return 0; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tests/copy_function_bad4.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | }; 5 | 6 | struct Y { 7 | X x; 8 | }; 9 | 10 | Y copy(Y*) = default; 11 | 12 | 13 | int main() { 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/destructor_bad5.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | struct X { 5 | }; 6 | 7 | template 8 | void destruct(X* x) { 9 | } 10 | 11 | int main() { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/get_member_name_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | int xyz; 5 | string abcdefg; 6 | }; 7 | 8 | int main() { 9 | const a = get_member_name(X, 2); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/get_member_name_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | int xyz; 5 | string abcdefg; 6 | }; 7 | 8 | int main() { 9 | const a = get_member_name(X, -1); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/lambda_capture_by_ref2.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | struct X { 4 | int v; 5 | }; 6 | 7 | int main() { 8 | mutable x = X(5); 9 | const f = [&x]{ x.v = 1;}; 10 | f(); 11 | return x.v; 12 | } 13 | -------------------------------------------------------------------------------- /tests/lambda_implicit_ref_capture2.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | int main() { 4 | mutable x = 1; 5 | mutable y = 2; 6 | const f = [&] { return x + y; }; 7 | ++x; 8 | ++y; 9 | return f(); 10 | } 11 | -------------------------------------------------------------------------------- /tests/mixin_bad5.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X {}; 4 | 5 | void f(X) {} 6 | 7 | int main() { 8 | const x = X(); 9 | mixin "f(move(x));"; 10 | f(move(x)); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/operator_value_or1.znn: -------------------------------------------------------------------------------- 1 | // 4 2 | 3 | int main() { 4 | mutable int? x = null; 5 | mutable res = 0; 6 | res += x ?? 1; 7 | x = 3; 8 | res += x ?? 5; 9 | return res; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/static_for5.znn: -------------------------------------------------------------------------------- 1 | // 10 2 | 3 | int main() { 4 | mutable res = 0; 5 | static for (i = 0; i < 5; ++i) 6 | static for (j = i + 1; j < 5; ++j) 7 | ++res; 8 | return res; 9 | } 10 | -------------------------------------------------------------------------------- /tests/static_for6.znn: -------------------------------------------------------------------------------- 1 | // 10 2 | 3 | int main() { 4 | mutable res = 0; 5 | static for (i = 4; i >= 0; --i) 6 | static for (j = i + 1; j < 5; ++j) 7 | ++res; 8 | return res; 9 | } 10 | -------------------------------------------------------------------------------- /tests/type_comparison2.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | struct X { 4 | }; 5 | 6 | template requires (T == X) 7 | int f(T value) { 8 | return 5; 9 | } 10 | 11 | int main() { 12 | return f(X()); 13 | } 14 | -------------------------------------------------------------------------------- /tests/uninitialized_var.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct S { 4 | int x; 5 | }; 6 | 7 | S() { 8 | return S::S(1); 9 | } 10 | 11 | int main() { 12 | const S s; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/variadic_args_bad8.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | int sum(Arg a, Args... args) { 5 | return sum(move(args)...); 6 | } 7 | 8 | int main() { 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /std/pointer.znn: -------------------------------------------------------------------------------- 1 | 2 | export template 3 | T* implicit_copy(T** p) { 4 | return *p; 5 | } 6 | 7 | export template 8 | T mutable* implicit_copy(T mutable** p) { 9 | return *p; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/calling_method_on_pointer.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int plus5(int* i) { 4 | return *i + 5; 5 | } 6 | 7 | int main() { 8 | int n = 5; 9 | const m = &n; 10 | return m.plus5(); 11 | } 12 | -------------------------------------------------------------------------------- /tests/compile_error_fun3.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | template 4 | void f() { 5 | static if (a == 1) 6 | compile_error("efwpok"); 7 | } 8 | 9 | int main() { 10 | f<2>(); 11 | return 1; 12 | } 13 | -------------------------------------------------------------------------------- /tests/constructor_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | struct S { 5 | T elem; 6 | }; 7 | 8 | template 9 | S() { 10 | return S::S(0); 11 | } 12 | 13 | void main() { 14 | } 15 | -------------------------------------------------------------------------------- /tests/copy_function1.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | struct X { 4 | int a; 5 | }; 6 | 7 | X copy(X*) = default; 8 | 9 | int main() { 10 | const x = X(5); 11 | const y = x.copy(); 12 | return y.a; 13 | } 14 | -------------------------------------------------------------------------------- /tests/destructor_bad4.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | }; 5 | 6 | void destruct(X* x) { 7 | } 8 | 9 | void destruct(X mutable* x) { 10 | } 11 | 12 | int main() { 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/destructor_not_exported2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | export template 4 | struct X { 5 | }; 6 | 7 | template 8 | void destruct(X*) {} 9 | 10 | int main() { 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/entry_point_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | [@entry_point] 4 | template 5 | int f(T a) { 6 | return 1; 7 | } 8 | 9 | int main() { 10 | embed { 11 | return f(false); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/escaped_char1.znn: -------------------------------------------------------------------------------- 1 | // 49 2 | 3 | 4 | int from_char(char c) { 5 | embed { 6 | return int(c); 7 | } 8 | } 9 | 10 | int main() { 11 | return from_char('\n') + from_char('\''); 12 | } 13 | -------------------------------------------------------------------------------- /tests/get_alternative3.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | union X { 4 | string s; 5 | int a; 6 | }; 7 | 8 | int main() { 9 | mutable x = X::a(5); 10 | *get_alternative<1>(&x) = 3; 11 | return x.a; 12 | } 13 | -------------------------------------------------------------------------------- /tests/import/struct1.znn: -------------------------------------------------------------------------------- 1 | export import "print.znn"; 2 | 3 | 4 | export struct Struct1 { 5 | int x; 6 | bool b; 7 | }; 8 | 9 | export int get(Struct1* s) { 10 | return getInt((*s).x); 11 | } 12 | -------------------------------------------------------------------------------- /tests/lambda_implicit_return2.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | int main() { 4 | const f = [](bool a) { 5 | if (a) 6 | return 1; 7 | else 8 | return 2; 9 | }; 10 | return f(true); 11 | } 12 | -------------------------------------------------------------------------------- /tests/less_than_vs_template.znn: -------------------------------------------------------------------------------- 1 | // 15 2 | 3 | int main() { 4 | int n = 5; 5 | const m = &n; 6 | mutable a = 5; 7 | for (i = 0; i < (*m); i = i + 1) 8 | a = a + i; 9 | return a; 10 | } 11 | -------------------------------------------------------------------------------- /tests/member1.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | struct A { 4 | int x; 5 | }; 6 | 7 | A f() { 8 | return A(1); 9 | } 10 | 11 | int main() { 12 | mutable a = A(1); 13 | a.x = 5; 14 | return a.x; 15 | } 16 | -------------------------------------------------------------------------------- /tests/move2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | T get(T a) { 5 | if (false) { 6 | discard move(a); 7 | } 8 | return move(a); 9 | } 10 | 11 | int main() { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/move_forgot3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | T f(T a) { 5 | const l = [](T a) { return a; }; 6 | return g(move(a)); 7 | } 8 | 9 | int main() { 10 | return f(5); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /tests/move_in_loop_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable x = 5; 5 | while (true) { 6 | discard move(x); 7 | continue; 8 | break; 9 | } 10 | return 1; 11 | } 12 | -------------------------------------------------------------------------------- /tests/move_in_loop_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable x = 5; 5 | while (true) { 6 | discard move(x); 7 | continue; 8 | return 1; 9 | } 10 | return 1; 11 | } 12 | -------------------------------------------------------------------------------- /tests/noreturn_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | noreturn f() { 4 | embed { 5 | } 6 | } 7 | 8 | noreturn g() { 9 | if (true) 10 | f(); 11 | } 12 | 13 | int main() { 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/optional1.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | int main() { 4 | mutable int? x = null; 5 | if (x != null) 6 | return *x; 7 | x = 5; 8 | if (!x) 9 | return 1; 10 | else 11 | return *x; 12 | } 13 | -------------------------------------------------------------------------------- /tests/static_for_bad_move1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable res = 0; 5 | mutable x = 5; 6 | static for (i = 0; i < 5; i += 2) 7 | res = move(x); 8 | return res; 9 | } 10 | -------------------------------------------------------------------------------- /tests/template_overload_bad2.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | template 4 | int f(T t) { 5 | return 1; 6 | } 7 | 8 | int f(int a) { 9 | return 2; 10 | } 11 | 12 | int main() { 13 | return f(5); 14 | } 15 | -------------------------------------------------------------------------------- /tests/template_overload_bad3.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | int f(int a) { 4 | return 2; 5 | } 6 | 7 | template 8 | int f(T t) { 9 | return 1; 10 | } 11 | 12 | int main() { 13 | return f(5); 14 | } 15 | -------------------------------------------------------------------------------- /tests/to_string3.znn: -------------------------------------------------------------------------------- 1 | // 10 2 | 3 | template 4 | int get() { 5 | return to_string(N).size(); 6 | } 7 | 8 | int main() { 9 | return get() + get(); 10 | } 11 | -------------------------------------------------------------------------------- /tests/type_name_conflict1/main.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | import "fun.znn"; 4 | 5 | struct T123 { 6 | }; 7 | 8 | int get_imp(T123*) { return 1; } 9 | 10 | int main() { 11 | return get(&"pok"); 12 | } 13 | -------------------------------------------------------------------------------- /tests/bad_operator_overload1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | int operator + (int a, T b) { 5 | return a; 6 | } 7 | 8 | int main() { 9 | const x = 5 + false; 10 | return x; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /tests/break1.znn: -------------------------------------------------------------------------------- 1 | // 15 2 | 3 | int main() { 4 | mutable sum = 0; 5 | for (i = 0; i < 10; ++i) { 6 | sum = sum + i; 7 | if (i == 5) 8 | break; 9 | } 10 | return sum; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /tests/member2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct A { 4 | int x; 5 | }; 6 | 7 | A f() { 8 | return A(1); 9 | } 10 | 11 | int main() { 12 | const a = A(1); 13 | f().x = 5; 14 | return a.x; 15 | } 16 | -------------------------------------------------------------------------------- /tests/mixin_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | int get() { 5 | mixin CMD; 6 | return 0; 7 | } 8 | 9 | int main() { 10 | static const s1 = ""; 11 | return get(); 12 | } 13 | -------------------------------------------------------------------------------- /tests/mixin_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | int get() { 5 | mixin CMD; 6 | return 0; 7 | } 8 | 9 | int main() { 10 | static const s1 = "&"; 11 | return get(); 12 | } 13 | -------------------------------------------------------------------------------- /tests/mixin_bad4.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | int get() { 5 | mixin CMD; 6 | return 0; 7 | } 8 | 9 | int main() { 10 | static const s1 = " "; 11 | return get(); 12 | } 13 | -------------------------------------------------------------------------------- /tests/static_for7.znn: -------------------------------------------------------------------------------- 1 | // 35 2 | 3 | int main() { 4 | mutable res = 0; 5 | static for (i = 4; i >= 0; --i) 6 | static for (j = i + 1; j < 5; ++j) 7 | res += i * j; 8 | return res; 9 | } 10 | -------------------------------------------------------------------------------- /tests/variadic_args_bad15.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void f() { 5 | } 6 | 7 | template 8 | void g() { 9 | f(); 10 | } 11 | 12 | int main() { 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/reader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "util.h" 4 | #include "code_loc.h" 5 | 6 | struct FileContents { 7 | string value; 8 | }; 9 | 10 | extern WithError readFromFile(const char* path); 11 | -------------------------------------------------------------------------------- /tests/calling_method_on_pointer2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int plus(int* i, int x) { 4 | return *i + x; 5 | } 6 | 7 | int main() { 8 | int n = 5; 9 | const m = &n; 10 | return m.plus(.x = 5); 11 | } 12 | -------------------------------------------------------------------------------- /tests/compile_error_fun4.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void f() { 5 | static if (a == 1) 6 | compile_error("efwpok"); 7 | } 8 | 9 | int main() { 10 | f<1>(); 11 | return 1; 12 | } 13 | -------------------------------------------------------------------------------- /tests/concept_bad_arg.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | concept can_eat { 4 | void eat(T); 5 | }; 6 | 7 | template requires can_eat 8 | void f() { 9 | } 10 | 11 | int main() { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/concept_type9.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | concept C1 { 4 | int f(T*); 5 | void destruct(T*); 6 | }; 7 | 8 | template 9 | int f(T*) { return 2; } 10 | 11 | int main() { 12 | return f(&5); 13 | } 14 | -------------------------------------------------------------------------------- /tests/continue1.znn: -------------------------------------------------------------------------------- 1 | // 15 2 | 3 | int main() { 4 | mutable sum = 0; 5 | for (i = 0; i < 10; ++i) { 6 | if (i > 5) 7 | continue; 8 | sum = sum + i; 9 | } 10 | return sum; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /tests/destructor_requirement_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | struct X { 5 | }; 6 | 7 | template requires (false) 8 | void destruct(X*) {} 9 | 10 | int main() { 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/enum_range_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "std/enum.znn"; 4 | 5 | int main() { 6 | mutable i = 0; 7 | for (e : enum_range()) { 8 | i += e^.asInt(); 9 | } 10 | return i; 11 | } 12 | -------------------------------------------------------------------------------- /tests/function_type_conflict2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int T(int a) { 4 | return a; 5 | } 6 | 7 | union T { 8 | int x; 9 | }; 10 | 11 | int main() { 12 | const t = T::x(1); 13 | return 1; 14 | } 15 | -------------------------------------------------------------------------------- /tests/lambda_capture2.znn: -------------------------------------------------------------------------------- 1 | // 7 2 | 3 | struct X { 4 | }; 5 | 6 | int main() { 7 | mutable x = 5; 8 | const f = [x]{ return 1 + x;}; 9 | const g = [x, &f]{ return 1 + f();}; 10 | return g(); 11 | } 12 | -------------------------------------------------------------------------------- /tests/move3.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | template 4 | T get(mutable T a) { 5 | if (false) { 6 | return move(a); 7 | } else 8 | return move(a); 9 | } 10 | 11 | int main() { 12 | return get(5); 13 | } 14 | -------------------------------------------------------------------------------- /tests/move_in_unchecked_if1.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | template 4 | int f(bool x) { 5 | unchecked if (const b = x) 6 | return 3; 7 | return 2; 8 | } 9 | 10 | int main() { 11 | return f(true); 12 | } 13 | -------------------------------------------------------------------------------- /tests/mutable_pointer_conversion1.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | template 4 | struct A { 5 | T t; 6 | }; 7 | 8 | int main() { 9 | mutable i = 1; 10 | const a = A(&i); 11 | return *a.t; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/static_for_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable res = 0; 5 | static for (i = 0; i < 5; i += 2) 6 | static for (i = 0; i < 5; i += 2) 7 | ++res; 8 | return res; 9 | } 10 | -------------------------------------------------------------------------------- /tests/struct3.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | struct X { 4 | int a; 5 | }; 6 | 7 | struct Y { 8 | X x1; 9 | X x2; 10 | }; 11 | 12 | int main() { 13 | const y = Y(X(1), X(2)); 14 | return y.x1.a + y.x2.a; 15 | } 16 | -------------------------------------------------------------------------------- /tests/template_requirement_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | bool b() { 4 | return true; 5 | } 6 | 7 | template requires (b()) 8 | int f() { return N; } 9 | 10 | int main() { 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/type_comparison_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | }; 5 | 6 | template requires (T == X) 7 | int f(T value) { 8 | return 5; 9 | } 10 | 11 | int main() { 12 | return f(1); 13 | } 14 | -------------------------------------------------------------------------------- /tests/void_struct_member1.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | template 4 | struct X { 5 | T elem; 6 | }; 7 | 8 | int f(X t) { 9 | return 1; 10 | } 11 | 12 | int main() { 13 | return f(X(void_value)); 14 | } 15 | -------------------------------------------------------------------------------- /tests/array_negative_size2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void f() {} 5 | 6 | template 7 | void g() { 8 | f(); 9 | } 10 | 11 | int main() { 12 | g<-10>(); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/destructor_union_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | }; 5 | 6 | union V { 7 | X x; 8 | int y; 9 | }; 10 | 11 | void destruct(V* v) { 12 | } 13 | 14 | int main() { 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/function_type_conflict.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | union T { 4 | int x; 5 | }; 6 | 7 | T T(int a) { 8 | return T::x(a * 2); 9 | } 10 | 11 | int main() { 12 | const t = T(1); 13 | return 1; 14 | } 15 | -------------------------------------------------------------------------------- /tests/get_member1.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | import "std/struct.znn"; 4 | 5 | struct X { 6 | string s; 7 | int a; 8 | }; 9 | 10 | int main() { 11 | const x = X("pok", 3); 12 | return *get_member<1>(&x); 13 | } 14 | -------------------------------------------------------------------------------- /tests/slice_subsequence1.znn: -------------------------------------------------------------------------------- 1 | // 14 2 | 3 | int main() { 4 | const a = {1, 2, 3, 4, 5, 6, 7, 8}; 5 | mutable ret = 0; 6 | for (it : a.slice().subsequence(1, 4)) 7 | ret += *it; 8 | return ret; 9 | } 10 | -------------------------------------------------------------------------------- /tests/struct_default_args3.znn: -------------------------------------------------------------------------------- 1 | // 6 2 | 3 | template 4 | struct X { 5 | T? a = null; 6 | }; 7 | 8 | int main() { 9 | const x = X(); 10 | const y = X(1); 11 | return x.a ?? 5 + y.a ?? 10; 12 | } 13 | -------------------------------------------------------------------------------- /tests/template_value_param_bad5.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | struct X { 5 | }; 6 | 7 | template 8 | void f() {} 9 | 10 | int main() { 11 | f>(); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/unchecked1.znn: -------------------------------------------------------------------------------- 1 | // 6 2 | 3 | int f(int a) { 4 | return 1 + a; 5 | } 6 | 7 | template 8 | int get(T t) { 9 | unchecked return f(move(t)); 10 | } 11 | 12 | int main() { 13 | return get(5); 14 | } 15 | -------------------------------------------------------------------------------- /src/parser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "token.h" 4 | 5 | struct AST; 6 | struct Statement; 7 | extern WithErrorLine parse(Tokens); 8 | extern WithErrorLine> parseStatement(Tokens&, bool topLevel); 9 | -------------------------------------------------------------------------------- /tests/concept_type_bad14.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | concept A { 4 | void f(T*, U*); 5 | }; 6 | 7 | template 8 | struct S { 9 | }; 10 | 11 | int main() { 12 | const s = S(); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/get_alternative1.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | import "std/struct.znn"; 4 | 5 | union X { 6 | string s; 7 | int a; 8 | }; 9 | 10 | int main() { 11 | const x = X::a(3); 12 | return *get_alternative<1>(&x); 13 | } 14 | -------------------------------------------------------------------------------- /tests/get_alternative2.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | import "std/struct.znn"; 4 | 5 | union X { 6 | string s; 7 | int a; 8 | }; 9 | 10 | int main() { 11 | const x = X::a(3); 12 | return get_alternative<1>(move(x)); 13 | } 14 | -------------------------------------------------------------------------------- /tests/import_constructor/struct1.znn: -------------------------------------------------------------------------------- 1 | import "hidden.znn"; 2 | 3 | 4 | export struct Struct1 { 5 | int x; 6 | }; 7 | 8 | export Struct1(int u) { 9 | hidden(); 10 | return Struct1::Struct1(u + 1); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /tests/import_vector/struct1.znn: -------------------------------------------------------------------------------- 1 | 2 | export import "std/vector.znn"; 3 | 4 | struct X { 5 | }; 6 | 7 | export struct Y { 8 | vector v; 9 | }; 10 | 11 | export Y get() { 12 | return Y({X()}.as_vector()); 13 | } 14 | -------------------------------------------------------------------------------- /tests/lambda_ambiguous_implicit_return1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const f = [](bool a) { 5 | if (a) 6 | return 1; 7 | else 8 | return 2.0; 9 | }; 10 | return f(true); 11 | } 12 | -------------------------------------------------------------------------------- /tests/lambda_move_in_body1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const f = [] (int index)->int { 5 | const x = move(index); 6 | const y = 2 * x; 7 | return index; 8 | }; 9 | return f(6); 10 | } 11 | -------------------------------------------------------------------------------- /tests/operator_overload_bad5.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | struct A { 5 | }; 6 | 7 | template 8 | A operator + (A a, A b, A c) { 9 | return a; 10 | } 11 | 12 | int main() { 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/optional4.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | template 4 | T getOr(T b, T? a) { 5 | if (a) 6 | return move(b); 7 | else 8 | return move(b); 9 | } 10 | 11 | int main() { 12 | return getOr(5, null); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /tests/panic_handler1.znn: -------------------------------------------------------------------------------- 1 | // 6 2 | 3 | import "std/panic.znn"; 4 | import "std/io.znn"; 5 | 6 | int main() { 7 | set_panic_handler(&[](string s) { exit(s.size()); }); 8 | panic("foobar"); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/static_for9.znn: -------------------------------------------------------------------------------- 1 | // 21 2 | 3 | int main() { 4 | mutable res = 0; 5 | static for (i = 4; i >= 0; --i) 6 | static for (j = i + 1; j < 5 && i % 2 == 1; ++j) 7 | res += i * j; 8 | return res; 9 | } 10 | -------------------------------------------------------------------------------- /tests/template3.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | template 4 | struct X { 5 | T t; 6 | }; 7 | 8 | template 9 | struct Y { 10 | X x; 11 | }; 12 | 13 | int main() { 14 | const y = Y(X(1)); 15 | return y.x.t; 16 | } 17 | -------------------------------------------------------------------------------- /tests/template_overload_bad.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | int f(T t) { 5 | return 1; 6 | } 7 | 8 | template 9 | int f(U a) { 10 | return 2; 11 | } 12 | 13 | int main() { 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/try_op_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | int a; 5 | }; 6 | 7 | extern X? get(int a); 8 | 9 | int? f() { 10 | return try get(1).a; 11 | } 12 | 13 | int main() { 14 | return f() ?? 1; 15 | } 16 | -------------------------------------------------------------------------------- /tests/two_constructors.znn: -------------------------------------------------------------------------------- 1 | // 6 2 | 3 | struct X { 4 | int value; 5 | }; 6 | 7 | X() { 8 | return X::X(1); 9 | } 10 | 11 | int main() { 12 | mutable x = X(); 13 | x = X::X(6); 14 | return x.value; 15 | } 16 | -------------------------------------------------------------------------------- /tests/constructor1.znn: -------------------------------------------------------------------------------- 1 | // 6 2 | 3 | 4 | struct A { 5 | int a; 6 | int b; 7 | }; 8 | 9 | A(int x) { 10 | return A::A(x, 2 * x); 11 | } 12 | 13 | int main() { 14 | const a = A(2); 15 | return a.a + a.b; 16 | } 17 | -------------------------------------------------------------------------------- /tests/continue2.znn: -------------------------------------------------------------------------------- 1 | // 9 2 | 3 | int main() { 4 | const a = {1, 2, 3, 4, 5}; 5 | mutable ret = 0; 6 | for (it : a) { 7 | if (*it % 2 == 0) 8 | continue; 9 | ret += *it; 10 | } 11 | return ret; 12 | } 13 | -------------------------------------------------------------------------------- /tests/function_overloading1.znn: -------------------------------------------------------------------------------- 1 | // 68 2 | 3 | int f(int a) { 4 | return a; 5 | } 6 | 7 | int f(int a, int b) { 8 | return a + b; 9 | } 10 | 11 | int main() { 12 | return f(1) + f(3, 4) + 10.f() + 20.f(30); 13 | } 14 | -------------------------------------------------------------------------------- /tests/function_type1.znn: -------------------------------------------------------------------------------- 1 | // 9 2 | 3 | int fa(string s) { 4 | return s.size(); 5 | } 6 | 7 | int fa(int a) { 8 | return a * 2; 9 | } 10 | 11 | int main() { 12 | const a = fa; 13 | return a("pok") + a(3); 14 | } 15 | -------------------------------------------------------------------------------- /tests/hash_map_incomplete1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "std/hash_map.znn"; 4 | 5 | struct X { 6 | hash_map h; 7 | }; 8 | 9 | struct Y { 10 | X x; 11 | }; 12 | 13 | int main() { 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/instance_context/main.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | import "fun.znn"; 4 | 5 | struct X { 6 | int a; 7 | }; 8 | 9 | int g(X*) { return 1; } 10 | int g(X**) { return 50; } 11 | 12 | int main() { 13 | return f(X(1)); 14 | } 15 | -------------------------------------------------------------------------------- /tests/lambda_capture_bad5.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | }; 5 | 6 | template 7 | void eat(T) {} 8 | 9 | int main() { 10 | mutable x = X(); 11 | const l1 = [move(x)] { eat(x); }; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/lambda_in_static_for1.znn: -------------------------------------------------------------------------------- 1 | // 25 2 | 3 | int main() { 4 | mutable res = 0; 5 | static for (i = 0; i < 5; ++i) { 6 | const f = [](int a) { return i + a;}; 7 | res += f(3); 8 | } 9 | return res; 10 | } 11 | -------------------------------------------------------------------------------- /tests/move_in_loop_bad5.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable y = 2; 5 | while (true) { 6 | while (true) { 7 | discard move(y); 8 | break; 9 | } 10 | } 11 | return 1; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tests/name_mangling2.znn: -------------------------------------------------------------------------------- 1 | // 10 2 | 3 | template 4 | struct S { 5 | T elem; 6 | }; 7 | 8 | struct X { 9 | }; 10 | 11 | int f(S) { 12 | return 10; 13 | } 14 | 15 | int main() { 16 | return f(S(X())); 17 | } 18 | -------------------------------------------------------------------------------- /tests/static_mutable_variable5.znn: -------------------------------------------------------------------------------- 1 | // 55 2 | 3 | int main() { 4 | mutable res = 0; 5 | static mutable a = 0; 6 | static for (i = 0; i < 10; ++i) { 7 | a = a + 1; 8 | res += a; 9 | } 10 | return res; 11 | } 12 | -------------------------------------------------------------------------------- /tests/ternary_operator_precedence1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | const b = false; 5 | const c = false; 6 | const x = 5; 7 | if (x == b ? x : 4) 8 | return 1; 9 | else 10 | return 2; 11 | } 12 | -------------------------------------------------------------------------------- /tests/type_alias2.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | using int32 = int; 4 | 5 | template 6 | struct X { 7 | T elem; 8 | }; 9 | 10 | using X32 = X; 11 | 12 | int main() { 13 | const x = X32(5); 14 | return x.elem; 15 | } 16 | -------------------------------------------------------------------------------- /tests/type_comparison1.znn: -------------------------------------------------------------------------------- 1 | // 101 2 | 3 | template requires (T == int || T == char) 4 | int f(T value) { 5 | embed { 6 | return int(value); 7 | } 8 | } 9 | 10 | int main() { 11 | return f(4) + f('a'); 12 | } 13 | -------------------------------------------------------------------------------- /tests/type_comparison3.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | template 4 | struct X { 5 | }; 6 | 7 | template requires (T == X) 8 | int f(T value) { 9 | return 5; 10 | } 11 | 12 | int main() { 13 | return f(X()); 14 | } 15 | -------------------------------------------------------------------------------- /tests/unchecked_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int f(char a) { 4 | return 1; 5 | } 6 | 7 | template 8 | int get(T t) { 9 | unchecked return f(move(t)); 10 | } 11 | 12 | int main() { 13 | return get(5); 14 | } 15 | -------------------------------------------------------------------------------- /tests/attribute_bad4.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | attribute @a1; 4 | 5 | template requires has_attribute 6 | void f() { 7 | } 8 | 9 | struct X { 10 | }; 11 | 12 | int main() { 13 | f(); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/concept_type_import1/main.znn: -------------------------------------------------------------------------------- 1 | // 10 2 | 3 | import "input2.znn"; 4 | import "input3.znn"; 5 | 6 | int main() { 7 | mutable x = X(5); 8 | const C1 mutable* c = &x; 9 | c^.set(6); 10 | return c^.get() + f(); 11 | } 12 | -------------------------------------------------------------------------------- /tests/double.znn: -------------------------------------------------------------------------------- 1 | // 50 2 | import "std/math.znn"; 3 | 4 | int main() { 5 | double a = 33.0; 6 | double b = 0.7; 7 | double c = 3.0; 8 | double d = 2; 9 | int e = as_int((a + b) * c / d); 10 | return e; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /tests/extern_void_function1.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | embed { 4 | void f(int* a) { *a = 5; } 5 | } 6 | 7 | extern void f(int mutable*); 8 | 9 | int main() { 10 | mutable res = 0; 11 | void a = f(&res); 12 | return res; 13 | } 14 | -------------------------------------------------------------------------------- /tests/get_member2.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | import "std/struct.znn"; 4 | 5 | struct X { 6 | string s; 7 | int a; 8 | }; 9 | 10 | int main() { 11 | mutable x = X("pok", 5); 12 | *get_member<1>(&x) = 3; 13 | return x.a; 14 | } 15 | -------------------------------------------------------------------------------- /tests/instance_context3/main.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | import "fun.znn"; 4 | 5 | struct X {}; 6 | struct Y {}; 7 | 8 | int get_for(Y*) { 9 | return 2; 10 | } 11 | 12 | int main() { 13 | return get(&X()) + get(&Y()) * 2; 14 | } 15 | -------------------------------------------------------------------------------- /tests/member3.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | struct A { 4 | int x; 5 | }; 6 | 7 | int mutable* get(A mutable* a) { 8 | return &a^.x; 9 | } 10 | 11 | int main() { 12 | mutable a = A(1); 13 | *(a.get()) = 5; 14 | return a.x; 15 | } 16 | -------------------------------------------------------------------------------- /tests/method4.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | int a; 5 | }; 6 | 7 | int b(X* x) { 8 | return x^.a; 9 | } 10 | 11 | int main() { 12 | X x = X(1); 13 | mutable u = x.a; 14 | u = x.b; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/method5.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | int a; 5 | }; 6 | 7 | int b(X* x) { 8 | return x^.a; 9 | } 10 | 11 | int main() { 12 | X x = X(1); 13 | const u = x.a; 14 | u = x.b(1); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/mixin_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | int get() { 5 | mixin CMD; 6 | return 0; 7 | } 8 | 9 | int main() { 10 | static const s1 = "const a = 5; return a;"; 11 | return get(); 12 | } 13 | -------------------------------------------------------------------------------- /tests/move4.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | template 4 | T f(mutable T a) { 5 | return g(move(a)); 6 | } 7 | 8 | template 9 | T g(mutable T a) { 10 | return move(a); 11 | } 12 | 13 | int main() { 14 | return f(5); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /tests/mutable_slice_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | void plus1(int mutable[] s) { 4 | for (it : s) 5 | ++*it; 6 | } 7 | 8 | int main() { 9 | const a = {1, 2, 3, 4}; 10 | plus1(a.slice()); 11 | return 0; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tests/pointer_comparison1.znn: -------------------------------------------------------------------------------- 1 | // 4 2 | 3 | int main() { 4 | int x = 1; 5 | int y = 2; 6 | const z = &x; 7 | if (&x == &y) 8 | return 3; 9 | else if (z == &x) 10 | return 4; 11 | else 12 | return 5; 13 | } 14 | -------------------------------------------------------------------------------- /tests/static_for2.znn: -------------------------------------------------------------------------------- 1 | // 15 2 | 3 | template 4 | int get() { 5 | return N; 6 | } 7 | 8 | int main() { 9 | mutable res = 0; 10 | static for (i = 0; i < 6; ++i) 11 | res += get(); 12 | return res; 13 | } 14 | -------------------------------------------------------------------------------- /tests/static_mutable_string1.znn: -------------------------------------------------------------------------------- 1 | // 6 2 | 3 | template 4 | int size() { 5 | return S.size(); 6 | } 7 | 8 | int main() { 9 | static mutable stmt = "abc"; 10 | stmt = "pokpak"; 11 | return size(); 12 | } 13 | -------------------------------------------------------------------------------- /tests/struct_default_args2.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | int f() { 4 | return 3; 5 | } 6 | 7 | struct X { 8 | int a = f(); 9 | }; 10 | 11 | int main() { 12 | const f = [] { return 4; }; 13 | const x = X(); 14 | return x.a; 15 | } 16 | -------------------------------------------------------------------------------- /tests/template_requirement2.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | template requires (U == int) 4 | struct X { 5 | U u; 6 | }; 7 | 8 | template 9 | T f(X x) { return move(x).u; } 10 | 11 | int main() { 12 | return f(X(2)); 13 | } 14 | -------------------------------------------------------------------------------- /tests/try_op2.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | struct X { 4 | int? a; 5 | }; 6 | 7 | X get(int a) { 8 | return X(a); 9 | } 10 | 11 | int? f() { 12 | return try get(1).a + 1; 13 | } 14 | 15 | int main() { 16 | return f() ?? 3; 17 | } 18 | -------------------------------------------------------------------------------- /tests/try_op3.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | struct X { 4 | int? a; 5 | }; 6 | 7 | X get(int a) { 8 | return X(null); 9 | } 10 | 11 | int? f() { 12 | return try get(1).a; 13 | } 14 | 15 | int main() { 16 | return f() ?? 2; 17 | } 18 | -------------------------------------------------------------------------------- /tests/vector_filter1.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | import "std/vector.znn"; 4 | 5 | int main() { 6 | const v = {1, 2, 3, 4, 5}.as_vector(); 7 | const w = v.filter([](int* x) -> bool { return *x % 2 == 1; }); 8 | return w[2]; 9 | } 10 | -------------------------------------------------------------------------------- /tests/compile_time_array_size_bad.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int f() { 4 | return 4; 5 | } 6 | 7 | int main() { 8 | const num = f(); 9 | const num2 = num + 1; 10 | const int[num2] a = {1, 2, 3, 4, 5}; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/import_double/print.znn: -------------------------------------------------------------------------------- 1 | embed { 2 | #include 3 | constexpr int g = 5; 4 | } 5 | 6 | export int getInt(int x) { 7 | embed { 8 | return g + x; 9 | } 10 | } 11 | 12 | export struct X { 13 | int a; 14 | }; 15 | -------------------------------------------------------------------------------- /tests/incomplete_template/main.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "x.znn"; 4 | 5 | template 6 | struct Y { 7 | T elem; 8 | }; 9 | 10 | extern Y get(); 11 | 12 | int main() { 13 | const a = get(); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/lambda8.znn: -------------------------------------------------------------------------------- 1 | // 6 2 | 3 | template requires invoke 4 | int runFun(Fun f, T t) { 5 | return f(move(t)); 6 | } 7 | 8 | int main() { 9 | return runFun([] (string s) { return s.size(); }, "foobar"); 10 | } 11 | -------------------------------------------------------------------------------- /tests/method_overload6.znn: -------------------------------------------------------------------------------- 1 | // 21 2 | 3 | struct X { 4 | }; 5 | 6 | int f(X*) { return 1; } 7 | int f(X) { return 2; } 8 | 9 | int main() { 10 | const x = X(); 11 | const y = X(); 12 | return 10 * move(x).f() + y.f(); 13 | } 14 | -------------------------------------------------------------------------------- /tests/mutable_ptr_template_param.znn: -------------------------------------------------------------------------------- 1 | // 0 2 | 3 | template 4 | struct A { 5 | }; 6 | 7 | A f() { 8 | mutable int a = 5; 9 | return A(); 10 | } 11 | 12 | int main() { 13 | return 0; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /tests/postfix_indirection1.znn: -------------------------------------------------------------------------------- 1 | // 6 2 | 3 | struct X { 4 | int a; 5 | }; 6 | 7 | int main() { 8 | const a = 5; 9 | const p = &a; 10 | mutable x = X(0); 11 | x.a = p^ + 1; 12 | const p2 = &x; 13 | return p2^.a; 14 | } 15 | -------------------------------------------------------------------------------- /tests/public_embed.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | export embed { 4 | #include 5 | } 6 | 7 | int f() { 8 | export embed { 9 | int x = 1; 10 | return x; 11 | } 12 | } 13 | 14 | int main() { 15 | return f(); 16 | } 17 | -------------------------------------------------------------------------------- /tests/subscript7.znn: -------------------------------------------------------------------------------- 1 | // 7 2 | 3 | struct X { 4 | }; 5 | 6 | template 7 | T operator[](X* x, mutable T a) { 8 | return move(a); 9 | } 10 | 11 | int main() { 12 | const x = X(); 13 | int i = 7; 14 | return x[i]; 15 | } 16 | -------------------------------------------------------------------------------- /tests/array_iterator2.znn: -------------------------------------------------------------------------------- 1 | // 20 2 | 3 | int main() { 4 | mutable a = {0, 0, 0, 0}; 5 | for (it : a) 6 | *it = it.index + 1; 7 | mutable res = 0; 8 | for (it : a) 9 | res += it.index * *it; 10 | return res; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /tests/enum_switch_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | enum E { 4 | E1, 5 | E2 6 | }; 7 | 8 | int main() { 9 | const u = E::E1; 10 | switch (&u) { 11 | case (E1) { 12 | } 13 | default {} 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/import_methods2/s1.znn: -------------------------------------------------------------------------------- 1 | import "fun.znn"; 2 | 3 | export struct X { 4 | int v; 5 | }; 6 | 7 | export int get(X* x) { 8 | return fun((*x).v); 9 | } 10 | 11 | export void set(X mutable* x, int t) { 12 | (*x).v = fun(t); 13 | } 14 | -------------------------------------------------------------------------------- /tests/import_template_fun/main.znn: -------------------------------------------------------------------------------- 1 | // 10 2 | import "fun.znn"; 3 | 4 | template 5 | int getT(T a) { 6 | return 10; 7 | } 8 | 9 | int main() { 10 | int a = getT(5); 11 | int b = 20; 12 | return *get(&a, &b, getNum()); 13 | } 14 | -------------------------------------------------------------------------------- /tests/mixin2.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | template 4 | int get() { 5 | mixin CMD; 6 | } 7 | 8 | int main() { 9 | static const s1 = "\{ const a = 5; const b = 2; return a - b; \}"; 10 | return get<"return 2;">() + get(); 11 | } 12 | -------------------------------------------------------------------------------- /tests/move_forgot1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | T f(mutable T a) { 5 | return g(a); 6 | } 7 | 8 | template 9 | T g(mutable T a) { 10 | return move(a); 11 | } 12 | 13 | int main() { 14 | return f(5); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /tests/move_forgot2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | T f(mutable T a) { 5 | return g(move(a)); 6 | } 7 | 8 | template 9 | T g(mutable T a) { 10 | return a; 11 | } 12 | 13 | int main() { 14 | return f(5); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /tests/mutable_for1.znn: -------------------------------------------------------------------------------- 1 | // 17 2 | 3 | int main() { 4 | const a = {1, 2, 3, 4, 5, 6}; 5 | mutable res = 0; 6 | for (i = 0; i < a.size(); ++i) { 7 | if (i == 3) 8 | ++i; 9 | res += a[i]; 10 | } 11 | return res; 12 | } 13 | -------------------------------------------------------------------------------- /tests/named_args_overload3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int f(int a, bool b) { 4 | return 1; 5 | } 6 | 7 | bool f(int a, int c) { 8 | return false; 9 | } 10 | 11 | int main() { 12 | bool b = f(.a = 3, .b = 3); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/string_to_int1.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | int main() { 4 | mutable res = 0; 5 | res += *"5".to_int(); 6 | if (const r = "5a".to_int()) 7 | res += *r; 8 | if (const r = "".to_int()) 9 | res += *r + 1; 10 | return res; 11 | } 12 | -------------------------------------------------------------------------------- /tests/template_expression1.znn: -------------------------------------------------------------------------------- 1 | // 15 2 | 3 | template 4 | int f() { 5 | return A; 6 | } 7 | 8 | template 9 | int g() { 10 | return f<(A + B)>(); 11 | } 12 | 13 | int main() { 14 | return g<5, 10>(); 15 | } 16 | -------------------------------------------------------------------------------- /tests/template_requirement_bad7.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template requires (U == bool) 4 | struct X { 5 | U u; 6 | }; 7 | 8 | template 9 | T f(X x) { return move(x).u; } 10 | 11 | int main() { 12 | return f(X(2)); 13 | } 14 | -------------------------------------------------------------------------------- /tests/transitive_requirement1/main.znn: -------------------------------------------------------------------------------- 1 | // 11 2 | 3 | import "input2.znn"; 4 | 5 | struct X { 6 | int a; 7 | }; 8 | 9 | int g(X* x) { 10 | return x^.a; 11 | } 12 | 13 | int main() { 14 | const x = X(5); 15 | return u(&x); 16 | } 17 | -------------------------------------------------------------------------------- /tests/type_comparison_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template requires (T == int || T == char) 4 | int f(T value) { 5 | embed { 6 | return int(value); 7 | } 8 | } 9 | 10 | int main() { 11 | return f(4) + f("abc"); 12 | } 13 | -------------------------------------------------------------------------------- /tests/variadic_value_parameter1.znn: -------------------------------------------------------------------------------- 1 | // 16 2 | 3 | int sum() { 4 | return 0; 5 | } 6 | 7 | template 8 | int sum() { 9 | return A + sum(); 10 | } 11 | 12 | int main() { 13 | return sum<1, 3, 5, 7>(); 14 | } 15 | -------------------------------------------------------------------------------- /codegen_includes/array_utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | template < class D, class... Types> 6 | constexpr std::array make_array(Types&&... t) { 7 | return {static_cast(std::forward(t))... }; 8 | } 9 | -------------------------------------------------------------------------------- /tests/array2d.znn: -------------------------------------------------------------------------------- 1 | // 36 2 | 3 | int main() { 4 | const a = array_repeat<3>(array_repeat<3>(2)); 5 | mutable res = 0; 6 | for (row : a) 7 | for (col : *row) 8 | res += *col * (row.index + col.index); 9 | return res; 10 | } 11 | -------------------------------------------------------------------------------- /tests/constructor_template1.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | template 4 | struct A { 5 | T a; 6 | }; 7 | 8 | template 9 | A(T a) { 10 | return A::A(move(a)); 11 | } 12 | 13 | int main() { 14 | const a = A(5); 15 | return a.a; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /tests/import_vector2/struct1.znn: -------------------------------------------------------------------------------- 1 | 2 | export import "std/vector.znn"; 3 | 4 | export struct X { 5 | int a; 6 | }; 7 | 8 | export struct Y { 9 | vector v; 10 | }; 11 | 12 | export Y get() { 13 | return Y({X(5)}.as_vector()); 14 | } 15 | -------------------------------------------------------------------------------- /tests/lambda_capture_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable x = 5; 5 | mutable y = 5; 6 | const f = [x] { 7 | const g = [y] { 8 | return y; 9 | }; 10 | return g(); 11 | }; 12 | return f(); 13 | } 14 | -------------------------------------------------------------------------------- /tests/move_in_loop1.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | import "std/range.znn"; 4 | 5 | int get() { 6 | int ret = 1; 7 | for (i : range(0, 10)) { 8 | return move(ret); 9 | } 10 | return 0; 11 | } 12 | 13 | int main() { 14 | return get(); 15 | } 16 | -------------------------------------------------------------------------------- /tests/move_in_loop2.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | import "std/range.znn"; 4 | 5 | int get() { 6 | for (i : range(0, 10)) { 7 | int ret = 1; 8 | return move(ret); 9 | } 10 | return 0; 11 | } 12 | 13 | int main() { 14 | return get(); 15 | } 16 | -------------------------------------------------------------------------------- /tests/move_in_loop7.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | int main() { 4 | mutable y = 2; 5 | mutable x = 1; 6 | while (true) { 7 | while (true) { 8 | x = move(y); 9 | break; 10 | } 11 | break; 12 | } 13 | return x; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /tests/op_in_place.znn: -------------------------------------------------------------------------------- 1 | // 14 2 | 3 | int main() { 4 | mutable sum = 0; 5 | for (i = 0; i < 10; i += 1) 6 | sum += i; 7 | for (i = 8; i > 3; i -= 1) 8 | sum -= i; 9 | sum /= 2; 10 | sum *= 2; 11 | return sum; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tests/shadow_static_var4.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | template 4 | int get() { 5 | return N; 6 | } 7 | 8 | int main() { 9 | static mutable a = 3; 10 | a += 1; 11 | [@shadow] 12 | static const a = a + 1; 13 | return get(); 14 | } 15 | -------------------------------------------------------------------------------- /tests/static_for_bad4.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable res = 0; 5 | mutable x = true; 6 | static for (i = 4; i >= 0; --i) 7 | static for (j = i + 1; j < 5 && x; ++j) 8 | res += i * j; 9 | return res; 10 | } 11 | -------------------------------------------------------------------------------- /tests/array_copy1.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | struct X { 4 | int a; 5 | }; 6 | 7 | X copy(X* x) { 8 | return X(x^.a - 1); 9 | } 10 | 11 | int main() { 12 | const x1 = array_repeat<10>(X(4)); 13 | const x2 = x1.copy(); 14 | return x2[0].a; 15 | } 16 | -------------------------------------------------------------------------------- /tests/concept_type_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | concept C1 { 4 | void call(int); 5 | }; 6 | 7 | struct X { 8 | }; 9 | 10 | void call(int) {} 11 | 12 | int main() { 13 | const x = X(); 14 | const C1* c1 = &x; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/concept_type_cast2.znn: -------------------------------------------------------------------------------- 1 | // 11 2 | 3 | import "std/any.znn"; 4 | 5 | int main() { 6 | const x = "popopo"; 7 | const y = 5; 8 | any* a = &x; 9 | any* b = &y; 10 | return (*a^.cast_to())^.size() + **b^.cast_to(); 11 | } 12 | -------------------------------------------------------------------------------- /tests/destructor1.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | struct X { 4 | int mutable* a; 5 | }; 6 | 7 | void destruct(X* x) { 8 | ++*x^.a; 9 | } 10 | 11 | int main() { 12 | mutable cnt = 1; 13 | { 14 | const x = X(&cnt); 15 | } 16 | return cnt; 17 | } 18 | -------------------------------------------------------------------------------- /tests/enum_implicit_copy1.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | import "std/enum.znn"; 4 | 5 | enum E { 6 | E1, 7 | E2, 8 | E3 9 | }; 10 | 11 | int main() { 12 | const x = E::E3; 13 | const E? s = x; 14 | const u = s; 15 | return u^.to_int(); 16 | } 17 | -------------------------------------------------------------------------------- /tests/enum_range1.znn: -------------------------------------------------------------------------------- 1 | // 10 2 | 3 | import "std/enum.znn"; 4 | 5 | enum E { 6 | E1, E2, E3, E4, E5 7 | }; 8 | 9 | int main() { 10 | mutable i = 0; 11 | for (e : enum_range()) { 12 | i += e^.to_int(); 13 | } 14 | return i; 15 | } 16 | -------------------------------------------------------------------------------- /tests/get_member3.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | import "std/struct.znn"; 4 | 5 | struct X { 6 | string s; 7 | int a; 8 | }; 9 | 10 | struct Y { 11 | X x; 12 | }; 13 | 14 | int main() { 15 | return get_member<1>(get_member<0>(Y(X("pok", 3)))); 16 | } 17 | -------------------------------------------------------------------------------- /tests/lambda_capture_by_copy1.znn: -------------------------------------------------------------------------------- 1 | // 4 2 | 3 | struct X { 4 | int a; 5 | }; 6 | 7 | X copy(X* x) { 8 | return X(x^.a + 1); 9 | } 10 | 11 | int main() { 12 | const x = X(3); 13 | const f = [copy(x)]{ return x.a;}; 14 | return f(); 15 | } 16 | -------------------------------------------------------------------------------- /tests/method_overload5.znn: -------------------------------------------------------------------------------- 1 | // 11 2 | 3 | struct X { 4 | }; 5 | 6 | int f(X*, bool) { return 1; } 7 | int f(X) { return 2; } 8 | 9 | int main() { 10 | const x = X(); 11 | const y = X(); 12 | return 10 * move(x).f(true) + y.f(true); 13 | } 14 | -------------------------------------------------------------------------------- /tests/move_in_loop5.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | int main() { 4 | mutable y = 2; 5 | mutable x = 0; 6 | while (true) { 7 | if (y == 3) { 8 | x = move(y); 9 | break; 10 | } 11 | y = y + 1; 12 | } 13 | return x; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /tests/name_mangling1.znn: -------------------------------------------------------------------------------- 1 | // 10 2 | 3 | import "std/vector.znn"; 4 | 5 | template 6 | struct S { 7 | T elem; 8 | }; 9 | 10 | int f(S>) { 11 | return 10; 12 | } 13 | 14 | int main() { 15 | return f(S(vector())); 16 | } 17 | -------------------------------------------------------------------------------- /tests/static_mutable_variable2.znn: -------------------------------------------------------------------------------- 1 | // 15 2 | 3 | template 4 | int get() { 5 | return N; 6 | } 7 | 8 | int main() { 9 | static mutable res = 0; 10 | static for (i = 0; i < 6; ++i) 11 | res += i; 12 | return get(); 13 | } 14 | -------------------------------------------------------------------------------- /tests/string1.znn: -------------------------------------------------------------------------------- 1 | // 14 2 | 3 | int main() { 4 | char c = 'p'; 5 | const s = "pok pok"; const s2 = "pak"; 6 | string s3 = s + s2; 7 | int x = s3.size(); 8 | if (s + s2 == s3) 9 | return 4 + x; 10 | else 11 | return 5 + x; 12 | } 13 | -------------------------------------------------------------------------------- /tests/template_requirement_bad6.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template requires (N > 0) 4 | struct S { 5 | int[N] elems; 6 | }; 7 | 8 | template 9 | void f() { 10 | } 11 | 12 | int main() { 13 | f>(); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/variadic_args_bad5.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void f() {} 5 | 6 | template 7 | struct X { 8 | }; 9 | 10 | template 11 | void eat() { 12 | MyArgs x; 13 | } 14 | 15 | int main() { 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/constructor_default_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | export struct X { 4 | int a; 5 | }; 6 | 7 | export X(bool) = default; 8 | 9 | export X() { 10 | return X::X(1); 11 | } 12 | 13 | int main() { 14 | const x = X(); 15 | return x.a; 16 | } 17 | -------------------------------------------------------------------------------- /tests/conversions1.znn: -------------------------------------------------------------------------------- 1 | // 8 2 | 3 | import "std/math.znn"; 4 | 5 | byte get() { 6 | return 260.as_byte(); 7 | } 8 | 9 | short get2() { 10 | return 65539.as_short(); 11 | } 12 | 13 | int main() { 14 | return get() + get2() + as_int(1.2); 15 | } 16 | -------------------------------------------------------------------------------- /tests/destructor_lambda_param1.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | struct X { 4 | int mutable* p; 5 | }; 6 | 7 | void destruct(X* x) { ++*x^.p; } 8 | 9 | int main() { 10 | mutable a = 1; 11 | const f = [](X x) { 12 | }; 13 | f(X(&a)); 14 | return a; 15 | } 16 | -------------------------------------------------------------------------------- /tests/function_concept1.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | concept CanAdd { 4 | T operator + (T* t1, T* t2); 5 | }; 6 | 7 | template requires CanAdd 8 | A add(A a, A b) { 9 | return a + b; 10 | } 11 | 12 | int main() { 13 | return add(1, 2); 14 | } 15 | -------------------------------------------------------------------------------- /tests/function_type2.znn: -------------------------------------------------------------------------------- 1 | // 4 2 | 3 | int fa(string s) { 4 | return s.size(); 5 | } 6 | 7 | template requires invoke 8 | int get(Fun f) { 9 | return 1 + f("xyz"); 10 | } 11 | 12 | int main() { 13 | return get(fa); 14 | } 15 | -------------------------------------------------------------------------------- /tests/lambda_capture_by_move1.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | struct X { 4 | int mutable* v; 5 | }; 6 | 7 | int main() { 8 | mutable a = 5; 9 | const x = X(&a); 10 | mutable y = 1; 11 | const f = [move(x), y]{ *x.v = y;}; 12 | f(); 13 | return a; 14 | } 15 | -------------------------------------------------------------------------------- /tests/method_overload1.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | int f(int a, bool b) { 4 | return 1; 5 | } 6 | 7 | bool f(int a, int c) { 8 | return true; 9 | } 10 | 11 | int main() { 12 | if (1.f(5)) 13 | return 1.f(false); 14 | else 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/move5.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | int main() { 4 | mutable x = 5; 5 | mutable y = 6; 6 | if (true) { 7 | if (false) { 8 | y = move(x); 9 | } else 10 | y = move(x); 11 | } else 12 | y = move(x); 13 | return y; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /tests/move_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | enum E { E1, E2 }; 4 | 5 | int main() { 6 | mutable e = E::E1; 7 | switch (move(e)) { 8 | case (E1) { 9 | e = E::E2; 10 | } 11 | default { 12 | } 13 | } 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /tests/variadic_args_bad4.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void f() {} 5 | 6 | template 7 | struct X { 8 | }; 9 | 10 | template 11 | void eat() { 12 | f>(); 13 | } 14 | 15 | int main() { 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/variadic_value_parameter_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int sum() { 4 | return 0; 5 | } 6 | 7 | template 8 | int sum() { 9 | return A + sum(); 10 | } 11 | 12 | int main() { 13 | return sum<1, 3, char, 7>(); 14 | } 15 | -------------------------------------------------------------------------------- /tests/variadic_value_parameter_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int sum() { 4 | return 0; 5 | } 6 | 7 | template 8 | int sum() { 9 | return A + sum(); 10 | } 11 | 12 | int main() { 13 | return sum<1, 3, 5.5, 7>(); 14 | } 15 | -------------------------------------------------------------------------------- /tests/destructor3.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | void destruct(X* x) { 4 | ++*x^.cnt; 5 | } 6 | 7 | struct X { 8 | int mutable* cnt; 9 | }; 10 | 11 | int main() { 12 | mutable int cnt = 1; 13 | { 14 | const x = X(&cnt); 15 | } 16 | return cnt; 17 | } 18 | -------------------------------------------------------------------------------- /tests/extern_struct_instance1.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | import "std/expected.znn"; 4 | 5 | embed { 6 | struct X {}; 7 | } 8 | 9 | extern struct X; 10 | 11 | expected get() { 12 | return 5; 13 | } 14 | 15 | int main() { 16 | return get() ?? 1; 17 | } 18 | -------------------------------------------------------------------------------- /tests/get_alternative_name_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | union V { 4 | int uvwxyz; 5 | }; 6 | 7 | template requires is_union 8 | int g() { 9 | return get_alternative_name(T, 1).size(); 10 | } 11 | 12 | int main() { 13 | return g(); 14 | } 15 | -------------------------------------------------------------------------------- /tests/import_circular/main.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | import "struct1.znn"; 3 | 4 | export int fun1(bool b) { 5 | if (b) 6 | return fun2(); 7 | else 8 | return 3; 9 | } 10 | 11 | int main() { 12 | const s = Struct1(true); 13 | return fun1(true); 14 | } 15 | -------------------------------------------------------------------------------- /tests/import_methods3/main.znn: -------------------------------------------------------------------------------- 1 | // 10 2 | import "s1.znn"; 3 | 4 | 5 | int main() { 6 | const x = X(10); 7 | const ret = x.get(true); 8 | const y = Y(true); 9 | if (y.get(54)) 10 | return x.get(false); 11 | else 12 | return 1; 13 | } 14 | -------------------------------------------------------------------------------- /tests/import_template_fun/fun.znn: -------------------------------------------------------------------------------- 1 | import "fun2.znn"; 2 | 3 | export int getNum() { 4 | return getNum2() - 1; 5 | } 6 | 7 | export template 8 | T* get(T* t1, T* t2, int a) { 9 | if (a == 0) 10 | return t1; 11 | else 12 | return t2; 13 | } 14 | -------------------------------------------------------------------------------- /tests/incomplete_enum/main.znn: -------------------------------------------------------------------------------- 1 | // 21 2 | 3 | import "enum1.znn"; 4 | import "fun2.znn"; 5 | 6 | int main() { 7 | const e1 = get(true); 8 | const e2 = get(false); 9 | const e3 = getE2(); 10 | return getValue(e1) + getValue(e2) + getValue(e3); 11 | } 12 | -------------------------------------------------------------------------------- /tests/lambda_capture_bad6.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | }; 5 | 6 | X copy(X*) = default; 7 | 8 | template 9 | void eat(T) {} 10 | 11 | int main() { 12 | mutable x = X(); 13 | const l1 = [copy(x)] { eat(x); }; 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/move_in_loop_bad.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "std/range.znn"; 4 | 5 | int get() { 6 | const ret = 1; 7 | for (i : range(0, 10)) { 8 | const k = move(ret); 9 | } 10 | return 1; 11 | } 12 | 13 | int main() { 14 | return get(); 15 | } 16 | -------------------------------------------------------------------------------- /tests/operator_pointer_args2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct A { 4 | }; 5 | 6 | int operator + (A* a, A *b) { 7 | return 0; 8 | } 9 | 10 | int main() { 11 | const a = A(); 12 | const b = A(); 13 | const c = (&a) + (&b); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/static_for3.znn: -------------------------------------------------------------------------------- 1 | // 33 2 | 3 | int round(double d) { 4 | embed { 5 | return int(d); 6 | } 7 | } 8 | 9 | int main() { 10 | mutable res = 0.0; 11 | static for (i = 0.0; i <= 5.5; i += 0.5) 12 | res += i; 13 | return round(res); 14 | } 15 | -------------------------------------------------------------------------------- /tests/static_while_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | int get() { 5 | static mutable a = 0; 6 | static while (a < N) { 7 | ++a; 8 | foobar(); 9 | } 10 | return a; 11 | } 12 | 13 | int main() { 14 | return get<0>(); 15 | } 16 | -------------------------------------------------------------------------------- /tests/concept_type_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | concept C1 { 4 | void call(int, T*, T*); 5 | }; 6 | 7 | struct X { 8 | }; 9 | 10 | void call(int, X*, X*) {} 11 | 12 | int main() { 13 | const x = X(); 14 | const C1* c1 = &x; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/concept_type_bad10.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | concept C1 { 4 | void fun1234(); 5 | }; 6 | 7 | void f(C1*) {} 8 | 9 | C1* get() { 10 | embed { 11 | } 12 | } 13 | 14 | int main() { 15 | f(get()); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/concept_type_bad5.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | concept C1 { 4 | void call(T?*, int); 5 | }; 6 | 7 | struct X { 8 | }; 9 | 10 | void call(X?*, int) { 11 | } 12 | 13 | int main() { 14 | const x = X(); 15 | const C1* c1 = &x; 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/deduce_from_concept_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void g(T) {} 5 | 6 | concept C { 7 | void g(U); 8 | }; 9 | 10 | template requires C 11 | void f() { 12 | } 13 | 14 | int main() { 15 | f(); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/destructor_requirement3.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | template 4 | struct X { 5 | }; 6 | 7 | template requires (T != int) 8 | void destruct(X*) {} 9 | 10 | template 11 | int f() { return 1; } 12 | 13 | int main() { 14 | return f>(); 15 | } 16 | -------------------------------------------------------------------------------- /tests/enum_size_in_template_struct_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template requires is_enum 4 | struct S { 5 | int[enum_count(Key)] values; 6 | }; 7 | 8 | int get(S* m) { 9 | return 0; 10 | } 11 | 12 | int main() { 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/lambda7.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | concept invoke { 4 | U invoke(T*); 5 | }; 6 | 7 | template requires invoke 8 | T run(Fun f) { 9 | return f(); 10 | } 11 | 12 | int main() { 13 | return run([] () -> int { return 1; }); 14 | } 15 | -------------------------------------------------------------------------------- /tests/lambda_capture_by_ref3.znn: -------------------------------------------------------------------------------- 1 | // 6 2 | 3 | template 4 | struct X { 5 | T elem; 6 | }; 7 | 8 | template 9 | void destruct(X*) {} 10 | 11 | int main() { 12 | mutable a = 5; 13 | const x = X([&]{ ++a;}); 14 | x.elem(); 15 | return a; 16 | } 17 | -------------------------------------------------------------------------------- /tests/move_in_loop6.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | int main() { 4 | mutable y = 2; 5 | mutable x = 0; 6 | while (true) { 7 | if (y == 3) { 8 | x = move(y); 9 | return 1; 10 | } 11 | y = y + 1; 12 | } 13 | y = 0; 14 | return x; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /tests/operator_overload_not_equal2.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | struct X { 4 | }; 5 | 6 | bool operator == (X*, X*) { 7 | return true; 8 | } 9 | 10 | int main() { 11 | const x = X(); 12 | const y = X(); 13 | if (x != y) 14 | return 1; 15 | return 2; 16 | } 17 | -------------------------------------------------------------------------------- /tests/shadow_static_var1.znn: -------------------------------------------------------------------------------- 1 | // 6 2 | 3 | template 4 | int get() { 5 | return N; 6 | } 7 | 8 | int main() { 9 | static mutable a = 3; 10 | a = a + 1; 11 | [@shadow] 12 | static mutable a = a + 1; 13 | a = a + 1; 14 | return get(); 15 | } 16 | -------------------------------------------------------------------------------- /tests/static_mutable_variable3.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | enum E { 4 | E1, 5 | E2 6 | }; 7 | 8 | int main() { 9 | const e = E::E1; 10 | switch (e) { 11 | case (E1) { static mutable u = 0; ++u; return u; } 12 | case (E2) {} 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/to_string2.znn: -------------------------------------------------------------------------------- 1 | // 11 2 | 3 | struct X { 4 | }; 5 | 6 | template 7 | struct Y { 8 | }; 9 | 10 | template 11 | int get() { 12 | return to_string(T).size(); 13 | } 14 | 15 | int main() { 16 | return get() + get>() + get(); 17 | } 18 | -------------------------------------------------------------------------------- /tests/variadic_args_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | void f1(T arg1) { 5 | } 6 | 7 | void f1() { 8 | } 9 | 10 | template 11 | void f2(Args*... args) { 12 | f1(args...); 13 | } 14 | 15 | int main() { 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/codegen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "stdafx.h" 4 | 5 | class AST; 6 | class Context; 7 | class TypeRegistry; 8 | 9 | extern string codegen(const vector&, TypeRegistry& registry, const string& codegenInclude, 10 | bool includeLineNumbers); 11 | -------------------------------------------------------------------------------- /tests/attribute_bad6.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | attribute @a1; 4 | 5 | template requires has_attribute 6 | int f() { 7 | return 1; 8 | } 9 | 10 | template 11 | int g() { 12 | return f(); 13 | } 14 | 15 | int main() { 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/concept_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | concept C1 { 4 | }; 5 | 6 | template requires (T != int) 7 | struct X { 8 | }; 9 | 10 | template requires C1> 11 | int f() { 12 | return 1; 13 | } 14 | 15 | int main() { 16 | return f(); 17 | } 18 | -------------------------------------------------------------------------------- /tests/constructor_default1.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | export struct X { 4 | int a; 5 | }; 6 | 7 | export X(int) = default; 8 | 9 | export X() { 10 | return X::X(1); 11 | } 12 | 13 | int main() { 14 | const x = X(); 15 | const y = X(2); 16 | return x.a + y.a; 17 | } 18 | -------------------------------------------------------------------------------- /tests/destructor5.znn: -------------------------------------------------------------------------------- 1 | // 4 2 | 3 | struct X { 4 | int mutable* cnt; 5 | }; 6 | 7 | void destruct(X* x) { 8 | ++*x^.cnt; 9 | } 10 | 11 | int main() { 12 | mutable a = 3; 13 | { 14 | if (true) 15 | const x = X(&a); 16 | } 17 | return a; 18 | } 19 | -------------------------------------------------------------------------------- /tests/empty_return_in_template.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | template 4 | void f(T mutable* a, T b, bool x) { 5 | if (x) 6 | return; 7 | *a = move(b); 8 | } 9 | 10 | int main() { 11 | mutable x = 1; 12 | const y = 2; 13 | f(&x, y, false); 14 | return x; 15 | } 16 | -------------------------------------------------------------------------------- /tests/enum_size_in_template_fun1.znn: -------------------------------------------------------------------------------- 1 | // 8 2 | 3 | template requires is_enum 4 | int f() { 5 | return enum_count(E); 6 | } 7 | 8 | enum E1 { 9 | A, 10 | B, 11 | C, 12 | D 13 | }; 14 | 15 | int main() { 16 | return f() + enum_count(E1); 17 | } 18 | -------------------------------------------------------------------------------- /tests/function.znn: -------------------------------------------------------------------------------- 1 | // 9 2 | 3 | int sum(int a, int b) { 4 | return a + b; 5 | } 6 | 7 | int main() { 8 | const b = true; 9 | if (b) { 10 | mutable x = sum(3, 4); 11 | x = x + sum(.a = 32, .b = -30); 12 | return x; 13 | } 14 | return 1; 15 | } 16 | -------------------------------------------------------------------------------- /tests/lambda_capture_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | }; 5 | 6 | int main() { 7 | mutable x = 5; 8 | mutable y = 5; 9 | const f = [x]{ 10 | const g = [y] { 11 | return y; 12 | }; 13 | return x; 14 | }; 15 | return f(); 16 | } 17 | -------------------------------------------------------------------------------- /tests/lambda_mutable_ptr1.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | template requires invoke 4 | int get(Fun mutable* ar) { 5 | return 1 + ar^.invoke(1); 6 | } 7 | 8 | int main() { 9 | mutable lambda = [&](int s) { return s * 2; }; 10 | return get(&lambda); 11 | } 12 | -------------------------------------------------------------------------------- /tests/method_overload4.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | int f(int mutable* a, int b) { 4 | return 1; 5 | } 6 | 7 | int f(int a, int b) { 8 | return 2; 9 | } 10 | 11 | int main() { 12 | int x = 1; 13 | if (1.f(5) == 2) 14 | return 1; 15 | else 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/named_args_overload4.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | int f(int a, bool b) { 4 | return 1; 5 | } 6 | 7 | bool f(int a, int c) { 8 | return true; 9 | } 10 | 11 | int main() { 12 | if (1.f(.c = 5)) 13 | return 1.f(.b = false); 14 | else 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/operator_pointer_args.znn: -------------------------------------------------------------------------------- 1 | // 7 2 | 3 | 4 | struct X { 5 | int x; 6 | }; 7 | 8 | X operator + (X* x1, X* x2) { 9 | return X(x1^.x + x2^.x); 10 | } 11 | 12 | int main() { 13 | const a = X(3); 14 | const b = X(4); 15 | return (a + b).x; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /tests/static_for_bad7.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | int get() { 5 | return N; 6 | } 7 | 8 | int main() { 9 | mutable res = 0; 10 | static for (i = 0; i < 6; ++i) { 11 | foobar(); 12 | res += get(); 13 | } 14 | return res; 15 | } 16 | -------------------------------------------------------------------------------- /src/lambda_capture_info.cpp: -------------------------------------------------------------------------------- 1 | #include "lambda_capture_info.h" 2 | 3 | 4 | const LambdaCaptureInfo::Var* LambdaCaptureInfo::find(const string& var) const { 5 | for (auto& elem : captures) 6 | if (elem.name == var) 7 | return &elem; 8 | return nullptr; 9 | } 10 | -------------------------------------------------------------------------------- /tests/arithmetic.znn: -------------------------------------------------------------------------------- 1 | // 116 2 | 3 | int f() { 4 | return 5; 5 | } 6 | 7 | int main() { 8 | const x = 3 * 3 + 1; 9 | int y = 3 * (3 + 1); 10 | int z = 1 + 3 * 3; 11 | int u = -z; 12 | int v = +z; 13 | return -f() * 3 + 1 - 2 + 100 + x + y + z + u + v; 14 | } 15 | -------------------------------------------------------------------------------- /tests/concept_type_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | concept C1 { 4 | T call(T*, int); 5 | }; 6 | 7 | struct X { 8 | }; 9 | 10 | X call(X*, int) { 11 | return X(); 12 | } 13 | 14 | int main() { 15 | const x = X(); 16 | const C1* c1 = &x; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /tests/import_double/struct1.znn: -------------------------------------------------------------------------------- 1 | export import "print.znn"; 2 | 3 | 4 | export struct Struct1 { 5 | X x; 6 | bool b; 7 | }; 8 | 9 | export int get(Struct1* s) { 10 | return getInt((*s).x.a); 11 | } 12 | 13 | template 14 | void f1(T t) { 15 | X x = X(1); 16 | } 17 | -------------------------------------------------------------------------------- /tests/instance_context/fun.znn: -------------------------------------------------------------------------------- 1 | 2 | export concept C1 { 3 | int g(T*); 4 | }; 5 | 6 | export template requires C1 7 | int f(T* t) { 8 | return g(t); 9 | } 10 | 11 | export template requires C1 12 | int f(T t) { 13 | return g(&t) + f(&t); 14 | } 15 | -------------------------------------------------------------------------------- /tests/method_overload2.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | int f(int mutable* a, int b) { 4 | return 1; 5 | } 6 | 7 | int f(int a, int b) { 8 | return 2; 9 | } 10 | 11 | int main() { 12 | int x = 1; 13 | if (1.f(.b = 5) == 2) 14 | return 1; 15 | else 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/method_overload3.znn: -------------------------------------------------------------------------------- 1 | // 22 2 | 3 | struct X { 4 | }; 5 | 6 | X implicit_copy(X*) = default; 7 | 8 | int f(X*) { return 1; } 9 | int f(X) { return 2; } 10 | 11 | int main() { 12 | const x = X(); 13 | const y = X(); 14 | return 10 * move(x).f() + y.f(); 15 | } 16 | -------------------------------------------------------------------------------- /tests/move_in_loop_bad4.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable y = 2; 5 | mutable x = 0; 6 | while (true) { 7 | if (y == 3) { 8 | x = move(y); 9 | break; 10 | } 11 | y = y + 1; 12 | } 13 | y = 0; 14 | return x; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /tests/multiline_comment.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | import "std/vector.znn"; 4 | 5 | int main() { 6 | /* pwoewpfk 7 | ewpfokwef 8 | ewpfok */ 9 | mutable v = vector(); 10 | /* ppokwef */ 11 | const x = &v; 12 | x^.push_back(5); 13 | return v[0]; 14 | } 15 | -------------------------------------------------------------------------------- /tests/operator_overload_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | concept Arithmetic { 4 | A operator + (A a, A b, A c); 5 | }; 6 | 7 | template requires Arithmetic 8 | T getResult(T t1, T t2) { 9 | return t1; 10 | } 11 | 12 | int main() { 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/ranged_loop2.znn: -------------------------------------------------------------------------------- 1 | // 10 2 | 3 | import "std/vector.znn"; 4 | 5 | struct X { 6 | vector a; 7 | }; 8 | 9 | int main() { 10 | mutable res = 0; 11 | const x = X({1, 2, 3, 4}.as_vector()); 12 | for (it : x.a) 13 | res += *it; 14 | return res; 15 | } 16 | -------------------------------------------------------------------------------- /tests/static_if1.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | template 4 | int f() { 5 | return N; 6 | } 7 | 8 | int main() { 9 | static mutable a = 1; 10 | static const b = true; 11 | static if (b) 12 | ++a; 13 | static if (false) 14 | a = 0; 15 | return f(); 16 | } 17 | -------------------------------------------------------------------------------- /tests/static_while1.znn: -------------------------------------------------------------------------------- 1 | // 36 2 | 3 | template 4 | int get() { 5 | return N; 6 | } 7 | 8 | int main() { 9 | mutable res = 0; 10 | static mutable a = 0; 11 | static while (a < 8) { 12 | ++a; 13 | res += get(); 14 | } 15 | return res; 16 | } 17 | -------------------------------------------------------------------------------- /tests/struct2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | struct V { 5 | int a; 6 | }; 7 | 8 | 9 | int main() { 10 | mutable a = V(1); 11 | mutable b = V(2); 12 | mutable c = V(3); 13 | b = move(a); 14 | c = move(b); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/subscript3.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | struct A { 4 | }; 5 | 6 | char operator[](A* a, string s) { 7 | return s[0]; 8 | } 9 | 10 | int main() { 11 | const a = A(); 12 | const b = a["pok"]; 13 | if (b == 'p') 14 | return 1; 15 | else 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/subscript_template_arg.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | struct A { 4 | }; 5 | 6 | template 7 | T operator [] (A* a, mutable T b) { 8 | return move(b); 9 | } 10 | 11 | int main() { 12 | const x = 5; 13 | const a = A(); 14 | mutable y = a[&x]; 15 | return *y; 16 | } 17 | -------------------------------------------------------------------------------- /tests/template_expression2.znn: -------------------------------------------------------------------------------- 1 | // 13 2 | 3 | template 4 | struct X { 5 | }; 6 | 7 | template 8 | int g() { 9 | static const y = A + B; 10 | X<(A + B)> x = X(); 11 | return y; 12 | } 13 | 14 | int main() { 15 | return g<6, 7>(); 16 | } 17 | -------------------------------------------------------------------------------- /tests/variadic_args3.znn: -------------------------------------------------------------------------------- 1 | // 6 2 | 3 | int cnt() { 4 | return 0; 5 | } 6 | 7 | template 8 | int cnt() { 9 | return 1 + cnt(); 10 | } 11 | 12 | struct X {}; 13 | 14 | int main() { 15 | return cnt(); 16 | } 17 | -------------------------------------------------------------------------------- /tests/vector_transform1.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | import "std/vector.znn"; 4 | 5 | struct X { 6 | int a; 7 | }; 8 | 9 | int main() { 10 | const v = {1, 2, 3, 4, 5}.as_vector(); 11 | const u = v.transform([](int* a) -> X { return X(*a);}); 12 | return u[2].a; 13 | } 14 | -------------------------------------------------------------------------------- /tests/concept_type12.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | concept C { 4 | int f(T*); 5 | }; 6 | 7 | struct X{}; 8 | 9 | int f(X*) { return 2; } 10 | 11 | template requires C 12 | int eat(T* t) { 13 | return t^.f(); 14 | } 15 | 16 | int main() { 17 | return eat(&X()); 18 | } 19 | -------------------------------------------------------------------------------- /tests/lambda9.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | template requires construct 4 | int f() { 5 | const l = []() { 6 | return 1; 7 | }; 8 | return l(); 9 | } 10 | 11 | struct X { 12 | }; 13 | 14 | struct Y { 15 | }; 16 | 17 | int main() { 18 | return f() + f(); 19 | } 20 | -------------------------------------------------------------------------------- /tests/lambda_capture_by_move2.znn: -------------------------------------------------------------------------------- 1 | // 4 2 | 3 | import "std/box.znn"; 4 | 5 | struct X { 6 | box u; 7 | }; 8 | 9 | int main() { 10 | mutable x = X(box(5)); 11 | const y = x.u.get(); 12 | const f = [move(x)]{ return *x.u; }; 13 | *y = 4; 14 | return f(); 15 | } 16 | -------------------------------------------------------------------------------- /tests/move_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable x = 1; 5 | mutable y = 2; 6 | mutable z = 3; 7 | if (x == 1) 8 | discard move(x); 9 | else if (x == 2) 10 | discard move(y); 11 | if (z == 3) 12 | x = x + 1; 13 | return 0; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /tests/no_copy2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | import "std/concepts.znn"; 4 | 5 | template requires copy 6 | void f(T t) { 7 | T t2 = t.copy(); 8 | } 9 | 10 | template 11 | struct X { 12 | T t; 13 | }; 14 | 15 | int main() { 16 | f(X(1)); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /tests/noreturn1.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | noreturn exitProgram() { 4 | embed { 5 | throw std::exception(); 6 | } 7 | } 8 | 9 | int get(bool b) { 10 | if (b) 11 | return 5; 12 | else 13 | exitProgram(); 14 | } 15 | 16 | int main() { 17 | return get(true); 18 | } 19 | -------------------------------------------------------------------------------- /tests/static_mutable_variable_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | enum E { 4 | E1, 5 | E2 6 | }; 7 | 8 | int main() { 9 | static mutable res = 0; 10 | const e = E::E1; 11 | switch (e) { 12 | case (E1) { ++res; } 13 | case (E2) {} 14 | } 15 | return res; 16 | } 17 | -------------------------------------------------------------------------------- /codegen_includes/main_body_args.h: -------------------------------------------------------------------------------- 1 | 2 | int main(int argc, char* argv[]) { 3 | auto strings = new zenon_string[argc]; 4 | for (int i = 0; i < argc; ++i) 5 | strings[i] = zenon_string::reference(argv[i]); 6 | return zenonMain(slice_t{strings, strings + argc}); 7 | } 8 | 9 | -------------------------------------------------------------------------------- /tests/array_transform1.znn: -------------------------------------------------------------------------------- 1 | // 15 2 | 3 | int main(string[] args) { 4 | const a = {"pokpok", "xyz", "u" }; 5 | const b = a.transform([](string* s) { return s^.size(); }); 6 | mutable res = 0; 7 | for (it : b) 8 | res += (it.index + 1) * *it; 9 | return res; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/auto_equality_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct A { 4 | }; 5 | 6 | [@auto_equality] 7 | struct X { 8 | int i; 9 | string s; 10 | A a; 11 | }; 12 | 13 | 14 | int main() { 15 | if (X(1, "pok", A()) == X(1, "pok", A())) 16 | return 1; 17 | return 2; 18 | } 19 | -------------------------------------------------------------------------------- /tests/countof_template_arg1.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | template 4 | T getValue() { 5 | return value; 6 | } 7 | 8 | template 9 | int get(T... args) { 10 | return getValue(); 11 | } 12 | 13 | int main() { 14 | return get(true, "pok", 1); 15 | } 16 | -------------------------------------------------------------------------------- /tests/destructor_requirement_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | struct X { 5 | T elem; 6 | }; 7 | 8 | template requires invoke 9 | void destruct(X* x) { 10 | x^.elem(); 11 | } 12 | 13 | int main() { 14 | const a = X(5); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/function_type3.znn: -------------------------------------------------------------------------------- 1 | // 9 2 | 3 | int fa(string s) { 4 | return s.size(); 5 | } 6 | 7 | template requires invoke 8 | Ret get(Fun f, Arg arg) { 9 | return f(move(arg)); 10 | } 11 | 12 | int main() { 13 | return get(fa, "pokpakpik"); 14 | } 15 | -------------------------------------------------------------------------------- /tests/import_union/struct2.znn: -------------------------------------------------------------------------------- 1 | 2 | export template 3 | union V2 { 4 | T t; 5 | U u; 6 | }; 7 | 8 | export template 9 | X get(V2* v, T t, U u, mutable X x) { 10 | return move(x); 11 | } 12 | 13 | void f() { 14 | const x = V2::u(5); 15 | } 16 | -------------------------------------------------------------------------------- /tests/lambda_capture_by_copy2.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | template 4 | struct X { 5 | T a; 6 | }; 7 | 8 | template requires copy 9 | X copy(X* x) = default; 10 | 11 | int main() { 12 | const x = X(3); 13 | const f = [copy(x)]{ return x.a;}; 14 | return f(); 15 | } 16 | -------------------------------------------------------------------------------- /tests/lambda_implicit_return3.znn: -------------------------------------------------------------------------------- 1 | // 31 2 | 3 | template 4 | T get(T a) { 5 | const f = [](T t) { return move(t); }; 6 | return f(move(a)); 7 | } 8 | 9 | struct X { 10 | int a; 11 | }; 12 | 13 | int main() { 14 | const x = X(31); 15 | return get(move(x)).a; 16 | } 17 | -------------------------------------------------------------------------------- /tests/concept_type_import3/main.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | import "input2.znn"; 4 | 5 | concept C1 { 6 | int f(T*); 7 | }; 8 | 9 | struct X {}; 10 | 11 | int f(X*) { return 1; } 12 | 13 | int main() { 14 | const x = X(); 15 | const c = x.cast_to(); 16 | return c^.f(); 17 | } 18 | -------------------------------------------------------------------------------- /tests/function_concept_bad.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | concept CanAdd { 4 | T operator + (T* t1, T* t2); 5 | }; 6 | 7 | template requires CanAdd 8 | A add(A a, A b) { 9 | return a + b; 10 | } 11 | 12 | int main() { 13 | const c = add('a', 'b'); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/implicit_conversion_to_union1.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | union X { 4 | int a; 5 | double b; 6 | }; 7 | 8 | X get() { 9 | return 5; 10 | } 11 | 12 | int main() { 13 | const x = get(); 14 | switch (x) { 15 | case (a) { return a; } 16 | default { return 13; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/lambda4.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | concept invoke { 4 | U invoke(T*); 5 | }; 6 | 7 | template requires invoke 8 | T run(Fun f) { 9 | return f(); 10 | } 11 | 12 | int main() { 13 | const f = [] () -> int { return 1; }; 14 | return run(move(f)); 15 | } 16 | -------------------------------------------------------------------------------- /tests/move_in_expression.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct S { 4 | int x; 5 | }; 6 | 7 | int get(S* s, int x) { 8 | return x + s^.x; 9 | } 10 | 11 | int get(S s) { 12 | return s.x; 13 | } 14 | 15 | int main() { 16 | const s = S(1); 17 | return get(&s, get(move(s))); 18 | } 19 | -------------------------------------------------------------------------------- /tests/named_args_overload5.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | int f(int* a, bool b) { 4 | return 1; 5 | } 6 | 7 | bool f(int* a, int c) { 8 | return true; 9 | } 10 | 11 | int main() { 12 | int x = 1; 13 | if (x.f(.c = 5)) 14 | return x.f(.b = false); 15 | else 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/variadic_concept3.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | concept can_call { 4 | Ret f(Args...); 5 | }; 6 | 7 | template requires can_call 8 | Ret g(U) { 9 | return f(); 10 | } 11 | 12 | int f() { return 5;} 13 | 14 | int main() { 15 | return g("pok"); 16 | } 17 | -------------------------------------------------------------------------------- /tests/break2.znn: -------------------------------------------------------------------------------- 1 | // 35 2 | 3 | int main() { 4 | mutable int sum = 0; 5 | for (i = 0; i < 100; ++i) { 6 | if (i == 7) 7 | break; 8 | for (j = 0; j < 100; ++j) { 9 | if (j == 5) 10 | break; 11 | ++sum; 12 | } 13 | } 14 | return sum; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /tests/concept_type4.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | concept C1 { 4 | int get(T*); 5 | }; 6 | 7 | struct X { 8 | int a; 9 | }; 10 | 11 | template 12 | int get(T* x) { 13 | return 5; 14 | } 15 | 16 | int main() { 17 | const x = X(5); 18 | const C1* c = &x; 19 | return c^.get(); 20 | } 21 | -------------------------------------------------------------------------------- /tests/import/print.znn: -------------------------------------------------------------------------------- 1 | embed { 2 | #include 3 | constexpr int g = 5; 4 | } 5 | 6 | export int getInt(int x) { 7 | embed { 8 | return g + x; 9 | } 10 | } 11 | 12 | export template 13 | T getSecond(T t, T u, T v) { 14 | embed { 15 | return u; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/move_bad4.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | int main() { 4 | mutable x = 1; 5 | mutable y = 2; 6 | mutable z = 3; 7 | if (x == 1) 8 | discard move(x); 9 | else if (x == 2) 10 | discard move(y); 11 | else if (x == 3) 12 | discard move(z); 13 | return y; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /tests/move_in_if2.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | int? g1() { 4 | return null; 5 | } 6 | 7 | int? g2() { 8 | return 2; 9 | } 10 | 11 | int main() { 12 | mutable ret = 0; 13 | if (const p = g1()) 14 | ret = *move(p); 15 | if (const p = g2()) 16 | ret = *move(p); 17 | return ret; 18 | } 19 | -------------------------------------------------------------------------------- /tests/static_mutable_string2.znn: -------------------------------------------------------------------------------- 1 | // 20 2 | 3 | template 4 | int size() { 5 | return S.size(); 6 | } 7 | 8 | int main() { 9 | static mutable stmt = "abc"; 10 | static for (i = 0; i < 5; ++i) 11 | stmt = stmt + "pak"; 12 | stmt += "po"; 13 | return size(); 14 | } 15 | -------------------------------------------------------------------------------- /tests/subscript2.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | struct A { 4 | string s; 5 | }; 6 | 7 | char operator[](A* a, int x) { 8 | return a^.s[x]; 9 | } 10 | 11 | int main() { 12 | const a = A("dupa"); 13 | const b = a[0]; 14 | if (b == a[0]) 15 | return 1; 16 | else 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /tests/switch_move_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | union U { 4 | int a; 5 | double b; 6 | string s; 7 | }; 8 | 9 | int main() { 10 | const u = U::a(1); 11 | switch (u) { 12 | case (a) { 13 | return move(a); 14 | } 15 | default {} 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /tests/switch_move_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | union U { 4 | int a; 5 | double b; 6 | string s; 7 | }; 8 | 9 | int main() { 10 | mutable u = U::a(1); 11 | switch (u) { 12 | case (a) { 13 | return move(a); 14 | } 15 | default {} 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /tests/template_function2.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | concept C { 4 | int get(T*); 5 | }; 6 | 7 | int get(int?* i) { 8 | return *i ?? 3; 9 | } 10 | 11 | template requires C 12 | int get2(T t) { 13 | return get(&t); 14 | } 15 | 16 | int main() { 17 | return get2(null); 18 | } 19 | -------------------------------------------------------------------------------- /tests/ambigous_method.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | }; 5 | 6 | X copy(X*) = default; 7 | 8 | int f(X*, int a) { 9 | return 1; 10 | } 11 | 12 | int f(X x, int c) { 13 | return 2; 14 | } 15 | 16 | int main() { 17 | const x = X(); 18 | x.copy().f(3); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /tests/concept_type5.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | concept C1 { 4 | int get(T*); 5 | }; 6 | 7 | template 8 | struct X { 9 | T a; 10 | }; 11 | 12 | int get(X* x) { 13 | return x^.a; 14 | } 15 | 16 | int main() { 17 | const x = X(5); 18 | const C1* c = &x; 19 | return c^.get(); 20 | } 21 | -------------------------------------------------------------------------------- /tests/deduce_from_concept_lambda1.znn: -------------------------------------------------------------------------------- 1 | // 6 2 | 3 | template requires invoke 4 | Ret run_fun(Fun f, Arg... a) { 5 | return f(move(a)...); 6 | } 7 | 8 | int main(string[] args) { 9 | return run_fun([](string s) { return s.size(); }, "pokpok"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/incomplete_struct_import3/main.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | import "input2.znn"; 4 | 5 | template requires is_struct 6 | int get() { 7 | return 1; 8 | } 9 | 10 | template requires is_union 11 | int get() { 12 | return 2; 13 | } 14 | 15 | int main() { 16 | return get(); 17 | } 18 | -------------------------------------------------------------------------------- /tests/lambda_capture_by_copy_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | struct X { 5 | T a; 6 | }; 7 | 8 | template requires (T == bool) 9 | X copy(X* x) = default; 10 | 11 | int main() { 12 | const x = X(3); 13 | const f = [copy(x)]{ return x.a;}; 14 | return f(); 15 | } 16 | -------------------------------------------------------------------------------- /tests/operator_pointer_args3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct A { 4 | }; 5 | 6 | int operator + (A* a, A *b) { 7 | return 0; 8 | } 9 | 10 | int main() { 11 | const a = A(); 12 | const b = A(); 13 | const pa = &a; 14 | const pb = &b; 15 | const c = pa + pb; 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/switch_multiple_elems1.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | enum E { 4 | E1, 5 | E2, 6 | E3, 7 | E4 8 | }; 9 | 10 | int main() { 11 | const e = E::E1; 12 | switch (e) { 13 | case (E2, E4) { 14 | return 1; 15 | } 16 | case (E1, E3) { 17 | return 2; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/template_requirement3.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | template 4 | struct X { 5 | U u; 6 | }; 7 | 8 | template requires (U == int) 9 | void destruct(X*) { 10 | } 11 | 12 | template 13 | X f(T t) { 14 | return X(move(t)); 15 | } 16 | 17 | int main() { 18 | return f(2).u; 19 | } 20 | -------------------------------------------------------------------------------- /tests/try_op_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X { 4 | int? a; 5 | }; 6 | 7 | X get(int a) { 8 | return X(a); 9 | } 10 | 11 | int? f() { 12 | const x = 1; 13 | const ret = try get(move(x)).a + 1; 14 | return ret + x; 15 | } 16 | 17 | int main() { 18 | return f() ?? 3; 19 | } 20 | -------------------------------------------------------------------------------- /tests/union_constructor1.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | export union V { 4 | int a; 5 | bool b; 6 | }; 7 | 8 | V() { 9 | return V::a(5); 10 | } 11 | 12 | int main() { 13 | const v = V(); 14 | switch (move(v)) { 15 | case (a) { return a; } 16 | case (b) { return 0; } 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /tests/concept_type_bad4.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | concept C1 { 4 | T call(T*, int); 5 | U call2(U*, int); 6 | }; 7 | 8 | struct X { 9 | }; 10 | 11 | X call(X*, int) { 12 | return X(); 13 | } 14 | 15 | int main() { 16 | const x = X(); 17 | const C1* c1 = &x; 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /tests/function_type4.znn: -------------------------------------------------------------------------------- 1 | // 9 2 | 3 | import "std/io.znn"; 4 | 5 | concept printable { 6 | string to_string(T*); 7 | }; 8 | 9 | template requires printable 10 | int fa(T t) { 11 | return "{t}".size(); 12 | } 13 | 14 | int main() { 15 | return fa(123) + fa("pokpak"); 16 | } 17 | -------------------------------------------------------------------------------- /tests/import_methods/s1.znn: -------------------------------------------------------------------------------- 1 | 2 | export template 3 | struct X { 4 | T v; 5 | }; 6 | 7 | export template 8 | T* get(X* x) { 9 | return &(*x).v; 10 | } 11 | 12 | export template requires copy 13 | void set(X mutable* x, mutable T t) { 14 | (*x).v = move(t); 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/is_enum_concept1.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | template requires is_enum 4 | int f(E e1) { 5 | embed { 6 | return int(e1); 7 | } 8 | } 9 | 10 | enum E1 { 11 | A, 12 | B, 13 | C 14 | }; 15 | 16 | int main() { 17 | const e = E1::B; 18 | return f(E1::A) + f(e) + f(E1::C); 19 | } 20 | -------------------------------------------------------------------------------- /tests/move1.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | struct X { 4 | int a; 5 | }; 6 | 7 | template 8 | T get(mutable T a) { 9 | mutable o = move(a); 10 | return move(o); 11 | } 12 | 13 | template 14 | T get2(mutable T a) { 15 | return move(a); 16 | } 17 | 18 | int main() { 19 | return get(X(5)).a; 20 | } 21 | -------------------------------------------------------------------------------- /tests/overload_resolution2.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | struct X { 4 | }; 5 | 6 | template 7 | void operator -(T?*, X a) { 8 | } 9 | 10 | template 11 | int operator -(T*?*, X a) { 12 | return 2; 13 | } 14 | 15 | int main() { 16 | const x = 5; 17 | const int*? y = &x; 18 | return y - X(); 19 | } 20 | -------------------------------------------------------------------------------- /tests/type_alias4.znn: -------------------------------------------------------------------------------- 1 | // 5 2 | 3 | template 4 | struct X { 5 | }; 6 | 7 | template 8 | X() { return X::X();} 9 | 10 | template 11 | T f(X*, T t) { 12 | return move(t); 13 | } 14 | 15 | using A = X; 16 | 17 | int main() { 18 | const a = A(); 19 | return a.f(5); 20 | } 21 | -------------------------------------------------------------------------------- /codegen_includes/main_body_args_void.h: -------------------------------------------------------------------------------- 1 | 2 | int main(int argc, char* argv[]) { 3 | auto strings = new zenon_string[argc]; 4 | for (int i = 0; i < argc; ++i) 5 | strings[i] = zenon_string::reference(argv[i]); 6 | zenonMain(slice_t{strings, strings + argc}); 7 | return 0; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /src/reader.cpp: -------------------------------------------------------------------------------- 1 | #include "reader.h" 2 | 3 | WithError readFromFile(const char* path){ 4 | ifstream in; 5 | in.open(path); 6 | if (!in.good()) 7 | return "Failed to open file " + quote(path); 8 | stringstream ss; 9 | ss << in.rdbuf(); 10 | return FileContents{ss.str()}; 11 | } 12 | -------------------------------------------------------------------------------- /tests/address_of_temporary.znn: -------------------------------------------------------------------------------- 1 | // 6 2 | 3 | struct S { 4 | int a; 5 | }; 6 | 7 | S get() { 8 | return S(1); 9 | } 10 | 11 | int value(S* s) { 12 | return s^.a; 13 | } 14 | 15 | int value2(int* a) { 16 | return *a; 17 | } 18 | 19 | int main() { 20 | return value(&get()) + value2(&5); 21 | } 22 | -------------------------------------------------------------------------------- /tests/enum_bad4.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | enum E1 { 3 | VALUE1 4 | VALUE2, 5 | VALUE3, 6 | VALUE4 7 | }; 8 | 9 | int main() { 10 | const e1 = E1::VALUE2; 11 | switch (e1) { 12 | case (VALUE2) { 13 | return 1; 14 | } 15 | default { 16 | return 3; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/has_members_bad2.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | struct X {}; 4 | 5 | struct Y { 6 | X a; 7 | int b; 8 | string c; 9 | }; 10 | 11 | template requires is_struct, has_members 12 | void f() { 13 | } 14 | 15 | int main() { 16 | f(); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /tests/hash_map_iterator1.znn: -------------------------------------------------------------------------------- 1 | // 40 2 | 3 | import "std/hash_map.znn"; 4 | 5 | int main() { 6 | mutable m = hash_map(); 7 | m.insert("pok", 1); 8 | m.insert("pakpak", 30); 9 | mutable res = 0; 10 | for (it : m) 11 | res += it.key()^.size() + *it.value(); 12 | return res; 13 | } 14 | -------------------------------------------------------------------------------- /tests/implicit_conversion_to_union2.znn: -------------------------------------------------------------------------------- 1 | // 13 2 | 3 | union X { 4 | int a; 5 | double b; 6 | int c; 7 | }; 8 | 9 | X get() { 10 | return 5.0; 11 | } 12 | 13 | int main() { 14 | const x = get(); 15 | switch (x) { 16 | case (a) { return a; } 17 | default { return 13; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/io1.znn: -------------------------------------------------------------------------------- 1 | // 13 2 | 3 | import "std/io.znn"; 4 | 5 | int main(string[] args) { 6 | const path = args[0] + "tmp.txt"; 7 | open_file_w(path)^.printf("13\n"); 8 | const input = *open_file_r(path); 9 | const ret = input.scan_int(); 10 | assert(!remove_file(path)); 11 | return ret ?? 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/lambda11.znn: -------------------------------------------------------------------------------- 1 | // 1 2 | 3 | template 4 | struct TextArchive { 5 | Output output; 6 | }; 7 | 8 | template 9 | T print(TextArchive* ar, T a) { 10 | return move(a); 11 | } 12 | 13 | int main() { 14 | mutable ar = TextArchive([](){}); 15 | return ar.print(1); 16 | } 17 | -------------------------------------------------------------------------------- /tests/lambda_capture3.znn: -------------------------------------------------------------------------------- 1 | // 35 2 | 3 | template requires invoke 4 | int runFun(Fun f, T t) { 5 | return f(move(t)); 6 | } 7 | 8 | int main() { 9 | mutable res = 0; 10 | for (i = 0; i < 5; ++i) 11 | res += runFun([i] (int a) { return i + a; }, 5); 12 | return res; 13 | } 14 | -------------------------------------------------------------------------------- /tests/move_in_if.znn: -------------------------------------------------------------------------------- 1 | // 3 2 | 3 | int main() { 4 | mutable x = 2; 5 | mutable y = 3; 6 | mutable z = 4; 7 | mutable res = 0; 8 | if (x == 1) 9 | res = move(x); 10 | else if (x == 2) 11 | res = move(y); 12 | else if (x == 3) 13 | res = move(z); 14 | return move(res); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /tests/operator_value_or3.znn: -------------------------------------------------------------------------------- 1 | // 2 2 | 3 | struct X { 4 | int a; 5 | }; 6 | 7 | int inc(X mutable* x) { 8 | ++x^.a; 9 | return x^.a; 10 | } 11 | 12 | int? get() { 13 | return 1; 14 | } 15 | 16 | int main() { 17 | mutable x = X(1); 18 | const y = get() ?? x.inc(); 19 | return x.a + y; 20 | } 21 | -------------------------------------------------------------------------------- /tests/variadic_concept_bad1.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | concept can_call { 4 | Ret f(Args...); 5 | }; 6 | 7 | template requires can_call 8 | Ret g() { 9 | return f(); 10 | } 11 | 12 | int f() { 13 | return 3; 14 | } 15 | 16 | int main() { 17 | return g(); 18 | } 19 | -------------------------------------------------------------------------------- /tests/vector_iterator1.znn: -------------------------------------------------------------------------------- 1 | // 55 2 | 3 | import "std/vector.znn"; 4 | import "std/range.znn"; 5 | 6 | int main() { 7 | mutable a = vector(); 8 | for (i : range(1, 6)) 9 | a.push_back(i); 10 | mutable res = 0; 11 | for (it : a) 12 | res += (it.index + 1) * *it; 13 | return res; 14 | } 15 | -------------------------------------------------------------------------------- /tests/break3.znn: -------------------------------------------------------------------------------- 1 | // 7 2 | 3 | enum E { 4 | ELEM1 5 | }; 6 | 7 | int main() { 8 | mutable int sum = 7; 9 | const e = E::ELEM1; 10 | for (i = 0; i < 100; ++i) { 11 | switch (e) { 12 | default { 13 | break; 14 | } 15 | } 16 | ++sum; 17 | } 18 | return sum; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /tests/destructor6.znn: -------------------------------------------------------------------------------- 1 | // 4 2 | 3 | struct X { 4 | int mutable* cnt; 5 | }; 6 | 7 | void destruct(X* x) { 8 | ++*x^.cnt; 9 | } 10 | 11 | void f(X x) {} 12 | 13 | int main() { 14 | mutable a = 3; 15 | { 16 | const x = X(&a); 17 | if (true) 18 | f(move(x)); 19 | } 20 | return a; 21 | } 22 | -------------------------------------------------------------------------------- /tests/switch_multiple_elems_bad3.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | enum E { 4 | E1, 5 | E2, 6 | E3, 7 | E4 8 | }; 9 | 10 | int main() { 11 | const e = E::E1; 12 | switch (e) { 13 | case (E2, E4, E1, E3) { 14 | return 1; 15 | } 16 | default { 17 | return 0; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/template_requirement_bad8.znn: -------------------------------------------------------------------------------- 1 | // no_compile 2 | 3 | template 4 | struct X { 5 | U u; 6 | }; 7 | 8 | template requires (U == bool) 9 | void destruct(X*) { 10 | } 11 | 12 | template 13 | X f(T t) { 14 | return X(move(t)); 15 | } 16 | 17 | int main() { 18 | return f(2).u; 19 | } 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | stdafx.h.* 2 | Zenon.config 3 | Zenon.files 4 | Zenon.includes 5 | Zenon.creator* 6 | Zenon.cxxflags 7 | Zenon.cflags 8 | *.swp 9 | docs/_build 10 | .build_cache 11 | find 12 | obj/ 13 | obj-opt/ 14 | compile_flags.txt 15 | tests/.build_cache 16 | tests/log.out 17 | zenon 18 | log.out 19 | /*.znn 20 | input 21 | --------------------------------------------------------------------------------