├── .gitattributes ├── .github ├── FUNDING.yml ├── README_logo.png └── workflows │ └── remoteBuild.yml ├── .gitignore ├── CMakeLists.txt ├── CMakePresets.json ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── HOW_TO_BUILD.md ├── LICENSE ├── README.md ├── dev ├── README.md ├── find_duplicate_code.sh ├── iwyu.sh ├── iwyu_mappings.imp ├── lsan_suppressions.txt ├── lsan_use_suppressions_source.sh └── todolists │ ├── 2.8.todolist │ ├── breaking-future │ └── 3.0-way-future.todolist │ └── old │ ├── 2.3.todolist │ ├── partially-recovered-old.todolist │ ├── reducancy.todolist │ ├── todo.todolist │ └── verbose.todolist ├── include ├── AST │ ├── EXPR │ │ └── ast_expr_ids.h │ ├── POLY │ │ ├── ast_resolve.h │ │ └── ast_translate.h │ ├── TYPE │ │ ├── ast_type_hash.h │ │ ├── ast_type_identical.h │ │ ├── ast_type_make.h │ │ └── ast_type_set.h │ ├── UTIL │ │ └── string_builder_extensions.h │ ├── ast.h │ ├── ast_dump.h │ ├── ast_expr.h │ ├── ast_expr_lean.h │ ├── ast_layout.h │ ├── ast_named_expression.h │ ├── ast_poly_catalog.h │ ├── ast_type.h │ ├── ast_type_lean.h │ └── meta_directives.h ├── BKEND │ ├── backend.h │ ├── backend_c.h │ ├── backend_llvm.h │ ├── ir_to_c.h │ └── ir_to_llvm.h ├── BRIDGE │ ├── any.h │ ├── bridge.h │ └── rtti_collector.h ├── BRIDGEIR │ ├── rtti.h │ ├── rtti_table.h │ └── rtti_table_entry.h ├── DBG │ └── debug.h ├── DRVR │ ├── compiler.h │ ├── config.h │ └── object.h ├── GENERATE │ └── generate_c.py ├── INFER │ └── infer.h ├── IR │ ├── ir.h │ ├── ir_dump.h │ ├── ir_func_endpoint.h │ ├── ir_lowering.h │ ├── ir_module.h │ ├── ir_pool.h │ ├── ir_proc_map.h │ ├── ir_proc_query.h │ ├── ir_type.h │ ├── ir_type_map.h │ ├── ir_type_spec.h │ ├── ir_value.h │ └── ir_value_str.h ├── IRGEN │ ├── ir_autogen.h │ ├── ir_build_instr.h │ ├── ir_build_literal.h │ ├── ir_builder.h │ ├── ir_cache.h │ ├── ir_gen.h │ ├── ir_gen_args.h │ ├── ir_gen_check_prereq.h │ ├── ir_gen_expr.h │ ├── ir_gen_find.h │ ├── ir_gen_find_sf.h │ ├── ir_gen_polymorphable.h │ ├── ir_gen_qualifiers.h │ ├── ir_gen_rtti.h │ ├── ir_gen_stmt.h │ ├── ir_gen_type.h │ ├── ir_gen_vtree.h │ └── ir_vtree.h ├── LEX │ ├── lex.h │ └── token.h ├── NET │ ├── download.h │ └── stash.h ├── PARSE │ ├── parse.h │ ├── parse_alias.h │ ├── parse_checks.h │ ├── parse_ctx.h │ ├── parse_dependency.h │ ├── parse_enum.h │ ├── parse_expr.h │ ├── parse_func.h │ ├── parse_global.h │ ├── parse_meta.h │ ├── parse_namespace.h │ ├── parse_pragma.h │ ├── parse_stmt.h │ ├── parse_struct.h │ ├── parse_type.h │ └── parse_util.h ├── TOKEN │ └── token_data.h └── UTIL │ ├── __insight.h │ ├── __insight_overloads.h │ ├── __insight_undo_overloads.h │ ├── builtin_type.h │ ├── color.h │ ├── datatypes.h │ ├── filename.h │ ├── func_pair.h │ ├── ground.h │ ├── hash.h │ ├── index_id_list.h │ ├── jsmn.h │ ├── jsmn_helper.h │ ├── levenshtein.h │ ├── list.h │ ├── search.h │ ├── set.h │ ├── string.h │ ├── string_builder.h │ ├── string_list.h │ ├── trait.h │ └── util.h ├── res ├── favicon.ico ├── icon.rc └── necessities │ ├── adept.config │ └── windows │ ├── bin │ ├── gcc.exe │ ├── ld.exe │ └── windres.exe │ ├── crt2.o │ ├── crtbegin.o │ ├── curl-ca-bundle.crt │ ├── include │ ├── _mingw.h │ ├── _mingw_mac.h │ ├── _mingw_secapi.h │ ├── _mingw_unicode.h │ ├── commctrl.rh │ ├── dde.rh │ ├── dlgs.h │ ├── sdkddkver.h │ ├── sdks │ │ └── _mingw_ddk.h │ ├── vadefs.h │ ├── windows.h │ ├── winnt.rh │ ├── winresrc.h │ ├── winuser.rh │ └── winver.h │ ├── libbrotlicommon.dll │ ├── libbrotlidec.dll │ ├── libcrypto-3-x64.dll │ ├── libcurl-4.dll │ ├── libdep.a │ ├── libexec │ └── gcc │ │ └── x86_64-w64-mingw32 │ │ └── 8.1.0 │ │ └── cc1.exe │ ├── libgcc_s_seh-1.dll │ ├── libiconv-2.dll │ ├── libidn2-0.dll │ ├── libintl-8.dll │ ├── libmsvcrt.a │ ├── libnghttp2-14.dll │ ├── libnghttp3-9.dll │ ├── libpsl-5.dll │ ├── libssh2-1.dll │ ├── libssl-3-x64.dll │ ├── libstdc++-6.dll │ ├── libunistring-5.dll │ ├── libwinpthread-1.dll │ ├── libzstd.dll │ └── zlib1.dll ├── src ├── AST │ ├── EXPR │ │ ├── ast_expr_free.c │ │ └── ast_expr_str.c │ ├── POLY │ │ ├── ast_resolve.c │ │ └── ast_translate.c │ ├── TYPE │ │ ├── ast_type_clone.c │ │ ├── ast_type_free.c │ │ ├── ast_type_hash.c │ │ ├── ast_type_helpers.c │ │ ├── ast_type_identical.c │ │ ├── ast_type_is.c │ │ ├── ast_type_make.c │ │ ├── ast_type_set.c │ │ └── ast_type_str.c │ ├── UTIL │ │ └── string_builder_extensions.c │ ├── ast.c │ ├── ast_dump.c │ ├── ast_expr.c │ ├── ast_layout.c │ ├── ast_named_expression.c │ ├── ast_poly_catalog.c │ └── meta_directives.c ├── BKEND │ ├── backend.c │ ├── ir_to_c.c │ ├── ir_to_llvm.c │ └── ir_to_llvm_impl.c ├── BRIDGE │ ├── any.c │ ├── bridge.c │ └── rtti_collector.c ├── BRIDGEIR │ ├── rtti.c │ ├── rtti_table.c │ └── rtti_table_entry.c ├── DBG │ └── debug.c ├── DRVR │ ├── compiler.c │ ├── config.c │ └── object.c ├── INFER │ └── infer.c ├── IR │ ├── ir.c │ ├── ir_dump.c │ ├── ir_func_endpoint.c │ ├── ir_lowering.c │ ├── ir_module.c │ ├── ir_pool.c │ ├── ir_proc_map.c │ ├── ir_proc_query.c │ ├── ir_type.c │ ├── ir_type_map.c │ ├── ir_type_spec.c │ └── ir_value_str.c ├── IRGEN │ ├── ir_autogen.c │ ├── ir_build_instr.c │ ├── ir_build_literal.c │ ├── ir_builder.c │ ├── ir_cache.c │ ├── ir_gen.c │ ├── ir_gen_args.c │ ├── ir_gen_check_prereq.c │ ├── ir_gen_expr.c │ ├── ir_gen_find.c │ ├── ir_gen_find_sf.c │ ├── ir_gen_polymorphable.c │ ├── ir_gen_qualifiers.c │ ├── ir_gen_rtti.c │ ├── ir_gen_stmt.c │ ├── ir_gen_type.c │ ├── ir_gen_vtree.c │ └── ir_vtree.c ├── LEX │ ├── lex.c │ └── token.c ├── MAIN │ └── main.c ├── NET │ ├── download.c │ └── stash.c ├── PARSE │ ├── parse.c │ ├── parse_alias.c │ ├── parse_checks.c │ ├── parse_ctx.c │ ├── parse_dependency.c │ ├── parse_enum.c │ ├── parse_expr.c │ ├── parse_func.c │ ├── parse_global.c │ ├── parse_meta.c │ ├── parse_namespace.c │ ├── parse_pragma.c │ ├── parse_stmt.c │ ├── parse_struct.c │ ├── parse_type.c │ └── parse_util.c ├── TOKEN │ └── token_data.c └── UTIL │ ├── __insight_Makefile │ ├── __insight_overloads.c │ ├── builtin_type.c │ ├── color.c │ ├── datatypes.c │ ├── filename.c │ ├── func_pair.c │ ├── ground.c │ ├── hash.c │ ├── jsmn_helper.c │ ├── levenshtein.c │ ├── list.c │ ├── search.c │ ├── set.c │ ├── string.c │ ├── string_builder.c │ ├── string_list.c │ └── util.c └── tests ├── CMakeLists.txt ├── e2e ├── CMakeLists.txt ├── e2e-runner.py ├── framework.py └── src │ ├── address │ └── main.adept │ ├── aliases │ └── main.adept │ ├── aliases_polymorphic │ └── main.adept │ ├── alignof │ └── main.adept │ ├── andor │ └── main.adept │ ├── andor_circuit │ └── main.adept │ ├── anonymous_composites │ └── main.adept │ ├── anonymous_enums │ └── main.adept │ ├── anonymous_fields │ └── main.adept │ ├── any_fixed_array │ └── main.adept │ ├── any_function_pointer │ └── main.adept │ ├── any_type_as │ └── main.adept │ ├── any_type_info │ └── main.adept │ ├── any_type_inventory │ └── main.adept │ ├── any_type_kind │ └── main.adept │ ├── any_type_list │ └── main.adept │ ├── any_type_offsets │ └── main.adept │ ├── any_type_sizes │ └── main.adept │ ├── array_access │ └── main.adept │ ├── as │ └── main.adept │ ├── assert_simple │ └── main.adept │ ├── assert_with_message │ └── main.adept │ ├── assign_func │ └── main.adept │ ├── assign_func_autogen │ └── main.adept │ ├── assignment │ └── main.adept │ ├── at │ └── main.adept │ ├── bitwise │ └── main.adept │ ├── bitwise_assign │ └── main.adept │ ├── break │ └── main.adept │ ├── break_to │ └── main.adept │ ├── cast │ └── main.adept │ ├── character_literals │ └── main.adept │ ├── circular_pointers │ └── main.adept │ ├── class │ └── main.adept │ ├── class_extends │ └── main.adept │ ├── class_missing_constructor │ └── main.adept │ ├── class_virtual_methods_1 │ └── main.adept │ ├── class_virtual_methods_2 │ └── main.adept │ ├── class_virtual_methods_3_missing_override │ └── main.adept │ ├── class_virtual_methods_4 │ └── main.adept │ ├── class_virtual_methods_5 │ └── main.adept │ ├── class_virtual_methods_6 │ └── main.adept │ ├── class_virtual_methods_7_incorrect_return_type │ └── main.adept │ ├── class_virtual_methods_8_unused_override │ └── main.adept │ ├── class_virtual_methods_9 │ └── main.adept │ ├── colons_alternative_syntax │ └── main.adept │ ├── complement │ └── main.adept │ ├── complex_composite_rtti │ └── main.adept │ ├── conditionless_block │ └── main.adept │ ├── conditionless_break_label │ └── main.adept │ ├── const_variables │ └── main.adept │ ├── constructor │ ├── constructor_in_only │ └── main.adept │ ├── constructor_with_defaults │ └── main.adept │ ├── continue │ └── main.adept │ ├── continue_to │ └── main.adept │ ├── default_args │ └── main.adept │ ├── defer │ └── main.adept │ ├── defer_auto_noop │ └── main.adept │ ├── defer_global │ └── main.adept │ ├── deprecated │ └── main.adept │ ├── dereference │ └── main.adept │ ├── disallow │ └── main.adept │ ├── disallow_assignment │ └── main.adept │ ├── disallow_assignment_container │ └── main.adept │ ├── disallow_funcaddr │ └── main.adept │ ├── disallow_poly │ └── main.adept │ ├── dropped_values │ └── main.adept │ ├── dylib │ ├── main.adept │ └── usage.adept │ ├── each_in │ └── main.adept │ ├── each_in_fixed │ └── main.adept │ ├── each_in_list │ └── main.adept │ ├── each_in_static │ └── main.adept │ ├── either_way_multiply │ └── main.adept │ ├── elif │ └── main.adept │ ├── embed │ ├── main.adept │ └── test.txt │ ├── entry_point │ └── main.adept │ ├── enums │ └── main.adept │ ├── enums_foreign │ └── main.adept │ ├── enums_relaxed_syntax │ └── main.adept │ ├── equals_func │ └── main.adept │ ├── external │ └── main.adept │ ├── fallthrough │ └── main.adept │ ├── fixed_array │ └── main.adept │ ├── fixed_array_alternative_syntax │ └── main.adept │ ├── fixed_array_assign │ └── main.adept │ ├── fixed_array_deference │ └── main.adept │ ├── fixed_array_pass │ └── main.adept │ ├── fixed_array_var_size │ └── main.adept │ ├── fixed_array_var_size_field │ └── main.adept │ ├── for │ └── main.adept │ ├── foreign_func_optional_names │ └── main.adept │ ├── foreign_in_namespace │ └── main.adept │ ├── func_aliases │ └── main.adept │ ├── func_aliases_va │ └── main.adept │ ├── funcaddr │ └── main.adept │ ├── funcaddr_autogen │ └── main.adept │ ├── funcaddr_autogen_noop_defer │ └── main.adept │ ├── funcaddrnull │ └── main.adept │ ├── funcptr │ └── main.adept │ ├── functions │ └── main.adept │ ├── globals │ └── main.adept │ ├── hello_world │ └── main.adept │ ├── hexadecimal │ └── main.adept │ ├── idx_manipulation │ └── main.adept │ ├── if │ └── main.adept │ ├── ifelse │ └── main.adept │ ├── import │ ├── hello.adept │ └── main.adept │ ├── import_std │ ├── main.adept │ └── other.adept │ ├── import_std_c_like │ └── main.adept │ ├── increment │ └── main.adept │ ├── increment_stmt │ └── main.adept │ ├── initializer_list │ └── main.adept │ ├── initializer_list_abstract │ └── main.adept │ ├── initializer_list_fixed │ └── main.adept │ ├── inline_declaration │ └── main.adept │ ├── inner_struct │ └── main.adept │ ├── inner_struct_polymorphic │ └── main.adept │ ├── int_ptr_cast │ └── main.adept │ ├── int_to_float_promotion_in_math │ └── main.adept │ ├── internal_deference │ └── main.adept │ ├── internal_deference_generic │ └── main.adept │ ├── list_map │ └── main.adept │ ├── llvm_asm │ └── main.adept │ ├── loose_struct_syntax │ └── main.adept │ ├── major_minor_release │ └── main.adept │ ├── management_access │ └── main.adept │ ├── management_as │ └── main.adept │ ├── management_assign │ └── main.adept │ ├── management_defer │ └── main.adept │ ├── management_math │ └── main.adept │ ├── management_pass │ └── main.adept │ ├── mathassign │ └── main.adept │ ├── mathassign_managed │ └── main.adept │ ├── member │ └── main.adept │ ├── meta │ └── main.adept │ ├── meta_dynamic │ └── main.adept │ ├── meta_get │ └── main.adept │ ├── methods │ └── main.adept │ ├── multiple_declaration │ └── main.adept │ ├── named_expressions │ └── main.adept │ ├── named_expressions_old_style │ └── main.adept │ ├── named_expressions_scoped │ └── main.adept │ ├── namespace_alternative_syntax │ └── main.adept │ ├── namespaces │ └── main.adept │ ├── native_linking_windows │ ├── glfw3.dll │ ├── libgdi32.a │ ├── libglfw3.a │ ├── libopengl32.a │ ├── main.adept │ └── opengl32.dll │ ├── negate │ └── main.adept │ ├── new_cstring │ └── main.adept │ ├── new_delete │ └── main.adept │ ├── new_dynamic │ └── main.adept │ ├── new_undef │ └── main.adept │ ├── newline_tolerance │ └── main.adept │ ├── no_discard │ └── main.adept │ ├── not │ └── main.adept │ ├── null │ └── main.adept │ ├── null_checks │ └── main.adept │ ├── numeric_separators │ └── main.adept │ ├── order │ └── main.adept │ ├── pass_func │ └── main.adept │ ├── permissive_blocks │ └── main.adept │ ├── poly_default_args │ └── main.adept │ ├── poly_prereq_extends │ └── main.adept │ ├── poly_prereq_extends_fail │ └── main.adept │ ├── polycount │ └── main.adept │ ├── polymorphic_anonymous_composites │ └── main.adept │ ├── polymorphic_anonymous_composites_mismatch │ └── main.adept │ ├── polymorphic_functions │ └── main.adept │ ├── polymorphic_inner │ └── main.adept │ ├── polymorphic_methods │ └── main.adept │ ├── polymorphic_prereqs │ └── main.adept │ ├── polymorphic_structs │ └── main.adept │ ├── pragma │ └── main.adept │ ├── primitives │ └── main.adept │ ├── records │ └── main.adept │ ├── records_polymorphic │ └── main.adept │ ├── repeat │ └── main.adept │ ├── repeat_args │ └── main.adept │ ├── repeat_fields │ └── main.adept │ ├── repeat_static │ └── main.adept │ ├── repeat_using │ └── main.adept │ ├── return_every_case │ └── main.adept │ ├── return_matching │ └── main.adept │ ├── return_ten │ └── main.adept │ ├── rtti_enum │ └── main.adept │ ├── runtime_resource │ ├── main.adept │ └── other │ │ ├── my_file.txt │ │ └── other.adept │ ├── scientific │ └── main.adept │ ├── scoped_variables │ └── main.adept │ ├── search_path │ ├── main.adept │ └── other_files │ │ └── file.adept │ ├── similar │ └── main.adept │ ├── sizeof │ └── main.adept │ ├── sizeof_value │ └── main.adept │ ├── small_functions │ └── main.adept │ ├── standard │ └── main.adept │ ├── static_arrays │ └── main.adept │ ├── static_structs │ └── main.adept │ ├── static_variables │ └── main.adept │ ├── stdcall │ └── main.adept │ ├── string │ └── main.adept │ ├── struct_association │ └── main.adept │ ├── structs │ └── main.adept │ ├── successful │ └── main.adept │ ├── super │ └── main.adept │ ├── super_polymorphic │ └── main.adept │ ├── switch │ └── main.adept │ ├── switch_exhaustive │ └── main.adept │ ├── switch_more │ └── main.adept │ ├── temporary_mutable │ └── main.adept │ ├── tentative_function_calls │ └── main.adept │ ├── tentative_method_calls │ └── main.adept │ ├── terminate_join │ └── main.adept │ ├── ternary │ └── main.adept │ ├── ternary_circuit │ └── main.adept │ ├── toggle │ └── main.adept │ ├── truefalse │ └── main.adept │ ├── typenameof │ └── main.adept │ ├── undef │ └── main.adept │ ├── union │ └── main.adept │ ├── unknown_enum_values │ └── main.adept │ ├── unknown_plural_enum_values │ └── main.adept │ ├── unless │ └── main.adept │ ├── unlesselse │ └── main.adept │ ├── unnecessary_manual_defer_call │ └── main.adept │ ├── unsupported │ └── main.adept │ ├── unterminated_comment │ └── main.adept │ ├── unterminated_cstring │ └── main.adept │ ├── unterminated_string │ └── main.adept │ ├── until │ └── main.adept │ ├── until_break │ └── main.adept │ ├── va_args │ └── main.adept │ ├── varargs │ └── main.adept │ ├── variables │ └── main.adept │ ├── variadic │ └── main.adept │ ├── variadic_method │ └── main.adept │ ├── variadic_print │ └── main.adept │ ├── version │ └── main.adept │ ├── void_ptr │ └── main.adept │ ├── volatile │ └── main.adept │ ├── vtable_checks │ └── main.adept │ ├── while │ └── main.adept │ ├── while_continue │ └── main.adept │ ├── windowed │ ├── GameData.adept │ ├── Textures.adept │ ├── assets │ │ └── example_texture.png │ └── main.adept │ ├── winmain_entry │ └── main.adept │ └── z_curl │ └── main.adept └── unit ├── CMakeLists.txt ├── framework ├── CuTest.c ├── CuTest.h └── LICENSE ├── include └── CuTestExtras.h └── src ├── UnitTestRunner.c ├── ast_expr.test.c └── lex.test.c /.gitattributes: -------------------------------------------------------------------------------- 1 | *.h linguist-language=C 2 | *.c linguist-language=C 3 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: IsaacShelton 4 | patreon: adeptlang 5 | custom: ['https://www.paypal.com/paypalme/adeptlang'] 6 | -------------------------------------------------------------------------------- /.github/README_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/.github/README_logo.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | build 3 | .vscode 4 | __pycache__ 5 | __ignore__ 6 | tests/e2e/**/main 7 | tests/e2e/**/*.o 8 | tests/e2e/**/*.dep 9 | tests/e2e/**/*.exe 10 | tests/e2e/src/**/pragma/pragma 11 | tests/e2e/src/native_linking/*.a 12 | tests/e2e/unused 13 | tests/e2e/src/runtime_resource/my_file.txt 14 | tests/e2e/src/dylib/main.dll 15 | tests/e2e/src/dylib/main.dylib 16 | tests/e2e/src/dylib/main.so 17 | tests/e2e/src/dylib/usage 18 | bugs 19 | dev/counter.py 20 | dev/iwyu.out 21 | dev/remove_include_comments.regex 22 | next/grab_import.sh 23 | next/main 24 | next/next.adept 25 | *.srctrlbm 26 | *.srctrldb 27 | *.srctrlprj 28 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | All contributions should adhere to the following requirements: 3 | - Be written in C11 4 | 5 | ## Thank You 6 | 🎉 Thanks for contributing 🎉 7 | -------------------------------------------------------------------------------- /dev/README.md: -------------------------------------------------------------------------------- 1 | ### dev/ 2 | 3 | Configuration files and scripts for optional development tools and helpers 4 | 5 | **Optional Development Dependencies:** 6 | 7 | - `include-what-you-use` for automatically cleaning up `#include` directives 8 | - `iwyu.sh` 9 | - `iwyu_mappings.imp` 10 | - `LSAN` Leak Sanitizer included with Clang 11 | - `lsan_supressions.txt` 12 | - `lsan_use_suppressions_sources.sh` 13 | - `PMD` for copy-paste detection and static analysis 14 | - `find_duplicate_code.sh` 15 | 16 | **Todolists** 17 | 18 | - `dev/todolists/` 19 | -------------------------------------------------------------------------------- /dev/find_duplicate_code.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ~/Downloads/pmd-bin-6.50.0/bin/run.sh cpd --minimum-tokens 100 --files ~/Projects/Adept/src --files ~/Projects/Adept/include --language c > code.txt 3 | -------------------------------------------------------------------------------- /dev/iwyu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Small script for automatically cleaning up #includes using 'include-what-you-use' 4 | # Usage: `dev/iwyu.sh` 5 | 6 | pushd build/macOS-Debug 7 | iwyu_tool.py -p . -- -Xiwyu --mapping_file=../../dev/iwyu_mappings.imp > ../../dev/iwyu.out 8 | fix_includes.py --nocomments --reorder < ../../dev/iwyu.out 9 | popd 10 | -------------------------------------------------------------------------------- /dev/iwyu_mappings.imp: -------------------------------------------------------------------------------- 1 | [ 2 | { include: ["<_ctype.h>", "private", "", "public"] }, 3 | { include: ["", "private", "", "public"] } 4 | ] -------------------------------------------------------------------------------- /dev/lsan_suppressions.txt: -------------------------------------------------------------------------------- 1 | leak:cache_t::insert(objc_selector*, void (*)(), objc_object*) 2 | leak:list_array_tt 3 | leak:realizeClassWithoutSwift(objc_class*, objc_class*) 4 | leak:list_array_tt::attachLists(property_list_t* const*, unsigned int) 5 | -------------------------------------------------------------------------------- /dev/lsan_use_suppressions_source.sh: -------------------------------------------------------------------------------- 1 | # Usage: 'source lsan_use_suppressions_source.sh' 2 | export LSAN_OPTIONS=suppressions=../../dev/lsan_suppressions.txt 3 | -------------------------------------------------------------------------------- /dev/todolists/breaking-future/3.0-way-future.todolist: -------------------------------------------------------------------------------- 1 | # Ideas for way-in-the-future changes for Adept 3.0 that would be radical or break backwards-compatibility 2 | 3 | IDEAS: 4 | - Make 'delete' call __defer__ by default, and add 'delete POD' to take the place of the current delete 5 | - Improve meta-programming system 6 | - Make more types be able to have methods 7 | - Modules or some kind of way to section off code 8 | - Change 'String' and 'List' (etc.) 9 | - Iterators 10 | - Sum types 11 | - Overhaul API for RTTI 12 | - Prefer @attribute syntax for attributes instead of using keywords, for example "@implicit\nfunc ..." instead of "implicit func ..." 13 | - Rethink inline/spontaneous variable declarations 14 | - Rethink syntax for constant expressions and named expressions 15 | - Rethink loop label syntax 16 | - Unify syntax more 17 | - Consider allowing methods to take in 'this' by-value 18 | - Have warning for foot-gun that is ; at end of single line conditional when the indentation seems to indicate the author did not mean to use statement continuation 19 | - Client-side online compiler demo 20 | - UTF-8 Support? 21 | -------------------------------------------------------------------------------- /dev/todolists/old/2.3.todolist: -------------------------------------------------------------------------------- 1 | 2 | 2.3 COMPLETED: 3 | + Allow for temporary mutable values so you can do stuff like "Hello World".clone() 4 | + __defer__ for dropped values 5 | + __defer__ for fixed arrays 6 | + __pass__ autogeneration 7 | + __pass__ for fixed arrays 8 | + Keyword 'verbatim' to prevent function autogeneration 9 | + Bitwise assignment operators '&=', '|=', '^=', '<<=', '>>=', '<<<=', '>>>=' 10 | + Fill in offsets for AnyStructType types 11 | + Runtime type information for indirectly used types 12 | + default arguments 13 | -------------------------------------------------------------------------------- /dev/todolists/old/reducancy.todolist: -------------------------------------------------------------------------------- 1 | # TODOLIST FOR REDUCING ADEPT CODE REDUNDANCY 2 | # CREATED SATURDAY MAY 4 2019 3 | # ------------------------------------------- 4 | 5 | MINIMAL: 6 | * arg_type_polymorphable & ast_types_identical 7 | * create constant definitions for storage types of each literal value type S8_STORAGE, S16_STORAGE, U64_STORAGE, etc. 8 | * create helper functions to handle calculating is_beginning_of_group values 9 | * combine expression-statement parsing in EXPR_WORD with other EXPR_* expression-statement parsing 10 | * cache 'ubyte' and '*ubyte' IR types 11 | 12 | MAJOR: 13 | * ir_gen_find_method_conforming & ir_gen_find_generic_base_method_conforming & others 14 | * calling function elem 15 | * handle_children_deference/handle_children_pass and handle_single_deference/handle_single_pass 16 | 17 | COMPLETED: 18 | + stmt & expr handling for EXPR_CALL 19 | + stmt & expr handling for EXPR_CALL_METHOD 20 | + stmt & expr handling for EXPR_P(RE/OST)(IN/DE)CREMENT 21 | + ast_type_dereference to replace occurrences of manual ast type dereference 22 | + remove unused 'ir_type_var' code 23 | -------------------------------------------------------------------------------- /include/AST/POLY/ast_translate.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_AST_TRANSLATE_H 3 | #define _ISAAC_AST_TRANSLATE_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #include "AST/ast.h" 10 | #include "AST/ast_type_lean.h" 11 | #include "DRVR/compiler.h" 12 | #include "UTIL/ground.h" 13 | 14 | // ---------------- ast_translate_poly_parent_class ---------------- 15 | // Translates a polymorphic parent class type 16 | // using contextual information from a specific usage 17 | // EXAMPLE: 18 | // For the concrete type usage: 19 | // point Vector4 20 | // The `<$T> Vector3f` in 21 | // class <$T> Vector4 extends <$T> Vector3 (w $T) 22 | // will be copied, translated into context (` Vector3f`), and returned. 23 | // The resolved type will be stored in `out_type` if successful. 24 | // USE CASE: 25 | // This function is used to help translate compile-time polymorphism 26 | // during vtable generation, as required classes are not guaranteed to do any 27 | // IR generation. 28 | errorcode_t ast_translate_poly_parent_class( 29 | compiler_t *compiler, 30 | ast_t *ast, 31 | ast_composite_t *the_child_class, 32 | const ast_type_t *the_child_class_concrete_usage, 33 | ast_type_t *out_type 34 | ); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif // _ISAAC_AST_TRANSLATE_H 41 | -------------------------------------------------------------------------------- /include/AST/TYPE/ast_type_hash.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_AST_TYPE_HASH_H 3 | #define _ISAAC_AST_TYPE_HASH_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | /* 10 | ============================ ast_type_hash.h ============================ 11 | Definitions for hashing AST types 12 | -------------------------------------------------------------------------- 13 | */ 14 | 15 | #include "UTIL/hash.h" 16 | #include "UTIL/ground.h" 17 | #include "AST/ast_type_lean.h" 18 | 19 | // ---------------- ast_type_hash ---------------- 20 | // Hashes an AST type 21 | hash_t ast_type_hash(const ast_type_t *type); 22 | 23 | // ---------------- ast_types_hash ---------------- 24 | // Hashes a collection of AST types 25 | hash_t ast_types_hash(const ast_type_t *types, length_t length); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif // _ISAAC_AST_TYPE_HASH_H 32 | -------------------------------------------------------------------------------- /include/AST/TYPE/ast_type_identical.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_AST_TYPE_IDENTICAL_H 3 | #define _ISAAC_AST_TYPE_IDENTICAL_H 4 | 5 | /* 6 | ========================== ast_type_identical ============================== 7 | Definitions for determining if two AST types are identical 8 | ---------------------------------------------------------------------------- 9 | */ 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #include 16 | 17 | #include "AST/ast_type_lean.h" 18 | #include "UTIL/ground.h" 19 | 20 | // ---------------- ast_types_identical ---------------- 21 | // Returns whether two AST types are identical 22 | bool ast_types_identical(const ast_type_t *a, const ast_type_t *b); 23 | 24 | // ---------------- ast_type_lists_identical ---------------- 25 | // Returns whether two lists of AST types are identical 26 | bool ast_type_lists_identical(const ast_type_t *a, const ast_type_t *b, length_t length); 27 | 28 | // ---------------- ast_elem_identical ---------------- 29 | // Returns whether two AST elements are identical 30 | bool ast_elem_identical(ast_elem_t *a, ast_elem_t *b); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif // _ISAAC_AST_TYPE_IDENTICAL_H 37 | -------------------------------------------------------------------------------- /include/AST/TYPE/ast_type_set.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_AST_TYPE_SET_H 3 | #define _ISAAC_AST_TYPE_SET_H 4 | 5 | #include "AST/ast_type_lean.h" 6 | #include "UTIL/set.h" 7 | #include "UTIL/ground.h" 8 | 9 | // ---------------- ast_type_set_t ---------------- 10 | // A set collection of AST types 11 | typedef struct { set_t impl; } ast_type_set_t; 12 | 13 | void ast_type_set_init(ast_type_set_t *set, length_t num_buckets); 14 | bool ast_type_set_insert(ast_type_set_t *set, ast_type_t *type); 15 | void ast_type_set_traverse(ast_type_set_t *set, void (*run_func)(ast_type_t*)); 16 | void ast_type_set_free(ast_type_set_t *set); 17 | 18 | #endif // _ISAAC_AST_TYPE_SET_H 19 | -------------------------------------------------------------------------------- /include/AST/ast_type_lean.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_AST_TYPE_LEAN_H 3 | #define _ISAAC_AST_TYPE_LEAN_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | /* 10 | ============================= ast_type_lean.h ============================ 11 | Module for lean definitions required for abstract syntax tree types 12 | -------------------------------------------------------------------------- 13 | */ 14 | 15 | #include "UTIL/ground.h" 16 | 17 | // ---------------- ast_elem_t ---------------- 18 | // General purpose struct for a type element 19 | typedef struct { 20 | unsigned int id; 21 | source_t source; 22 | } ast_elem_t; 23 | 24 | // ---------------- ast_type_t ---------------- 25 | // Struct containing AST type information 26 | typedef struct { 27 | ast_elem_t **elements; 28 | length_t elements_length; 29 | source_t source; 30 | } ast_type_t; 31 | 32 | // ---------------- AST_TYPE_NONE ---------------- 33 | // AST type that represents the absence of a valid type 34 | #define AST_TYPE_NONE ((ast_type_t){0}) 35 | #define AST_TYPE_IS_NONE(ast_type_val) ((ast_type_val).elements_length == 0) 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif // _ISAAC_AST_TYPE_LEAN_H 42 | -------------------------------------------------------------------------------- /include/BKEND/backend.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_BACKEND_H 3 | #define _ISAAC_BACKEND_H 4 | 5 | /* 6 | ================================= backend.h ================================ 7 | Module for exporting intermediate representation given some backend 8 | 9 | NOTE: 'backend_whatever.h' files are for mapping a backend to this module. 10 | ---------------------------------------------------------------------------- 11 | */ 12 | 13 | #include "DRVR/compiler.h" 14 | #include "DRVR/object.h" 15 | #include "UTIL/ground.h" 16 | 17 | // Possible backends 18 | enum ir_export_backend { 19 | BACKEND_NONE, 20 | BACKEND_LLVM, 21 | BACKEND_C, 22 | }; 23 | 24 | // ---------------- ir_export ---------------- 25 | // Exports intermediate representation given 26 | // some backend. 27 | errorcode_t ir_export(compiler_t *compiler, object_t *object, enum ir_export_backend backend); 28 | 29 | #endif // _ISAAC_BACKEND_H 30 | -------------------------------------------------------------------------------- /include/BKEND/backend_c.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_BACKEND_C_H 3 | #define _ISAAC_BACKEND_C_H 4 | 5 | /* 6 | ================================ backend_c.h ================================ 7 | Module for exporting intermediate representation via C 8 | 9 | NOTE: Corresponds to ir_to_c.c & ir_to_c.h 10 | ----------------------------------------------------------------------------- 11 | */ 12 | 13 | #include "DRVR/object.h" 14 | #include "DRVR/compiler.h" 15 | 16 | // ---------------- ir_to_c ---------------- 17 | // Invokes the LLVM backend 18 | errorcode_t ir_to_c(compiler_t *compiler, object_t *object); 19 | 20 | #endif // _ISAAC_BACKEND_C_H 21 | -------------------------------------------------------------------------------- /include/BKEND/backend_llvm.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_BACKEND_LLVM_H 3 | #define _ISAAC_BACKEND_LLVM_H 4 | 5 | /* 6 | ============================== backend_llvm.h ============================== 7 | Module for exporting intermediate representation via LLVM 8 | 9 | NOTE: Corresponds to ir_to_llvm.c & ir_to_llvm.h 10 | ---------------------------------------------------------------------------- 11 | */ 12 | 13 | #include "DRVR/object.h" 14 | #include "DRVR/compiler.h" 15 | 16 | // ---------------- ir_to_llvm ---------------- 17 | // Invokes the LLVM backend 18 | errorcode_t ir_to_llvm(compiler_t *compiler, object_t *object); 19 | 20 | #endif // _ISAAC_BACKEND_LLVM_H 21 | -------------------------------------------------------------------------------- /include/BKEND/ir_to_c.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_IR_TO_C_H 3 | #define _ISAAC_IR_TO_C_H 4 | 5 | /* 6 | ================================= ir_to_c.h ================================ 7 | Module for exporting intermediate representation to C 8 | ---------------------------------------------------------------------------- 9 | */ 10 | 11 | #endif // _ISAAC_IR_TO_C_H 12 | -------------------------------------------------------------------------------- /include/BRIDGE/rtti_collector.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_RTTI_COLLECTOR_H 3 | #define _ISAAC_RTTI_COLLECTOR_H 4 | 5 | #include "AST/TYPE/ast_type_set.h" 6 | #include "AST/TYPE/ast_type_make.h" 7 | #include "UTIL/ground.h" 8 | #include "UTIL/string.h" 9 | 10 | // ---------------- rtti_collector_t ---------------- 11 | // Keeps track of what AST types have been mentioned to it 12 | typedef struct { 13 | ast_type_set_t ast_types_used; 14 | } rtti_collector_t; 15 | 16 | void rtti_collector_init(rtti_collector_t *collector); 17 | void rtti_collector_free(rtti_collector_t *collector); 18 | 19 | // ---------------- rtti_collector_mention ---------------- 20 | // Mentions an AST type to an RTTI collector 21 | void rtti_collector_mention(rtti_collector_t *collector, ast_type_t *type); 22 | 23 | // ---------------- rtti_collector_mention_base ---------------- 24 | // Helper to mention a simple base AST type to an RTTI collector. 25 | // Used for mentioning built-in types 26 | bool rtti_collector_mention_base(rtti_collector_t *collector, const char *name); 27 | 28 | #endif // _ISAAC_RTTI_COLLECTOR_H 29 | -------------------------------------------------------------------------------- /include/BRIDGEIR/rtti.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_RTTI_H 3 | #define _ISAAC_RTTI_H 4 | 5 | #include "AST/ast_type_lean.h" 6 | #include "BRIDGE/rtti_collector.h" 7 | #include "BRIDGEIR/rtti_table.h" 8 | #include "IR/ir.h" 9 | #include "IR/ir_value.h" 10 | #include "IRGEN/ir_builder.h" 11 | #include "UTIL/ground.h" 12 | 13 | // ---------------- rtti_for ---------------- 14 | // NOTE: Returns NULL on failure 15 | ir_value_t* rtti_for(ir_builder_t *builder, ast_type_t *ast_type, source_t source_on_failure); 16 | 17 | // ---------------- rtti_resolve ---------------- 18 | // Resolves a single RTTI relocation 19 | // NOTE: Used to fill in requested indices for the __types__ runtime array 20 | errorcode_t rtti_resolve(rtti_table_t *rtti_table, rtti_relocation_t *relocation); 21 | 22 | #endif // _ISAAC_RTTI_H 23 | -------------------------------------------------------------------------------- /include/BRIDGEIR/rtti_table.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_RTTI_TABLE_H 3 | #define _ISAAC_RTTI_TABLE_H 4 | 5 | #include "AST/ast.h" 6 | #include "BRIDGE/rtti_collector.h" 7 | #include "BRIDGEIR/rtti_table_entry.h" 8 | #include "UTIL/ground.h" 9 | #include "UTIL/list.h" 10 | #include "UTIL/trait.h" 11 | 12 | // ---------------- rtti_table_t ---------------- 13 | // A table of finalized runtime type information 14 | typedef struct { 15 | rtti_table_entry_t *entries; 16 | length_t length; 17 | } rtti_table_t; 18 | 19 | // ---------------- rtti_table_create ---------------- 20 | // Creates an RTTI table 21 | rtti_table_t rtti_table_create(rtti_collector_t collector, ast_t *ast); 22 | 23 | // ---------------- rtti_table_free ---------------- 24 | // Frees an RTTI table 25 | void rtti_table_free(rtti_table_t *rtti_table); 26 | 27 | // ---------------- rtti_table_find ---------------- 28 | // Finds an entry in an RTTI table 29 | rtti_table_entry_t *rtti_table_find(const rtti_table_t *rtti_table, const char *name); 30 | 31 | // ---------------- rtti_table_find_index ---------------- 32 | // Finds the index of an entry in an RTTI table 33 | maybe_index_t rtti_table_find_index(const rtti_table_t *rtti_table, const char *name); 34 | 35 | #endif // _ISAAC_RTTI_TABLE_H 36 | -------------------------------------------------------------------------------- /include/IR/ir_dump.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_IR_DUMP_H 3 | #define _ISAAC_IR_DUMP_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | /* 10 | =================================== ir_dump.h =================================== 11 | Module for dumping intermediate representation 12 | ---------------------------------------------------------------------------- 13 | */ 14 | 15 | #include 16 | 17 | #include "IR/ir.h" 18 | #include "IR/ir_module.h" 19 | #include "UTIL/ground.h" 20 | 21 | // ---------------- ir_module_dump ---------------- 22 | // Generates a string representation from an IR 23 | // module and writes it to a file 24 | void ir_module_dump(ir_module_t *ir_module, const char *filename); 25 | 26 | // ---------------- ir_dump_functions (and friends) ---------------- 27 | // Dumps a specific part of an IR module 28 | void ir_dump_function(FILE *file, ir_func_t *function, func_id_t ir_func_id, ir_func_t *all_funcs); 29 | void ir_dump_functions(FILE *file, ir_funcs_t *funcs); 30 | void ir_dump_basicsblocks(FILE *file, ir_basicblocks_t basicblocks, ir_func_t *functions); 31 | void ir_dump_instruction(FILE *file, ir_instr_t *instruction, length_t instr_index, ir_func_t *all_funcs); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif // _ISAAC_IR_DUMP_H 38 | -------------------------------------------------------------------------------- /include/IR/ir_type_spec.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_IR_TYPE_TRAITS_H 3 | #define _ISAAC_IR_TYPE_TRAITS_H 4 | 5 | /* 6 | ============================== ir_type_spec.h ============================== 7 | Module for IR type specification info 8 | ---------------------------------------------------------------------------- 9 | */ 10 | 11 | #include "IR/ir_type.h" 12 | #include "UTIL/ground.h" 13 | #include "UTIL/trait.h" 14 | 15 | #define IR_TYPE_TRAIT_NONE TRAIT_NONE 16 | #define IR_TYPE_TRAIT_POINTER TRAIT_1 17 | #define IR_TYPE_TRAIT_SIGNED TRAIT_2 18 | #define IR_TYPE_TRAIT_FLOAT TRAIT_3 19 | typedef trait_t ir_type_traits_t; 20 | 21 | typedef struct { 22 | length_t bytes; 23 | ir_type_traits_t traits; 24 | } ir_type_spec_t; 25 | 26 | successful_t ir_type_get_spec(ir_type_t *type, ir_type_spec_t *out_spec); 27 | 28 | #endif // _ISAAC_IR_TYPE_TRAITS_H 29 | -------------------------------------------------------------------------------- /include/IR/ir_value_str.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_IR_VALUE_STR_H 3 | #define _ISAAC_IR_VALUE_STR_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | /* 10 | ============================== ir_value_str.h ============================== 11 | Module for creating human-readable string representations of IR values 12 | ---------------------------------------------------------------------------- 13 | */ 14 | 15 | #include "UTIL/ground.h" 16 | #include "IR/ir_value.h" 17 | 18 | // ---------------- ir_value_str ---------------- 19 | // Stringifies an IR value 20 | strong_cstr_t ir_value_str(ir_value_t *value); 21 | 22 | // ---------------- ir_values_str ---------------- 23 | // Stringifies a list of IR values, separating them with commas 24 | strong_cstr_t ir_values_str(ir_value_t **values, length_t length); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif // _ISAAC_IR_VALUE_STR_H 31 | -------------------------------------------------------------------------------- /include/IRGEN/ir_autogen.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_IR_AUTOGEN_H 3 | #define _ISAAC_IR_AUTOGEN_H 4 | 5 | /* 6 | =============================== ir_autogen.h =============================== 7 | Helper module for automatically generating management procedures 8 | ---------------------------------------------------------------------------- 9 | */ 10 | 11 | #include "AST/ast_type.h" 12 | #include "IRGEN/ir_builder.h" 13 | #include "UTIL/ground.h" 14 | 15 | enum ir_autogen_action_kind { 16 | IR_AUTOGEN_ACTION_DEFER, 17 | IR_AUTOGEN_ACTION_PASS 18 | }; 19 | 20 | errorcode_t ir_autogen_for_children_of_struct_like( 21 | ir_builder_t *builder, 22 | enum ir_autogen_action_kind action_kind, 23 | ast_elem_t *struct_like_elem, 24 | ast_type_t *param_ast_type 25 | ); 26 | 27 | errorcode_t ir_autogen_for_child_of_struct( 28 | ir_builder_t *builder, 29 | enum ir_autogen_action_kind action_kind, 30 | ast_type_t *ast_field_type, 31 | length_t field_i, 32 | ast_type_t *param_ast_type, 33 | source_t composite_source, 34 | source_t field_source 35 | ); 36 | 37 | #endif // _ISAAC_IR_AUTOGEN_H 38 | -------------------------------------------------------------------------------- /include/IRGEN/ir_gen_qualifiers.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_IR_GEN_QUALIFIERS_H 3 | #define _ISAAC_IR_GEN_QUALIFIERS_H 4 | 5 | /* 6 | =========================== ir_gen_qualifiers.h ============================ 7 | Module for ensuring function qualifiers are not violated 8 | ---------------------------------------------------------------------------- 9 | */ 10 | 11 | #include "AST/ast.h" 12 | #include "DRVR/compiler.h" 13 | 14 | errorcode_t ensure_not_violating_no_discard(compiler_t *compiler, bool no_discard_active, source_t call_source, ast_func_t *callee); 15 | 16 | errorcode_t ensure_not_violating_disallow(compiler_t *compiler, source_t call_source, ast_func_t *callee); 17 | 18 | #endif // _ISAAC_IR_GEN_QUALIFIERS_H 19 | -------------------------------------------------------------------------------- /include/LEX/lex.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_LEX_H 3 | #define _ISAAC_LEX_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | /* 10 | ================================== lex.h ================================== 11 | Module for performing lexical analysis 12 | --------------------------------------------------------------------------- 13 | */ 14 | 15 | #include 16 | 17 | #include "DRVR/compiler.h" 18 | #include "DRVR/object.h" 19 | #include "UTIL/ground.h" 20 | 21 | // ---------------- lex ---------------- 22 | // Entry point for lexical analysis 23 | errorcode_t lex(compiler_t *compiler, object_t *object); 24 | 25 | // ---------------- lex_buffer ---------------- 26 | // Lex the text buffer attached to the given object 27 | // NOTE: The attached buffer 'object->buffer' must be terminated with '\n\0' 28 | // NOTE: The final \0 is not included in the 'object->buffer_size' 29 | errorcode_t lex_buffer(compiler_t *compiler, object_t *object); 30 | 31 | // ---------------- lex_get_location ---------------- 32 | // Retrieves line and column of an index in a buffer 33 | void lex_get_location(const char *buffer, length_t i, int *line, int *column); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif // _ISAAC_LEX_H 40 | -------------------------------------------------------------------------------- /include/NET/download.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_DOWNLOAD_H 3 | #define _ISAAC_DOWNLOAD_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | /* 10 | ================================ download.h =============================== 11 | Module for downloading files 12 | --------------------------------------------------------------------------- 13 | */ 14 | 15 | #include "UTIL/ground.h" 16 | 17 | typedef struct { 18 | void *bytes; 19 | length_t length; 20 | } download_buffer_t; 21 | 22 | #ifdef ADEPT_ENABLE_PACKAGE_MANAGER 23 | 24 | // ---------------- download ---------------- 25 | // Downloads a file, returns whether successful 26 | successful_t download(weak_cstr_t url, weak_cstr_t destination, weak_cstr_t cainfo_file); 27 | 28 | // ---------------- download_to_memory ---------------- 29 | // Downloads a file into memory, returns whether successful 30 | // NOTE: If successful, out_memory->buffer must be freed by the caller 31 | successful_t download_to_memory(weak_cstr_t url, download_buffer_t *out_memory, weak_cstr_t cainfo_file); 32 | 33 | #endif // ADEPT_ENABLE_PACKAGE_MANAGER 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif // _ISAAC_DOWNLOAD_H 40 | -------------------------------------------------------------------------------- /include/NET/stash.h: -------------------------------------------------------------------------------- 1 | 2 | #if !defined(_ISAAC_STASH_H) && defined(ADEPT_ENABLE_PACKAGE_MANAGER) 3 | #define _ISAAC_STASH_H 4 | 5 | #include "DRVR/config.h" 6 | #include "UTIL/ground.h" 7 | 8 | successful_t adept_install(config_t *config, weak_cstr_t root, weak_cstr_t identifier); 9 | successful_t adept_install_stash(config_t *config, weak_cstr_t root, char *bytes, length_t length); 10 | maybe_null_strong_cstr_t adept_locate_package(weak_cstr_t identifier, char *buffer, length_t length); 11 | successful_t adept_uninstall(config_t *config, weak_cstr_t identifier); 12 | successful_t adept_info(config_t *config, weak_cstr_t identifier); 13 | 14 | #endif // _ISAAC_STASH_H 15 | -------------------------------------------------------------------------------- /include/PARSE/parse.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_PARSE_H 3 | #define _ISAAC_PARSE_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | /* 10 | ================================= parse.h ================================= 11 | Module for parsing a token list into an abstract syntax tree. Also 12 | responsible for forwarding 'pragma' directives to the pragma module. 13 | --------------------------------------------------------------------------- 14 | */ 15 | 16 | #include "DRVR/compiler.h" 17 | #include "DRVR/object.h" 18 | #include "PARSE/parse_ctx.h" 19 | #include "UTIL/ground.h" 20 | 21 | // ------------------ parse ------------------ 22 | // Entry point of the parser 23 | // Returns SUCCESS on conventional success (parse completed) 24 | // Returns FAILURE on error 25 | // Returns ALT_FAILURE on unconventional success (parse incomplete) 26 | errorcode_t parse(compiler_t *compiler, object_t *object); 27 | 28 | // ------------------ parse_tokens ------------------ 29 | // Indirect entry point of the parser. Takes in a 30 | // parsing context that has already been created. 31 | errorcode_t parse_tokens(parse_ctx_t *ctx); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif // _ISAAC_PARSE_H 38 | -------------------------------------------------------------------------------- /include/PARSE/parse_alias.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_PARSE_ALIAS_H 3 | #define _ISAAC_PARSE_ALIAS_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #include "UTIL/ground.h" 10 | #include "PARSE/parse_ctx.h" 11 | 12 | errorcode_t parse_alias(parse_ctx_t *ctx); 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | 18 | #endif // _ISAAC_PARSE_ALIAS_H 19 | -------------------------------------------------------------------------------- /include/PARSE/parse_checks.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_PARSE_CHECKS_H 3 | #define _ISAAC_PARSE_CHECKS_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #include "AST/ast.h" 10 | #include "PARSE/parse_ctx.h" 11 | #include "UTIL/ground.h" 12 | 13 | errorcode_t validate_func_requirements(parse_ctx_t *ctx, ast_func_t *func, source_t source); 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | 19 | #endif // _ISAAC_PARSE_CHECKS_H 20 | -------------------------------------------------------------------------------- /include/PARSE/parse_enum.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_PARSE_ENUM_H 3 | #define _ISAAC_PARSE_ENUM_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #include 10 | 11 | #include "PARSE/parse_ctx.h" 12 | #include "UTIL/ground.h" 13 | 14 | // ------------------ parse_enum ------------------ 15 | // Parses a enum 16 | errorcode_t parse_enum(parse_ctx_t *ctx, bool is_foreign); 17 | 18 | // ------------------ parse_enum_body ------------------ 19 | // Parses the body of a enum 20 | errorcode_t parse_enum_body(parse_ctx_t *ctx, weak_cstr_t **kinds, length_t *length); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif // _ISAAC_PARSE_ENUM_H 27 | -------------------------------------------------------------------------------- /include/PARSE/parse_global.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_PARSE_GLOBAL_H 3 | #define _ISAAC_PARSE_GLOBAL_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #include "AST/ast_named_expression.h" 10 | #include "PARSE/parse_ctx.h" 11 | #include "UTIL/ground.h" 12 | 13 | // ------------------ parse_global ------------------ 14 | // Parses a global variable or global named expression 15 | errorcode_t parse_global(parse_ctx_t *ctx); 16 | 17 | // ------------------ parse_named_expression_definition ------------------ 18 | // Parses a named expression declaration 19 | errorcode_t parse_named_expression_definition(parse_ctx_t *ctx, ast_named_expression_t *out_named_expression); 20 | 21 | // ------------------ parse_global_named_expression_definition ------------------ 22 | // Parses a global named expression definition 23 | errorcode_t parse_global_named_expression_definition(parse_ctx_t *ctx); 24 | 25 | // ------------------ parse_old_style_named_expression_global ------------------ 26 | // Parses an old-style global named expression definition 27 | errorcode_t parse_old_style_named_expression_global(parse_ctx_t *ctx, strong_cstr_t name, source_t source); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif // _ISAAC_PARSE_GLOBAL_H 34 | -------------------------------------------------------------------------------- /include/PARSE/parse_meta.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_PARSE_META_H 3 | #define _ISAAC_PARSE_META_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #include "UTIL/ground.h" 10 | #include "PARSE/parse_ctx.h" 11 | #include "AST/meta_directives.h" 12 | 13 | errorcode_t parse_meta(parse_ctx_t *ctx); 14 | errorcode_t parse_meta_import_stdlib(parse_ctx_t *ctx, source_t source); 15 | errorcode_t parse_meta_expr(parse_ctx_t *ctx, meta_expr_t **out_expr); 16 | errorcode_t parse_meta_primary_expr(parse_ctx_t *ctx, meta_expr_t **out_expr); 17 | errorcode_t parse_meta_op_expr(parse_ctx_t *ctx, int precedence, meta_expr_t **inout_left); 18 | errorcode_t meta_parse_rhs_expr(parse_ctx_t *ctx, meta_expr_t **left, meta_expr_t **out_right, int op_prec); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif // _ISAAC_PARSE_META_H 25 | -------------------------------------------------------------------------------- /include/PARSE/parse_namespace.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_PARSE_NAMESPACE_H 3 | #define _ISAAC_PARSE_NAMESPACE_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | /* 10 | ============================ parse_namespace.h ============================ 11 | Module for parsing namespace-related operations 12 | --------------------------------------------------------------------------- 13 | */ 14 | 15 | #include "UTIL/ground.h" 16 | #include "PARSE/parse_ctx.h" 17 | 18 | // ------------------ parse_namespace ------------------ 19 | // Parses 'namespace' directive 20 | errorcode_t parse_namespace(parse_ctx_t *ctx); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif // _ISAAC_PARSE_NAMESPACE_H 27 | -------------------------------------------------------------------------------- /include/PARSE/parse_pragma.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_PARSE_PRAGMA_H 3 | #define _ISAAC_PARSE_PRAGMA_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | /* 9 | ============================== parse_pragma.h ============================== 10 | Module for handling 'pragma' directives sent from code being compiled 11 | ---------------------------------------------------------------------------- 12 | */ 13 | 14 | #include "LEX/token.h" 15 | #include "PARSE/parse_ctx.h" 16 | #include "UTIL/ground.h" 17 | 18 | // ---------------- parse_pragma ---------------- 19 | // Handles parsing and interpretation of pragma directions 20 | // Expects 'ctx->i' to point to 'pragma' keyword 21 | errorcode_t parse_pragma(parse_ctx_t *ctx); 22 | 23 | // ---------------- parse_pragma_cloptions ---------------- 24 | // Parses the 'options' pragma directive's command line 25 | // arguments string and passes it off to the compiler 26 | errorcode_t parse_pragma_cloptions(parse_ctx_t *ctx); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif // _ISAAC_PARSE_PRAGMA_H 33 | -------------------------------------------------------------------------------- /include/PARSE/parse_type.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_PARSE_TYPE_H 3 | #define _ISAAC_PARSE_TYPE_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #include 10 | 11 | #include "AST/ast_type.h" 12 | #include "LEX/token.h" 13 | #include "PARSE/parse_ctx.h" 14 | #include "UTIL/ground.h" 15 | 16 | // ------------------ parse_type ------------------ 17 | // Parses a type into an abstract syntax tree form. 18 | // NOTE: Returns SUCCESS on success 19 | // NOTE: If failed, will set 'out_type' to empty type (all zeros) 20 | // This means that calling ast_type_free on 'out_type' after this function fails is optional. 21 | errorcode_t parse_type(parse_ctx_t *ctx, ast_type_t *out_type); 22 | 23 | // ------------------ parse_type_func ------------------ 24 | // Parses a function type into an abstract syntax tree 25 | // type-element form. Primary called from 'parse_type'. 26 | errorcode_t parse_type_func(parse_ctx_t *ctx, ast_elem_func_t *out_func_elem); 27 | 28 | // ------------------ parse_can_type_start_with ------------------ 29 | // Returns whether an AST type can start with a token 30 | // Won't consider '[' token unless 'allow_open_bracket' is specified as true 31 | bool parse_can_type_start_with(tokenid_t id, bool allow_open_bracket); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif // _ISAAC_PARSE_TYPE_H 38 | -------------------------------------------------------------------------------- /include/PARSE/parse_util.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_PARSE_UTIL_H 3 | #define _ISAAC_PARSE_UTIL_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #include "UTIL/ground.h" 10 | #include "PARSE/parse_ctx.h" 11 | 12 | // ------------------ parse_ignore_newlines ------------------ 13 | // Passes over newlines until something else is encountered 14 | // NOTE: Won't print error message if 'error_message' is NULL 15 | errorcode_t parse_ignore_newlines(parse_ctx_t *ctx, const char *error_message); 16 | 17 | // ------------------ parse_panic_token ------------------ 18 | // Will print an error message with general information 19 | // using the message 'message' and replacing '%s' within 20 | // it with the name of the token pointed to by 'source' 21 | void parse_panic_token(parse_ctx_t *ctx, source_t source, unsigned int token_id, const char *message); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif // _ISAAC_PARSE_UTIL_H 28 | -------------------------------------------------------------------------------- /include/UTIL/__insight.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC___INSIGHT_H 3 | #define _ISAAC___INSIGHT_H 4 | 5 | // ------------------------------------------------------- 6 | // Insight API for Adept Compiler Insights 7 | // ------------------------------------------------------- 8 | 9 | #if !defined(ADEPT_INSIGHT_BUILD) && !defined(ADEPT_INSIGHT_BUILD_IGNORE_UNDEFINED) 10 | #error "ADEPT_INSIGHT_BUILD must be defined when using the Adept Insight API" 11 | #endif 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #include "DRVR/compiler.h" 18 | #include "LEX/lex.h" 19 | #include "PARSE/parse.h" 20 | #include "UTIL/__insight_undo_overloads.h" 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif // _ISAAC___INSIGHT_H 27 | -------------------------------------------------------------------------------- /include/UTIL/__insight_overloads.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC___INSIGHT_OVERLOADS_H 3 | #define _ISAAC___INSIGHT_OVERLOADS_H 4 | 5 | #if !defined(ADEPT_INSIGHT_BUILD) && !defined(ADEPT_INSIGHT_BUILD_IGNORE_UNDEFINED) 6 | #error "This file can only be used in the Adept Insight API" 7 | #endif 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | // Don't include package manager for insight builds 18 | #undef ADEPT_ENABLE_PACKAGE_MANAGER 19 | 20 | #ifndef __EMSCRIPTEN__ 21 | extern char insight_buffer[2560]; 22 | extern char insight_tmp_buffer[1280]; 23 | extern size_t insight_buffer_index; 24 | extern size_t insight_tmp_buffer_length; 25 | 26 | #define printf(...) { \ 27 | snprintf(insight_tmp_buffer, 1280, __VA_ARGS__); \ 28 | insight_tmp_buffer_length = strlen(insight_tmp_buffer) + 1; \ 29 | if(insight_buffer_index + insight_tmp_buffer_length < 2560){ \ 30 | memcpy(&insight_buffer[insight_buffer_index], insight_tmp_buffer, insight_tmp_buffer_length); \ 31 | insight_buffer_index += insight_tmp_buffer_length - 1;\ 32 | } \ 33 | } 34 | 35 | #define puts(a) printf("%s\n", a) 36 | #endif // !__EMSCRIPTEN__ 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif // _ISAAC___INSIGHT_OVERLOADS_H -------------------------------------------------------------------------------- /include/UTIL/__insight_undo_overloads.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC___INSIGHT_UNDO_OVERLOADS_H 3 | #define _ISAAC___INSIGHT_UNDO_OVERLOADS_H 4 | 5 | #if !defined(ADEPT_INSIGHT_BUILD) && !defined(ADEPT_INSIGHT_BUILD_IGNORE_UNDEFINED) 6 | #error "This file can only be used in the Adept Insight API" 7 | #endif 8 | 9 | #undef printf 10 | #undef puts 11 | 12 | #endif // _ISAAC___INSIGHT_UNDO_OVERLOADS_H -------------------------------------------------------------------------------- /include/UTIL/builtin_type.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_BUILTIN_TYPE_H 3 | #define _ISAAC_BUILTIN_TYPE_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #include "UTIL/search.h" // IWYU pragma: keep 10 | 11 | #define BUILTIN_TYPE_NONE -1 12 | #define BUILTIN_TYPE_BOOL 0 13 | #define BUILTIN_TYPE_BYTE 1 14 | #define BUILTIN_TYPE_DOUBLE 2 15 | #define BUILTIN_TYPE_FLOAT 3 16 | #define BUILTIN_TYPE_INT 4 17 | #define BUILTIN_TYPE_LONG 5 18 | #define BUILTIN_TYPE_SHORT 6 19 | #define BUILTIN_TYPE_SUCCESSFUL 7 20 | #define BUILTIN_TYPE_UBYTE 8 21 | #define BUILTIN_TYPE_UINT 9 22 | #define BUILTIN_TYPE_ULONG 10 23 | #define BUILTIN_TYPE_USHORT 11 24 | #define BUILTIN_TYPE_USIZE 12 25 | 26 | extern const char * const global_primitives[13]; 27 | extern const char * const global_primitives_extended[15]; 28 | 29 | #define typename_builtin_type(base) binary_string_search_const(global_primitives, 13, base) 30 | 31 | #define typename_is_extended_builtin_type(base) (binary_string_search_const(global_primitives_extended, 15, base) != -1) 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif // _ISAAC_BUILTIN_TYPE_H 38 | -------------------------------------------------------------------------------- /include/UTIL/func_pair.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_FUNCPAIR_H 3 | #define _ISAAC_FUNCPAIR_H 4 | 5 | #include 6 | 7 | #include "AST/ast.h" 8 | #include "UTIL/ground.h" 9 | #include "UTIL/list.h" 10 | 11 | // ---------------- func_pair_t ---------------- 12 | // A container for function results 13 | typedef struct { 14 | func_id_t ast_func_id; 15 | func_id_t ir_func_id; 16 | } func_pair_t; 17 | 18 | typedef optional(func_pair_t) optional_func_pair_t; 19 | void optional_func_pair_set(optional_func_pair_t *result, bool has, func_id_t ast_func_id, func_id_t ir_func_id); 20 | 21 | typedef listof(func_pair_t, pairs) func_pair_list_t; 22 | #define func_pair_list_append(LIST, VALUE) list_append((LIST), (VALUE), func_pair_t) 23 | #define func_pair_list_free(LIST) free((LIST)->pairs) 24 | 25 | #endif // _ISAAC_FUNCPAIR_H 26 | -------------------------------------------------------------------------------- /include/UTIL/hash.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_HASH_H 3 | #define _ISAAC_HASH_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | /* 10 | ================================ hash.h =============================== 11 | Module for hashing generic data 12 | --------------------------------------------------------------------------- 13 | */ 14 | 15 | #include "UTIL/ground.h" 16 | 17 | typedef length_t hash_t; 18 | 19 | // ---------------- hash_data ---------------- 20 | // Hashes a generic block of memory 21 | hash_t hash_data(const void *data, length_t size); 22 | 23 | // ---------------- hash_string ---------------- 24 | // Hashes a C string 25 | hash_t hash_string(const char *s); 26 | 27 | // ---------------- hash_strings ---------------- 28 | // Hashes an array of C strings 29 | hash_t hash_strings(char *strings[], length_t num_strings); 30 | 31 | // ---------------- hash_combine ---------------- 32 | // Combines two hashes into one 33 | hash_t hash_combine(hash_t h1, hash_t h2); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif // _ISAAC_HASH_H 40 | -------------------------------------------------------------------------------- /include/UTIL/index_id_list.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_INDEX_ID_LIST_H 3 | #define _ISAAC_INDEX_ID_LIST_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #include "UTIL/ground.h" 10 | #include "UTIL/list.h" 11 | 12 | // ---------------- index_id_list_t ---------------- 13 | typedef listof(index_id_t, ids) index_id_list_t; 14 | #define index_id_list_append(LIST, VALUE) list_append((LIST), (VALUE), index_id_t) 15 | #define index_id_list_free(LIST) free((LIST)->ids) 16 | 17 | // ---------------- func_id_list_t ---------------- 18 | typedef listof(func_id_t, ids) func_id_list_t; 19 | #define func_id_list_append(LIST, VALUE) list_append((LIST), (VALUE), func_id_t) 20 | #define func_id_list_free(LIST) free((LIST)->ids) 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif // _ISAAC_INDEX_ID_LIST_H 27 | -------------------------------------------------------------------------------- /include/UTIL/levenshtein.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_LEVENSHTEIN_H 3 | #define _ISAAC_LEVENSHTEIN_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | /* 10 | ============================== levanshtein.h ============================== 11 | Module for calculating levanshtein distance 12 | --------------------------------------------------------------------------- 13 | */ 14 | 15 | int levenshtein(const char *s1, const char *s2); 16 | int levenshtein_overlapping(const char *s1, const char *s2); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif // _ISAAC_LEVENSHTEIN_H 23 | -------------------------------------------------------------------------------- /include/UTIL/search.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_SEARCH_H 3 | #define _ISAAC_SEARCH_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | /* 10 | ================================= search.h ================================= 11 | Module for performing special search algorithms 12 | ---------------------------------------------------------------------------- 13 | */ 14 | 15 | #include "UTIL/ground.h" 16 | 17 | // ---------------- binary_string_search ---------------- 18 | // Performs a binary search to find a string in an array 19 | maybe_index_t binary_string_search(char *strings[], length_t string_count, const char *target); 20 | maybe_index_t binary_string_search_const(const char *const strings[], length_t string_count, const char *target); 21 | 22 | // ---------------- binary_int_search ---------------- 23 | // Performs a binary search to find an int in an array 24 | maybe_index_t binary_int_search(const int ints[], length_t int_count, int target); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif // _ISAAC_SEARCH_H 31 | -------------------------------------------------------------------------------- /res/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/favicon.ico -------------------------------------------------------------------------------- /res/icon.rc: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _resource_rc 3 | #define _resource_rc 4 | 5 | MAINICON ICON "favicon.ico" 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /res/necessities/adept.config: -------------------------------------------------------------------------------- 1 | { 2 | "adept.config": { 3 | "update": "monthly", 4 | "lastUpdated": 1636576987, 5 | "stash": "https://adeptlanguage.github.io/v1/adept.stash", 6 | "showNewCompilerAvailable": true, 7 | "showCheckingForUpdatesMessage": true 8 | }, 9 | "installs": [] 10 | } -------------------------------------------------------------------------------- /res/necessities/windows/bin/gcc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/bin/gcc.exe -------------------------------------------------------------------------------- /res/necessities/windows/bin/ld.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/bin/ld.exe -------------------------------------------------------------------------------- /res/necessities/windows/bin/windres.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/bin/windres.exe -------------------------------------------------------------------------------- /res/necessities/windows/crt2.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/crt2.o -------------------------------------------------------------------------------- /res/necessities/windows/crtbegin.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/crtbegin.o -------------------------------------------------------------------------------- /res/necessities/windows/include/dde.rh: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the mingw-w64 runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. 5 | */ 6 | #define WM_DDE_FIRST 0x03E0 7 | #define WM_DDE_INITIATE (WM_DDE_FIRST) 8 | #define WM_DDE_TERMINATE (WM_DDE_FIRST+1) 9 | #define WM_DDE_ADVISE (WM_DDE_FIRST+2) 10 | #define WM_DDE_UNADVISE (WM_DDE_FIRST+3) 11 | #define WM_DDE_ACK (WM_DDE_FIRST+4) 12 | #define WM_DDE_DATA (WM_DDE_FIRST+5) 13 | #define WM_DDE_REQUEST (WM_DDE_FIRST+6) 14 | #define WM_DDE_POKE (WM_DDE_FIRST+7) 15 | #define WM_DDE_EXECUTE (WM_DDE_FIRST+8) 16 | #define WM_DDE_LAST (WM_DDE_FIRST+8) 17 | -------------------------------------------------------------------------------- /res/necessities/windows/include/sdks/_mingw_ddk.h: -------------------------------------------------------------------------------- 1 | #ifndef MINGW_DDK_H 2 | #define MINGW_DDK_H 3 | #if 1 4 | #define MINGW_HAS_DDK_H 1 5 | #endif 6 | #endif 7 | -------------------------------------------------------------------------------- /res/necessities/windows/include/winresrc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the mingw-w64 runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. 5 | */ 6 | #ifndef _WINRESRC_ 7 | #define _WINRESRC_ 8 | 9 | #ifndef WINVER 10 | #define WINVER 0x0502 11 | #endif 12 | 13 | #ifndef _WIN32_IE 14 | #define _WIN32_IE 0x0501 15 | #endif 16 | 17 | #ifndef _WIN32_WINDOWS 18 | #define _WIN32_WINDOWS 0x0502 19 | #endif 20 | 21 | #ifndef _WIN32_WINNT 22 | #define _WIN32_WINNT 0x0502 23 | #endif 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #endif 32 | -------------------------------------------------------------------------------- /res/necessities/windows/libbrotlicommon.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/libbrotlicommon.dll -------------------------------------------------------------------------------- /res/necessities/windows/libbrotlidec.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/libbrotlidec.dll -------------------------------------------------------------------------------- /res/necessities/windows/libcrypto-3-x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/libcrypto-3-x64.dll -------------------------------------------------------------------------------- /res/necessities/windows/libcurl-4.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/libcurl-4.dll -------------------------------------------------------------------------------- /res/necessities/windows/libdep.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/libdep.a -------------------------------------------------------------------------------- /res/necessities/windows/libexec/gcc/x86_64-w64-mingw32/8.1.0/cc1.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/libexec/gcc/x86_64-w64-mingw32/8.1.0/cc1.exe -------------------------------------------------------------------------------- /res/necessities/windows/libgcc_s_seh-1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/libgcc_s_seh-1.dll -------------------------------------------------------------------------------- /res/necessities/windows/libiconv-2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/libiconv-2.dll -------------------------------------------------------------------------------- /res/necessities/windows/libidn2-0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/libidn2-0.dll -------------------------------------------------------------------------------- /res/necessities/windows/libintl-8.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/libintl-8.dll -------------------------------------------------------------------------------- /res/necessities/windows/libmsvcrt.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/libmsvcrt.a -------------------------------------------------------------------------------- /res/necessities/windows/libnghttp2-14.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/libnghttp2-14.dll -------------------------------------------------------------------------------- /res/necessities/windows/libnghttp3-9.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/libnghttp3-9.dll -------------------------------------------------------------------------------- /res/necessities/windows/libpsl-5.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/libpsl-5.dll -------------------------------------------------------------------------------- /res/necessities/windows/libssh2-1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/libssh2-1.dll -------------------------------------------------------------------------------- /res/necessities/windows/libssl-3-x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/libssl-3-x64.dll -------------------------------------------------------------------------------- /res/necessities/windows/libstdc++-6.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/libstdc++-6.dll -------------------------------------------------------------------------------- /res/necessities/windows/libunistring-5.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/libunistring-5.dll -------------------------------------------------------------------------------- /res/necessities/windows/libwinpthread-1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/libwinpthread-1.dll -------------------------------------------------------------------------------- /res/necessities/windows/libzstd.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/libzstd.dll -------------------------------------------------------------------------------- /res/necessities/windows/zlib1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/res/necessities/windows/zlib1.dll -------------------------------------------------------------------------------- /src/BKEND/backend.c: -------------------------------------------------------------------------------- 1 | 2 | #include "BKEND/backend.h" 3 | 4 | #include "BKEND/backend_c.h" 5 | #include "BKEND/backend_llvm.h" 6 | #include "DRVR/compiler.h" 7 | #include "DRVR/object.h" 8 | #include "UTIL/color.h" 9 | #include "UTIL/ground.h" 10 | 11 | errorcode_t ir_export(compiler_t *compiler, object_t *object, enum ir_export_backend backend){ 12 | switch(backend){ 13 | case BACKEND_NONE: 14 | internalerrorprintf("No backend specified\n"); 15 | return FAILURE; 16 | case BACKEND_LLVM: 17 | return ir_to_llvm(compiler, object); 18 | case BACKEND_C: 19 | return ir_to_c(compiler, object); 20 | default: 21 | internalerrorprintf("IR Export failed due to unrecognized backend\n"); 22 | return FAILURE; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/BKEND/ir_to_c.c: -------------------------------------------------------------------------------- 1 | 2 | #include "BKEND/ir_to_c.h" 3 | #include "DRVR/compiler.h" 4 | #include "DRVR/object.h" 5 | #include "UTIL/color.h" 6 | #include "UTIL/ground.h" 7 | 8 | errorcode_t ir_to_c(compiler_t *compiler, object_t *object){ 9 | (void) compiler; 10 | (void) object; 11 | 12 | redprintf("The C backend is not implemented yet\n"); 13 | return FAILURE; 14 | } 15 | -------------------------------------------------------------------------------- /src/BRIDGE/rtti_collector.c: -------------------------------------------------------------------------------- 1 | 2 | #include "BRIDGE/rtti_collector.h" 3 | 4 | void rtti_collector_init(rtti_collector_t *collector){ 5 | ast_type_set_init(&collector->ast_types_used, 2048); 6 | } 7 | 8 | void rtti_collector_free(rtti_collector_t *collector){ 9 | ast_type_set_free(&collector->ast_types_used); 10 | } 11 | 12 | void rtti_collector_mention(rtti_collector_t *collector, ast_type_t *type){ 13 | ast_type_set_insert(&collector->ast_types_used, type); 14 | } 15 | 16 | bool rtti_collector_mention_base(rtti_collector_t *collector, const char *name){ 17 | ast_type_t type = ast_type_make_base(strclone(name)); 18 | bool inserted = ast_type_set_insert(&collector->ast_types_used, &type); 19 | ast_type_free(&type); 20 | return inserted; 21 | } 22 | -------------------------------------------------------------------------------- /src/BRIDGEIR/rtti_table_entry.c: -------------------------------------------------------------------------------- 1 | 2 | #include "AST/ast_type.h" 3 | #include "BRIDGEIR/rtti_table_entry.h" 4 | 5 | extern inline void rtti_table_entry_list_append_unchecked(rtti_table_entry_list_t *list, rtti_table_entry_t entry); 6 | 7 | static inline int rtti_table_entry_list_cmp(const void *raw_a, const void *raw_b){ 8 | const rtti_table_entry_t *a = (rtti_table_entry_t*) raw_a; 9 | const rtti_table_entry_t *b = (rtti_table_entry_t*) raw_b; 10 | return strcmp(a->name, b->name); 11 | } 12 | 13 | void rtti_table_entry_free(rtti_table_entry_t *entry){ 14 | free(entry->name); 15 | ast_type_free(&entry->resolved_ast_type); 16 | } 17 | 18 | void rtti_table_entry_list_sort(rtti_table_entry_list_t *entries){ 19 | list_qsort((void*) entries, sizeof(rtti_table_entry_t), &rtti_table_entry_list_cmp); 20 | } 21 | -------------------------------------------------------------------------------- /src/DRVR/object.c: -------------------------------------------------------------------------------- 1 | 2 | #include "DRVR/object.h" 3 | 4 | void object_init_ast(object_t *object, unsigned int cross_compile_for){ 5 | ast_init(&object->ast, cross_compile_for); 6 | object->compilation_stage = COMPILATION_STAGE_AST; 7 | } 8 | 9 | #ifndef ADEPT_INSIGHT_BUILD 10 | void object_create_module(object_t *object){ 11 | ast_t *ast = &object->ast; 12 | ir_module_t *module = &object->ir_module; 13 | 14 | // Initialize module 15 | ir_module_init(module, ast->funcs_length, ast->globals_length, ast->funcs_length + ast->func_aliases_length + 32); 16 | 17 | // Advance compilation stage 18 | object->compilation_stage = COMPILATION_STAGE_IR_MODULE; 19 | } 20 | #endif 21 | -------------------------------------------------------------------------------- /src/IR/ir_type_map.c: -------------------------------------------------------------------------------- 1 | 2 | #include "IR/ir_type_map.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | void ir_type_map_free(ir_type_map_t *type_map){ 9 | free(type_map->mappings); 10 | } 11 | 12 | successful_t ir_type_map_find(ir_type_map_t *type_map, const char *name, ir_type_t **type_ptr){ 13 | // Does a binary search on the type map to find the requested type by name 14 | 15 | ir_type_mapping_t *mappings = type_map->mappings; 16 | 17 | long long first = 0, middle, last = (long long) type_map->length - 1, comparison; 18 | 19 | while(first <= last){ 20 | middle = (first + last) / 2; 21 | comparison = strcmp(mappings[middle].name, name); 22 | 23 | if(comparison == 0){ 24 | *type_ptr = mappings[middle].type; 25 | return true; 26 | } 27 | else if(comparison > 0) last = middle - 1; 28 | else first = middle + 1; 29 | } 30 | 31 | return false; 32 | } 33 | -------------------------------------------------------------------------------- /src/IRGEN/ir_gen_qualifiers.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include "AST/ast.h" 6 | #include "DRVR/compiler.h" 7 | #include "UTIL/ground.h" 8 | 9 | errorcode_t ensure_not_violating_no_discard(compiler_t *compiler, bool no_discard_active, source_t call_source, ast_func_t *callee){ 10 | if(no_discard_active && callee->traits & AST_FUNC_NO_DISCARD){ 11 | strong_cstr_t display = ast_func_head_str(callee); 12 | compiler_panicf(compiler, call_source, "Not allowed to discard value returned from '%s'", display); 13 | free(display); 14 | return ALT_FAILURE; 15 | } 16 | 17 | return SUCCESS; 18 | } 19 | 20 | errorcode_t ensure_not_violating_disallow(compiler_t *compiler, source_t call_source, ast_func_t *callee){ 21 | if(callee->traits & AST_FUNC_DISALLOW){ 22 | strong_cstr_t display = ast_func_head_str(callee); 23 | compiler_panicf(compiler, call_source, "Cannot use disallowed '%s'", display); 24 | free(display); 25 | return ALT_FAILURE; 26 | } 27 | 28 | return SUCCESS; 29 | } 30 | -------------------------------------------------------------------------------- /src/MAIN/main.c: -------------------------------------------------------------------------------- 1 | 2 | #ifdef _WIN32 3 | #define WIN32_LEAN_AND_MEAN 4 | #include 5 | #endif // _WIN32 6 | 7 | #include "DRVR/compiler.h" 8 | 9 | int main(int argc, char **argv){ 10 | #ifdef _WIN32 11 | SetConsoleOutputCP(CP_UTF8); 12 | #endif 13 | 14 | compiler_t compiler; 15 | compiler_init(&compiler); 16 | int exitcode = compiler_run(&compiler, argc, argv); 17 | compiler_free(&compiler); 18 | 19 | return exitcode; 20 | } 21 | -------------------------------------------------------------------------------- /src/UTIL/__insight_overloads.c: -------------------------------------------------------------------------------- 1 | 2 | #ifdef ADEPT_INSIGHT_BUILD 3 | 4 | #include "UTIL/__insight_overloads.h" 5 | 6 | char insight_buffer[2560]; 7 | char insight_tmp_buffer[1280]; 8 | size_t insight_buffer_index = 0; 9 | size_t insight_tmp_buffer_length; 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /src/UTIL/builtin_type.c: -------------------------------------------------------------------------------- 1 | 2 | #include "UTIL/builtin_type.h" 3 | 4 | const char * const global_primitives[13] = { 5 | "bool", "byte", "double", "float", "int", "long", "short", 6 | "successful", "ubyte", "uint", "ulong", "ushort", "usize" 7 | }; 8 | 9 | const char * const global_primitives_extended[15] = { 10 | "bool", "byte", "double", "float", "int", "long", /* Extra */ "ptr", 11 | "short", "successful", "ubyte", "uint", "ulong", "ushort", "usize", /* Extra */ "void" 12 | }; 13 | -------------------------------------------------------------------------------- /src/UTIL/func_pair.c: -------------------------------------------------------------------------------- 1 | 2 | #include "UTIL/func_pair.h" 3 | 4 | void optional_func_pair_set(optional_func_pair_t *result, bool has, func_id_t ast_func_id, func_id_t ir_func_id){ 5 | result->has = has; 6 | 7 | if(has){ 8 | func_pair_t *out_result = &result->value; 9 | out_result->ast_func_id = ast_func_id; 10 | out_result->ir_func_id = ir_func_id; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/UTIL/ground.c: -------------------------------------------------------------------------------- 1 | 2 | #include "UTIL/ground.h" 3 | 4 | extern inline bool lenstreq(lenstr_t a, lenstr_t b); 5 | extern inline int lenstrcmp(lenstr_t a, lenstr_t b); 6 | extern inline lenstr_t cstr_to_lenstr(char *cstr); 7 | extern inline void *memclone(void *memory, length_t bytes); 8 | -------------------------------------------------------------------------------- /src/UTIL/hash.c: -------------------------------------------------------------------------------- 1 | 2 | #include "UTIL/ground.h" 3 | #include "UTIL/hash.h" 4 | 5 | hash_t hash_data(const void *data, length_t size){ 6 | hash_t hash = 0; 7 | for(length_t i = 0; i != size; i++){ 8 | hash = (hash * 31) + (hash_t)((char*) data)[i]; 9 | } 10 | return hash; 11 | } 12 | 13 | hash_t hash_string(const char *s){ 14 | return hash_data(s, strlen(s)); 15 | } 16 | 17 | hash_t hash_strings(char *strings[], length_t num_strings){ 18 | if(num_strings == 0) return 0; 19 | 20 | hash_t hash = hash_string(strings[0]); 21 | 22 | for(length_t i = 1; i < num_strings; i++){ 23 | hash = hash_combine(hash, hash_string(strings[i])); 24 | } 25 | 26 | return hash; 27 | } 28 | 29 | hash_t hash_combine(hash_t h1, hash_t h2){ 30 | hash_t hash = h1; 31 | for(length_t i = 0; i != sizeof(h2); i++){ 32 | hash = (hash * 31) + (hash_t)((char*) &h2)[i]; 33 | } 34 | return hash; 35 | } 36 | -------------------------------------------------------------------------------- /src/UTIL/list.c: -------------------------------------------------------------------------------- 1 | 2 | #include "UTIL/list.h" 3 | 4 | #include 5 | 6 | #include "UTIL/ground.h" 7 | #include "UTIL/util.h" 8 | 9 | void *list_append_new_impl(void *list_struct, length_t sizeof_element){ 10 | void_list_t *list = (void_list_t*) list_struct; 11 | 12 | // Make room for new item 13 | expand((void**) &list->items, sizeof_element, list->length, &list->capacity, 1, 4); 14 | 15 | // Return new item 16 | return (void*) &(((char*) list->items)[list->length++ * sizeof_element]); 17 | } 18 | 19 | extern inline void list_qsort(void *list_struct, length_t sizeof_element, int (*cmp)(const void*, const void*)); 20 | 21 | void *list_last_unchecked_ptr_impl(void *list_struct, length_t sizeof_element){ 22 | void_list_t *list = (void_list_t*) list_struct; 23 | return (void*) &(((char*) list->items)[(list->length - 1) * sizeof_element]); 24 | } 25 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_subdirectory(unit) 3 | add_subdirectory(e2e) 4 | -------------------------------------------------------------------------------- /tests/e2e/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | if (UNIX) 3 | set(PYTHON_COMMAND "/usr/bin/python3") 4 | else() 5 | set(PYTHON_COMMAND "python3") 6 | endif() 7 | 8 | # Regular Local Testing 9 | add_test(NAME E2E COMMAND ${PYTHON_COMMAND} ${CMAKE_CURRENT_SOURCE_DIR}/e2e-runner.py $ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) 10 | -------------------------------------------------------------------------------- /tests/e2e/src/address/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | import 'sys/cstdlib.adept' 4 | 5 | func main(in argc int, in argv **ubyte) int { 6 | memory ptr = malloc(10) 7 | printf('Memory allocated at %p\n', memory) 8 | printf('Memory pointer on stack is at %p\n', &memory) 9 | free(memory) 10 | return 0 11 | } 12 | -------------------------------------------------------------------------------- /tests/e2e/src/aliases/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | alias HANDLE = ptr 5 | alias s32 = int 6 | alias char = ubyte 7 | alias cstr = *char 8 | 9 | func main(in argc int, in argv **ubyte) int { 10 | handle HANDLE = null 11 | signed32 s32 = 0 12 | character char = 65 13 | name cstr = 'Isaac' 14 | 15 | format cstr = '%p, %d, "%c", "%s"\n' 16 | printf(format, handle, signed32, character, name) 17 | return 0 18 | } 19 | -------------------------------------------------------------------------------- /tests/e2e/src/aliases_polymorphic/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | record <$A, $B> Douplet (a $A, b $B) 5 | 6 | alias <$T, $S> TwoThing = <$T, $S> Douplet 7 | 8 | func main { 9 | two_thing TwoThing = Douplet(12si, 9.0) 10 | 11 | printf('first=%d second=%f\n', two_thing.a, two_thing.b) 12 | } 13 | -------------------------------------------------------------------------------- /tests/e2e/src/alignof/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main { 5 | printAlignof(null as *bool) 6 | printAlignof(null as *ubyte) 7 | printAlignof(null as *ushort) 8 | printAlignof(null as *uint) 9 | printAlignof(null as *ulong) 10 | printAlignof(null as *usize) 11 | printAlignof(null as *ptr) 12 | printAlignof(null as **int) 13 | printAlignof(null as *String) 14 | } 15 | 16 | func printAlignof(_type *$T) { 17 | printf("alignof %s = %zu\n", typenameof $T, alignof $T) 18 | } 19 | -------------------------------------------------------------------------------- /tests/e2e/src/andor/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | import 'sys/cstdlib.adept' 4 | 5 | func main(in argc int, in argv **ubyte) int { 6 | if 1 and 1 { 7 | puts('1 and 1') 8 | } 9 | if 1 or 1 { 10 | puts('1 or 1') 11 | } 12 | if 0 && 1 { 13 | puts('0 && 1') 14 | } 15 | if 0 || 1 { 16 | puts('0 || 1') 17 | } 18 | if 0 and 0 { 19 | puts('0 and 0') 20 | } 21 | if 0 or 0 { 22 | puts('0 or 0') 23 | } 24 | return 0 25 | } 26 | -------------------------------------------------------------------------------- /tests/e2e/src/andor_circuit/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | import 'sys/cstdlib.adept' 4 | 5 | func main(in argc int, in argv **ubyte) int { 6 | printf('1 and 1 = %s\n\n', one() and one() ? 'true' : 'false') 7 | printf('1 or 1 = %s\n\n', one() or one() ? 'true' : 'false') 8 | printf('0 && 1 = %s\n\n', zero() && one() ? 'true' : 'false') 9 | printf('0 || 1 = %s\n\n', zero() || one() ? 'true' : 'false') 10 | printf('0 and 0 = %s\n\n', zero() and zero() ? 'true' : 'false') 11 | printf('0 or 0 = %s\n\n', zero() or zero() ? 'true' : 'false') 12 | return 0 13 | } 14 | 15 | func one int { 16 | printf('one\n') 17 | return 1 18 | } 19 | 20 | func zero int { 21 | printf('zero\n') 22 | return 0 23 | } 24 | -------------------------------------------------------------------------------- /tests/e2e/src/anonymous_composites/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma compiler_version '2.5' 3 | 4 | import basics 5 | import math 6 | 7 | func main { 8 | point struct (x, y, z float) 9 | 10 | point.x = 1.0f 11 | point.y = 2.0f 12 | point.z = 3.0f 13 | printf("(1.0f, 2.0f, 3.0f) distance to origin is %hf\n", distanceToOrigin(point)) 14 | 15 | maybe_float struct (is_float bool, union (f float, i int)) 16 | maybe_float.is_float = true 17 | maybe_float.f = 2.0f * PI 18 | 19 | printf("Tau = %S\n", toString(maybe_float)) 20 | } 21 | 22 | func distanceToOrigin(p struct (x, y, z float)) float { 23 | return sqrt(p.x * p.x + p.y * p.y + p.z * p.z) 24 | } 25 | 26 | func toString(maybe_float struct (is_float bool, union (f float, i int))) String { 27 | if maybe_float.is_float, return toString(maybe_float.f) 28 | return toString(maybe_float.i) 29 | } 30 | -------------------------------------------------------------------------------- /tests/e2e/src/anonymous_enums/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main { 5 | a, b, c enum (A, C, B) 6 | 7 | a = ::A 8 | b = ::B 9 | c = ::C 10 | 11 | print(a as usize, b as usize, c as usize) 12 | 13 | assert typeinfo enum (A, B, C) == typeinfo enum (C, A, B) 14 | 15 | ty_info *AnyEnumType = typeinfo enum (A, B, C) as *AnyEnumType 16 | assert ty_info.kind == ::ENUM 17 | 18 | print(ty_info.name) 19 | 20 | each *ubyte in [ty_info.members, ty_info.length] { 21 | printf(" - member %d is %s\n", idx, it) 22 | } 23 | 24 | print(a, b, c) 25 | } 26 | -------------------------------------------------------------------------------- /tests/e2e/src/any_fixed_array/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | import basics 4 | 5 | func main { 6 | my_fixed_array 100 int 7 | 8 | fixed *AnyFixedArrayType = cast *AnyFixedArrayType typeinfo 100 int 9 | printf("Information about '%s'\n", fixed.name) 10 | printf("Number of elements: %d\n", fixed.length) 11 | printf("Element Type: %s\n", fixed.subtype.name) 12 | } 13 | -------------------------------------------------------------------------------- /tests/e2e/src/any_function_pointer/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | import basics 4 | 5 | func main { 6 | my_function_pointer func(int, float, double) long 7 | 8 | fp *AnyFuncPtrType = cast *AnyFuncPtrType typeinfo func(int, float, double) long 9 | printf("Information about '%s'\n", fp.name) 10 | 11 | each *AnyType in [fp.args, fp.length] { 12 | printf(" argument[%d] has type: %s\n", idx, it.name) 13 | } 14 | printf(" Return type is: %s\n", fp.return_type.name) 15 | } 16 | -------------------------------------------------------------------------------- /tests/e2e/src/any_type_as/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | struct Thing (x int, y int) 5 | 6 | func main { 7 | show(10) 8 | show(1234) 9 | show(31.4142) 10 | show(3.14159f) 11 | show(987654321ul) 12 | show(true) 13 | show('Hello World') 14 | x Thing 15 | x.x = 1234 16 | x.y = 5678 17 | show(&x) 18 | show('\n'ub) 19 | } 20 | 21 | func show(in any Any) { 22 | if any.type.kind == AnyTypeKind::INT { 23 | printf('int: %d\n', *cast *int &any.placeholder) 24 | } else if any.type.kind == AnyTypeKind::FLOAT { 25 | printf('float: %f\n', cast double *cast *float &any.placeholder) 26 | } else if any.type.kind == AnyTypeKind::DOUBLE { 27 | printf('double: %f\n', *cast *double &any.placeholder) 28 | } else if any.type.kind == AnyTypeKind::ULONG { 29 | printf('ulong: %d\n', cast int *cast *ulong &any.placeholder) 30 | } else if any.type.kind == AnyTypeKind::BOOL { 31 | printf('bool: %d\n', cast int *cast *bool &any.placeholder) 32 | } else if any.type == typeinfo *ubyte { 33 | printf('cstring: \'%s\'\n', *cast **ubyte &any.placeholder) 34 | } else if any.type.kind == AnyTypeKind::PTR { 35 | printf('pointer: %p\n', *cast *ptr &any.placeholder) 36 | } else { 37 | printf('unknown value\n') 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/e2e/src/any_type_info/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | import 'sys/cstring.adept' 4 | 5 | func main { 6 | value Any = undef 7 | 8 | int_type *AnyType = typeinfo **short 9 | printf('typeinfo of **short has a name of \'%s\'\n', int_type.name) 10 | 11 | value.type = typeinfo int 12 | *cast *int &value.placeholder = 123456789 13 | showIntOrFloat(value) 14 | 15 | value.type = typeinfo float 16 | *cast *float &value.placeholder = 3.14159 17 | showIntOrFloat(value) 18 | } 19 | 20 | func showIntOrFloat(in any Any) { 21 | if any.type.kind == AnyTypeKind::INT { 22 | printf('int: %d\n', *cast *int &any.placeholder) 23 | } else if any.type.kind == AnyTypeKind::FLOAT { 24 | printf('float: %f\n', cast double *cast *float &any.placeholder) 25 | } else { 26 | printf('unknown value\n') 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/e2e/src/any_type_inventory/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main { 5 | printf('--------------------- TYPES ---------------------\n') 6 | each *AnyType in [__types__, __types_length__], 7 | printf('type: %-20s ', it.name); 8 | if idx % 2 == 1, printf('\n') 9 | 10 | if __types_length__ % 2 == 1, printf('\n') 11 | 12 | printf('--------------------- KINDS ---------------------\n') 13 | each *ubyte in [__type_kinds__, __type_kinds_length__], 14 | printf('kind: %-20s ', it); 15 | if idx % 2 == 1, printf('\n') 16 | } 17 | -------------------------------------------------------------------------------- /tests/e2e/src/any_type_kind/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | import 'sys/cstring.adept' 4 | 5 | func main { 6 | _force_int_runtime_info int = undef 7 | some_type *AnyType = null 8 | 9 | each *AnyType in [__types__, __types_length__], 10 | if strcmp(it.name, 'int') == 0, 11 | some_type = it; break 12 | 13 | if some_type.kind == AnyTypeKind::INT { 14 | printf('some_type kind is an int\n'); 15 | } else { 16 | printf('some_type kind is NOT an int\n'); 17 | } 18 | 19 | printf('some_type is named: \'%s\'\n', some_type.name) 20 | printf('some_type kind is named: \'%s\'\n', __type_kinds__[some_type.kind]) 21 | } 22 | -------------------------------------------------------------------------------- /tests/e2e/src/any_type_list/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | // Alias to test {alias} description 5 | alias FuncReturnsInt = func () int 6 | 7 | func main { 8 | each *AnyType in [__types__, __types_length__] { 9 | additional_description *ubyte = '' 10 | if it.is_alias, additional_description = '{alias}' 11 | printf('%-20s - %-16s %s\n', it.name, __type_kinds__[it.kind], additional_description) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/e2e/src/any_type_offsets/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import '2.3/basics.adept' 3 | 4 | struct Test1 (a, b, c int) 5 | struct Test2 (a, b, c ulong) 6 | struct Test3 (a, b, c ubyte) 7 | 8 | func main { 9 | printOffsets(typeinfo Test1 as *AnyStructType, sizeof Test1) 10 | printOffsets(typeinfo Test2 as *AnyStructType, sizeof Test2) 11 | printOffsets(typeinfo Test3 as *AnyStructType, sizeof Test3) 12 | } 13 | 14 | func printOffsets(type *AnyStructType, size usize) { 15 | each usize in [type.offsets, type.length] { 16 | printf('%d - %d\n', idx as int, it as int) 17 | } 18 | printf('sizeof = %d\n', size as int) 19 | } 20 | -------------------------------------------------------------------------------- /tests/e2e/src/any_type_sizes/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main { 5 | // Print the size of each type used in the program 6 | each *AnyType in [__types__, __types_length__] { 7 | printf('\'%s\' is %d bytes\n', it.name, it.size as int); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/e2e/src/array_access/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | import 'sys/cstdlib.adept' 4 | 5 | func main(in argc int, in argv **ubyte) int { 6 | memory *ubyte = malloc(3) 7 | memory[0] = 72 8 | memory[1] = 105 9 | memory[2] = 0 10 | printf('memory is: %s\n', memory) 11 | memory[1] = memory[2] 12 | printf('memory is now: "%s"\n', memory) 13 | free(memory) 14 | return 0 15 | } 16 | -------------------------------------------------------------------------------- /tests/e2e/src/assert_simple/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import assertions 3 | 4 | func main { 5 | this_is_true bool = true 6 | this_is_false bool = false 7 | 8 | assert this_is_true 9 | assert this_is_false 10 | } 11 | -------------------------------------------------------------------------------- /tests/e2e/src/assert_with_message/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import String 3 | import assertions 4 | 5 | func main { 6 | this_is_true bool = true 7 | this_is_false bool = false 8 | 9 | assert this_is_true, 'Expected this_is_true to be true' 10 | assert this_is_false, "Expected this_is_false to be false" + " hi btw!!!!!!!!!!!" 11 | } 12 | -------------------------------------------------------------------------------- /tests/e2e/src/assign_func/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | foreign printf(*ubyte, ...) int 4 | 5 | struct Test () 6 | struct <$T> Container (t $T) 7 | 8 | func main { 9 | t1 Test 10 | t2 Test = t1 11 | 12 | t3 Container 13 | t4 Container = t3 14 | } 15 | 16 | func __assign__(this *Test, other POD Test) { 17 | printf('Hello ') 18 | } 19 | 20 | func __assign__(this *<$T> Container, other POD <$T> Container) { 21 | printf('World\n') 22 | } 23 | -------------------------------------------------------------------------------- /tests/e2e/src/assign_func_autogen/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | record PrintWhenAssign () { 5 | func __assign__(_other POD PrintWhenAssign) { 6 | print(" - PrintWhenAssign was assigned") 7 | } 8 | } 9 | 10 | record Container (pwa PrintWhenAssign) 11 | 12 | // Even though 'Container.__assign__' is not directly declared, 13 | // it will automatically be generated because it directly contains 14 | // 'PrintWhenAssign' which does have an __assign__ function. 15 | // (and so the whole structure should not be treated as plain-old-data for assignment) 16 | 17 | func main { 18 | // Should print the message five times 19 | 20 | print("line one (2 messages expected)") 21 | container1 Container = Container(PrintWhenAssign()) 22 | newline() 23 | 24 | print("line two (2 messages expected)") 25 | container2 Container = Container(PrintWhenAssign()) 26 | newline() 27 | 28 | print("line three (1 messages expected)") 29 | container1 = container2 30 | newline() 31 | } 32 | -------------------------------------------------------------------------------- /tests/e2e/src/assignment/main.adept: -------------------------------------------------------------------------------- 1 | 2 | foreign puts(*ubyte) int 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | message *ubyte = 'This text will not be displayed' 6 | message = 'Hello World!' 7 | puts(message) 8 | return 0 9 | } 10 | -------------------------------------------------------------------------------- /tests/e2e/src/at/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | ints 10 int = undef 6 | 7 | // Set to some numbers 8 | repeat 10, ints[idx] = idx + 1 9 | print(ints) 10 | 11 | // Zero some numbers 12 | repeat 10, zero(ints at idx) 13 | print(ints) 14 | 15 | return 0 16 | } 17 | 18 | func zero(out ref *int) void { 19 | *ref = 0 20 | } 21 | 22 | func print(in ints 10 int) void { 23 | repeat 10, printf('%d ', ints[idx]) 24 | putchar('\n'ub) 25 | } 26 | -------------------------------------------------------------------------------- /tests/e2e/src/bitwise/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | a int = 100 6 | b int = 73 7 | 8 | printf('Bitwise AND : 100 & 73 = %d\n', a & b) 9 | printf('Bitwise OR : 100 | 73 = %d\n', a | b) 10 | printf('Bitwise XOR : 100 ^ 73 = %d\n', a ^ b) 11 | printf('Left Shift : -100 << 2 = %d\n', -a << 2) 12 | printf('Right Shift : -100 >> 2 = %d\n', -a >> 2) 13 | printf('Logical Left Shift : -100 <<< 2 = %d\n', -a <<< 2) 14 | printf('Logical Right Shift : -100 >>> 2 = %d\n', -a >>> 2) 15 | printf('Bitwise Complement : ~100 = %d\n', ~a) 16 | return 0 17 | } 18 | -------------------------------------------------------------------------------- /tests/e2e/src/bitwise_assign/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma no_typeinfo 3 | import 'sys/cstdio.adept' 4 | 5 | func main { 6 | a int = undef 7 | b int = 73 8 | 9 | a = 100; a &= b 10 | printf('Bitwise AND : 100 & 73 = %d\n', a) 11 | 12 | a = 100; a |= b 13 | printf('Bitwise OR : 100 | 73 = %d\n', a) 14 | 15 | a = 100; a ^= b 16 | printf('Bitwise XOR : 100 ^ 73 = %d\n', a) 17 | 18 | a = -100; a <<= 2 19 | printf('Left Shift : -100 << 2 = %d\n', a) 20 | 21 | a = -100; a >>= 2 22 | printf('Right Shift : -100 >> 2 = %d\n', a) 23 | 24 | a = -100; a <<<= 2 25 | printf('Logical Left Shift : -100 <<< 2 = %d\n', a) 26 | 27 | a = -100; a >>>= 2 28 | printf('Logical Right Shift : -100 >>> 2 = %d\n', a) 29 | 30 | a = 100; a = ~a 31 | printf('Bitwise Complement : ~100 = %d\n', a) 32 | } 33 | -------------------------------------------------------------------------------- /tests/e2e/src/break/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | i usize = 0; while i != 100 { 6 | if i == 10, break 7 | printf('> %d\n', cast int i) 8 | i += 1 9 | } 10 | return 0 11 | } 12 | -------------------------------------------------------------------------------- /tests/e2e/src/break_to/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | i, j usize = 0 6 | 7 | // This code will result in i and j being 21. 8 | // This isn't a very practical example of when you would use this, 9 | // but it showcases the feature well in little code, so whatever 10 | 11 | while outer : i != 100 { 12 | while inner : j != 100 { 13 | if i == 10 and j == 10, break outer 14 | j += 1 15 | } 16 | j = 0; i += 1 17 | } 18 | 19 | // Labels can be resued. The first surrounding block with the 20 | // given label will be selected if there are duplicates. 21 | while outer : i != 50 or j != 50 { 22 | i += 1; j += 1 23 | if i == 21, break outer 24 | } 25 | 26 | printf('%d %d\n', i, j) 27 | return 0 28 | } 29 | -------------------------------------------------------------------------------- /tests/e2e/src/character_literals/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | printf('%c%c%c%c%c%c%c', 'H'ub, 'e'ub, 'l'ub, 'l'ub, 'o'ub, '!'ub, '\n'ub) 6 | return 0 7 | } 8 | -------------------------------------------------------------------------------- /tests/e2e/src/circular_pointers/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma compiler_version '2.5' 3 | 4 | import basics 5 | 6 | struct Person (father *Person) 7 | 8 | struct A (b *B) 9 | struct B (a *A) 10 | 11 | func main { 12 | selfContainingTypes() 13 | crossContainingTypes() 14 | } 15 | 16 | func selfContainingTypes { 17 | print("selfContainingTypes:") 18 | person Person 19 | 20 | p *Person = &person 21 | p.father = &person 22 | 23 | repeat 10 { 24 | printf("p.father = %p ; p = p.father\n", p.father) 25 | p = p.father 26 | } 27 | } 28 | 29 | func crossContainingTypes { 30 | print("crossContainingTypes:") 31 | a A 32 | b B 33 | 34 | a.b = &b 35 | b.a = &a 36 | 37 | printf("a.b = %p\n", a.b) 38 | printf("b.a = %p\n", b.a) 39 | } 40 | -------------------------------------------------------------------------------- /tests/e2e/src/class/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | class Player (name String, id ulong) { 5 | constructor(name String){ 6 | static next_id ulong = 1 7 | 8 | this.name = name.toOwned() 9 | this.id = next_id++ 10 | } 11 | } 12 | 13 | func toString(player Player) String { 14 | return sprintf("Player(%S - %d)", player.name, player.id) 15 | } 16 | 17 | func main { 18 | players List = { 19 | Player("Jonish".clone()), 20 | Player("Joshish".clone()), 21 | Player("Jimish".clone()), 22 | } 23 | 24 | each Player in static players { 25 | print(it) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/e2e/src/class_extends/main.adept: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Test basic usage of 'extends' syntax for classes 4 | */ 5 | 6 | import basics 7 | 8 | class Animal (name String) { 9 | constructor() {} 10 | } 11 | 12 | class Dog extends Animal (age int) { 13 | constructor() {} 14 | } 15 | 16 | class GoldenRetriever extends Dog (color String) { 17 | constructor() {} 18 | } 19 | 20 | func main { 21 | printCompositeLayout(null as *Animal) 22 | printCompositeLayout(null as *Dog) 23 | printCompositeLayout(null as *GoldenRetriever) 24 | } 25 | 26 | func printCompositeLayout(_unused *$T){ 27 | ty *AnyCompositeType = typeinfo $T as *AnyCompositeType 28 | 29 | printf("%s:\n", typenameof $T) 30 | 31 | each name *ubyte in [ty.member_names, ty.length] { 32 | printf(" - %s\n", name) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/e2e/src/class_missing_constructor/main.adept: -------------------------------------------------------------------------------- 1 | 2 | class ThisIsMissingConstructor () 3 | 4 | func main {} 5 | -------------------------------------------------------------------------------- /tests/e2e/src/class_virtual_methods_1/main.adept: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Test to make sure the following work: 4 | - basic vtables 5 | - basic virtual methods 6 | - basic method overriding 7 | - basic virtual dispatch 8 | */ 9 | 10 | import 'sys/cstdio.adept' 11 | 12 | class Shape () { 13 | constructor {} 14 | 15 | virtual func printName { 16 | printf('shape\n') 17 | } 18 | } 19 | 20 | class Rectangle extends Shape () { 21 | constructor {} 22 | 23 | override func printName { 24 | printf('rectangle\n') 25 | } 26 | } 27 | 28 | func main { 29 | shape *Shape = new Shape() 30 | defer delete shape 31 | 32 | rectangle *Shape = new Rectangle() as *Shape 33 | defer delete rectangle 34 | 35 | shape.printName() 36 | rectangle.printName() 37 | } 38 | -------------------------------------------------------------------------------- /tests/e2e/src/class_virtual_methods_2/main.adept: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Test to make sure that we can return values from virtual methods 4 | */ 5 | 6 | import 'sys/cstdio.adept' 7 | 8 | class Shape () { 9 | constructor {} 10 | 11 | virtual func getName *ubyte { 12 | return 'shape' 13 | } 14 | } 15 | 16 | class Rectangle extends Shape () { 17 | constructor {} 18 | 19 | override func getName *ubyte { 20 | return 'rectangle' 21 | } 22 | } 23 | 24 | func main { 25 | shape *Shape = new Shape() 26 | defer delete shape 27 | 28 | rectangle *Shape = new Rectangle() as *Shape 29 | defer delete rectangle 30 | 31 | printf('%s\n%s\n', shape.getName(), rectangle.getName()) 32 | } 33 | -------------------------------------------------------------------------------- /tests/e2e/src/class_virtual_methods_3_missing_override/main.adept: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Test to make sure that not using the 'override' keyword for virtual method overrides is a compile-time error 4 | */ 5 | 6 | import 'sys/cstdio.adept' 7 | 8 | class Shape () { 9 | constructor {} 10 | 11 | virtual func getName *ubyte { 12 | return 'shape' 13 | } 14 | } 15 | 16 | class Rectangle extends Shape () { 17 | constructor {} 18 | 19 | // Missing override keyword is a compile-time error 20 | func getName *ubyte { 21 | return 'rectangle' 22 | } 23 | } 24 | 25 | func main { 26 | shape *Shape = new Shape() 27 | defer delete shape 28 | 29 | rectangle *Shape = new Rectangle() as *Shape 30 | defer delete rectangle 31 | 32 | printf('%s\n', shape.getName()) 33 | printf('%s\n', rectangle.getName()) 34 | printf('%s\n', (shape as *Rectangle).getName()) 35 | } 36 | -------------------------------------------------------------------------------- /tests/e2e/src/class_virtual_methods_4/main.adept: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Test to make sure that the following work with polymorphic classes: 4 | - basic vtables 5 | - basic virtual methods 6 | - basic method overriding 7 | - basic virtual dispatch 8 | */ 9 | 10 | import 'sys/cstdio.adept' 11 | 12 | class <$T> Shape () { 13 | constructor {} 14 | 15 | virtual func printName { 16 | printf('<%s> shape\n', typenameof $T) 17 | } 18 | } 19 | 20 | class <$T> Rectangle extends <$T> Shape () { 21 | constructor {} 22 | 23 | override func printName { 24 | printf('<%s> rectangle\n', typenameof $T) 25 | } 26 | } 27 | 28 | func test(_ *$T) { 29 | shape *<$T> Shape = new <$T> Shape() 30 | defer delete shape 31 | 32 | rectangle *<$T> Shape = new <$T> Rectangle() as *<$T> Shape 33 | defer delete rectangle 34 | 35 | shape.printName() 36 | rectangle.printName() 37 | } 38 | 39 | func main { 40 | test(null as *int) 41 | test(null as *struct (x, y, z float)) 42 | test(null as *100 float) 43 | } 44 | -------------------------------------------------------------------------------- /tests/e2e/src/class_virtual_methods_5/main.adept: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Test to make sure that non-polymorphic classes can extend polymorphic classes and still have the following work: 4 | - vtables 5 | - virtual methods 6 | - method overriding 7 | - virtual dispatch 8 | */ 9 | 10 | import 'sys/cstdio.adept' 11 | 12 | class <$T> Shape () { 13 | constructor {} 14 | 15 | virtual func printName1 { 16 | printf('<%s> shape\n', typenameof $T) 17 | } 18 | 19 | virtual func printName2 { 20 | printf('shape of %s\n', typenameof $T) 21 | } 22 | } 23 | 24 | class Rectangle extends Shape () { 25 | constructor {} 26 | 27 | override func printName1 { 28 | printf(' rectangle\n') 29 | } 30 | 31 | override func printName2 { 32 | printf('rectangle of always int\n') 33 | } 34 | } 35 | 36 | func main { 37 | shape * Shape = new Shape() 38 | defer delete shape 39 | 40 | rectangle * Shape = new Rectangle() as * Shape 41 | defer delete rectangle 42 | 43 | shape.printName1() 44 | rectangle.printName1() 45 | shape.printName2() 46 | rectangle.printName2() 47 | } 48 | -------------------------------------------------------------------------------- /tests/e2e/src/class_virtual_methods_6/main.adept: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Test to make sure that polymorphic classes can extend non-polymorphic classes and still have the following work: 4 | - vtables 5 | - virtual methods 6 | - method overriding 7 | - virtual dispatch 8 | */ 9 | 10 | import 'sys/cstdio.adept' 11 | 12 | class RootObject () { 13 | constructor {} 14 | 15 | virtual func printName { 16 | printf('root object\n') 17 | } 18 | } 19 | 20 | class <$T> Container extends RootObject (value $T) { 21 | constructor {} 22 | 23 | override func printName { 24 | printf('container of %s\n', typenameof $T) 25 | } 26 | } 27 | 28 | func main { 29 | root *RootObject = new RootObject() 30 | defer delete root 31 | 32 | container *RootObject = new Container() as *RootObject 33 | defer delete container 34 | 35 | root.printName() 36 | container.printName() 37 | } 38 | -------------------------------------------------------------------------------- /tests/e2e/src/class_virtual_methods_7_incorrect_return_type/main.adept: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Test to make sure that overrides are not allowed to return a different type 4 | from the original virtual method that they override 5 | */ 6 | 7 | import 'sys/cstdio.adept' 8 | 9 | class Shape () { 10 | constructor {} 11 | 12 | virtual func getName *ubyte { 13 | return 'shape' 14 | } 15 | } 16 | 17 | import basics 18 | 19 | class Rectangle extends Shape () { 20 | constructor {} 21 | 22 | // should be a compile time error - trying to have int return type but should be returning *ubyte 23 | override func getName int { 24 | return 10 25 | } 26 | } 27 | 28 | func main { 29 | shape *Shape = new Shape() 30 | defer delete shape 31 | 32 | rectangle *Shape = new Rectangle() as *Shape 33 | defer delete rectangle 34 | 35 | printf('%s\n%s\n', shape.getName(), rectangle.getName()) 36 | } 37 | -------------------------------------------------------------------------------- /tests/e2e/src/class_virtual_methods_8_unused_override/main.adept: -------------------------------------------------------------------------------- 1 | 2 | class Thing () { 3 | constructor {} 4 | } 5 | 6 | class OtherThing extends Thing () { 7 | constructor {} 8 | 9 | // this should be a compile-time error - trying to override a virtual method that doesn't exist 10 | override func myUnusedOverride { 11 | 12 | } 13 | } 14 | 15 | func main {} 16 | -------------------------------------------------------------------------------- /tests/e2e/src/class_virtual_methods_9/main.adept: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Test automatic casting for values of compatible class pointers types 4 | */ 5 | 6 | import basics 7 | 8 | class Shape () { 9 | constructor {} 10 | 11 | virtual func getArea float { 12 | return 0.0 13 | } 14 | } 15 | 16 | class Circle extends Shape (r float) { 17 | constructor(r float) { 18 | this.r = r 19 | } 20 | 21 | override func getArea float { 22 | return 3.14159 * this.r * this.r 23 | } 24 | } 25 | 26 | class Rectangle extends Shape (w, h float) { 27 | constructor(w, h float) { 28 | this.w = w 29 | this.h = h 30 | } 31 | 32 | override func getArea float { 33 | return this.w * this.h 34 | } 35 | } 36 | 37 | func main { 38 | shape *Shape = new Shape() 39 | defer delete shape 40 | 41 | printf('shape.getArea() = %f\n', shape.getArea() as double) 42 | 43 | circle *Shape = new Circle(2.0) 44 | defer delete circle 45 | 46 | printf('circle.getArea() = %f\n', circle.getArea() as double) 47 | 48 | rectangle *Shape = new Rectangle(4.0, 5.0) 49 | defer delete rectangle 50 | 51 | printf('rectangle.getArea() = %f\n', rectangle.getArea() as double) 52 | } 53 | -------------------------------------------------------------------------------- /tests/e2e/src/colons_alternative_syntax/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | import basics 4 | 5 | people :: namespace { 6 | Person :: struct (firstname, lastname String) 7 | } 8 | 9 | pi :: namespace 10 | 11 | almost_pi :: define = 3.123456 12 | 13 | namespace 14 | 15 | PePerson :: alias = people\Person 16 | 17 | main :: func { 18 | person: PePerson 19 | scan("Enter your name: ", &person.firstname) 20 | myPrintf("Hello %f %S!", pi\almost_pi, person.firstname) 21 | } 22 | 23 | myPrintf :: func (format String, arguments ...) : int { 24 | name: String = "Hello" 25 | vsprintf(def result String, format, arguments) 26 | print(result) 27 | return 0 28 | } 29 | -------------------------------------------------------------------------------- /tests/e2e/src/complement/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | printf('~0 = %llX\n', ~0) 6 | printf('~0ub = %2X\n', ~0ub) 7 | printf('~0sb = %2X\n', ~0sb) 8 | printf('~0us = %4X\n', ~0us) 9 | printf('~0ss = %4X\n', ~0ss) 10 | printf('~0ui = %8X\n', ~0ui) 11 | printf('~0si = %8X\n', ~0si) 12 | printf('~0ul = %llX\n', ~0ul) 13 | printf('~0sl = %llX\n', ~0sl) 14 | return 0 15 | } 16 | -------------------------------------------------------------------------------- /tests/e2e/src/complex_composite_rtti/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma compiler_version '2.5' 3 | 4 | import basics 5 | 6 | struct IntOrFloat ( 7 | is_float bool, 8 | union (f float, i int) 9 | ) 10 | 11 | func main { 12 | ty *AnyStructType = typeinfo IntOrFloat as *AnyStructType 13 | 14 | // Complex Composite Types will just be 15 | // AnyCompositeType with overlapping fields 16 | // NOTE: The 'kind' will still either be 'AnyTypeKind::STRUCT' or 'AnyTypeKind::UNION' 17 | // based on the root node of the type. Also 'AnyStructType' and 'AnyUnionType' have 18 | // been removed and are now aliases to 'AnyCompositeType'. 19 | 20 | composite_kind String = ty.kind == AnyTypeKind::STRUCT ? "struct" : "union" 21 | printf("Mappings of '%S IntOrFloat' complex composite:\n", composite_kind) 22 | repeat ty.length { 23 | field_name String = stringConstant(ty.member_names[idx]) 24 | field_type String = stringConstant(ty.members[idx].name) 25 | offset usize = ty.offsets[idx] 26 | 27 | printf(" %S %S @+%zu\n", field_name, field_type, offset) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/e2e/src/conditionless_block/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main { 5 | defer print("4") 6 | 7 | { 8 | defer print("2") 9 | 10 | print("1") 11 | } 12 | 13 | print("3") 14 | } 15 | -------------------------------------------------------------------------------- /tests/e2e/src/conditionless_break_label/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | value int = 0 6 | 7 | 8 | until break at_10 { 9 | value += 1 10 | if value == 10, break at_10 11 | } 12 | 13 | printf('value is %d after "until break at_10" loop\n', value) 14 | 15 | while continue not_at_0 { 16 | value -= 1 17 | unless value == 0, continue not_at_0 18 | } 19 | 20 | printf('value is %d after "while continue not_at_0" loop\n', value) 21 | return 0 22 | } 23 | -------------------------------------------------------------------------------- /tests/e2e/src/const_variables/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main { 5 | // [10, 11, 12] 6 | define x = getIntegerValue() 7 | print({x, x, x} as Array) 8 | 9 | // [13, 13, 13] 10 | const y int = getIntegerValue() 11 | print({y, y, y} as Array) 12 | } 13 | 14 | func getIntegerValue int { 15 | static next int = 10 16 | return next++ 17 | } 18 | -------------------------------------------------------------------------------- /tests/e2e/src/constructor/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | struct Person (name String, age int) { 5 | constructor(name String, age int){ 6 | this.name = name.toOwned() 7 | this.age = age 8 | } 9 | } 10 | 11 | func main { 12 | person1 Person("Isaac Shelton", 100) 13 | person2 *Person = new Person("John Smith", 50) 14 | 15 | defer { 16 | person2.__defer__() 17 | delete person2 18 | } 19 | 20 | print(person1) 21 | print(*person2) 22 | print(Person("Jade Armstrong", 25)) 23 | } 24 | 25 | func toString(person Person) String { 26 | return sprintf("%S is %d years old", person.name, person.age) 27 | } 28 | -------------------------------------------------------------------------------- /tests/e2e/src/constructor_in_only/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | struct Thing (a, b, c int) { 5 | in constructor { 6 | this.a = 1 7 | this.b = 2 8 | this.c = 3 9 | } 10 | 11 | func __assign__(other POD Thing) = delete 12 | } 13 | 14 | func main { 15 | thing Thing() 16 | print(thing.a, thing.b, thing.c) 17 | 18 | // `in constructor` does not generate additional subject-less constructor function 19 | // main.adept:20:20: error: Undeclared function 'Thing' 20 | thing2 Thing = Thing() 21 | print(thing2.a, thing2.b, thing2.c) 22 | } 23 | -------------------------------------------------------------------------------- /tests/e2e/src/constructor_with_defaults/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | struct Thing () { 5 | constructor(default_value int = 10) { 6 | printf('Value is %d\n', default_value) 7 | } 8 | } 9 | 10 | func main { 11 | _thing1 Thing() 12 | _thing2 Thing(11) 13 | _thing3 Thing = Thing() 14 | _thing4 Thing = Thing(11) 15 | _thing5 *Thing = new Thing() 16 | _thing6 *Thing = new Thing(11) 17 | delete _thing5 18 | delete _thing6 19 | } 20 | -------------------------------------------------------------------------------- /tests/e2e/src/continue/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | i usize = 0; while i != 10 { 6 | i += 1; if i == 3 or i == 6, continue 7 | printf('> %d\n', cast int i) 8 | } 9 | return 0 10 | } 11 | -------------------------------------------------------------------------------- /tests/e2e/src/continue_to/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | count_time, counter usize = 0 6 | 7 | // Will count from 1 to 10 for each even number in 0 to 3. 8 | // This isn't a very practical example of when you would use this, 9 | // but it showcases the feature well in little code, so whatever 10 | 11 | while outer : count_time != 4 { 12 | counter = 0; while inner : counter != 10 { 13 | if count_time % 2 == 0, count_time += 1; continue outer 14 | counter += 1 15 | printf('%d\n', counter) 16 | } 17 | count_time += 1 18 | } 19 | 20 | return 0 21 | } 22 | -------------------------------------------------------------------------------- /tests/e2e/src/default_args/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main { 5 | printf('%f %f %f\n', sum(), sum(10.0), sum(10.0, 11.0)) 6 | printf('%f %f %f\n', sumB(), sumB(10.0), sumB(10.0, 11.0)) 7 | printf('%f %f %f\n', sumC(), sumC(10.0), sumC(10.0, 11.0)) 8 | 9 | my_struct MyStruct 10 | printf('%f\n', my_struct.getValue()) 11 | } 12 | 13 | struct MyStruct () { 14 | func getValue(value double = 3.14159265) double = value 15 | } 16 | 17 | func sum(a double = 0.0, b double = 0.0, c double = 0.0) double { 18 | return a + b + c 19 | } 20 | 21 | func sumB(a, b, c double = 0.0) double { 22 | return a + b + c 23 | } 24 | 25 | func sumC(a = 1.0, b = 2.0, c double = 3.0) double { 26 | return a + b + c 27 | } 28 | -------------------------------------------------------------------------------- /tests/e2e/src/defer/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | puts('Defering statements...') 6 | defer puts('defer 1') 7 | defer puts('defer 2') 8 | defer puts('defer 3') 9 | return 0 10 | } 11 | -------------------------------------------------------------------------------- /tests/e2e/src/defer_auto_noop/main.adept: -------------------------------------------------------------------------------- 1 | 2 | struct Test () 3 | 4 | func main { 5 | test POD Test 6 | 7 | // Even though Test.__defer__() does not exist (won't be auto-generated since it's unnecessary), 8 | // trying to call it will be ignored, for backwards compatibility reasons 9 | test.__defer__() 10 | } 11 | -------------------------------------------------------------------------------- /tests/e2e/src/defer_global/main.adept: -------------------------------------------------------------------------------- 1 | 2 | #default test_global_list_of_strings true 3 | 4 | import 'sys/cstdio.adept' 5 | 6 | struct Test () { 7 | func __defer__ { 8 | printf('Test.__defer__() called!\n') 9 | } 10 | } 11 | 12 | #if test_global_list_of_strings 13 | #set log_string_deletion true 14 | import '2.2/basics.adept' 15 | list List 16 | #end 17 | 18 | test1 Test 19 | test2 POD Test 20 | 21 | func main { 22 | #if test_global_list_of_strings 23 | list.add(scan("Enter first item: ")) 24 | list.add(scan("Enter second item: ")) 25 | list.add(scan("Enter third item: ")) 26 | #end 27 | 28 | // 'test1.__defer__()' should be called but not 'test2.__defer__()' 29 | // 'list.__defer__()' should be called and string deletion should be logged for each entry in the list 30 | } 31 | -------------------------------------------------------------------------------- /tests/e2e/src/deprecated/main.adept: -------------------------------------------------------------------------------- 1 | 2 | // With no deprecation message 3 | pragma deprecated 4 | 5 | // With deprecation message 6 | pragma deprecated 'Use \'newer/better/undeprecated.adept\' instead' 7 | 8 | func main(in argc int, in argv **ubyte) int { 9 | return 0 10 | } 11 | -------------------------------------------------------------------------------- /tests/e2e/src/dereference/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | import 'sys/cstdlib.adept' 4 | 5 | func main(in argc int, in argv **ubyte) int { 6 | printf('First argument of program is: "%s"\n', *argv) 7 | 8 | my_string *ubyte = malloc(1) 9 | *my_string = 0 10 | printf('Empty string my_string has contents: "%s"\n') 11 | free(my_string) 12 | return 0 13 | } 14 | -------------------------------------------------------------------------------- /tests/e2e/src/disallow/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | import basics 4 | 5 | struct Thing () { 6 | func print(value String) { 7 | print(value) 8 | } 9 | 10 | func print(value int) = delete { 11 | print(value) 12 | } 13 | 14 | func print(value double) = delete 15 | } 16 | 17 | func main { 18 | thing Thing 19 | thing.print("Hello World") 20 | thing.print(1234) 21 | thing.print(3.14159) 22 | } 23 | -------------------------------------------------------------------------------- /tests/e2e/src/disallow_assignment/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | import basics 4 | 5 | struct Thing () { 6 | func __assign__(other Thing) = delete 7 | } 8 | 9 | func main { 10 | a, b Thing 11 | a = b 12 | } 13 | -------------------------------------------------------------------------------- /tests/e2e/src/disallow_assignment_container/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | import basics 4 | 5 | struct Thing () { 6 | func __assign__(other Thing) = delete 7 | } 8 | 9 | struct ThingContainer (thing Thing) 10 | 11 | func main { 12 | a, b ThingContainer 13 | a = b 14 | } 15 | -------------------------------------------------------------------------------- /tests/e2e/src/disallow_funcaddr/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | import basics 4 | 5 | func main { 6 | function_pointer func(int) int = func &disallowedFunction 7 | print(function_pointer) 8 | print(function_pointer(10)) 9 | } 10 | 11 | func disallowedFunction(value int) int = delete { 12 | return value * value 13 | } 14 | -------------------------------------------------------------------------------- /tests/e2e/src/disallow_poly/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | import basics 4 | 5 | func main { 6 | testWithoutBody(10) 7 | testWithBody(10) 8 | } 9 | 10 | func testWithoutBody(value $T) = delete 11 | 12 | func testWithBody(value $T) = delete { 13 | print(value) 14 | } 15 | -------------------------------------------------------------------------------- /tests/e2e/src/dropped_values/main.adept: -------------------------------------------------------------------------------- 1 | 2 | #set log_string_deletion true 3 | 4 | import '2.3/basics.adept' 5 | 6 | struct Bomb () { 7 | func __defer__ { 8 | printf('Bomb dropped!\n') 9 | } 10 | 11 | func dropAgain Bomb { 12 | return *this 13 | } 14 | } 15 | 16 | func main { 17 | // Value of type 'Bomb' ignored and __defer__ is called 18 | accidentlyDropBomb() 19 | 20 | // "Shelton".clone() is destroyed 21 | // The string that "Isaac ".clone() becomes, which is "Isaac Shelton" is destroyed 22 | // "Isaac ".clone() is never destroyed because it becomes "Isaac Shelton" 23 | "Isaac ".clone().append("Shelton".clone()) 24 | 25 | // Each returned value of 'Bomb' has __defer__ called on it because none are stored in a variable 26 | (accidentlyDropBomb()).dropAgain().dropAgain() 27 | } 28 | 29 | func accidentlyDropBomb Bomb { 30 | bomb POD Bomb 31 | return bomb 32 | } 33 | -------------------------------------------------------------------------------- /tests/e2e/src/dylib/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma dylib my_main_init my_main_deinit 3 | pragma ignore_unused 4 | 5 | import basics 6 | 7 | // -------------------------------------- 8 | 9 | struct Logger (name String) { 10 | constructor(name String) { 11 | this.name = name.commit() 12 | printf("[LOGGER %S] Created\n", this.name) 13 | } 14 | 15 | func __defer__ { 16 | printf("[LOGGER %S] Destroyed\n", this.name) 17 | } 18 | } 19 | 20 | // -------------------------------------- 21 | 22 | global_variable_logger Logger = Logger("global variable") 23 | 24 | external func my_main_init(){ 25 | print("Initialize called") 26 | 27 | static static_variable_logger Logger = Logger("static variable") 28 | } 29 | 30 | external func my_main_print(message *ubyte){ 31 | printf("[MY_MAIN] %s\n", message) 32 | } 33 | 34 | external func my_main_deinit(){ 35 | print("Deinitialize called") 36 | } 37 | -------------------------------------------------------------------------------- /tests/e2e/src/dylib/usage.adept: -------------------------------------------------------------------------------- 1 | 2 | #if __windows__ 3 | foreign "main.dll" 4 | #elif __macos__ 5 | foreign "main.dylib" 6 | #else 7 | foreign "main.so" 8 | #end 9 | 10 | foreign my_main_init() void 11 | foreign my_main_deinit() void 12 | foreign my_main_print(message *ubyte) void 13 | 14 | func main { 15 | my_main_init() 16 | my_main_print('Hello World') 17 | my_main_print('Bye World') 18 | my_main_deinit() 19 | } 20 | -------------------------------------------------------------------------------- /tests/e2e/src/each_in/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | import 'sys/cstring.adept' 4 | 5 | func main(in argc int, in argv **ubyte) int { 6 | names **ubyte; length usize 7 | 8 | requestNames(&names, &length) 9 | defer freeNames(names, length) 10 | 11 | printNames(names, length) 12 | 13 | jamesify(names, length) 14 | 15 | printNames(names,length) 16 | 17 | return 0 18 | } 19 | 20 | func requestNames(out names ***ubyte, out length *usize) void { 21 | *names = new *ubyte * 4 22 | (*names)[0] = 'Isaac' 23 | (*names)[1] = 'John' 24 | (*names)[2] = 'Peter' 25 | (*names)[3] = 'Luke' 26 | 27 | *length = 4 28 | } 29 | 30 | func freeNames(in names **ubyte, in length usize) void { 31 | each *ubyte in [names, length], free(it) 32 | } 33 | 34 | func jamesify(out names **ubyte, in length usize) void { 35 | each *ubyte in [names, length], it = 'James' 36 | } 37 | 38 | func printNames(in names **ubyte, in length usize) void { 39 | each name *ubyte in [names, length] { 40 | printf('names[%d] = %s\n', idx as int, name) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/e2e/src/each_in_fixed/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma compiler_version '2.3' 3 | import 'sys/cstdio.adept' 4 | 5 | func main { 6 | my_ints 10 int 7 | each int in my_ints { 8 | it = idx * idx 9 | } 10 | each int in my_ints { 11 | printf('%d => %d\n', idx, it) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/e2e/src/each_in_list/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main { 5 | my_list MyList = createList() 6 | 7 | each *ubyte in my_list { 8 | if idx == 2, my_list.change() 9 | printf('=> %s\n', it) 10 | } 11 | } 12 | 13 | struct MyList (list **ubyte, length usize) { 14 | func __defer__ { 15 | delete this.list 16 | } 17 | 18 | func change { 19 | this.__defer__() 20 | this.list = new *ubyte * 5 21 | this.length = 5 22 | this.list[0] = 'Apple' 23 | this.list[1] = 'Banana' 24 | this.list[2] = 'Peach' 25 | this.list[3] = 'Orange' 26 | this.list[4] = 'Carrot' 27 | } 28 | 29 | func __array__ **ubyte = this.list 30 | func __length__ usize = this.length 31 | } 32 | 33 | func createList() MyList { 34 | list POD MyList 35 | list.list = new *ubyte * 4 36 | list.length = 4 37 | list.list[0] = 'Apple' 38 | list.list[1] = 'Banana' 39 | list.list[2] = 'Peach' 40 | list.list[3] = 'Orange' 41 | return list 42 | } 43 | -------------------------------------------------------------------------------- /tests/e2e/src/either_way_multiply/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | // This program demonstrates how the compiler will automatically flip the arguments 5 | // to __multiply__ and other math overloads 6 | func __multiply__(_ String, b float) String { 7 | return toString(b) 8 | } 9 | 10 | func main { 11 | print("Hello World" * PI) 12 | print(PI * "Hello World") 13 | } 14 | -------------------------------------------------------------------------------- /tests/e2e/src/elif/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main { 5 | scan("Enter a number: ", def number int) 6 | 7 | if number == 1 { 8 | print("one") 9 | } elif number == 2 { 10 | print("two") 11 | } elif number == 3 { 12 | print("three") 13 | } elif number == 4 { 14 | print("four") 15 | } else { 16 | print("number is greater than four or less than one") 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/e2e/src/embed/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main { 5 | newline() 6 | print(embed 'test.txt') 7 | newline() 8 | } 9 | -------------------------------------------------------------------------------- /tests/e2e/src/embed/test.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, 2 | sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 3 | Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris 4 | nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit 5 | in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint 6 | occaecat cupidatat non proident, sunt in culpa qui officia deserunt 7 | mollit anim id est laborum. -------------------------------------------------------------------------------- /tests/e2e/src/entry_point/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma compiler_version '2.4' 3 | pragma entry_point myEntryPoint 4 | 5 | import basics 6 | 7 | func myEntryPoint(argc int, argv **ubyte) int { 8 | printf("%S\n", toString(argv, argc)) 9 | return 0 10 | } 11 | -------------------------------------------------------------------------------- /tests/e2e/src/enums/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | enum EyeColor (GREEN, BLUE, BROWN, HAZEL, OTHER, __length__) 5 | 6 | func main(in argc int, in argv **ubyte) int { 7 | eyecolor EyeColor = EyeColor::BLUE 8 | 9 | eyecolor = eyecolor as int as EyeColor 10 | 11 | names 5 *ubyte = undef 12 | names[0] = 'Green' 13 | names[1] = 'Blue' 14 | names[2] = 'Brown' 15 | names[3] = 'Hazel' 16 | names[4] = 'Other' 17 | 18 | printf('%s\n', names[eyecolor]) 19 | return 0 20 | } 21 | -------------------------------------------------------------------------------- /tests/e2e/src/enums_foreign/main.adept: -------------------------------------------------------------------------------- 1 | 2 | // Enums that are prefixed with 'foreign' will have 3 | // their values accessible without the EnumName:: prefix 4 | 5 | import 'sys/cstdio.adept' 6 | 7 | foreign enum Colors ( 8 | COLOR_RED, 9 | COLOR_GREEN, 10 | COLOR_BLUE 11 | ) 12 | 13 | func main { 14 | printf('%d\n', COLOR_RED as int) 15 | printf('%d\n', COLOR_GREEN as int) 16 | printf('%d\n', COLOR_BLUE as int) 17 | } 18 | -------------------------------------------------------------------------------- /tests/e2e/src/enums_relaxed_syntax/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | enum RelaxedEnum ( 5 | Entry1, 6 | Entry2, 7 | Entry3, 8 | Entry4, 9 | Entry5, 10 | ) 11 | 12 | func main { 13 | printEnum(null as *RelaxedEnum) 14 | printEnum(null as *enum(A, B, C, D, E, )) 15 | } 16 | 17 | func printEnum(_enum_type *$E~__flat_enum__) { 18 | ty *AnyEnumType = typeinfo $E as *AnyEnumType 19 | 20 | assert ty.kind == ::ENUM 21 | 22 | each member *ubyte in static [ty.members, ty.length] { 23 | printf(" - %s\n", member) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/e2e/src/equals_func/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | import '2.1/basics.adept' 4 | 5 | func main { 6 | test1, test2 Test 7 | if test1 == test2, print("test1 == test2") 8 | } 9 | 10 | struct Test () 11 | 12 | func __equals__(first Test, second Test) bool { 13 | return true 14 | } 15 | -------------------------------------------------------------------------------- /tests/e2e/src/external/main.adept: -------------------------------------------------------------------------------- 1 | 2 | #if __macos__ 3 | // THE MAC LIBC IMPLEMENTATION USES 4 | external __stdoutp *FILE 5 | stdout == __stdoutp 6 | 7 | struct FILE (_opaque 32 usize) 8 | #elif __windows__ 9 | #print_error "Windows doesn't have external stdout global" 10 | #done 11 | #else 12 | // SOME LIBC IMPLEMENTATIONS SUCH AS GLIBC USE 13 | external stdout *FILE 14 | struct FILE (_opaque 32 usize) 15 | #end 16 | 17 | foreign fprintf(*FILE, *ubyte, ...) int 18 | foreign printf(*ubyte, ...) int 19 | 20 | func main { 21 | fprintf(stdout, 'Hello World!\n') 22 | } 23 | -------------------------------------------------------------------------------- /tests/e2e/src/fallthrough/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/ctime.adept' 3 | import 'sys/cstdio.adept' 4 | import 'sys/cstdlib.adept' 5 | 6 | func main { 7 | srand(time(null)) 8 | 9 | switch 0 { 10 | case 0 11 | printf('zero\n') 12 | if rand() % 2 == 0, fallthrough 13 | case 1 14 | printf('one\n') 15 | if rand() % 2 == 0, fallthrough 16 | case 2 17 | printf('two\n') 18 | if rand() % 2 == 0, fallthrough 19 | case 3 20 | printf('three\n') 21 | if rand() % 2 == 0, fallthrough 22 | default 23 | printf('more\n') 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/e2e/src/fixed_array/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | import 'sys/cstring.adept' 4 | 5 | struct Human (name 256 ubyte, real *ubyte) 6 | 7 | func main(in argc int, in argv **ubyte) int { 8 | human Human 9 | memcpy(&human.name as *ubyte, 'Billy', 6) 10 | printf('human.name : %s\n', &human.name as *ubyte) 11 | 12 | buffer 512 ubyte 13 | message *ubyte = 'Hello World! This is a test message in a static buffer' 14 | memcpy(&buffer as *ubyte, message, strlen(message) + 1) 15 | printf('%s\n', &buffer as *ubyte) 16 | print512ubyte(getHelloWorldAgain()) 17 | return 0 18 | } 19 | 20 | func getHelloWorldAgain() 512 ubyte { 21 | buf 512 ubyte = undef 22 | msg *ubyte = 'Hello World Again!' 23 | memcpy(&buf as *ubyte, msg, strlen(msg) + 1) 24 | return buf 25 | } 26 | 27 | func print512ubyte(msg 512 ubyte) void { 28 | len usize = strlen(&msg as *ubyte) + 1 29 | repeat len, putchar(msg[idx]) 30 | putchar('\n'ub) 31 | } 32 | -------------------------------------------------------------------------------- /tests/e2e/src/fixed_array_alternative_syntax/main.adept: -------------------------------------------------------------------------------- 1 | 2 | #pragma default_stdlib '2.5' 3 | #import 4 | 5 | main :: func { 6 | array : [5] int = {0, 1, 2, 3, 4} 7 | print(array) 8 | zeroize(&array) 9 | print(array) 10 | } 11 | 12 | func zeroize(array : *[$#N] int) : void { 13 | each int in *array, it = 0 14 | } 15 | -------------------------------------------------------------------------------- /tests/e2e/src/fixed_array_assign/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | import 'sys/cstring.adept' 4 | 5 | func main(in argc int, in argv **ubyte) int { 6 | original_name 6 ubyte 7 | copied_name 6 ubyte 8 | 9 | memcpy(&original_name as *ubyte, 'Isaac', 6) 10 | copied_name = original_name 11 | puts(&copied_name as *ubyte) 12 | return 0 13 | } 14 | -------------------------------------------------------------------------------- /tests/e2e/src/fixed_array_deference/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma no_typeinfo 3 | #set log_string_deletion true 4 | 5 | import '2.3/basics.adept' 6 | 7 | func main { 8 | strings 10 String 9 | repeat 10, strings[idx] = "%" % cast int idx 10 | // __defer__() is called on each item of 'strings' before going out of scope 11 | } 12 | -------------------------------------------------------------------------------- /tests/e2e/src/fixed_array_var_size/main.adept: -------------------------------------------------------------------------------- 1 | 2 | // Examples of syntax disambiguation 3 | // pointers[10] * int 4 | // pointers[10] string 5 | // pointers[10] * string 6 | // pointers[10] 10 string 7 | // pointers [10] [10] string = getValue() 8 | // pointers [10] $T 9 | // pointers [10] $#T int 10 | // pointers [10] <$T> string 11 | // pointers [$#N] $T 12 | // pointers [10] func() void 13 | // pointers [10] stdcall func() void 14 | // pointers [10] packed struct() 15 | // pointers [10] struct() 16 | // pointers [10] union() 17 | // strings [10] String 18 | 19 | import basics 20 | 21 | func main { 22 | define num_integers = 2 * half_size 23 | define half_size = 10 24 | 25 | integers [num_integers] int 26 | 27 | // Set each element to its index plus one, squared 28 | each int in integers, it = sq(idx + 1) 29 | 30 | // Print out result 31 | header String = sprintf("---------- %d..%d squared ----------", 1, num_integers) 32 | print(header, toString(integers), "-" * header.length) 33 | } 34 | 35 | func sq(value $T~__number__) $T = value * value 36 | -------------------------------------------------------------------------------- /tests/e2e/src/fixed_array_var_size_field/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | define NUM_ITEMS = 10 5 | 6 | struct ItemHolder ( 7 | items [NUM_ITEMS] int 8 | ) { 9 | func fibonacci { 10 | items *int = this.items at 0 11 | 12 | items[0] = 1 13 | items[1] = 1 14 | 15 | repeat static NUM_ITEMS < 2 ? 0 : NUM_ITEMS - 2 { 16 | items[idx + 2] = items[idx] + items[idx + 1] 17 | } 18 | } 19 | } 20 | 21 | func toString(item_holder POD ItemHolder) String { 22 | return toString(item_holder.items) 23 | } 24 | 25 | func main { 26 | item_holder ItemHolder 27 | item_holder.fibonacci() 28 | print(item_holder) 29 | } 30 | -------------------------------------------------------------------------------- /tests/e2e/src/for/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main { 5 | // More traditional version 6 | for(i int = 0; i < 10; i++){ 7 | printf("%d ", i) 8 | } 9 | newline() 10 | 11 | // More traditional version, Single Line 12 | for(i int = 0; i < 10; i++), printf("%d ", i) 13 | newline() 14 | 15 | // Without parentheses 16 | for i int = 0; i < 10; i++ { 17 | printf("%d ", i) 18 | } 19 | 20 | // Without parentheses, Single Line 21 | for i int = 0; i < 10; i++, printf("%d ", i) 22 | newline() 23 | } 24 | -------------------------------------------------------------------------------- /tests/e2e/src/foreign_func_optional_names/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma libm 3 | 4 | // Examples of malformed foreign function declarations (where argument/types are ambiguous) 5 | #if false 6 | foreign calloc(usize, num usize) ptr // Error - 'usize' is ambiguous, did you mean 'usize Type' or '_ usize'? 7 | foreign atan2f(y, x float) float // Error - 'y' is ambiguous, did you mean 'y Type' (as a parameter name) or '_ y' (as a type name)? 8 | #end 9 | 10 | foreign atan2(y double, x double) double 11 | foreign atan2f(float, float) float 12 | foreign printf(format *ubyte, ...) int 13 | foreign free(ptr) void 14 | foreign malloc(size usize) ptr 15 | 16 | func main { 17 | x *int = malloc(sizeof int) 18 | defer free(x) 19 | 20 | *x = 123 21 | printf('Hello World %f %f %d\n', atan2(1.0, 1.0), cast double atan2f(-1.0f, -1.0f), *x) 22 | } 23 | -------------------------------------------------------------------------------- /tests/e2e/src/foreign_in_namespace/main.adept: -------------------------------------------------------------------------------- 1 | 2 | namespace libc { 3 | foreign printf(*ubyte, ...) int 4 | } 5 | 6 | func main { 7 | libc\printf('Hello World!\n') 8 | } 9 | -------------------------------------------------------------------------------- /tests/e2e/src/func_aliases/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func alias echo() => newline 5 | func alias echo(String) => print 6 | 7 | func main { 8 | echo("Hello World") 9 | echo() 10 | echo("This is a test") 11 | echo(myFunc(1, 2, 3)) 12 | } 13 | 14 | func echo(value int){ 15 | print("Function echo: " + toString(value).reversed()) 16 | } 17 | 18 | func alias myFunc => myFunction 19 | 20 | func myFunction(a, b, c int) int { 21 | return a + b + c 22 | } 23 | -------------------------------------------------------------------------------- /tests/e2e/src/func_aliases_va/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func alias strictPrintf(*ubyte, ...) => printf 5 | func alias newPrintf(String, ..) => printf 6 | 7 | func main { 8 | strictPrintf('Hello %s!\n', 'World') 9 | newPrintf("Hello %S!\n", "World") 10 | } 11 | -------------------------------------------------------------------------------- /tests/e2e/src/funcaddr/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cmath.adept' 3 | import "sys/cstdio.adept" 4 | 5 | func main(in argc int, in argv **ubyte) int { 6 | int_operation func(int, int) int 7 | double_operation func(double, double) double 8 | myprint func(*ubyte, ...) int = func &printf(*ubyte) 9 | 10 | int_operation = func &math(int, int) 11 | myprint('>>> 8 + 13 = %d\n', int_operation(8, 13)) 12 | 13 | double_operation = func &math(double, double) 14 | myprint('>>> 8 * 13 = %f\n', double_operation(8.0, 13.0)) 15 | return 0 16 | } 17 | 18 | func math(in a int, in b int) int { 19 | printf('[Sum Version was Called]\n') 20 | return a + b 21 | } 22 | 23 | func math(in a double, in b double) double { 24 | printf('[Product Version was Called]\n') 25 | return a * b 26 | } 27 | -------------------------------------------------------------------------------- /tests/e2e/src/funcaddr_autogen/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | struct RequiresDefer () { 5 | func __defer__ {} 6 | } 7 | 8 | struct ThingWithoutDefer () 9 | struct ThingWithDefer (value RequiresDefer) 10 | 11 | func main { 12 | // __defer__ functions will automatically be generated if referenced from a 'func &' expression 13 | printf(' ThingWithDefer.__defer__() => %p\n', func null &__defer__(*ThingWithDefer)) 14 | printf('ThingWithoutDefer.__defer__() => %p\n', func null &__defer__(*ThingWithoutDefer)) 15 | printf(' __defer__(*int) => %p\n', func null &__defer__(*int)) 16 | } 17 | -------------------------------------------------------------------------------- /tests/e2e/src/funcaddr_autogen_noop_defer/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | struct ThingWith (firstname, lastname String) 5 | struct ThingWithout (firstname, lastname int) 6 | 7 | func main { 8 | // For backwards compatibility reasons, 9 | // 'func &__defer__(*Type)' will return no-op function if it doesn't exist. 10 | // (Doesn't apply to 'func null &__defer__(*Type)', where null will be returned instead) 11 | printf("%p = noop __defer__ function\n", func &__defer__(*ptr) as ptr) 12 | printf("%p = ThingWith.__defer__\n", cast ptr func &__defer__(*ThingWith)) 13 | printf("%p = ThingWithout.__defer__\n", cast ptr func &__defer__(*ThingWithout)) 14 | printf("%p = ThingWith.__defer__ or null\n", cast ptr func null &__defer__(*ThingWith)) 15 | printf("%p = ThingWithout.__defer__ or null\n", cast ptr func null &__defer__(*ThingWithout)) 16 | } 17 | -------------------------------------------------------------------------------- /tests/e2e/src/funcaddrnull/main.adept: -------------------------------------------------------------------------------- 1 | 2 | #default define_f false 3 | import 'sys/cstdio.adept' 4 | 5 | func main { 6 | function_address func() void = func null &f 7 | 8 | #if define_f 9 | printf('%p should not be null because the function f() does exist\n', function_address) 10 | #else 11 | printf('%p should be null because the function f() does not exist\n', function_address) 12 | #end 13 | } 14 | 15 | #if define_f 16 | func f {} 17 | #end 18 | -------------------------------------------------------------------------------- /tests/e2e/src/funcptr/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cmath.adept' 3 | import "sys/cstdio.adept" 4 | 5 | func main(in argc int, in argv **ubyte) int { 6 | math_operation func(int, int) int 7 | myprint func(*ubyte, ...) int = func &printf 8 | 9 | math_operation = func &sum 10 | myprint('>>> 8 + 13 = %d\n', math_operation(8, 13)) 11 | math_operation(8, 13) 12 | 13 | math_operation = func &product 14 | myprint('>>> 8 * 13 = %d\n', math_operation(8, 13)) 15 | math_operation(8, 13) 16 | 17 | if !math_operation || math_operation == null || !(math_operation && math_operation) { 18 | printf('math_operation is null\n') 19 | } else { 20 | printf('math_operation exists\n') 21 | } 22 | 23 | return 0 24 | } 25 | 26 | func sum(in a int, in b int) int { 27 | printf('sum was called\n') 28 | return a + b 29 | } 30 | 31 | func product(in a int, in b int) int { 32 | printf('product was called\n') 33 | return a * b 34 | } 35 | -------------------------------------------------------------------------------- /tests/e2e/src/functions/main.adept: -------------------------------------------------------------------------------- 1 | 2 | foreign puts(*ubyte) int 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | say('Hello World from function call!') 6 | return sum(13, 8) 7 | } 8 | 9 | func say(in message *ubyte) void { 10 | puts(message) 11 | } 12 | 13 | func sum(in a int, in b int) int { 14 | return a + b 15 | } 16 | -------------------------------------------------------------------------------- /tests/e2e/src/globals/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | import 'sys/cstdlib.adept' 4 | 5 | counter int = 1 6 | 7 | func main(in argc int, in argv **ubyte) int { 8 | increase_counter() 9 | increase_counter() 10 | printf('counter = %d\n', counter) 11 | return 0 12 | } 13 | 14 | func increase_counter() void { 15 | counter += 5 16 | } 17 | -------------------------------------------------------------------------------- /tests/e2e/src/hello_world/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import "sys/cstdio.adept" 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | printf('Hello World!\n') 6 | return 0 7 | } 8 | -------------------------------------------------------------------------------- /tests/e2e/src/hexadecimal/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | import 'sys/cstdlib.adept' 4 | 5 | func main(in argc int, in argv **ubyte) int { 6 | printf('0xC0DEBEEF = %d\n', 0xC0DEBEEF) 7 | printf('0x000000FF = %d\n', 0x000000FF) 8 | printf('0x00000FFF = %d\n', 0x00000FFF) 9 | printf('0x0000FFFF = %d\n', 0x0000FFFF) 10 | return 0 11 | } 12 | -------------------------------------------------------------------------------- /tests/e2e/src/idx_manipulation/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | import 'sys/cstdlib.adept' 4 | 5 | func main { 6 | repeat 9, printf('%d ', idx as int); idx += 1 7 | printf('\n') 8 | 9 | letters *ubyte = 'abcdefghijklmnopqrstuvwxyz' 10 | each ubyte in [letters, 26], printf('%c', it); idx += 2 11 | printf('\n') 12 | } 13 | -------------------------------------------------------------------------------- /tests/e2e/src/if/main.adept: -------------------------------------------------------------------------------- 1 | 2 | foreign puts(*ubyte) int 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | if argc == 1 { 6 | puts('No arguments specified') 7 | } 8 | 9 | if argc != 1 { 10 | puts('Arguments specified') 11 | } 12 | 13 | return 0 14 | } 15 | -------------------------------------------------------------------------------- /tests/e2e/src/ifelse/main.adept: -------------------------------------------------------------------------------- 1 | 2 | foreign puts(*ubyte) int 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | if argc == 1 { 6 | puts('No arguments specified') 7 | } else { 8 | puts('Arguments specified') 9 | } 10 | return 0 11 | } 12 | -------------------------------------------------------------------------------- /tests/e2e/src/import/hello.adept: -------------------------------------------------------------------------------- 1 | 2 | foreign puts(*ubyte) int 3 | 4 | func hello_world() void { 5 | puts('Hello World!') 6 | } 7 | -------------------------------------------------------------------------------- /tests/e2e/src/import/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import "hello.adept" 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | hello_world() 6 | return 0 7 | } 8 | -------------------------------------------------------------------------------- /tests/e2e/src/import_std/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma default_stdlib '2.3' 3 | 4 | import basics 5 | import "other.adept" 6 | 7 | func main { 8 | print("Hello World") 9 | } 10 | -------------------------------------------------------------------------------- /tests/e2e/src/import_std/other.adept: -------------------------------------------------------------------------------- 1 | 2 | import string_manipulation 3 | -------------------------------------------------------------------------------- /tests/e2e/src/import_std_c_like/main.adept: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | 4 | func main { 5 | print("Hello World") 6 | } 7 | -------------------------------------------------------------------------------- /tests/e2e/src/increment/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main { 5 | x int = 0 6 | printf('%d %d %d %d\n', x++, x--, ++x, --x) 7 | } 8 | -------------------------------------------------------------------------------- /tests/e2e/src/increment_stmt/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main { 5 | x int = 0 6 | x++ 7 | x-- 8 | ++x 9 | --x 10 | x++ 11 | x-- 12 | (*(&x))-- 13 | printf('%d\n', x) 14 | } 15 | -------------------------------------------------------------------------------- /tests/e2e/src/initializer_list/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main { 5 | my_integers List = {0, 1, 2, 3, 4, 5} 6 | my_matrix < List> List = {my_integers, my_integers, my_integers, my_integers} 7 | 8 | printMatrix(my_matrix) 9 | 10 | float_matrix < List> List = { 11 | {1.0f, 0.0f, 0.0f, 0.0f} as List, 12 | {0.0f, 1.0f, 0.0f, 0.0f}, 13 | {0.0f, 0.0f, 1.0f, 0.0f}, 14 | {0.0f, 0.0f, 0.0f, 1.0f} 15 | } 16 | 17 | printMatrix(float_matrix) 18 | } 19 | 20 | func printMatrix(matrix <<$T> List> List) { 21 | each list <$T> List in matrix { 22 | each item $T in list { 23 | place(item) 24 | place(" ") 25 | } 26 | newline() 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/e2e/src/initializer_list_fixed/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main { 5 | arr1d 10 int = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} 6 | 7 | arr2d 10 10 int = { 8 | {10, 9, 8, 7, 6, 5, 4, 3, 2, 1} as 10 int, 9 | {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, 10 | {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, 11 | {10, 9, 8, 7, 6, 5, 4, 3, 2, 1} 12 | } 13 | 14 | print(arr1d) 15 | print(arr2d) 16 | } 17 | -------------------------------------------------------------------------------- /tests/e2e/src/inline_declaration/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main { 5 | // NOTE: Obviously you should shouldn't use 'gets', but this is 6 | // a good example of the power this feature has 7 | 8 | printf('Enter some input: ') 9 | gets(undef input 256 ubyte as *ubyte) 10 | printf('Got input: %s\n', &input as *ubyte) 11 | } 12 | -------------------------------------------------------------------------------- /tests/e2e/src/inner_struct/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | struct Vec3 (x, y, z float) 5 | struct Vec4 (struct Vec3, w float) 6 | 7 | func main { 8 | v Vec4 9 | v.x = 1.0f 10 | v.y = 2.0f 11 | v.z = 3.0f 12 | v.w = 4.0f 13 | printf('%f %f %f %f\n', v.x as double, v.y as double, v.z as double, v.w as double) 14 | } 15 | -------------------------------------------------------------------------------- /tests/e2e/src/inner_struct_polymorphic/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | struct <$T> Vector2 (x, y $T) 5 | struct <$S> Vector3 (struct <$S> Vector2, z $S) 6 | struct <$K> Vector4 (struct <$K> Vector3, w $K) 7 | struct Vector4f (struct Vector4) 8 | 9 | func main { 10 | v2 Vector2 11 | v2.x = 1 12 | v2.y = 2 13 | 14 | v3 Vector3 15 | v3.x = 1.0 16 | v3.y = 2.0 17 | v3.z = 3.0 18 | 19 | v4 Vector4 20 | v4.x = 1.0f 21 | v4.y = 2.0f 22 | v4.z = 3.0f 23 | v4.w = 4.0f 24 | 25 | printf('%f %f %f %f\n', v4.x as double, v4.y as double, v4.z as double, v4.w as double) 26 | 27 | v4f Vector4f 28 | v4f.x = 10.0f 29 | v4f.y = 11.0f 30 | v4f.z = 12.0f 31 | v4f.w = 13.0f 32 | printf('%f %f %f %f\n', v4f.x as double, v4f.y as double, v4f.z as double, v4f.w as double) 33 | } 34 | -------------------------------------------------------------------------------- /tests/e2e/src/int_to_float_promotion_in_math/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main { 5 | x int = 3 6 | y double = 4 7 | 8 | print(x * y) 9 | } 10 | -------------------------------------------------------------------------------- /tests/e2e/src/internal_deference/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | 4 | struct Bomb () 5 | struct Gift (bomb1, bomb2, bomb3 Bomb) 6 | struct Present (gift Gift) 7 | 8 | foreign printf(*ubyte, ...) int 9 | 10 | func __defer__(this *Bomb) { 11 | printf('Kaboom!\n') 12 | } 13 | 14 | func main { 15 | present Present 16 | } 17 | -------------------------------------------------------------------------------- /tests/e2e/src/internal_deference_generic/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | 4 | struct Bomb () 5 | struct Gift (bomb1, bomb2, bomb3 Bomb) 6 | struct <$T> Present (contents $T) 7 | struct <$K, $V> Pair (key $K, value $V) 8 | 9 | foreign printf(*ubyte, ...) int 10 | 11 | func __defer__(this *Bomb) { 12 | printf('Kaboom!\n') 13 | } 14 | 15 | func __defer__(this *Gift) { 16 | printf('Destroying Gift...\n') 17 | } 18 | 19 | func __defer__(this *<$K, $V> Pair) { 20 | printf('Destroying <$K, $V> Pair\n') 21 | } 22 | 23 | func main { 24 | present Present 25 | bomb < Present> Present 26 | pair Pair 27 | } 28 | -------------------------------------------------------------------------------- /tests/e2e/src/list_map/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma compiler_version '2.7' 3 | 4 | import basics 5 | 6 | func main { 7 | strings List 8 | strings.add("1") 9 | strings.add("3") 10 | strings.add("5") 11 | strings.add("7") 12 | each String in strings, print("strings[%] = \"%\"" % idx % it) 13 | 14 | integers List = strings.map(func &toInt(String)) 15 | each int in integers, print("integers[%] = %" % idx % it) 16 | 17 | print("integers.contains(2) == %" % integers.contains(2)) 18 | print("integers.contains(3) == %" % integers.contains(3)) 19 | } 20 | -------------------------------------------------------------------------------- /tests/e2e/src/llvm_asm/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main { 5 | value int = 3 6 | result int = 0 7 | 8 | #if __x86_64__ 9 | llvm_asm att { 10 | "movl $1, $0" 11 | } "=*m,r,~{memory}" (&result, value) 12 | #else 13 | result = value 14 | #end 15 | 16 | printf("Result = %d\n", result) 17 | 18 | multiplied int = 0 19 | 20 | #if __x86_64__ 21 | llvm_asm att { 22 | "imull $1, $2" 23 | "movl $2, $0" 24 | } "=*m,r,r,~{memory}" (&multiplied, value, result) 25 | #else 26 | multiplied = value * result 27 | #end 28 | 29 | printf("Multiplied = %d\n", multiplied) 30 | } 31 | -------------------------------------------------------------------------------- /tests/e2e/src/major_minor_release/main.adept: -------------------------------------------------------------------------------- 1 | 2 | // ----------------------------------------------------------------------- 3 | 4 | #print "Compiler major version: " + __compiler_major__ 5 | #print "Compiler minor version: " + __compiler_minor__ 6 | #print "Compiler release version: " + __compiler_release__ 7 | #print "Compiler qualifier: " + __compiler_qualifier__ 8 | #print "Compiler version (now a number): " + __compiler_version__ 9 | #print "Compiler version name: " + __compiler_version_name__ 10 | #done 11 | 12 | // ----------------------------------------------------------------------- 13 | 14 | /* 15 | 16 | // Example of a backwards compatible way of getting specific compiler version info 17 | // (Only Adept 2.3 and 2.4 supported the necessary components for this to work though) 18 | 19 | // Test to see if __compiler_major__ already exists 20 | #default __compiler_major__ 0 21 | 22 | #if __compiler_major__ != 0 23 | // Compiler version specifics are available (Adept 2.5+) 24 | #else 25 | #set version 0 + __compiler__version__ 26 | #set __compiler_major__ 2 27 | #set __compiler_minor__ (version - 2.0) * 10 28 | #set __compiler_release__ 0 29 | #set __compiler_qualifier__ "" 30 | #end 31 | 32 | */ 33 | -------------------------------------------------------------------------------- /tests/e2e/src/management_access/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | import basics 4 | 5 | struct MyFakeList (value int) { 6 | func __access__(index usize) *int { 7 | return &this.value 8 | } 9 | } 10 | 11 | func myFakeList() MyFakeList { 12 | list MyFakeList 13 | list.value = 1234 14 | return list 15 | } 16 | 17 | 18 | struct MyDictionary (value1, value2 String) { 19 | func __access__(firstname String) *String { 20 | if this.value1.empty(), this.value1 = "Shelton" 21 | if this.value2.empty(), this.value2 = "Smith" 22 | 23 | // Ignore case 24 | firstname = firstname.lowercase() 25 | 26 | // Returns lastname for given firstname 27 | if firstname == "isaac", return &this.value1 28 | return &this.value2 29 | } 30 | } 31 | 32 | 33 | func main { 34 | list MyFakeList = myFakeList() 35 | 36 | // Since out __access__ operator ignores index, we can pass any index 37 | list[524352345] = 10 38 | printf('list[any value] = %d\n\n', list[45143523]) 39 | 40 | dictionary MyDictionary 41 | print("Isaac's lastname is %" % dictionary["Isaac"]) 42 | print("John's lastname is %" % dictionary["John"]) 43 | 44 | dictionary["John"] = "Johnson" 45 | print("John's new lastname is %" % dictionary["John"]) 46 | } 47 | -------------------------------------------------------------------------------- /tests/e2e/src/management_as/main.adept: -------------------------------------------------------------------------------- 1 | 2 | #define use_implicit_as true 3 | 4 | import basics 5 | 6 | func main { 7 | value_string String = "10" 8 | 9 | #if use_implicit_as 10 | value1 int = value_string 11 | value2 float = value_string 12 | value3 double = value_string 13 | #else 14 | value1 int = value_string as int 15 | value2 float = value_string as float 16 | value3 double = value_string as double 17 | #end 18 | 19 | print(value1) 20 | print(value2) 21 | print(value3) 22 | 23 | #if use_implicit_as 24 | print(sum("1234", "1234")) 25 | #else 26 | print(sum("1234" as int, "1234" as int)) 27 | #end 28 | } 29 | 30 | func sum(a, b int) int { 31 | return a + b 32 | } 33 | 34 | #if use_implicit_as 35 | // When using 'implicit', we won't have to manually cast 36 | 37 | implicit func __as__(string String) int = string.toInt() 38 | implicit func __as__(string String) float = string.toFloat() 39 | implicit func __as__(string String) double = string.toDouble() 40 | #else 41 | // When using regular version, we will have to manually cast 42 | 43 | func __as__(string String) int = string.toInt() 44 | func __as__(string String) float = string.toFloat() 45 | func __as__(string String) double = string.toDouble() 46 | #end 47 | -------------------------------------------------------------------------------- /tests/e2e/src/management_assign/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | import 'sys/cstdio.adept' 4 | 5 | struct Assigned (value int) 6 | 7 | func __assign__(this *Assigned, rhs POD Assigned) void { 8 | this.value = 12345 9 | } 10 | 11 | func main() void { 12 | x, y Assigned 13 | x = y 14 | printf('x.value = %d\ny.value = %d\n', x.value, y.value) 15 | 16 | y.value = 54321 17 | x = POD y 18 | printf('x.value = %d\ny.value = %d\n', x.value, y.value) 19 | } 20 | -------------------------------------------------------------------------------- /tests/e2e/src/management_defer/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | struct Scoped (name *ubyte) 5 | 6 | func __defer__(this *Scoped) void { 7 | // __defer__ method gets called whenever a variable 8 | // on the stack will become inaccessible 9 | 10 | printf('Scoped.__defer__ called on %s!\n', this.name) 11 | } 12 | 13 | func main() void { 14 | // Scoped.__defer__ should be called for every variable of 15 | // type 'Scoped' immediately before the variable is lost 16 | 17 | a, b, c Scoped 18 | a.name = 'a'; b.name = 'b'; c.name = 'c' 19 | 20 | while continue f { 21 | f Scoped 22 | f.name = 'f' 23 | repeat 100 { 24 | z Scoped 25 | z.name = 'z' 26 | if idx == 1, break f 27 | } 28 | } 29 | 30 | callRegular(a) 31 | callPOD(a) 32 | } 33 | 34 | func callRegular(x Scoped) void { 35 | x.name = 'x' 36 | } 37 | 38 | func callPOD(y POD Scoped) void { 39 | y.name = 'y' 40 | y.__defer__() 41 | } 42 | -------------------------------------------------------------------------------- /tests/e2e/src/mathassign/main.adept: -------------------------------------------------------------------------------- 1 | 2 | foreign puts(*ubyte) int 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | i int = 0 6 | i += 10 7 | i -= 2 8 | i *= 3 9 | i /= 8 10 | puts('Should exit with a value of 3') 11 | return i 12 | } 13 | -------------------------------------------------------------------------------- /tests/e2e/src/mathassign_managed/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | record MyInteger (value int) 5 | 6 | func toString(x MyInteger) String = toString(x.value) 7 | func __add__(a, b MyInteger) MyInteger = MyInteger(a.value + b.value) 8 | func __subtract__(a, b MyInteger) MyInteger = MyInteger(a.value - b.value) 9 | func __multiply__(a, b MyInteger) MyInteger = MyInteger(a.value * b.value) 10 | func __divide__(a, b MyInteger) MyInteger = MyInteger(a.value / b.value) 11 | 12 | func main { 13 | a MyInteger = MyInteger(10) 14 | b MyInteger = MyInteger(11) 15 | 16 | c MyInteger = a 17 | 18 | c += b // c == 21 19 | 20 | c += b // c == 32 21 | c -= b // c == 21 22 | 23 | c *= b // c == 231 24 | c /= b // c == 21 25 | 26 | print(c) 27 | } 28 | -------------------------------------------------------------------------------- /tests/e2e/src/member/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import "sys/cstdio.adept" 3 | import "sys/cstdlib.adept" 4 | 5 | struct Person (firstname *ubyte, age int, lastname *ubyte) 6 | 7 | func main(in argc int, in argv **ubyte) int { 8 | person Person 9 | person.firstname = 'Isaac' 10 | person.lastname = 'Shelton' 11 | person.age = 15 12 | printf('Person: %s, %s\n', person.firstname, person.lastname) 13 | 14 | anonymous *Person = malloc(24) 15 | anonymous.firstname = 'Unknown' 16 | anonymous.lastname = 'Unknown' 17 | anonymous.age = 0 18 | 19 | printf('Anonymous: %s, %s\n', anonymous.firstname, anonymous.lastname) 20 | free(anonymous) 21 | return 0 22 | } 23 | -------------------------------------------------------------------------------- /tests/e2e/src/meta_dynamic/main.adept: -------------------------------------------------------------------------------- 1 | 2 | // Static meta variables 3 | #print "__compiler__ = " + __compiler__ 4 | #print "__compiler_version__ = " + __compiler_version__ 5 | 6 | // Dynamic meta variables 7 | #print "__no_typeinfo__ = " + __no_typeinfo__ 8 | #print "__line__ = " + __line__ 9 | #print "__column__ = " + __column__ 10 | #print "__file__ = " + __file__ 11 | #print "__stdlib__ = " + __stdlib__ 12 | #done 13 | -------------------------------------------------------------------------------- /tests/e2e/src/meta_get/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import '2.3/basics.adept' 3 | 4 | #default name "Isaac Shelton" 5 | #default welcome_format "Welcome %!" 6 | #default nine 1 * 2 + 3 + 6 / 2 + 1 7 | #default pi 3.1415926535 8 | 9 | func main { 10 | print(#get welcome_format % #get name) 11 | print("9 == %" % #get nine) 12 | print("pi == %" % #get pi) 13 | } 14 | -------------------------------------------------------------------------------- /tests/e2e/src/methods/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | struct Person (name *ubyte, age int) 5 | 6 | func main(in argc int, in argv **ubyte) int { 7 | isaac Person 8 | isaac.set('Isaac', 15) 9 | isaac.print() 10 | printf('isaac.getAge() = %d\n', isaac.getAge()) 11 | 12 | josh *Person = malloc(sizeof Person) 13 | josh.set('Josh', 14) 14 | josh.print() 15 | free(josh) 16 | return 0 17 | } 18 | 19 | func set(this *Person, name *ubyte, age int) void { 20 | this.name = name 21 | this.age = age 22 | } 23 | 24 | func print(this *Person) void { 25 | printf('Person (name = "%s", age = %d)\n', this.name, this.age) 26 | } 27 | 28 | func getAge(this *Person) int { 29 | return this.age 30 | } 31 | -------------------------------------------------------------------------------- /tests/e2e/src/multiple_declaration/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | a, b int = 0 6 | printf('a = %d, b = %d\n', a, b) 7 | 8 | one, two, three, four int = 21 9 | printf('one = %d\n', one) 10 | printf('two = %d\n', two) 11 | printf('three = %d\n', three) 12 | printf('four = %d\n', four) 13 | return 0 14 | } 15 | -------------------------------------------------------------------------------- /tests/e2e/src/named_expressions/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | import 'sys/cstdlib.adept' 4 | 5 | define MY_NAMED_EXPRESSION = 7 * 3 6 | define APPLICATION_NAME = 'Named Expressions Example Program' 7 | define SOLVED_GENERIC_NAMED_EXPRESSION = 3 8 | 9 | func main(in argc int, in argv **ubyte) int { 10 | printf('MY_NAMED_EXPRESSION = %d\n', MY_NAMED_EXPRESSION) 11 | printf('APPLICATION_NAME = %s\n', APPLICATION_NAME) 12 | printf('3.1415d + SOLVED_GENERIC_NAMED_EXPRESSION = %f\n', 3.1415d + SOLVED_GENERIC_NAMED_EXPRESSION) 13 | return 0 14 | } 15 | -------------------------------------------------------------------------------- /tests/e2e/src/named_expressions_old_style/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | import 'sys/cstdlib.adept' 4 | 5 | MY_NAMED_EXPRESSION == 7 * 3 6 | APPLICATION_NAME == 'Named Expressions Example Program' 7 | SOLVED_GENERIC_NAMED_EXPRESSION == 3 8 | 9 | func main(in argc int, in argv **ubyte) int { 10 | printf('MY_NAMED_EXPRESSION = %d\n', MY_NAMED_EXPRESSION) 11 | printf('APPLICATION_NAME = %s\n', APPLICATION_NAME) 12 | printf('3.1415d + SOLVED_GENERIC_NAMED_EXPRESSION = %f\n', 3.1415d + SOLVED_GENERIC_NAMED_EXPRESSION) 13 | return 0 14 | } 15 | -------------------------------------------------------------------------------- /tests/e2e/src/named_expressions_scoped/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main { 5 | define MY_VALUE = 1.234567 6 | 7 | if true { 8 | define MY_VALUE = "Hello World" 9 | print(MY_VALUE) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/e2e/src/namespace_alternative_syntax/main.adept: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | #pragma ignore_unused 4 | 5 | io:printf :: func alias (String, ..) => printf 6 | io:printf :: func alias (*ubyte, ...) => printf 7 | 8 | main :: func { 9 | x : int = 0 10 | y: int = 0 11 | z :int = 0 12 | 13 | io:printf("Hello World!\n") 14 | } 15 | -------------------------------------------------------------------------------- /tests/e2e/src/namespaces/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | import basics 4 | 5 | // Some defintions inside of "things" namespace 6 | namespace things { 7 | struct XThing () 8 | union YThing () 9 | enum ZThing () 10 | alias AThing = things\XThing 11 | } 12 | 13 | // Some more stuff inside "things" namespace 14 | namespace things { 15 | func alias testCallingWithin => things\helloWrapper 16 | 17 | func helloWrapper { 18 | things\hello() 19 | } 20 | 21 | func hello { 22 | print("Hello World") 23 | } 24 | } 25 | 26 | // An additional function inside "things" namespace 27 | func things\testAdditionalThing(){ 28 | print("Bye World") 29 | } 30 | 31 | func main { 32 | things\testCallingWithin() 33 | 34 | x things\XThing 35 | y things\YThing 36 | z things\ZThing 37 | a things\AThing 38 | 39 | things\testAdditionalThing() 40 | } 41 | -------------------------------------------------------------------------------- /tests/e2e/src/native_linking_windows/glfw3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/tests/e2e/src/native_linking_windows/glfw3.dll -------------------------------------------------------------------------------- /tests/e2e/src/native_linking_windows/libgdi32.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/tests/e2e/src/native_linking_windows/libgdi32.a -------------------------------------------------------------------------------- /tests/e2e/src/native_linking_windows/libglfw3.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/tests/e2e/src/native_linking_windows/libglfw3.a -------------------------------------------------------------------------------- /tests/e2e/src/native_linking_windows/libopengl32.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/tests/e2e/src/native_linking_windows/libopengl32.a -------------------------------------------------------------------------------- /tests/e2e/src/native_linking_windows/opengl32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/tests/e2e/src/native_linking_windows/opengl32.dll -------------------------------------------------------------------------------- /tests/e2e/src/negate/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | x int = 412 6 | y int = -x 7 | printf(' x == %d\n', x) 8 | printf('-x == %d\n', y) 9 | return 0 10 | } 11 | -------------------------------------------------------------------------------- /tests/e2e/src/new_cstring/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | name *ubyte = new 'Hello World!' 6 | defer delete name 7 | 8 | puts(name) 9 | return 0 10 | } 11 | -------------------------------------------------------------------------------- /tests/e2e/src/new_delete/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | import 'sys/cstdlib.adept' 4 | 5 | struct Person (name *ubyte, age int) 6 | 7 | func main(in argc int, in argv **ubyte) int { 8 | isaac *Person = new Person 9 | defer delete isaac 10 | 11 | isaac.create('Isaac', 15) 12 | isaac.print() 13 | return 0 14 | } 15 | 16 | func create(this *Person, name *ubyte, age int) void { 17 | this.name = name 18 | this.age = age 19 | } 20 | 21 | func print(this *Person) void { 22 | printf('Person {%s, %d}\n', this.name, this.age) 23 | } 24 | -------------------------------------------------------------------------------- /tests/e2e/src/new_dynamic/main.adept: -------------------------------------------------------------------------------- 1 | 2 | // An example using the 'new Type * amount' syntax dynamically 3 | 4 | import 'sys/cstdio.adept' 5 | import 'sys/cstdlib.adept' 6 | import 'sys/cstring.adept' 7 | 8 | func main(in argc int, in argv **ubyte) int { 9 | args_string *ubyte = argumentsString(argc, argv) 10 | defer delete args_string 11 | 12 | puts(args_string) 13 | return 0 14 | } 15 | 16 | func argumentsString(in argc int, in argv **ubyte) *ubyte { 17 | index usize = 0 18 | total_length usize = argumentsStringLength(argc, argv) 19 | str *ubyte = new ubyte * total_length 20 | 21 | i int = 0; while i != argc { 22 | memcpy(&str[index], argv[i], strlen(argv[i])) 23 | index += strlen(argv[i]) 24 | 25 | if i + 1 == argc, str[index] = 0x00; return str 26 | else str[index] = ' 'ub; index += 1 27 | 28 | i += 1 29 | } 30 | return str 31 | } 32 | 33 | func argumentsStringLength(in argc int, in argv **ubyte) usize { 34 | i int = 0; total usize = 0 35 | while i != argc, total += strlen(argv[i]) + 1; i += 1 36 | return total 37 | } 38 | -------------------------------------------------------------------------------- /tests/e2e/src/new_undef/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import '2.1/basics.adept' 3 | 4 | func main { 5 | undefined_integers *int = new undef int * 10 6 | repeat 10, print("[%] : %" % idx % undefined_integers[idx]) 7 | } 8 | -------------------------------------------------------------------------------- /tests/e2e/src/newline_tolerance/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | struct Dummy () { 5 | func withMethod(format, s1, s2 *ubyte, c ubyte) { 6 | printf(format, s1, s2, c) 7 | } 8 | } 9 | 10 | func main { 11 | printf( 12 | '%s %s%c\n' 13 | , 14 | 'Hello' 15 | , 'World', 16 | '!'ub 17 | ) 18 | 19 | dummy Dummy 20 | dummy.withMethod( 21 | '%s %s%c\n' 22 | , 23 | 'Hi' 24 | , 'World', 25 | '!'ub 26 | ) 27 | 28 | printf('%d\n', 123 29 | + 1 * 30 | 1234 / 2 31 | - 43 32 | ) 33 | 34 | x int = ( 35 | 123 36 | + 1 * 37 | 1234 / 2 38 | - 43 + 1 39 | ) 40 | 41 | printf('%d\n', x) 42 | 43 | printf('%d\n', cast int 44 | ( 45 | 123ul 46 | + 1ul * 47 | 1234ul / 2ul 48 | - 43ul + 2ul 49 | ) 50 | ) 51 | } 52 | -------------------------------------------------------------------------------- /tests/e2e/src/no_discard/main.adept: -------------------------------------------------------------------------------- 1 | 2 | // These values can be changed to simulate 3 | // different scenerios where exhuastive return values 4 | // are allowed or disallowed 5 | #default methods true 6 | #default neglect true 7 | 8 | import basics 9 | 10 | func main { 11 | #if methods 12 | thing Thing 13 | 14 | #if neglect 15 | // Will cause a compile-time error, since 16 | // we are not allowed to ignore an "exhaustive" return value 17 | thing.getMessage() 18 | #else 19 | print(thing.getMessage()) 20 | #end 21 | #else 22 | #if neglect 23 | // Will cause a compile-time error, since 24 | // we are not allowed to ignore an "exhaustive" return value 25 | getMessage() 26 | #else 27 | print(getMessage()) 28 | #end 29 | #end 30 | } 31 | 32 | struct Thing () 33 | 34 | func getMessage() exhaustive String { 35 | return "Hello World" 36 | } 37 | 38 | func getMessage(this *Thing) exhaustive String { 39 | return "Hello World" 40 | } 41 | -------------------------------------------------------------------------------- /tests/e2e/src/not/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | if !true, puts('!true') 6 | if !false, puts('!false') 7 | if !3, puts('!3') 8 | if !2, puts('!2') 9 | if !1, puts('!1') 10 | if !0, puts('!0') 11 | if !3.0f, puts('!3.0f') 12 | if !2.0f, puts('!2.0f') 13 | if !1.0f, puts('!1.0f') 14 | if !0.0f, puts('!0.0f') 15 | return 0 16 | } 17 | -------------------------------------------------------------------------------- /tests/e2e/src/null/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | import 'sys/cstdio.adept' 4 | import 'sys/cstdlib.adept' 5 | 6 | func main(in argc int, in argv **ubyte) int { 7 | value1 ptr = null 8 | value2 *int = null 9 | value3 **int = null 10 | return 0 11 | } 12 | -------------------------------------------------------------------------------- /tests/e2e/src/null_checks/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | triggerNullCheck(null) 6 | return 0 7 | } 8 | 9 | func triggerNullCheck(out value *int) void { 10 | *value = 1234567 11 | } 12 | -------------------------------------------------------------------------------- /tests/e2e/src/numeric_separators/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main { 5 | print(123_456_789) 6 | } 7 | -------------------------------------------------------------------------------- /tests/e2e/src/order/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | import 'sys/cstdio.adept' 4 | import 'sys/cstdlib.adept' 5 | 6 | func main(in argc int, in argv **ubyte) int { 7 | first() 8 | printf('sum(8, 13) = %d\n', sum(8, 13)) 9 | return 0 10 | } 11 | 12 | func first() void { 13 | printf('This function was declared first\n') 14 | } 15 | 16 | func first() void { 17 | printf('This function was declared second\n') 18 | } 19 | 20 | func sum(a ptr, b ptr) int { 21 | printf('sum(ptr, ptr) was called\n') 22 | return 0 23 | } 24 | 25 | func sum(a int, b int) int { 26 | printf('sum(int, int) was called\n') 27 | return a + b 28 | } 29 | -------------------------------------------------------------------------------- /tests/e2e/src/pass_func/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | struct Something (value int) 5 | struct <$T> Container (value $T) 6 | 7 | func main { 8 | something Something 9 | container Container 10 | printSomething(something) 11 | printContainer(container) 12 | } 13 | 14 | func printSomething(something Something) { 15 | printf('something.value = %d\n', something.value) 16 | } 17 | 18 | func printContainer(container <$T> Container) { 19 | // Assume $T is double for testing purposes 20 | printf('container.value = %f\n', container.value) 21 | } 22 | 23 | func __pass__(something POD Something) Something { 24 | something.value = 1234 25 | return something 26 | } 27 | 28 | func __pass__(container POD <$T> Container) <$T> Container { 29 | container.value = 3.14159265 30 | return container 31 | } 32 | -------------------------------------------------------------------------------- /tests/e2e/src/permissive_blocks/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main { 5 | name String = "Isaac Shelton" 6 | 7 | if name.startsWith("Isaac") print(name) 8 | while name.endsWith("Shelton") name = "" 9 | until name.length > 10 name.append(toString(name.length)) 10 | print(name) 11 | } 12 | -------------------------------------------------------------------------------- /tests/e2e/src/poly_default_args/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main(argc int, argv **ubyte) { 5 | print(Array(argv, argc)) 6 | } 7 | -------------------------------------------------------------------------------- /tests/e2e/src/poly_prereq_extends/main.adept: -------------------------------------------------------------------------------- 1 | 2 | #default make_compilation_fail false 3 | 4 | import basics 5 | 6 | class Shape { 7 | constructor {} 8 | } 9 | 10 | class Rectangle extends Shape (w, h float) { 11 | constructor {} 12 | } 13 | 14 | class Circle extends Shape (r float) { 15 | constructor {} 16 | } 17 | 18 | func main { 19 | shape Shape() 20 | rectangle Rectangle() 21 | circle Circle() 22 | 23 | do_something(shape) 24 | do_something(rectangle) 25 | do_something(circle) 26 | 27 | #if make_compilation_fail 28 | do_something("Hello") 29 | #end 30 | } 31 | 32 | func do_something(_shape $T extends Shape) { 33 | printf("%s\n", typenameof $T) 34 | } 35 | -------------------------------------------------------------------------------- /tests/e2e/src/poly_prereq_extends_fail/main.adept: -------------------------------------------------------------------------------- 1 | 2 | #define make_compilation_fail true 3 | import "../poly_prereq_extends/main.adept" 4 | -------------------------------------------------------------------------------- /tests/e2e/src/polycount/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main { 5 | array 10 int 6 | printNumberOfElements(array) 7 | initializeFixedArray(&array) 8 | print(array) 9 | 10 | floats 4 float 11 | printNumberOfElements(floats) 12 | initializeFixedArray(&floats) 13 | print(floats) 14 | } 15 | 16 | func printNumberOfElements(_fixed_array $#N $T) { 17 | print($#N) 18 | } 19 | 20 | func initializeFixedArray(fixed_array *$#N $T~__primitive__) { 21 | pointer_duplicate_using_polycount *$#N $T = fixed_array 22 | each $T in *fixed_array, (*pointer_duplicate_using_polycount)[idx] = idx as $T 23 | } 24 | -------------------------------------------------------------------------------- /tests/e2e/src/polymorphic_anonymous_composites/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main { 5 | other(null as *struct(a int, b float, c 20 String)) 6 | } 7 | 8 | func other(_type *struct (a $A, b $B, c $C)) { 9 | print(typenameof $A) 10 | print(typenameof $B) 11 | print(typenameof $C) 12 | } 13 | -------------------------------------------------------------------------------- /tests/e2e/src/polymorphic_anonymous_composites_mismatch/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main { 5 | // error: Undeclared function other(*struct (a int, b float, c 20 String)) 6 | other(null as *struct(a int, b float, c 20 String)) 7 | } 8 | 9 | func other(_type *struct (a $A, b $B, c $A)) { 10 | print(typenameof $A) 11 | print(typenameof $B) 12 | print(typenameof $A) 13 | } 14 | -------------------------------------------------------------------------------- /tests/e2e/src/polymorphic_functions/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import '2.1/basics.adept' 3 | 4 | func main { 5 | print("--------------------------------------") 6 | print(thing("Hello World")) 7 | print("--------------------------------------") 8 | print("3 + 5 = %" % sum(3, 5)) 9 | print("3.1415 + 5.0 = %" % sum(3.1415, 5.0)) 10 | print("\"Hello \" + \"World\" = \"%\"" % sum("Hello ", "World")) 11 | print("--------------------------------------") 12 | sumThings(3, 5) 13 | sumThings(3.1415, 5.0) 14 | sumThings("Hello ", "World") 15 | print("--------------------------------------") 16 | } 17 | 18 | func thing(in value $T) $T { 19 | return value 20 | } 21 | 22 | func sum(in a $T, in b $T) $T { 23 | return a + b 24 | } 25 | 26 | func sumThings(a, b $T) { 27 | print("% + % = %" % a % b % sum(a, b)) 28 | } 29 | -------------------------------------------------------------------------------- /tests/e2e/src/polymorphic_inner/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import '2.1/basics.adept' 3 | 4 | struct <$T> Box (contents $T) 5 | 6 | func main { 7 | test(100) 8 | test(3.14159265) 9 | test("Hello") 10 | } 11 | 12 | func test(value $T) { 13 | x $T = value 14 | y *$T = new $T 15 | z <$T> Box 16 | 17 | defer delete y 18 | *y = value 19 | z.contents = value 20 | 21 | print("% + % + % = %" % x % *y % z.contents % (x + *y + z.contents)) 22 | } 23 | -------------------------------------------------------------------------------- /tests/e2e/src/polymorphic_structs/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import '2.1/basics.adept' 3 | 4 | struct <$T> Box (contents $T) 5 | 6 | func boxes_demo { 7 | int_box Box 8 | float_box Box 9 | box_box < Box> Box 10 | 11 | int_box.contents = 123 12 | print("int_box.contents = %" % int_box.contents) 13 | 14 | float_box.contents = 3.14159265 15 | print("float_box.contents = %" % float_box.contents) 16 | 17 | box_box.contents.contents = "Hello World" 18 | print("box_box.contents.contents = \"%\"" % box_box.contents.contents) 19 | } 20 | 21 | struct <$K, $V> Pair (key $K, value $V) 22 | 23 | func pairs_demo { 24 | name_age Pair 25 | name_age.key = "John Smith" 26 | name_age.value = 42 27 | print("% is % years old" % name_age.key % name_age.value) 28 | } 29 | 30 | func main { 31 | boxes_demo() 32 | pairs_demo() 33 | } 34 | -------------------------------------------------------------------------------- /tests/e2e/src/pragma/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma compiler_version '2.0' 3 | 4 | // Old prama 'options' directive testing 5 | pragma options '-n pragma -O3' 6 | 7 | // Modern pragma directives 8 | pragma project_name 'pragma' 9 | pragma optimization aggressive 10 | 11 | import 'sys/cstdio.adept' 12 | 13 | func main(in argc int, in argv **ubyte) int { 14 | printf('Hello World') 15 | return 0 16 | } 17 | -------------------------------------------------------------------------------- /tests/e2e/src/primitives/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | signed8 byte = -50sb 6 | unsigned8 ubyte = 255ub 7 | signed16 short = -256ss 8 | unsigned16 ushort = 65535us 9 | signed32 int = -1000000si 10 | unsigned32 uint = 4000000ui 11 | signed64 long = -1000000000sl 12 | unsigned64 ulong = 1000000000ul 13 | float32 float = 3.1415f 14 | float64 double = 3.14159265d 15 | return 0 16 | } 17 | -------------------------------------------------------------------------------- /tests/e2e/src/records/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | record Position (x, y float) 5 | record Person (firstname, lastname String) 6 | 7 | func main { 8 | // A constructor function is automatically generated for "record" types 9 | position Position = Position(1.0, 2.0) 10 | printf("%f %f\n", position.x, position.y) 11 | 12 | // They work with non-trival types as well 13 | isaac Person = Person("Isaac", "Shelton") 14 | printf("%S %S\n", isaac.firstname, isaac.lastname) 15 | 16 | // And memory is taken care of appropriately 17 | smith Person = Person("John".clone(), "Smith".clone()) 18 | printf("%S %S\n", smith.firstname, smith.lastname) 19 | } 20 | 21 | // Example of a function automatically generated 22 | // - The variable '$' is a specially named variable that is impossible to have conflicts with 23 | // - The value '$' is always treated as plain-old-data (POD) and is zero initialized during creation 24 | // - The arguments are always passed as plain-old-data (POD) 25 | // - The arguments are always assigned to fields NOT as plain-old-data (POD) 26 | /* 27 | func Person(firstname POD String, lastname POD String) Person { 28 | $ POD Person 29 | $.firstname = firstname 30 | $.lastname = lastname 31 | return $ 32 | } 33 | */ 34 | -------------------------------------------------------------------------------- /tests/e2e/src/records_polymorphic/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | record <$T> Dummy () 5 | record <$T> Couple (a, b $T) 6 | 7 | func main { 8 | _dummy Dummy = Dummy() ~> Dummy 9 | 10 | couple Couple = Couple(8, 13) 11 | printf("8 + 13 = %d\n", couple.a + couple.b) 12 | } 13 | -------------------------------------------------------------------------------- /tests/e2e/src/repeat/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | 6 | repeat argc { 7 | if idx == 0, continue 8 | printf('arg[%d] is %s\n', idx as int, argv[idx]) 9 | } 10 | 11 | return 0 12 | } 13 | -------------------------------------------------------------------------------- /tests/e2e/src/repeat_args/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | printIntegers(10, 8, 54, 21) 6 | return 0 7 | } 8 | 9 | func printIntegers(x, y, z, w int) void { 10 | printf('%d %d %d %d\n', x, y, z, w) 11 | } 12 | -------------------------------------------------------------------------------- /tests/e2e/src/repeat_fields/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | struct IntVector (x, y, z int) 5 | 6 | func main(in argc int, in argv **ubyte) int { 7 | i IntVector 8 | i.set(1, 2, 3) 9 | printf('%d %d %d\n', i.x, i.y, i.z) 10 | return 0 11 | } 12 | 13 | func set(this *IntVector, x, y, z int) void { 14 | this.x = x; this.y = y; this.z = z 15 | } 16 | -------------------------------------------------------------------------------- /tests/e2e/src/repeat_static/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/ctime.adept' 3 | import 'sys/cstdio.adept' 4 | import 'sys/cstdlib.adept' 5 | 6 | import '2.3/basics.adept' 7 | import '2.3/TypeInfo.adept' 8 | 9 | func main { 10 | srand(time(null)) 11 | repeat getAmount() {} 12 | printf('-------------------------\n') 13 | repeat static getAmount() {} 14 | } 15 | 16 | func getAmount usize { 17 | amount usize = cast usize (rand() % 8) 18 | printf('getAmount() called! returning %d\n', amount as int) 19 | return amount 20 | } 21 | -------------------------------------------------------------------------------- /tests/e2e/src/repeat_using/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main { 5 | repeat 10 using x_idx { 6 | repeat 10 using y_idx { 7 | place(x_idx == y_idx ? " x " : " - ") 8 | } 9 | newline() 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/e2e/src/return_every_case/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func sumOfAbsolute(a, b long) long { 5 | if a > 0 && b > 0 { 6 | return a + b 7 | } else if a < 0 && b < 0 { 8 | return -(a + b) 9 | } else if a < 0 && b > 0 { 10 | return -a + b 11 | } else { 12 | return a + -b 13 | } 14 | } 15 | 16 | func main { 17 | numbers < Pair> Array = { 18 | pair(1, 2), 19 | pair(-3, 4), 20 | pair(5, -6), 21 | pair(-7, -8), 22 | } 23 | 24 | each Pair in numbers { 25 | print(sumOfAbsolute(it.first, it.second)) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/e2e/src/return_matching/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | 4 | import basics 5 | 6 | func something int { 7 | return 42 8 | } 9 | 10 | func something float { 11 | return 3.1415 12 | } 13 | 14 | func something List { 15 | floats List 16 | repeat 3, floats.add(idx as float) 17 | return floats.commit() 18 | } 19 | 20 | func main { 21 | // Use '~>' operator to specify return type 22 | print(something() ~> int) 23 | print(something() ~> float) 24 | print(something() ~> List) 25 | } 26 | -------------------------------------------------------------------------------- /tests/e2e/src/return_ten/main.adept: -------------------------------------------------------------------------------- 1 | 2 | func main(argc int, argv **ubyte) int { 3 | return (8 + 13 - 1) / 2 4 | } 5 | -------------------------------------------------------------------------------- /tests/e2e/src/rtti_enum/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma compiler_version '2.8' 3 | 4 | import basics 5 | 6 | enum MyEnum (NONE, ERROR, WARNING, INFO, ICON) 7 | 8 | func main { 9 | print("Information about every enum used:") 10 | 11 | // NOTE: Types that are never used will not show up in RTTI 12 | // (we will use MyEnum here so that it'll be included in our runtime info) 13 | _used MyEnum 14 | 15 | each *AnyType in [__types__, __types_length__] { 16 | if it.kind == ::ENUM { 17 | as_enum *AnyEnumType = it as *AnyEnumType 18 | printf(" %s : %S\n", as_enum.name, toString(Array(as_enum.members, as_enum.length))) 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/e2e/src/runtime_resource/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | import "other/other.adept" 4 | 5 | #default utilize_where __windows__ || __macos__ 6 | 7 | #if utilize_where 8 | import where 9 | #end 10 | 11 | func main { 12 | #if utilize_where 13 | filename *ubyte = (where() + "my_file.txt").cstr() 14 | #else 15 | filename *ubyte = strdup('my_file.txt') 16 | #end 17 | 18 | defer delete filename 19 | 20 | file *FILE = fopen(filename, 'r') 21 | 22 | if file == null { 23 | printf('failed to read file\n') 24 | return 25 | } 26 | 27 | defer fclose(file) 28 | 29 | buf 1024 ubyte = undef 30 | 31 | while fgets(buf at 0, sizeof(buf), file) { 32 | printf('%s', buf at 0) 33 | } 34 | 35 | printf('\n[file complete]\n') 36 | } 37 | -------------------------------------------------------------------------------- /tests/e2e/src/runtime_resource/other/my_file.txt: -------------------------------------------------------------------------------- 1 | Hello world this is a file -------------------------------------------------------------------------------- /tests/e2e/src/runtime_resource/other/other.adept: -------------------------------------------------------------------------------- 1 | 2 | #runtime_resource "my_file.txt" 3 | -------------------------------------------------------------------------------- /tests/e2e/src/scientific/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main { 5 | printf('%f %f %f\n', 3.14159265e5, 3.14159265e-3, 3.1415265e2) 6 | } 7 | -------------------------------------------------------------------------------- /tests/e2e/src/scoped_variables/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | x int = 3 6 | 7 | if true { 8 | x int = 1 9 | printf('%d\n', x) 10 | 11 | if true { 12 | x int = 2 13 | printf('%d\n', x) 14 | } 15 | } 16 | 17 | printf('%d\n', x) 18 | return 0 19 | } 20 | -------------------------------------------------------------------------------- /tests/e2e/src/search_path/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma search_path "other_files/" 3 | import "file.adept" 4 | 5 | func main { 6 | say("Hello World!!!") 7 | } 8 | -------------------------------------------------------------------------------- /tests/e2e/src/search_path/other_files/file.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func say(message String) { 5 | print(message) 6 | } 7 | -------------------------------------------------------------------------------- /tests/e2e/src/similar/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | struct Damagable (health int, blows_taken int) 5 | struct BadGuy (name *ubyte, struct Damagable) 6 | 7 | func main { 8 | badguy BadGuy 9 | badguy.name = 'Smith' 10 | badguy.health = 10 11 | badguy.damage(add(3, 3)) 12 | badguy.damage(1) 13 | badguy.damage(3) 14 | } 15 | 16 | func damage(this *$D~Damagable, amount int) bool { 17 | this.health -= amount 18 | this.blows_taken++ 19 | printf('Health decreased from %d to %d\n', this.health + amount, this.health) 20 | printf(' (Blows taken increased to %d)\n', this.blows_taken) 21 | return this.health < 0 22 | } 23 | 24 | func add(a, b $T~__number__) $T { 25 | return a + b 26 | } 27 | -------------------------------------------------------------------------------- /tests/e2e/src/sizeof/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | struct Person (name *ubyte, age int) 5 | 6 | packed struct PackedPerson (name *ubyte, age int) 7 | 8 | func main(in argc int, in argv **ubyte) int { 9 | printf('sizeof ubyte = %llu\n', sizeof ubyte) 10 | printf('sizeof int = %llu\n', sizeof int) 11 | printf('sizeof Person = %llu\n', sizeof Person) 12 | printf('sizeof PackedPerson = %llu\n', sizeof PackedPerson) 13 | return 0 14 | } 15 | -------------------------------------------------------------------------------- /tests/e2e/src/sizeof_value/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main { 5 | value 10 int 6 | print(sizeof(value)) 7 | } 8 | -------------------------------------------------------------------------------- /tests/e2e/src/small_functions/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main { 5 | printf('%s %d\n', message(), sum(10, 11)) 6 | } 7 | 8 | func message *ubyte = 'Hello World' 9 | func sum(x, y int) int = x + y 10 | -------------------------------------------------------------------------------- /tests/e2e/src/standard/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import '2.1/basics.adept' 3 | 4 | func main { 5 | print("Hello World from Adept!") 6 | } 7 | -------------------------------------------------------------------------------- /tests/e2e/src/static_arrays/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | names_length usize = 3 6 | names **ubyte = static *ubyte { 7 | 'Isaac', 'Andy', 'Alex' 8 | } 9 | 10 | counting_length usize = 10 11 | counting *int = static int { 12 | 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 13 | } 14 | 15 | each *ubyte in [names, names_length] { 16 | printf('%s', it) 17 | if idx + 1 == names_length, putchar('\n'ub) else printf(', ') 18 | } 19 | 20 | each int in [counting, counting_length] { 21 | printf('%d', it) 22 | if idx + 1 == counting_length, putchar('\n'ub) else printf(', ') 23 | } 24 | 25 | return 0 26 | } 27 | -------------------------------------------------------------------------------- /tests/e2e/src/static_variables/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main { 5 | next() 6 | next() 7 | next() 8 | print("[done]") 9 | } 10 | 11 | func next { 12 | static x int = 0 13 | static y int = 0 14 | static z int = 0 15 | static string String = "-> " 16 | 17 | place(x++, y++, z++) 18 | 19 | string.append("Hello ") 20 | print(string) 21 | } 22 | -------------------------------------------------------------------------------- /tests/e2e/src/stdcall/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | ms_function(10, 11) 6 | c int = ms_function(13, 8) 7 | ref stdcall func(int, int) int = func &ms_function 8 | d int = ref(14, 43) 9 | printf('c = %d, d = %d\n', c, d) 10 | return 0 11 | } 12 | 13 | stdcall func ms_function(a int, b int) int { 14 | return a + b 15 | } 16 | -------------------------------------------------------------------------------- /tests/e2e/src/string/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | pragma compiler_version '2.1' 4 | 5 | import '2.1/String.adept' 6 | import 'sys/cstdio.adept' 7 | 8 | func main { 9 | string String = "Hello World!!!" 10 | 11 | each ubyte in [string.array, string.length] { 12 | putchar(it) 13 | } 14 | putchar(0xA) 15 | } 16 | -------------------------------------------------------------------------------- /tests/e2e/src/struct_association/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main { 5 | greeter Greeter 6 | greeter.greet() 7 | 8 | welcomer Welcomer 9 | welcomer.welcome(10) 10 | } 11 | 12 | struct Greeter () { 13 | func greet { 14 | printf('Hello World!\n') 15 | } 16 | } 17 | 18 | struct <$T> Welcomer () { 19 | func welcome(value $~T) { 20 | printf('Welcome! [x%d]\n', value as int) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/e2e/src/structs/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | 4 | struct Person (name *ubyte, age int, parent Parent) 5 | struct Parent (gender bool) 6 | 7 | func main(in argc int, in argv **ubyte) int { 8 | person Person 9 | return 0 10 | } 11 | -------------------------------------------------------------------------------- /tests/e2e/src/successful/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | unless doSomething(), printf('Failed\n'); return 1 6 | printf('Succeeded\n') 7 | return 0 8 | } 9 | 10 | func doSomething() successful { 11 | return true 12 | } 13 | -------------------------------------------------------------------------------- /tests/e2e/src/super/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | class Shape (x int) { 5 | constructor(value int = 21){ 6 | print("[shape constructor]") 7 | this.x = value 8 | } 9 | 10 | virtual func getName String = "Shape" 11 | } 12 | 13 | class Circle extends Shape () { 14 | constructor(){ 15 | super() 16 | print("[circle constructor]") 17 | } 18 | 19 | override func getName String = "Circle" 20 | } 21 | 22 | func main { 23 | shape *Shape = new Circle() 24 | defer del(shape) 25 | 26 | print("Name is: " + shape.getName(), "X is: " + shape.x) 27 | } 28 | -------------------------------------------------------------------------------- /tests/e2e/src/super_polymorphic/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | class <$T> Parent (x $T) { 5 | constructor(x $T~__number__){ 6 | this.x = x 7 | } 8 | 9 | virtual func print { 10 | print("x=" + this.x) 11 | } 12 | } 13 | 14 | class <$T> Child extends <$T> Parent (y $T) { 15 | constructor(x, y $T~__number__){ 16 | super(x) 17 | this.y = y 18 | } 19 | 20 | override func print { 21 | print("x=" + this.x + ", y=" + this.y) 22 | } 23 | } 24 | 25 | func main { 26 | { 27 | thing * Parent = new Child(10.0, 11.0) 28 | defer del(thing) 29 | 30 | thing.print() 31 | } 32 | 33 | { 34 | thing * Parent = new Child('a'ub, 'b'ub) 35 | defer del(thing) 36 | 37 | thing.print() 38 | } 39 | 40 | { 41 | thing * Parent = new Parent(21) 42 | defer del(thing) 43 | 44 | thing.print() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/e2e/src/switch_exhaustive/main.adept: -------------------------------------------------------------------------------- 1 | 2 | #default test_with_missing_cases false 3 | #default test_with_default_case false 4 | import 'sys/cstdio.adept' 5 | 6 | enum MyEnum (VALUE1, VALUE2, VALUE3, VALUE4, VALUE5) 7 | 8 | func main { 9 | value MyEnum = MyEnum::VALUE1 10 | 11 | #if test_with_missing_cases 12 | 13 | exhaustive switch value { 14 | case MyEnum::VALUE3 15 | // Do nothing 16 | case MyEnum::VALUE5 17 | // Do nothing 18 | } 19 | 20 | #elif test_with_default_case 21 | 22 | exhaustive switch value { 23 | case MyEnum::VALUE3 24 | // Do nothing 25 | case MyEnum::VALUE5 26 | // Do nothing 27 | default 28 | // Since we have default case, no error is thrown 29 | } 30 | 31 | #else 32 | 33 | exhaustive switch value { 34 | case MyEnum::VALUE1, fallthrough 35 | case MyEnum::VALUE2, fallthrough 36 | case MyEnum::VALUE3, fallthrough 37 | case MyEnum::VALUE4, fallthrough 38 | case MyEnum::VALUE5 39 | printf('Hello World!\n') 40 | } 41 | 42 | #end 43 | } 44 | -------------------------------------------------------------------------------- /tests/e2e/src/switch_more/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | THREE == 3.0f as ubyte 5 | FRUIT_PEAR == Fruit::PEAR 6 | 7 | enum Fruit (APPLE, BANANA, ORANGE, PEAR) 8 | 9 | func main { 10 | switch 3 { 11 | case 0, printf('zero!\n') 12 | case 1, printf('one!\n') 13 | case 2, printf('two!\n') 14 | case THREE, printf('three!\n') 15 | } 16 | 17 | switch Fruit::PEAR { 18 | case Fruit::APPLE, printf('apple!\n') 19 | case Fruit::BANANA, printf('banana!\n') 20 | case Fruit::ORANGE, printf('orange!\n') 21 | case FRUIT_PEAR, printf('pear!\n') 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/e2e/src/temporary_mutable/main.adept: -------------------------------------------------------------------------------- 1 | 2 | #set log_string_deletion true 3 | 4 | import '2.3/basics.adept' 5 | 6 | func main { 7 | name String = "Isaac Shelton".clone() 8 | print(("Hello " + name + "!").clone()) 9 | } 10 | -------------------------------------------------------------------------------- /tests/e2e/src/tentative_function_calls/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | struct StructA () 5 | struct StructB () 6 | 7 | func main { 8 | a StructA 9 | b StructB 10 | test(a) 11 | test(b) 12 | } 13 | 14 | func test(thing $T) { 15 | greet?(&thing, 1234) 16 | } 17 | 18 | func greet(this *StructB, _unused int) { 19 | printf('Hello World from StructB\n') 20 | } 21 | -------------------------------------------------------------------------------- /tests/e2e/src/tentative_method_calls/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | struct StructA () 5 | struct StructB () 6 | 7 | func main { 8 | a StructA 9 | b StructB 10 | test(a) 11 | test(b) 12 | } 13 | 14 | func test(thing $T) { 15 | thing.?greet(1234) 16 | } 17 | 18 | func greet(this *StructB, _unused int) { 19 | printf('Hello World from StructB\n') 20 | } 21 | -------------------------------------------------------------------------------- /tests/e2e/src/terminate_join/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | if argc == 1, puts('No args specified'); return 1 6 | if argc == 2, puts('Only one arg specified'); return 1 7 | puts('More than one arg specified') 8 | 9 | i int = 0; while i != 10, i += 1; printf('%d\n', i) 10 | 11 | if i == 0, puts('Failed to get off the ground') 12 | else if i > 0 && i < 10, puts('Failed to completely launch') 13 | else puts('Launched successfully') 14 | return 0 15 | } 16 | -------------------------------------------------------------------------------- /tests/e2e/src/ternary/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import '2.1/basics.adept' 3 | 4 | func main { 5 | print(true ? "true is true" : "true is false") 6 | print(false ? "false is true" : false ? "false is true" : "false is false") 7 | } 8 | -------------------------------------------------------------------------------- /tests/e2e/src/ternary_circuit/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/ctime.adept' 3 | import 'sys/cstdio.adept' 4 | import 'sys/cstdlib.adept' 5 | 6 | func main { 7 | srand(time(null)) 8 | printf('%d\n', rand() % 2 == 0 ? one() : two()) 9 | } 10 | 11 | func one int { 12 | printf('one\n') 13 | return 1 14 | } 15 | 16 | func two int { 17 | printf('two\n') 18 | return 2 19 | } 20 | -------------------------------------------------------------------------------- /tests/e2e/src/toggle/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import '2.3/basics.adept' 3 | 4 | func main { 5 | value bool = false 6 | 7 | repeat 3, 8 | print("% => %" % value % value!!) 9 | } 10 | -------------------------------------------------------------------------------- /tests/e2e/src/truefalse/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | is_blue bool = true 6 | is_grey bool = false 7 | return 0 8 | } 9 | -------------------------------------------------------------------------------- /tests/e2e/src/typenameof/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma compiler_version '2.5' 3 | pragma ignore_unused 4 | pragma no_typeinfo 5 | 6 | import basics 7 | 8 | func main() { 9 | printTypenameof("Hello World") 10 | printTypenameof(3 + 4) 11 | printTypenameof(3.0f * 3.14159265f) 12 | printTypenameof(stdout) 13 | printTypenameof('Bye World') 14 | printTypenameof(func &main) 15 | } 16 | 17 | func printTypenameof(_x $T) { 18 | printf("%s\n", typenameof $T) 19 | } 20 | -------------------------------------------------------------------------------- /tests/e2e/src/undef/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | // 'undef' does nothing for globals, they will be initialized as zero regardless 5 | global_var int = undef 6 | 7 | func main(in argc int, in argv **ubyte) int { 8 | // {initialized int} will be assigned to default value of zero 9 | // {uninitialized int = undef} will be whatever memory was left there 10 | initialized int 11 | uninitialized int = undef 12 | printf('init = %d, uninit = %d, global_var = %d\n', initialized, uninitialized, global_var) 13 | return 0 14 | } 15 | -------------------------------------------------------------------------------- /tests/e2e/src/union/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | union Data (x int, y double, z long) 5 | union <$T> PolymorphicData (x int, y double, z long, w $T) 6 | 7 | func main { 8 | x Data 9 | x.y = 12345.0 10 | print("sizeof Data = %" % sizeof Data) 11 | print("data.x int = %" % x.x) 12 | print("data.y double = %" % x.y) 13 | print("data.z long = %" % x.z) 14 | newline() 15 | 16 | type *AnyUnionType = typeinfo PolymorphicData as *AnyUnionType 17 | printf('%s %s (size = %d)\n', __type_kinds__[type.kind], type.name, type.size as int) 18 | repeat static type.length { 19 | printf('-> %s %s\n', type.member_names[idx], type.members[idx].name) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/e2e/src/unknown_enum_values/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | enum Color (RED, GREEN, BLUE) 5 | 6 | func printColor(color Color, indentation int = 0) { 7 | repeat indentation, putchar(' 'ub) 8 | 9 | exhaustive switch color { 10 | case ::RED, print("red") 11 | case ::GREEN, print("green") 12 | case ::BLUE, print("blue") 13 | } 14 | } 15 | 16 | func printColor(c1, c2, c3 $T){ 17 | print("{") 18 | printColor(c1, 4) 19 | printColor(c2, 4) 20 | printColor(c3, 4) 21 | print("}") 22 | } 23 | 24 | func main { 25 | printColor(Color::RED, ::GREEN, ::BLUE) 26 | 27 | printColor(::RED) 28 | printColor(::GREEN) 29 | printColor(::BLUE) 30 | } 31 | -------------------------------------------------------------------------------- /tests/e2e/src/unknown_plural_enum_values/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | import random 4 | 5 | enum Animal (CAT, DOG, BAT) 6 | 7 | func main { 8 | randomSetSeed(2023) 9 | 10 | repeat static 10 { 11 | fruit enum (APPLE, ORANGE, BANANA) = randomDouble() > 0.5 ? (randomDouble() > 0.5 ? ::APPLE : ::ORANGE) : ::BANANA 12 | print(fruit) 13 | } 14 | 15 | repeat static 10 { 16 | animal Animal = randomDouble() > 0.5 ? (randomDouble() > 0.5 ? ::DOG : ::CAT) : ::BAT 17 | print(animal) 18 | } 19 | 20 | print("-----------") 21 | 22 | // The conditions of these ternary expressions could be determined at runtime if desired. 23 | // We'll just use `true` and `false` though so it's obvious what the answers should be. 24 | functionThatAcceptsEnum( true ? (true ? ::CAT : ::DOG) : ::BAT ) 25 | functionThatAcceptsEnum( true ? (false ? ::CAT : ::DOG) : ::BAT ) 26 | functionThatAcceptsEnum( false ? (false ? ::CAT : ::DOG) : ::BAT ) 27 | } 28 | 29 | func functionThatAcceptsEnum(animal Animal) { 30 | print(animal) 31 | } 32 | -------------------------------------------------------------------------------- /tests/e2e/src/unless/main.adept: -------------------------------------------------------------------------------- 1 | 2 | foreign puts(in *ubyte) int 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | unless argc == 1 { 6 | puts('Arguments were specified') 7 | } 8 | return 0 9 | } 10 | -------------------------------------------------------------------------------- /tests/e2e/src/unlesselse/main.adept: -------------------------------------------------------------------------------- 1 | 2 | foreign puts(*ubyte) int 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | unless argc == 1 { 6 | puts('Arguments specified') 7 | } else { 8 | puts('No arguments specified') 9 | } 10 | return 0 11 | } 12 | -------------------------------------------------------------------------------- /tests/e2e/src/unnecessary_manual_defer_call/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | 4 | struct DoesntNeedDefer () 5 | 6 | func main { 7 | value *DoesntNeedDefer = new DoesntNeedDefer 8 | 9 | // Even though this function doesn't exist, since it's a no-op, 10 | // We will give back a dummy no-op function for backwards compatibility 11 | // e.g. func __noop__(ptr) void 12 | f func(*DoesntNeedDefer) void = func &__defer__(*DoesntNeedDefer) 13 | 14 | // Even though __defer__(*DoesntNeedDefer) is unnecessary 15 | // and therefore doesn't exist, this is still permitted. 16 | // (partially for backwards-compatibility, but also to encourage good code practice) 17 | value.__defer__() 18 | delete value 19 | } 20 | -------------------------------------------------------------------------------- /tests/e2e/src/unsupported/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma unsupported 'Use \'newer/supported.adept\' instead' 3 | -------------------------------------------------------------------------------- /tests/e2e/src/unterminated_comment/main.adept: -------------------------------------------------------------------------------- 1 | 2 | func main { 3 | /* todo 4 | } 5 | -------------------------------------------------------------------------------- /tests/e2e/src/unterminated_cstring/main.adept: -------------------------------------------------------------------------------- 1 | 2 | func main { 3 | value *ubyte = ' 4 | } 5 | -------------------------------------------------------------------------------- /tests/e2e/src/unterminated_string/main.adept: -------------------------------------------------------------------------------- 1 | 2 | func main { 3 | value String = " 4 | } 5 | -------------------------------------------------------------------------------- /tests/e2e/src/until/main.adept: -------------------------------------------------------------------------------- 1 | 2 | foreign puts(*ubyte) int 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | i int = 0 6 | until i == 10 { 7 | puts('Increamenting i...') 8 | i += 1 9 | } 10 | return 0 11 | } 12 | -------------------------------------------------------------------------------- /tests/e2e/src/until_break/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | countdown int = 10 6 | 7 | until break { 8 | printf('counting down... %d\n', countdown) 9 | if countdown == 0, break else countdown -= 1 10 | } 11 | 12 | printf('Liftoff!\n') 13 | return 0 14 | } 15 | -------------------------------------------------------------------------------- /tests/e2e/src/va_args/main.adept: -------------------------------------------------------------------------------- 1 | 2 | // VARIABLE ARGUMENT HELPERS 3 | // ap va_list = undef 4 | // va_start ap 5 | // va_start(ap) 6 | // va_end ap 7 | // va_end(ap) 8 | // va_arg(ap, Type) 9 | // va_copy(dest, src) 10 | 11 | import basics 12 | 13 | func main { 14 | print(sizeof va_list) 15 | print(addEmUp(5uz, 4, 10, 11, 12, 13)) 16 | } 17 | 18 | func addEmUp(count usize, ...) long { 19 | ap, ap2 va_list 20 | sum long 21 | 22 | va_start ap 23 | defer va_end ap 24 | 25 | va_copy(ap2, ap) 26 | 27 | repeat count { 28 | sum += va_arg(ap, long) 29 | sum += va_arg(ap2, long) 30 | } 31 | 32 | return sum 33 | } 34 | -------------------------------------------------------------------------------- /tests/e2e/src/varargs/main.adept: -------------------------------------------------------------------------------- 1 | 2 | foreign printf(*ubyte, ...) int 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | printf('You can call %s functions using %s!\n', 'variadic', 'Adept') 6 | printf('11 + 10 = %d\n', 11 + 10) 7 | return 0 8 | } 9 | -------------------------------------------------------------------------------- /tests/e2e/src/variables/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma ignore_unused 3 | 4 | foreign puts(*ubyte) int 5 | 6 | func main(in argc int, in argv **ubyte) int { 7 | hello_world *ubyte = 'Hello Variables!' 8 | another int = 10 9 | puts(hello_world) 10 | return 0 11 | } 12 | -------------------------------------------------------------------------------- /tests/e2e/src/variadic/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import VariadicArray 3 | import 'sys/cstdio.adept' 4 | 5 | func main { 6 | printf('sum = %d\n', sumEmUp(1, 2, 3, 4, 5)) 7 | } 8 | 9 | func sumEmUp(integers ...) int { 10 | printf('%p\n', integers.items) 11 | printf('%p\n', integers.next) 12 | printf('%d\n', integers.length as int) 13 | printf('%d\n', integers.index as int) 14 | printf('%p\n', integers.types) 15 | 16 | sum int = 0 17 | while integers.hasNext() { 18 | if integers.getNextType() != typeinfo long { 19 | printf('ERROR: sumEmUp() got non-long value of type %s!\n', integers.types[integers.index].name) 20 | return 0 21 | } 22 | 23 | x int = integers.readLong() 24 | printf('Got value: %d\n', x) 25 | sum += x 26 | } 27 | return sum 28 | } 29 | -------------------------------------------------------------------------------- /tests/e2e/src/variadic_method/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import VariadicArray 3 | import 'sys/cstdio.adept' 4 | 5 | struct Dummy (name *ubyte) 6 | 7 | func main { 8 | printf('sum = %d\n', getDummy().sumEmUp('Thing', 1, 2, 3, 4, 5)) 9 | } 10 | 11 | func getDummy Dummy { 12 | dummy POD Dummy 13 | dummy.name = 'Test' 14 | return dummy 15 | } 16 | 17 | func sumEmUp(this *Dummy, thing *ubyte, integers ...) int { 18 | printf('%s %s\n', this.name, thing) 19 | printf('%p\n', integers.items) 20 | printf('%p\n', integers.next) 21 | printf('%d\n', integers.length as int) 22 | printf('%d\n', integers.index as int) 23 | printf('%p\n', integers.types) 24 | 25 | sum int = 0 26 | while integers.hasNext() { 27 | if integers.getNextType() != typeinfo long { 28 | printf('ERROR: sumEmUp() got non-long value of type %s!\n', integers.types[integers.index].name) 29 | return 0 30 | } 31 | 32 | x int = integers.readLong() 33 | printf('Got value: %d\n', x) 34 | sum += x 35 | } 36 | return sum 37 | } 38 | -------------------------------------------------------------------------------- /tests/e2e/src/variadic_print/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | 4 | func main { 5 | // Hello there isaac, you are 1234 years old! 6 | printf("Hello there %s, you are %d years old!\n", 'isaac', 1234) 7 | 8 | // Welcome back, we are glad to see you! 9 | printf("Welcome back, we are %S to see you!\n", "glad") 10 | 11 | // 1 12 | // two 13 | // 3 14 | // four 15 | // I declare 16 | // A thumb war 17 | print(1, "two", 3, "four", 'I declare', "A thumb war") 18 | 19 | // 1234, false, Test String, 44, Hello, 1, 2, 3, 4, 5 20 | place(1234ss, false, 'Test string', 44ub, "Hello", 1, 2, 3, 4, 5) 21 | 22 | // Values are: 1 2 3 4 5 23 | placePlain("Values are: ", 1, " ", 2, " ", 3, " ", 4, " ", 5, "\n") 24 | 25 | // 1 and 2 and 3 and 4 26 | placeEx(" and ", false, "\n", 1, 2, 3, 4) 27 | } 28 | -------------------------------------------------------------------------------- /tests/e2e/src/version/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma compiler_version '2.3' 3 | 4 | #print "Adept Build:\t" + __compiler__ 5 | #print "Adept Version:\t" + __compiler_version__ 6 | 7 | #if __compiler_version__ >= 2.7 8 | // As of v2.7, #halt now exits with status 1 9 | // We will use new #done directive to exit with status 0 10 | #done 11 | #else 12 | #halt 13 | #end 14 | -------------------------------------------------------------------------------- /tests/e2e/src/void_ptr/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main { 5 | x int = 10 6 | value *void = &x 7 | *cast *int value = 21 8 | } 9 | -------------------------------------------------------------------------------- /tests/e2e/src/volatile/main.adept: -------------------------------------------------------------------------------- 1 | 2 | // NOTE: The only way to verify this works is with --llvmir 3 | 4 | struct WithinStruct ( address *volatile ubyte ) 5 | 6 | func main { 7 | compatible_with_normal_pointers *volatile ubyte = null 8 | 9 | my_int int = 10 10 | rw *volatile int = &my_int 11 | 12 | *rw = 10 13 | _volatile_read_result int = *rw 14 | 15 | within_struct WithinStruct 16 | within_struct.address = null 17 | *within_struct.address = 'a'ub 18 | } -------------------------------------------------------------------------------- /tests/e2e/src/vtable_checks/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import basics 3 | import Unique 4 | 5 | class Shape (x int) { 6 | constructor(value int = 21){ 7 | print("[shape constructor]") 8 | this.x = value 9 | } 10 | 11 | virtual func getName String = "Shape" 12 | } 13 | 14 | class Circle extends Shape () { 15 | constructor(){ 16 | super() 17 | print("[circle constructor]") 18 | } 19 | 20 | override func getName String = "Circle" 21 | } 22 | 23 | func main { 24 | shape *Shape = new Circle 25 | defer del(shape) 26 | 27 | print("Name is: " + shape.getName() /* runtime error: calling virtual method on unconstructed class instance */, "X is: " + shape.x) 28 | } 29 | -------------------------------------------------------------------------------- /tests/e2e/src/while/main.adept: -------------------------------------------------------------------------------- 1 | 2 | foreign puts(*ubyte) int 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | i int = 0 6 | while i != 10 { 7 | puts('Increamenting i...') 8 | i += 1 9 | } 10 | return 0 11 | } 12 | -------------------------------------------------------------------------------- /tests/e2e/src/while_continue/main.adept: -------------------------------------------------------------------------------- 1 | 2 | import 'sys/cstdio.adept' 3 | 4 | func main(in argc int, in argv **ubyte) int { 5 | countup int = 0 6 | 7 | while continue { 8 | countup += 1 9 | printf('%d\n', countup) 10 | unless countup == 10, continue 11 | } 12 | 13 | return 0 14 | } 15 | -------------------------------------------------------------------------------- /tests/e2e/src/windowed/GameData.adept: -------------------------------------------------------------------------------- 1 | 2 | // Data is put here. 3 | // Everything except textures belongs in here. 4 | // Textures should instead by put inside the 'Textures' struct 5 | struct GameData ( 6 | example_value int 7 | ) { 8 | func load { 9 | this.example_value = 1234 // etc. 10 | } 11 | 12 | func reset { 13 | this.__defer__() 14 | memset(this, 0, sizeof(*this)) 15 | this.load() 16 | } 17 | } 18 | 19 | gamedata GameData 20 | -------------------------------------------------------------------------------- /tests/e2e/src/windowed/Textures.adept: -------------------------------------------------------------------------------- 1 | 2 | import where 3 | import captain 4 | 5 | // Textures are put here, and automatically loaded when 'Textures.load()' is called. 6 | // Then, textures can be accessed by doing 'textures.example_texture', 7 | // Until they are destroyed when 'Textures.unload()' is called. 8 | struct Textures ( 9 | example_texture CaptTexture 10 | ) { 11 | func load { 12 | assets_folder String = where() + "assets/" 13 | error_message String = "Failed to load texture \"%S\"\n" 14 | exceptions Array 15 | suffix String = ".png" 16 | approximate_by_default bool = false 17 | captLoadTexturesByFieldName(this, assets_folder, error_message, suffix, approximate_by_default, exceptions.length ? &exceptions : null as * Array) 18 | } 19 | 20 | func unload { 21 | captUnloadTexturesByFieldName(this) 22 | } 23 | } 24 | 25 | textures Textures 26 | -------------------------------------------------------------------------------- /tests/e2e/src/windowed/assets/example_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptLanguage/Adept/41c3069fd18e0eaa2c33ec61dd2b93c9dde1289f/tests/e2e/src/windowed/assets/example_texture.png -------------------------------------------------------------------------------- /tests/e2e/src/winmain_entry/main.adept: -------------------------------------------------------------------------------- 1 | pragma windows_only 2 | pragma ignore_unused 3 | 4 | import 'sys/cstdio.adept' 5 | 6 | alias HANDLE = ptr 7 | alias HINSTANCE = HANDLE 8 | alias LPSTR = *ubyte 9 | 10 | record Bomb (message *ubyte) { 11 | func __defer__ { 12 | printf('%s\n', this.message) 13 | } 14 | } 15 | 16 | bomb Bomb = Bomb('Hello World') 17 | 18 | external stdcall func WinMain(hInstance, hPrevInstance HINSTANCE, lpCmdLine LPSTR, nCmdShow int) int { 19 | // The initialization of 'bomb' and its automatic '__defer__' call should 20 | // happen here implicitly 21 | 22 | return 0 23 | } 24 | 25 | /* 26 | If no main function exists, and an 'external stdcall func WinMain' exists, 27 | then it will be treated as the entry point 28 | */ 29 | -------------------------------------------------------------------------------- /tests/e2e/src/z_curl/main.adept: -------------------------------------------------------------------------------- 1 | 2 | #unless __windows__ || __macos__ || __linux__ 3 | #print "Test not applicable" 4 | #done 5 | #end 6 | 7 | import 'sys/cstdio.adept' 8 | import 'curl/curl.adept' 9 | 10 | #if __windows__ 11 | import String 12 | import where 13 | #end 14 | 15 | func main { 16 | curl *CURL 17 | res CURLcode 18 | 19 | curl = curl_easy_init() 20 | 21 | if(curl) { 22 | curl_easy_setopt(curl, CURLOPT_URL, 'https://example.com') 23 | 24 | /* specify certificate bundle (only required for windows) */ 25 | #if __windows__ 26 | certificate_bundle *ubyte = (where() + "curl-ca-bundle.crt").cstr() 27 | defer delete certificate_bundle 28 | 29 | curl_easy_setopt(curl, CURLOPT_CAINFO, certificate_bundle) 30 | #end 31 | 32 | /* example.com is redirected, so we tell libcurl to follow redirection */ 33 | curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1) 34 | 35 | /* Perform the request, res will get the return code */ 36 | res = curl_easy_perform(curl) 37 | 38 | /* Check for errors */ 39 | if(res != CURLE_OK) fprintf(stderr, 'curl_easy_perform() failed: %s\n', curl_easy_strerror(res)) 40 | 41 | /* always cleanup */ 42 | curl_easy_cleanup(curl) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/unit/include/CuTestExtras.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ISAAC_CUTEST_EXTRAS_H_INCLUDED 3 | #define _ISAAC_CUTEST_EXTRAS_H_INCLUDED 4 | 5 | #include "CuTest.h" 6 | #include "UTIL/ground.h" 7 | 8 | #define CuAssertIntEquals_Msgf(tc,ms,ex,ac, ...) { \ 9 | strong_cstr_t message_tmp = mallocandsprintf((ms), __VA_ARGS__); \ 10 | CuAssertIntEquals_LineMsg((tc),__FILE__,__LINE__,(message_tmp),(ex),(ac)); \ 11 | free(message_tmp); \ 12 | } 13 | 14 | #endif // _ISAAC_CUTEST_EXTRAS_H_INCLUDED 15 | -------------------------------------------------------------------------------- /tests/unit/src/UnitTestRunner.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "CuTest.h" 5 | 6 | CuSuite *CuSuite_for_ast_expr(void); 7 | CuSuite *CuSuite_for_lex(void); 8 | 9 | int RunAllTests(void){ 10 | printf("Running all unit tests:\n"); 11 | 12 | CuString *output = CuStringNew(); 13 | CuSuite* suite = CuSuiteNew(); 14 | 15 | CuSuiteAddSuite(suite, CuSuite_for_ast_expr()); 16 | CuSuiteAddSuite(suite, CuSuite_for_lex()); 17 | 18 | CuSuiteRun(suite); 19 | CuSuiteSummary(suite, output); 20 | CuSuiteDetails(suite, output); 21 | printf("%s\n", output->buffer); 22 | return suite->failCount; 23 | } 24 | 25 | int main(void){ 26 | return RunAllTests(); 27 | } 28 | --------------------------------------------------------------------------------