├── .clang-format ├── .clang-tidy ├── .github └── workflows │ └── test.yml ├── .gitignore ├── .gitmodules ├── .pylintrc ├── .vimrc ├── CMakeLists.txt ├── CPackConfig.cmake ├── LICENSE.TXT ├── README.md ├── bootstrap_llvm.sh ├── build.py ├── dbg_env.sh ├── dockerfiles └── mac-build ├── docs ├── Doxyfile ├── constraints_analysis.md ├── gym_tutorial.md ├── machine_learning.dot ├── philosophy.md ├── poster-fioravanti.pdf ├── rationale.md ├── sky_tower_report_example.pdf ├── space_hulk_level_design.md ├── sphinx_doc │ ├── 4hammer.md │ ├── _static │ │ └── custom.css │ ├── board_games.md │ ├── building.md │ ├── conf.py │ ├── gym_tutorial.md │ ├── imgs │ │ ├── RLC_logo.png │ │ ├── generation.png │ │ ├── lines_of_code.png │ │ ├── machine_learning_rules.png │ │ ├── mean_reward.png │ │ ├── ml_progress.jpeg │ │ ├── mono_behaviour.webp │ │ ├── moore_law.jpg │ │ ├── performance.png │ │ ├── rl_game_progress.webp │ │ ├── sh_board1.png │ │ ├── sh_board2.png │ │ ├── sh_board3.png │ │ ├── sh_state_machine.dot │ │ ├── sh_state_machine.svg │ │ ├── tensorboard.png │ │ └── tensorboard2.png │ ├── index.rst │ ├── interoperating.md │ ├── language-reference.md │ ├── language_tour.md │ ├── project_rationale.md │ ├── rlc.md │ ├── stdlib │ │ ├── action.md │ │ ├── algorithms │ │ │ ├── equal.md │ │ │ └── index.rst │ │ ├── bounded_arg.md │ │ ├── collections │ │ │ ├── dictionary.md │ │ │ ├── graph.md │ │ │ ├── index.rst │ │ │ ├── pair.md │ │ │ └── vector.md │ │ ├── enum_utils.md │ │ ├── index.rst │ │ ├── learn.md │ │ ├── machine_learning.md │ │ ├── math │ │ │ ├── index.rst │ │ │ └── numeric.md │ │ ├── none.md │ │ ├── python.md │ │ ├── range.md │ │ ├── serialization │ │ │ ├── index.rst │ │ │ ├── key_equal.md │ │ │ ├── print.md │ │ │ ├── to_byte_vector.md │ │ │ └── to_hash.md │ │ └── string.md │ ├── the_inversion_of_control_problem.md │ ├── tutorial.md │ └── ui_gameplay.md ├── tutorial.md └── where_we_are_going.md ├── environment.bat ├── environment.fish ├── environment.sh ├── fish_dbg_env.fish ├── imgs ├── RLC_logo.png ├── generation.png ├── lines_of_code.png ├── machine_learning_rules.png ├── mean_reward.png ├── ml_progress.jpeg ├── mono_behaviour.webp ├── moore_law.jpg ├── performance.png ├── rl_game_progress.webp ├── sh_board1.png ├── sh_board2.png ├── sh_board3.png ├── sh_state_machine.dot ├── sh_state_machine.svg ├── tensorboard.png └── tensorboard2.png ├── lib ├── CMakeLists.txt ├── backend │ ├── CMakeLists.txt │ ├── backendConfig.cmake │ ├── include │ │ └── rlc │ │ │ └── backend │ │ │ └── BackEnd.hpp │ ├── src │ │ └── BackEnd.cpp │ └── test │ │ └── CMakeLists.txt ├── conversions │ ├── CMakeLists.txt │ ├── conversionsConfig.cmake │ ├── include │ │ └── rlc │ │ │ └── conversions │ │ │ ├── CSharpConversions.hpp │ │ │ └── RLCToC.hpp │ └── src │ │ ├── RLCToC.cpp │ │ ├── RLCToCPass.cpp │ │ ├── RLCToCSharp.cpp │ │ └── RLCToPython.cpp ├── dialect │ ├── CMakeLists.txt │ ├── dialectConfig.cmake │ ├── include │ │ └── rlc │ │ │ └── dialect │ │ │ ├── ActionArgumentAnalysis.hpp │ │ │ ├── ActionLiveness.hpp │ │ │ ├── Attrs.hpp │ │ │ ├── ConstraintsAnalysis.hpp │ │ │ ├── DebugInfo.hpp │ │ │ ├── Dialect.h │ │ │ ├── Enums.hpp │ │ │ ├── IRBuilder.hpp │ │ │ ├── Interfaces.hpp │ │ │ ├── MemberFunctionsTable.hpp │ │ │ ├── Operations.hpp │ │ │ ├── OverloadResolver.hpp │ │ │ ├── Passes.hpp │ │ │ ├── ProgramGraph.hpp │ │ │ ├── ReachingDefinitions.hpp │ │ │ ├── SerializationContext.hpp │ │ │ ├── SymbolTable.h │ │ │ ├── TypeInterfaces.hpp │ │ │ ├── TypeStorage.hpp │ │ │ ├── Types.hpp │ │ │ ├── Visits.hpp │ │ │ └── conversion │ │ │ └── TypeConverter.h │ ├── src │ │ ├── ActionArgumentAnalysis.cpp │ │ ├── ActionLiveness.cpp │ │ ├── ActionStatementsToCoro.cpp │ │ ├── AddOutOfBoundsCheckPass.cpp │ │ ├── AddPreconditionsCheckPass.cpp │ │ ├── Attrs.cpp │ │ ├── Attrs.td │ │ ├── ConstraintsAnalysis.cpp │ │ ├── Conversion.cpp │ │ ├── DebugInfo.cpp │ │ ├── Dialect.cpp │ │ ├── Dialect.td │ │ ├── EmitEnumEntitiesPass.cpp │ │ ├── EmitImplicitAssignPass.cpp │ │ ├── EmitImplicitDestructorInvocationsPass.cpp │ │ ├── EmitImplicitInitPass.cpp │ │ ├── EmitMain.cpp │ │ ├── Enums.cpp │ │ ├── Enums.td │ │ ├── ExtractPreconditionPass.cpp │ │ ├── HoistAllocaPass.cpp │ │ ├── InstantiateTemplatesPass.cpp │ │ ├── Interfaces.cpp │ │ ├── Interfaces.td │ │ ├── LowerActionPass.cpp │ │ ├── LowerArrayCalls.cpp │ │ ├── LowerAssertsPass.cpp │ │ ├── LowerAssignPass.cpp │ │ ├── LowerConstructOpPass.cpp │ │ ├── LowerForFieldOpPass.cpp │ │ ├── LowerForLoopsPass.cpp │ │ ├── LowerInitializerListsPass.cpp │ │ ├── LowerIsOperationsPass.cpp │ │ ├── LowerSubActionStatements.cpp │ │ ├── LowerSubActionsPass.cpp │ │ ├── LowerToCf.cpp │ │ ├── MembeFunctionsToRegularFunctionsPass.cpp │ │ ├── Operations.cpp │ │ ├── Operations.td │ │ ├── OverloadResolver.cpp │ │ ├── Passes.td │ │ ├── PrintIRPass.cpp │ │ ├── RemoveUninitConstructsPass.cpp │ │ ├── RemoveUselessAllocaPass.cpp │ │ ├── RewriteCallSignaturesPass.cpp │ │ ├── SerializeRLPass.cpp │ │ ├── SortTypeDeclarationsPass.cpp │ │ ├── SymbolTable.cpp │ │ ├── TypeCheck.cpp │ │ ├── TypeInterface.cpp │ │ ├── Types.cpp │ │ ├── Types.td │ │ └── UncheckedAstToDot.cpp │ └── test │ │ ├── CMakeLists.txt │ │ ├── filecheck │ │ ├── entity-declaration.ll │ │ └── entity-to-global.ll │ │ ├── lit.cfg.py │ │ ├── lit.site.cfg.py.in │ │ └── src │ │ └── DialectTest.cpp ├── driver │ ├── CMakeLists.txt │ ├── driverConfig.cmake │ ├── include │ │ └── rlc │ │ │ └── driver │ │ │ └── Driver.hpp │ ├── src │ │ └── Driver.cpp │ └── test │ │ ├── CMakeLists.txt │ │ └── src │ │ └── Driver.cpp ├── fuzzer │ ├── CMakeLists.txt │ ├── fuzzerConfig.cmake │ ├── include │ │ └── Fuzzer.hpp │ └── src │ │ └── fuzz_target.cpp ├── lsp │ ├── CMakeLists.txt │ ├── include │ │ └── rlc │ │ │ └── lsp │ │ │ ├── LSP.hpp │ │ │ ├── LSPContext.hpp │ │ │ └── Protocol.hpp │ ├── lspConfig.cmake │ ├── src │ │ ├── LSP.cpp │ │ ├── LSPContext.cpp │ │ └── Protocol.cpp │ └── test │ │ ├── CMakeLists.txt │ │ └── src │ │ └── LSPTest.cpp ├── parser │ ├── CMakeLists.txt │ ├── include │ │ └── rlc │ │ │ └── parser │ │ │ ├── Lexer.hpp │ │ │ ├── MultiFileParser.hpp │ │ │ └── Parser.hpp │ ├── parserConfig.cmake │ ├── src │ │ ├── Lexer.cpp │ │ ├── MultiFileParser.cpp │ │ └── Parser.cpp │ └── test │ │ ├── CMakeLists.txt │ │ └── src │ │ ├── LexerTester.cpp │ │ └── ParserTest.cpp ├── runtime │ ├── CMakeLists.txt │ ├── include │ │ └── rlc │ │ │ └── runtime │ │ │ └── Runtime.h │ ├── runtimeConfig.cmake │ ├── src │ │ └── Runtime.c │ └── test │ │ ├── CMakeLists.txt │ │ └── src │ │ └── Parse.cpp └── utils │ ├── CMakeLists.txt │ ├── benchmark │ ├── CMakeLists.txt │ └── src │ │ ├── BattleshipBenchmark.cpp │ │ ├── CatchBenchmark.cpp │ │ ├── CheckersBenchmark.cpp │ │ ├── ConnectFourBenchmark.cpp │ │ ├── DictIntBenchBenchmark.cpp │ │ ├── GameUtils.hpp │ │ ├── HanabiBenchmark.cpp │ │ ├── RLDictWrapper.hpp │ │ ├── TicTacToeBenchmark.cpp │ │ ├── dictBenchmark.cpp │ │ └── utilsBenchmark.cpp │ ├── include │ └── rlc │ │ └── utils │ │ ├── Error.hpp │ │ ├── IRange.hpp │ │ ├── MCTS.hpp │ │ ├── PatternMatcher.hpp │ │ ├── ScopeGuard.hpp │ │ └── SimpleIterator.hpp │ ├── src │ ├── Error.cpp │ └── Utils.cpp │ ├── test │ ├── CMakeLists.txt │ └── src │ │ └── ScopeGuard.cpp │ └── utilsConfig.cmake ├── macros.cmake ├── plot.py ├── python ├── MANIFEST.in ├── action.py ├── command_line │ ├── __init__.py │ └── utils.py ├── disassembly.py ├── fix_ray.py ├── learn.py ├── llmplayer.py ├── make_report.py ├── ml │ ├── __init__.py │ ├── env.py │ └── ppg │ │ ├── __init__.py │ │ ├── constants.py │ │ ├── distr_builder.py │ │ ├── envs.py │ │ ├── graph.py │ │ ├── graph_util.py │ │ ├── impala_cnn.py │ │ ├── log_save_helper.py │ │ ├── logger.py │ │ ├── minibatch_optimize.py │ │ ├── ppg.py │ │ ├── ppo.py │ │ ├── reward_normalizer.py │ │ ├── roller.py │ │ ├── tic_tac_toe.py │ │ ├── torch_util.py │ │ ├── train.py │ │ ├── tree_util.py │ │ └── vec_monitor2.py ├── native │ └── call_python.c ├── play.py ├── probs.py ├── rlc │ ├── __init__.py │ ├── llm_runner.py │ ├── program.py │ └── program_graph.py ├── setup.py ├── solve.py ├── test.py └── test │ ├── __init__.py │ └── example_test.py ├── requirements.txt ├── rlcConfig.cmake.in ├── run-requirements.txt ├── setup.sh ├── stdlib ├── action.rl ├── algorithms │ └── equal.rl ├── bounded_arg.rl ├── collections │ ├── dictionary.rl │ ├── graph.rl │ ├── pair.rl │ └── vector.rl ├── enum_utils.rl ├── learn.rl ├── machine_learning.rl ├── math │ └── numeric.rl ├── none.rl ├── python.rl ├── range.rl ├── serialization │ ├── key_equal.rl │ ├── print.rl │ ├── to_byte_vector.rl │ └── to_hash.rl └── string.rl └── tool ├── CMakeLists.txt ├── rlc-doc ├── CMakeLists.txt └── src │ └── Main.cpp ├── rlc-fuzz-lsp ├── CMakeLists.txt └── src │ └── Main.cpp ├── rlc-fuzz ├── CMakeLists.txt └── src │ └── Main.cpp ├── rlc-lsp ├── CMakeLists.txt └── src │ └── Main.cpp ├── rlc-mlir-lsp ├── CMakeLists.txt └── src │ └── Main.cpp ├── rlc-opt ├── CMakeLists.txt └── src │ └── Main.cpp ├── rlc-tblgen ├── CMakeLists.txt └── src │ └── Main.cpp ├── rlc-to-mlir ├── CMakeLists.txt └── src │ └── Main.cpp └── rlc ├── CMakeLists.txt ├── src ├── LibNames.hpp.in └── Main.cpp └── test ├── CMakeLists.txt ├── DefaultInitializedOwningPtr.rl ├── GlobalConstant.rl ├── GlobalIntInType.rl ├── OneSubAction.rl ├── ReturnReference.rl ├── SameNameActions.rl ├── StringSerializationInStruct.rl ├── UsingType.rl ├── action_leak.rl ├── action_trait.rl ├── addition_associates_left.rl ├── alias_type_used_in_structs.rl ├── all_actions_O2.rl ├── all_actions_alternative_type.rl ├── alloca_entity.rl ├── alterantive.rl ├── alterantive_in_alternative.rl ├── alternative_actions.rl ├── alternative_actions_print.rl ├── alternative_serialization.rl ├── alternative_subaction.rl ├── alternative_to_string.rl ├── array_access.rl ├── array_access_reference.rl ├── array_deduction.rl ├── array_test.rl ├── assign.rl ├── assign_integer.rl ├── bit_and.rl ├── bit_not.rl ├── bit_or.rl ├── bit_xor.rl ├── bool_array_literal.rl ├── bounded_arg_test.rl ├── bounded_byte.rl ├── bounded_vector_tensor_serialization.rl ├── break_test.rl ├── bug_multiple_can_apply_definitions.rl ├── byte.rl ├── can_apply_ctx.rl ├── can_call.rl ├── cannot_exec_action.rl ├── captured_reference_in_precondition.rl ├── cast_bool_to_bool.rl ├── cast_test.rl ├── char_literal.rl ├── char_literal_string_literal_comparison.rl ├── comment_as_first_line.rl ├── conditionally_spilled.rl ├── constant_is_subaction_context.rl ├── constraint ├── CA_1.rl ├── CA_10.rl ├── CA_11.rl ├── CA_12.rl ├── CA_13.rl ├── CA_2.rl ├── CA_3.rl ├── CA_4.rl ├── CA_5.rl ├── CA_6.rl ├── CA_7.rl ├── CA_8.rl └── CA_9.rl ├── context_arg.rl ├── context_subaction.rl ├── continue_test.rl ├── count_actions.rl ├── crashes ├── array_overflow.rl ├── array_underflow.rl ├── illegal_argument.rl └── unexpected_subaction.rl ├── custom_init.rl ├── declaration.rl ├── destructor.rl ├── destructor_after_if.rl ├── dict_clear.rl ├── dict_contains.rl ├── dict_empty.rl ├── dict_get.rl ├── dict_init.rl ├── dict_insert.rl ├── dict_int_bench.rl ├── dict_keys.rl ├── dict_leak.rl ├── dict_remove.rl ├── dict_size.rl ├── dict_struct_key.rl ├── dict_values.rl ├── dict_vector_key.rl ├── dict_vector_value.rl ├── either_subaction.rl ├── elseif.rl ├── enum.rl ├── enum_field_expression.rl ├── enum_tensor_serialization.rl ├── enum_to_string.rl ├── enumerate_action_nested.rl ├── enumerate_alternative_bounded_arg_test.rl ├── enumerate_bounded_arg_test.rl ├── enumerate_enum.rl ├── enumerate_test.rl ├── enumeration_errors.rl ├── equality_trait.rl ├── examples ├── 2players_texas_holdem.rl ├── battleship.rl ├── black_jack.rl ├── catch.rl ├── checkers.rl ├── connect_four.rl ├── hanabi.rl ├── sequence.rl ├── simplest_example.rl ├── sky_tower.rl ├── space_hulk │ ├── board.rl │ ├── direction.rl │ ├── main.rl │ ├── move.rl │ ├── traces.rl │ └── unit.rl ├── stock_dump.rl └── sudoku.rl ├── extern_fun.rl ├── for_field.rl ├── for_field_multiple_inputs.rl ├── for_loop.rl ├── for_loop_action.rl ├── for_loop_break.rl ├── for_loop_continue.rl ├── for_loop_vector.rl ├── frm_ctx_alterantive_upcast.rl ├── from_string.rl ├── function_argument.rl ├── get_custom_operator.rl ├── global_using_type.rl ├── graph_test.rl ├── hidden_info_tensor_serialization.rl ├── if_else.rl ├── implicit_assigment.rl ├── import_test.rl ├── include_tic_tac_toe.rl ├── initializer_list.rl ├── is.rl ├── is_done.rl ├── is_trait.rl ├── isa_in_for_field.rl ├── left_shift_text.rl ├── lit.cfg.py ├── lit.site.cfg.py.in ├── load_action_file.rl ├── load_file_test.rl ├── local_var_in_array_initializer.rl ├── long_name_action_print.rl ├── loop_alloca.rl ├── malloc_before_break.rl ├── malloc_before_continue.rl ├── mangled_name.rl ├── member_function.rl ├── messages ├── action_in_if.rl ├── action_in_itself.rl ├── action_statement_in_function.rl ├── actions_with_different_args.rl ├── assert_crash.rl ├── assign_wrong_type.rl ├── assign_wrong_type_struct.rl ├── assign_wrong_type_struct_struct.rl ├── assign_wrong_type_struct_template.rl ├── assign_wrong_type_struct_union.rl ├── call_to_void_function.rl ├── continue_without_loop.rl ├── double_trait_definition.rl ├── empty_field_name.rl ├── empty_initializer_list.rl ├── error.rl ├── frm_in_fun_decl.rl ├── incorrect_byte_conversion.rl ├── invalid_frame_var.rl ├── missing_final_return.rl ├── missing_function.rl ├── missing_return.rl ├── missing_var_in_action.rl ├── missing_variable.rl ├── missmatched_argument_count.rl ├── multiple_same_name_actions.rl ├── no_action_recursion_allowed.rl ├── no_know_type_named.rl ├── non_int_array_access.rl ├── not_enough_template_arguments.rl ├── private_function_access.rl ├── private_member_access.rl ├── return_in_void_function.rl ├── subactions_nonactions.rl ├── tensorable_warnings.rl ├── too_many_template_types_error.rl ├── wrong_action_return_type.rl ├── wrong_ref_return_type.rl └── wrong_type.rl ├── minus.rl ├── multiaction_end.rl ├── multiple_precondition.rl ├── named_for_field.rl ├── negative_global_constant.rl ├── nested_for_loops.rl ├── nested_free_returned_copy.rl ├── nexted_action.rl ├── non_instantiated_template_assign.rl ├── not_test.rl ├── parse_and_execute_from_byte_vector.rl ├── parse_array.rl ├── parse_bool.rl ├── parse_double.rl ├── parse_false.rl ├── pebble_game.rl ├── precondition_on_context_args.rl ├── prereq.rl ├── print_parse_custom_type_name.rl ├── print_parse_enum.rl ├── reaching_definitions.rl ├── recursive_template.rl ├── recursive_template_entity.rl ├── removeUninitConstructTest.rl ├── right_shift.rl ├── sanitize_should_detect_leaks.rl ├── shortcircuiting_or.rl ├── shortcircuiting_value.rl ├── simple_struct.rl ├── simplest_template.rl ├── string_append.rl ├── string_concat.rl ├── string_literal_access.rl ├── string_literal_on_boundery.rl ├── string_parse_float.rl ├── string_parse_int.rl ├── string_reverse.rl ├── string_suffix.rl ├── string_test.rl ├── struct_to_string.rl ├── subaction.rl ├── subaction_bounded_args.rl ├── subaction_expression.rl ├── subaction_in_struct.rl ├── subaction_vending_machine.rl ├── subaction_with_expression.rl ├── subtemplate.rl ├── template.rl ├── template_array.rl ├── template_can_call.rl ├── template_custom_assign.rl ├── template_destructor.rl ├── template_entity.rl ├── template_in_class_only.rl ├── template_member_function.rl ├── tensor_serialization.rl ├── test_action.rl ├── test_and.rl ├── test_apply_action.rl ├── test_malloc.rl ├── test_member_alternative_assign.rl ├── test_pair.rl ├── test_print.rl ├── test_trace_runner.rl ├── tic_tac_toe.rl ├── to_be_fuzzed.rl ├── to_byte_vector_serialization.rl ├── to_from_byte_array.rl ├── trailing_comments.rl ├── trait.rl ├── trait_in_function_body.rl ├── tutorial ├── 2.rl ├── 3.rl └── START_HERE.rl ├── upcasting_is.rl ├── user_of_action_statement_type.rl ├── using_type_directly.rl ├── var_decl_in_template_is.rl ├── vector_assign.rl ├── vector_in_action.rl ├── vector_in_actions_does_not_leak.rl ├── vector_in_loop.rl ├── void_definition.rl ├── while_after_action.rl ├── while_test.rl ├── wrappers ├── action_with_frame_vars.rl ├── c_function.rl ├── call_function.rl ├── callpython.rl ├── csharp_action.rl ├── csharp_alias.rl ├── csharp_call.rl ├── csharp_custom_functions.rl ├── csharp_enums.rl ├── csharp_struct_decl.rl ├── csharp_union.rl ├── csharp_vector.rl ├── custom_abort.rl ├── godot_wrapper.rl ├── python_enum.rl ├── python_primitive_types.rl ├── python_templates.rl └── wrap_rlc_object_into_ctypes_pointer.rl ├── write_reference.rl └── zero_terminated_string_literal.rl /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v2 12 | - name: fetch-llvm 13 | run: wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 15 all && sudo apt-get install libmlir-15-dev mlir-15-tools 14 | - name: showllvm 15 | run: ls /lib/cmake/ 16 | - name: collect-dependencies 17 | run: git submodule update --recursive --init 18 | - name: build 19 | run: mkdir build && cd build && cmake ../ && make all -j4 && make test 20 | 21 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "benchmark"] 2 | path = benchmark 3 | url = https://github.com/google/benchmark.git 4 | [submodule "googletest"] 5 | path = googletest 6 | url = https://github.com/google/googletest.git 7 | -------------------------------------------------------------------------------- /.pylintrc: -------------------------------------------------------------------------------- 1 | [MASTER] 2 | init-hook="from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.dirname(find_pylintrc()))" 3 | [MESSAGES CONTROL] 4 | disable=C0326,missing-docstring,invalid-name,trailing-whitespace 5 | 6 | -------------------------------------------------------------------------------- /CPackConfig.cmake: -------------------------------------------------------------------------------- 1 | include("release/CPackConfig.cmake") 2 | set(CPACK_INSTALL_CMAKE_PROJECTS "build;example;ALL;/" "release;example;ALL;/") 3 | -------------------------------------------------------------------------------- /dbg_env.sh: -------------------------------------------------------------------------------- 1 | DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 2 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"$DIR/../rlc-release/install/lib/" 3 | export PATH=$PATH:"$DIR/../rlc-release/install/bin/" 4 | 5 | -------------------------------------------------------------------------------- /dockerfiles/mac-build: -------------------------------------------------------------------------------- 1 | FROM sickcodes/docker-osx:auto 2 | 3 | COPY ~/.ssh/mac-build-machine ./.ssh/ 4 | 5 | RUN softwareupdate -i "Command Line Tools for Xcode-12.4" --verbose && ssh-add ./.ssh/mac-build-machine && git clone git@github.com:rl-language/rlc.git && cd rlc && ./setup.sh && echo alpine | sudo --stdin /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile && brew install ninja && brew install cmake && rlc-infrastructure/rlc && source environment.sh && cd .. && python ./rlc/build.py --no-use-lld 6 | -------------------------------------------------------------------------------- /docs/machine_learning.dot: -------------------------------------------------------------------------------- 1 | digraph loop { 2 | node[shape=box]; 3 | "initial state" -> "machine learning" [label="state"]; 4 | "machine learning" -> "game rules" [label="\naction"]; 5 | "game rules" -> "machine learning" [label="next state"]; 6 | } 7 | -------------------------------------------------------------------------------- /docs/poster-fioravanti.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/docs/poster-fioravanti.pdf -------------------------------------------------------------------------------- /docs/sky_tower_report_example.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/docs/sky_tower_report_example.pdf -------------------------------------------------------------------------------- /docs/sphinx_doc/_static/custom.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/docs/sphinx_doc/_static/custom.css -------------------------------------------------------------------------------- /docs/sphinx_doc/imgs/RLC_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/docs/sphinx_doc/imgs/RLC_logo.png -------------------------------------------------------------------------------- /docs/sphinx_doc/imgs/generation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/docs/sphinx_doc/imgs/generation.png -------------------------------------------------------------------------------- /docs/sphinx_doc/imgs/lines_of_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/docs/sphinx_doc/imgs/lines_of_code.png -------------------------------------------------------------------------------- /docs/sphinx_doc/imgs/machine_learning_rules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/docs/sphinx_doc/imgs/machine_learning_rules.png -------------------------------------------------------------------------------- /docs/sphinx_doc/imgs/mean_reward.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/docs/sphinx_doc/imgs/mean_reward.png -------------------------------------------------------------------------------- /docs/sphinx_doc/imgs/ml_progress.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/docs/sphinx_doc/imgs/ml_progress.jpeg -------------------------------------------------------------------------------- /docs/sphinx_doc/imgs/mono_behaviour.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/docs/sphinx_doc/imgs/mono_behaviour.webp -------------------------------------------------------------------------------- /docs/sphinx_doc/imgs/moore_law.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/docs/sphinx_doc/imgs/moore_law.jpg -------------------------------------------------------------------------------- /docs/sphinx_doc/imgs/performance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/docs/sphinx_doc/imgs/performance.png -------------------------------------------------------------------------------- /docs/sphinx_doc/imgs/rl_game_progress.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/docs/sphinx_doc/imgs/rl_game_progress.webp -------------------------------------------------------------------------------- /docs/sphinx_doc/imgs/sh_board1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/docs/sphinx_doc/imgs/sh_board1.png -------------------------------------------------------------------------------- /docs/sphinx_doc/imgs/sh_board2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/docs/sphinx_doc/imgs/sh_board2.png -------------------------------------------------------------------------------- /docs/sphinx_doc/imgs/sh_board3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/docs/sphinx_doc/imgs/sh_board3.png -------------------------------------------------------------------------------- /docs/sphinx_doc/imgs/tensorboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/docs/sphinx_doc/imgs/tensorboard.png -------------------------------------------------------------------------------- /docs/sphinx_doc/imgs/tensorboard2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/docs/sphinx_doc/imgs/tensorboard2.png -------------------------------------------------------------------------------- /docs/sphinx_doc/stdlib/algorithms/equal.md: -------------------------------------------------------------------------------- 1 | # equal.rl 2 | 3 | ## Free Functions 4 | 5 | - **Function**: `custom_equal(Int lhs, Int rhs) -> Bool` 6 | - **Function**: `custom_equal(Bool lhs, Bool rhs) -> Bool` 7 | - **Function**: `custom_equal(Byte lhs, Byte rhs) -> Bool` 8 | - **Function**: `custom_equal(Float lhs, Float rhs) -> Bool` 9 | - **Function**: `custom_equal(T[X] lhs, T[X] rhs) -> Bool` 10 | - **Function**: `equal(T lhs, T rhs) -> Bool` 11 | 12 | ```text 13 | Nof fully impelemted, do not use 14 | 15 | ``` 16 | 17 | 18 | ## Traits 19 | 20 | ## Trait Comparable 21 | 22 | - **Function**: `custom_equal(T lhs, T rhs) -> Bool` 23 | 24 | 25 | -------------------------------------------------------------------------------- /docs/sphinx_doc/stdlib/algorithms/index.rst: -------------------------------------------------------------------------------- 1 | algorithms 2 | ========== 3 | 4 | 5 | .. toctree:: 6 | :maxdepth: 2 7 | :caption: algorithms: 8 | :glob: 9 | 10 | ./* 11 | -------------------------------------------------------------------------------- /docs/sphinx_doc/stdlib/collections/index.rst: -------------------------------------------------------------------------------- 1 | collections 2 | =========== 3 | 4 | 5 | .. toctree:: 6 | :maxdepth: 2 7 | :caption: collections: 8 | :glob: 9 | 10 | ./* 11 | -------------------------------------------------------------------------------- /docs/sphinx_doc/stdlib/collections/pair.md: -------------------------------------------------------------------------------- 1 | # pair.rl 2 | 3 | ## Class Pair 4 | 5 | 6 | ```text 7 | A parameterized container with two fields, first and second 8 | 9 | ``` 10 | 11 | ### Fields 12 | - `T1 first` 13 | - `T2 second` 14 | 15 | ## Free Functions 16 | 17 | - **Function**: `zip(Vector x, Vector y) -> Vector>` 18 | 19 | ```text 20 | Accepts two vectors x, y of types T1, T2 of any length and returns 21 | a vector with length equal to the shortest of the lengths of the 22 | two input vectors. output.get(i).first == x.get(i) and 23 | output.get(i).second == y.get(i) for all i from 0 to output.length() 24 | 25 | ``` 26 | 27 | 28 | -------------------------------------------------------------------------------- /docs/sphinx_doc/stdlib/enum_utils.md: -------------------------------------------------------------------------------- 1 | # enum_utils.rl 2 | 3 | ## Traits 4 | 5 | ## Trait Enum 6 | 7 | 8 | ```text 9 | 10 | Copyright 2024 Massimo Fioravanti 11 | 12 | Licensed under the Apache License, Version 2.0 (the "License"); 13 | you may not use this file except in compliance with the License. 14 | You may obtain a copy of the License at 15 | 16 | http://www.apache.org/licenses/LICENSE-2.0 17 | 18 | Unless required by applicable law or agreed to in writing, software 19 | distributed under the License is distributed on an "AS IS" BASIS, 20 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | See the License for the specific language governing permissions and 22 | limitations under the License. 23 | 24 | 25 | ``` 26 | 27 | - **Function**: `max(T obj) -> Int` 28 | - **Function**: `is_enum(T obj) -> Bool` 29 | - **Function**: `as_int(T obj) -> Int` 30 | - **Function**: `from_int(T obj, Int new_value) ` 31 | - **Function**: `as_string_literal(T obj) -> StringLiteral` 32 | 33 | 34 | -------------------------------------------------------------------------------- /docs/sphinx_doc/stdlib/index.rst: -------------------------------------------------------------------------------- 1 | stdlib 2 | ====== 3 | 4 | 5 | .. toctree:: 6 | :maxdepth: 1 7 | :caption: Contents: 8 | :glob: 9 | 10 | ./*/index 11 | ./* 12 | -------------------------------------------------------------------------------- /docs/sphinx_doc/stdlib/learn.md: -------------------------------------------------------------------------------- 1 | # learn.rl 2 | 3 | ## Free Functions 4 | 5 | - **Function**: `gen_printer_parser() ` 6 | 7 | -------------------------------------------------------------------------------- /docs/sphinx_doc/stdlib/math/index.rst: -------------------------------------------------------------------------------- 1 | math 2 | ==== 3 | 4 | 5 | .. toctree:: 6 | :maxdepth: 2 7 | :caption: math: 8 | :glob: 9 | 10 | ./* 11 | -------------------------------------------------------------------------------- /docs/sphinx_doc/stdlib/math/numeric.md: -------------------------------------------------------------------------------- 1 | # numeric.rl 2 | 3 | ## Free Functions 4 | 5 | - **Function**: `max(Int a, Int b) -> Int` 6 | 7 | ```text 8 | Copyright 2024 Massimo Fioravanti 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | returns the max between two numbers 22 | 23 | ``` 24 | 25 | - **Function**: `min(Int a, Int b) -> Int` 26 | 27 | ```text 28 | retursn the min between two numbers 29 | 30 | ``` 31 | 32 | - **Function**: `sqrt(Float f) -> Float` 33 | - **Function**: `abs(Int a) -> Int` 34 | 35 | -------------------------------------------------------------------------------- /docs/sphinx_doc/stdlib/none.md: -------------------------------------------------------------------------------- 1 | # none.rl 2 | 3 | ## Class Nothing 4 | 5 | 6 | ```text 7 | 8 | Part of the RLC Project, under the MIT license. 9 | See stdlib/LICENSE.TXT for license information. 10 | SPDX-License-Identifier: MIT 11 | 12 | A class to rapresent the absence of information 13 | usefull to implement functions that return optionals 14 | fun maybe_int() -> Int | Nothing: 15 | 16 | ``` 17 | 18 | ### Fields 19 | 20 | ## Free Functions 21 | 22 | - **Function**: `none() -> Nothing` 23 | 24 | -------------------------------------------------------------------------------- /docs/sphinx_doc/stdlib/range.md: -------------------------------------------------------------------------------- 1 | # range.rl 2 | 3 | ## Class Range 4 | 5 | ### Fields 6 | 7 | ### Methods 8 | - **Function**: `get(Int i) -> Int` 9 | - **Function**: `size() -> Int` 10 | - **Function**: `set_size(Int new_size) ` 11 | 12 | ## Free Functions 13 | 14 | - **Function**: `range(Int size) -> Range` 15 | 16 | -------------------------------------------------------------------------------- /docs/sphinx_doc/stdlib/serialization/index.rst: -------------------------------------------------------------------------------- 1 | serialization 2 | ============= 3 | 4 | 5 | .. toctree:: 6 | :maxdepth: 2 7 | :caption: serialization: 8 | :glob: 9 | 10 | ./* 11 | -------------------------------------------------------------------------------- /docs/sphinx_doc/stdlib/serialization/key_equal.md: -------------------------------------------------------------------------------- 1 | # key_equal.rl 2 | 3 | ## Free Functions 4 | 5 | - **Function**: `compute_equal(Int value1, Int value2) -> Bool` 6 | - **Function**: `compute_equal(Float value1, Float value2) -> Bool` 7 | - **Function**: `compute_equal(Bool value1, Bool value2) -> Bool` 8 | - **Function**: `compute_equal(Byte value1, Byte value2) -> Bool` 9 | - **Function**: `compute_equal(Vector vector1, Vector vector2) -> Bool` 10 | - **Function**: `compute_equal(T[N] array1, T[N] array2) -> Bool` 11 | - **Function**: `compute_equal_of(T value1, T value2) -> Bool` 12 | 13 | ## Traits 14 | 15 | ## Trait KeyEquivalent 16 | 17 | - **Function**: `compute_equal(T first, T second) -> Bool` 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/sphinx_doc/stdlib/serialization/print.md: -------------------------------------------------------------------------------- 1 | # print.rl 2 | 3 | ## Free Functions 4 | 5 | - **Function**: `print_string(String s) ` 6 | - **Function**: `print_string_lit(StringLiteral s) ` 7 | - **Function**: `print(T to_print) ` 8 | 9 | ```text 10 | print a arbitrary object to stdout 11 | 12 | ``` 13 | 14 | - **Function**: `print_indented(T to_print) ` 15 | 16 | ```text 17 | print a arbitrary object to stdout on multiple 18 | lines and indented 19 | 20 | ``` 21 | 22 | 23 | -------------------------------------------------------------------------------- /docs/sphinx_doc/stdlib/serialization/to_hash.md: -------------------------------------------------------------------------------- 1 | # to_hash.rl 2 | 3 | ## Free Functions 4 | 5 | - **Function**: `compute_hash(Int value) -> Int` 6 | 7 | ```text 8 | Specialized implementations for basic types 9 | 10 | ``` 11 | 12 | - **Function**: `compute_hash(Float value) -> Int` 13 | - **Function**: `compute_hash(Bool value) -> Int` 14 | - **Function**: `compute_hash(Byte value) -> Int` 15 | - **Function**: `compute_hash(String str) -> Int` 16 | 17 | ```text 18 | Add String hashing - assuming a String type exists 19 | Using FNV-1a hash algorithm which is fast and has good distribution 20 | 21 | ``` 22 | 23 | - **Function**: `compute_hash(Vector vector) -> Int` 24 | 25 | ```text 26 | Implementations for collections 27 | 28 | ``` 29 | 30 | - **Function**: `compute_hash(T[N] array) -> Int` 31 | - **Function**: `compute_hash_of(T value) -> Int` 32 | 33 | ```text 34 | The public interface 35 | 36 | ``` 37 | 38 | 39 | ## Traits 40 | 41 | ## Trait Hashable 42 | 43 | - **Function**: `compute_hash(T to_hash) -> Int` 44 | 45 | 46 | -------------------------------------------------------------------------------- /environment.bat: -------------------------------------------------------------------------------- 1 | ..\.venv\Scripts\activate.bat 2 | @set LIBPATH=%LIBPATH%;C:\Users\mofio\Documents\rlc-infrastructure\llvm-install-release\lib 3 | @set PATH=%PATH%;C:\Users\mofio\Documents\rlc-infrastructure\llvm-install-release\bin 4 | -------------------------------------------------------------------------------- /environment.fish: -------------------------------------------------------------------------------- 1 | set -x LD_LIBRARY_PATH (realpath ../llvm-install-release/lib):$LD_LIBRARY_PATH 2 | set -x LD_LIBRARY_PATH (realpath ../llvm-install-debug/lib):$LD_LIBRARY_PATH 3 | set -x PATH (realpath ../llvm-install-release/bin/):$PATH 4 | source ../.venv/bin/activate.fish 5 | -------------------------------------------------------------------------------- /environment.sh: -------------------------------------------------------------------------------- 1 | DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 2 | source $DIR/../.venv/bin/activate 3 | export LD_LIBRARY_PATH="$DIR/../llvm-install-release/lib/":$LD_LIBRARY_PATH 4 | export LD_LIBRARY_PATH="$DIR/../llvm-install-debug/lib/":$LD_LIBRARY_PATH 5 | export PATH="$DIR/../llvm-install-release/bin/":$PATH 6 | if [ "$(uname)" == "Darwin" ]; then 7 | export SDKROOT=$(xcrun --sdk macosx --show-sdk-path) 8 | fi 9 | -------------------------------------------------------------------------------- /fish_dbg_env.fish: -------------------------------------------------------------------------------- 1 | set -x LD_LIBRARY_PATH (realpath ../rlc-release/install/lib/) ; 2 | set -x PATH (realpath ../rlc-release/install/bin/) $PATH 3 | -------------------------------------------------------------------------------- /imgs/RLC_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/imgs/RLC_logo.png -------------------------------------------------------------------------------- /imgs/generation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/imgs/generation.png -------------------------------------------------------------------------------- /imgs/lines_of_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/imgs/lines_of_code.png -------------------------------------------------------------------------------- /imgs/machine_learning_rules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/imgs/machine_learning_rules.png -------------------------------------------------------------------------------- /imgs/mean_reward.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/imgs/mean_reward.png -------------------------------------------------------------------------------- /imgs/ml_progress.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/imgs/ml_progress.jpeg -------------------------------------------------------------------------------- /imgs/mono_behaviour.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/imgs/mono_behaviour.webp -------------------------------------------------------------------------------- /imgs/moore_law.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/imgs/moore_law.jpg -------------------------------------------------------------------------------- /imgs/performance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/imgs/performance.png -------------------------------------------------------------------------------- /imgs/rl_game_progress.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/imgs/rl_game_progress.webp -------------------------------------------------------------------------------- /imgs/sh_board1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/imgs/sh_board1.png -------------------------------------------------------------------------------- /imgs/sh_board2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/imgs/sh_board2.png -------------------------------------------------------------------------------- /imgs/sh_board3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/imgs/sh_board3.png -------------------------------------------------------------------------------- /imgs/tensorboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/imgs/tensorboard.png -------------------------------------------------------------------------------- /imgs/tensorboard2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/imgs/tensorboard2.png -------------------------------------------------------------------------------- /lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(utils) 2 | add_subdirectory(parser) 3 | add_subdirectory(dialect) 4 | add_subdirectory(conversions) 5 | add_subdirectory(backend) 6 | add_subdirectory(lsp) 7 | add_subdirectory(driver) 8 | add_subdirectory(fuzzer) 9 | add_subdirectory(runtime) 10 | -------------------------------------------------------------------------------- /lib/backend/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | rlcAddLibrary(backend src/BackEnd.cpp) 2 | llvm_map_components_to_libnames(llvm_utils_libs Support) 3 | llvm_map_components_to_libnames(llvm_libs core ipo vectorize instcombine target scalaropts objcarcopts ${LLVM_TARGETS_TO_BUILD}) 4 | target_link_libraries(backend 5 | PRIVATE 6 | rlc::parser 7 | rlc::conversions 8 | rlc::dialect 9 | ${llvm_utils_libs} 10 | MLIRTargetLLVMIRExport 11 | LLVMCodeGen 12 | LLVMAnalysis 13 | LLVMMC 14 | LLVMTransformUtils 15 | LLVMPasses 16 | LLVMOption 17 | LLVMInstrumentation 18 | LLVMAggressiveInstCombine 19 | MLIRLLVMToLLVMIRTranslation 20 | MLIRLLVMCommonConversion 21 | MLIRTargetLLVMIRExport 22 | MLIRTranslateLib 23 | MLIRSPIRVDialect 24 | lldCOFF 25 | clangDriver 26 | clangBasic 27 | ${dialect_libs} 28 | ${translation_libs} 29 | ${llvm_libs} 30 | ) 31 | 32 | -------------------------------------------------------------------------------- /lib/backend/backendConfig.cmake: -------------------------------------------------------------------------------- 1 | include(CmakeFindDependencyMacro) 2 | 3 | include(${CMAKE_CURRENT_LIST_DIR}/backendTargets.cmake) 4 | -------------------------------------------------------------------------------- /lib/backend/test/CMakeLists.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/lib/backend/test/CMakeLists.txt -------------------------------------------------------------------------------- /lib/conversions/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | rlcAddLibrary(conversions src/RLCToPython.cpp src/RLCToC.cpp src/RLCToCPass.cpp src/RLCToCSharp.cpp) 2 | llvm_map_components_to_libnames(llvm_utils_libs Support) 3 | target_link_libraries(conversions PUBLIC ${llvm_utils_libs} rlc::dialect) 4 | 5 | -------------------------------------------------------------------------------- /lib/conversions/conversionsConfig.cmake: -------------------------------------------------------------------------------- 1 | include(CmakeFindDependencyMacro) 2 | 3 | include(${CMAKE_CURRENT_LIST_DIR}/utilsTargets.cmake) 4 | -------------------------------------------------------------------------------- /lib/conversions/include/rlc/conversions/CSharpConversions.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2025 Massimo Fioravanti 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "rlc/dialect/Operations.hpp" 19 | #include "rlc/utils/PatternMatcher.hpp" 20 | 21 | namespace mlir::rlc 22 | { 23 | 24 | } // namespace mlir::rlc 25 | -------------------------------------------------------------------------------- /lib/conversions/include/rlc/conversions/RLCToC.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Massimo Fioravanti 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "mlir/IR/BuiltinOps.h" 19 | 20 | namespace rlc 21 | { 22 | void rlcToCHeader(mlir::ModuleOp Module, llvm::raw_ostream& OS); 23 | void rlcToGodot(mlir::ModuleOp Module, llvm::raw_ostream& OS); 24 | } // namespace rlc 25 | -------------------------------------------------------------------------------- /lib/dialect/dialectConfig.cmake: -------------------------------------------------------------------------------- 1 | include(CmakeFindDependencyMacro) 2 | 3 | include(${CMAKE_CURRENT_LIST_DIR}/utilsTargets.cmake) 4 | -------------------------------------------------------------------------------- /lib/dialect/include/rlc/dialect/ActionLiveness.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Massimo Fioravanti 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "mlir/Analysis/Liveness.h" 19 | #include "rlc/dialect/Operations.hpp" 20 | 21 | namespace mlir::rlc 22 | { 23 | 24 | } // namespace mlir::rlc 25 | -------------------------------------------------------------------------------- /lib/dialect/include/rlc/dialect/Attrs.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Massimo Fioravanti 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | #pragma once 17 | #include "mlir/IR/DialectImplementation.h" 18 | #include "mlir/IR/OpDefinition.h" 19 | #include "mlir/IR/Operation.h" 20 | #include "mlir/IR/TypeSupport.h" 21 | #include "mlir/IR/Types.h" 22 | 23 | #define GET_ATTRDEF_CLASSES 24 | #include "rlc/dialect/Attrs.inc" 25 | -------------------------------------------------------------------------------- /lib/dialect/include/rlc/dialect/Dialect.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "mlir/Dialect/LLVMIR/LLVMDialect.h" 4 | #include "mlir/IR/Dialect.h" 5 | #include "rlc/dialect/Dialect.inc" 6 | 7 | namespace mlir::rlc 8 | { 9 | mlir::LogicalResult logRemark(mlir::Operation *op, llvm::Twine twine); 10 | mlir::LogicalResult logError(mlir::Operation *op, llvm::Twine twine); 11 | void moveCastsNearUses(mlir::ModuleOp module); 12 | } // namespace mlir::rlc 13 | -------------------------------------------------------------------------------- /lib/dialect/include/rlc/dialect/Enums.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Massimo Fioravanti 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "mlir/IR/Attributes.h" 19 | #include "mlir/IR/BuiltinAttributes.h" 20 | #include "mlir/IR/BuiltinTypes.h" 21 | 22 | // 23 | #include "rlc/dialect/Enums.inc" 24 | -------------------------------------------------------------------------------- /lib/dialect/include/rlc/dialect/IRBuilder.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /* 3 | Copyright 2024 Massimo Fioravanti 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | 18 | #include "mlir/IR/Builders.h" 19 | #include "rlc/dialect/Operations.hpp" 20 | 21 | namespace mlir::rlc 22 | { 23 | template 24 | class IRBuilderWrapper: public Base 25 | { 26 | public: 27 | using Base::Base; 28 | #include "rlc/dialect/Builder.inc" 29 | }; 30 | 31 | using IRBuilder = IRBuilderWrapper; 32 | 33 | } // namespace mlir::rlc 34 | -------------------------------------------------------------------------------- /lib/dialect/include/rlc/dialect/Interfaces.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Massimo Fioravanti 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "mlir/Transforms/DialectConversion.h" 19 | #include "rlc/dialect/Dialect.h" 20 | #include "rlc/dialect/SymbolTable.h" 21 | 22 | namespace mlir 23 | { 24 | class IRRewriter; 25 | } 26 | 27 | namespace mlir::rlc 28 | { 29 | class ConstraintsLattice; 30 | class SourceRangeAttr; 31 | class ConstraintsAnalysis; 32 | } // namespace mlir::rlc 33 | 34 | #include "rlc/dialect/Interfaces.inc" 35 | -------------------------------------------------------------------------------- /lib/dialect/include/rlc/dialect/Passes.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Massimo Fioravanti 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "mlir/Pass/Pass.h" 19 | #include "rlc/dialect/Dialect.h" 20 | 21 | namespace mlir::rlc 22 | { 23 | struct TargetInfo; 24 | #define GEN_PASS_DECL 25 | #include "rlc/dialect/Passes.inc" 26 | 27 | #define GEN_PASS_REGISTRATION 28 | #include "rlc/dialect/Passes.inc" 29 | 30 | } // namespace mlir::rlc 31 | -------------------------------------------------------------------------------- /lib/dialect/include/rlc/dialect/SerializationContext.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Massimo Fioravanti 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | namespace mlir::rlc 20 | { 21 | class SerializationContext 22 | { 23 | public: 24 | private: 25 | }; 26 | } // namespace mlir::rlc 27 | -------------------------------------------------------------------------------- /lib/dialect/include/rlc/dialect/TypeInterfaces.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Massimo Fioravanti 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "mlir/Transforms/DialectConversion.h" 19 | #include "rlc/dialect/Dialect.h" 20 | #include "rlc/dialect/SerializationContext.hpp" 21 | // 22 | 23 | #include "rlc/dialect/TypeInterfaces.inc" 24 | -------------------------------------------------------------------------------- /lib/dialect/src/Enums.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Massimo Fioravanti 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | #include "rlc/dialect/Enums.hpp" 17 | // 18 | #include "Enums.inc" 19 | -------------------------------------------------------------------------------- /lib/dialect/src/Enums.td: -------------------------------------------------------------------------------- 1 | include "mlir/IR/EnumAttr.td" 2 | include "mlir/IR/OpBase.td" 3 | 4 | -------------------------------------------------------------------------------- /lib/dialect/src/Interfaces.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Massimo Fioravanti 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | #include "rlc/dialect/Attrs.hpp" 17 | // 18 | #include "rlc/dialect/Interfaces.hpp" 19 | 20 | // 21 | #include "Interfaces.inc" 22 | -------------------------------------------------------------------------------- /lib/dialect/src/TypeInterface.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Massimo Fioravanti 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | #include "rlc/dialect/TypeInterfaces.hpp" 17 | // 18 | #include "TypeInterfaces.inc" 19 | -------------------------------------------------------------------------------- /lib/dialect/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | rlcAddTest(dialect src/DialectTest.cpp) 2 | 3 | -------------------------------------------------------------------------------- /lib/dialect/test/filecheck/entity-to-global.ll: -------------------------------------------------------------------------------- 1 | // RUN: rlc-opt -rlc-lower-to-llvm %s | FileCheck %s 2 | 3 | // CHECK-LABEL: module @unknown 4 | 5 | #field_info = #rlc.class_field<"asd" : !rlc.int<64>> 6 | #field_info1 = #rlc.class_field<"tasd" : !rlc.int<64>> 7 | #loc = loc("/tmp/asd.rl":2:5) 8 | #loc1 = loc("/tmp/asd.rl":2:8) 9 | #loc2 = loc("/tmp/asd.rl":3:5) 10 | #loc3 = loc("/tmp/asd.rl":3:8) 11 | #loc4 = loc("/tmp/asd.rl":1:5) 12 | #loc5 = loc("/tmp/asd.rl":1:6) 13 | !C_0_ = !rlc.class>, #rlc.class_field<"tasd" : !rlc.int<64>>, }> 14 | #shugar_type = #rlc.shugarized_type<<#loc, #loc1> !rlc.int<64>> 15 | #shugar_type1 = #rlc.shugarized_type<<#loc2, #loc3> !rlc.int<64>> 16 | module @unknown { 17 | %0 = rlc.class_decl "Asd" [#rlc.class_field_declaration<#field_info shugarized = #shugar_type>, #rlc.class_field_declaration<#field_info1 shugarized = #shugar_type1>] !C_0_ { 18 | } location = <#loc4, #loc5> 19 | } 20 | -------------------------------------------------------------------------------- /lib/driver/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | rlcAddLibrary(driver src/Driver.cpp) 2 | llvm_map_components_to_libnames(llvm_utils_libs Support) 3 | target_link_libraries(driver PUBLIC ${llvm_utils_libs} rlc::dialect rlc::parser rlc::backend rlc::conversions ) 4 | 5 | -------------------------------------------------------------------------------- /lib/driver/driverConfig.cmake: -------------------------------------------------------------------------------- 1 | include(CmakeFindDependencyMacro) 2 | 3 | include(${CMAKE_CURRENT_LIST_DIR}/utilsTargets.cmake) 4 | -------------------------------------------------------------------------------- /lib/driver/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | rlcAddTest(driver src/Driver.cpp) 2 | -------------------------------------------------------------------------------- /lib/driver/test/src/Driver.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Massimo Fioravanti 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | #include "gtest/gtest.h" 17 | 18 | TEST(driverTest, example) {} 19 | -------------------------------------------------------------------------------- /lib/fuzzer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | rlcAddLibrary(fuzzer STATIC src/fuzz_target.cpp) 2 | llvm_map_components_to_libnames(llvm_utils_libs Support) 3 | target_link_libraries(fuzzer) 4 | if(APPLE) 5 | #target_compile_options(fuzzer PRIVATE -undefined dynamic_lookup) 6 | target_link_options(fuzzer PRIVATE -undefined dynamic_lookup) 7 | endif() 8 | -------------------------------------------------------------------------------- /lib/fuzzer/fuzzerConfig.cmake: -------------------------------------------------------------------------------- 1 | include(CmakeFindDependencyMacro) 2 | 3 | include(${CMAKE_CURRENT_LIST_DIR}/fuzzerTargets.cmake) -------------------------------------------------------------------------------- /lib/fuzzer/include/Fuzzer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | -------------------------------------------------------------------------------- /lib/lsp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | rlcAddLibrary(lsp src/LSP.cpp src/LSPContext.cpp src/Protocol.cpp) 2 | target_link_libraries(lsp PUBLIC MLIRLspServerLib rlc::parser) 3 | 4 | -------------------------------------------------------------------------------- /lib/lsp/lspConfig.cmake: -------------------------------------------------------------------------------- 1 | include(CmakeFindDependencyMacro) 2 | 3 | include(${CMAKE_CURRENT_LIST_DIR}/utilsTargets.cmake) 4 | -------------------------------------------------------------------------------- /lib/lsp/src/LSPContext.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Massimo Fioravanti 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | #include "rlc/lsp/LSPContext.hpp" 17 | 18 | using namespace mlir::rlc::lsp; 19 | -------------------------------------------------------------------------------- /lib/lsp/src/Protocol.cpp: -------------------------------------------------------------------------------- 1 | #include "rlc/lsp/Protocol.hpp" 2 | 3 | bool mlir::rlc::lsp::fromJSON( 4 | const llvm::json::Value &value, 5 | mlir::rlc::lsp::RenameParams &result, 6 | llvm::json::Path path) 7 | { 8 | llvm::json::ObjectMapper o(value, path); 9 | if (!o) 10 | return false; 11 | // We deliberately don't fail if we can't parse individual fields. 12 | return o.map("textDocument", result.textDocument) and 13 | o.map("newName", result.newName) and 14 | o.map("position", result.position); 15 | } 16 | -------------------------------------------------------------------------------- /lib/lsp/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | rlcAddTest(lsp src/LSPTest.cpp) 2 | -------------------------------------------------------------------------------- /lib/lsp/test/src/LSPTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Massimo Fioravanti 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #include "gtest/gtest.h" 18 | 19 | TEST(LSPTest, exampleTest) { EXPECT_EQ(5, 5); } 20 | -------------------------------------------------------------------------------- /lib/parser/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | rlcAddLibrary(parser src/Lexer.cpp src/Parser.cpp src/MultiFileParser.cpp) 2 | target_link_libraries(parser PUBLIC 3 | rlc::utils 4 | rlc::dialect) 5 | 6 | -------------------------------------------------------------------------------- /lib/parser/parserConfig.cmake: -------------------------------------------------------------------------------- 1 | include(CmakeFindDependencyMacro) 2 | 3 | include(${CMAKE_CURRENT_LIST_DIR}/lexerTargets.cmake) 4 | -------------------------------------------------------------------------------- /lib/parser/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | rlcAddTest(parser 2 | src/LexerTester.cpp 3 | src/ParserTest.cpp) 4 | -------------------------------------------------------------------------------- /lib/runtime/runtimeConfig.cmake: -------------------------------------------------------------------------------- 1 | include(CmakeFindDependencyMacro) 2 | 3 | -------------------------------------------------------------------------------- /lib/runtime/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | rlcAddTest(runtime src/Parse.cpp) 2 | -------------------------------------------------------------------------------- /lib/utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | rlcAddLibrary(utils src/Utils.cpp src/Error.cpp) 2 | llvm_map_components_to_libnames(llvm_utils_libs Support) 3 | target_link_libraries(utils PUBLIC ${llvm_utils_libs}) 4 | 5 | -------------------------------------------------------------------------------- /lib/utils/benchmark/src/BattleshipBenchmark.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Massimo Fioravanti 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #define RLC_GET_FUNCTION_DECLS 21 | #define RLC_GET_TYPE_DECLS 22 | #define RLC_GET_TYPE_DEFS 23 | #include "Battleship.h" 24 | 25 | // 26 | const constexpr char* name = "battleship_rlc"; 27 | #include "GameUtils.hpp" 28 | -------------------------------------------------------------------------------- /lib/utils/benchmark/src/CatchBenchmark.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Samuele Pasini 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #define RLC_GET_FUNCTION_DECLS 18 | #define RLC_GET_TYPE_DECLS 19 | #define RLC_GET_TYPE_DEFS 20 | #include 21 | #include 22 | #include 23 | 24 | #include "Catch.h" 25 | // 26 | const constexpr char* name = "catch_rlc"; 27 | #include "GameUtils.hpp" 28 | -------------------------------------------------------------------------------- /lib/utils/benchmark/src/CheckersBenchmark.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Massimo Fioravanti 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #define RLC_GET_FUNCTION_DECLS 18 | #define RLC_GET_TYPE_DECLS 19 | #define RLC_GET_TYPE_DEFS 20 | #include 21 | #include 22 | #include 23 | 24 | #include "Checkers.h" 25 | // 26 | const constexpr char* name = "checkers_rlc"; 27 | #include "GameUtils.hpp" 28 | -------------------------------------------------------------------------------- /lib/utils/benchmark/src/ConnectFourBenchmark.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Samuele Pasini 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #define RLC_GET_FUNCTION_DECLS 18 | #define RLC_GET_TYPE_DECLS 19 | #define RLC_GET_TYPE_DEFS 20 | #include 21 | #include 22 | #include 23 | 24 | #include "ConnectFour.h" 25 | // 26 | const constexpr char* name = "connect_four_rlc"; 27 | #include "GameUtils.hpp" 28 | -------------------------------------------------------------------------------- /lib/utils/benchmark/src/HanabiBenchmark.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Massimo Fioravanti 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #define RLC_GET_FUNCTION_DECLS 18 | #define RLC_GET_TYPE_DECLS 19 | #define RLC_GET_TYPE_DEFS 20 | #include 21 | #include 22 | #include 23 | 24 | #include "Hanabi.h" 25 | // 26 | const constexpr char* name = "hanabi_rlc"; 27 | #include "GameUtils.hpp" 28 | -------------------------------------------------------------------------------- /lib/utils/benchmark/src/TicTacToeBenchmark.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Massimo Fioravanti 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #define RLC_GET_FUNCTION_DECLS 18 | #define RLC_GET_TYPE_DECLS 19 | #define RLC_GET_TYPE_DEFS 20 | #include 21 | #include 22 | #include 23 | 24 | #include "TicTacToe.h" 25 | // 26 | const constexpr char* name = "tic_tac_toe_rlc"; 27 | #include "GameUtils.hpp" 28 | -------------------------------------------------------------------------------- /lib/utils/src/Utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Massimo Fioravanti 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | -------------------------------------------------------------------------------- /lib/utils/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | rlcAddTest(utils src/ScopeGuard.cpp) 2 | -------------------------------------------------------------------------------- /lib/utils/test/src/ScopeGuard.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 Massimo Fioravanti 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | #include "rlc/utils/ScopeGuard.hpp" 17 | 18 | #include "gtest/gtest.h" 19 | 20 | using namespace rlc; 21 | 22 | TEST(ScopeGuardTest, scopeGuardShouldRestoreInteger) 23 | { 24 | int val = 4; 25 | { 26 | auto g = makeGuard([&]() { val++; }); 27 | } 28 | 29 | EXPECT_EQ(val, 5); 30 | } 31 | -------------------------------------------------------------------------------- /lib/utils/utilsConfig.cmake: -------------------------------------------------------------------------------- 1 | include(CmakeFindDependencyMacro) 2 | 3 | include(${CMAKE_CURRENT_LIST_DIR}/utilsTargets.cmake) 4 | -------------------------------------------------------------------------------- /python/MANIFEST.in: -------------------------------------------------------------------------------- 1 | include rlc-bin/* 2 | recursive-include lib * 3 | -------------------------------------------------------------------------------- /python/command_line/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of the RLC project. 3 | # 4 | # RLC is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. 5 | # 6 | # RLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 7 | # 8 | # You should have received a copy of the GNU General Public License along with RLC. If not, see . 9 | # 10 | from .utils import ( 11 | make_rlc_argparse, 12 | load_program_from_args, 13 | get_included_conents_from_args, 14 | ) 15 | -------------------------------------------------------------------------------- /python/fix_ray.py: -------------------------------------------------------------------------------- 1 | import ray.rllib.algorithms.ppo.ppo as ppo 2 | import os 3 | 4 | 5 | def main(): 6 | found = False 7 | file_path = os.path.join(os.path.dirname(ppo.__file__), "ppo.py") 8 | contents = None 9 | with open(file_path, "r") as file: 10 | contents = file.readlines() 11 | for line in contents: 12 | if "default=0," in line: 13 | found = True 14 | 15 | if found: 16 | print("ppo.py was already fixed") 17 | exit() 18 | 19 | contents.insert(535, " ,default=0,\n") 20 | 21 | with open(file_path, "w") as file: 22 | file.writelines(contents) 23 | 24 | print(file_path + " patched, you can now run rlc") 25 | 26 | 27 | if __name__ == "__main__": 28 | main() 29 | -------------------------------------------------------------------------------- /python/ml/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of the RLC project. 3 | # 4 | # RLC is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. 5 | # 6 | # RLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 7 | # 8 | # You should have received a copy of the GNU General Public License along with RLC. If not, see . 9 | # 10 | -------------------------------------------------------------------------------- /python/ml/ppg/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rl-language/rlc/be8eb7c730d002adb70d2072a17bbec2cbcef13c/python/ml/ppg/__init__.py -------------------------------------------------------------------------------- /python/rlc/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of the RLC project. 3 | # 4 | # RLC is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. 5 | # 6 | # RLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 7 | # 8 | # You should have received a copy of the GNU General Public License along with RLC. If not, see . 9 | # 10 | from .program import Program, compile, State, get_included_contents 11 | from .llm_runner import make_llm, run_game, Ollama, Gemini, GeminiStateless 12 | from .program_graph import parse_call_graph, Node, CallGraph, NodeKind 13 | -------------------------------------------------------------------------------- /python/test/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of the RLC project. 3 | # 4 | # RLC is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. 5 | # 6 | # RLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 7 | # 8 | # You should have received a copy of the GNU General Public License along with RLC. If not, see . 9 | # 10 | -------------------------------------------------------------------------------- /python/test/example_test.py: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of the RLC project. 3 | # 4 | # RLC is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. 5 | # 6 | # RLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 7 | # 8 | # You should have received a copy of the GNU General Public License along with RLC. If not, see . 9 | # 10 | def test_true(): 11 | assert True 12 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | vulture 2 | pytest 3 | pylint 4 | lit 5 | -r run-requirements.txt 6 | -------------------------------------------------------------------------------- /run-requirements.txt: -------------------------------------------------------------------------------- 1 | torch 2 | numpy 3 | gym3 4 | tensorboard 5 | matplotlib 6 | standard-imghdr; python_version >= '3.13' 7 | -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | if ! [ -x "$(command -v python3)" ]; then 4 | echo 'Error: python3 is not installed.' >&2 5 | exit 1 6 | fi 7 | 8 | if ! [ -x "$(command -v cmake)" ]; then 9 | echo 'Error: cmake is not installed.' >&2 10 | exit 1 11 | fi 12 | 13 | if ! [ -x "$(command -v ninja)" ]; then 14 | echo 'Error: ninja is not installed.' >&2 15 | exit 1 16 | fi 17 | 18 | mkdir rlc-infrastructure 19 | cd rlc-infrastructure 20 | 21 | # INSTALL RLC 22 | git clone https://github.com/rl-language/rlc.git 23 | 24 | # SETUP PYTHON 25 | python3 -m pip install virtualenv --user 26 | python3 -m virtualenv .venv 27 | source .venv/bin/activate 28 | pip install -r rlc/requirements.txt 29 | deactivate 30 | 31 | cd rlc 32 | source ./rlc/environment.sh 33 | git submodule init 34 | git submodule update --recursive 35 | cd .. 36 | 37 | -------------------------------------------------------------------------------- /stdlib/algorithms/equal.rl: -------------------------------------------------------------------------------- 1 | trait Comparable: 2 | fun custom_equal(T lhs, T rhs) -> Bool 3 | 4 | fun custom_equal(Int lhs, Int rhs) -> Bool: 5 | return lhs == rhs 6 | 7 | fun custom_equal(Bool lhs, Bool rhs) -> Bool: 8 | return lhs == rhs 9 | 10 | fun custom_equal(Byte lhs, Byte rhs) -> Bool: 11 | return lhs == rhs 12 | 13 | fun custom_equal(Float lhs, Float rhs) -> Bool: 14 | return lhs == rhs 15 | 16 | fun custom_equal(T[X] lhs, T[X] rhs) -> Bool: 17 | let counter = 0 18 | while counter < X: 19 | if !equal(lhs, rhs): 20 | return false 21 | counter = counter + 1 22 | return true 23 | 24 | # Nof fully impelemted, do not use 25 | fun equal(T lhs, T rhs) -> Bool: 26 | if lhs is Comparable: 27 | if rhs is Comparable: 28 | return custom_equal(lhs, rhs) 29 | for field, field2 of lhs, rhs: 30 | using T2 = type(field) 31 | if field2 is T2: 32 | if !equal(field, field2): 33 | return false 34 | return true 35 | -------------------------------------------------------------------------------- /stdlib/enum_utils.rl: -------------------------------------------------------------------------------- 1 | # 2 | #Copyright 2024 Massimo Fioravanti 3 | # 4 | #Licensed under the Apache License, Version 2.0 (the "License"); 5 | #you may not use this file except in compliance with the License. 6 | #You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | #Unless required by applicable law or agreed to in writing, software 11 | #distributed under the License is distributed on an "AS IS" BASIS, 12 | #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | #See the License for the specific language governing permissions and 14 | #limitations under the License. 15 | # 16 | 17 | trait Enum: 18 | fun max(T obj) -> Int 19 | fun is_enum(T obj) -> Bool 20 | fun as_int(T obj) -> Int 21 | fun from_int(T obj, Int new_value) 22 | fun as_string_literal(T obj) -> StringLiteral 23 | -------------------------------------------------------------------------------- /stdlib/learn.rl: -------------------------------------------------------------------------------- 1 | # 2 | #Copyright 2024 Massimo Fioravanti 3 | # 4 | #Licensed under the Apache License, Version 2.0 (the "License"); 5 | #you may not use this file except in compliance with the License. 6 | #You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | #Unless required by applicable law or agreed to in writing, software 11 | #distributed under the License is distributed on an "AS IS" BASIS, 12 | #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | #See the License for the specific language governing permissions and 14 | #limitations under the License. 15 | # 16 | 17 | import action 18 | 19 | fun gen_printer_parser(): 20 | let state : Game 21 | let any_action : AnyGameAction 22 | gen_python_methods(state, any_action) 23 | 24 | -------------------------------------------------------------------------------- /stdlib/math/numeric.rl: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Massimo Fioravanti 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # returns the max between two numbers 16 | fun max(Int a, Int b) -> Int: 17 | if a > b: 18 | return a 19 | return b 20 | 21 | # retursn the min between two numbers 22 | fun min(Int a, Int b) -> Int: 23 | if b > a: 24 | return a 25 | return b 26 | 27 | ext fun sqrt(Float f) -> Float 28 | 29 | fun abs(Int a) -> Int: 30 | if 0 > a: 31 | return -a 32 | return a 33 | -------------------------------------------------------------------------------- /stdlib/none.rl: -------------------------------------------------------------------------------- 1 | # 2 | # Part of the RLC Project, under the MIT license. 3 | # See stdlib/LICENSE.TXT for license information. 4 | # SPDX-License-Identifier: MIT 5 | # 6 | 7 | # A class to rapresent the absence of information 8 | # usefull to implement functions that return optionals 9 | # fun maybe_int() -> Int | Nothing: 10 | cls Nothing: 11 | Bool _dont_care 12 | 13 | fun none() -> Nothing: 14 | let to_return : Nothing 15 | return to_return 16 | -------------------------------------------------------------------------------- /stdlib/range.rl: -------------------------------------------------------------------------------- 1 | ## Copyright 2025 Massimo Fioravanti 2 | ## 3 | ## Licensed under the Apache License, Version 2.0 (the "License"); 4 | ## you may not use this file except in compliance with the License. 5 | ## You may obtain a copy of the License at 6 | ## 7 | ## http://www.apache.org/licenses/LICENSE-2.0 8 | ## 9 | ## Unless required by applicable law or agreed to in writing, software 10 | ## distributed under the License is distributed on an "AS IS" BASIS, 11 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | ## See the License for the specific language governing permissions and 13 | ## limitations under the License. 14 | 15 | cls Range: 16 | Int _size 17 | 18 | fun get(Int i) -> Int: 19 | return i 20 | 21 | fun size() -> Int: 22 | return self._size 23 | 24 | fun set_size(Int new_size): 25 | self._size = new_size 26 | 27 | fun range(Int size) -> Range: 28 | let range : Range 29 | range.set_size(size) 30 | return range 31 | -------------------------------------------------------------------------------- /tool/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(rlc) 2 | add_subdirectory(rlc-to-mlir) 3 | add_subdirectory(rlc-opt) 4 | add_subdirectory(rlc-lsp) 5 | add_subdirectory(rlc-fuzz) 6 | add_subdirectory(rlc-fuzz-lsp) 7 | add_subdirectory(rlc-doc) 8 | add_subdirectory(rlc-mlir-lsp) 9 | add_subdirectory(rlc-tblgen) 10 | -------------------------------------------------------------------------------- /tool/rlc-doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | rlcAddTool(rlc-doc rlc::parser) 2 | -------------------------------------------------------------------------------- /tool/rlc-fuzz-lsp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | IF (WIN32) 2 | ELSE() 3 | get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) 4 | get_property(translation_libs GLOBAL PROPERTY MLIR_TRANSLATION_LIBS) 5 | rlcAddTool(rlc-fuzz-lsp 6 | rlc::lsp 7 | MLIRLLVMToLLVMIRTranslation 8 | MLIRLLVMCommonConversion 9 | MLIRTargetLLVMIRExport 10 | MLIRTranslateLib 11 | MLIRSPIRVDialect 12 | ${dialect_libs} 13 | ${translation_libs} 14 | ) 15 | 16 | target_link_options(rlc-fuzz-lsp PUBLIC -fsanitize=fuzzer) 17 | ENDIF() 18 | -------------------------------------------------------------------------------- /tool/rlc-fuzz/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | IF (WIN32) 2 | ELSE() 3 | get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) 4 | get_property(translation_libs GLOBAL PROPERTY MLIR_TRANSLATION_LIBS) 5 | rlcAddTool(rlc-fuzz 6 | rlc::driver 7 | rlc::backend 8 | MLIRLLVMToLLVMIRTranslation 9 | MLIRLLVMCommonConversion 10 | MLIRTargetLLVMIRExport 11 | MLIRTranslateLib 12 | MLIRSPIRVDialect 13 | ${dialect_libs} 14 | ${translation_libs} 15 | ) 16 | 17 | target_link_options(rlc-fuzz PUBLIC -fsanitize=fuzzer) 18 | ENDIF() 19 | -------------------------------------------------------------------------------- /tool/rlc-lsp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | rlcAddTool(rlc-lsp rlc::lsp) 2 | -------------------------------------------------------------------------------- /tool/rlc-mlir-lsp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) 2 | rlcAddTool(rlc-mlir-lsp 3 | rlc::parser 4 | rlc::backend 5 | rlc::conversions 6 | rlc::dialect 7 | MLIRLspServerLib 8 | ${dialect_libs}) 9 | -------------------------------------------------------------------------------- /tool/rlc-opt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) 2 | rlcAddTool(rlc-opt 3 | rlc::parser 4 | rlc::backend 5 | rlc::conversions 6 | rlc::dialect 7 | MLIROptLib 8 | ${dialect_libs}) 9 | -------------------------------------------------------------------------------- /tool/rlc-tblgen/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | get_property(translation_libs GLOBAL PROPERTY MLIR_TRANSLATION_LIBS) 2 | rlcAddTool(rlc-tblgen 3 | MLIRTblgenLib 4 | LLVMTableGen 5 | MLIRTableGen 6 | ${dialect_libs} 7 | ${llvm_libs} 8 | ${translation_libs}) 9 | target_include_directories(rlc-tblgen PUBLIC ${MLIR_INCLUDE_DIRS}) 10 | -------------------------------------------------------------------------------- /tool/rlc-to-mlir/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | rlcAddTool(rlc-to-mlir 2 | rlc::parser 3 | MLIRTranslateLib) 4 | -------------------------------------------------------------------------------- /tool/rlc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) 2 | get_property(translation_libs GLOBAL PROPERTY MLIR_TRANSLATION_LIBS) 3 | llvm_map_components_to_libnames(llvm_libs core ipo vectorize instcombine target scalaropts objcarcopts ${LLVM_TARGETS_TO_BUILD}) 4 | rlcAddTool(rlc 5 | rlc::parser 6 | rlc::conversions 7 | rlc::backend 8 | rlc::driver 9 | MLIRTargetLLVMIRExport 10 | LLVMCodeGen 11 | LLVMAnalysis 12 | LLVMMC 13 | LLVMTransformUtils 14 | LLVMPasses 15 | LLVMInstrumentation 16 | LLVMAggressiveInstCombine 17 | MLIRLLVMToLLVMIRTranslation 18 | MLIRLLVMCommonConversion 19 | MLIRTargetLLVMIRExport 20 | MLIRTranslateLib 21 | MLIRSPIRVDialect 22 | ${dialect_libs} 23 | ${translation_libs} 24 | ${llvm_libs}) 25 | 26 | file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/include/rlc/LibNames.hpp INPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/LibNames.hpp.in) 27 | target_include_directories(rlc PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include) 28 | add_dependencies(rlc rlc::fuzzer rlc::runtime rlc::pyrlc) 29 | -------------------------------------------------------------------------------- /tool/rlc/src/LibNames.hpp.in: -------------------------------------------------------------------------------- 1 | auto const FUZZER_LIBRARY_FILENAME = "$"; 2 | auto const RUNTIME_LIBRARY_FILENAME = "$"; 3 | auto const PYRLC_LIBRARY_FILENAME = "$"; 4 | -------------------------------------------------------------------------------- /tool/rlc/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/fuzzer_lib_location.txt CONTENT "$") 2 | file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/runtime_lib_location.txt CONTENT "$") 3 | file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/pyrlc_lib_location.txt CONTENT "$") 4 | 5 | rlcAddLitTest(rlc) 6 | 7 | find_package(Python3 COMPONENTS Interpreter REQUIRED) 8 | add_test(NAME python_tic_tac_toe COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/python/solve.py ${CMAKE_CURRENT_SOURCE_DIR}/tic_tac_toe.rl --rlc $ --stdlib ${CMAKE_SOURCE_DIR}/stdlib/ --runtime $ --pyrlc $) 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /tool/rlc/test/DefaultInitializedOwningPtr.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o - --ir -O2 | FileCheck %s 2 | 3 | # CHECK-LABEL: define void @rl_m_init__Asd(ptr nocapture writeonly %0) local_unnamed_addr 4 | # CHECK: store ptr null, ptr %0, align 8 5 | cls Asd: 6 | OwningPtr a 7 | 8 | fun main() -> Int: 9 | return 0 10 | -------------------------------------------------------------------------------- /tool/rlc/test/GlobalConstant.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | const global = 3 5 | 6 | fun main() -> Int: 7 | let x : Int[global] 8 | if global == 3: 9 | return 0 10 | else: 11 | return -1 12 | -------------------------------------------------------------------------------- /tool/rlc/test/GlobalIntInType.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | const global = 3 5 | 6 | cls Asd: 7 | fun get_t() -> Int: 8 | return T 9 | 10 | using Fixed = Asd 11 | 12 | fun main() -> Int: 13 | let x : Fixed 14 | if x.get_t() == 3: 15 | return 0 16 | else: 17 | return -1 18 | -------------------------------------------------------------------------------- /tool/rlc/test/OneSubAction.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | act to_run() -> ToRun: 5 | frm to_ret : Int 6 | act dead_store(Int val) 7 | to_ret = val 8 | act to_call(Int val2) 9 | to_ret = val2 10 | act final(Int val3) 11 | to_ret = val3 12 | 13 | fun frame_creator() -> ToRun: 14 | let frame = to_run() 15 | frame.dead_store(1) 16 | return frame 17 | 18 | act outer() -> Outer: 19 | subaction frame = frame_creator() 20 | frame.final(10) 21 | 22 | fun main() -> Int: 23 | let frame = outer() 24 | frame.to_call(4) 25 | return frame.frame.to_ret - 10 26 | -------------------------------------------------------------------------------- /tool/rlc/test/ReturnReference.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | cls Asd: 5 | Int x 6 | 7 | fun ret_x(Asd val) -> ref Int: 8 | return val.x 9 | 10 | fun main() -> Int: 11 | let var : Asd 12 | var.x = 10 13 | ref refvar = ret_x(var) 14 | var.x = 20 15 | return refvar - 20 16 | -------------------------------------------------------------------------------- /tool/rlc/test/SameNameActions.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | act action() -> Action: 5 | frm result = 5 6 | 7 | act first(Int x) 8 | result = x 9 | 10 | act first(Int x) 11 | result = x + x 12 | 13 | act outer() -> Outer: 14 | subaction* frame1 = action() 15 | subaction* frame2 = action() 16 | 17 | fun main() -> Int: 18 | let frame = outer() 19 | frame.first(1) 20 | frame.first(2) 21 | frame.first(4) 22 | frame.first(8) 23 | if !frame.is_done(): 24 | return -1 25 | return frame.frame2.result - 16 26 | -------------------------------------------------------------------------------- /tool/rlc/test/StringSerializationInStruct.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | import string 4 | import serialization.print 5 | 6 | cls Asd: 7 | String asd 8 | Int second 9 | 10 | fun main() -> Int: 11 | let asd : Asd 12 | asd.asd = "first"s 13 | asd.second = 5 14 | if "{asd: \"first\", second: 5}"s != to_string(asd): 15 | return 2 16 | let asd2 : Asd 17 | if !from_string(asd2, to_string(asd)): 18 | return 1 19 | return 0 20 | -------------------------------------------------------------------------------- /tool/rlc/test/UsingType.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | using T = type(6) 6 | let asd : T 7 | asd = 10 8 | return asd - 10 9 | -------------------------------------------------------------------------------- /tool/rlc/test/action_leak.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -i %stdlib -o %t --sanitize 2 | # RUN: %t%exeext 3 | import collections.vector 4 | 5 | act asd() -> Move: 6 | let vector : Vector 7 | act inner() 8 | 9 | fun main() -> Int: 10 | asd() 11 | return 0 12 | -------------------------------------------------------------------------------- /tool/rlc/test/action_trait.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | @classes 5 | act action() -> Action: 6 | frm to_return = 0 7 | act to_call(Int arg) 8 | to_return = arg 9 | 10 | 11 | fun main() -> Int: 12 | let x : ActionToCall 13 | if x is ActionAction: 14 | return 0 15 | else: 16 | return 1 17 | 18 | -------------------------------------------------------------------------------- /tool/rlc/test/addition_associates_left.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | return 0 - 1 + 1 6 | -------------------------------------------------------------------------------- /tool/rlc/test/alias_type_used_in_structs.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | cls Asd: 5 | Int content 6 | 7 | using T = Asd 8 | 9 | cls Tasd: 10 | T content 11 | 12 | fun main() -> Int: 13 | let x : Tasd 14 | if x.content is Asd: 15 | return 0 16 | return 1 17 | 18 | -------------------------------------------------------------------------------- /tool/rlc/test/all_actions_O2.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib -O2 2 | # RUN: %t%exeext 3 | 4 | import action 5 | import bounded_arg 6 | 7 | cls Asd: 8 | Bool field 9 | 10 | fun main() -> Int: 11 | let x : Asd | Bool 12 | let state = enumerate(x) 13 | print(state) 14 | return 0 15 | -------------------------------------------------------------------------------- /tool/rlc/test/all_actions_alternative_type.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import string 5 | 6 | @classes 7 | act play() -> Name: 8 | act first() 9 | act second(Int asd) 10 | 11 | fun main() -> Int: 12 | let any_action : AnyNameAction 13 | let second_action : NameSecond 14 | any_action = second_action 15 | if to_string(any_action) == "second {asd: 0}": 16 | return 0 17 | return 1 18 | -------------------------------------------------------------------------------- /tool/rlc/test/alloca_entity.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | cls some_entity: 5 | Int field 6 | Int field2 7 | 8 | fun main() -> Int: 9 | let var : some_entity 10 | let var2 : Int 11 | var.field2 = 10 12 | var.field2 = var.field2 - 10 13 | return var.field2 14 | -------------------------------------------------------------------------------- /tool/rlc/test/alterantive.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import collections.vector 5 | 6 | fun main() -> Int: 7 | let asd : Int | Float | Bool | Vector 8 | asd = false 9 | if asd is Float: 10 | return -2 11 | asd = 3 12 | if asd is Int: 13 | return asd - 3 14 | return -1 15 | -------------------------------------------------------------------------------- /tool/rlc/test/alterantive_in_alternative.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize 2 | # RUN: %t%exeext 3 | 4 | using Inner = Int | Float 5 | using Inner2 = Int | Float 6 | using Outer = Inner2 | Inner 7 | 8 | fun main() -> Int: 9 | let x : Outer 10 | if x is Inner2: 11 | return 0 12 | return 1 13 | -------------------------------------------------------------------------------- /tool/rlc/test/alternative_actions.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | act play() -> Play: 5 | frm z = 0 6 | actions: 7 | act mark(Int x, Int y) {x == 2} 8 | z = y 9 | 10 | act other_mark(Int x, Int y) {y == 2} 11 | z = x 12 | 13 | fun main() -> Int: 14 | let state = play() 15 | state.other_mark(3, 2) 16 | return state.z - 3 17 | -------------------------------------------------------------------------------- /tool/rlc/test/alternative_actions_print.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import serialization.print 5 | import string 6 | 7 | @classes 8 | act to_run() -> ToRun: 9 | act first(Bool asd) 10 | act second(Int tasd) 11 | 12 | fun main() -> Int: 13 | let x : ToRunFirst | ToRunSecond 14 | print(to_string(x)) 15 | if to_string(x) == "first {asd: false}": 16 | return 0 17 | return 1 18 | -------------------------------------------------------------------------------- /tool/rlc/test/alternative_serialization.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import collections.vector 5 | import serialization.to_byte_vector 6 | 7 | fun main() -> Int: 8 | let asd : Int | Float 9 | asd = 3.4 10 | 11 | let serialized = as_byte_vector(asd) 12 | let result : Int | Float 13 | from_byte_vector(result, serialized) 14 | 15 | if result is Float: 16 | return int(result - 3.4) 17 | else: 18 | return -1 19 | -------------------------------------------------------------------------------- /tool/rlc/test/alternative_to_string.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize 2 | # RUN: %t%exeext 3 | 4 | import string 5 | import collections.vector 6 | import serialization.print 7 | 8 | cls SomeStruct: 9 | Bool | Float x 10 | Vector y 11 | 12 | fun main() -> Int: 13 | let var : SomeStruct 14 | var.x = true 15 | var.y.append(3) 16 | var.y.append(4) 17 | if to_string(var) == "{x: Bool true, y: [3, 4]}": 18 | return 0 19 | return -1 20 | 21 | -------------------------------------------------------------------------------- /tool/rlc/test/array_access.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import machine_learning 5 | import collections.vector 6 | 7 | const NODE_SIZE = 1024 8 | 9 | cls NodeID: 10 | Int id 11 | 12 | cls Graph: 13 | Bool[NODE_SIZE] nodes 14 | Hidden[NODE_SIZE]> edges 15 | BoundedVector[NODE_SIZE] in_edges 16 | Hidden pebble_reserve 17 | Hidden max_used_pebble 18 | 19 | fun add_edge(Int source, Int target): 20 | let target_id : NodeID 21 | target_id.id = source 22 | self.in_edges[target].append(target_id) 23 | 24 | target_id.id = target 25 | self.edges.value[source].append(target_id) 26 | 27 | 28 | fun main() -> Int: 29 | let x : Graph 30 | x.add_edge(100, 200) 31 | return x.edges.value[16].size() 32 | 33 | 34 | -------------------------------------------------------------------------------- /tool/rlc/test/array_access_reference.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | let x : Int[4] 6 | x[2] = 10 7 | ref reference = x[2] 8 | reference = 2 9 | return x[2] - 2 10 | -------------------------------------------------------------------------------- /tool/rlc/test/array_deduction.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun f(X[T] x) -> X: 5 | let to_return = x[0] 6 | if x is Int[T]: 7 | if to_return is Int: 8 | to_return = to_return + T 9 | return to_return 10 | 11 | fun main() -> Int: 12 | let x : Int[4] 13 | x[0] = 5 14 | return f(x) - 9 15 | -------------------------------------------------------------------------------- /tool/rlc/test/array_test.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | let array : Int[10] 6 | let i = 0 7 | while i < 10: 8 | array[i] = i * i 9 | i = i + 1 10 | let array2 : Int[10] 11 | array2 = array 12 | return array2[7] - 49 13 | -------------------------------------------------------------------------------- /tool/rlc/test/assign.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | let a = 5 6 | a = a + 2 7 | if a == 7: 8 | return 0 9 | return 1 10 | -------------------------------------------------------------------------------- /tool/rlc/test/assign_integer.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | let a = 0 6 | let b = a 7 | b = b + 1 8 | return a 9 | -------------------------------------------------------------------------------- /tool/rlc/test/bit_and.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import serialization.print 5 | 6 | fun main() -> Int: 7 | let x = 2 & 3 8 | print(x) 9 | return x - 2 10 | -------------------------------------------------------------------------------- /tool/rlc/test/bit_not.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | let x = ~0 6 | return x + 1 7 | -------------------------------------------------------------------------------- /tool/rlc/test/bit_or.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | let x = 2 | 3 6 | return x - 3 7 | -------------------------------------------------------------------------------- /tool/rlc/test/bit_xor.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import serialization.print 5 | 6 | fun main() -> Int: 7 | let x = 2 ^ 3 8 | print(x) 9 | return x - 1 10 | -------------------------------------------------------------------------------- /tool/rlc/test/bool_array_literal.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | [true] 6 | return 0 7 | -------------------------------------------------------------------------------- /tool/rlc/test/bounded_arg_test.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | import bounded_arg 4 | import serialization.print 5 | 6 | fun main() -> Int: 7 | let x : BInt<0, 3> 8 | x.value = 2 9 | if to_string(x) != "2"s: 10 | return -1 11 | 12 | let loaded : BInt<0, 3> 13 | from_string(loaded, "2"s) 14 | if loaded != x: 15 | return -2 16 | 17 | let y = byte(-127) 18 | let out = as_byte_vector(y) 19 | 20 | from_byte_vector(loaded, out) 21 | 22 | if loaded.value != 1: 23 | return -2 24 | 25 | if as_byte_vector(loaded).size() != 1: 26 | return -3 27 | 28 | return 0 29 | -------------------------------------------------------------------------------- /tool/rlc/test/bounded_byte.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import serialization.to_byte_vector 5 | import collections.vector 6 | 7 | cls BoundedByte: 8 | Byte _value 9 | 10 | fun get() -> Byte: 11 | return self._value 12 | 13 | fun parse_from_vector(BoundedByte to_add, Vector input, Int index) -> Bool: 14 | if input.size() < index: 15 | return false 16 | let value = input.get(index) 17 | if value < byte(Min): 18 | value = byte(Min) 19 | if value >= byte(Max): 20 | value = byte(Max - 1) 21 | to_add._value = value 22 | index = index + 1 23 | return true 24 | 25 | fun main() -> Int: 26 | let val : BoundedByte<0, 4> 27 | let vector : Vector 28 | vector.append(byte(2)) 29 | from_byte_vector(val, vector) 30 | if val.get() != byte(2): 31 | return -1 32 | vector.pop() 33 | vector.append(byte(10)) 34 | from_byte_vector(val, vector) 35 | if val.get() != byte(3): 36 | return -1 37 | return 0 38 | 39 | -------------------------------------------------------------------------------- /tool/rlc/test/bounded_vector_tensor_serialization.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import action 5 | 6 | fun main() -> Int: 7 | let vec : Vector 8 | let v : BoundedVector 9 | 10 | v.append(false) 11 | v.append(true) 12 | let x = observation_tensor_size(v) 13 | print(observation_tensor_size(v)) 14 | while x != 0: 15 | vec.append(0.0) 16 | x = x - 1 17 | to_observation_tensor(v, 0, vec) 18 | if vec.size() != 5: 19 | return 1 20 | if vec.get(0) != 0.0: 21 | return 2 22 | if vec.get(1) != 1.0: 23 | return 3 24 | 25 | return 0 26 | -------------------------------------------------------------------------------- /tool/rlc/test/break_test.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | let x = 0 6 | while x != 6: 7 | while x != 10: 8 | x = x + 5 9 | break 10 | x = x + 1 11 | 12 | if x != 6: 13 | return -1 14 | 15 | while x != 10: 16 | x = x + 5 17 | break 18 | 19 | if x != 11: 20 | return -1 21 | 22 | while x != 16: 23 | x = x + 5 24 | 25 | return x - 16 26 | -------------------------------------------------------------------------------- /tool/rlc/test/bug_multiple_can_apply_definitions.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --fuzzer --fuzzer-lib=%fuzzer_lib 2 | # UNSUPPORTED: system-windows, system-darwin 3 | 4 | import action 5 | 6 | fun crash_on_five(Int input) -> Int {input != 5}: 7 | return 0 8 | 9 | @classes 10 | act play() -> Play: 11 | frm current = 0 12 | while current != 7: 13 | act subact(Int x) {x > 5, x < 15} 14 | current = x 15 | 16 | actions: 17 | act this(Int y, Int z) {z < 3, z > 0, y < 14, y >= 0 } 18 | current = y 19 | act that(Int a) {a >= 0, a < 100} 20 | crash_on_five(a) 21 | 22 | act subact(Int x) {x > -12, x < 3} 23 | 24 | fun fuzz(Vector input): 25 | let frame = play() 26 | let action : AnyPlayAction 27 | crash_on_five(5) 28 | parse_and_execute(frame, action, input) 29 | 30 | fun main() -> Int: 31 | return 0 32 | -------------------------------------------------------------------------------- /tool/rlc/test/byte.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | let var = byte(8) 6 | var = var - byte(7) 7 | var = var - byte(true) 8 | return int(var) 9 | -------------------------------------------------------------------------------- /tool/rlc/test/can_apply_ctx.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | @classes 5 | act asd(ctx Int arg) -> Inner: 6 | frm copy = arg 7 | act x() 8 | copy = copy + arg 9 | 10 | fun main() -> Int: 11 | let frame = asd(3) 12 | let action : AnyInnerAction 13 | apply(action, frame, 2) 14 | return frame.copy - 5 15 | 16 | -------------------------------------------------------------------------------- /tool/rlc/test/can_call.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun function(Int x) -> Int {x < 4}: 5 | return x - 1 6 | 7 | fun main() -> Int: 8 | if can function(5): 9 | return -4 10 | else if can function(1): 11 | return 0 12 | else: 13 | return 4 14 | -------------------------------------------------------------------------------- /tool/rlc/test/cannot_exec_action.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | act action() -> State: 5 | actions: 6 | act first() 7 | act second() 8 | 9 | fun main() -> Int: 10 | let state = action() 11 | if can state.second(): 12 | return -1 13 | return 0 14 | -------------------------------------------------------------------------------- /tool/rlc/test/captured_reference_in_precondition.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | act inner(frm Int local_var) -> Inner: 5 | act to_call(Int other){ 6 | other == local_var + 1 7 | } 8 | local_var = other 9 | 10 | act outer() -> Outer: 11 | subaction inner_frame = inner(5) 12 | 13 | fun main() -> Int: 14 | let outer_frame = outer() 15 | outer_frame.to_call(6) 16 | return outer_frame.inner_frame.local_var - 6 17 | -------------------------------------------------------------------------------- /tool/rlc/test/cast_bool_to_bool.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | return int(bool(false)) 6 | -------------------------------------------------------------------------------- /tool/rlc/test/cast_test.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | if (float(1) == float(true)): 6 | return int(bool(int(true) - int(float(1)))) 7 | return 1 8 | -------------------------------------------------------------------------------- /tool/rlc/test/char_literal.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | if '1' + byte(1) == '2': 6 | return 0 7 | return 1 8 | -------------------------------------------------------------------------------- /tool/rlc/test/char_literal_string_literal_comparison.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | if "1"[0] == '1': 6 | return 0 7 | return 1 8 | -------------------------------------------------------------------------------- /tool/rlc/test/comment_as_first_line.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | act asd() -> A: #asd 5 | # asd 6 | act f() 7 | return 8 | 9 | fun main() -> Int: #asd 10 | # asd 11 | return 0 #asd 12 | -------------------------------------------------------------------------------- /tool/rlc/test/conditionally_spilled.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | act test() -> Test: 5 | frm x = 0 6 | if x == 0: 7 | act asd(Int y) 8 | x = 1 9 | 10 | fun main() -> Int: 11 | let frame = test() 12 | frame.asd(1) 13 | return frame.x - 1 14 | -------------------------------------------------------------------------------- /tool/rlc/test/constant_is_subaction_context.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | cls Asd: 4 | Int y 5 | 6 | act inner(ctx Int inner) -> Inner: 7 | act something() 8 | 9 | act outer() -> Outer: 10 | frm asd : Asd 11 | subaction*(2) i = inner(asd.y) 12 | 13 | fun main() -> Int: 14 | return 0 15 | -------------------------------------------------------------------------------- /tool/rlc/test/constraint/CA_1.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s --flattened --hide-position %t -i %stdlib -o - | rlc-opt --rlc-test-function-constraints-analysis | FileCheck %s 2 | 3 | # CHECK: {a_F = "[-9223372036854775808,11)", a_T = "[11,9223372036854775807)", is_member_function = false} 4 | 5 | # THE POLICY WE USE NOW IS [min,max) 6 | 7 | fun foo(Int a) -> Bool {true}: 8 | if a > 10: 9 | return true 10 | return false 11 | -------------------------------------------------------------------------------- /tool/rlc/test/constraint/CA_10.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s --flattened --hide-position %t -i %stdlib -o - | rlc-opt --rlc-test-function-constraints-analysis | FileCheck %s 2 | 3 | # CHECK: {a_F = "[-9223372036854775808,9223372036854775807)", a_T = "[6,11)", is_member_function = false} 4 | 5 | # We could note that doing this it would work fine 6 | #if a < 11: 7 | # if a > 5: 8 | # return true 9 | #return false 10 | 11 | fun foo(Int a) -> Bool {true}: 12 | return a<11 and a>5 13 | -------------------------------------------------------------------------------- /tool/rlc/test/constraint/CA_11.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s --flattened --hide-position %t -i %stdlib -o - | rlc-opt --rlc-test-function-constraints-analysis | FileCheck %s 2 | 3 | # CHECK: {a_F = "[-9223372036854775808,9223372036854775807)", a_T = "[5,10)", is_member_function = false} 4 | 5 | fun foo(Int a) -> Bool {true}: 6 | a=a+1 7 | return a<11 and a>5 8 | -------------------------------------------------------------------------------- /tool/rlc/test/constraint/CA_12.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s --flattened --hide-position %t -i %stdlib -o - | rlc-opt --rlc-test-function-constraints-analysis | FileCheck %s 2 | 3 | # CHECK: {a_F = "[-9223372036854775808,9223372036854775807)", a_T = "[1,9)", is_member_function = false} 4 | 5 | fun foo(Int a) -> Bool {true}: 6 | if a>0: 7 | let temp=a+1 8 | return temp<10 9 | return false 10 | -------------------------------------------------------------------------------- /tool/rlc/test/constraint/CA_13.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s --flattened --hide-position %t -i %stdlib -o - | rlc-opt --rlc-test-function-constraints-analysis | FileCheck %s 2 | 3 | # CHECK: {a_F = "[-9223372036854775808,9223372036854775807)", a_T = "[6,11)", b_F = "[-9223372036854775808,9223372036854775807)", b_T = "[7,10)", c_F = "[-9223372036854775808,9223372036854775807)", c_T = "[8,9)", is_member_function = false} 4 | 5 | # We could note that doing this it would work fine 6 | #if a < 11: 7 | # if a > 5: 8 | # if b < 10: 9 | # if b > 6: 10 | # if c < 9: 11 | # if c > 7: 12 | # return true 13 | #return false 14 | 15 | fun foo(Int a, Int b, Int c) -> Bool {true}: 16 | return a<11 and a>5 and b<10 and b>6 and c<9 and c>7 17 | -------------------------------------------------------------------------------- /tool/rlc/test/constraint/CA_2.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s --flattened --hide-position %t -i %stdlib -o - | rlc-opt --rlc-test-function-constraints-analysis | FileCheck %s 2 | 3 | # CHECK: {a_F = "[10,9223372036854775807)", a_T = "[-9223372036854775808,10)", is_member_function = false} 4 | 5 | fun foo(Int a) -> Bool {true}: 6 | if a < 10: 7 | return true 8 | return false 9 | 10 | -------------------------------------------------------------------------------- /tool/rlc/test/constraint/CA_3.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s --flattened --hide-position %t -i %stdlib -o - | rlc-opt --rlc-test-function-constraints-analysis | FileCheck %s 2 | 3 | # CHECK: {a_F = "[10,9223372036854775807)", a_T = "[-9223372036854775808,10)", b_F = "[-9223372036854775808,11)", b_T = "[11,9223372036854775807)", is_member_function = false} 4 | 5 | fun foo(Int a, Int b) -> Bool {true}: 6 | if b > 10: 7 | if a < 10: 8 | return true 9 | return false 10 | 11 | -------------------------------------------------------------------------------- /tool/rlc/test/constraint/CA_4.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s --flattened --hide-position %t -i %stdlib -o - | rlc-opt --rlc-test-function-constraints-analysis | FileCheck %s 2 | 3 | # CHECK: {a_F = "[-9223372036854775808,9223372036854775807)", a_T = "[11,10)", is_member_function = false} 4 | 5 | # a_true : invalid range (MIN > MAX) 6 | 7 | fun foo(Int a) -> Bool {true}: 8 | if a > 10: 9 | if a < 10: 10 | return true 11 | return false 12 | 13 | -------------------------------------------------------------------------------- /tool/rlc/test/constraint/CA_5.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s --flattened --hide-position %t -i %stdlib -o - | rlc-opt --rlc-test-function-constraints-analysis | FileCheck %s 2 | 3 | # CHECK: {a_F = "[-9223372036854775808,9223372036854775807)", a_T = "[11,12)", is_member_function = false} 4 | 5 | fun foo(Int a) -> Bool {true}: 6 | if a > 10: 7 | if a < 12: 8 | return true 9 | return false 10 | 11 | -------------------------------------------------------------------------------- /tool/rlc/test/constraint/CA_6.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s --flattened --hide-position %t -i %stdlib -o - | rlc-opt --rlc-test-function-constraints-analysis | FileCheck %s 2 | 3 | # CHECK: {a_F = "[10,11)", a_T = "[-9223372036854775808,9223372036854775807)", is_member_function = false} 4 | 5 | fun foo(Int a) -> Bool {true}: 6 | if a > 10: 7 | return true 8 | else if a < 10: 9 | return true 10 | return false 11 | 12 | -------------------------------------------------------------------------------- /tool/rlc/test/constraint/CA_7.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s --flattened --hide-position %t -i %stdlib -o - | rlc-opt --rlc-test-function-constraints-analysis | FileCheck %s 2 | 3 | # CHECK: {a_F = "[-9223372036854775808,9223372036854775807)", a_T = "[11,20)", is_member_function = false} 4 | 5 | fun foo(Int a) -> Bool {true}: 6 | if a > 10: 7 | if a < 20: 8 | return true 9 | if a > 15: 10 | return false 11 | return false 12 | 13 | -------------------------------------------------------------------------------- /tool/rlc/test/constraint/CA_8.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s --flattened --hide-position %t -i %stdlib -o - | rlc-opt --rlc-test-function-constraints-analysis | FileCheck %s 2 | 3 | # CHECK: {a_F = "[-10,9223372036854775807)", a_T = "[-9223372036854775808,20)", is_member_function = false} 4 | 5 | fun foo(Int a) -> Bool {true}: 6 | if a > 10: 7 | if a < 20: 8 | return true 9 | if a < -10: 10 | return true 11 | return false 12 | 13 | -------------------------------------------------------------------------------- /tool/rlc/test/constraint/CA_9.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s --flattened --hide-position %t -i %stdlib -o - | rlc-opt --rlc-test-function-constraints-analysis | FileCheck %s 2 | 3 | # CHECK: {a_F = "[-9223372036854775808,9223372036854775807)", a_T = "[1,10)", is_member_function = false} 4 | 5 | fun foo(Int a) -> Bool {true}: 6 | if a > 0: 7 | return a < 10 8 | return false 9 | -------------------------------------------------------------------------------- /tool/rlc/test/context_arg.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | act action_with_arg(ctx Int arg) -> Name: 5 | act inner(Int inner_arg) {arg + 2 == inner_arg} 6 | arg = arg + 1 7 | 8 | fun main() -> Int: 9 | let context = 3 10 | let frame = action_with_arg(context) 11 | frame.inner(context, 5) 12 | return context - 4 13 | -------------------------------------------------------------------------------- /tool/rlc/test/context_subaction.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | act action_with_arg(ctx Int arg) -> Name: 5 | act inner(Int inner_arg) {arg + 2 == inner_arg} 6 | arg = arg + 1 7 | act inner2(Int inner_arg) {arg - 2 == inner_arg} 8 | arg = arg + 1 9 | 10 | act outer_middle(ctx Int context) -> WrapperMiddle: 11 | subaction* (context) frame = action_with_arg(context) 12 | 13 | act outer() -> Wrapper: 14 | frm context = 3 15 | subaction* (context) frame = outer_middle(context) 16 | 17 | fun main() -> Int: 18 | let frame = outer() 19 | frame.inner(5) 20 | frame.inner2(2) 21 | return frame.context - 5 22 | -------------------------------------------------------------------------------- /tool/rlc/test/continue_test.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | let x = 0 6 | while x != 3: 7 | while x != 10: 8 | x = x + 1 9 | if x == 1: 10 | continue 11 | else: 12 | break 13 | x = x + 1 14 | 15 | if x != 3: 16 | return -1 17 | 18 | while x != 13: 19 | x = x + 5 20 | continue 21 | 22 | if x != 13: 23 | return -1 24 | 25 | while x != 18: 26 | x = x + 5 27 | 28 | return x - 18 29 | 30 | -------------------------------------------------------------------------------- /tool/rlc/test/count_actions.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | act action() -> Action: 5 | frm counter = 0 6 | while true: 7 | act sub() 8 | counter = counter + 1 9 | 10 | 11 | fun main() -> Int: 12 | let frame = action() 13 | frame.sub() 14 | frame.sub() 15 | return frame.counter - 2 16 | -------------------------------------------------------------------------------- /tool/rlc/test/crashes/array_overflow.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | # XFAIL: * 4 | 5 | fun main() -> Int: 6 | let array : Int[10] 7 | let a = array[10] 8 | return 0 9 | -------------------------------------------------------------------------------- /tool/rlc/test/crashes/array_underflow.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | # XFAIL: * 4 | 5 | fun main() -> Int: 6 | let array : Int[10] 7 | let a = array[-1] 8 | return 0 9 | -------------------------------------------------------------------------------- /tool/rlc/test/crashes/illegal_argument.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | # XFAIL: * 4 | 5 | act action() -> Action: 6 | act sub(Int x) {x == 0} 7 | 8 | fun main() -> Int: 9 | let a = action() 10 | a.sub(1) 11 | return 0 12 | -------------------------------------------------------------------------------- /tool/rlc/test/crashes/unexpected_subaction.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | # XFAIL: * 4 | 5 | act action() -> Action: 6 | act first() 7 | act second() 8 | 9 | fun main() -> Int: 10 | let a = action() 11 | a.second() 12 | return 0 13 | -------------------------------------------------------------------------------- /tool/rlc/test/custom_init.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | cls Example: 5 | Int f1 6 | 7 | fun init(): 8 | self.f1 = 5 9 | 10 | fun main() -> Int: 11 | let asd : Example 12 | return asd.f1 - 5 13 | -------------------------------------------------------------------------------- /tool/rlc/test/declaration.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun a() -> Int: 5 | let a = 0 6 | let b = a + 4 7 | return b 8 | 9 | fun main() -> Int: 10 | let x = a() 11 | return 0 12 | -------------------------------------------------------------------------------- /tool/rlc/test/destructor.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o - -i %stdlib --flattened | FileCheck %s 2 | 3 | cls CustomDestructor: 4 | Int a 5 | 6 | fun drop(): 7 | self.a = 2 8 | 9 | # CHECK: rlc.flat_fun "main" 10 | fun main() -> Int: 11 | # CHECK: rlc.ref @rl_m_drop__CustomDestructor 12 | # CHECK-NEXT: rlc.call 13 | let var : CustomDestructor 14 | return 0 15 | # CHECK-NOT: rlc.ref @rl_m_drop__CustomDestructor 16 | -------------------------------------------------------------------------------- /tool/rlc/test/destructor_after_if.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o - -i %stdlib --flattened | FileCheck %s 2 | 3 | import collections.vector 4 | 5 | # CHECK: rlc.flat_fun "main" 6 | fun main() -> Int: 7 | if (0 == 1): 8 | return 1 9 | let v : Vector 10 | if (0 == 1): 11 | # CHECK: rlc.ref @rl_m_drop__VectorTint64_tT 12 | # CHECK-NEXT: rlc.call 13 | return 1 14 | # CHECK: rlc.ref @rl_m_drop__VectorTint64_tT 15 | # CHECK-NEXT: rlc.call 16 | return 0 17 | # CHECK-NOT: rlc.ref @rl_m_drop__VectorTint64_tT 18 | -------------------------------------------------------------------------------- /tool/rlc/test/dict_clear.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import collections.dictionary 5 | import none 6 | 7 | fun main() -> Int: 8 | let x: Dict 9 | x.insert(1, 1) 10 | x.insert(2, 2) 11 | x.clear() 12 | 13 | if x.size() == 0: 14 | return 0 15 | else: 16 | return 1 17 | 18 | -------------------------------------------------------------------------------- /tool/rlc/test/dict_contains.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import collections.dictionary 5 | import none 6 | 7 | fun main() -> Int: 8 | let x: Dict 9 | x.insert(1, 1) 10 | 11 | if x.contains(1) and !(x.contains(2)): 12 | return 0 13 | else: 14 | return 1 15 | 16 | -------------------------------------------------------------------------------- /tool/rlc/test/dict_empty.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import collections.dictionary 5 | import collections.vector 6 | import serialization.print 7 | import serialization.to_hash 8 | import none 9 | 10 | fun main() -> Int: 11 | let x: Dict 12 | x.insert(1, 1) 13 | x.remove(1) 14 | 15 | if x.empty(): 16 | return 0 17 | else: 18 | return 1 19 | 20 | -------------------------------------------------------------------------------- /tool/rlc/test/dict_get.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import collections.dictionary 5 | import none 6 | 7 | fun main() -> Int: 8 | let x: Dict 9 | x.insert(1, 2) 10 | 11 | if x.get(1) == 2: 12 | return 0 13 | else: 14 | return 1 15 | 16 | -------------------------------------------------------------------------------- /tool/rlc/test/dict_init.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import collections.dictionary 5 | import serialization.print 6 | import serialization.to_hash 7 | import none 8 | 9 | fun main() -> Int: 10 | let x: Dict 11 | 12 | let result : Vector 13 | print(compute_hash_of(4)) 14 | x.insert(4,0) 15 | let counter = 1 16 | let max = 0 17 | 18 | return 0 19 | -------------------------------------------------------------------------------- /tool/rlc/test/dict_insert.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib -g --sanitize 2 | # RUN: %t%exeext 3 | 4 | import collections.dictionary 5 | import none 6 | 7 | fun main() -> Int: 8 | let x: Dict 9 | x.insert(1, 1) 10 | 11 | if x.contains(1): 12 | return 0 13 | 14 | return 1 15 | 16 | -------------------------------------------------------------------------------- /tool/rlc/test/dict_keys.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize 2 | # RUN: %t%exeext 3 | 4 | import collections.dictionary 5 | import collections.vector 6 | import serialization.print 7 | 8 | fun main() -> Int: 9 | let x: Dict 10 | x.insert(1, 2) 11 | 12 | let actual: Vector 13 | actual = x.keys() 14 | 15 | let expected: Vector 16 | expected.append(1) 17 | 18 | let i = 0 19 | while i < actual.size(): 20 | if actual.get(i) != expected.get(i): 21 | return 1 22 | i = i + 1 23 | 24 | return 0 25 | 26 | -------------------------------------------------------------------------------- /tool/rlc/test/dict_leak.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -i %stdlib -o %t --sanitize 2 | # RUN: %t%exeext 3 | import collections.dictionary 4 | 5 | act asd() -> Move: 6 | let dictionary : Dict 7 | dictionary.insert(1, 1) 8 | act inner() 9 | 10 | fun main() -> Int: 11 | asd() 12 | return 0 -------------------------------------------------------------------------------- /tool/rlc/test/dict_remove.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import collections.dictionary 5 | import none 6 | 7 | fun main() -> Int: 8 | let x: Dict 9 | x.insert(1, 1) 10 | x.remove(1) 11 | 12 | if !(x.contains(1)): 13 | return 0 14 | else: 15 | return 1 16 | 17 | -------------------------------------------------------------------------------- /tool/rlc/test/dict_size.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import collections.dictionary 5 | import none 6 | 7 | fun main() -> Int: 8 | let x: Dict 9 | x.insert(1, 1) 10 | x.insert(2, 2) 11 | 12 | if x.size() == 2: 13 | return 0 14 | else: 15 | return 1 16 | 17 | -------------------------------------------------------------------------------- /tool/rlc/test/dict_struct_key.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import collections.dictionary 5 | import collections.vector 6 | import serialization.print 7 | import serialization.to_hash 8 | import none 9 | 10 | cls Point: 11 | Int x 12 | Int y 13 | 14 | fun main() -> Int: 15 | let x: Dict 16 | let p1: Point 17 | p1.x = 1 18 | p1.y = 2 19 | 20 | x.insert(p1, 42) 21 | 22 | let p2: Point 23 | p2.x = 1 24 | p2.y = 2 25 | 26 | if x.contains(p2) and x.get(p2) == 42: 27 | return 0 28 | return 1 -------------------------------------------------------------------------------- /tool/rlc/test/dict_values.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize 2 | # RUN: %t%exeext 3 | 4 | import collections.dictionary 5 | import collections.vector 6 | import none 7 | 8 | fun main() -> Int: 9 | let x: Dict 10 | x.insert(1, 2) 11 | 12 | let actual: Vector 13 | actual = x.values() 14 | 15 | let expected: Vector 16 | expected.append(2) 17 | 18 | let i = 0 19 | while i < actual.size(): 20 | if actual.get(i) != expected.get(i): 21 | return 1 22 | i = i + 1 23 | 24 | return 0 25 | 26 | -------------------------------------------------------------------------------- /tool/rlc/test/dict_vector_key.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import collections.dictionary 5 | import collections.vector 6 | import serialization.print 7 | import serialization.to_hash 8 | import none 9 | 10 | fun main() -> Int: 11 | let x: Dict,Int> 12 | let v: Vector 13 | v.append(1) 14 | v.append(2) 15 | 16 | x.insert(v, 42) 17 | 18 | let v2: Vector 19 | v2.append(1) 20 | v2.append(2) 21 | 22 | if x.contains(v2) and x.get(v2) == 42: 23 | return 0 24 | return 1 -------------------------------------------------------------------------------- /tool/rlc/test/dict_vector_value.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import collections.dictionary 5 | import collections.vector 6 | import serialization.print 7 | import serialization.to_hash 8 | import none 9 | 10 | fun main() -> Int: 11 | let x: Dict> 12 | let v: Vector 13 | v.append(1) 14 | v.append(2) 15 | 16 | x.insert(1, v) 17 | 18 | if x.contains(1): 19 | let result = x.get(1) 20 | if result.size() == 2 and result.get(0) == 1 and result.get(1) == 2: 21 | return 0 22 | return 1 -------------------------------------------------------------------------------- /tool/rlc/test/either_subaction.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | act inner() -> Inner: 5 | act asd() 6 | 7 | act inner2() -> Inner2: 8 | act asd2() 9 | 10 | act outer() -> Outer: 11 | frm first = inner() 12 | frm second = inner2() 13 | subaction* first, second 14 | 15 | fun main() -> Int: 16 | let state = outer() 17 | if state.is_done(): 18 | return 1 19 | state.asd() 20 | if state.is_done(): 21 | return 1 22 | state.asd2() 23 | if state.is_done(): 24 | return 0 25 | return 1 26 | 27 | -------------------------------------------------------------------------------- /tool/rlc/test/elseif.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | if false: 6 | return -1 7 | 8 | else if false: 9 | return -2 10 | else if true: 11 | return 0 12 | else: 13 | return 1 14 | -------------------------------------------------------------------------------- /tool/rlc/test/enum.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | enum Asd: 5 | first 6 | second 7 | 8 | fun main() -> Int: 9 | let asd : Asd 10 | asd = Asd::second 11 | if max(asd) != 1: 12 | return -2 13 | return asd.value - 1 14 | -------------------------------------------------------------------------------- /tool/rlc/test/enum_field_expression.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import string 5 | import serialization.print 6 | 7 | enum Example: 8 | blue: 9 | String name = "blu"s 10 | red: 11 | String name = "red"s 12 | 13 | fun main() -> Int: 14 | if Example::blue.name() != "blu"s: 15 | return -10 16 | if Example::red.name() == "red"s: 17 | return 0 18 | return 1 19 | 20 | -------------------------------------------------------------------------------- /tool/rlc/test/enum_tensor_serialization.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import action 5 | import machine_learning 6 | 7 | enum Example: 8 | first 9 | second 10 | third 11 | 12 | fun main() -> Int: 13 | let vec : Vector 14 | let value = Example::second 15 | 16 | if !(value is Enum): 17 | return -5 18 | 19 | let x = observation_tensor_size(value) 20 | if x != 3: 21 | return 5 22 | while x != 0: 23 | vec.append(0.0) 24 | x = x - 1 25 | to_observation_tensor(value, 0, vec) 26 | if vec.size() != 3: 27 | return 1 28 | if vec.get(0) != 0.0: 29 | return 2 30 | if vec.get(1) != 1.0: 31 | return 3 32 | if vec.get(0) != 0.0: 33 | return 4 34 | 35 | return 0 36 | -------------------------------------------------------------------------------- /tool/rlc/test/enum_to_string.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import string 5 | 6 | enum Example: 7 | first 8 | second 9 | 10 | fun main() -> Int: 11 | if "first"s != as_string_literal(Example::first): 12 | return -1 13 | if "second"s != as_string_literal(Example::second): 14 | return -2 15 | return 0 16 | -------------------------------------------------------------------------------- /tool/rlc/test/enumerate_action_nested.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import action 5 | 6 | cls Asd: 7 | Bool i 8 | 9 | cls Asd2: 10 | Asd i 11 | 12 | cls Asd3: 13 | Asd2 i 14 | 15 | fun main() -> Int: 16 | let asd : Asd2 17 | let result = enumerate(asd) 18 | if result.size() != 2: 19 | return 1 20 | return 0 21 | -------------------------------------------------------------------------------- /tool/rlc/test/enumerate_alternative_bounded_arg_test.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import action 5 | import serialization.print 6 | import bounded_arg 7 | 8 | using Alt = Bool | BInt<0, 10> 9 | 10 | fun main() -> Int: 11 | let content : Alt 12 | let result = enumerate(content) 13 | print(result) 14 | if result.size() != 12: 15 | return 1 16 | return 0 17 | -------------------------------------------------------------------------------- /tool/rlc/test/enumerate_bounded_arg_test.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import action 5 | import serialization.print 6 | import bounded_arg 7 | 8 | cls Content: 9 | Bool asd 10 | BInt<3, 13> asd2 11 | 12 | 13 | fun main() -> Int: 14 | let content : Content 15 | let result = enumerate(content) 16 | if result.size() != 20: 17 | return 1 18 | print(result) 19 | if result.back().asd2.value != 12: 20 | return -1 21 | return 0 22 | -------------------------------------------------------------------------------- /tool/rlc/test/enumerate_enum.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import machine_learning 5 | import action 6 | 7 | enum Asd: 8 | first 9 | second 10 | 11 | fun equal(Asd other) -> Bool: 12 | return self.value == other.value 13 | 14 | fun not_equal(Asd other) -> Bool: 15 | return self.value != other.value 16 | 17 | fun main() -> Int: 18 | let enumeration = enumerate(Asd::first) 19 | if enumeration.size() != 2: 20 | return -3 21 | if enumeration.get(0) != Asd::first: 22 | return -2 23 | if enumeration.get(1) != Asd::second: 24 | return -1 25 | return 0 26 | -------------------------------------------------------------------------------- /tool/rlc/test/enumerate_test.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import action 5 | import serialization.print 6 | 7 | cls Content: 8 | Bool asd 9 | Bool asd2 10 | 11 | fun main() -> Int: 12 | let content : Content 13 | let result = enumerate(content) 14 | if result.size() != 4: 15 | return 1 16 | if !result.get(0).asd or !result.get(0).asd2: 17 | return -1 18 | if result.get(3).asd or result.get(3).asd2: 19 | return -1 20 | if !result.get(1).asd or result.get(1).asd2: 21 | return -1 22 | if result.get(2).asd or !result.get(2).asd2: 23 | return -1 24 | return 0 25 | -------------------------------------------------------------------------------- /tool/rlc/test/enumeration_errors.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext | FileCheck %s 3 | 4 | 5 | import action 6 | 7 | 8 | cls TopLevel: 9 | # CHECK: a is of type Int, which is not enumerable. Replace it instead with a BInt with appropriate bounds or specify yourself how to enumerate it. 10 | Int a 11 | # CHECK-NEXT: b is of type Float, which is not enumerable. Specify yourself how to enumerate it. 12 | Float b 13 | Bool[3] c 14 | Vector> f 15 | 16 | @classes 17 | act play() -> Game: 18 | # CHECK: GameDoNothing.a is of type Int, which is not enumerable. Replace it instead with a BInt with appropriate bounds or specify yourself how to enumerate it. 19 | act do_nothing(Int a, Bool b) 20 | 21 | fun main() -> Int: 22 | let y : TopLevel 23 | let state : AnyGameAction 24 | print(get_enumeration_errors(y)) 25 | print(get_enumeration_errors(state)) 26 | return 0 27 | -------------------------------------------------------------------------------- /tool/rlc/test/equality_trait.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | trait Comparable: 5 | fun equal(T a, T2 b) -> Bool 6 | 7 | fun equal(Float b, Int a) -> Bool: 8 | return true 9 | 10 | fun main() -> Int: 11 | if 3 is Comparable: 12 | return 0 13 | return 1 14 | -------------------------------------------------------------------------------- /tool/rlc/test/examples/simplest_example.rl: -------------------------------------------------------------------------------- 1 | # RUN: python %pyscript/test.py %s --stdlib %stdlib --rlc rlc 2 | # RUN: python %pyscript/learn.py %s --stdlib %stdlib --rlc rlc --total-steps 200 --model-save-frequency 1 -o %t --envs 1 --steps-per-env 100 3 | # RUN: python %pyscript/play.py %s --stdlib %stdlib --rlc rlc %t 4 | # RUN: python %pyscript/probs.py %s %t --stdlib %stdlib --rlc rlc 5 | 6 | @classes 7 | act play() -> Game: 8 | frm score = 0.0 9 | act win(Bool do_it) 10 | if do_it: 11 | score = 1.0 12 | -------------------------------------------------------------------------------- /tool/rlc/test/examples/space_hulk/traces.rl: -------------------------------------------------------------------------------- 1 | # RUN: python %pyscript/action.py %S/main.rl --stdlib %stdlib --rlc rlc %s 2 | 3 | # move right 4 | place_blip {index: 0} 5 | place_blip {index: 0} 6 | toggle_door {unit_id: 1} 7 | begin_move {unit_id: 1} 8 | move {absolute_direction: 1} 9 | end_move {} 10 | do_nothing {} 11 | 12 | # move right 13 | begin_move {unit_id: 1} 14 | move {absolute_direction: 1} 15 | end_move {} 16 | do_nothing {} 17 | 18 | -------------------------------------------------------------------------------- /tool/rlc/test/extern_fun.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | ext fun something_extern() -> Int 5 | 6 | fun main() -> Int: 7 | return 0 8 | -------------------------------------------------------------------------------- /tool/rlc/test/for_field.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | cls Inner: 5 | Int x2 6 | Int y2 7 | cls Asd: 8 | Int x 9 | Inner y 10 | 11 | fun collect(T asd) -> Int: 12 | let result = 0 13 | 14 | for field of asd: 15 | if field is Int: 16 | result = result + field 17 | if field is Float: 18 | result = result + int(field) 19 | if field is Bool: 20 | result = result + int(field) 21 | result = result + collect(field) 22 | 23 | return result 24 | 25 | fun main() -> Int: 26 | let var : Asd 27 | var.x = 1 28 | var.y.x2 = 3 29 | var.y.y2 = 5 30 | return collect(var) - 9 31 | -------------------------------------------------------------------------------- /tool/rlc/test/for_field_multiple_inputs.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | cls Asd: 5 | Int v1 6 | Int v2 7 | 8 | fun cross_product(T x, T y) -> Int: 9 | let sum = 0 10 | for f1, f2 of x, y: 11 | if f1 is Int: 12 | if f2 is Int: 13 | sum = sum + (f1 * f2) 14 | return sum 15 | 16 | fun main() -> Int: 17 | let x : Asd 18 | let y : Asd 19 | x.v1 = 10 20 | y.v1 = 3 21 | x.v2 = 2 22 | y.v2 = 4 23 | 24 | return cross_product(x, y) - 38 25 | -------------------------------------------------------------------------------- /tool/rlc/test/for_loop.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | cls Range: 5 | Int _size 6 | 7 | fun get(Int i) -> Int: 8 | return i 9 | 10 | fun size() -> Int: 11 | return self._size 12 | 13 | fun set_size(Int new_size): 14 | self._size = new_size 15 | 16 | fun range(Int size) -> Range: 17 | let range : Range 18 | range.set_size(size) 19 | return range 20 | 21 | fun main() -> Int: 22 | let sum = 0 23 | for i in range(10): 24 | sum = sum + i 25 | if sum == 45: 26 | return 0 27 | return 1 28 | -------------------------------------------------------------------------------- /tool/rlc/test/for_loop_action.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import collections.vector 5 | 6 | act asd() -> Action: 7 | frm sum = 0 8 | let v : Vector 9 | v.append(0) 10 | v.append(1) 11 | v.append(2) 12 | for i in v: 13 | sum = sum + i 14 | act inner() 15 | 16 | fun main() -> Int: 17 | let var = asd() 18 | if var.sum == 3: 19 | return 0 20 | return 1 21 | 22 | -------------------------------------------------------------------------------- /tool/rlc/test/for_loop_break.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | cls Range: 5 | Int _size 6 | 7 | fun get(Int i) -> Int: 8 | return i 9 | 10 | fun size() -> Int: 11 | return self._size 12 | 13 | fun set_size(Int new_size): 14 | self._size = new_size 15 | 16 | fun range(Int size) -> Range: 17 | let range : Range 18 | range.set_size(size) 19 | return range 20 | 21 | fun main() -> Int: 22 | let sum = 0 23 | for i in range(10): 24 | if i == 5: 25 | break 26 | sum = sum + i 27 | if sum == 10: 28 | return 0 29 | return 1 30 | -------------------------------------------------------------------------------- /tool/rlc/test/for_loop_continue.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import range 5 | 6 | fun main() -> Int: 7 | let sum = 0 8 | for i in range(10): 9 | if i == 5: 10 | continue 11 | sum = sum + i 12 | if sum == 40: 13 | return 0 14 | return 1 15 | -------------------------------------------------------------------------------- /tool/rlc/test/for_loop_vector.rl: -------------------------------------------------------------------------------- 1 | 2 | # RUN: rlc %s -o %t -i %stdlib 3 | # RUN: %t%exeext 4 | 5 | import collections.vector 6 | 7 | fun main() -> Int: 8 | let sum = 0 9 | let v : Vector 10 | v.append(0) 11 | v.append(1) 12 | v.append(2) 13 | for i in v: 14 | sum = sum + i 15 | if sum == 3: 16 | return 0 17 | return 1 18 | -------------------------------------------------------------------------------- /tool/rlc/test/frm_ctx_alterantive_upcast.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | using Asd = Int | Float 5 | 6 | act asd(frm Asd x) -> RollStat: 7 | if x is Int: 8 | x = x + 1 9 | act asd() 10 | 11 | fun main() -> Int: 12 | let x : Asd 13 | x = 0 14 | let y = asd(x) 15 | y.asd() 16 | let value = y.x 17 | if value is Int: 18 | return value - 1 19 | return -1 20 | -------------------------------------------------------------------------------- /tool/rlc/test/from_string.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize 2 | # RUN: %t%exeext 3 | 4 | import string 5 | import collections.vector 6 | 7 | cls Asd: 8 | Vector asd 9 | Float | Bool tasd 10 | 11 | fun main() -> Int: 12 | let result : Asd 13 | if !from_string(result, "{asd: [2, 3], tasd: Bool true}"s): 14 | return 2 15 | if result.asd.size() != 2: 16 | return 1 17 | if result.asd.get(0) != 2: 18 | return 1 19 | if result.asd.get(1) != 3: 20 | return 1 21 | return 0 22 | -------------------------------------------------------------------------------- /tool/rlc/test/function_argument.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun fun_with_arg(Int arg, Float f, Bool b) -> Int: 5 | let a = arg - 4 6 | return a 7 | 8 | fun main() -> Int: 9 | return fun_with_arg(4, 3.14, true) 10 | -------------------------------------------------------------------------------- /tool/rlc/test/get_custom_operator.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import collections.vector 5 | 6 | fun main() -> Int: 7 | let t : Vector 8 | t.append(2) 9 | return t[0] - 2 10 | -------------------------------------------------------------------------------- /tool/rlc/test/global_using_type.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import collections.vector 5 | 6 | using T = Int | Vector 7 | 8 | fun main() -> Int: 9 | let asd : T 10 | asd = 10 11 | if asd is Int: 12 | return asd - 10 13 | return -10 14 | 15 | -------------------------------------------------------------------------------- /tool/rlc/test/graph_test.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib -g 2 | # RUN: %t%exeext 3 | 4 | import collections.graph 5 | 6 | fun main() -> Int: 7 | let x : Graph 8 | x.add_node() 9 | if x.get_nodes_size() != 1: 10 | return -1 11 | x.add_node() 12 | x.get_node(0).add_edge(x.get_node(1)) 13 | if x.get_node(0).get_outgoing(0).get_target_id() != 1: 14 | return -2 15 | 16 | x.remove_node(x.get_node(0)) 17 | x.remove_node(x.get_node(0)) 18 | return x.get_nodes_size() 19 | -------------------------------------------------------------------------------- /tool/rlc/test/hidden_info_tensor_serialization.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import action 5 | import machine_learning 6 | 7 | fun main() -> Int: 8 | let vec : Vector 9 | let hidden : HiddenInformation 10 | let hidden2 : Hidden 11 | 12 | if observation_tensor_size(hidden2) != 0: 13 | return 4 14 | 15 | hidden.owner = 1 16 | hidden.value = true 17 | let x = observation_tensor_size(hidden) 18 | while x != 0: 19 | vec.append(0.0) 20 | x = x - 1 21 | to_observation_tensor(hidden, 0, vec) 22 | if vec.size() != 1: 23 | return 1 24 | if vec.get(0) != 0.0: 25 | return 2 26 | to_observation_tensor(hidden, 1, vec) 27 | if vec.get(0) != 1.0: 28 | return 3 29 | 30 | return 0 31 | -------------------------------------------------------------------------------- /tool/rlc/test/if_else.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun with_if_else() -> Int: 5 | if 4 == 4: 6 | return 0 7 | else: 8 | return 1 9 | 10 | fun main() -> Int: 11 | return with_if_else() 12 | -------------------------------------------------------------------------------- /tool/rlc/test/implicit_assigment.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | cls asd: 5 | Int first 6 | Int second 7 | 8 | fun main() -> Int: 9 | let e1 : asd 10 | let e2 : asd 11 | e1.second = 4 12 | e2 = e1 13 | return e2.second - 4 14 | -------------------------------------------------------------------------------- /tool/rlc/test/import_test.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import collections.vector 5 | 6 | fun main() -> Int: 7 | let v : Vector 8 | v.append(1) 9 | v.append(2) 10 | v.append(3) 11 | v.pop() 12 | return v.pop() - 2 13 | 14 | -------------------------------------------------------------------------------- /tool/rlc/test/include_tic_tac_toe.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import tic_tac_toe 5 | import learn 6 | -------------------------------------------------------------------------------- /tool/rlc/test/initializer_list.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | let list = [[1, 1], 6 | [2, 2], 7 | [-3, 3]] 8 | return list[0][1] + list[1][1] - list[2][1] 9 | -------------------------------------------------------------------------------- /tool/rlc/test/is.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | if !4 is Int: 6 | return -1 7 | else: 8 | return 0 9 | -------------------------------------------------------------------------------- /tool/rlc/test/is_done.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | act action() -> Action: 5 | act first() 6 | act second() 7 | 8 | fun main() -> Int: 9 | let state = action() 10 | if is_done(state): 11 | return -1 12 | state.first() 13 | if is_done(state): 14 | return -2 15 | state.second() 16 | if is_done(state): 17 | return 0 18 | return 1 19 | -------------------------------------------------------------------------------- /tool/rlc/test/is_trait.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | trait SummableToInt: 5 | fun addInt(T x, Int y) -> Int 6 | 7 | fun addInt(Float x, Int y) -> Int: 8 | return int(x) + y 9 | 10 | fun tryAddInt(K x, Int y) -> Int: 11 | if x is SummableToInt: 12 | return x.addInt(y) 13 | return y 14 | 15 | fun main() -> Int: 16 | return tryAddInt(4.0, 3) -7 17 | -------------------------------------------------------------------------------- /tool/rlc/test/isa_in_for_field.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | trait Trait: 5 | fun function(T a) -> Bool 6 | 7 | fun template(T to_add) -> Bool: 8 | for field of to_add: 9 | if field is Trait: 10 | return field.function() 11 | return false 12 | 13 | cls Entity: 14 | Int x 15 | 16 | cls Outer: 17 | Entity x 18 | 19 | fun function(Entity a) -> Bool: 20 | return true 21 | 22 | fun main() -> Int: 23 | let entity : Outer 24 | if template(entity): 25 | return 0 26 | return 1 27 | -------------------------------------------------------------------------------- /tool/rlc/test/left_shift_text.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | if 4 << 2 != 16: 6 | return -1 7 | else: 8 | return 0 9 | -------------------------------------------------------------------------------- /tool/rlc/test/load_action_file.rl: -------------------------------------------------------------------------------- 1 | # RUN: split-file %s %t 2 | # RUN: rlc %t/source.rl -o %t/exec -i %stdlib 3 | # RUN: cd %t && %t/exec%exeext 4 | 5 | #--- source.rl 6 | import string 7 | import serialization.print 8 | import action 9 | 10 | @classes 11 | act example() -> Game: 12 | act asd(Int x) 13 | act asdy(Bool x) 14 | 15 | fun main() -> Int: 16 | let state = example() 17 | let actions_vector : Vector 18 | if !load_action_vector_file("./content.txt"s, actions_vector): 19 | return -3 20 | if actions_vector.size() != 2: 21 | return -1 22 | apply(actions_vector.get(0), state) 23 | apply(actions_vector.get(1), state) 24 | if !state.is_done(): 25 | return -2 26 | return 0 27 | 28 | #--- content.txt 29 | asd {x: 1} 30 | asdy {x: true} 31 | 32 | -------------------------------------------------------------------------------- /tool/rlc/test/load_file_test.rl: -------------------------------------------------------------------------------- 1 | # RUN: split-file %s %t 2 | # RUN: rlc %t/source.rl -o %t/exec -i %stdlib 3 | # RUN: cd %t && %t/exec%exeext 4 | 5 | #--- source.rl 6 | import string 7 | import serialization.print 8 | 9 | fun main() -> Int: 10 | let content : String 11 | if !load_file("./content.txt"s, content): 12 | return -2 13 | 14 | if content != "example\nex2\n": 15 | return -1 16 | return 0 17 | 18 | #--- content.txt 19 | example 20 | ex2 21 | -------------------------------------------------------------------------------- /tool/rlc/test/local_var_in_array_initializer.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | let counter = 4 6 | return [counter][0] - 4 7 | -------------------------------------------------------------------------------- /tool/rlc/test/long_name_action_print.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import string 5 | import serialization.print 6 | 7 | @classes 8 | act asd() -> Name: 9 | act veeeeeereey_looooong() 10 | 11 | fun main() -> Int: 12 | let x : AnyNameAction 13 | print(x) 14 | if to_string(x) == "veeeeeereey_looooong {}": 15 | return 0 16 | return 1 17 | -------------------------------------------------------------------------------- /tool/rlc/test/loop_alloca.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | let a = 0 6 | while a != 200000000: 7 | let x : Int[1000] 8 | x[1] = 1 9 | a = a + x[1] 10 | return 0 11 | -------------------------------------------------------------------------------- /tool/rlc/test/malloc_before_break.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -i %stdlib -o %t --sanitize 2 | # RUN: %t%exeext 3 | import collections.vector 4 | import serialization.print 5 | 6 | fun main() -> Int: 7 | while true: 8 | let vector : Vector 9 | if 4 == 4: 10 | vector.append(1) 11 | vector.append(1) 12 | vector.append(1) 13 | vector.append(1) 14 | vector.append(1) 15 | vector.append(1) 16 | vector.append(1) 17 | break 18 | else: 19 | vector.append(1) 20 | 21 | return 0 22 | -------------------------------------------------------------------------------- /tool/rlc/test/malloc_before_continue.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -i %stdlib -o %t --sanitize 2 | # RUN: %t%exeext 3 | import collections.vector 4 | import serialization.print 5 | 6 | fun main() -> Int: 7 | let a = 3 8 | while 4 == a: 9 | let vector : Vector 10 | if a == 3: 11 | vector.append(1) 12 | vector.append(1) 13 | vector.append(1) 14 | vector.append(1) 15 | vector.append(1) 16 | vector.append(1) 17 | vector.append(1) 18 | a = a + 1 19 | print(vector) 20 | continue 21 | else: 22 | vector.append(1) 23 | 24 | return 0 25 | -------------------------------------------------------------------------------- /tool/rlc/test/mangled_name.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import string 5 | 6 | fun main() -> Int: 7 | if s(__builtin_mangled_name(3)) == s("int64_t"): 8 | return 0 9 | return 1 10 | -------------------------------------------------------------------------------- /tool/rlc/test/member_function.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | cls Class: 5 | fun get_field() -> Int: 6 | return self._field 7 | 8 | fun set_field(Int x): 9 | self._field = x 10 | 11 | Int _field 12 | 13 | fun main() -> Int: 14 | let x : Class 15 | x.set_field(4) 16 | return x.get_field() - 4 17 | 18 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/action_in_if.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 6:5: error: Declaration statement declared as a local variable 4 | 5 | act asd() -> Asd: 6 | let a = 0 7 | if a == a: 8 | act c() 9 | a = 3 10 | 11 | fun main() -> Int: 12 | return 0 13 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/action_in_itself.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --print-ir-on-failure=false 2>&1 --expect-fail --shared | FileCheck %s 2 | 3 | # CHECK: tool/rlc/test/messages/action_in_itself.rl:5:1: error: Action type contains itself, this in not allowed 4 | 5 | act action() -> Asd: 6 | act inner(frm Asd x) 7 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/action_statement_in_function.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdl.ib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 6:5: error: Action statements can only appear in Action Functions 4 | 5 | fun function(Int x): 6 | act play() 7 | 8 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/actions_with_different_args.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 7:5: error: Multiple definitions of actions with same name but different argument types 4 | 5 | act guess() -> Guess: 6 | act p1_choise(frm Int secret) 7 | act p1_choise(Int guess) 8 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/assert_crash.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t%exeext -i %stdlib --print-ir-on-failure=false 2 | # RUN %t%exeext | FileCheck %s 3 | 4 | 5 | # CHECK: failed assert 6 | 7 | fun main() -> Int: 8 | assert(false, "failed assert") 9 | return 0 10 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/assign_wrong_type.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 7:7: error: Cannot assign Float to Int. Cast it instead 4 | 5 | fun asd(): 6 | let a = 0 7 | a = 0.0 8 | 9 | fun main() -> Int: 10 | return 0 11 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/assign_wrong_type_struct.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 10:7: error: Could not find matching function assign(A,Float) 4 | 5 | cls A: 6 | Int b 7 | 8 | fun asd(): 9 | let a : A 10 | a = 0.0 11 | 12 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/assign_wrong_type_struct_struct.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 14:7: error: Could not find matching function assign(A,B) 4 | 5 | cls A: 6 | Int b 7 | 8 | cls B: 9 | Int b 10 | 11 | fun asd(): 12 | let a : A 13 | let b : B 14 | a = b 15 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/assign_wrong_type_struct_template.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 14:7: error: Could not find matching function assign(A,B) 4 | 5 | cls A: 6 | Int | Float c 7 | 8 | cls B: 9 | Int b 10 | 11 | fun asd(T a): 12 | let a : T 13 | let b : B 14 | a = b 15 | 16 | fun main() -> Int: 17 | let a : A 18 | asd(a) 19 | return 0 20 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/assign_wrong_type_struct_union.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 14:9: error: Could not find matching function assign(Int | Float,B) 4 | 5 | cls A: 6 | Int | Float c 7 | 8 | cls B: 9 | Int b 10 | 11 | fun asd(): 12 | let a : A 13 | let b : B 14 | a.c = b 15 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/call_to_void_function.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdl.ib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 9:14: error: Call of void returning function cannot be used as expression 4 | 5 | fun call(Int val): 6 | val = val + 1 7 | 8 | fun main() -> Int: 9 | call(call(5)) 10 | 11 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/continue_without_loop.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdl.ib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 6:5: error: Break statement cannot be used outside of a while or for statement 4 | 5 | fun function(Int x): 6 | break 7 | 8 | 9 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/double_trait_definition.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdl.ib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 9:1: error: Trait Trait already declared 4 | # CHECK: 6:1: remark: Previous declaration here 5 | 6 | trait Trait: 7 | fun wasd(T x, Int y) -> Int 8 | 9 | trait Trait: 10 | fun rasd(T K) 11 | 12 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/empty_field_name.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc --expect-fail --print-ir-on-failure=false %s -o %t -i %stdlib 2>&1 | FileCheck %s 2 | 3 | # CHECK: 5:18: error: Unexpected token: 'Newline', expected 'Identifier' 4 | cls Declared: 5 | NonExistingType 6 | 7 | fun main() -> Int: 8 | let decl : Declared 9 | return decl.field 10 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/empty_initializer_list.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdl.ib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 6:15: error: Initializer list cannot be empty 4 | 5 | fun main() -> Int: 6 | let asd = [] 7 | return 0 8 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/error.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 5:1: error: Action type cannot be primitive type 4 | 5 | act asd() -> Int: 6 | let a = 0 7 | 8 | fun main() -> Int: 9 | return 0 10 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/frm_in_fun_decl.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 5:1: error: Only types in action functions can be marked as ctx or frm. 4 | 5 | fun asd(frm Int x) -> Int: 6 | return 0 7 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/incorrect_byte_conversion.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdl.ib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 7:20: error: Type argument of __builtin_from_array must be a primitive type, not Booi 4 | 5 | fun main() -> Int: 6 | let converted2 = __builtin_to_array(true) 7 | let uncoverted2 = __builtin_from_array(converted2) 8 | return 0 9 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/invalid_frame_var.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdl.ib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 5:1: error: Action function argument declared as a local variable, but it is used in different actions. 4 | 5 | act ret_x(Int val) -> Name: 6 | act asd() 7 | val = 4 8 | 9 | fun main() -> Int: 10 | let frame = ret_x(4) 11 | return 0 12 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/missing_final_return.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 4:1: error: Non void function requires to be terminated by a return statement 4 | fun main() -> Int: 5 | if false: 6 | return 0 7 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/missing_function.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc --expect-fail --print-ir-on-failure=false %s -o %t -i %stdlib 2>&1 | FileCheck %s 2 | 3 | # CHECK: 11:10: error: Could not find matching function correct(Int) 4 | # CHECK-NEXT: return correct(4) 5 | # CHECK: 7:1: remark: Candidate: (Float) -> Int 6 | # CHECK-NEXT: fun correct(Float asd) -> Int: 7 | fun correct(Float asd) -> Int: 8 | return 0 9 | 10 | fun main() -> Int: 11 | return correct(4) 12 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/missing_return.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdl.ib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 4:1: error: Non void function requires to be terminated by a return statement 4 | fun ret_x(Int vial) -> ref Int: 5 | vial = 4 6 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/missing_var_in_action.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc --expect-fail --print-ir-on-failure=false %s -o %t -i %stdlib 2>&1 | FileCheck %s 2 | 3 | # CHECK: 10:14: error: No known value x 4 | 5 | act outer() -> Outer: 6 | inner() 7 | 8 | act inner() -> Inner: 9 | let to_return : Int 10 | to_return = x 11 | 12 | fun main() -> Int: 13 | return 0 14 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/missing_variable.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc --expect-fail --print-ir-on-failure=false %s -o %t -i %stdlib 2>&1 | FileCheck %s 2 | 3 | # CHECK: 7:10: error: No known value x2 4 | # CHECK-NEXT: return x2 5 | fun main() -> Int: 6 | let x1 = 5 7 | return x2 8 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/missmatched_argument_count.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc --expect-fail --print-ir-on-failure=false %s -o %t -i %stdlib 2>&1 | FileCheck %s 2 | 3 | # CHECK: 11:10: error: Could not find matching function correct(Float,Int) 4 | # CHECK-NEXT: return correct(4.0, 1) 5 | # CHECK: 7:1: remark: Candidate: (Float) -> Int 6 | # CHECK-NEXT: fun correct(Float asd) -> Int: 7 | fun correct(Float asd) -> Int: 8 | return 0 9 | 10 | fun main() -> Int: 11 | return correct(4.0, 1) 12 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/multiple_same_name_actions.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 8:1: error: Redefinition of action function named action 4 | 5 | act action() -> Action: 6 | act first() 7 | 8 | act action() -> Actin: 9 | act first() 10 | 11 | fun main() -> Int: 12 | let state = action() 13 | return 0 14 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/no_action_recursion_allowed.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdl.ib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 5:1: error: Found recursive call path involving Action Declaration. This is not allowed since would actions frame of infinite size 4 | 5 | act example(Int x) -> Example: 6 | example(x) 7 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/no_know_type_named.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 8:18: error: No known type named Vectora 4 | 5 | import collections.vector 6 | 7 | fun main() -> Int: 8 | let vector : Vectora 9 | return 0 10 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/non_int_array_access.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdl.ib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 6:13: error: Array access must have a integer index operand 4 | 5 | fun main() -> Int: 6 | return [11][[1, 4]] 7 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/not_enough_template_arguments.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: :10:12: error: Could not find matching function add(Int,Int) 4 | 5 | fun add(Int a, Int b) -> Int: 6 | return a + b 7 | 8 | 9 | fun main() -> Int: 10 | return add(5, 3) - 8 11 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/private_function_access.rl: -------------------------------------------------------------------------------- 1 | # RUN: split-file %s %t 2 | # RUN: rlc %t/source.rl -o %t3 -i %stdlib -i %t --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 3 | 4 | # CHECK: 4:3: error: Could not find matching function _function() 5 | 6 | #--- source.rl 7 | import to_include 8 | 9 | fun function2(): 10 | _function() 11 | 12 | #--- to_include.rl 13 | fun _function(): 14 | let y : Int 15 | 16 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/private_member_access.rl: -------------------------------------------------------------------------------- 1 | # RUN: split-file %s %t 2 | # RUN: rlc %t/source.rl -o %t3 -i %stdlib -i %t --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 3 | 4 | # CHECK: 3:4: error: Members starting with _ are private and cannot be accessed from another module 5 | 6 | #--- source.rl 7 | import to_include 8 | 9 | cls Asd: 10 | Int _x 11 | 12 | #--- to_include.rl 13 | fun function(): 14 | let y : Asd 15 | y._x 16 | 17 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/return_in_void_function.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdl.ib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 6:2: error: Return statement returns values incompatible with the function signature 4 | 5 | fun function(): 6 | return 0 7 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/subactions_nonactions.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdl.ib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 10:5: error: Subaction statement must refer to a action, not a Something 4 | 5 | cls Something: 6 | Int x 7 | 8 | act outer() -> Outer: 9 | let val : Something 10 | subaction frame = val 11 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/tensorable_warnings.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext | FileCheck %s 3 | 4 | 5 | import action 6 | 7 | 8 | cls TopLevel: 9 | # CHECK: obj.a is of type Int, which is not tensorable. Replace it instead with a BInt with appropriate bounds or specify yourself how to serialize it, 10 | Int a 11 | # CHECK-NEXT: obj.b is of type Float, which is not tensorable. Specify yourself how to serialize it, 12 | Float b 13 | Bool[3] c 14 | Vector> f 15 | 16 | act play() -> Game: 17 | # CHECK: obj.a2 is of type Int, which is not tensorable. Replace it instead with a BInt with appropriate bounds or specify yourself how to serialize it, 18 | frm a2 = 0 19 | act do_nothing() 20 | frm b2 = true 21 | 22 | fun main() -> Int: 23 | let y : TopLevel 24 | let state = play() 25 | print(to_observation_tensor_warnings(y)) 26 | print(to_observation_tensor_warnings(state)) 27 | return 0 28 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/too_many_template_types_error.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 8:18: error: Template type has 1 parameters but 2 were provided. 4 | 5 | import collections.vector 6 | 7 | fun main() -> Int: 8 | let vector : Vector 9 | return 0 10 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/wrong_action_return_type.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdl.ib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: error: User defined type clashes with implicit action type Ent 4 | 5 | cls Ent: 6 | Int x 7 | 8 | act action() -> Ent: 9 | return 5 10 | 11 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/wrong_ref_return_type.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdl.ib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 8:1: error: No known type named int 4 | 5 | cls Asd: 6 | Int x 7 | 8 | fun ret_x(Asd val) -> ref int: 9 | return val.x 10 | 11 | fun main() -> Int: 12 | let var : Asd 13 | var.x = 10 14 | let refvar = ret_x(var) 15 | var.x = 20 16 | return refvar - 20 17 | 18 | -------------------------------------------------------------------------------- /tool/rlc/test/messages/wrong_type.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdl.ib --print-ir-on-failure=false 2>&1 --expect-fail | FileCheck %s 2 | 3 | # CHECK: 8:1: error: No known type named int 4 | 5 | cls Asd: 6 | Int x 7 | 8 | fun ret_x(Asd val) -> ref int: 9 | return val.x 10 | 11 | fun main() -> Int: 12 | let var : Asd 13 | var.x = 10 14 | let refvar = ret_x(var) 15 | var.x = 20 16 | return refvar - 20 17 | 18 | -------------------------------------------------------------------------------- /tool/rlc/test/minus.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | let a = 5 6 | a = -a 7 | a = a + 5 8 | return a 9 | -------------------------------------------------------------------------------- /tool/rlc/test/multiaction_end.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize 2 | # RUN: %t%exeext 3 | 4 | import collections.vector 5 | 6 | act play(Int seed) -> Play: 7 | let board : Vector 8 | 9 | frm over = false 10 | 11 | while !over: 12 | actions: 13 | act not_quit(Int x) 14 | over = false 15 | 16 | act quit(Int y) 17 | over = true 18 | 19 | fun main() -> Int: 20 | let state = play(4) 21 | state.not_quit(2) 22 | state.quit(2) 23 | return 0 24 | -------------------------------------------------------------------------------- /tool/rlc/test/multiple_precondition.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun f(Int x) -> Int { true, x == 5 }: 5 | return x + 1 6 | 7 | fun main() -> Int: 8 | if f(5) == 6: 9 | return 0 10 | return 1 11 | -------------------------------------------------------------------------------- /tool/rlc/test/named_for_field.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext | FileCheck %s 3 | 4 | import serialization.print 5 | 6 | # CHECK: first 7 | # CHECK-NEXT: second 8 | cls Asd: 9 | Int first 10 | Int second 11 | 12 | fun main() -> Int: 13 | let x : Asd 14 | for name, value of x: 15 | print(name) 16 | return 0 17 | -------------------------------------------------------------------------------- /tool/rlc/test/negative_global_constant.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | const x = -1 5 | 6 | fun main() -> Int: 7 | return x + 1 8 | 9 | -------------------------------------------------------------------------------- /tool/rlc/test/nested_for_loops.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | import range 4 | 5 | fun main() -> Int: 6 | let count = 0 7 | for x in range(3): 8 | for y in range(3): 9 | count = count + 1 10 | return count - 9 11 | -------------------------------------------------------------------------------- /tool/rlc/test/nested_free_returned_copy.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import collections.vector 5 | 6 | cls Player: 7 | fun assign(Player other): 8 | 1 == 1 9 | 10 | cls State: 11 | Vector players 12 | 13 | fun get_current_player() -> Player: 14 | return self.players[0] 15 | 16 | 17 | fun main()-> Int: 18 | let state : State 19 | let player : Player 20 | state.players.append(player) 21 | state.get_current_player() 22 | return 0 23 | 24 | -------------------------------------------------------------------------------- /tool/rlc/test/nexted_action.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | act guess() -> Guess: 5 | act p1_choise(frm Int secret) 6 | frm result : Int 7 | 8 | while true: 9 | act p2_choise(Int guess) 10 | 11 | if guess == secret: 12 | result = secret + guess 13 | return 14 | 15 | fun main() -> Int: 16 | let struct = guess() 17 | if struct.is_done(): 18 | return 1 19 | struct.p1_choise(1) 20 | struct.p2_choise(3) 21 | struct.p2_choise(4) 22 | struct.p2_choise(1) 23 | return struct.result - 2 24 | -------------------------------------------------------------------------------- /tool/rlc/test/non_instantiated_template_assign.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | cls Example: 5 | T value 6 | fun assign(Example other): 7 | self.value = 4 8 | 9 | fun asd(Example arg): 10 | let x = 0 11 | 12 | fun main() -> Int: 13 | let x : Example 14 | let x2 : Example 15 | return x.value 16 | -------------------------------------------------------------------------------- /tool/rlc/test/not_test.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | let a = false 6 | if !a: 7 | return 0 8 | return 1 9 | -------------------------------------------------------------------------------- /tool/rlc/test/parse_and_execute_from_byte_vector.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import action 5 | 6 | @classes 7 | act play() -> Game: 8 | frm counter = 0 9 | while true: 10 | actions: 11 | act quit() 12 | return 13 | act count(Int x) 14 | counter = counter + x 15 | 16 | fun main() -> Int: 17 | let serialized : Vector 18 | 19 | let action1 : GameCount 20 | action1.x = 4 21 | 22 | let action2 : GameQuit 23 | 24 | let to_append : AnyGameAction 25 | to_append = action1 26 | append_to_byte_vector(to_append, serialized) 27 | 28 | let to_append2 : AnyGameAction 29 | to_append = action2 30 | append_to_byte_vector(to_append2, serialized) 31 | 32 | let frame = play() 33 | 34 | let action : AnyGameAction 35 | parse_and_execute(frame, action, serialized) 36 | 37 | if !frame.is_done(): 38 | return -1 39 | else if frame.counter != 4: 40 | return 1 41 | return 0 42 | -------------------------------------------------------------------------------- /tool/rlc/test/parse_array.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import string 5 | 6 | fun main() -> Int: 7 | let x : Int[2] 8 | let y : Int[2] 9 | x[0] = 1 10 | y[1] = 1 11 | from_string(y, to_string(x)) 12 | if x[0] == y[0] and x[1] == y[1]: 13 | return 0 14 | return -1 15 | -------------------------------------------------------------------------------- /tool/rlc/test/parse_bool.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import string 5 | 6 | fun main() -> Int: 7 | let parsed : Bool 8 | if parse_string(parsed, " true false "s, 0) and parsed: 9 | return 0 10 | else: 11 | return 1 12 | 13 | -------------------------------------------------------------------------------- /tool/rlc/test/parse_double.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import string 5 | 6 | fun main() -> Int: 7 | let parsed : Float 8 | if parse_string(parsed, " 34.4 "s, 0) and parsed == 34.4: 9 | return 0 10 | else: 11 | return 1 12 | -------------------------------------------------------------------------------- /tool/rlc/test/parse_false.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import string 5 | 6 | fun main() -> Int: 7 | let x = false 8 | let y = true 9 | from_string(y, to_string(x)) 10 | if x == y: 11 | return 0 12 | return -1 13 | -------------------------------------------------------------------------------- /tool/rlc/test/precondition_on_context_args.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | cls EntOne: 5 | Bool field_one 6 | 7 | cls EntTwo: 8 | Bool field_two 9 | 10 | act play(ctx EntOne one, ctx EntTwo two) -> Play: 11 | one.field_one 12 | act subact() {one.field_one} 13 | 14 | fun main() -> Int: 15 | return 0 16 | -------------------------------------------------------------------------------- /tool/rlc/test/prereq.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | act example(frm Int x) -> Example {x < 4}: 5 | x = x + 1 6 | act sub_action(Int y) {y < x} 7 | x = x 8 | 9 | fun main() -> Int: 10 | let frame = example(2) 11 | return 0 12 | -------------------------------------------------------------------------------- /tool/rlc/test/print_parse_custom_type_name.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize 2 | # RUN: %t%exeext 3 | 4 | import string 5 | import collections.vector 6 | import serialization.print 7 | 8 | cls SomeInnerStruct: 9 | Bool x 10 | 11 | cls SomeStruct: 12 | Bool | SomeInnerStruct x 13 | 14 | fun get_type_name(SomeInnerStruct s) -> StringLiteral: 15 | return "custom" 16 | 17 | fun main() -> Int: 18 | let var : SomeStruct 19 | let var2 : SomeInnerStruct 20 | var2.x = true 21 | var.x = var2 22 | let string = to_string(var) 23 | print(string) 24 | let var3 : SomeStruct 25 | from_string(var3, string) 26 | print(var3) 27 | if to_string(var3) == "{x: custom {x: true}}": 28 | return 0 29 | return 1 30 | -------------------------------------------------------------------------------- /tool/rlc/test/print_parse_enum.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import enum_utils 5 | import serialization.print 6 | 7 | enum Example: 8 | first 9 | second 10 | 11 | fun main() -> Int: 12 | let check : Example 13 | if to_string(Example::first) != "first": 14 | return -1 15 | if to_string(Example::second) != "second": 16 | return -2 17 | if !from_string(check, " second"s) or check.value != 1: 18 | return -4 19 | if !from_string(check, "first"s) or check.value != 0: 20 | return -3 21 | return 0 22 | -------------------------------------------------------------------------------- /tool/rlc/test/reaching_definitions.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize 2 | # RUN: %t%exeext 3 | 4 | import collections.vector 5 | 6 | cls Asd: 7 | Vector a 8 | 9 | fun f() -> Asd: 10 | let other : Asd 11 | return other 12 | 13 | fun make_asd() -> Asd: 14 | let other : Asd 15 | return other 16 | 17 | fun main() -> Int: 18 | make_asd().f() 19 | return 0 20 | -------------------------------------------------------------------------------- /tool/rlc/test/recursive_template.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun counter(T dc, Int x) -> Int: 5 | x = x + 1 6 | if x == 5: 7 | return x 8 | else: 9 | return counter(dc, x) 10 | 11 | fun main() -> Int: 12 | return counter(7, 0) - 5 13 | -------------------------------------------------------------------------------- /tool/rlc/test/recursive_template_entity.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | cls Pair: 5 | T first 6 | Y second 7 | 8 | cls SamePair: 9 | Pair content 10 | 11 | fun init(): 12 | if self.content.first is Int: 13 | self.content.first = 5 14 | self.content.second = 5 15 | 16 | fun main() -> Int: 17 | let var : SamePair 18 | return var.content.first + var.content.second - 10 19 | -------------------------------------------------------------------------------- /tool/rlc/test/removeUninitConstructTest.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o - -i %stdlib --flattened 2 | 3 | fun asd() -> Bool: 4 | return 1 == 1 and 2 == 2 or 3 == 3 5 | 6 | -------------------------------------------------------------------------------- /tool/rlc/test/right_shift.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | if 16 >> 2 != 4: 6 | return -1 7 | else: 8 | return 0 9 | 10 | -------------------------------------------------------------------------------- /tool/rlc/test/sanitize_should_detect_leaks.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize -g 2 | # RUN: %t%exeext 3 | # XFAIL: * 4 | # UNSUPPORTED: system-windows, system-darwin 5 | 6 | fun has_loop(): 7 | let i = 0 8 | while i < 10: 9 | let new_data = __builtin_malloc_do_not_use(1000) 10 | i = i + 1 11 | 12 | fun main() -> Int: 13 | has_loop() 14 | return 0 15 | -------------------------------------------------------------------------------- /tool/rlc/test/shortcircuiting_or.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun crash() -> Bool: 5 | let x : Int[10] 6 | x[100] 7 | return false 8 | 9 | fun main() -> Int: 10 | if true or crash(): 11 | if !(false and crash()): 12 | return 0 13 | return -1 14 | -------------------------------------------------------------------------------- /tool/rlc/test/shortcircuiting_value.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun f() {1 >= 0 and 0 < 2, true, (0 == 0 or 1 == 1), true}: 5 | return 6 | 7 | fun g() -> Bool {can f()}: 8 | return can f() 9 | 10 | fun main() -> Int: 11 | return 1 - int(can g()) 12 | -------------------------------------------------------------------------------- /tool/rlc/test/simple_struct.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | cls Asd: 5 | Int rsd 6 | Int tasd 7 | 8 | fun main() -> Int: 9 | return 0 10 | 11 | fun some_function(Asd field) -> Int: 12 | return 1 13 | -------------------------------------------------------------------------------- /tool/rlc/test/simplest_template.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun pick_second(G asd, G asd2) -> G: 5 | return asd 6 | 7 | fun main() -> Int: 8 | return pick_second(1, 2) - 1 9 | 10 | -------------------------------------------------------------------------------- /tool/rlc/test/string_append.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize -O2 -g 2 | # RUN: %t%exeext 3 | 4 | import string 5 | 6 | fun main() -> Int: 7 | let x : String 8 | x.append("hey") 9 | if x.get(0) != 'h': 10 | return -1 11 | if x.get(1) != 'e': 12 | return -2 13 | if x.get(2) != 'y': 14 | return -3 15 | if x.size() == 3: 16 | return 0 17 | return 1 18 | -------------------------------------------------------------------------------- /tool/rlc/test/string_concat.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize -O2 -g 2 | # RUN: %t%exeext 3 | 4 | import string 5 | 6 | fun main() -> Int: 7 | let x = "hey"s + "wey"s 8 | if x == "heywey"s: 9 | return 0 10 | return 1 11 | 12 | -------------------------------------------------------------------------------- /tool/rlc/test/string_literal_access.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | return int("asd"[0] == "asda"[3]) - 1 6 | -------------------------------------------------------------------------------- /tool/rlc/test/string_literal_on_boundery.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | # RUN: rlc %s -o %t --header 4 | # RUN: rlc %s -o %t --python 5 | 6 | fun f() -> StringLiteral: 7 | return "asd" 8 | 9 | fun main() -> Int: 10 | return int(f()[0] == "asda"[3]) - 1 11 | -------------------------------------------------------------------------------- /tool/rlc/test/string_parse_float.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize 2 | # RUN: %t%exeext 3 | 4 | import string 5 | 6 | fun main() -> Int: 7 | if to_string(-285.4) == "-285.400000": 8 | return 0 9 | return 1 10 | -------------------------------------------------------------------------------- /tool/rlc/test/string_parse_int.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize 2 | # RUN: %t%exeext 3 | 4 | import string 5 | 6 | fun main() -> Int: 7 | if to_string(-285) == "-285": 8 | return 0 9 | return 1 10 | -------------------------------------------------------------------------------- /tool/rlc/test/string_reverse.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize 2 | # RUN: %t%exeext 3 | 4 | import string 5 | 6 | fun main() -> Int: 7 | let str = "hey"s 8 | str.reverse() 9 | if str == "yeh"s: 10 | return 0 11 | return 1 12 | -------------------------------------------------------------------------------- /tool/rlc/test/string_suffix.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize -O2 -g 2 | # RUN: %t%exeext 3 | 4 | import string 5 | 6 | fun main() -> Int: 7 | let x = "hey"s 8 | return x.size() - 3 9 | -------------------------------------------------------------------------------- /tool/rlc/test/string_test.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize -O2 -g 2 | # RUN: %t%exeext 3 | 4 | import string 5 | 6 | fun main() -> Int: 7 | let x : String 8 | return x.size() 9 | 10 | 11 | -------------------------------------------------------------------------------- /tool/rlc/test/struct_to_string.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize 2 | # RUN: %t%exeext 3 | 4 | import string 5 | import collections.vector 6 | import serialization.print 7 | 8 | cls SomeStruct: 9 | Bool x 10 | Vector y 11 | 12 | fun main() -> Int: 13 | let var : SomeStruct 14 | var.x = true 15 | var.y.append(3) 16 | var.y.append(4) 17 | if to_string(var) == "{x: true, y: [3, 4]}": 18 | return 0 19 | return -1 20 | -------------------------------------------------------------------------------- /tool/rlc/test/subaction.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | act outer() -> Outer: 5 | frm frame = inner() 6 | act run(Int x) 7 | frame.asd(x) 8 | 9 | act inner() -> Inner: 10 | frm to_return : Int 11 | act asd(Int x) 12 | to_return = x 13 | 14 | fun main() -> Int: 15 | let frame = outer() 16 | frame.run(8) 17 | return frame.frame.to_return - 8 18 | -------------------------------------------------------------------------------- /tool/rlc/test/subaction_bounded_args.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | act inner(Int arg) -> Inner: 5 | arg = 2 6 | act set_to_5(Int arg) 7 | arg = 5 8 | act set_to_anything(Int arg, Int val) 9 | arg = val 10 | 11 | act outer() -> Outer: 12 | frm result : Int 13 | subaction*(result) inner_frame = inner(result) 14 | 15 | fun main() -> Int: 16 | let frame = outer() 17 | if frame.result != 2: 18 | return -1 19 | frame.set_to_5() 20 | if frame.result != 5: 21 | return -2 22 | frame.set_to_anything(10) 23 | if frame.result == 10: 24 | return 0 25 | return -3 26 | -------------------------------------------------------------------------------- /tool/rlc/test/subaction_expression.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | act outer() -> Outer: 5 | subaction* inner_frame = inner() 6 | 7 | act inner() -> Inner: 8 | frm sum = 60 9 | while sum != -3: 10 | actions: 11 | act first(Int x, Int y) 12 | sum = x + y 13 | 14 | act second(Bool is_set) 15 | if is_set: 16 | sum = sum * -1 17 | 18 | fun main() -> Int: 19 | let frame = outer() 20 | if frame.is_done(): 21 | return 1 22 | frame.first(1, 2) 23 | if frame.is_done(): 24 | return 2 25 | frame.second(true) 26 | if !frame.is_done(): 27 | return 4 28 | return frame.inner_frame.sum + 3 29 | -------------------------------------------------------------------------------- /tool/rlc/test/subaction_in_struct.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | act inner() -> Inner: 5 | act asd() 6 | 7 | cls Cont: 8 | Inner content 9 | 10 | act outer() -> Outer: 11 | frm asd : Cont 12 | subaction* asd.content 13 | 14 | fun main() -> Int: 15 | return 0 16 | -------------------------------------------------------------------------------- /tool/rlc/test/subaction_vending_machine.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize 2 | # RUN: %t%exeext 3 | 4 | act vending_machine(frm Int target_cost) -> VendingMachine: 5 | while target_cost != 0: 6 | actions: 7 | act insert_5_coin() 8 | target_cost = target_cost - 5 9 | act insert_1_coin() 10 | target_cost = target_cost - 1 11 | act insert_10_coin() 12 | target_cost = target_cost - 10 13 | 14 | act vending_machine_times_two(Int first, Int second) -> VendingMachinePair: 15 | frm first_machine = vending_machine(first) 16 | frm second_machine = vending_machine(second) 17 | 18 | while !first_machine.is_done() and !second_machine.is_done(): 19 | subaction first_machine 20 | subaction second_machine 21 | 22 | 23 | 24 | fun main() -> Int: 25 | let state = vending_machine_times_two(10, 2) 26 | state.insert_5_coin() 27 | state.insert_1_coin() 28 | state.insert_5_coin() 29 | state.insert_1_coin() 30 | if state.is_done(): 31 | return 0 32 | return 1 33 | -------------------------------------------------------------------------------- /tool/rlc/test/subaction_with_expression.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | act with_context(ctx Int a) -> Type: 5 | act do_something() 6 | 7 | cls G: 8 | Int a 9 | 10 | act caller() -> Type2: 11 | frm g : G 12 | subaction*(g.a) sub = with_context(g.a) 13 | 14 | fun main() -> Int: 15 | let c = caller() 16 | c.do_something() 17 | if c.is_done(): 18 | return 0 19 | return 1 20 | -------------------------------------------------------------------------------- /tool/rlc/test/subtemplate.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun identity(T asd) -> T: 5 | return asd 6 | 7 | fun pick_second(G asd, G asd2) -> G: 8 | return identity(asd2) 9 | 10 | fun main() -> Int: 11 | return pick_second(1, 2) - 2 12 | -------------------------------------------------------------------------------- /tool/rlc/test/template.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | trait Addable: 5 | fun add(T i, T i2) -> T 6 | 7 | fun timesTwo(T i) -> T: 8 | return add(i, i) 9 | 10 | fun add(Int i, Int i2) -> Int: 11 | return i + i2 12 | 13 | fun main() -> Int: 14 | return timesTwo(1) - 2 15 | -------------------------------------------------------------------------------- /tool/rlc/test/template_array.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | cls ArrayVector: 5 | T[10] data 6 | Int size 7 | 8 | fun append(T new): 9 | self.data[self.size] = new 10 | self.size = self.size + 1 11 | 12 | fun pop() -> T: 13 | self.size = self.size - 1 14 | return self.data[self.size] 15 | 16 | fun main() -> Int: 17 | let array : ArrayVector 18 | array.append(1) 19 | array.append(2) 20 | array.append(3) 21 | array.pop() 22 | return array.pop() - 2 23 | -------------------------------------------------------------------------------- /tool/rlc/test/template_can_call.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun function(Int x, T dc) -> Int {x < 4}: 5 | return x - 1 6 | 7 | fun function2(Int x, T dc) -> Bool: 8 | return can function(x, dc) 9 | 10 | fun main() -> Int: 11 | if function2(5, 5.0): 12 | return -4 13 | else if function2(1, 5.0): 14 | return 0 15 | else: 16 | return 4 17 | -------------------------------------------------------------------------------- /tool/rlc/test/template_custom_assign.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | cls CustomAssign: 5 | Int x 6 | 7 | fun assign(CustomAssign other): 8 | self.x = other.x + 1 9 | 10 | 11 | fun main() -> Int: 12 | let var : CustomAssign 13 | let copy : CustomAssign 14 | copy = var 15 | return copy.x - 1 16 | -------------------------------------------------------------------------------- /tool/rlc/test/template_destructor.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o - -i %stdlib --flattened | FileCheck %s 2 | 3 | cls CustomDestructor: 4 | Int a 5 | 6 | fun drop(): 7 | self.a = 2 8 | 9 | # CHECK: rlc.flat_fun "main" 10 | fun main() -> Int: 11 | # CHECK: rlc.ref @rl_m_drop__CustomDestructorTint64_tT 12 | # CHECK-NEXT: rlc.call 13 | let var : CustomDestructor 14 | return 0 15 | # CHECK-NOT: rlc.ref @rl_m_drop__CustomDestructorTint64_tT 16 | -------------------------------------------------------------------------------- /tool/rlc/test/template_entity.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | cls TemplatedEntity: 5 | T asd 6 | 7 | fun main() -> Int: 8 | let var : TemplatedEntity 9 | var.asd = 2 10 | return var.asd - 2 11 | -------------------------------------------------------------------------------- /tool/rlc/test/template_in_class_only.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | cls Vector: 5 | Int content 6 | 7 | fun init(): 8 | self.content = 3 9 | 10 | fun drop(): 11 | self.content = 3 12 | 13 | cls VectorContainer: 14 | Vector asd 15 | 16 | 17 | fun main() -> Int: 18 | return 0 19 | -------------------------------------------------------------------------------- /tool/rlc/test/template_member_function.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | cls Class: 5 | fun get_field() -> T: 6 | return self._field 7 | 8 | fun set_field(T x): 9 | self._field = x 10 | 11 | fun identity(R val) -> R: 12 | return val 13 | 14 | T _field 15 | 16 | fun main() -> Int: 17 | let x : Class 18 | x.set_field(4) 19 | return x.identity(x.get_field() - 4) 20 | 21 | -------------------------------------------------------------------------------- /tool/rlc/test/tensor_serialization.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import action 5 | 6 | fun main() -> Int: 7 | let vec : Vector 8 | let y : Bool | BInt<0, 3> 9 | let v : BoundedVector, 2> 10 | let bounded_arg : BInt<0, 3> 11 | 12 | bounded_arg.value = 1 13 | y = bounded_arg 14 | v.append(y) 15 | v.append(y) 16 | let x = observation_tensor_size(v) 17 | while x != 0: 18 | vec.append(0.0) 19 | x = x - 1 20 | to_observation_tensor(v, 0, vec) 21 | if vec.size() != 10: 22 | return 1 23 | if vec.get(1) != 1.0: 24 | return 2 25 | if vec.get(3) != 1.0: 26 | return 3 27 | 28 | return 0 29 | -------------------------------------------------------------------------------- /tool/rlc/test/test_action.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | act action_example(Int x) -> Action: 5 | let wasd = 4 6 | frm asd = wasd + x 7 | 8 | act dont_care() 9 | asd = asd 10 | 11 | fun main() -> Int: 12 | let coroutine_frame = action_example(6) 13 | return coroutine_frame.asd - 10 14 | -------------------------------------------------------------------------------- /tool/rlc/test/test_and.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun return_true() -> Bool: 5 | return 4 * 12 == 48 6 | 7 | fun main() -> Int: 8 | let yes = return_true() and true 9 | return 0 10 | -------------------------------------------------------------------------------- /tool/rlc/test/test_apply_action.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | import action 5 | 6 | @classes 7 | act example() -> Name: 8 | act first(Int x) 9 | frm to_return = x 10 | act second(Bool x, Float y) 11 | 12 | fun main() -> Int: 13 | let any_action : AnyNameAction 14 | 15 | let actual_action : NameFirst 16 | actual_action.x = 1 17 | any_action = actual_action 18 | 19 | let frame = example() 20 | if !can apply(any_action, frame): 21 | return -3 22 | apply(any_action, frame) 23 | if frame.to_return == 1: 24 | return 0 25 | return 1 26 | -------------------------------------------------------------------------------- /tool/rlc/test/test_member_alternative_assign.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize 2 | # RUN: %t%exeext 3 | 4 | cls SomeInnerStruct: 5 | Bool x 6 | 7 | cls SomeStruct: 8 | Bool | SomeInnerStruct x 9 | 10 | 11 | fun main() -> Int: 12 | let var : SomeStruct 13 | let var2 : SomeInnerStruct 14 | var2.x = true 15 | var.x = var2 16 | ref field = var.x 17 | if field is SomeInnerStruct: 18 | if field.x: 19 | return 0 20 | else: 21 | return 1 22 | return -1 23 | 24 | -------------------------------------------------------------------------------- /tool/rlc/test/test_pair.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize 2 | # RUN: %t%exeext 3 | 4 | import collections.pair 5 | 6 | fun main() -> Int: 7 | let first : Vector 8 | let second : Vector 9 | first.append(true) 10 | first.append(false) 11 | second.append(0.0) 12 | second.append(1.1) 13 | let zipped = zip(first, second) 14 | if zipped.get(0).first != true: 15 | return -1 16 | if zipped.get(1).first != false: 17 | return -1 18 | if zipped.get(0).second != 0.0: 19 | return -1 20 | if zipped.get(1).second != 1.1: 21 | return -1 22 | return 0 23 | -------------------------------------------------------------------------------- /tool/rlc/test/test_print.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext | FileCheck %s 3 | 4 | import serialization.print 5 | 6 | # CHECK: result is: 4 7 | fun main() -> Int: 8 | print("result is: "s + to_string(4)) 9 | return 0 10 | -------------------------------------------------------------------------------- /tool/rlc/test/test_trace_runner.rl: -------------------------------------------------------------------------------- 1 | # RUN: split-file %s %t 2 | # RUN: python %pyscript/action.py %t/source.rl %t/trace.txt --stdlib %stdlib -ii | FileCheck %s 3 | 4 | # CHECK: asd {x: 4} 5 | # CHECK-NEXT: asd2 {y: {field: 5}} 6 | # CHECK-NEXT: asd3 {} 7 | # CHECK-NEXT: {resume_index: -1} 8 | 9 | #--- source.rl 10 | import action 11 | 12 | cls Struct: 13 | Int field 14 | 15 | @classes 16 | act play() -> Game: 17 | act asd(Int x) {x == 4} 18 | act asd2(Struct y) {y.field == 5} 19 | act asd3() 20 | 21 | #--- trace.txt 22 | asd {x: 4} 23 | asd2 {y: {field: 5}} 24 | asd {x: 10} 25 | asd3 {} 26 | -------------------------------------------------------------------------------- /tool/rlc/test/to_be_fuzzed.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --fuzzer --fuzzer-lib=%fuzzer_lib 2 | # RUN: %t%exeext -runs=100000 3 | # XFAIL: * 4 | 5 | import action 6 | 7 | fun crash_on_five(Byte input) -> Int {input != byte(5)}: 8 | return 0 9 | 10 | act play() -> Play: 11 | frm current = 0 12 | while current != 7: 13 | act that(Byte a) {a >= byte(0), a < byte(100)} 14 | crash_on_five(a) 15 | 16 | fun fuzz(Vector input): 17 | let frame = play() 18 | let action : AnyPlayAction 19 | parse_and_execute(frame, action, input) 20 | -------------------------------------------------------------------------------- /tool/rlc/test/to_from_byte_array.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | let converted = __builtin_to_array(6) 6 | let unconverted = __builtin_from_array(converted) 7 | let converted2 = __builtin_to_array(true) 8 | let uncoverted2 = __builtin_from_array(converted2) 9 | let converted3 = __builtin_to_array(7.0) 10 | let unconverted3 = __builtin_from_array(converted3) 11 | let byte_array = __builtin_to_array(true) 12 | let read = __builtin_from_array(byte_array) 13 | if !read: 14 | return -1 15 | let byte_array2 = __builtin_to_array(false) 16 | let read2 = __builtin_from_array(byte_array2) 17 | if read2: 18 | return -2 19 | return int(unconverted3) - (unconverted + int(uncoverted2)) 20 | -------------------------------------------------------------------------------- /tool/rlc/test/trailing_comments.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | return 0 6 | 7 | # i am a wonderfull comment 8 | -------------------------------------------------------------------------------- /tool/rlc/test/trait.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | trait Trait: 5 | fun wasd(T x, Int y) -> Int 6 | fun rasd(T K) 7 | 8 | fun wasd(Int x, Int y) -> Int: 9 | return x + y 10 | 11 | fun rasd(Int K): 12 | wasd(K, 0) 13 | 14 | fun main() -> Int: 15 | if 5.0 is Trait: 16 | return -1 17 | 18 | if 5 is Trait: 19 | return 0 20 | else: 21 | return -1 22 | -------------------------------------------------------------------------------- /tool/rlc/test/trait_in_function_body.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | trait HasF: 5 | fun f(T arg) 6 | 7 | cls A: 8 | Int b 9 | 10 | fun f(A a): 11 | a.b 12 | 13 | fun invoke_twice(G a): 14 | let d = a 15 | d.f() 16 | d.f() 17 | 18 | fun main() -> Int: 19 | let a : A 20 | if a is HasF : 21 | return 0 22 | return -1 23 | -------------------------------------------------------------------------------- /tool/rlc/test/tutorial/START_HERE.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | # These files are a series of examples to introduce you to the rulebook language. 5 | # Each of these files is a valid rl program that can be run by pressing ctrl+shift+b. 6 | 7 | # Here the simplest rl program. Try running it, and then try edit the return value to 10 8 | # to see the program fail. 9 | 10 | fun main() -> Int: 11 | let exit_code = 0 12 | return exit_code 13 | 14 | # Open the other files, starting with `2.rl`, in this directory to see what are the 15 | # main features of the language. 16 | 17 | # The `more_examples` folder contains other short programs currently used as tests 18 | # in the compiler that you can freely explore. 19 | -------------------------------------------------------------------------------- /tool/rlc/test/upcasting_is.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun returnDoubleIfInt(T a) -> T: 5 | let to_return : T 6 | if a is Int: 7 | if to_return is Int: 8 | to_return = a + a 9 | return to_return 10 | 11 | fun main() -> Int: 12 | return returnDoubleIfInt(2) - 4 13 | -------------------------------------------------------------------------------- /tool/rlc/test/user_of_action_statement_type.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | @classes 5 | act action() -> Action: 6 | frm to_return = 0 7 | act to_call(Int arg) 8 | to_return = arg 9 | 10 | fun main() -> Int: 11 | let frame = action() 12 | let x : ActionToCall 13 | x.arg = 4 14 | 15 | apply(x, frame) 16 | 17 | if frame.to_return == 4: 18 | return 0 19 | else: 20 | return 1 21 | -------------------------------------------------------------------------------- /tool/rlc/test/using_type_directly.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | using T = Int 6 | let asd : T 7 | asd = 10 8 | return asd - 10 9 | 10 | -------------------------------------------------------------------------------- /tool/rlc/test/var_decl_in_template_is.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize 2 | # RUN: %t%exeext 3 | 4 | trait CustomTrait: 5 | fun to_call(T x) -> Bool 6 | 7 | fun template(T to_visit): 8 | if to_visit is Alternative: 9 | for name, field of to_visit: 10 | if field is CustomTrait: 11 | let bool = field.to_call() 12 | 13 | fun main() -> Int: 14 | let x : Int | Bool 15 | template(x) 16 | 17 | return 0 18 | -------------------------------------------------------------------------------- /tool/rlc/test/vector_assign.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | cls Asd: 5 | Int value 6 | 7 | fun main() -> Int: 8 | let x : Asd[10] 9 | let y : Asd[10] 10 | x[3].value = 1 11 | y = x 12 | return y[3].value - 1 13 | -------------------------------------------------------------------------------- /tool/rlc/test/vector_in_action.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize -g 2 | # RUN: %t%exeext 3 | 4 | import collections.vector 5 | 6 | act has_member() -> HM: 7 | frm member: Vector 8 | member.append(10) 9 | act asd() 10 | 11 | fun main() -> Int: 12 | let hm = has_member() 13 | return 0 14 | -------------------------------------------------------------------------------- /tool/rlc/test/vector_in_actions_does_not_leak.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize 2 | # RUN: %t%exeext 3 | 4 | import collections.vector 5 | import serialization.print 6 | 7 | cls Context: 8 | Int x 9 | Int y 10 | 11 | act sequence(ctx Context context) -> Sequence: 12 | frm accumulator : Vector 13 | while true: 14 | act add(Int z) 15 | accumulator.append(context.x + context.y + z) 16 | print(accumulator) 17 | 18 | fun main() -> Int: 19 | let context : Context 20 | let state = sequence(context) 21 | state.add(context, 10) 22 | return 0 23 | -------------------------------------------------------------------------------- /tool/rlc/test/vector_in_loop.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --sanitize -g 2 | # RUN: %t%exeext 3 | import collections.vector 4 | 5 | cls Entity: 6 | Vector member 7 | 8 | fun has_loop(): 9 | let i = 0 10 | while i < 10: 11 | let e : Entity 12 | i = i + 1 13 | 14 | fun main() -> Int: 15 | has_loop() 16 | return 0 17 | -------------------------------------------------------------------------------- /tool/rlc/test/void_definition.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun fun_with_trailing_type() -> Void: 5 | let aasds = 0 6 | return 7 | 8 | fun function(): 9 | return 10 | 11 | 12 | fun main() -> Int: 13 | function() 14 | fun_with_trailing_type() 15 | return 0 16 | -------------------------------------------------------------------------------- /tool/rlc/test/while_after_action.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | act play() -> Game: 4 | 5 | act f() 6 | 7 | while true: 8 | 1 9 | 10 | fun main() -> Int: 11 | let x = play() 12 | return 0 13 | -------------------------------------------------------------------------------- /tool/rlc/test/while_test.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun while_function(Int a) -> Int: 5 | while (4 > 5): 6 | let b = 8 7 | 8 | while (4 < 5): 9 | return 0 10 | 11 | return 1 12 | 13 | fun main() -> Int: 14 | return while_function(6) 15 | -------------------------------------------------------------------------------- /tool/rlc/test/wrappers/c_function.rl: -------------------------------------------------------------------------------- 1 | # RUN: split-file %s %t 2 | 3 | # RUN: rlc %t/source.rl -o %t/lib%sharedext -i %stdlib --shared 4 | # RUN: rlc %t/source.rl -o %t/lib%libext -i %stdlib --compile 5 | 6 | # RUN: rlc %t/source.rl -o %t/header.h -i %stdlib --header 7 | # RUN: clang %t/to_run.c %t/lib%libext -o %t/result%exeext 8 | # RUN: %t/result%exeext 9 | 10 | # RUN: rlc %t/source.rl -o %t/wrapper.py -i %stdlib --python 11 | # RUN: python %t/to_run.py 12 | 13 | #--- source.rl 14 | fun to_invoke() -> Int {true}: 15 | return 5 16 | 17 | #--- to_run.c 18 | #include 19 | #include 20 | #define RLC_GET_FUNCTION_DECLS 21 | #define RLC_GET_TYPE_DECLS 22 | #define RLC_GET_TYPE_DEFS 23 | #include "./header.h" 24 | 25 | int main() { 26 | int64_t result; 27 | rl_to_invoke__r_int64_t(&result); 28 | return 5 - result; 29 | } 30 | 31 | 32 | #--- to_run.py 33 | import wrapper as wrapper 34 | 35 | assert(wrapper.can_to_invoke()) 36 | exit(wrapper.to_invoke() - 5) 37 | -------------------------------------------------------------------------------- /tool/rlc/test/wrappers/call_function.rl: -------------------------------------------------------------------------------- 1 | # RUN: split-file %s %t 2 | # RUN: rlc %t/source.rl -o %t/lib%sharedext -i %stdlib --shared %pyrlc_lib 3 | # RUN: rlc %t/source.rl -o %t/wrapper.py -i %stdlib --python 4 | # RUN: python %t/to_run.py 5 | 6 | #--- source.rl 7 | import python 8 | 9 | fun rlc_call(PyObject x, Bool obj): 10 | x.call(to_pyobject(obj)) 11 | 12 | 13 | #--- to_run.py 14 | import wrapper 15 | 16 | 17 | called = False 18 | def py_call(obj): 19 | global called 20 | called = obj 21 | 22 | wrapper.rlc_call(py_call, True) 23 | assert(called) 24 | 25 | -------------------------------------------------------------------------------- /tool/rlc/test/wrappers/callpython.rl: -------------------------------------------------------------------------------- 1 | # RUN: split-file %s %t 2 | # RUN: rlc %t/source.rl -o %t/lib%sharedext -i %stdlib --shared %pyrlc_lib 3 | # RUN: rlc %t/source.rl -o %t/wrapper.py -i %stdlib --python 4 | # RUN: python %t/to_run.py 5 | 6 | #--- source.rl 7 | import python 8 | import serialization.print 9 | 10 | fun rlc_call(PyObject x, Int value): 11 | x.call("py_call", to_pyobject(value)) 12 | 13 | 14 | #--- to_run.py 15 | import wrapper 16 | 17 | class C: 18 | def __init__(self): 19 | self.value = 3 20 | 21 | def py_call(self, obj): 22 | self.value = obj 23 | 24 | c = C() 25 | 26 | wrapper.rlc_call(c, 10) 27 | assert(c.value == 10) 28 | -------------------------------------------------------------------------------- /tool/rlc/test/wrappers/csharp_action.rl: -------------------------------------------------------------------------------- 1 | # REQUIRES: has_mono 2 | # RUN: split-file %s %t 3 | 4 | # RUN: rlc %t/source.rl -o %t/Lib%sharedext -i %stdlib --shared 5 | # RUN: rlc %t/source.rl -o %t/csharp.cs -i %stdlib --c-sharp 6 | 7 | # RUN: mcs -out:%t/executable.exe %t/csharp.cs %t/main.cs -unsafe 8 | # RUN: mono %t/executable.exe 9 | 10 | #--- source.rl 11 | 12 | act play() -> Game: 13 | frm asd = 0 14 | act pick(Int x) 15 | asd = x 16 | 17 | #--- main.cs 18 | using System; 19 | using System.IO; 20 | using System.Reflection; 21 | class Tester { 22 | public static int Main() { 23 | RLCNative.setup(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "/Lib" + RLCNative.SharedLibExtension); 24 | Game pair = RLC.play(); 25 | pair.pick(3); 26 | return (int)(pair.asd - 3); 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /tool/rlc/test/wrappers/csharp_alias.rl: -------------------------------------------------------------------------------- 1 | # RUN: split-file %s %t 2 | 3 | # RUN: rlc %t/source.rl -o %t/Lib%sharedext -i %stdlib --shared 4 | # RUN: rlc %t/source.rl -o %t/csharp.cs -i %stdlib --c-sharp 5 | 6 | # RUN: mcs -out:%t/executable.exe %t/csharp.cs %t/main.cs -unsafe 7 | # RUN: mono %t/executable.exe 8 | # REQUIRES: has_mono 9 | 10 | #--- source.rl 11 | import collections.vector 12 | using ThisOne = Int | Float 13 | 14 | #--- main.cs 15 | using System; 16 | using System.IO; 17 | using System.Reflection; 18 | class Tester { 19 | public static int Main() { 20 | RLCNative.setup(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "/Lib" + RLCNative.SharedLibExtension); 21 | ThisOne pair = new ThisOne(); 22 | return 0; 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /tool/rlc/test/wrappers/csharp_call.rl: -------------------------------------------------------------------------------- 1 | # RUN: split-file %s %t 2 | 3 | # RUN: rlc %t/source.rl -o %t/Lib%sharedext -i %stdlib --shared 4 | # RUN: rlc %t/source.rl -o %t/csharp.cs -i %stdlib --c-sharp 5 | 6 | # RUN: mcs -out:%t/executable.exe %t/csharp.cs %t/main.cs -unsafe 7 | # RUN: mono %t/executable.exe 8 | # REQUIRES: has_mono 9 | 10 | #--- source.rl 11 | fun to_invoke() -> Int {true}: 12 | return 5 13 | 14 | #--- main.cs 15 | using System; 16 | using System.IO; 17 | using System.Reflection; 18 | class Tester { 19 | public static int Main() { 20 | RLCNative.setup(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "/Lib" + RLCNative.SharedLibExtension); 21 | long result = RLC.to_invoke(); 22 | return ((int)(result)) - 5; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tool/rlc/test/wrappers/csharp_custom_functions.rl: -------------------------------------------------------------------------------- 1 | # RUN: split-file %s %t 2 | 3 | # RUN: rlc %t/source.rl -o %t/Lib%sharedext -i %stdlib --shared 4 | # RUN: rlc %t/source.rl -o %t/csharp.cs -i %stdlib --c-sharp 5 | 6 | # RUN: mcs -out:%t/executable.exe %t/csharp.cs %t/main.cs -unsafe 7 | # RUN: mono %t/executable.exe 8 | # REQUIRES: has_mono 9 | 10 | #--- source.rl 11 | cls Pair: 12 | Int x 13 | Int y 14 | 15 | fun init(): 16 | self.x = 2 17 | self.y = 1 18 | 19 | cls Outer: 20 | Pair inner 21 | 22 | 23 | fun to_invoke(Outer self, Int to_add) -> Int {true}: 24 | return self.inner.x + self.inner.y + to_add 25 | 26 | #--- main.cs 27 | using System; 28 | using System.IO; 29 | using System.Reflection; 30 | class Tester { 31 | public static int Main() { 32 | RLCNative.setup(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "/Lib" + RLCNative.SharedLibExtension); 33 | Outer pair = new Outer(); 34 | Console.WriteLine(pair.inner.x); 35 | 36 | return ((int) RLC.to_invoke(pair, 2)) - 5; 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /tool/rlc/test/wrappers/csharp_enums.rl: -------------------------------------------------------------------------------- 1 | # RUN: split-file %s %t 2 | 3 | # RUN: rlc %t/source.rl -o %t/Lib%sharedext -i %stdlib --shared 4 | # RUN: rlc %t/source.rl -o %t/csharp.cs -i %stdlib --c-sharp 5 | 6 | # RUN: mcs -out:%t/executable.exe %t/csharp.cs %t/main.cs -unsafe 7 | # RUN: mono %t/executable.exe 8 | # REQUIRES: has_mono 9 | 10 | #--- source.rl 11 | enum Signal: 12 | rock 13 | paper 14 | scizzor 15 | 16 | #--- main.cs 17 | using System; 18 | using System.IO; 19 | using System.Reflection; 20 | class Tester { 21 | public static int Main() { 22 | RLCNative.setup(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "/Lib" + RLCNative.SharedLibExtension); 23 | Signal pair = Signal.paper(); 24 | return (int)(pair.value - 1); 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /tool/rlc/test/wrappers/csharp_struct_decl.rl: -------------------------------------------------------------------------------- 1 | # RUN: split-file %s %t 2 | 3 | # RUN: rlc %t/source.rl -o %t/Lib%sharedext -i %stdlib --shared 4 | # RUN: rlc %t/source.rl -o %t/csharp.cs -i %stdlib --c-sharp 5 | 6 | # RUN: mcs -out:%t/executable.exe %t/csharp.cs %t/main.cs -unsafe 7 | # RUN: mono %t/executable.exe 8 | # REQUIRES: has_mono 9 | 10 | #--- source.rl 11 | cls Pair: 12 | Int x 13 | Int y 14 | 15 | fun to_invoke() -> Int {true}: 16 | return self.x + self.y 17 | 18 | cls Outer: 19 | Pair inner 20 | 21 | fun to_invoke() -> Int {true}: 22 | return self.inner.x + self.inner.y 23 | 24 | #--- main.cs 25 | using System; 26 | using System.IO; 27 | using System.Reflection; 28 | class Tester { 29 | public static int Main() { 30 | RLCNative.setup(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "/Lib" + RLCNative.SharedLibExtension); 31 | Outer pair = new Outer(); 32 | pair.inner.x = 2; 33 | pair.inner.y = 1; 34 | 35 | return ((int) pair.inner.to_invoke()) - 3; 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /tool/rlc/test/wrappers/csharp_union.rl: -------------------------------------------------------------------------------- 1 | # RUN: split-file %s %t 2 | 3 | # RUN: rlc %t/source.rl -o %t/Lib%sharedext -i %stdlib --shared 4 | # RUN: rlc %t/source.rl -o %t/csharp.cs -i %stdlib --c-sharp 5 | 6 | # RUN: mcs -out:%t/executable.exe %t/csharp.cs %t/main.cs -unsafe 7 | # RUN: mono %t/executable.exe 8 | # REQUIRES: has_mono 9 | 10 | #--- source.rl 11 | cls Pair: 12 | Int | Float x 13 | 14 | 15 | cls Outer: 16 | Pair inner 17 | 18 | #--- main.cs 19 | using System; 20 | using System.IO; 21 | using System.Reflection; 22 | class Tester { 23 | public static int Main() { 24 | RLCNative.setup(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "/Lib" + RLCNative.SharedLibExtension); 25 | Outer pair = new Outer(); 26 | pair.inner.x.assign(2.2); 27 | if (pair.inner.x.get_long != null) { 28 | return -10; 29 | } 30 | return (int)(pair.inner.x.get_double - 2.2); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tool/rlc/test/wrappers/csharp_vector.rl: -------------------------------------------------------------------------------- 1 | # RUN: split-file %s %t 2 | 3 | # RUN: rlc %t/source.rl -o %t/Lib%sharedext -i %stdlib --shared 4 | # RUN: rlc %t/source.rl -o %t/csharp.cs -i %stdlib --c-sharp 5 | 6 | # RUN: mcs -out:%t/executable.exe %t/csharp.cs %t/main.cs -unsafe 7 | # RUN: mono %t/executable.exe 8 | # REQUIRES: has_mono 9 | 10 | #--- source.rl 11 | import collections.vector 12 | cls Pair: 13 | Vector x 14 | 15 | fun asd(): 16 | let x : Pair 17 | x.x.size() 18 | 19 | 20 | #--- main.cs 21 | using System; 22 | using System.IO; 23 | using System.Reflection; 24 | class Tester { 25 | public static int Main() { 26 | RLCNative.setup(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "/Lib" + RLCNative.SharedLibExtension); 27 | VectorTint64_tT pair = new VectorTint64_tT(); 28 | long x = 2; 29 | pair.append(x); 30 | pair.append(x); 31 | pair.append(x); 32 | return (int)(pair.size() - 3); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tool/rlc/test/wrappers/custom_abort.rl: -------------------------------------------------------------------------------- 1 | # RUN: split-file %s %t 2 | 3 | # RUN: rlc %t/source.rl -o %t/lib%libext -i %stdlib --compile --abort-symbol "custom_abort" 4 | # RUN: rlc %t/source.rl -o %t/header.h -i %stdlib --header 5 | # RUN: clang %t/to_run.c %t/lib%libext -o %t/result%exeext 6 | # RUN: %t/result%exeext 7 | 8 | 9 | #--- source.rl 10 | fun to_invoke() -> Int: 11 | assert(false, "message") 12 | return 5 13 | 14 | #--- to_run.c 15 | #include 16 | #include 17 | #define RLC_GET_FUNCTION_DECLS 18 | #define RLC_GET_TYPE_DECLS 19 | #include "./header.h" 20 | #include "string.h" 21 | #include "stdio.h" 22 | 23 | void custom_abort(char* message){ 24 | } 25 | 26 | int main() { 27 | int64_t result; 28 | rl_to_invoke__r_int64_t(&result); 29 | return 0; 30 | } 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /tool/rlc/test/wrappers/godot_wrapper.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib --godot 2 | 3 | fun example_add(Int x, Int y) -> Int: 4 | return x + y 5 | 6 | -------------------------------------------------------------------------------- /tool/rlc/test/wrappers/python_enum.rl: -------------------------------------------------------------------------------- 1 | # RUN: split-file %s %t 2 | # RUN: rlc %t/source.rl -o %t/lib%sharedext -i %stdlib --shared --pyrlc-lib=%pyrlc_lib 3 | # RUN: rlc %t/source.rl -o %t/wrapper.py -i %stdlib --python 4 | # RUN: python %t/to_run.py 5 | 6 | #--- source.rl 7 | 8 | enum Something: 9 | first 10 | second 11 | 12 | 13 | #--- to_run.py 14 | import wrapper 15 | 16 | assert wrapper.Something.second().value == 1 17 | -------------------------------------------------------------------------------- /tool/rlc/test/wrappers/python_templates.rl: -------------------------------------------------------------------------------- 1 | # RUN: split-file %s %t 2 | # RUN: rlc %t/source.rl -o %t/lib%sharedext -i %stdlib --shared --pyrlc-lib=%pyrlc_lib 3 | # RUN: rlc %t/source.rl -o %t/wrapper.py -i %stdlib --python 4 | # RUN: python %t/to_run.py 5 | 6 | #--- source.rl 7 | fun this_one(T i) -> StringLiteral: 8 | if i is Int: 9 | return "int" 10 | if i is Bool: 11 | return "bool" 12 | return "none" 13 | 14 | fun asd(): 15 | this_one(1) 16 | this_one(true) 17 | 18 | #--- to_run.py 19 | import wrapper 20 | 21 | assert(wrapper.this_one(True).decode("utf-8") == 'bool') 22 | -------------------------------------------------------------------------------- /tool/rlc/test/wrappers/wrap_rlc_object_into_ctypes_pointer.rl: -------------------------------------------------------------------------------- 1 | # RUN: split-file %s %t 2 | # RUN: rlc %t/source.rl -o %t/lib%sharedext -i %stdlib --shared %pyrlc_lib 3 | # RUN: rlc %t/source.rl -o %t/wrapper.py -i %stdlib --python 4 | # RUN: python %t/to_run.py 5 | 6 | #--- source.rl 7 | import python 8 | import serialization.print 9 | 10 | cls Something: 11 | Int content 12 | 13 | fun rlc_call(PyObject x, Something value): 14 | x.call("py_call", to_pyobject(value)) 15 | 16 | 17 | #--- to_run.py 18 | import wrapper 19 | 20 | class C: 21 | def __init__(self): 22 | self.value = None 23 | 24 | def py_call(self, obj): 25 | self.value = obj 26 | 27 | 28 | c = C() 29 | rlc_obj = wrapper.Something() 30 | rlc_obj.content = 10 31 | 32 | wrapper.rlc_call(c, rlc_obj) 33 | 34 | assert(wrapper.ctypes.addressof(rlc_obj) == wrapper.ctypes.addressof(c.value)) 35 | -------------------------------------------------------------------------------- /tool/rlc/test/write_reference.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | cls Outer: 5 | Int inner 6 | 7 | fun take_ref(Outer val) -> ref Int: 8 | return val.inner 9 | 10 | fun main() -> Int: 11 | let var : Outer 12 | var.inner = 4 13 | take_ref(var) = 3 14 | return var.inner - 3 15 | 16 | -------------------------------------------------------------------------------- /tool/rlc/test/zero_terminated_string_literal.rl: -------------------------------------------------------------------------------- 1 | # RUN: rlc %s -o %t -i %stdlib 2 | # RUN: %t%exeext 3 | 4 | fun main() -> Int: 5 | if "asd"[3] != '\0': 6 | return -1 7 | else: 8 | return 0 9 | --------------------------------------------------------------------------------