├── .gitignore
├── 3rdparty
├── linenoise
│ ├── .gitignore
│ ├── Makefile
│ ├── README.markdown
│ ├── example.c
│ ├── linenoise.c
│ └── linenoise.h
└── tinymt
│ ├── CHANGE-LOG.txt
│ ├── LICENSE.txt
│ ├── Makefile
│ ├── check32.c
│ ├── check32.out.txt
│ ├── check64.c
│ ├── check64.out.txt
│ ├── dc
│ ├── include
│ │ ├── random_util.hpp
│ │ ├── recursion_search.hpp
│ │ ├── search_all.hpp
│ │ ├── search_temper.hpp
│ │ ├── sequential.hpp
│ │ └── simple_shortest_basis.hpp
│ └── src
│ │ ├── LICENSE.txt
│ │ ├── Makefile
│ │ ├── doxygen.cfg
│ │ ├── getid.cpp
│ │ ├── mainpage.txt
│ │ ├── output.hpp
│ │ ├── parse_opt.cpp
│ │ ├── parse_opt.h
│ │ ├── tinymt32dc.0.20.txt
│ │ ├── tinymt32dc.cpp
│ │ ├── tinymt32search.hpp
│ │ ├── tinymt64dc.0.20.txt
│ │ ├── tinymt64dc.cpp
│ │ └── tinymt64search.hpp
│ ├── doxygen.cfg
│ ├── mainpage.txt
│ ├── readme-jp.html
│ ├── readme.html
│ ├── tinymt32.c
│ ├── tinymt32.h
│ ├── tinymt64.c
│ ├── tinymt64.cc
│ └── tinymt64.h
├── BUGS
├── BUILDING.txt
├── LICENSE.txt
├── Makefile
├── README.md
├── Vagrantfile
├── docs
├── code_samples
│ ├── 99_bottles_of_beer.ca
│ ├── hello_world.ca
│ ├── projecteuler_1.ca
│ ├── projecteuler_2.ca
│ └── projecteuler_3.ca
├── getting_started_on_command_line.md
└── internal
│ ├── accessors.md
│ ├── change_cascades.md
│ ├── change_events.md
│ ├── code_layout.md
│ ├── interpreter.md
│ ├── object_model.md
│ └── retained_frames.md
├── improv
├── .gitignore
├── Makefile
├── ca
│ ├── audio.ca
│ ├── cairo.ca
│ ├── code_context_menu.ca
│ ├── code_view.ca
│ ├── codeviewb
│ │ ├── layout.ca
│ │ ├── main.ca
│ │ ├── outline
│ │ ├── test.ca
│ │ ├── test_cli.ca
│ │ └── window.ca
│ ├── context_menu.ca
│ ├── diagram.ca
│ ├── draw.ca
│ ├── draw_buffer_2d
│ │ ├── main.ca
│ │ ├── stack_iterator.ca
│ │ └── test_stack_iterator.ca
│ ├── editor.ca
│ ├── editor_env.ca
│ ├── editor_main.ca
│ ├── error_trace.ca
│ ├── error_trace_test.ca
│ ├── feedback.ca
│ ├── fps_tracker.ca
│ ├── gl
│ │ ├── env.ca
│ │ ├── improv_util.ca
│ │ ├── main.ca
│ │ ├── render_list.ca
│ │ └── shader_builder.ca
│ ├── improv.ca
│ ├── improv_main.ca
│ ├── improv_shell.ca
│ ├── indent_writer.ca
│ ├── input.ca
│ ├── kflogo
│ │ └── main.ca
│ ├── layout.ca
│ ├── layout_test.ca
│ ├── linewise_layout.ca
│ ├── popup_menu.ca
│ ├── sample_backgrounds.ca
│ ├── source_view.ca
│ ├── time.ca
│ ├── ui2
│ │ ├── main.ca
│ │ ├── textview.ca
│ │ ├── textview_test.ca
│ │ └── viewport.ca
│ ├── ui_icons.ca
│ ├── ui_script_control.ca
│ ├── vertical_layout.ca
│ └── window.ca
├── demos
│ ├── BoxUITest.ca
│ ├── CairoTest.ca
│ ├── CodeBrowser.ca
│ ├── StackBrowser.ca
│ ├── asteroids.ca
│ ├── avatar.ca
│ ├── code_view_test.ca
│ ├── garden.ca
│ ├── gltest.ca
│ ├── intro.ca
│ ├── just_black.ca
│ ├── just_green.ca
│ ├── mouse_test.ca
│ ├── natureofcode
│ │ ├── chp1_vectors
│ │ │ ├── NOC_1_1_bouncingball_novectors.ca
│ │ │ ├── NOC_1_2_bouncingball_vectors.ca
│ │ │ ├── NOC_1_2_bouncingball_vectors_object.ca
│ │ │ ├── NOC_1_3_vector_subtraction.ca
│ │ │ ├── NOC_1_4_vector_multiplication.ca
│ │ │ ├── NOC_1_5_vector_magnitude.ca
│ │ │ ├── NOC_1_6_vector_normalize.ca
│ │ │ ├── NOC_1_7_motion101.ca
│ │ │ ├── NOC_1_8_motion101_acceleration.ca
│ │ │ └── NOC_1_9_motion101_acceleration.ca
│ │ └── introduction
│ │ │ ├── Exercise_I_1_WalkerTendsToDownRight.ca
│ │ │ ├── Figure_I_2_BellCurve.ca
│ │ │ ├── Figure_I_5_Noise1DGraph.ca
│ │ │ ├── Figure_I_6_RandomGraph.ca
│ │ │ ├── Gaussian2.ca
│ │ │ ├── NOC_I_1_RandomWalkTraditional.ca
│ │ │ ├── NOC_I_2_RandomDistribution.ca
│ │ │ ├── NOC_I_3_RandomWalkTendsToRight.ca
│ │ │ ├── NOC_I_4_Gaussian.ca
│ │ │ └── NOC_I_5_NoiseWalk.ca
│ ├── platformer.ca
│ ├── ransom.ca
│ ├── really_simple.ca
│ ├── skeletal.ca
│ ├── space_invaders.ca
│ ├── tetris.ca
│ ├── threeworlds
│ │ ├── fish.ca
│ │ ├── fish_layer.ca
│ │ ├── main.ca
│ │ └── notes
│ └── websock_test.ca
├── improv.xcodeproj
│ ├── project.pbxproj
│ └── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ └── improv.xccheckout
├── make
├── premake4.lua
└── src
│ ├── FontFace.cpp
│ ├── FontFace.h
│ ├── Makefile
│ ├── cairo_surface.cpp
│ ├── cairo_surface.h
│ ├── gl.cpp
│ ├── gl.h
│ ├── improv_common.h
│ ├── key_codes.cpp
│ ├── key_codes.h
│ ├── sdl_window.cpp
│ └── sdl_window.h
├── include
└── circa
│ ├── circa.h
│ └── file.h
├── libs
└── zmq
│ ├── .gitignore
│ ├── Makefile
│ ├── admin_listener_zmq.ca
│ ├── build.ca
│ ├── file_server.ca
│ ├── pub_test.ca
│ ├── requester_test.ca
│ ├── responder_test.ca
│ ├── sub_test.ca
│ ├── test.ca
│ ├── zmq-sample.cpp
│ ├── zmq.ca
│ └── zmq.cpp
├── modules
└── improv.ca
├── platform
├── emscripten
│ ├── .gitignore
│ └── make
├── nacl
│ ├── .gitignore
│ ├── Makefile
│ ├── assets
│ │ ├── icon_128.jpg
│ │ └── icon_16.jpg
│ ├── circa_cl.nmf
│ ├── configure
│ ├── index.html
│ ├── index.js
│ ├── main.make
│ ├── make
│ ├── manifest.json
│ ├── nacl_cl_main.cpp
│ ├── premake4.lua
│ └── translate_pexe
└── vim
│ ├── indent
│ └── circa.vim
│ ├── install
│ └── syntax
│ └── circa.vim
├── premake4.lua
├── src
├── blob.cpp
├── blob.h
├── block.cpp
├── block.h
├── building.cpp
├── building.h
├── builtin_types.cpp
├── builtin_types.h
├── bytecode.cpp
├── bytecode.h
├── c_api.cpp
├── ca
│ ├── Feedback.ca
│ ├── FeedbackTest.ca
│ ├── GenBindingsCpp.ca
│ ├── abstract_vm.ca
│ ├── annotations.ca
│ ├── bytecode_analysis.ca
│ ├── bytecode_generated.ca
│ ├── code_change.ca
│ ├── command_line.ca
│ ├── cpp_codegen.ca
│ ├── indent_writer.ca
│ ├── json.ca
│ ├── match
│ │ └── main.ca
│ ├── matrix.ca
│ ├── socket.ca
│ ├── source_repro.ca
│ ├── stack_dump.ca
│ ├── stack_trace
│ │ └── main.ca
│ ├── static_checking.ca
│ └── stdlib.ca
├── change_events.cpp
├── change_events.h
├── closures.cpp
├── closures.h
├── code_iterators.cpp
├── code_iterators.h
├── command_line.make
├── command_line
│ ├── command_line.cpp
│ ├── command_line.h
│ └── command_line_main.cpp
├── common_headers.h
├── control_flow.cpp
├── control_flow.h
├── debug.cpp
├── debug.h
├── ext
│ ├── libuv.cpp
│ ├── libuv.h
│ ├── perlin.cpp
│ ├── perlin.h
│ ├── read_tar.cpp
│ └── read_tar.h
├── file.cpp
├── file.h
├── file_source.cpp
├── file_source.h
├── file_watch.cpp
├── file_watch.h
├── function.cpp
├── function.h
├── generated
│ ├── all_builtin_types.cpp
│ ├── all_source_files.cpp
│ └── stdlib_script_text.cpp
├── hashtable.cpp
├── hashtable.h
├── inspection.cpp
├── inspection.h
├── json.cpp
├── json.h
├── kernel.cpp
├── kernel.h
├── library.make
├── list.cpp
├── list.h
├── loops.cpp
├── loops.h
├── migration.cpp
├── migration.h
├── misc_builtins.cpp
├── misc_builtins.h
├── modules.cpp
├── modules.h
├── names.cpp
├── names.h
├── names.txt
├── names_builtin.cpp
├── names_builtin.h
├── native_patch.cpp
├── native_patch.h
├── native_ptr.cpp
├── native_ptr.h
├── object_header.h
├── parser.cpp
├── parser.h
├── rand.cpp
├── rand.h
├── reflection.cpp
├── reflection.h
├── replication.cpp
├── replication.h
├── selector.cpp
├── selector.h
├── string_repr.cpp
├── string_repr.h
├── string_type.cpp
├── string_type.h
├── switch.cpp
├── switch.h
├── symbols.cpp
├── symbols.h
├── tagged_value.cpp
├── tagged_value.h
├── term.cpp
├── term.h
├── term_list.cpp
├── term_list.h
├── term_map.h
├── term_namespace.cpp
├── term_namespace.h
├── term_source_location.h
├── token.cpp
├── token.h
├── type.cpp
├── type.h
├── type_inference.cpp
├── type_inference.h
├── unit_tests
│ ├── block_test.cpp
│ ├── building_test.cpp
│ ├── bytecode_test.cpp
│ ├── cascading_test.cpp
│ ├── code_iterator_test.cpp
│ ├── compound_type_test.cpp
│ ├── control_flow_test.cpp
│ ├── fakefs_test.cpp
│ ├── file_test.cpp
│ ├── file_watch_test.cpp
│ ├── function_test.cpp
│ ├── hashtable_test.cpp
│ ├── if_block.cpp
│ ├── list_test.cpp
│ ├── loop_test.cpp
│ ├── main.cpp
│ ├── migration_test.cpp
│ ├── modules_test.cpp
│ ├── names_test.cpp
│ ├── native_patch_test.cpp
│ ├── parser_test.cpp
│ ├── path_expression_test.cpp
│ ├── stack_test.cpp
│ ├── string_test.cpp
│ ├── symbol_test.cpp
│ ├── tagged_value_test.cpp
│ ├── tokenizer_test.cpp
│ ├── type_test.cpp
│ └── unit_test_common.h
├── value_array.h
├── value_iterator.h
├── vm.cpp
├── vm.h
├── world.cpp
└── world.h
├── tests
├── _disabled_tests
├── annotations.ca.output
├── assert_failure.ca.output
├── blob
│ ├── floats.ca
│ ├── floats.ca.output
│ ├── simple.ca
│ ├── simple.ca.output
│ ├── slice.ca
│ ├── slice.ca.output
│ ├── slice_modified.ca
│ ├── slice_modified.ca.output
│ ├── slice_underlying_data_modified.ca
│ ├── slice_underlying_data_modified.ca.output
│ ├── to_string.ca
│ └── to_string.ca.output
├── block
│ └── block_properties.ca
├── bugrepro
│ ├── bug_with_double_pack_state.ca
│ ├── bug_with_double_pack_state.ca.output
│ ├── bug_with_for_loop_output.ca
│ ├── bug_with_for_loop_output.ca.output
│ ├── bug_with_loop_state_outer_rebind.ca
│ ├── bug_with_loop_state_outer_rebind.ca.output
│ ├── bug_with_state_reading_uninitialized_slot.ca
│ ├── bug_with_state_reading_uninitialized_slot.ca.output
│ ├── bug_with_stateful_outer_in_for_loop.ca
│ ├── bug_with_stateful_outer_in_for_loop.ca.output
│ ├── create_nil.ca
│ ├── create_nil.ca.output
│ ├── deep_pack_state.ca
│ ├── field_assignment_in_loop.ca
│ ├── field_assignment_in_loop.ca.output
│ ├── function_statements_reflection.ca
│ ├── if_block_extra_pack_states.ca
│ ├── if_block_extra_pack_states.ca.output
│ ├── if_block_messing_up_pack_state.ca
│ ├── if_block_messing_up_pack_state.ca.output
│ ├── if_block_rebinding.ca
│ ├── lost_identifier_rebinding.ca
│ ├── method_recur.ca
│ ├── method_recur_2.ca
│ ├── parser_crash_unnecessary_self.ca
│ ├── state_name_collision.ca
│ ├── subroutine_exit_point.ca
│ ├── subroutine_exit_point.ca.output
│ ├── type_decl_messing_up_state.ca
│ ├── type_decl_messing_up_state.ca.output
│ └── unknown_function_masked_by_value.ca
├── building
│ └── bug_with_implicit_extra_output.ca
├── builtin_funcs.ca
├── bytecode_inspection
│ ├── helper.ca
│ ├── loop_no_copy.ca
│ ├── no_dyn_method_in_loop.ca
│ ├── no_unnecessary_state.ca
│ └── simple_no_copy.ca
├── cache
│ └── simple.ca.output
├── cast.ca
├── closure
│ ├── apply.ca
│ ├── apply_input_errors.ca
│ ├── apply_not_enough_inputs.ca
│ ├── apply_not_enough_inputs.ca.output
│ ├── as_return_value.ca
│ ├── call.ca
│ ├── call_free_func.ca
│ ├── def_syntax_makes_closure.ca
│ ├── direct_call_simple.ca
│ ├── direct_call_simple.ca.output
│ ├── dynamic_method_closures.ca
│ ├── dynamic_method_closures.ca.output
│ ├── freeze_bindings.ca.output
│ ├── in_loop.ca
│ ├── in_loop.ca.output
│ ├── is_major_block.ca
│ ├── nested_bindings.ca
│ ├── nested_bindings.ca.output
│ ├── not_enough_inputs.ca
│ ├── rebind_syntax_on_call.ca
│ ├── simple.ca
│ └── simple.ca.output
├── compound_type.ca
├── compound_type.ca.output
├── control_flow
│ ├── state_and_break.ca
│ ├── state_and_break.ca.output
│ ├── state_and_return.ca
│ ├── state_and_return.ca.output
│ ├── state_nullification_1.ca
│ └── state_nullification_1.ca.output
├── curry.ca
├── curry.ca.output
├── declared_state_1.ca
├── declared_state_2.ca
├── declared_state_2.ca.output
├── dyn_method
│ ├── apply.ca
│ ├── call.ca
│ ├── capture.ca
│ ├── capture.ca.output
│ ├── capture_on_module.ca
│ ├── capture_on_module.ca.output
│ ├── lib.ca
│ ├── opt_call_on_module.ca
│ ├── opt_call_on_module.ca.output
│ └── output_type_cast.ca
├── dynamic_overload.ca
├── dynamic_typing.ca
├── effect
│ ├── no_effect_run.ca
│ └── no_effect_run.ca.output
├── embed
│ ├── ActorA.ca
│ ├── ActorB.ca
│ ├── ActorC.ca
│ ├── ActorD.ca
│ ├── ClassA.ca
│ ├── TestA.ca
│ ├── actors.cpp
│ ├── file_to_reload.ca
│ ├── reload_file.c
│ ├── reload_loop.cpp
│ └── sample1.cpp
├── emit
│ ├── cant_consume_without_expect.ca
│ └── simple.ca
├── env
│ ├── inheritance.ca
│ ├── inheritance.ca.output
│ ├── opt.ca
│ ├── opt.ca.output
│ ├── test.ca
│ └── test.ca.output
├── error
│ ├── bad_array_notation.ca
│ ├── dynamic_method_fail.ca.output
│ ├── if_input.ca
│ ├── if_input.ca.output
│ ├── input_cast.ca
│ ├── input_cast.ca.output
│ ├── nonexistant_func_after_bar.ca
│ ├── not_enough_inputs.ca
│ ├── not_enough_inputs.ca.output
│ ├── not_enough_inputs_2.ca
│ ├── not_enough_inputs_2.ca.output
│ ├── too_many_inputs.ca
│ ├── too_many_inputs.ca.output
│ ├── type_as_func.ca
│ ├── undefined_name.ca
│ ├── undefined_name.ca.output
│ ├── unknown_identifier.ca
│ ├── unrecognized_expression.ca
│ └── unrecognized_expression.ca.output
├── exit_points
│ ├── for_continue.ca
│ ├── for_continue.ca.output
│ ├── for_discard.ca
│ ├── for_discard.ca.output
│ ├── for_if_if_if_break.ca
│ ├── for_if_if_if_break.ca.output
│ ├── for_output.ca
│ ├── for_output_2.ca
│ ├── for_plain.ca
│ ├── for_plain_2.ca
│ ├── for_rebind.ca
│ ├── for_return.ca
│ ├── for_return_2.ca
│ ├── if_if_if_return.ca
│ ├── if_return.ca
│ ├── if_return_2.ca
│ └── plain_return.ca
├── field
│ ├── audio.ca
│ ├── audio.ca.output
│ ├── bouncingball.ca
│ ├── bouncingball.ca.output
│ ├── euler
│ │ ├── 1.ca
│ │ ├── 1.ca.output
│ │ ├── 2.ca
│ │ └── 2.ca.output
│ ├── layout_ver1.ca
│ ├── map_of_lists.ca
│ ├── noc_motion101.ca
│ ├── plants_recr.ca
│ ├── plants_recr.ca.output
│ ├── rebind_and_bar_comprehensions.ca
│ ├── rebind_and_bar_comprehensions.ca.output
│ ├── resource_loading.ca
│ ├── resource_loading.ca.output
│ ├── space_shooter.ca
│ ├── space_snippet.ca
│ ├── space_snippet.ca.output
│ ├── table_as_iterator.ca.output
│ └── wrap_around.ca
├── file_reading
│ └── x
├── for
│ ├── as_expression.ca
│ ├── break.ca
│ ├── break.ca.output
│ ├── break_2.ca
│ ├── bug_discard_state.ca
│ ├── bug_discard_state.ca.output
│ ├── bug_looped_input_tries_to_rebind_a_builtin.ca
│ ├── bug_looped_input_tries_to_rebind_a_builtin.ca.output
│ ├── bug_with_output_on_discard_last.ca
│ ├── continue.ca
│ ├── continue.ca.output
│ ├── continue_1.ca
│ ├── continue_1.ca.output
│ ├── continue_2.ca
│ ├── continue_2.ca.output
│ ├── continue_3.ca
│ ├── continue_4.ca
│ ├── continue_4.ca.output
│ ├── continue_rebind.ca
│ ├── continue_rebind_2.ca
│ ├── discard.ca
│ ├── discard.ca.output
│ ├── discard_2.ca
│ ├── discard_3.ca
│ ├── discard_3.ca.output
│ ├── empty_list_output.ca
│ ├── explicit_type.ca
│ ├── for.ca
│ ├── for.ca.output
│ ├── for_if_1.ca
│ ├── for_index.ca.output
│ ├── for_input_stateful.ca
│ ├── for_input_stateful.ca.output
│ ├── for_loop_lots_of_stateful_rebinds.ca
│ ├── for_loop_output_2.ca
│ ├── for_loop_output_2.ca.output
│ ├── for_loop_output_3.ca
│ ├── for_loop_output_3.ca.output
│ ├── for_loop_rebinds_multi_iter.ca
│ ├── for_loop_rebinds_no_iter.ca
│ ├── for_state.ca
│ ├── for_state.ca.output
│ ├── for_state_1.ca
│ ├── for_state_1.ca.output
│ ├── for_state_2.ca
│ ├── for_state_2.ca.output
│ ├── for_state_3.ca
│ ├── for_state_4.ca
│ ├── for_state_4.ca.output
│ ├── infer_with_nil_input.ca
│ ├── list_is_movable_but_shared.ca
│ ├── list_is_movable_but_shared.ca.output
│ ├── list_observed_inside_loop.ca
│ ├── list_observed_inside_loop.ca.output
│ ├── list_output.ca
│ ├── list_rebind.ca
│ ├── list_rebind.ca.output
│ ├── list_rebind_method.ca
│ ├── list_rebind_method.ca.output
│ ├── named_index.ca
│ ├── named_index.ca.output
│ ├── nested.ca
│ ├── nested.ca.output
│ ├── output_and_state.ca
│ ├── output_and_state.ca.output
│ ├── state
│ │ ├── discard_1.ca
│ │ └── discard_1.ca.output
│ ├── state_0.ca
│ ├── state_0.ca.output
│ ├── state_bug_when_1st_iteration_has_no_state.ca
│ └── state_bug_when_1st_iteration_has_no_state.ca.output
├── forward_function_ref.ca
├── funcs
│ ├── assert.ca
│ ├── average.ca
│ ├── average.ca.output
│ ├── boolean.ca
│ ├── comparison.ca
│ ├── comparison.ca.output
│ ├── do_once.ca
│ ├── do_once.ca.output
│ ├── do_once_1.ca
│ ├── do_once_1.ca.output
│ ├── filter.ca
│ ├── fold.ca
│ ├── get_index.ca
│ ├── get_index.ca.output
│ ├── math.ca
│ ├── mod.ca
│ ├── mod.ca.output
│ ├── rand.ca
│ ├── range.ca
│ ├── rpath.ca
│ ├── set.ca
│ ├── set2.ca.output
│ ├── set_index.ca
│ ├── set_index.ca.output
│ ├── sum.ca
│ ├── type_check.ca
│ └── zip.ca
├── generic
│ ├── too_many_inputs_to_overloaded_func.ca
│ └── too_many_inputs_to_overloaded_func.ca.output
├── hacks
│ ├── derivative_test.ca
│ ├── derivative_test.ca.output
│ ├── no_effect.ca
│ ├── no_effect.ca.output
│ ├── no_save_state.ca
│ ├── no_save_state.ca.output
│ ├── set_value.ca
│ ├── set_value.ca.output
│ └── watch.ca
├── if
│ ├── empty_blocks.ca
│ ├── if.ca
│ ├── if.ca.output
│ ├── if_1.ca
│ ├── if_1.ca.output
│ ├── if_2.ca
│ ├── if_2.ca.output
│ ├── if_3.ca
│ ├── if_3.ca.output
│ ├── if_4.ca
│ ├── if_4.ca.output
│ ├── if_5.ca
│ ├── if_5.ca.output
│ ├── if_6.ca
│ ├── if_6.ca.output
│ ├── if_block_1.ca
│ ├── if_block_1.ca.output
│ ├── if_block_2.ca
│ ├── if_block_2.ca.output
│ ├── if_block_output.ca
│ ├── if_block_output.ca.output
│ ├── if_primary_output.ca
│ ├── if_state.ca
│ ├── if_state.ca.output
│ ├── if_state_sample.ca
│ ├── method_rebinding.ca
│ ├── method_rebinding.ca.output
│ ├── rebind_1.ca
│ ├── state_in_condition.ca
│ ├── state_in_condition.ca.output
│ ├── state_in_condition_1.ca
│ ├── state_in_condition_1.ca.output
│ ├── state_in_condition_2.ca
│ ├── state_in_condition_2.ca.output
│ ├── state_in_condition_3.ca
│ ├── state_in_condition_3.ca.output
│ ├── state_reset_1.ca
│ ├── state_reset_1.ca.output
│ ├── state_reset_2.ca
│ ├── state_reset_2.ca.output
│ ├── state_reset_on_cond_fail.ca
│ ├── state_reset_on_cond_fail.ca.output
│ └── with_rebind_operator.ca
├── interpreter
│ ├── error_message_dyn_output_fail.ca
│ ├── error_message_dyn_output_fail.ca.output
│ ├── error_message_output_cast.ca
│ ├── error_message_output_cast.ca.output
│ ├── many_stack_frames.ca
│ ├── many_stack_frames.ca.output
│ ├── misc.ca.disable
│ ├── missing_error_message_doesnt_crash.ca.disable
│ ├── multi_inputs.ca.disable
│ ├── no_output.ca.disable
│ ├── simple.ca.disable
│ ├── state.ca.disable
│ └── state_preserved_on_error.ca.disable
├── lazy.ca.output
├── libs
│ ├── error_trace_test.ca
│ ├── error_trace_test.ca.output
│ ├── indent_writer_test.ca
│ └── indent_writer_test.ca.output
├── list
│ ├── List.or.ca
│ ├── contains.ca
│ ├── filter.ca
│ ├── flatten.ca
│ ├── functional.ca
│ ├── get_and_set.ca
│ ├── insert.ca
│ ├── list_values.ca
│ ├── methods.ca
│ ├── misc.ca
│ ├── out_of_range.ca
│ ├── remove.ca
│ ├── split.ca
│ └── to_set.ca
├── match
│ ├── test.ca
│ └── test.ca.output
├── math
│ ├── max_min.ca
│ └── operators_on_point_rect.ca
├── method_lookup_cache
│ ├── many_entries.ca
│ ├── many_entries.ca.output
│ ├── simple.ca
│ └── simple.ca.output
├── methods
│ ├── chaining.ca
│ ├── chaining2.ca
│ ├── default_output_type.ca
│ ├── dynamic_method_and_varargs.ca
│ ├── dynamic_method_and_varargs.ca.output
│ ├── method_calls.ca
│ ├── method_calls.ca.output
│ ├── method_without_parens.ca
│ ├── methods.ca
│ ├── methods.ca.output
│ ├── multi_returns.ca.output
│ ├── precedence_over_simulated_methods.ca
│ ├── precedence_over_simulated_methods.ca.output
│ ├── rebind_input.ca
│ ├── recur.ca
│ ├── varargs.ca
│ └── varargs.ca.output
├── migrate
│ ├── added_state.ca
│ ├── added_state.ca.output
│ ├── added_state_2.ca
│ ├── added_state_2.ca.output
│ ├── added_state_3.ca
│ ├── added_state_3.ca.output
│ ├── block_reference.ca
│ ├── bug_where_stack_values_werent_always_migrated.ca
│ ├── bug_with_type_methods.ca
│ ├── bug_with_type_methods.ca.output
│ ├── closure_reference.ca
│ ├── closure_reference.ca.output
│ ├── hashtable.ca
│ ├── hashtable.ca.output
│ ├── removed_state.ca
│ ├── removed_state.ca.output
│ ├── simple.ca
│ ├── simple.ca.output
│ ├── term_reference.ca
│ ├── term_reference.ca.output
│ ├── type_change_cast.ca
│ ├── type_change_cast.ca.output
│ ├── type_change_incompatible.ca
│ └── type_change_incompatible.ca.output
├── module
│ ├── in_directory
│ │ ├── lib.ca
│ │ └── lib.ca.output
│ ├── lib1.ca
│ ├── lib1.ca.output
│ ├── lib2.ca
│ ├── lib2.ca.output
│ ├── lib3.ca
│ ├── lib_with_static_error.ca
│ ├── lib_with_static_error.ca.output
│ ├── libc.ca
│ ├── load_in_directory.ca
│ ├── load_in_directory.ca.output
│ ├── module_get_with_symbol.ca
│ ├── module_get_with_symbol.ca.output
│ ├── module_method_with_binding.ca.output
│ ├── nested.ca
│ ├── nested.ca.output
│ ├── nonexistant_module.ca
│ ├── require_error_module.ca
│ ├── require_error_module.ca.output
│ ├── require_file.ca
│ ├── require_file.ca.output
│ ├── require_local_dynamic.ca
│ ├── require_local_dynamic.ca.output
│ ├── require_local_dynamic_2.ca
│ ├── require_local_dynamic_2.ca.output
│ ├── require_statement_syntax.ca
│ ├── require_statement_syntax.ca.output
│ ├── simple.ca
│ ├── simple.ca.output
│ ├── static_value.ca
│ ├── static_value.ca.output
│ ├── use_another_modules_module.ca
│ ├── use_another_modules_module.ca.output
│ ├── use_type.ca
│ └── use_type.ca.output
├── move_optimization
│ └── nonlocal_user.ca
├── object
│ ├── update.ca
│ └── update.ca.output
├── old_cast.ca
├── parser
│ ├── anon_func.ca
│ ├── anon_func.ca.output
│ ├── anon_func2.ca
│ ├── anon_func2.ca.output
│ ├── at_symbol_resolved_first.ca
│ ├── at_symbol_resolved_first.ca.output
│ ├── bar_to_method.ca
│ ├── bar_to_method.ca.output
│ ├── function_called_add.ca
│ └── function_called_add.ca.output
├── patch
│ ├── misc.ca
│ └── misc.ca.output
├── rebinding
│ ├── bug_repro_input_1.ca
│ ├── complicated_expressions.ca
│ └── dynamic_method.ca
├── rect
│ └── methods.ca
├── recursion.ca
├── recursion.ca.output
├── recursion_2.ca
├── recursion_2.ca.output
├── recursion_3.ca
├── recursion_3.ca.output
├── reflection
│ ├── anon_func.ca
│ ├── call.ca.output
│ ├── caller.ca
│ ├── is_comment.ca
│ ├── link.ca.output
│ ├── list_statements.ca
│ ├── list_statements.ca.output
│ ├── misc.ca
│ └── trace_dependents.ca
├── right_apply
│ ├── bug_with_rebind_operator_1.ca
│ └── bug_with_rebind_operator_2.ca
├── runtime_typing
│ ├── dynamic_method.ca
│ ├── dynamic_method.ca.output
│ ├── dynamic_method_1.ca
│ └── dynamic_method_2.ca
├── selectors
│ ├── assign_syntax.ca
│ ├── complex_assign.ca
│ ├── element_type_cast.ca
│ ├── element_type_cast.ca.output
│ ├── element_type_cast_error.ca
│ ├── element_type_cast_error.ca.output
│ ├── method_assign_1.ca
│ ├── method_lens.ca
│ ├── runtime_type.ca
│ └── runtime_type.ca.output
├── seq
│ ├── func_seq.ca
│ ├── func_seq.ca.output
│ ├── take_by.ca
│ ├── take_by.ca.output
│ └── test.ca
├── state
│ ├── bug_where_close_was_in_wrong_location.ca
│ ├── cached_func.ca.output
│ ├── declared_state_explicit_call.ca
│ ├── declared_state_explicit_call.ca.output
│ ├── initializer_requires_cast.ca
│ ├── interpreter_output.ca
│ ├── interpreter_output.ca.output
│ ├── lazy.ca
│ ├── lazy.ca.output
│ ├── list_state_synced_across_discard.ca
│ ├── list_state_synced_across_discard.ca.output
│ ├── minor_exiting_block.ca
│ ├── minor_exiting_block.ca.output
│ ├── minor_exiting_block_2.ca
│ ├── minor_exiting_block_2.ca.output
│ ├── minor_exiting_block_3.ca
│ ├── minor_exiting_block_3.ca.output
│ ├── recursion.ca
│ ├── recursion.ca.output
│ ├── recursion_and_for.ca.output
│ ├── recursion_and_for2.ca
│ ├── recursion_and_for2.ca.output
│ ├── recursion_and_for3.ca
│ ├── recursion_and_for3.ca.output
│ ├── recursion_and_if2.ca
│ ├── recursion_and_if2.ca.output
│ ├── recursion_and_if3.ca
│ ├── recursion_and_if3.ca.output
│ ├── simple.ca
│ ├── simple.ca.output
│ ├── state_arg.ca
│ ├── state_arg.ca.output
│ ├── state_unique_naming.ca
│ ├── state_unique_naming.ca.output
│ ├── stateful_call_as_input.ca
│ ├── stateful_call_as_input.ca.output
│ ├── stateful_function.ca
│ ├── stateful_function.ca.output
│ ├── stateful_method.ca
│ ├── stateful_method.ca.output
│ └── super_simple.ca
├── static_errors
│ └── unknown_function.ca.output
├── stats
│ ├── after_each.ca
│ ├── after_each.ca.output
│ ├── dummy_lib.ca
│ ├── field_draw_points.ca
│ ├── field_draw_points.ca.output
│ ├── if_block_observability.ca
│ ├── if_block_observability.ca.output
│ ├── large_copy.ca
│ ├── large_copy.ca.output
│ ├── list_modify.ca
│ ├── list_modify.ca.output
│ ├── looped_value.ca
│ ├── looped_value.ca.output
│ ├── module_no_dynamic_lookup.ca
│ ├── module_no_dynamic_lookup.ca.output
│ └── no_unnecessary_state_calls.ca
├── stdlib
│ ├── json_test.ca
│ ├── json_test.ca.output
│ └── list_by_pairs.ca
├── string
│ ├── bug_with_default_value.ca
│ ├── char_code.ca
│ ├── char_code.ca.output
│ ├── index_of.ca
│ └── substr.ca
├── string_repr.ca
├── subroutine
│ ├── cast_output.ca
│ ├── cast_output.ca.output
│ ├── implicit_return.ca
│ ├── input_rebind_syntax.ca
│ ├── omitted_arg_type.ca
│ ├── omitted_arg_type.ca.output
│ ├── optional_input.ca
│ ├── optional_input.ca.output
│ ├── rebind_input.ca
│ ├── return_1.ca
│ ├── return_2.ca
│ ├── return_2.ca.output
│ ├── return_3.ca
│ ├── return_3.ca.output
│ ├── return_4.ca
│ ├── return_4.ca.output
│ ├── subroutine.ca
│ ├── subroutine.ca.output
│ ├── subroutine_state.ca
│ ├── subroutine_state.ca.output
│ ├── subroutine_state_1.ca
│ ├── subroutine_state_1.ca.output
│ ├── subroutine_state_2.ca
│ └── subroutine_state_2.ca.output
├── switch
│ ├── local_rebind_simple.ca
│ ├── local_rebind_simple.ca.output
│ ├── output_value.ca
│ ├── simple.ca
│ ├── simple.ca.output
│ ├── simple2.ca
│ ├── simple2.ca.output
│ ├── unindented_case.ca.disable
│ ├── with_input.ca
│ ├── with_input.ca.output
│ ├── with_input2.ca
│ └── with_input2.ca.output
├── symbols
│ └── simple.ca
├── syntax
│ ├── bar_apply.ca
│ ├── bar_apply.ca.output
│ ├── bar_apply_method.ca
│ ├── bar_apply_method.ca.output
│ ├── closure.ca.disable
│ ├── compound_type.ca
│ ├── compound_type.ca.output
│ ├── control_flow.ca
│ ├── for.ca
│ ├── for.ca.output
│ ├── for_rebind.ca
│ ├── for_rebind.ca.output
│ ├── for_rebind_complex.ca
│ ├── for_rebind_complex.ca.output
│ ├── function_calls.ca
│ ├── if.ca
│ ├── if_indenting_1.ca
│ ├── if_indenting_2.ca
│ ├── if_indenting_3.ca
│ ├── if_indenting_4.ca
│ ├── infix.ca
│ ├── infix.ca.output
│ ├── infix_multiline.ca
│ ├── left_arrow.ca.output
│ ├── lists.ca
│ ├── lists.ca.output
│ ├── literal_map.ca
│ ├── literal_map.ca.output
│ ├── literal_map_whitespace.ca
│ ├── local_typedef.ca
│ ├── math.ca
│ ├── math.ca.output
│ ├── method_rebinding.ca
│ ├── method_rebinding.ca.output
│ ├── method_rebinding_new.ca
│ ├── multiline_comment.ca
│ ├── multiline_comment.ca.output
│ ├── not.ca
│ ├── not.ca.output
│ ├── return_multi.ca
│ ├── subroutine.ca
│ ├── subroutine.ca.output
│ ├── subroutine_semicolon.ca
│ ├── syntax_simple_values.ca
│ ├── syntax_subroutine.ca
│ ├── trailing_dot_method.ca
│ ├── trailing_dot_method_bad_indent.ca
│ ├── trailing_dot_method_bad_indent.ca.output
│ ├── type_decl.ca
│ ├── type_decl_2.ca
│ └── type_decl_2.ca.output
├── table
│ ├── apply.ca
│ ├── empty.ca
│ ├── equals.ca
│ ├── hashable_keys.ca
│ ├── hashable_keys.ca.output
│ ├── implicit_get_and_call.ca
│ ├── implicit_get_and_call.ca.output
│ ├── list_append.ca
│ ├── list_append.ca.output
│ ├── make_table.ca
│ ├── make_table.ca.output
│ ├── many_inserts.ca
│ ├── many_inserts.ca.output
│ ├── method_syntax.ca
│ ├── modify.ca
│ ├── modify.ca.output
│ ├── remove_nonexistant.ca
│ ├── remove_nonexistant.ca.output
│ ├── shorthand_syntax.ca
│ ├── shorthand_syntax.ca.output
│ ├── simple.ca
│ └── simple.ca.output
├── type
│ ├── interface
│ │ ├── override_and_fallthrough.ca
│ │ ├── override_and_fallthrough.ca.output
│ │ ├── simple.ca
│ │ └── simple.ca.output
│ ├── make.ca
│ ├── make_1.ca
│ ├── make_no_unnecessary_init.ca.disable
│ └── make_no_unnecessary_init.ca.output
├── type_inferrence
│ ├── assign.ca
│ ├── bug_with_list_based_type.ca
│ ├── bug_with_list_based_type.ca.output
│ ├── implicit_type_considers_return1.ca
│ ├── implicit_type_considers_return2.ca
│ ├── implicit_type_considers_return3.ca
│ ├── method.ca
│ └── overloaded_func.ca
├── types
│ ├── color_values.ca
│ ├── color_values.ca.output
│ ├── dict.ca.output
│ ├── rect.ca
│ ├── semicolon_syntax.ca
│ ├── setters.ca
│ ├── setters.ca.output
│ ├── strings.ca
│ ├── super_special_handle_type_syntax.ca.disable
│ └── typeof_func.ca
├── varargs
│ ├── empty.ca
│ ├── empty.ca.output
│ ├── mixed.ca
│ ├── mixed.ca.output
│ ├── regular.ca
│ └── regular.ca.output
├── vectorized_func.ca.output
├── vm
│ ├── append_hack.ca
│ ├── append_hack.ca.output
│ ├── capture_stack.ca.disabled
│ ├── capture_stack.ca.output
│ ├── deep_stack.ca
│ ├── deep_stack.ca.output
│ ├── eval_term_on_demand.ca.output
│ ├── fib.ca
│ ├── fib.ca.output
│ ├── find_active_frame.ca.disabled
│ ├── find_active_value.ca.output
│ ├── make_with_closure.ca
│ ├── make_with_closure.ca.output
│ ├── null_vm.ca
│ └── set_env.ca
└── while
│ ├── continue_and_locals.ca
│ ├── continue_and_locals.ca.output
│ ├── counter.ca
│ ├── counter.ca.output
│ ├── locals1.ca
│ ├── locals1.ca.output
│ ├── locals2.ca
│ ├── locals2.ca.output
│ ├── locals3.ca
│ ├── locals3.ca.output
│ └── zero.ca
└── tools
├── BuiltinFilesToC.py
├── NamesFile.py
├── README
├── __init__.py
├── ca-d
├── ca-deploy
├── ca-grep
├── ca-prebuild.py
├── ca-r
├── ca-sed
├── ca-sed.darwin
├── ca-tag
├── ca-tests.py
├── ca-update-tags
├── ca-valgrind
├── cpre.rb
├── file_cycler.py
├── vagrant
├── .gitignore
└── bootstrap.sh
└── wrangle_deps.py
/3rdparty/linenoise/.gitignore:
--------------------------------------------------------------------------------
1 | history.txt
2 | linenoise_example
3 |
--------------------------------------------------------------------------------
/3rdparty/linenoise/Makefile:
--------------------------------------------------------------------------------
1 | linenoise_example: linenoise.h linenoise.c
2 |
3 | linenoise_example: linenoise.c example.c
4 | $(CC) -Wall -W -Os -g -o linenoise_example linenoise.c example.c
5 |
6 | clean:
7 | rm -f linenoise_example
8 |
--------------------------------------------------------------------------------
/docs/code_samples/hello_world.ca:
--------------------------------------------------------------------------------
1 | print('Hello world!')
2 |
--------------------------------------------------------------------------------
/improv/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | xcuserdata
3 |
--------------------------------------------------------------------------------
/improv/ca/codeviewb/main.ca:
--------------------------------------------------------------------------------
1 |
2 | require ./layout
3 | require ./window
4 |
5 | def get_phrases(Block block)
6 | layout.Layout.make.get_phrases(block)
7 |
--------------------------------------------------------------------------------
/improv/ca/codeviewb/outline:
--------------------------------------------------------------------------------
1 |
2 | Goals:
3 | Display an interactive configurable code view
4 |
5 | Text view:
6 | Lines of code
7 | Mouse interaction
8 | Popup menus for certain interaction
9 |
--------------------------------------------------------------------------------
/improv/ca/codeviewb/test_cli.ca:
--------------------------------------------------------------------------------
1 |
2 | require ./layout
3 | require ./window
4 |
5 | func = ->
6 | def my_rebinding_func(@a)
7 | a += 1
8 |
9 | print('done')
10 |
11 | a = 3
12 | my_rebinding_func(@a)
13 | print(a)
14 |
15 | phrases = layout.Layout.make.get_phrases(func.block)
16 | w = window.new([20 20] [10 8])
17 | @w.add_phrases(phrases)
18 |
19 | for e in w.elements
20 | print(e)
21 |
--------------------------------------------------------------------------------
/improv/ca/context_menu.ca:
--------------------------------------------------------------------------------
1 |
2 | struct ContextMenu {
3 | }
4 | event = input(Symbol)
5 | data = input()
6 |
7 | if event == :term_details
8 | term = data[0]
9 | pos = data[1]
10 |
11 |
12 |
--------------------------------------------------------------------------------
/improv/ca/editor_main.ca:
--------------------------------------------------------------------------------
1 |
2 | require ./editor_env
3 |
4 | state editorEnv = editor_env.new
5 | editorEnv.rect = env(:canvasRect)
6 |
7 | state userScript = load_script(env(:scriptName)).to_stack
8 |
9 | userScript.init_env()
10 | editorEnv.pre(userScript)
11 | userScript.run
12 | editorEnv.post(userScript)
13 |
14 | if userScript.has_error
15 | require stack_trace
16 | stack_trace.dump(userScript)
17 |
18 |
--------------------------------------------------------------------------------
/improv/ca/error_trace_test.ca:
--------------------------------------------------------------------------------
1 |
2 | require error_trace
3 |
4 | def f()
5 | assert(false)
6 |
7 | def g()
8 | f()
9 |
10 | def main()
11 | g()
12 |
13 | int = make_vm(main)
14 | int.run
15 |
16 | error_trace.trace_to_string(int) | print
17 |
--------------------------------------------------------------------------------
/improv/ca/gl/env.ca:
--------------------------------------------------------------------------------
1 |
2 | require gl/render_list
3 |
4 | def pre(VM vm)
5 | vm.init_channel(:render_commands)
6 |
7 | def post(VM vm)
8 | commands = vm.read_channel(:render_commands)
9 | render_list.submit(commands)
10 |
--------------------------------------------------------------------------------
/improv/ca/gl/improv_util.ca:
--------------------------------------------------------------------------------
1 |
2 | require improv
3 | require matrix
4 |
5 | def screenspace_mat3()
6 | window_rect = improv.window_rect
7 | scale = Vec2.make(2 / window_rect.width, 2 / window_rect.height)
8 | matrix.make_mat3.scale([1 -1]).translate([-1 -1]).scale(scale)
9 |
--------------------------------------------------------------------------------
/improv/ca/kflogo/main.ca:
--------------------------------------------------------------------------------
1 |
2 | require draw
3 | require cairo
4 |
5 | blue = #0000ff
6 | green = #00ff00
7 |
8 | center = Vec2.make(200 200)
9 |
10 | draw.background(#fff)
11 |
12 | cairo.draw_to_screen([0 0 200 200], (canvas) ->
13 | canvas.set_color(blue)
14 | canvas.show_text_centered("KidFriendly" center)
15 | )
16 |
--------------------------------------------------------------------------------
/improv/ca/ui2/main.ca:
--------------------------------------------------------------------------------
1 |
2 | require ./textview
3 |
--------------------------------------------------------------------------------
/improv/ca/ui2/textview_test.ca:
--------------------------------------------------------------------------------
1 |
2 | import draw
3 | import ui2
4 | import cairo
5 |
6 | draw.background(#000)
7 |
8 | cairo.draw_to_screen([0 0 100 100], (canvas) ->
9 | lines = ['a' 'b' 'c']
10 |
11 | canvas.set_source_color(#fff)
12 |
13 | view = ui2.textview.TextView.make(lines canvas)
14 | )
15 |
16 |
--------------------------------------------------------------------------------
/improv/ca/ui2/viewport.ca:
--------------------------------------------------------------------------------
1 |
2 | struct Viewport {
3 | Rect rect
4 | Vec2 scroll
5 | }
6 |
--------------------------------------------------------------------------------
/improv/ca/window.ca:
--------------------------------------------------------------------------------
1 |
2 | def size() -> Vec2
3 | env(:canvasRect).size
4 |
5 | def random_location() -> Vec2
6 | s = size()
7 | [s.x * rand(), s.y * rand()]
8 |
--------------------------------------------------------------------------------
/improv/demos/just_green.ca:
--------------------------------------------------------------------------------
1 |
2 | require draw
3 | draw.background(#0f0)
4 |
--------------------------------------------------------------------------------
/improv/demos/natureofcode/chp1_vectors/NOC_1_3_vector_subtraction.ca:
--------------------------------------------------------------------------------
1 |
2 | require draw
3 | require input
4 | require improv
5 |
6 | draw.background(#fff)
7 |
8 | center = improv.window_size.mult(1/2)
9 |
10 | draw.line(#000 center, input.mouse 2.0)
11 |
--------------------------------------------------------------------------------
/improv/demos/natureofcode/chp1_vectors/NOC_1_4_vector_multiplication.ca:
--------------------------------------------------------------------------------
1 |
2 | require draw
3 | require input
4 | require improv
5 |
6 | draw.background(#fff)
7 |
8 | center = improv.window_size.mult(1/2)
9 |
10 | mouse = input.mouse.sub(center)
11 |
12 | -- Multiplying a vector! The vector is now half its original size (multiplied by 0.5).
13 | @mouse.mult(.5)
14 |
15 | draw.line(#000 center, center.add(mouse) 2.0)
16 |
--------------------------------------------------------------------------------
/improv/demos/natureofcode/chp1_vectors/NOC_1_5_vector_magnitude.ca:
--------------------------------------------------------------------------------
1 |
2 | require draw
3 | require input
4 | require improv
5 |
6 | draw.background(#fff)
7 |
8 | center = improv.window_size.mult(1/2)
9 | mouse = input.mouse.sub(center)
10 |
11 | m = mouse.magnitude
12 |
13 | draw.fill_rect(#000 [0 0 m 10])
14 | draw.line(#000 center, center.add(mouse) 2.0)
15 |
--------------------------------------------------------------------------------
/improv/demos/natureofcode/chp1_vectors/NOC_1_6_vector_normalize.ca:
--------------------------------------------------------------------------------
1 |
2 | require draw
3 | require input
4 | require improv
5 |
6 | draw.background(#fff)
7 |
8 | center = improv.window_size.mult(1/2)
9 | mouse = input.mouse.sub(center)
10 |
11 | -- Normalize the vector
12 | @mouse.norm
13 |
14 | -- Multiply its length by 50
15 | @mouse.mult(150)
16 |
17 | draw.line(#000 center, center.add(mouse) 2.0)
18 |
--------------------------------------------------------------------------------
/improv/demos/natureofcode/introduction/Figure_I_5_Noise1DGraph.ca:
--------------------------------------------------------------------------------
1 |
2 | require draw
3 | require time
4 | require improv
5 |
6 | draw.background(#fff)
7 |
8 | width = improv.window_size.x
9 | height = improv.window_size.y
10 |
11 | points = for x in 0..round(width)
12 | y = noise(time.elapsed() + x*0.01) * height
13 | [x y]
14 |
15 | draw.line_list(#000 points 2.0)
16 |
--------------------------------------------------------------------------------
/improv/demos/natureofcode/introduction/Figure_I_6_RandomGraph.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | require draw
4 | require time
5 | require improv
6 |
7 | draw.background(#fff)
8 |
9 | width = improv.window_size.x
10 | height = improv.window_size.y
11 |
12 | points = for x in 0..round(width)
13 | y = rand() * height
14 | [x y]
15 |
16 | draw.line_list(#000 points 2.0)
17 |
--------------------------------------------------------------------------------
/improv/demos/natureofcode/introduction/Gaussian2.ca:
--------------------------------------------------------------------------------
1 |
2 | require draw
3 | require improv
4 |
5 | draw.background(#fff)
6 |
7 | width = improv.window_size.x
8 | height = improv.window_size.y
9 | sd = 60
10 | mean = width/2
11 | xloc = rand_gaussian()*sd + mean
12 |
13 | state List xs = []
14 | @xs.append(xloc)
15 |
16 | for x in xs
17 | draw.fill_ellipse(#0001 [x height/2] [16 16])
18 |
--------------------------------------------------------------------------------
/improv/demos/natureofcode/introduction/NOC_I_4_Gaussian.ca:
--------------------------------------------------------------------------------
1 |
2 | require draw
3 | require improv
4 |
5 | draw.background(#fff)
6 |
7 | width = improv.window_size.x
8 | height = improv.window_size.y
9 |
10 | sd = 60
11 | mean = width/2
12 | xloc = rand_gaussian()*sd + mean
13 |
14 | state List xs = []
15 | @xs.append(xloc)
16 |
17 | for x in xs
18 | draw.fill_ellipse(#0001 [x height/2] [16 16])
19 |
--------------------------------------------------------------------------------
/improv/demos/really_simple.ca:
--------------------------------------------------------------------------------
1 |
2 | a = 1 + 2
3 | b = mult(a, (1 + 2))
4 | c = div(b 2)
5 |
6 | def f(a,b)
7 | -- a function
8 | a + b
9 |
--------------------------------------------------------------------------------
/improv/demos/threeworlds/fish_layer.ca:
--------------------------------------------------------------------------------
1 |
2 | require draw
3 | fish_module = require ./fish
4 |
5 | fish_count = 3
6 |
7 | draw.background(#00f)
8 |
9 | state fishes = init_fishes()
10 |
11 | def init_fishes()
12 | for i in 0..fish_count
13 | fish_module.new
14 |
15 | for fish in @fishes
16 | @fish.update
17 | fish.draw
18 |
--------------------------------------------------------------------------------
/improv/demos/threeworlds/main.ca:
--------------------------------------------------------------------------------
1 |
2 | fish_layer = require ./fish_layer
3 |
4 | fish_layer.block.call
5 |
6 |
--------------------------------------------------------------------------------
/improv/demos/websock_test.ca:
--------------------------------------------------------------------------------
1 |
2 | require websocket
3 |
4 | server = websocket.listen(8080)
5 |
--------------------------------------------------------------------------------
/improv/improv.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/improv/make:
--------------------------------------------------------------------------------
1 | cd ..
2 | make config=release
3 | cd improv
4 | rm build/improv
5 | make config=release
6 |
--------------------------------------------------------------------------------
/improv/src/FontFace.h:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 |
5 | #include "circa/circa.h"
6 |
7 | struct FontFace {
8 | circa::Value rawData;
9 | FT_Face ftFace;
10 | cairo_font_face_t* cairoFace;
11 |
12 | FontFace();
13 | ~FontFace();
14 | };
15 |
16 |
17 | FontFace* as_font_face(caValue* value);
18 |
19 | void font_native_patch(caNativePatch* module);
20 |
--------------------------------------------------------------------------------
/improv/src/cairo_surface.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Andrew Fischer. See LICENSE file for license terms.
2 |
3 | #include
4 |
5 | #pragma once
6 |
7 | void set_cairo_context(caValue* value, cairo_t* context);
8 |
9 | void cairo_native_patch(caNativePatch* module);
10 |
--------------------------------------------------------------------------------
/improv/src/gl.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Andrew Fischer. See LICENSE file for license terms.
2 |
3 | void gl_native_patch(caNativePatch* patch);
4 |
--------------------------------------------------------------------------------
/improv/src/key_codes.h:
--------------------------------------------------------------------------------
1 |
2 | #pragma once
3 |
4 | #include "circa/circa.h"
5 |
6 | #if IMPROV_USE_SDL
7 | #include "SDL_keycode.h"
8 |
9 | SDL_Keycode nacl_keycode_to_sdl_key(uint32_t code);
10 | void sdl_key_to_symbol(SDL_Keycode sym, caValue* value);
11 | #endif
12 |
13 | void nacl_key_to_symbol(uint32_t code, caValue* value);
14 |
15 |
--------------------------------------------------------------------------------
/improv/src/sdl_window.h:
--------------------------------------------------------------------------------
1 |
2 | #pragma once
3 |
4 |
--------------------------------------------------------------------------------
/include/circa/file.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Andrew Fischer. See LICENSE file for license terms.
2 |
3 | #ifndef CIRCA_FILE_H_INCLUDED
4 | #define CIRCA_FILE_H_INCLUDED
5 |
6 | #include "circa.h"
7 |
8 | #ifdef __cplusplus
9 | extern "C" {
10 | #endif
11 |
12 |
13 | #ifdef __cplusplus
14 | } // extern "C"
15 | #endif
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/libs/zmq/.gitignore:
--------------------------------------------------------------------------------
1 | zmq-sample
2 |
--------------------------------------------------------------------------------
/libs/zmq/Makefile:
--------------------------------------------------------------------------------
1 |
2 | all:
3 | g++ -lzmq zmq-sample.cpp -o zmq-sample
4 |
--------------------------------------------------------------------------------
/libs/zmq/admin_listener_zmq.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | import zmq
4 |
5 | state responder = zmq:create_responder(2222)
6 |
7 | msg = responder.read()
8 | if msg != null
9 | reply = sys:do_admin_command(msg)
10 | responder.reply(reply)
11 |
--------------------------------------------------------------------------------
/libs/zmq/build.ca:
--------------------------------------------------------------------------------
1 |
2 | name = 'zmq'
3 | cflags = '-I../../../zeromq-2.1.11/include'
4 | linkflags = '-lzmq'
5 |
--------------------------------------------------------------------------------
/libs/zmq/file_server.ca:
--------------------------------------------------------------------------------
1 |
2 | import zmq
3 |
4 | state responder = zmq:create_responder(2222)
5 | state publisher = zmq:create_publisher(22222)
6 |
7 | req = responder.read()
8 | if req != null
9 | print('received request: ' req)
10 | if req == 'get_manifest'
11 | responder.reply(['pub_addr' []])
12 | else
13 | responder.reply(concat("Unknown command: " req))
14 |
--------------------------------------------------------------------------------
/libs/zmq/pub_test.ca:
--------------------------------------------------------------------------------
1 |
2 | import zmq
3 |
4 | state server = zmq:create_publisher(2222)
5 |
6 | server.send('hi')
7 |
--------------------------------------------------------------------------------
/libs/zmq/requester_test.ca:
--------------------------------------------------------------------------------
1 |
2 | require zmq
3 |
4 | state client = zmq.create_requester('tcp://localhost:2222')
5 |
6 | client.send('hi')
7 |
8 | print(client.receive())
9 |
--------------------------------------------------------------------------------
/libs/zmq/responder_test.ca:
--------------------------------------------------------------------------------
1 |
2 | require zmq
3 |
4 | state server = zmq.create_responder(2222)
5 |
6 | if once()
7 | print("Listening on port 2222")
8 |
9 | msg = server.read()
10 |
11 | if msg != null
12 | print('received: ' msg)
13 | server.reply('reply')
14 |
--------------------------------------------------------------------------------
/libs/zmq/sub_test.ca:
--------------------------------------------------------------------------------
1 |
2 | import zmq
3 |
4 | state listener = zmq:create_subscriber("tcp://127.0.0.1:2222")
5 |
6 | msg = listener.poll()
7 | if msg != null
8 | print('received: ' msg)
9 |
--------------------------------------------------------------------------------
/libs/zmq/test.ca:
--------------------------------------------------------------------------------
1 |
2 | import zmq
3 |
4 | state resp = zmq:create_responder(2222)
5 | i = resp.read()
6 | if i != null
7 | print("Received " i)
8 | resp.reply("There")
9 |
--------------------------------------------------------------------------------
/platform/emscripten/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | *.map
3 | /project.html
4 | /project.js
5 |
--------------------------------------------------------------------------------
/platform/nacl/.gitignore:
--------------------------------------------------------------------------------
1 | *.pexe
2 | *.nexe
3 |
--------------------------------------------------------------------------------
/platform/nacl/assets/icon_128.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andyfischer/circa/39d6473b44bb1f7598703d3f6aed3b4c9942aa27/platform/nacl/assets/icon_128.jpg
--------------------------------------------------------------------------------
/platform/nacl/assets/icon_16.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andyfischer/circa/39d6473b44bb1f7598703d3f6aed3b4c9942aa27/platform/nacl/assets/icon_16.jpg
--------------------------------------------------------------------------------
/platform/nacl/circa_cl.nmf:
--------------------------------------------------------------------------------
1 | {
2 | "files": {},
3 | "program": {
4 | "x86-64": {
5 | "url": "circa_cl_x86_64.nexe"
6 | },
7 | "arm": {
8 | "url": "circa_cl_arm.nexe"
9 | },
10 | "x86-32": {
11 | "url": "circa_cl_x86_32.nexe"
12 | }
13 | }
14 | }
15 |
16 |
--------------------------------------------------------------------------------
/platform/nacl/configure:
--------------------------------------------------------------------------------
1 |
2 | cd $CIRCA_HOME
3 | premake4 --file=platform/nacl/premake4.lua gmake
4 |
--------------------------------------------------------------------------------
/platform/nacl/make:
--------------------------------------------------------------------------------
1 | /usr/bin/env make -R verbose=1 $*
2 |
--------------------------------------------------------------------------------
/platform/nacl/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "manifest_version": 2,
3 | "name": "circa_cl test",
4 | "description": "Circa command-line app",
5 | "version": "0",
6 | "icons": {
7 | "16": "assets/icon_16.jpg",
8 | "128": "assets/icon_128.jpg"
9 | },
10 | "app": {
11 | "launch": {
12 | "local_path": "index.html"
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/platform/nacl/translate_pexe:
--------------------------------------------------------------------------------
1 |
2 | NAME="circa_cl"
3 |
4 | echo "Translating i686.."
5 | pnacl-translate ${NAME}.pexe -arch i686 -o ${NAME}_x86_32.nexe
6 |
7 | echo "Translating x86-64.."
8 | pnacl-translate ${NAME}.pexe -arch x86-64 -o ${NAME}_x86_64.nexe
9 |
10 | echo "Translating armv7.."
11 | pnacl-translate ${NAME}.pexe -arch armv7 -o ${NAME}_arm.nexe
12 |
--------------------------------------------------------------------------------
/platform/vim/install:
--------------------------------------------------------------------------------
1 | ln syntax/circa.vim ~/.vim/syntax/circa.vim
2 | ln indent/circa.vim ~/.vim/indent/circa.vim
3 |
--------------------------------------------------------------------------------
/src/ca/abstract_vm.ca:
--------------------------------------------------------------------------------
1 |
2 | {-
3 | Goals for abstract interpreter:
4 | Constant propogation
5 | Lift expressions out of loops
6 | Type information
7 | Unused expression elimination
8 | Common subexpression elimination
9 | Escape analysis
10 | -}
11 |
12 | struct AVM {
13 | Func func
14 | Table results
15 | }
16 |
17 | def AVM.eval(self, Term term)
18 |
19 | def step(Func func)
20 |
--------------------------------------------------------------------------------
/src/ca/annotations.ca:
--------------------------------------------------------------------------------
1 |
2 | def get(Func func)
3 | for term in func.block.terms.filter((t) -> t.function.name == 'annotation')
4 | args = for input in term.inputs
5 | input.value
6 |
7 | {:id => term.property(:Name), :args => args}
8 |
--------------------------------------------------------------------------------
/src/ca/code_change.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | def codechange_set_value(Term target, any newValue) -> List
4 | [:set_value target newValue]
5 |
--------------------------------------------------------------------------------
/src/ca/command_line.ca:
--------------------------------------------------------------------------------
1 |
2 | require stack_trace
3 |
4 | def run(Func func)
5 | vm = make_vm(func)
6 | vm.call
7 |
8 | if vm.has_error
9 | stack_trace.dump(vm)
10 |
--------------------------------------------------------------------------------
/src/command_line/command_line.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Andrew Fischer. See LICENSE file for license terms.
2 |
3 | #pragma once
4 |
5 | namespace circa {
6 |
7 | int run_command_line(caWorld* world, int argc, const char* args[]);
8 | int run_command_line(caWorld* world, Value* args);
9 |
10 | } // namespace circa
11 |
--------------------------------------------------------------------------------
/src/ext/libuv.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Andrew Fischer. See LICENSE file for license terms.
2 |
3 | #pragma once
4 |
5 | namespace circa {
6 |
7 | LibuvWorld* alloc_libuv_world();
8 | void libuv_process_events(LibuvWorld* world);
9 | void libuv_native_patch(caWorld* world);
10 |
11 | } // namespace circa
12 |
13 |
--------------------------------------------------------------------------------
/src/ext/read_tar.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Andrew Fischer. See LICENSE file for license terms.
2 |
3 | #pragma once
4 |
5 | namespace circa {
6 |
7 | void tar_read_file(Value* tarBlob, const char* filename, Value* fileOut);
8 | bool tar_file_exists(Value* tarBlob, const char* filename);
9 | void tar_debug_dump_listing(Value* tarBlob);
10 |
11 | } // namespace circa
12 |
--------------------------------------------------------------------------------
/src/generated/all_builtin_types.cpp:
--------------------------------------------------------------------------------
1 | #include "../types/any.cpp"
2 | #include "../types/bool.cpp"
3 | #include "../types/color.cpp"
4 | #include "../types/common.cpp"
5 | #include "../types/int.cpp"
6 | #include "../types/null.cpp"
7 | #include "../types/number.cpp"
8 | #include "../types/opaque_pointer_t.cpp"
9 | #include "../types/void.cpp"
10 |
--------------------------------------------------------------------------------
/src/json.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Andrew Fischer. See LICENSE file for license terms.
2 |
3 | #pragma once
4 |
5 | namespace circa {
6 |
7 | void json_parse(const char* str, Value* valueOut);
8 | void json_write(Value* value, Value* stringOut);
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/src/misc_builtins.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Andrew Fischer. See LICENSE file for license terms.
2 |
3 | #pragma once
4 |
5 | namespace circa {
6 |
7 | void misc_builtins_setup_functions(NativePatch* patch);
8 |
9 | } // namespace circa
10 |
--------------------------------------------------------------------------------
/src/native_ptr.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Andrew Fischer. See LICENSE file for license terms.
2 |
3 | namespace circa {
4 |
5 | bool is_native_ptr(Value* val);
6 | void* as_native_ptr(Value* val);
7 | void set_native_ptr(Value* val, void* ptr, caNativePtrRelease release);
8 | void native_ptr_setup_type(Type* type);
9 |
10 | } // namespace circa
11 |
--------------------------------------------------------------------------------
/src/rand.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Andrew Fischer. See LICENSE file for license terms.
2 |
3 | #pragma once
4 |
5 | #include "tinymt/tinymt64.h"
6 |
7 | namespace circa {
8 |
9 | struct RandState {
10 | TINYMT64_T tinymt;
11 | };
12 |
13 | void rand_init(RandState* state, int seed);
14 | uint64_t rand_next_int(RandState* state);
15 | double rand_next_double(RandState* state);
16 |
17 | } // namespace circa
18 |
--------------------------------------------------------------------------------
/src/reflection.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Andrew Fischer. See LICENSE file for license terms.
2 |
3 | #pragma once
4 |
5 | namespace circa {
6 |
7 | void reflection_install_functions(NativePatch* kernel);
8 |
9 | } // namespace circa
10 |
--------------------------------------------------------------------------------
/src/replication.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Andrew Fischer. See LICENSE file for license terms.
2 |
3 | #pragma once
4 |
5 | namespace circa {
6 |
7 | void compute_value_patch(Value* base, Value* latest, Value* patchResult, Value* error);
8 | void apply_patch(Value* val, Value* patch);
9 |
10 | } // namespace circa
11 |
--------------------------------------------------------------------------------
/src/string_repr.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) Andrew Fischer. See LICENSE file for license terms.
2 |
3 | #pragma once
4 |
5 | namespace circa {
6 |
7 | void parse_string_repr(const char* str, int len, Value* out);
8 | void parse_string_repr(Value* str, Value* out);
9 | void write_string_repr(Value* value, Value* stringOut);
10 |
11 | } // namespace circa
12 |
--------------------------------------------------------------------------------
/src/unit_tests/bytecode_test.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) Andrew Fischer. See LICENSE file for license terms.
2 |
3 | #include "unit_test_common.h"
4 |
5 | #include "block.h"
6 | #include "bytecode2.h"
7 | #include "type.h"
8 |
9 | namespace bytecode_test {
10 |
11 | void register_tests()
12 | {
13 | }
14 |
15 | } // namespace bytecode_test
16 |
--------------------------------------------------------------------------------
/tests/_disabled_tests:
--------------------------------------------------------------------------------
1 | embed/*
2 | syntax/local_typedef.ca
3 | parser/at_symbol_resolved_first.ca
4 | hacks/derivative_test.ca
5 | hacks/watch.ca
6 | module/require_error_module.ca
7 | state/list_state_synced_across_discard.ca
8 | stats/field_draw_points.ca
9 | stats/module_no_dynamic_lookup.ca
10 | stats/no_unnecessary_state_calls.ca
11 |
--------------------------------------------------------------------------------
/tests/annotations.ca.output:
--------------------------------------------------------------------------------
1 | [{:args => [], :id => ':anno1'}, {:args => ['hello', 2], :id => ':anno2'}]
2 |
--------------------------------------------------------------------------------
/tests/assert_failure.ca.output:
--------------------------------------------------------------------------------
1 | Error occurred:
2 | [tests/assert_failure.ca:1,0] assert()
3 | [native] | Assert failed
4 |
--------------------------------------------------------------------------------
/tests/blob/floats.ca.output:
--------------------------------------------------------------------------------
1 | 6de7fb3d85eb9140
2 | should be 0.123 = 0.123
3 | should be 4.56 = 4.56
4 | should be 78.9 = 78.900002
5 | should be 10.1 = 10.1
6 | 000000a0ed7cbf3f000000a0703d1240
7 | should be 0.123 = 0.123
8 | should be 4.56 = 4.56
9 | should be 78.9 = 78.900002
10 | should be 10.1 = 10.1
11 |
--------------------------------------------------------------------------------
/tests/blob/simple.ca:
--------------------------------------------------------------------------------
1 |
2 | b = make_blob(10)
3 |
4 | print('b.size = ' b.size)
5 |
6 | for i in 0..10
7 | @b.set_u8(i, i * 3)
8 |
9 | for i in 0..10
10 | print('byte ' i ' = ' b.u8(i))
11 |
--------------------------------------------------------------------------------
/tests/blob/simple.ca.output:
--------------------------------------------------------------------------------
1 | b.size = 10
2 | byte 0 = 0
3 | byte 1 = 3
4 | byte 2 = 6
5 | byte 3 = 9
6 | byte 4 = 12
7 | byte 5 = 15
8 | byte 6 = 18
9 | byte 7 = 21
10 | byte 8 = 24
11 | byte 9 = 27
12 |
--------------------------------------------------------------------------------
/tests/blob/slice.ca:
--------------------------------------------------------------------------------
1 |
2 | b = make_blob(10)
3 |
4 | for i in 0..10
5 | @b.set_u8(i, i)
6 |
7 | slice = b.slice(4, 4)
8 |
9 | print('slice.size = ' slice.size)
10 |
11 | for i in 0..4
12 | print('slice byte ' i ' = ' slice.u8(i))
13 |
--------------------------------------------------------------------------------
/tests/blob/slice.ca.output:
--------------------------------------------------------------------------------
1 | slice.size = 4
2 | slice byte 0 = 4
3 | slice byte 1 = 5
4 | slice byte 2 = 6
5 | slice byte 3 = 7
6 |
--------------------------------------------------------------------------------
/tests/blob/to_string.ca:
--------------------------------------------------------------------------------
1 |
2 | str = "Hello world!"
3 |
4 | blob = Blob.make.from_string(str)
5 |
6 | print('hex = ' blob.to_hex_string)
7 | print('str = ' blob.to_string)
8 |
--------------------------------------------------------------------------------
/tests/blob/to_string.ca.output:
--------------------------------------------------------------------------------
1 | hex = 48656c6c6f20776f726c6421
2 | str = Hello world!
3 |
--------------------------------------------------------------------------------
/tests/block/block_properties.ca:
--------------------------------------------------------------------------------
1 |
2 | def f() {}
3 |
4 | assert(comment.block.property(:EvaluationEmpty) == true)
5 |
6 | assert(f.block.property(:EvaluationEmpty) == nil)
7 |
--------------------------------------------------------------------------------
/tests/bugrepro/bug_with_double_pack_state.ca.output:
--------------------------------------------------------------------------------
1 | {'a' => 'second value'}
2 |
--------------------------------------------------------------------------------
/tests/bugrepro/bug_with_for_loop_output.ca:
--------------------------------------------------------------------------------
1 |
2 | L = [1 2 3]
3 | -- This had a bug where each element in the list was being assigned '5' because
4 | -- 'some_other_thing' occurred last.
5 | for i in @L
6 | i = 4 - i
7 | some_other_thing = 5
8 |
9 | print('should be [3 2 1]: ' L)
10 |
--------------------------------------------------------------------------------
/tests/bugrepro/bug_with_for_loop_output.ca.output:
--------------------------------------------------------------------------------
1 | should be [3 2 1]: [3, 2, 1]
2 |
--------------------------------------------------------------------------------
/tests/bugrepro/bug_with_loop_state_outer_rebind.ca:
--------------------------------------------------------------------------------
1 |
2 | -- There was a bug in for() loop; if it used a implicit input that was a state var,
3 | -- then this would mess up the loop's own state.
4 |
5 | def main()
6 | state a = 1
7 |
8 | for i in [1]
9 | state s = a
10 | s += 1
11 |
12 | int = make_vm(main)
13 | int.run
14 | print(int.get_state)
15 | int.run
16 | print(int.get_state)
17 |
--------------------------------------------------------------------------------
/tests/bugrepro/bug_with_loop_state_outer_rebind.ca.output:
--------------------------------------------------------------------------------
1 | {'_for' => {0 => {'s' => 2}}, 'a' => 1}
2 | {'_for' => {0 => {'s' => 3}}, 'a' => 1}
3 |
--------------------------------------------------------------------------------
/tests/bugrepro/bug_with_state_reading_uninitialized_slot.ca.output:
--------------------------------------------------------------------------------
1 | {'t' => 1, 'u' => 2}
2 |
--------------------------------------------------------------------------------
/tests/bugrepro/bug_with_stateful_outer_in_for_loop.ca.output:
--------------------------------------------------------------------------------
1 | {'_for' => {0 => {'_othercall' => {'s' => 123}}, 1 => {'_othercall' => {'s' => 123}}, 2 => {'_othercall' => {'s' => 123}}}, 'outer' => 4}
2 |
--------------------------------------------------------------------------------
/tests/bugrepro/create_nil.ca:
--------------------------------------------------------------------------------
1 |
2 | make(nil)
3 |
--------------------------------------------------------------------------------
/tests/bugrepro/create_nil.ca.output:
--------------------------------------------------------------------------------
1 | [tests/bugrepro/create_nil.ca:2]
2 | [inside make()]
3 | Error: Couldn't cast nil to type Type
4 |
--------------------------------------------------------------------------------
/tests/bugrepro/field_assignment_in_loop.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 | int i
4 | }
5 |
6 | tlist = [make(T) make(T) make(T)]
7 |
8 | for t in @tlist
9 | t.i = 2
10 | print('t = ' t)
11 |
12 | print('tlist = ' tlist)
13 |
--------------------------------------------------------------------------------
/tests/bugrepro/field_assignment_in_loop.ca.output:
--------------------------------------------------------------------------------
1 | t = T{i: 2}
2 | t = T{i: 2}
3 | t = T{i: 2}
4 | tlist = [T{i: 2}, T{i: 2}, T{i: 2}]
5 |
--------------------------------------------------------------------------------
/tests/bugrepro/function_statements_reflection.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | -- This had a bug, where the 'functions' call was confused by a temporary
4 | -- value holding a function.
5 |
6 | def hi()
7 | def hi2()
8 | x = hi2
9 |
10 | term_ref(hi).contents.statements
11 |
--------------------------------------------------------------------------------
/tests/bugrepro/if_block_extra_pack_states.ca.output:
--------------------------------------------------------------------------------
1 | {'_if' => {0 => {'s' => 1}}}
2 |
--------------------------------------------------------------------------------
/tests/bugrepro/if_block_messing_up_pack_state.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | def main()
4 | state a = 1
5 |
6 | if true
7 | a = 2
8 |
9 | state b = 3
10 |
11 | int = make_vm(main)
12 | int.run
13 | print(int.get_state)
14 |
--------------------------------------------------------------------------------
/tests/bugrepro/if_block_messing_up_pack_state.ca.output:
--------------------------------------------------------------------------------
1 | {'a' => 2, 'b' => 3}
2 |
--------------------------------------------------------------------------------
/tests/bugrepro/if_block_rebinding.ca:
--------------------------------------------------------------------------------
1 |
2 | -- This had a bug where the if-block had two output placeholders for 'button'
3 |
4 | def f()
5 | if true
6 | buttons = []
7 | for button in @buttons {}
8 | else
9 | buttons = []
10 | for button in @buttons {}
11 |
12 | f()
13 |
--------------------------------------------------------------------------------
/tests/bugrepro/method_recur_2.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 | }
4 |
5 | def T.f(@self, Rect rect)
6 | if false
7 | self.f([0 0 100 100])
8 |
9 | element = make(T)
10 | element.f([0 0 100 100])
11 |
--------------------------------------------------------------------------------
/tests/bugrepro/state_name_collision.ca:
--------------------------------------------------------------------------------
1 |
2 | something = 1
3 | state something = something + 1
4 |
5 | assert(something == 2)
6 |
--------------------------------------------------------------------------------
/tests/bugrepro/subroutine_exit_point.ca:
--------------------------------------------------------------------------------
1 |
2 | -- This bug was a two-parter. The for loop was leaking a #control value, and
3 | -- the subroutine definition was creating an unnecessary exit_point. The end
4 | -- result is that the block would exit after the subroutine def.
5 |
6 | print('check 1')
7 |
8 | for i in [1]
9 | discard
10 |
11 | def f()
12 | return
13 |
14 | print('check 2')
15 |
--------------------------------------------------------------------------------
/tests/bugrepro/subroutine_exit_point.ca.output:
--------------------------------------------------------------------------------
1 | check 1
2 | check 2
3 |
--------------------------------------------------------------------------------
/tests/bugrepro/type_decl_messing_up_state.ca.output:
--------------------------------------------------------------------------------
1 | {'a' => 1, 'b' => 2}
2 |
--------------------------------------------------------------------------------
/tests/bugrepro/unknown_function_masked_by_value.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | a = 2
4 |
5 | cl = ->
6 | return a()
7 |
8 | print(cl.call)
9 |
10 | stack = make_vm(main)
11 | stack.run
12 | assert(stack.errored)
13 |
--------------------------------------------------------------------------------
/tests/building/bug_with_implicit_extra_output.ca:
--------------------------------------------------------------------------------
1 |
2 | def f()
3 | a = 'other val'
4 | if true
5 | a = 'other val 2'
6 | 'correct output'
7 | else
8 | a = 'other val 3'
9 | 'wrong output'
10 |
11 | assert(f() == 'correct output')
12 |
--------------------------------------------------------------------------------
/tests/bytecode_inspection/loop_no_copy.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | a = [1 2 3]
4 | for i in [4 5 6 7]
5 | @a.append(i)
6 | print(a)
7 |
8 | vm = make_vm(main)
9 |
10 | require_local helper
11 | --helper.assert_no_copy(vm, main)
12 |
--------------------------------------------------------------------------------
/tests/bytecode_inspection/no_dyn_method_in_loop.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | for a in range(0 10)
4 | print(a)
5 |
6 | --require_local helper
7 | --helper.assert_no_dyn_method(main)
8 |
--------------------------------------------------------------------------------
/tests/bytecode_inspection/no_unnecessary_state.ca:
--------------------------------------------------------------------------------
1 |
2 | require bytecode_analysis
3 |
4 | vm = make_vm(->)
5 | def ops(f)
6 | bytecode_analysis.func_ops(vm f)
7 |
8 | def func()
9 | add(1 2)
10 |
11 | ops(func) | filter(op -> op.opcode == :push_state_frame) | flatten | equals([]) | assert
12 |
--------------------------------------------------------------------------------
/tests/bytecode_inspection/simple_no_copy.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | a = [1 2 3]
4 | @a.append(4)
5 | @a.append(5)
6 | print(a)
7 |
8 | vm = make_vm(main)
9 |
10 | require_local helper
11 | helper.assert_no_copy(vm, main)
12 |
--------------------------------------------------------------------------------
/tests/cache/simple.ca.output:
--------------------------------------------------------------------------------
1 | called func: 1
2 | a: 1
3 | b: 1
4 | called func: 2
5 | c: 2
6 |
--------------------------------------------------------------------------------
/tests/cast.ca:
--------------------------------------------------------------------------------
1 |
2 | v = cast([1 1], Vec2)
3 |
4 | assert(v == [1 1])
5 | assert(v.x == 1)
6 |
7 | v = cast('hello', number)
8 | assert(v == nil)
9 |
--------------------------------------------------------------------------------
/tests/closure/apply.ca:
--------------------------------------------------------------------------------
1 |
2 | f = (a,b) ->
3 | a + b
4 |
5 | assert(f.apply([1 1]) == 2)
6 | assert(f.apply([1 3]) == 4)
7 |
--------------------------------------------------------------------------------
/tests/closure/apply_input_errors.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | assert(str.apply([]) == "")
5 | assert(str.apply([1 2 3]) == "123")
6 |
7 | def no_args()
8 | str.apply()
9 |
10 | vm = make_vm(no_args)
11 | vm.run
12 | assert(vm.has_error)
13 |
--------------------------------------------------------------------------------
/tests/closure/apply_not_enough_inputs.ca:
--------------------------------------------------------------------------------
1 |
2 | cl = (a,b,c) ->
3 | print([a b c])
4 |
5 | cl.apply([1 2])
6 |
--------------------------------------------------------------------------------
/tests/closure/apply_not_enough_inputs.ca.output:
--------------------------------------------------------------------------------
1 | [tests/closure/apply_not_enough_inputs.ca:5]
2 | Error: Not enough inputs for function 'cl': expected 3 and found 2
3 |
--------------------------------------------------------------------------------
/tests/closure/call.ca:
--------------------------------------------------------------------------------
1 |
2 | f = (a,b) ->
3 | a + b
4 |
5 | assert(f.call(1 1) == 2)
6 | assert(f.call(1 3) == 4)
7 |
--------------------------------------------------------------------------------
/tests/closure/call_free_func.ca:
--------------------------------------------------------------------------------
1 |
2 | x = call(-> 1 + 1)
3 | assert(x == 2)
4 |
--------------------------------------------------------------------------------
/tests/closure/def_syntax_makes_closure.ca:
--------------------------------------------------------------------------------
1 |
2 | def top(int t)
3 | def func(int i)
4 | t + i
5 |
6 | func
7 |
8 | assert(top(2).call(3) == 5)
9 |
10 |
--------------------------------------------------------------------------------
/tests/closure/direct_call_simple.ca:
--------------------------------------------------------------------------------
1 |
2 | func = -> print('hi')
3 |
4 | func()
5 |
--------------------------------------------------------------------------------
/tests/closure/direct_call_simple.ca.output:
--------------------------------------------------------------------------------
1 | hi
2 |
--------------------------------------------------------------------------------
/tests/closure/dynamic_method_closures.ca:
--------------------------------------------------------------------------------
1 |
2 | cl = (i) ->
3 | print('Called cl: ' i)
4 |
5 | cl.call('call normal')
6 | cl.apply(['apply normal'])
7 |
8 | cld = any.cast(cl)
9 |
10 | cld.call('call dynamic')
11 | cld.apply(['apply dynamic'])
12 |
--------------------------------------------------------------------------------
/tests/closure/dynamic_method_closures.ca.output:
--------------------------------------------------------------------------------
1 | Called cl: call normal
2 | Called cl: apply normal
3 | Called cl: call dynamic
4 | Called cl: apply dynamic
5 |
--------------------------------------------------------------------------------
/tests/closure/freeze_bindings.ca.output:
--------------------------------------------------------------------------------
1 | called case1 with: run1
2 | called case1 closure with: run1
3 | called case1 with: run2
4 | called case1 closure with: run2
5 | called case2 with: run1
6 | called case2 closure with: run1
7 | called case2 with: run2
8 | called case2 closure with: run1
9 |
--------------------------------------------------------------------------------
/tests/closure/in_loop.ca:
--------------------------------------------------------------------------------
1 |
2 | msg = (el) -> print(str('first element: ' el))
3 |
4 | for i in [0 2 4 6 8]
5 | msg.call(i)
6 | msg = (el) -> print(str('element is: ' el ', previous was: ' i))
7 |
--------------------------------------------------------------------------------
/tests/closure/in_loop.ca.output:
--------------------------------------------------------------------------------
1 | first element: 0
2 | element is: 2, previous was: 0
3 | element is: 4, previous was: 2
4 | element is: 6, previous was: 4
5 | element is: 8, previous was: 6
6 |
--------------------------------------------------------------------------------
/tests/closure/is_major_block.ca:
--------------------------------------------------------------------------------
1 |
2 | def func() -> String
3 |
4 | closure = -> return "closure return value"
5 |
6 | -- there was a bug where the closure's return was causing the entire function to exit.
7 | assert(closure.call() == "closure return value")
8 |
9 | return "func return value"
10 |
11 | assert(func() == "func return value")
12 |
--------------------------------------------------------------------------------
/tests/closure/nested_bindings.ca:
--------------------------------------------------------------------------------
1 |
2 | def f(a)
3 | def g(b)
4 | def h(c)
5 | print('called h with: ' a ', ' b ', ' c)
6 | h
7 | g
8 |
9 |
10 | f(1).call(2).call(3)
11 |
--------------------------------------------------------------------------------
/tests/closure/nested_bindings.ca.output:
--------------------------------------------------------------------------------
1 | called h with: 1, 2, 3
2 |
--------------------------------------------------------------------------------
/tests/closure/not_enough_inputs.ca:
--------------------------------------------------------------------------------
1 |
2 | int = make_vm(->
3 |
4 | cl = (a,b,c) ->
5 | [a b c]
6 |
7 | cl.call(1 2)
8 | )
9 |
10 | int.run
11 | assert(int.errored)
12 |
13 |
--------------------------------------------------------------------------------
/tests/closure/rebind_syntax_on_call.ca:
--------------------------------------------------------------------------------
1 |
2 | plus_1 = (x) -> x + 1
3 |
4 |
5 | a = 4
6 | plus_1.call(@a)
7 |
8 | assert(a == 5)
9 |
--------------------------------------------------------------------------------
/tests/closure/simple.ca.output:
--------------------------------------------------------------------------------
1 | check 1
2 | check 2: ok
3 | check 3: ok
4 | check 4: ok, yes
5 | check 5: yes good right
6 | check 6: yes good right ok1 ok2 ok3
7 | check 7: ok
8 | check 8: ok
9 |
--------------------------------------------------------------------------------
/tests/compound_type.ca.output:
--------------------------------------------------------------------------------
1 | [tests/compound_type.ca:20]
2 | [inside assert()]
3 | Error: Assert failed
4 |
--------------------------------------------------------------------------------
/tests/control_flow/state_and_break.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | a = 0
4 | for i in [1 2 3]
5 | a = i
6 | if i == 2
7 | state s = 1
8 | break
9 |
10 | vm = make_vm(main)
11 | vm.run
12 | vm.get_state | print
13 |
--------------------------------------------------------------------------------
/tests/control_flow/state_and_break.ca.output:
--------------------------------------------------------------------------------
1 | {'_for' => {1 => {'_if' => {0 => {'s' => 1}}}}}
2 |
--------------------------------------------------------------------------------
/tests/control_flow/state_and_return.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | for i in [1 2 3]
4 | state is = i
5 |
6 | if i == 2
7 | state s = 1
8 | return
9 |
10 | vm = make_vm(main)
11 | vm.run
12 | vm.get_state | print
13 |
--------------------------------------------------------------------------------
/tests/control_flow/state_and_return.ca.output:
--------------------------------------------------------------------------------
1 | {'_for' => {0 => {'is' => 1}, 1 => {'_if' => {0 => {'s' => 1}}, 'is' => 2}}}
2 |
--------------------------------------------------------------------------------
/tests/control_flow/state_nullification_1.ca.output:
--------------------------------------------------------------------------------
1 | after 1 call without early return: {'bottom' => 101, 'top' => 2}
2 | after 2 calls without early return: {'bottom' => 102, 'top' => 3}
3 | after 1 call with early return: {'top' => 4}
4 | after 2 calls with early return: {'top' => 5}
5 | after another call without early return: {'bottom' => 101, 'top' => 6}
6 |
--------------------------------------------------------------------------------
/tests/curry.ca:
--------------------------------------------------------------------------------
1 |
2 | def f(a,b,c)
3 | print('called f with a: ' a ', b: ' b ', c: ' c)
4 |
5 | f(1 2 3)
6 |
7 | g = curry(f [4])
8 | g.call(5 6)
9 |
10 | h = curry(g [7])
11 | h.call(8)
12 |
13 | j = curry(f [9 10])
14 | j.call(11)
15 |
16 | h = curry(f [12 13 14])
17 | h.call()
18 |
--------------------------------------------------------------------------------
/tests/curry.ca.output:
--------------------------------------------------------------------------------
1 | called f with a: 1, b: 2, c: 3
2 | called f with a: 4, b: 5, c: 6
3 | called f with a: 4, b: 7, c: 8
4 | called f with a: 9, b: 10, c: 11
5 | called f with a: 12, b: 13, c: 14
6 |
--------------------------------------------------------------------------------
/tests/declared_state_1.ca:
--------------------------------------------------------------------------------
1 | state s = 1
2 |
--------------------------------------------------------------------------------
/tests/declared_state_2.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | state s = add(1 2) + add(3 4)
4 |
5 | vm = make_vm(main)
6 | vm.call
7 | print(vm.get_state)
8 |
--------------------------------------------------------------------------------
/tests/declared_state_2.ca.output:
--------------------------------------------------------------------------------
1 | {'s' => 10}
2 |
--------------------------------------------------------------------------------
/tests/dyn_method/apply.ca:
--------------------------------------------------------------------------------
1 |
2 | def func(a, b) -> int
3 | return a + b
4 |
5 | f = untyped(func)
6 |
7 | assert(f.apply([1 2]) == 3)
8 |
--------------------------------------------------------------------------------
/tests/dyn_method/call.ca:
--------------------------------------------------------------------------------
1 |
2 | def func(a, b) -> int
3 | return a + b
4 |
5 | f = untyped(func)
6 |
7 | assert(f.call(1 2) == 3)
8 |
--------------------------------------------------------------------------------
/tests/dyn_method/capture.ca.output:
--------------------------------------------------------------------------------
1 | T.func called | self = T{f: 'my field'}, i = :the_input
2 |
--------------------------------------------------------------------------------
/tests/dyn_method/capture_on_module.ca:
--------------------------------------------------------------------------------
1 |
2 | require_local lib
3 |
4 | cap = method_capture(lib :func)
5 | cap.first.call
6 |
7 | cap1 = method_capture(lib :func1)
8 | cap1.first.call('input_value')
9 |
--------------------------------------------------------------------------------
/tests/dyn_method/capture_on_module.ca.output:
--------------------------------------------------------------------------------
1 | called lib.func
2 | called lib.func1 with: input_value
3 |
--------------------------------------------------------------------------------
/tests/dyn_method/lib.ca:
--------------------------------------------------------------------------------
1 |
2 | def func()
3 | print('called lib.func')
4 |
5 | def func1(i)
6 | print('called lib.func1 with: ' i)
7 |
--------------------------------------------------------------------------------
/tests/dyn_method/opt_call_on_module.ca:
--------------------------------------------------------------------------------
1 |
2 | require_local lib
3 |
4 | print('1 | ' method_opt(lib :func [] :default))
5 | print('2 | ' method_opt(lib :func1 ['input'] :default))
6 | print('3 | ' method_opt(lib :nonexistant [] :default))
7 |
--------------------------------------------------------------------------------
/tests/dyn_method/opt_call_on_module.ca.output:
--------------------------------------------------------------------------------
1 | called lib.func
2 | 1 | nil
3 | called lib.func1 with: input
4 | 2 | nil
5 | 3 | :default
6 |
--------------------------------------------------------------------------------
/tests/dyn_method/output_type_cast.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 | }
4 |
5 | t = T.make
6 |
7 | def T.f(self) -> Vec2
8 | [1, 2]
9 |
10 | assert(typeof(t.f) == Vec2)
11 |
12 | any.cast(@t)
13 |
14 | assert(typeof(t.f) == Vec2)
15 |
--------------------------------------------------------------------------------
/tests/dynamic_overload.ca:
--------------------------------------------------------------------------------
1 |
2 | def f(any a, any b) -> any
3 | return add(a,b)
4 |
5 | assert(f(1,2) == 3)
6 |
--------------------------------------------------------------------------------
/tests/dynamic_typing.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | -- Field access
4 | def h() -> any
5 | Vec2.cast([1 2])
6 |
7 | p = h()
8 | assert(p.x == 1.0)
9 | assert(p.y == 2.0)
10 |
--------------------------------------------------------------------------------
/tests/effect/no_effect_run.ca.output:
--------------------------------------------------------------------------------
1 | Regular run:
2 | called has_effect
3 | called no_effect
4 | result = 2
5 | No effect run:
6 | called no_effect
7 | result = 2
8 |
--------------------------------------------------------------------------------
/tests/embed/ActorA.ca:
--------------------------------------------------------------------------------
1 |
2 | msg = input() -> int
3 |
4 | print('Actor A received message: ' msg)
5 |
6 | send('ActorB', msg + 1)
7 |
--------------------------------------------------------------------------------
/tests/embed/ActorB.ca:
--------------------------------------------------------------------------------
1 |
2 | msg = input() -> int
3 |
4 | print('Actor B received message: ' msg)
5 |
6 | send('ActorA', msg + 1)
7 |
--------------------------------------------------------------------------------
/tests/embed/ActorC.ca:
--------------------------------------------------------------------------------
1 |
2 | msg = input() -> int
3 |
4 | print('Actor C received message: ' msg)
5 |
6 | print('Actor C calling actor D')
7 | call_actor('ActorD' msg + 1)
8 |
9 | print('Actor C finished calling actor D')
10 |
--------------------------------------------------------------------------------
/tests/embed/ActorD.ca:
--------------------------------------------------------------------------------
1 |
2 | msg = input() -> int
3 |
4 | print('Actor D received message: ' msg)
5 |
6 | send('ActorC', msg + 1)
7 |
--------------------------------------------------------------------------------
/tests/embed/ClassA.ca:
--------------------------------------------------------------------------------
1 |
2 | type ClassA {
3 | String dummyString
4 | int counter
5 | }
6 |
7 | def create_ClassA() -> ClassA
8 | print("Called ClassA")
9 | a = make(ClassA)
10 | a.dummyString = 'DummyString'
11 | return a
12 |
13 | def ClassA.increment(self :output)
14 | self.counter += 1
15 |
16 | def ClassA.dump(self)
17 | print("ClassA dump: ", self)
18 |
--------------------------------------------------------------------------------
/tests/embed/TestA.ca:
--------------------------------------------------------------------------------
1 |
2 | msg = input()
3 |
4 |
5 |
6 | print('received: ' msg)
7 |
--------------------------------------------------------------------------------
/tests/embed/file_to_reload.ca:
--------------------------------------------------------------------------------
1 | def f() -> int
2 | return 1
3 |
--------------------------------------------------------------------------------
/tests/emit/cant_consume_without_expect.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | def func()
4 | emit(:a 1)
5 |
6 | vm = make_vm(func)
7 | vm.call
8 | vm.consume_messages(:a) == [1 2 3]
9 |
10 | vm = make_vm(main)
11 | vm.call
12 | assert(vm.has_error)
13 | assert(vm.error_message == 'Message channel was not expected: :a')
14 |
--------------------------------------------------------------------------------
/tests/emit/simple.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | emit(:a 1)
4 | emit(:a 2)
5 | emit(:a 3)
6 |
7 |
8 | vm = make_vm(main)
9 | vm.expect_messages(:a)
10 | vm.call
11 | assert(vm.consume_messages(:a) == [1 2 3])
12 |
--------------------------------------------------------------------------------
/tests/env/inheritance.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | def bottom_layer()
4 | print('in bottom_layer, env(:a) = ' env(:a))
5 |
6 | def top_layer()
7 | print('in top_layer, env(:a) = ' env(:a))
8 | vm = make_vm(bottom_layer)
9 | vm.call
10 |
11 | vm = make_vm(top_layer)
12 | vm.set_env(:a 1)
13 | vm.call
14 |
--------------------------------------------------------------------------------
/tests/env/inheritance.ca.output:
--------------------------------------------------------------------------------
1 | in top_layer, env(:a) = 1
2 | in bottom_layer, env(:a) = 1
3 |
--------------------------------------------------------------------------------
/tests/env/opt.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | print('env_opt(:a :default) = ' env_opt(:a :default))
4 |
5 | vm = make_vm(main)
6 | vm.call
7 |
8 | vm.set_env(:a 1)
9 | vm.call
10 |
--------------------------------------------------------------------------------
/tests/env/opt.ca.output:
--------------------------------------------------------------------------------
1 | env_opt(:a :default) = :default
2 | env_opt(:a :default) = 1
3 |
--------------------------------------------------------------------------------
/tests/env/test.ca:
--------------------------------------------------------------------------------
1 |
2 | def f()
3 | print('inside f')
4 | print('env(:a) = ' env(:a))
5 | print('env(:b) = ' env(:b))
6 | print('env(:c) = ' env(:c))
7 | g()
8 |
9 | def g()
10 | print('inside g, env(:a) = ' env(:a))
11 |
12 |
13 | vm = make_vm(f)
14 | vm.set_env(:a 1)
15 | vm.set_env(:b 2)
16 | vm.call
17 |
--------------------------------------------------------------------------------
/tests/env/test.ca.output:
--------------------------------------------------------------------------------
1 | inside f
2 | env(:a) = 1
3 | env(:b) = 2
4 | env(:c) = nil
5 | inside g, env(:a) = 1
6 |
--------------------------------------------------------------------------------
/tests/error/bad_array_notation.ca:
--------------------------------------------------------------------------------
1 |
2 | f = ->
3 | -- This caused an interpreter crash at one point
4 | 1[1] = 1
5 |
6 | int = make_vm(f)
7 | int.run
8 | assert(int.errored)
9 |
--------------------------------------------------------------------------------
/tests/error/dynamic_method_fail.ca.output:
--------------------------------------------------------------------------------
1 | Error occurred:
2 | [tests/error/dynamic_method_fail.ca:2,0] dynamic_method()
3 | [$866] output_placeholder() | Method hello not found on type int
4 |
5 |
--------------------------------------------------------------------------------
/tests/error/if_input.ca:
--------------------------------------------------------------------------------
1 | if 1
2 | print('hi')
3 |
--------------------------------------------------------------------------------
/tests/error/if_input.ca.output:
--------------------------------------------------------------------------------
1 | [tests/error/if_input.ca:1]
2 | Error: Couldn't cast 1 to type bool
3 |
--------------------------------------------------------------------------------
/tests/error/input_cast.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | increment('fish')
4 |
--------------------------------------------------------------------------------
/tests/error/input_cast.ca.output:
--------------------------------------------------------------------------------
1 | [tests/error/input_cast.ca:3]
2 | [:659 inside increment()]
3 | Error: Couldn't cast fish to type int
4 |
--------------------------------------------------------------------------------
/tests/error/nonexistant_func_after_bar.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | 1 | NonexistantFunc
4 |
5 | vm = make_vm(main)
6 | vm.run
7 |
8 | assert(vm.has_error)
9 |
--------------------------------------------------------------------------------
/tests/error/not_enough_inputs.ca:
--------------------------------------------------------------------------------
1 |
2 | def f(int a, int b)
3 | print('a = ' a)
4 | print('b = ' b)
5 |
6 | f(1, 2)
7 | f(1)
8 |
--------------------------------------------------------------------------------
/tests/error/not_enough_inputs.ca.output:
--------------------------------------------------------------------------------
1 | a = 1
2 | b = 2
3 | [tests/error/not_enough_inputs.ca:7]
4 | Error: Not enough inputs for function 'f': expected 2 and found 1
5 |
--------------------------------------------------------------------------------
/tests/error/not_enough_inputs_2.ca:
--------------------------------------------------------------------------------
1 |
2 | def f(int a, b :multiple)
3 | print('a = ' a)
4 | print('b = ' b)
5 |
6 | f(1, 2)
7 | f()
8 |
--------------------------------------------------------------------------------
/tests/error/not_enough_inputs_2.ca.output:
--------------------------------------------------------------------------------
1 | a = 1
2 | b = [2]
3 | [tests/error/not_enough_inputs_2.ca:7]
4 | Error: Not enough inputs for function 'f': expected 1 (or more) and found 0
5 |
--------------------------------------------------------------------------------
/tests/error/too_many_inputs.ca:
--------------------------------------------------------------------------------
1 |
2 | def f(int a, int b)
3 | print('a = ' a)
4 | print('b = ' b)
5 |
6 | f(1, 2)
7 | f(1, 2, 3)
8 |
--------------------------------------------------------------------------------
/tests/error/too_many_inputs.ca.output:
--------------------------------------------------------------------------------
1 | a = 1
2 | b = 2
3 | [tests/error/too_many_inputs.ca:7]
4 | Error: Too many inputs for function 'f': expected 2 and found 3
5 |
--------------------------------------------------------------------------------
/tests/error/type_as_func.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | Vec2([0 0])
4 |
5 | vm = make_vm(main)
6 | vm.run
7 |
8 | assert(vm.has_error)
9 |
--------------------------------------------------------------------------------
/tests/error/undefined_name.ca:
--------------------------------------------------------------------------------
1 |
2 | f = ->
3 | add(a b c)
4 |
5 | vm = make_vm(f)
6 | vm.call
7 | assert(vm.has_error)
8 |
--------------------------------------------------------------------------------
/tests/error/undefined_name.ca.output:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andyfischer/circa/39d6473b44bb1f7598703d3f6aed3b4c9942aa27/tests/error/undefined_name.ca.output
--------------------------------------------------------------------------------
/tests/error/unknown_identifier.ca:
--------------------------------------------------------------------------------
1 |
2 | testBlock = ->
3 | print(a)
4 |
5 | vm = make_vm(testBlock)
6 | vm.call
7 |
8 | assert(vm.has_error)
9 |
--------------------------------------------------------------------------------
/tests/error/unrecognized_expression.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | def 1
4 |
--------------------------------------------------------------------------------
/tests/error/unrecognized_expression.ca.output:
--------------------------------------------------------------------------------
1 | [tests/error/unrecognized_expression.ca:3]
2 | Error: Syntax error: Expected identifier after def, found: 1
3 |
--------------------------------------------------------------------------------
/tests/exit_points/for_continue.ca:
--------------------------------------------------------------------------------
1 |
2 | results = []
3 |
4 | a = 0
5 | L = for i in [1 2 3 4]
6 |
7 | @results.append(str('start(' i ',' a ')'))
8 |
9 | if i == 2 or i == 4
10 | continue
11 |
12 | a += 1
13 |
14 | @results.append(str('end(' i ',' a ')'))
15 |
16 | print(results)
17 |
--------------------------------------------------------------------------------
/tests/exit_points/for_continue.ca.output:
--------------------------------------------------------------------------------
1 | ['start(1,0)', 'end(1,1)', 'start(2,1)', 'start(3,1)', 'end(3,2)', 'start(4,2)']
2 |
--------------------------------------------------------------------------------
/tests/exit_points/for_discard.ca:
--------------------------------------------------------------------------------
1 |
2 | L = [1 2 3 4]
3 |
4 | for i in @L
5 | if i == 2
6 | discard
7 | i
8 |
9 | print(L)
10 |
--------------------------------------------------------------------------------
/tests/exit_points/for_discard.ca.output:
--------------------------------------------------------------------------------
1 | [1, 3, 4]
2 |
--------------------------------------------------------------------------------
/tests/exit_points/for_if_if_if_break.ca:
--------------------------------------------------------------------------------
1 |
2 | a = 1
3 |
4 | for i in [0]
5 | if true
6 | if true
7 | if true
8 | a = 2
9 | break
10 |
11 | print(a)
12 |
--------------------------------------------------------------------------------
/tests/exit_points/for_if_if_if_break.ca.output:
--------------------------------------------------------------------------------
1 | 2
2 |
--------------------------------------------------------------------------------
/tests/exit_points/for_output.ca:
--------------------------------------------------------------------------------
1 |
2 | a = for i in [1 2 3]
3 | i + 1
4 |
5 | assert(a == [2 3 4])
6 |
--------------------------------------------------------------------------------
/tests/exit_points/for_output_2.ca:
--------------------------------------------------------------------------------
1 |
2 | a = for i in []
3 | 1
4 |
5 | assert(a == [])
6 |
--------------------------------------------------------------------------------
/tests/exit_points/for_plain.ca:
--------------------------------------------------------------------------------
1 |
2 | a = 1
3 |
4 | for i in []
5 | a = 2
6 |
7 | assert(a == 1)
8 |
--------------------------------------------------------------------------------
/tests/exit_points/for_plain_2.ca:
--------------------------------------------------------------------------------
1 |
2 | a = 1
3 |
4 | for i in [1]
5 | a = 2
6 |
7 | assert(a == 2)
8 |
--------------------------------------------------------------------------------
/tests/exit_points/for_rebind.ca:
--------------------------------------------------------------------------------
1 |
2 | a = 0
3 | L = for i in [1 2 3]
4 | a += i
5 |
6 | a
7 |
8 | assert(L == [1 3 6])
9 | assert(a == 6)
10 |
--------------------------------------------------------------------------------
/tests/exit_points/for_return.ca:
--------------------------------------------------------------------------------
1 |
2 | def f() -> int
3 | for i in [1]
4 | return 1
5 |
6 | r = f()
7 | assert(r == 1)
8 |
--------------------------------------------------------------------------------
/tests/exit_points/for_return_2.ca:
--------------------------------------------------------------------------------
1 |
2 | def f() -> int
3 | for i in []
4 | return 1
5 |
6 | return 2
7 |
8 | r = f()
9 | assert(r == 2)
10 |
--------------------------------------------------------------------------------
/tests/exit_points/if_if_if_return.ca:
--------------------------------------------------------------------------------
1 |
2 | def f() -> int
3 | if true
4 | if true
5 | if true
6 | return 1
7 | else
8 | return 2
9 | else
10 | return 3
11 | else
12 | return 4
13 |
14 | r = f()
15 | assert(r == 1)
16 |
--------------------------------------------------------------------------------
/tests/exit_points/if_return.ca:
--------------------------------------------------------------------------------
1 |
2 | def f() -> int
3 | if true
4 | return 1
5 | else
6 | return 2
7 |
8 | r = f()
9 | assert(r == 1)
10 |
--------------------------------------------------------------------------------
/tests/exit_points/if_return_2.ca:
--------------------------------------------------------------------------------
1 |
2 | def f() -> int
3 | if false
4 | return 1
5 | else
6 | return 2
7 |
8 | r = f()
9 | assert(r == 2)
10 |
--------------------------------------------------------------------------------
/tests/exit_points/plain_return.ca:
--------------------------------------------------------------------------------
1 |
2 | def f() -> int
3 | return 1
4 |
5 | r = f()
6 | assert(r == 1)
7 |
--------------------------------------------------------------------------------
/tests/field/audio.ca.output:
--------------------------------------------------------------------------------
1 | Creating a 0.005 second 44khz 16bit stereo tone..
2 | Done
3 |
--------------------------------------------------------------------------------
/tests/field/euler/1.ca.output:
--------------------------------------------------------------------------------
1 | 233168
2 |
--------------------------------------------------------------------------------
/tests/field/euler/2.ca.output:
--------------------------------------------------------------------------------
1 | 4613732
2 |
--------------------------------------------------------------------------------
/tests/field/rebind_and_bar_comprehensions.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 | int i
4 | }
5 |
6 | def T.inc(t)
7 | @t.i | add(1)
8 |
9 | def T.odd(t)
10 | t.i % 2 == 1
11 |
12 | list = [1 2 3 4 5]
13 | @list | map(n -> T.make(n))
14 | @list | map(b -> b.inc)
15 | @list | filter(b -> b.odd)
16 |
17 | list | flatten | print
18 |
--------------------------------------------------------------------------------
/tests/field/rebind_and_bar_comprehensions.ca.output:
--------------------------------------------------------------------------------
1 | [T{i: 3}, T{i: 5}]
2 |
--------------------------------------------------------------------------------
/tests/field/resource_loading.ca.output:
--------------------------------------------------------------------------------
1 | loading: locationMoreArrow.png
2 | loading: optionsIcon.png
3 | loading: nowAreaButtonVertSelected.png
4 |
--------------------------------------------------------------------------------
/tests/field/space_snippet.ca.output:
--------------------------------------------------------------------------------
1 | check1
2 | check2
3 |
--------------------------------------------------------------------------------
/tests/file_reading/x:
--------------------------------------------------------------------------------
1 | a b c
2 |
--------------------------------------------------------------------------------
/tests/for/as_expression.ca:
--------------------------------------------------------------------------------
1 |
2 | points = [[1 2] [3 4] [5 6] [7 8]]
3 | points = (for i in 0 .. (points.length-1) { [points[i] points[i+1]] }).flatten
4 | assert(points == [[1 2] [3 4] [3 4] [5 6] [5 6] [7 8]])
5 |
--------------------------------------------------------------------------------
/tests/for/break.ca:
--------------------------------------------------------------------------------
1 |
2 | for i in [0, 1, 2]
3 | print('first loop reached top: ' i)
4 | break
5 | print('don\'t print this')
6 |
7 | for i in [0, 1, 2]
8 | print('second loop reached top: ' i)
9 | if i == 1
10 | break
11 | print('second loop reached bottom: ' i)
12 |
--------------------------------------------------------------------------------
/tests/for/break.ca.output:
--------------------------------------------------------------------------------
1 | first loop reached top: 0
2 | second loop reached top: 0
3 | second loop reached bottom: 0
4 | second loop reached top: 1
5 |
--------------------------------------------------------------------------------
/tests/for/break_2.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | outer = 1
4 |
5 | for i in [2]
6 | outer = 2
7 | break
8 |
9 | assert(outer == 2)
10 |
--------------------------------------------------------------------------------
/tests/for/bug_discard_state.ca.output:
--------------------------------------------------------------------------------
1 | i = 1, state = 1
2 | i = 2, state = 2
3 | i = 3, state = 3
4 | i = 1, state = 1
5 | i = 3, state = 3
6 |
--------------------------------------------------------------------------------
/tests/for/bug_looped_input_tries_to_rebind_a_builtin.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | for index in [0 1 2]
5 | print(index)
6 |
--------------------------------------------------------------------------------
/tests/for/bug_looped_input_tries_to_rebind_a_builtin.ca.output:
--------------------------------------------------------------------------------
1 | 0
2 | 1
3 | 2
4 |
--------------------------------------------------------------------------------
/tests/for/bug_with_output_on_discard_last.ca:
--------------------------------------------------------------------------------
1 |
2 | -- Bug repro, the for loop produced an empty output when the last iteration
3 | -- was interrupted.
4 |
5 | list = [1 2 3 4]
6 |
7 | for i in @list
8 | if i == 4
9 | discard
10 | i
11 |
12 | assert(list == [1 2 3])
13 |
--------------------------------------------------------------------------------
/tests/for/continue.ca:
--------------------------------------------------------------------------------
1 |
2 | for i in [0, 1, 2, 3]
3 | print('first loop reached top: ' i)
4 | continue
5 | print('don\'t print this')
6 |
7 |
--------------------------------------------------------------------------------
/tests/for/continue.ca.output:
--------------------------------------------------------------------------------
1 | first loop reached top: 0
2 | first loop reached top: 1
3 | first loop reached top: 2
4 | first loop reached top: 3
5 |
--------------------------------------------------------------------------------
/tests/for/continue_1.ca:
--------------------------------------------------------------------------------
1 |
2 | for i in [0, 1, 2, 3]
3 | print('first loop reached top: ' i)
4 | if i == 2
5 | continue
6 | print('first loop reached bottom: ' i)
7 |
--------------------------------------------------------------------------------
/tests/for/continue_1.ca.output:
--------------------------------------------------------------------------------
1 | first loop reached top: 0
2 | first loop reached bottom: 0
3 | first loop reached top: 1
4 | first loop reached bottom: 1
5 | first loop reached top: 2
6 | first loop reached top: 3
7 | first loop reached bottom: 3
8 |
--------------------------------------------------------------------------------
/tests/for/continue_2.ca:
--------------------------------------------------------------------------------
1 |
2 | -- Rebinds with 'continue'
3 |
4 | x = 'outer'
5 |
6 | for i in [1 2 3 4 5]
7 | print('start of loop ' i ', x = ' x)
8 | if i % 2 == 1
9 | continue
10 |
11 | x = str('inner_' i)
12 | print('end of loop ' i ', x = ' x)
13 |
--------------------------------------------------------------------------------
/tests/for/continue_2.ca.output:
--------------------------------------------------------------------------------
1 | start of loop 1, x = outer
2 | start of loop 2, x = outer
3 | end of loop 2, x = inner_2
4 | start of loop 3, x = inner_2
5 | start of loop 4, x = inner_2
6 | end of loop 4, x = inner_4
7 | start of loop 5, x = inner_4
8 |
--------------------------------------------------------------------------------
/tests/for/continue_3.ca:
--------------------------------------------------------------------------------
1 |
2 | outer = 1
3 |
4 | for i in [2]
5 | outer = 2
6 | continue
7 |
8 | assert(outer == 2)
9 |
--------------------------------------------------------------------------------
/tests/for/continue_4.ca:
--------------------------------------------------------------------------------
1 |
2 | -- This once had a bug, the get_index was going out of range
3 | for i in [0, 1, 2, 3]
4 | print('step: ' i)
5 | continue
6 |
--------------------------------------------------------------------------------
/tests/for/continue_4.ca.output:
--------------------------------------------------------------------------------
1 | step: 0
2 | step: 1
3 | step: 2
4 | step: 3
5 |
--------------------------------------------------------------------------------
/tests/for/continue_rebind.ca:
--------------------------------------------------------------------------------
1 |
2 | a = 1
3 |
4 | for i in [1]
5 | a = 2
6 | continue
7 |
8 | assert(a == 2)
9 |
--------------------------------------------------------------------------------
/tests/for/continue_rebind_2.ca:
--------------------------------------------------------------------------------
1 |
2 | a = 1
3 |
4 | for i in [1]
5 | a = 2
6 |
7 | if i == 1
8 | continue
9 |
10 | assert(a == 2)
11 |
--------------------------------------------------------------------------------
/tests/for/discard.ca:
--------------------------------------------------------------------------------
1 |
2 | L = [1 2 3 4]
3 |
4 | print('initial L = ' L)
5 |
6 | for i in @L
7 | if i == 3
8 | discard
9 | i
10 |
11 | print('result L = ' L)
12 |
--------------------------------------------------------------------------------
/tests/for/discard.ca.output:
--------------------------------------------------------------------------------
1 | initial L = [1, 2, 3, 4]
2 | result L = [1, 2, 4]
3 |
--------------------------------------------------------------------------------
/tests/for/discard_2.ca:
--------------------------------------------------------------------------------
1 |
2 | outer = 1
3 |
4 | for i in [2]
5 | outer = 2
6 | discard
7 |
8 | assert(outer == 2)
9 |
--------------------------------------------------------------------------------
/tests/for/discard_3.ca:
--------------------------------------------------------------------------------
1 |
2 | def f()
3 | state a = 1
4 | for i in [1]
5 | state i
6 | discard
7 |
8 | state b = 2
9 |
10 | int = make_vm(f)
11 | int.call
12 | print(int.get_state)
13 |
--------------------------------------------------------------------------------
/tests/for/discard_3.ca.output:
--------------------------------------------------------------------------------
1 | {'a' => 1, 'b' => 2}
2 |
--------------------------------------------------------------------------------
/tests/for/empty_list_output.ca:
--------------------------------------------------------------------------------
1 |
2 | a = for i in []
3 | 1
4 |
5 | assert(a == [])
6 |
--------------------------------------------------------------------------------
/tests/for/explicit_type.ca:
--------------------------------------------------------------------------------
1 |
2 | for Vec2 p in [[0 0]]
3 | assert(typeof(p) == Vec2)
4 |
--------------------------------------------------------------------------------
/tests/for/for_if_1.ca:
--------------------------------------------------------------------------------
1 |
2 | l = []
3 |
4 | for i in [1 2 3]
5 | if i == 2
6 | @l.append(i)
7 |
8 | assert(l == [2])
9 |
--------------------------------------------------------------------------------
/tests/for/for_index.ca.output:
--------------------------------------------------------------------------------
1 | Should be 0 through 3:
2 | 0
3 | 1
4 | 2
5 | 3
6 |
--------------------------------------------------------------------------------
/tests/for/for_input_stateful.ca:
--------------------------------------------------------------------------------
1 |
2 | def stateful_call() -> List
3 | state i = 0
4 | i += 1
5 | return [i]
6 |
7 | def main()
8 |
9 | for i in stateful_call()
10 | print(i)
11 |
12 | int = make_vm(main)
13 | int.call
14 | int.call
15 | int.call
16 |
--------------------------------------------------------------------------------
/tests/for/for_input_stateful.ca.output:
--------------------------------------------------------------------------------
1 | 1
2 | 2
3 | 3
4 |
--------------------------------------------------------------------------------
/tests/for/for_loop_output_2.ca:
--------------------------------------------------------------------------------
1 |
2 | L = [1 2 3]
3 | for i in @L
4 | i
5 |
6 | -- L should remain unchanged
7 | print('should be [1 2 3]: ' L)
8 |
--------------------------------------------------------------------------------
/tests/for/for_loop_output_2.ca.output:
--------------------------------------------------------------------------------
1 | should be [1 2 3]: [1, 2, 3]
2 |
--------------------------------------------------------------------------------
/tests/for/for_loop_output_3.ca:
--------------------------------------------------------------------------------
1 |
2 | L = [1 2 3]
3 | for i in @L
4 | if i == 2
5 | i = 5
6 |
7 | print('should be [1 5 3]: ' L)
8 |
--------------------------------------------------------------------------------
/tests/for/for_loop_output_3.ca.output:
--------------------------------------------------------------------------------
1 | should be [1 5 3]: [1, 5, 3]
2 |
--------------------------------------------------------------------------------
/tests/for/for_loop_rebinds_multi_iter.ca:
--------------------------------------------------------------------------------
1 |
2 | -- Test that the for-loop correctly rebinds outer bindings.
3 |
4 | a = 1
5 | b = 2
6 | c = 3
7 | d = 4
8 | e = 5
9 |
10 | for i in [1 2 3]
11 | a = 6
12 | b = 7
13 | c = 8
14 | d = 9
15 | e = 10
16 |
17 | assert(a == 6)
18 | assert(b == 7)
19 | assert(c == 8)
20 | assert(d == 9)
21 | assert(e == 10)
22 |
--------------------------------------------------------------------------------
/tests/for/for_state.ca:
--------------------------------------------------------------------------------
1 |
2 | def f()
3 | for i in [10 12 14]
4 | state s = i
5 |
6 | vm = make_vm(f)
7 |
8 | vm.call
9 | print(vm.get_state)
10 |
11 |
--------------------------------------------------------------------------------
/tests/for/for_state.ca.output:
--------------------------------------------------------------------------------
1 | {'_for' => {0 => {'s' => 10}, 1 => {'s' => 12}, 2 => {'s' => 14}}}
2 |
--------------------------------------------------------------------------------
/tests/for/for_state_1.ca:
--------------------------------------------------------------------------------
1 | def f()
2 | for i in [10 12 14]
3 | state s = i
4 |
5 | vm = make_vm(f)
6 | vm.call
7 | print(vm.get_state)
8 |
9 | --require bytecode_analysis
10 | --bytecode_analysis.dump(vm)
11 |
--------------------------------------------------------------------------------
/tests/for/for_state_1.ca.output:
--------------------------------------------------------------------------------
1 | {'_for' => {0 => {'s' => 10}, 1 => {'s' => 12}, 2 => {'s' => 14}}}
2 |
--------------------------------------------------------------------------------
/tests/for/for_state_2.ca:
--------------------------------------------------------------------------------
1 | def f()
2 | for i in [10 12 14]
3 | state s = i
4 | state t = 1
5 | state u = i + 2
6 |
7 | vm = make_vm(f)
8 | vm.call
9 | print(vm.get_state)
10 |
--------------------------------------------------------------------------------
/tests/for/for_state_2.ca.output:
--------------------------------------------------------------------------------
1 | {'_for' => {0 => {'s' => 10, 't' => 1, 'u' => 12}, 1 => {'s' => 12, 't' => 1, 'u' => 14}, 2 => {'s' => 14, 't' => 1, 'u' => 16}}}
2 |
--------------------------------------------------------------------------------
/tests/for/for_state_3.ca:
--------------------------------------------------------------------------------
1 | def f()
2 | for i in []
3 | state s = i
4 | state t = 1
5 | state u = i + 2
6 |
7 | vm = make_vm(f)
8 | vm.call
9 | s = vm.get_state
10 | assert(s == nil or s == [])
11 |
--------------------------------------------------------------------------------
/tests/for/for_state_4.ca:
--------------------------------------------------------------------------------
1 | -- This code once had a bug related to the brackets (the same code without
2 | -- brackets didn't have the same bug).
3 |
4 | def f()
5 | for i in [1 2 3] { state s = i }
6 |
7 | vm = make_vm(f)
8 | vm.call
9 | print(vm.get_state)
10 |
--------------------------------------------------------------------------------
/tests/for/for_state_4.ca.output:
--------------------------------------------------------------------------------
1 | {'_for' => {0 => {'s' => 1}, 1 => {'s' => 2}, 2 => {'s' => 3}}}
2 |
--------------------------------------------------------------------------------
/tests/for/infer_with_nil_input.ca:
--------------------------------------------------------------------------------
1 |
2 | -- This once caused a runtime error: Couldn't cast value 5 to type nil
3 | -- The reason is that, inside the for-loop there was an input 'non_zero',
4 | -- which had declared type 'nil', even though it wasn't necessarily nil.
5 |
6 | non_zero = nil
7 |
8 | for i in [5 0]
9 | if i != 0
10 | non_zero = i
11 |
12 |
--------------------------------------------------------------------------------
/tests/for/list_is_movable_but_shared.ca:
--------------------------------------------------------------------------------
1 |
2 | struct Object {
3 | List list
4 | }
5 |
6 | obj = Object.make([1 2 3])
7 | print('obj = ' obj)
8 |
9 | for i in obj.list
10 | print('i = ' i)
11 |
12 | print('obj = ' obj)
13 |
--------------------------------------------------------------------------------
/tests/for/list_is_movable_but_shared.ca.output:
--------------------------------------------------------------------------------
1 | obj = Object{list: [1, 2, 3]}
2 | i = 1
3 | i = 2
4 | i = 3
5 | obj = Object{list: [1, 2, 3]}
6 |
--------------------------------------------------------------------------------
/tests/for/list_observed_inside_loop.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | list = [1 2 3]
4 | for i in list
5 | print('i = ' i)
6 | print('list = ' list)
7 |
8 | main()
9 |
--------------------------------------------------------------------------------
/tests/for/list_observed_inside_loop.ca.output:
--------------------------------------------------------------------------------
1 | i = 1
2 | list = [1, 2, 3]
3 | i = 2
4 | list = [1, 2, 3]
5 | i = 3
6 | list = [1, 2, 3]
7 |
--------------------------------------------------------------------------------
/tests/for/list_output.ca:
--------------------------------------------------------------------------------
1 |
2 | output = for i in [0 1 2 3]
3 | 5
4 |
5 | assert(output == [5 5 5 5])
6 |
7 | output = for i in [0 1 2 3]
8 | i += 3
9 | 5
10 |
11 | assert(output == [5 5 5 5])
12 |
--------------------------------------------------------------------------------
/tests/for/list_rebind.ca:
--------------------------------------------------------------------------------
1 |
2 | l = [1 2 3]
3 |
4 | print('list start: ' l)
5 |
6 | for i in @l
7 | i += 2
8 |
9 | print('list end: ' l)
10 |
--------------------------------------------------------------------------------
/tests/for/list_rebind.ca.output:
--------------------------------------------------------------------------------
1 | list start: [1, 2, 3]
2 | list end: [3, 4, 5]
3 |
--------------------------------------------------------------------------------
/tests/for/list_rebind_method.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 | int i
4 | }
5 |
6 | def T.increment(t :out)
7 | t.i += 1
8 |
9 | items = [T.make(1), T.make(2), T.make(3)]
10 |
11 | print('items start: ' items)
12 |
13 | for T t in @items
14 | @t.increment
15 |
16 | print('items end: ' items)
17 |
--------------------------------------------------------------------------------
/tests/for/list_rebind_method.ca.output:
--------------------------------------------------------------------------------
1 | items start: [T{i: 1}, T{i: 2}, T{i: 3}]
2 | items end: [T{i: 2}, T{i: 3}, T{i: 4}]
3 |
--------------------------------------------------------------------------------
/tests/for/named_index.ca:
--------------------------------------------------------------------------------
1 |
2 | list = ['apple' 'banana' 'cucumber']
3 |
4 | for i, str in list
5 | print(i ' -> ' str)
6 |
--------------------------------------------------------------------------------
/tests/for/named_index.ca.output:
--------------------------------------------------------------------------------
1 | 0 -> apple
2 | 1 -> banana
3 | 2 -> cucumber
4 |
--------------------------------------------------------------------------------
/tests/for/nested.ca:
--------------------------------------------------------------------------------
1 |
2 | for i in [1 2 3]
3 | for j in ['a' 'b' 'c']
4 | for k in [true false]
5 | for l in [:left :right]
6 | print([i j k l])
7 |
--------------------------------------------------------------------------------
/tests/for/output_and_state.ca.output:
--------------------------------------------------------------------------------
1 | step1, result = [0, 1, 2], s = {'result' => {0 => {'s' => 0}, 1 => {'s' => 1}, 2 => {'s' => 2}}}
2 | step2, result = [0, 2, 4], s = {'result' => {0 => {'s' => 0}, 1 => {'s' => 2}, 2 => {'s' => 4}}}
3 |
--------------------------------------------------------------------------------
/tests/for/state/discard_1.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | for i in [0 1 2]
4 | state s = i
5 | if i == 1
6 | discard
7 |
8 | vm = make_vm(main)
9 | vm.call
10 | vm.get_state | print
11 |
12 |
--------------------------------------------------------------------------------
/tests/for/state/discard_1.ca.output:
--------------------------------------------------------------------------------
1 | {'_for' => {0 => {'s' => 0}, 2 => {'s' => 2}}}
2 |
--------------------------------------------------------------------------------
/tests/for/state_0.ca:
--------------------------------------------------------------------------------
1 |
2 | def g()
3 | for i in [0 1 2]
4 | print('i: ' i)
5 |
6 | state s = 0
7 | print(' s: ' s)
8 |
9 | s += 1
10 |
11 | print('calling g')
12 | int = make_vm(g)
13 | int.call
14 | print('state: ' int.get_state)
15 | int.call
16 | print('state: ' int.get_state)
17 |
--------------------------------------------------------------------------------
/tests/for/state_0.ca.output:
--------------------------------------------------------------------------------
1 | calling g
2 | i: 0
3 | s: 0
4 | i: 1
5 | s: 0
6 | i: 2
7 | s: 0
8 | state: {'_for' => {0 => {'s' => 1}, 1 => {'s' => 1}, 2 => {'s' => 1}}}
9 | i: 0
10 | s: 1
11 | i: 1
12 | s: 1
13 | i: 2
14 | s: 1
15 | state: {'_for' => {0 => {'s' => 2}, 1 => {'s' => 2}, 2 => {'s' => 2}}}
16 |
--------------------------------------------------------------------------------
/tests/for/state_bug_when_1st_iteration_has_no_state.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | print("calling main:")
4 | for step in [1 2]
5 | if step == 1
6 | print(' step 1')
7 | elif step == 2
8 | state s = 0
9 | s += 1
10 | print(' step 2, state = ' s)
11 |
12 | vm = make_vm(main)
13 | vm.call
14 | vm.call
15 |
16 |
--------------------------------------------------------------------------------
/tests/for/state_bug_when_1st_iteration_has_no_state.ca.output:
--------------------------------------------------------------------------------
1 | calling main:
2 | step 1
3 | step 2, state = 1
4 | calling main:
5 | step 1
6 | step 2, state = 2
7 |
--------------------------------------------------------------------------------
/tests/forward_function_ref.ca:
--------------------------------------------------------------------------------
1 |
2 | def a() -> int
3 | return b()
4 |
5 | def b() -> int
6 | return 5
7 |
8 | assert(a() == 5)
9 |
10 | --
11 |
12 | def a2() -> int
13 | b2()
14 |
15 | def b2() -> int
16 | 10
17 |
18 | assert(a2() == 10)
19 |
20 | for i in [1]
21 | for j in [2]
22 | for k in [3]
23 | assert(b3() == 25)
24 |
25 | def b3() -> int
26 | 25
27 |
--------------------------------------------------------------------------------
/tests/funcs/assert.ca:
--------------------------------------------------------------------------------
1 |
2 | def main(b)
3 | assert(b)
4 |
5 |
6 | int = make_vm(main)
7 |
8 | int.call(true)
9 | assert(not int.errored)
10 |
11 | int.call(false)
12 | assert(int.errored)
13 |
--------------------------------------------------------------------------------
/tests/funcs/average.ca:
--------------------------------------------------------------------------------
1 |
2 | average(1.0 3.0 5.0) | print
3 | average(1.0) | print
4 | average() | print
5 | average(5 5 5 5 9 10) | print
6 |
--------------------------------------------------------------------------------
/tests/funcs/average.ca.output:
--------------------------------------------------------------------------------
1 | 3.0
2 | 1.0
3 | 0.0
4 | 6.5
5 |
--------------------------------------------------------------------------------
/tests/funcs/boolean.ca:
--------------------------------------------------------------------------------
1 |
2 | assert(str(true) == 'true')
3 | assert(str(false) == 'false')
4 |
5 | -- and
6 | assert(and(true,true) == true)
7 | assert(and(true,false) == false)
8 | assert(and(false,true) == false)
9 | assert(and(false,false) == false)
10 |
11 | -- or
12 | assert(or(true,true) == true)
13 | assert(or(true,false) == true)
14 | assert(or(false,true) == true)
15 | assert(or(false,false) == false)
16 |
--------------------------------------------------------------------------------
/tests/funcs/comparison.ca.output:
--------------------------------------------------------------------------------
1 | 5 > 3
2 | 3 > 5
3 | 1 + 2 > 2
4 | 1 + 2 >= 2
5 | 1 + 2 >= 3
6 | 3 + 6 >= 10
7 | 3 + 6 >= 9
8 |
--------------------------------------------------------------------------------
/tests/funcs/do_once.ca:
--------------------------------------------------------------------------------
1 | def once() -> bool
2 | state bool s = true
3 | result = s
4 | s = false
5 | result
6 |
7 | def f()
8 | if once()
9 | print("Check (should only print once)")
10 |
11 |
12 | vm = make_vm(f)
13 | vm.call
14 | vm.call
15 | vm.call
16 | vm.call
17 | vm.call
18 | print('final state: ' vm.get_state)
19 |
--------------------------------------------------------------------------------
/tests/funcs/do_once.ca.output:
--------------------------------------------------------------------------------
1 | Check (should only print once)
2 | final state: {'_once' => {'s' => false}}
3 |
--------------------------------------------------------------------------------
/tests/funcs/do_once_1.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | print('once = ' once())
4 |
5 | int = make_vm(main)
6 | int.call
7 | int.call
8 | int.call
9 |
--------------------------------------------------------------------------------
/tests/funcs/do_once_1.ca.output:
--------------------------------------------------------------------------------
1 | once = true
2 | once = false
3 | once = false
4 |
--------------------------------------------------------------------------------
/tests/funcs/filter.ca:
--------------------------------------------------------------------------------
1 |
2 | assert(flatten(filter([1 2 3 4], (i) -> i % 2 == 1)) == [1 3])
3 |
--------------------------------------------------------------------------------
/tests/funcs/fold.ca:
--------------------------------------------------------------------------------
1 |
2 | def fold(it, func, accum)
3 | for i in it
4 | accum = func.call(accum i)
5 | accum
6 |
7 | def append(l, i)
8 | l.append(i)
9 |
10 | result = fold([1 2 3] append [:x])
11 | assert(result == [:x 1 2 3])
12 |
--------------------------------------------------------------------------------
/tests/funcs/get_index.ca:
--------------------------------------------------------------------------------
1 |
2 | l = [1 2 3]
3 | print('l = ' l)
4 | print('get_index(l, 0) == ', get_index(l, 0))
5 | print('l[1] == ', l[1])
6 |
7 | -- try with nested lists
8 | print('[[[1]]][0][0][0] == ' [[[1]]][0][0][0])
9 |
--------------------------------------------------------------------------------
/tests/funcs/get_index.ca.output:
--------------------------------------------------------------------------------
1 | l = [1, 2, 3]
2 | get_index(l, 0) == 1
3 | l[1] == 2
4 | [[[1]]][0][0][0] == 1
5 |
--------------------------------------------------------------------------------
/tests/funcs/math.ca:
--------------------------------------------------------------------------------
1 |
2 | assert(1 + 2 == 3)
3 | assert(1 + 3 == 4)
4 |
5 | assert(6 - 2 == 4)
6 | assert(5 - 6 == -1)
7 |
8 | assert(3 * 2 == 6)
9 | assert(3 * 1 == 3)
10 | assert(3 * 0 == 0)
11 | assert(3 * -1 == -3)
12 |
13 | -- operator precedence
14 | assert(1 + 2 * 3 == 7)
15 | assert(1 * 2 + 3 == 5)
16 | assert(5 - 4 + 3 == 4)
17 | assert(1 - 2 * 3 == -5)
18 | assert(1 + 4 / 2 == 3)
19 | assert(1 - 4 / 2 == -1)
20 |
--------------------------------------------------------------------------------
/tests/funcs/mod.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | for i in -9..10
4 | print('mod(' i ',4) = ' mod(i,4))
5 | for i in -9..10
6 | print('remainder(' i ',4) = ' remainder(i,4))
7 |
8 |
--------------------------------------------------------------------------------
/tests/funcs/rand.ca:
--------------------------------------------------------------------------------
1 |
2 | for i in 0..1000
3 | r = rand()
4 | assert(r >= 0.0)
5 | assert(r < 1.0)
6 |
7 | for i in 1..1000
8 | r = rand_i(i)
9 | assert(r >= 0)
10 | assert(r < i)
11 |
--------------------------------------------------------------------------------
/tests/funcs/range.ca:
--------------------------------------------------------------------------------
1 |
2 | assert(flatten(range(0 0)) == [])
3 | assert(flatten(range(0 1)) == [0])
4 | assert(flatten(range(0 5)) == [0 1 2 3 4])
5 | assert(flatten(range(5 8)) == [5 6 7])
6 |
--------------------------------------------------------------------------------
/tests/funcs/rpath.ca:
--------------------------------------------------------------------------------
1 |
2 | p = rpath('p')
3 |
4 | assert(p == "tests/funcs/p")
5 |
--------------------------------------------------------------------------------
/tests/funcs/set.ca:
--------------------------------------------------------------------------------
1 |
2 | s = make(Set)
3 | @s.add(1)
4 |
5 | assert(s.contains(1))
6 | assert(not(s.contains(2)))
7 |
8 | @s.remove(1)
9 | assert(not(s.contains(1)))
10 | assert(not(s.contains(2)))
11 |
12 | @s.add(1)
13 | @s.add(2)
14 | @s.add(3)
15 | assert(s.contains(1))
16 | assert(s.contains(2))
17 | assert(s.contains(3))
18 | assert(not(s.contains(4)))
19 |
--------------------------------------------------------------------------------
/tests/funcs/set2.ca.output:
--------------------------------------------------------------------------------
1 | s1 = {1, 2, 3}
2 | s2 = {3, 4, 5}
3 | u1 = {1, 2, 3, 4, 5}
4 |
--------------------------------------------------------------------------------
/tests/funcs/set_index.ca:
--------------------------------------------------------------------------------
1 |
2 | l = [1 2 3]
3 |
4 | -- explicit call
5 | set_index(@l, 1, 5)
6 |
7 | print('should be [1 5 3]: ' l)
8 |
9 | -- [] syntax
10 | l[2] = 9
11 | print('should be [1 5 9]: ' l)
12 |
--------------------------------------------------------------------------------
/tests/funcs/set_index.ca.output:
--------------------------------------------------------------------------------
1 | should be [1 5 3]: [1, 5, 3]
2 | should be [1 5 9]: [1, 5, 9]
3 |
--------------------------------------------------------------------------------
/tests/funcs/sum.ca:
--------------------------------------------------------------------------------
1 |
2 | assert(sum([]) == 0)
3 | assert(sum([1]) == 1)
4 | assert(sum([1 2 3 4]) == 10)
5 | assert(sum([1 2.0 3 4.0]) == 10)
6 |
--------------------------------------------------------------------------------
/tests/funcs/type_check.ca:
--------------------------------------------------------------------------------
1 |
2 | assert(is_list([]))
3 | assert(not is_list(1))
4 | assert(not is_list(Vec2.make))
5 |
6 | assert(is_number(1.0))
7 | assert(not is_number(1))
8 |
9 | assert(is_int(1))
10 | assert(not is_int(1.0))
11 | assert(not is_int(:hello))
12 |
13 | assert(is_string(''))
14 | assert(not is_string(1))
15 |
--------------------------------------------------------------------------------
/tests/funcs/zip.ca:
--------------------------------------------------------------------------------
1 |
2 | assert(zip([1] [2]) == [[1 2]])
3 | assert(zip([] []) == [])
4 | assert(zip([1 2 3] []) == [[1 nil] [2 nil] [3 nil]])
5 | assert(zip([1 2 3] [4 5 6]) == [[1 4] [2 5] [3 6]])
6 |
--------------------------------------------------------------------------------
/tests/generic/too_many_inputs_to_overloaded_func.ca:
--------------------------------------------------------------------------------
1 |
2 | add(1 2 3 4)
3 |
--------------------------------------------------------------------------------
/tests/generic/too_many_inputs_to_overloaded_func.ca.output:
--------------------------------------------------------------------------------
1 | [tests/generic/too_many_inputs_to_overloaded_func.ca:2]
2 | Error: Too many inputs for function 'add': expected 2 and found 4
3 |
--------------------------------------------------------------------------------
/tests/hacks/derivative_test.ca.output:
--------------------------------------------------------------------------------
1 | Original y = 15.0
2 | Modified y = 15.05
3 | dY/dX = 5.000019
4 |
--------------------------------------------------------------------------------
/tests/hacks/no_effect.ca:
--------------------------------------------------------------------------------
1 |
2 | def f()
3 | trace('called f()')
4 |
5 | def g()
6 | annotate_block(:effect)
7 | trace('called g()')
8 |
9 | def main()
10 | f()
11 | g()
12 |
13 | vm = make_vm(main)
14 |
15 | print('normal run:')
16 | vm.call
17 |
18 | vm.append_hack(:no_effect)
19 | print('no effect run:')
20 | vm.call
21 |
--------------------------------------------------------------------------------
/tests/hacks/no_effect.ca.output:
--------------------------------------------------------------------------------
1 | normal run:
2 | called f()
3 | called g()
4 | no effect run:
5 | called f()
6 |
--------------------------------------------------------------------------------
/tests/hacks/no_save_state.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | state s = 0
4 | print('Current s is ' s)
5 | s += 1
6 | s
7 |
8 | vm = make_vm(main)
9 | vm.call
10 | vm.call
11 | vm.call
12 |
13 | vm.append_hack(:no_save_state)
14 | print(':no_save_state is on')
15 |
16 | vm.call
17 | vm.call
18 | vm.call
19 |
--------------------------------------------------------------------------------
/tests/hacks/no_save_state.ca.output:
--------------------------------------------------------------------------------
1 | Current s is 0
2 | Current s is 1
3 | Current s is 2
4 | :no_save_state is on
5 | Current s is 3
6 | Current s is 3
7 | Current s is 3
8 |
--------------------------------------------------------------------------------
/tests/hacks/set_value.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | a = 1
4 | print(' The value of a is: ' a)
5 |
6 | vm = make_vm(main)
7 |
8 | print('Unhacked run:')
9 | vm.run
10 |
11 | vm.append_hack([:set_value main.block.find_term('a') 2])
12 |
13 | print('Hacked run:')
14 | vm.run
15 |
--------------------------------------------------------------------------------
/tests/hacks/set_value.ca.output:
--------------------------------------------------------------------------------
1 | Unhacked run:
2 | The value of a is: 1
3 | Hacked run:
4 | The value of a is: 2
5 |
--------------------------------------------------------------------------------
/tests/hacks/watch.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | a = 1 + 2
4 |
5 | vm = make_vm(main)
6 |
7 | watch_path = [main.block.find_term('a')]
8 | vm.append_hack([:watch watch_path])
9 | vm.run
10 | result = vm.get_watch_result(watch_path)
11 | assert(result == 3)
12 |
--------------------------------------------------------------------------------
/tests/if/empty_blocks.ca:
--------------------------------------------------------------------------------
1 |
2 | if true
3 | elif false
4 | else
5 |
6 | if false
7 | else
8 |
--------------------------------------------------------------------------------
/tests/if/if.ca:
--------------------------------------------------------------------------------
1 |
2 | if true
3 | print('check1')
4 |
5 | if false
6 | print('error1')
7 |
8 | if 1 < 2
9 | print('check2')
10 |
11 | if 1 > 2
12 | print('error2')
13 |
14 |
--------------------------------------------------------------------------------
/tests/if/if.ca.output:
--------------------------------------------------------------------------------
1 | check1
2 | check2
3 |
--------------------------------------------------------------------------------
/tests/if/if_1.ca:
--------------------------------------------------------------------------------
1 |
2 | if true
3 | print('check3')
4 | elif true
5 | print('error3.1')
6 | else
7 | print('error3.2')
8 |
9 | if false
10 | print('error4.1')
11 | elif true
12 | print('check4')
13 | else
14 | print('error4.2')
15 |
16 | if false
17 | print('error5')
18 | else
19 | print('check5')
20 |
21 |
--------------------------------------------------------------------------------
/tests/if/if_1.ca.output:
--------------------------------------------------------------------------------
1 | check3
2 | check4
3 | check5
4 |
--------------------------------------------------------------------------------
/tests/if/if_2.ca:
--------------------------------------------------------------------------------
1 |
2 | x = 3
3 | y = 4
4 | if x == y
5 | print('error6')
6 | if x != y
7 | print('check6')
8 |
9 | if x == 1
10 | print('error7.1')
11 | elif x == 2
12 | print('error7.2')
13 | elif x == 3
14 | print('check7')
15 | elif x == 4
16 | print('error7.3')
17 |
18 |
--------------------------------------------------------------------------------
/tests/if/if_2.ca.output:
--------------------------------------------------------------------------------
1 | check6
2 | check7
3 |
--------------------------------------------------------------------------------
/tests/if/if_3.ca:
--------------------------------------------------------------------------------
1 |
2 | -- Use brackets
3 | if 1 != 2 { print('check8') } else { print('error8') }
4 |
5 |
--------------------------------------------------------------------------------
/tests/if/if_3.ca.output:
--------------------------------------------------------------------------------
1 | check8
2 |
--------------------------------------------------------------------------------
/tests/if/if_4.ca:
--------------------------------------------------------------------------------
1 |
2 | print('Rebinding locals:')
3 | a = 'outer'
4 | if true
5 | a = 'inner'
6 | print('should be inner: ' a)
7 |
8 | a = 'outer'
9 | if false
10 | a = 'inner'
11 | print('should be outer: ' a)
12 |
13 |
--------------------------------------------------------------------------------
/tests/if/if_4.ca.output:
--------------------------------------------------------------------------------
1 | Rebinding locals:
2 | should be inner: inner
3 | should be outer: outer
4 |
--------------------------------------------------------------------------------
/tests/if/if_5.ca:
--------------------------------------------------------------------------------
1 |
2 | a = 1 + 2
3 | if true
4 | a = 3 + 4
5 | print('should be 7: ' a)
6 |
7 | a = 1 + 2
8 | if false
9 | a = 5
10 | print('should be 3: ' a)
11 |
12 |
--------------------------------------------------------------------------------
/tests/if/if_5.ca.output:
--------------------------------------------------------------------------------
1 | should be 7: 7
2 | should be 3: 3
3 |
--------------------------------------------------------------------------------
/tests/if/if_6.ca:
--------------------------------------------------------------------------------
1 |
2 | print('Output values:')
3 |
4 | a = if true { 1 } else { 2 }
5 | print('Should be 1: ' a)
6 | a = if false { 1 } else { 2 }
7 | print('Should be 2: ' a)
8 |
9 |
10 |
--------------------------------------------------------------------------------
/tests/if/if_6.ca.output:
--------------------------------------------------------------------------------
1 | Output values:
2 | Should be 1: 1
3 | Should be 2: 2
4 |
--------------------------------------------------------------------------------
/tests/if/if_block_1.ca:
--------------------------------------------------------------------------------
1 |
2 | -- Rebind an outer name
3 | a = 'outer'
4 | if true
5 | a = 'inner'
6 |
7 | print('should be inner: ' a)
8 |
--------------------------------------------------------------------------------
/tests/if/if_block_1.ca.output:
--------------------------------------------------------------------------------
1 | should be inner: inner
2 |
--------------------------------------------------------------------------------
/tests/if/if_block_2.ca:
--------------------------------------------------------------------------------
1 |
2 | -- Rebind a name because it's bound in every block
3 | if true
4 | a = 1
5 | else
6 | a = 2
7 |
8 | print('should be 1: ' a)
9 |
--------------------------------------------------------------------------------
/tests/if/if_block_2.ca.output:
--------------------------------------------------------------------------------
1 | should be 1: 1
2 |
--------------------------------------------------------------------------------
/tests/if/if_block_output.ca:
--------------------------------------------------------------------------------
1 | a = if true { 1 } else { 2 }
2 | print('Should be 1: ' a)
3 |
--------------------------------------------------------------------------------
/tests/if/if_block_output.ca.output:
--------------------------------------------------------------------------------
1 | Should be 1: 1
2 |
--------------------------------------------------------------------------------
/tests/if/if_primary_output.ca:
--------------------------------------------------------------------------------
1 |
2 | a = if true { 1 } else { 2 }
3 | assert(a == 1)
4 |
--------------------------------------------------------------------------------
/tests/if/if_state.ca:
--------------------------------------------------------------------------------
1 |
2 | def f()
3 | if true
4 | state a = 1
5 |
6 | int = make_vm(f)
7 | int.call
8 | print('f state: ' int.get_state)
9 |
--------------------------------------------------------------------------------
/tests/if/if_state.ca.output:
--------------------------------------------------------------------------------
1 | f state: {'_if' => {0 => {'a' => 1}}}
2 |
--------------------------------------------------------------------------------
/tests/if/if_state_sample.ca:
--------------------------------------------------------------------------------
1 |
2 | if true
3 | state a
4 |
--------------------------------------------------------------------------------
/tests/if/method_rebinding.ca:
--------------------------------------------------------------------------------
1 |
2 | a = true
3 | b = false
4 |
5 | x = make(List)
6 |
7 | if true
8 | @x.append(1)
9 |
10 | @x.append(2)
11 |
12 | if true
13 | @x.append(3)
14 | else
15 | @x.append('no 1')
16 |
17 | @x.append(4)
18 |
19 | if true
20 | if true
21 | @x.append(5)
22 | else
23 | @x.append('no 2')
24 |
25 | elif false
26 | @x.append('no 3')
27 |
28 | print(x)
29 |
--------------------------------------------------------------------------------
/tests/if/method_rebinding.ca.output:
--------------------------------------------------------------------------------
1 | [1, 2, 3, 4, 5]
2 |
--------------------------------------------------------------------------------
/tests/if/rebind_1.ca:
--------------------------------------------------------------------------------
1 |
2 | if true
3 | a = [1 2 3]
4 | else
5 | a = [4 5 6]
6 |
7 | assert(a == [1 2 3])
8 |
--------------------------------------------------------------------------------
/tests/if/state_in_condition.ca:
--------------------------------------------------------------------------------
1 |
2 | def f() -> bool
3 | state s = 1
4 | print('Called f with state: ' s)
5 | s += 1
6 | true
7 |
8 | def main()
9 | if f() {}
10 |
11 | int = make_vm(main)
12 | int.call
13 | int.call
14 |
--------------------------------------------------------------------------------
/tests/if/state_in_condition.ca.output:
--------------------------------------------------------------------------------
1 | Called f with state: 1
2 | Called f with state: 2
3 |
--------------------------------------------------------------------------------
/tests/if/state_in_condition_1.ca:
--------------------------------------------------------------------------------
1 |
2 | def f() -> bool
3 | state s = 1
4 | print('Called f with state: ' s)
5 | s += 1
6 | true
7 |
8 | def main()
9 | if f()
10 |
11 | vm = make_vm(main)
12 | vm.call
13 | vm.call
14 |
--------------------------------------------------------------------------------
/tests/if/state_in_condition_1.ca.output:
--------------------------------------------------------------------------------
1 | Called f with state: 1
2 | Called f with state: 2
3 |
--------------------------------------------------------------------------------
/tests/if/state_in_condition_2.ca:
--------------------------------------------------------------------------------
1 |
2 | def f() -> bool
3 | state s = 1
4 | print('Called f with state: ' s)
5 | s += 1
6 | false
7 |
8 | def main()
9 | if f()
10 | else
11 |
12 | vm = make_vm(main)
13 | vm.call
14 | vm.call
15 |
--------------------------------------------------------------------------------
/tests/if/state_in_condition_2.ca.output:
--------------------------------------------------------------------------------
1 | Called f with state: 1
2 | Called f with state: 2
3 |
--------------------------------------------------------------------------------
/tests/if/state_in_condition_3.ca:
--------------------------------------------------------------------------------
1 |
2 | def f() -> bool
3 | state s = 1
4 | print('Called f with state: ' s)
5 | s += 1
6 | false
7 |
8 | def g() -> bool
9 | state s = 10
10 | print('Called g with state: ' s)
11 | s += 1
12 | false
13 |
14 | def main()
15 | if f()
16 | elif g()
17 | else
18 |
19 | int = make_vm(main)
20 | int.call
21 | int.call
22 |
--------------------------------------------------------------------------------
/tests/if/state_in_condition_3.ca.output:
--------------------------------------------------------------------------------
1 | Called f with state: 1
2 | Called g with state: 10
3 | Called f with state: 2
4 | Called g with state: 11
5 |
--------------------------------------------------------------------------------
/tests/if/state_reset_1.ca.output:
--------------------------------------------------------------------------------
1 | Call 1 to s branch: {'_if' => {0 => {'s' => 1}}}
2 | Call 2 to s branch: {'_if' => {0 => {'s' => 2}}}
3 | Call 1 to t branch: {'_if' => {1 => {'t' => 1}}}
4 | Call 2 to t branch: {'_if' => {1 => {'t' => 2}}}
5 | Call 3 to s branch: {'_if' => {0 => {'s' => 1}}}
6 |
--------------------------------------------------------------------------------
/tests/if/state_reset_on_cond_fail.ca:
--------------------------------------------------------------------------------
1 |
2 | def f(bool b)
3 | if b
4 | state int i = 0
5 | i += 1
6 |
7 | vm = make_vm(f)
8 | vm.call(true)
9 | print(vm.get_state)
10 | vm.call(true)
11 | print(vm.get_state)
12 | vm.call(false)
13 | print(vm.get_state)
14 | vm.call(true)
15 | print(vm.get_state)
16 |
--------------------------------------------------------------------------------
/tests/if/state_reset_on_cond_fail.ca.output:
--------------------------------------------------------------------------------
1 | {'_if' => {0 => {'i' => 1}}}
2 | {'_if' => {0 => {'i' => 2}}}
3 | nil
4 | {'_if' => {0 => {'i' => 1}}}
5 |
--------------------------------------------------------------------------------
/tests/if/with_rebind_operator.ca:
--------------------------------------------------------------------------------
1 |
2 | def increment(int i)
3 | i + 1
4 |
5 | def decrement(int i)
6 | i - 1
7 |
8 | a = 1
9 | if true
10 | increment(@a)
11 | else
12 | decrement(@a)
13 |
14 | increment(@a)
15 |
16 | assert(a == 3)
17 |
--------------------------------------------------------------------------------
/tests/interpreter/error_message_dyn_output_fail.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | def main()
4 | struct T {}
5 | t = make(T)
6 | t.hello()
7 |
8 | main()
9 |
--------------------------------------------------------------------------------
/tests/interpreter/error_message_dyn_output_fail.ca.output:
--------------------------------------------------------------------------------
1 | [tests/interpreter/error_message_dyn_output_fail.ca:8]
2 | [tests/interpreter/error_message_dyn_output_fail.ca:6 inside main()]
3 | Error: Method 'hello' not found on T{}
4 |
--------------------------------------------------------------------------------
/tests/interpreter/error_message_output_cast.ca:
--------------------------------------------------------------------------------
1 |
2 | def f() -> int
3 | return "hi"
4 |
5 | f()
6 |
--------------------------------------------------------------------------------
/tests/interpreter/error_message_output_cast.ca.output:
--------------------------------------------------------------------------------
1 | [tests/interpreter/error_message_output_cast.ca:5]
2 | [tests/interpreter/error_message_output_cast.ca:3 inside f()]
3 | Error: Couldn't cast hi to type int
4 |
--------------------------------------------------------------------------------
/tests/interpreter/many_stack_frames.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | def recur(int count) -> int
4 | if count == 0
5 | return 0
6 | else
7 | return 1 + recur(count - 1)
8 |
9 |
10 | print('recur(5) = ' recur(5))
11 | print('recur(50) = ' recur(50))
12 | print('recur(100) = ' recur(100))
13 | print('recur(1000) = ' recur(1000))
14 |
--------------------------------------------------------------------------------
/tests/interpreter/many_stack_frames.ca.output:
--------------------------------------------------------------------------------
1 | recur(5) = 5
2 | recur(50) = 50
3 | recur(100) = 100
4 | recur(1000) = 1000
5 |
--------------------------------------------------------------------------------
/tests/interpreter/misc.ca.disable:
--------------------------------------------------------------------------------
1 |
2 | f = {
3 | i = input()
4 | }.block
5 |
6 | actor = make_actor(f)
7 |
8 | assert(actor.block == f)
9 |
--------------------------------------------------------------------------------
/tests/interpreter/missing_error_message_doesnt_crash.ca.disable:
--------------------------------------------------------------------------------
1 |
2 | actor = make_actor({ 1 + 2 }.block)
3 | actor.call()
4 |
5 | -- this once caused an interpreter crash
6 | assert(actor.error_message == "")
7 |
--------------------------------------------------------------------------------
/tests/interpreter/multi_inputs.ca.disable:
--------------------------------------------------------------------------------
1 |
2 | f = {
3 | a = input()
4 | b = input()
5 | c = input()
6 |
7 | output(concat("received inputs: " a ", " b ", " c))
8 | }.block
9 |
10 | actor = make_actor(f)
11 | assert(actor.call(1 2 3) == "received inputs: 1, 2, 3")
12 | assert(actor.apply([4 5 6]) == "received inputs: 4, 5, 6")
13 |
--------------------------------------------------------------------------------
/tests/interpreter/no_output.ca.disable:
--------------------------------------------------------------------------------
1 |
2 | actor = make_actor({}.block)
3 | actor.call
4 |
--------------------------------------------------------------------------------
/tests/interpreter/simple.ca.disable:
--------------------------------------------------------------------------------
1 |
2 | square = {
3 | i = input()
4 |
5 | output(i * i)
6 | }
7 |
8 | actor = make_actor(square.block)
9 |
10 | assert(actor.call(2) == 4)
11 | assert(actor.call(3) == 9)
12 |
--------------------------------------------------------------------------------
/tests/interpreter/state.ca.disable:
--------------------------------------------------------------------------------
1 |
2 | accum = {
3 | i = input()
4 |
5 | state sum = 0
6 | sum += i
7 |
8 | output(sum)
9 | }
10 |
11 | actor = make_actor(accum.block)
12 |
13 | assert(actor.call(1) == 1)
14 | assert(actor.call(1) == 2)
15 | assert(actor.call(1) == 3)
16 | assert(actor.call(1) == 4)
17 | assert(actor.call(6) == 10)
18 |
--------------------------------------------------------------------------------
/tests/lazy.ca.output:
--------------------------------------------------------------------------------
1 | called lazyCall
2 |
--------------------------------------------------------------------------------
/tests/libs/error_trace_test.ca:
--------------------------------------------------------------------------------
1 |
2 | require stack_trace
3 |
4 | def main()
5 | def func()
6 | error('an error occurred!')
7 |
8 | func()
9 |
10 | vm = make_vm(main)
11 | vm.run
12 |
13 | stack_trace.trace_to_string(vm) | print
14 |
--------------------------------------------------------------------------------
/tests/libs/error_trace_test.ca.output:
--------------------------------------------------------------------------------
1 | [tests/libs/error_trace_test.ca:8 inside main()]
2 | [tests/libs/error_trace_test.ca:6 inside func()]
3 | Error: an error occurred!
4 |
--------------------------------------------------------------------------------
/tests/libs/indent_writer_test.ca:
--------------------------------------------------------------------------------
1 |
2 | require indent_writer
3 |
4 | indent_writer.new.writeln('Line 1').indent.writeln('Line 2 (indented)').toString | print
5 |
--------------------------------------------------------------------------------
/tests/libs/indent_writer_test.ca.output:
--------------------------------------------------------------------------------
1 | Line 1
2 | Line 2 (indented)
3 |
4 |
--------------------------------------------------------------------------------
/tests/list/List.or.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | assert(equals([1].or(2), 1))
4 | assert(equals([].or(2), 2))
5 |
--------------------------------------------------------------------------------
/tests/list/contains.ca:
--------------------------------------------------------------------------------
1 |
2 | assert([1 2 3].contains(1))
3 | assert([1 2 3].contains(2))
4 | assert([1 2 3].contains(3))
5 | assert(not [1 2 3].contains(4))
6 |
--------------------------------------------------------------------------------
/tests/list/filter.ca:
--------------------------------------------------------------------------------
1 |
2 | assert([1 2 3 4 5].filter((i) -> i % 2 == 1) == [1 3 5])
3 |
--------------------------------------------------------------------------------
/tests/list/flatten.ca:
--------------------------------------------------------------------------------
1 |
2 | a = [[1] [2 3] [4 [5 6]]].flatten
3 |
4 | assert(a == [1 2 3 4 [5 6]])
5 |
--------------------------------------------------------------------------------
/tests/list/functional.ca:
--------------------------------------------------------------------------------
1 |
2 | assert([1 2 3].each((i) -> i + 3) == [4 5 6])
3 |
--------------------------------------------------------------------------------
/tests/list/get_and_set.ca:
--------------------------------------------------------------------------------
1 |
2 | l = ['a' 'b' 'c']
3 |
4 | assert(l.get(1) == 'b')
5 |
6 | assert(l.set(1, 'B') == ['a' 'B' 'c'])
7 |
8 | l = [0 1 2 3]
9 |
10 | assert(l.apply(2, (i) -> i + 3 ) == [0 1 5 3])
11 |
--------------------------------------------------------------------------------
/tests/list/insert.ca:
--------------------------------------------------------------------------------
1 |
2 | assert([0 1 2].insert(0, :a) == [:a 0 1 2])
3 | assert([0 1 2].insert(1, :a) == [0 :a 1 2])
4 | assert([0 1 2].insert(3, :a) == [0 1 2 :a])
5 |
--------------------------------------------------------------------------------
/tests/list/misc.ca:
--------------------------------------------------------------------------------
1 |
2 | l = [1,2]
3 |
4 | assert(str(l) == "[1, 2]");
5 | assert(l.count() == 2)
6 | assert(l[0] == 1)
7 | assert(l[1] == 2)
8 |
9 | @l.append(3)
10 |
11 | assert(str(l) == "[1, 2, 3]");
12 | assert(l.count() == 3)
13 | assert(l[0] == 1)
14 | assert(l[1] == 2)
15 | assert(l[2] == 3)
16 |
17 | @l.concat([4 5])
18 | assert(str(l) == "[1, 2, 3, 4, 5]");
19 |
--------------------------------------------------------------------------------
/tests/list/out_of_range.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | int = make_vm(->
4 | l = []
5 | l[0]
6 | )
7 |
8 | int.run
9 |
10 | assert(int.errored)
11 |
--------------------------------------------------------------------------------
/tests/list/remove.ca:
--------------------------------------------------------------------------------
1 |
2 | assert([0 1 2].remove(1) == [0 2])
3 | assert([0 1 2].remove(0) == [1 2])
4 | assert([0 1 2].remove(2) == [0 1])
5 |
--------------------------------------------------------------------------------
/tests/list/split.ca:
--------------------------------------------------------------------------------
1 |
2 | assert([1 2 3 :ha 4 5 :ha :ha 6].split(:ha) == [[1 2 3] [4 5] [] [6]])
3 |
4 |
--------------------------------------------------------------------------------
/tests/list/to_set.ca:
--------------------------------------------------------------------------------
1 |
2 | set = [1 2 3].to_set
3 |
4 | assert(typeof(set) == Set)
5 | assert(set.contains(1))
6 | assert(not set.contains(4))
7 |
--------------------------------------------------------------------------------
/tests/match/test.ca:
--------------------------------------------------------------------------------
1 |
2 | require match
3 |
4 | print('match 1 = ' match.match_list([1 2 3] [1 any 3]))
5 |
--------------------------------------------------------------------------------
/tests/match/test.ca.output:
--------------------------------------------------------------------------------
1 | match 1 = true
2 |
--------------------------------------------------------------------------------
/tests/math/max_min.ca:
--------------------------------------------------------------------------------
1 |
2 | assert(min(1 3) == 1)
3 | assert(min(3 1) == 1)
4 | assert(typeof(min(1 3)) == int)
5 | assert(min(1.0 3) == 1.0)
6 | assert(typeof(min(1.0 3)) == number)
7 |
8 | assert(max(1 3) == 3)
9 | assert(max(3 1) == 3)
10 | assert(typeof(max(1 3)) == int)
11 | assert(max(1.0 3) == 3)
12 | assert(typeof(max(1.0 3)) == number)
13 |
--------------------------------------------------------------------------------
/tests/method_lookup_cache/many_entries.ca.output:
--------------------------------------------------------------------------------
1 | called A.f
2 | called B.f
3 | called C.f
4 | called D.f
5 | called E.f
6 | called F.f
7 | called G.f
8 | called A.f
9 | called B.f
10 | called C.f
11 | called D.f
12 | called E.f
13 | called F.f
14 | called G.f
15 | called A.f
16 | called B.f
17 | called C.f
18 | called D.f
19 | called E.f
20 | called F.f
21 |
--------------------------------------------------------------------------------
/tests/method_lookup_cache/simple.ca:
--------------------------------------------------------------------------------
1 |
2 | struct A {}
3 |
4 | def A.f(self)
5 | print('called A.f')
6 |
7 | struct B {}
8 |
9 | def B.f(self)
10 | print('called B.f')
11 |
12 | def one_test(bool b)
13 |
14 | def main(bool b)
15 | val = cond(b A.make B.make)
16 | any.cast(@val)
17 | val.f
18 |
19 | stack = make_vm(main)
20 |
21 | for i in 0..10
22 | stack.call(i % 2 == 1)
23 | --stack.dump_with_bytecode
24 |
--------------------------------------------------------------------------------
/tests/method_lookup_cache/simple.ca.output:
--------------------------------------------------------------------------------
1 | called B.f
2 | called A.f
3 | called B.f
4 | called A.f
5 | called B.f
6 | called A.f
7 | called B.f
8 | called A.f
9 | called B.f
10 | called A.f
11 |
--------------------------------------------------------------------------------
/tests/methods/default_output_type.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 | int i
4 | }
5 |
6 | -- T.f should implicitly have output type T.
7 | def T.f(@self)
8 | self.i += 1
9 |
10 | t = make(T)
11 | assert(t == [0])
12 |
13 | t = t.f
14 | assert(t == [1])
15 | assert(static_type(t) == T)
16 |
--------------------------------------------------------------------------------
/tests/methods/dynamic_method_and_varargs.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | struct T {}
4 |
5 | def T.f(self, args :multiple)
6 | print('T.f: ', args)
7 |
8 | t = T.make
9 |
10 | t.f
11 | t.f(1)
12 | t.f(1 2)
13 |
14 | any.cast(@t)
15 |
16 | -- This had a bug: when using dynamic inputs, the 't.f' call would set 'args' to
17 | -- null instead of [].
18 | t.f
19 |
20 | t.f(1)
21 | t.f(1 2)
22 |
--------------------------------------------------------------------------------
/tests/methods/dynamic_method_and_varargs.ca.output:
--------------------------------------------------------------------------------
1 | T.f: []
2 | T.f: [1]
3 | T.f: [1, 2]
4 | T.f: []
5 | T.f: [1]
6 | T.f: [1, 2]
7 |
--------------------------------------------------------------------------------
/tests/methods/method_calls.ca:
--------------------------------------------------------------------------------
1 |
2 | print('[1 2 3].length() == ' [1 2 3].length())
3 | l = [4 5 6]
4 | print('l.length() == ' l.length())
5 |
6 | -- define a new method
7 | struct T;
8 | def T.method(t) -> String
9 | return "called T.method"
10 |
11 | struct U;
12 | def U.method(t) -> String
13 | return "called U.method"
14 |
15 | print("T.method == " make(T).method())
16 | print("U.method == " make(U).method())
17 |
--------------------------------------------------------------------------------
/tests/methods/method_calls.ca.output:
--------------------------------------------------------------------------------
1 | [1 2 3].length() == 3
2 | l.length() == 3
3 | T.method == called T.method
4 | U.method == called U.method
5 |
--------------------------------------------------------------------------------
/tests/methods/method_without_parens.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 | int i
4 | }
5 |
6 | def T.get_i(self) -> int
7 | self.i
8 |
9 | t = make(T)
10 | assert(t.get_i == 0)
11 | @t.set_i(5)
12 | assert(t.get_i == 5)
13 | assert(t.i == 5)
14 |
--------------------------------------------------------------------------------
/tests/methods/methods.ca.output:
--------------------------------------------------------------------------------
1 | [tests/methods/methods.ca:42]
2 | [inside assert()]
3 | Error: Assert failed
4 |
--------------------------------------------------------------------------------
/tests/methods/multi_returns.ca.output:
--------------------------------------------------------------------------------
1 | plain style:
2 | a = {list: [1, 2]}
3 | b = 3
4 | rebind style:
5 | a = 3
6 | t = {list: [1, 2]}
7 |
--------------------------------------------------------------------------------
/tests/methods/precedence_over_simulated_methods.ca:
--------------------------------------------------------------------------------
1 |
2 | struct A {
3 | int i
4 | }
5 |
6 | def A.set_i(s, val)
7 | mult(@val 2)
8 | print('setting i to: ', val)
9 | s.i = val
10 |
11 | a = A.make
12 | @a.set_i(3)
13 |
14 | print('result: ' a)
15 |
--------------------------------------------------------------------------------
/tests/methods/precedence_over_simulated_methods.ca.output:
--------------------------------------------------------------------------------
1 | setting i to: 6
2 | result: A{i: 6}
3 |
--------------------------------------------------------------------------------
/tests/methods/rebind_input.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 | int a
4 | }
5 |
6 | def T.add(@self, b)
7 | self.a += b
8 | 0
9 |
10 | t = T.make
11 | @t.add(1)
12 | assert(t.a == 1)
13 | @t.add(3)
14 | assert(t.a == 4)
15 |
--------------------------------------------------------------------------------
/tests/methods/recur.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {}
3 |
4 | def T.f(self, int i) -> int
5 | if i <= 0
6 | return 0
7 | return self.f(i - 1) + i
8 |
9 | t = make(T)
10 | assert(t.f(1) == 1)
11 | assert(t.f(2) == 3)
12 | assert(t.f(3) == 6)
13 | assert(t.f(4) == 10)
14 |
--------------------------------------------------------------------------------
/tests/methods/varargs.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 | }
4 |
5 | def T.f(self, any args :multiple)
6 | print('args = ' args)
7 |
8 | t = make(T)
9 | t.f(1)
10 | t.f(2 3)
11 | t.f(4 5 6)
12 |
--------------------------------------------------------------------------------
/tests/methods/varargs.ca.output:
--------------------------------------------------------------------------------
1 | args = [1]
2 | args = [2, 3]
3 | args = [4, 5, 6]
4 |
--------------------------------------------------------------------------------
/tests/migrate/added_state.ca:
--------------------------------------------------------------------------------
1 |
2 | require stack_trace
3 |
4 | def left()
5 | state a = 'old'
6 |
7 | def right()
8 | state b = 3
9 | state a = 'old'
10 | print('after migration, a is: ' a)
11 | print('b is: ' b)
12 |
13 | vm = make_vm(left)
14 | vm.call
15 |
16 | if vm.has_error
17 | stack_trace.dump(vm)
18 |
19 | vm.migrate_to(right)
20 | vm.call
21 |
22 | if vm.has_error
23 | stack_trace.dump(vm)
24 |
--------------------------------------------------------------------------------
/tests/migrate/added_state.ca.output:
--------------------------------------------------------------------------------
1 | after migration, a is: old
2 | b is: 3
3 |
--------------------------------------------------------------------------------
/tests/migrate/added_state_2.ca:
--------------------------------------------------------------------------------
1 |
2 | def left()
3 | def nested()
4 | state a = 'old'
5 |
6 | nested()
7 |
8 | def right()
9 | def nested()
10 | state a = 'new'
11 | state b = 'b'
12 | print('after migration, a is: ' a)
13 | print('b is: ' b)
14 |
15 | nested()
16 |
17 | int = make_vm(left)
18 | int.run
19 |
20 | int.migrate_to(right)
21 | int.run
22 |
--------------------------------------------------------------------------------
/tests/migrate/added_state_2.ca.output:
--------------------------------------------------------------------------------
1 | after migration, a is: old
2 | b is: b
3 |
--------------------------------------------------------------------------------
/tests/migrate/added_state_3.ca:
--------------------------------------------------------------------------------
1 |
2 | def nested(any initial) -> any
3 | state a = initial
4 | a
5 |
6 | def left()
7 | nested_result = nested('old')
8 |
9 | def right()
10 | state a = 2
11 |
12 | nested_result = nested('new')
13 | print('after migration, a is: ' a)
14 | print('nested_result is: ' nested_result)
15 |
16 | int = make_vm(left)
17 | int.run
18 |
19 | int.migrate_to(right)
20 | int.run
21 |
--------------------------------------------------------------------------------
/tests/migrate/added_state_3.ca.output:
--------------------------------------------------------------------------------
1 | after migration, a is: 2
2 | nested_result is: old
3 |
--------------------------------------------------------------------------------
/tests/migrate/block_reference.ca:
--------------------------------------------------------------------------------
1 |
2 | def left()
3 | def nested()
4 |
5 | state b = nested.block
6 |
7 | def right()
8 | def nested()
9 |
10 | state b = null
11 |
12 | assert(b == nested.block)
13 |
14 | int = make_vm(left)
15 | int.call
16 |
17 | int.migrate_to(right)
18 | int.call
19 |
--------------------------------------------------------------------------------
/tests/migrate/bug_with_type_methods.ca.output:
--------------------------------------------------------------------------------
1 | Calling t_from_left.func:
2 | [left] called T.func with: T{a: 1}
3 | Calling t_from_right.func:
4 | [right] called T.func with: T{a: 1}
5 |
--------------------------------------------------------------------------------
/tests/migrate/closure_reference.ca:
--------------------------------------------------------------------------------
1 |
2 | def left()
3 | binding = 'old'
4 |
5 | state closure = -> print('closure called with: ' binding)
6 |
7 | def right()
8 | binding = 'new'
9 |
10 | state closure = -> print('closure called with: ' binding)
11 |
12 | closure.call
13 |
14 | vm = make_vm(left)
15 | vm.run
16 |
17 | vm.migrate_to(right)
18 | vm.run
19 |
--------------------------------------------------------------------------------
/tests/migrate/closure_reference.ca.output:
--------------------------------------------------------------------------------
1 | closure called with: new
2 |
--------------------------------------------------------------------------------
/tests/migrate/hashtable.ca.output:
--------------------------------------------------------------------------------
1 | After migration..
2 | map has: 3 -> 4
3 |
--------------------------------------------------------------------------------
/tests/migrate/removed_state.ca:
--------------------------------------------------------------------------------
1 |
2 | def left()
3 | state a = 'old a'
4 | state b = 'old b'
5 | state c = 'old c'
6 |
7 | def right()
8 | state a = 'new a'
9 | state c = 'new c'
10 |
11 | print('after migration, a is: ' a)
12 | print('c is: ' c)
13 |
14 | int = make_vm(left)
15 | int.run
16 |
17 | int.migrate_to(right)
18 | int.run
19 |
--------------------------------------------------------------------------------
/tests/migrate/removed_state.ca.output:
--------------------------------------------------------------------------------
1 | after migration, a is: old a
2 | c is: old c
3 |
--------------------------------------------------------------------------------
/tests/migrate/simple.ca:
--------------------------------------------------------------------------------
1 |
2 | def left()
3 | state a = 1
4 |
5 | def right()
6 | state a = 2
7 | print('after migration, a is: ' a)
8 |
9 | int = make_vm(left)
10 | int.call
11 |
12 | int.migrate_to(right)
13 | int.call
14 |
--------------------------------------------------------------------------------
/tests/migrate/simple.ca.output:
--------------------------------------------------------------------------------
1 | after migration, a is: 1
2 |
--------------------------------------------------------------------------------
/tests/migrate/term_reference.ca:
--------------------------------------------------------------------------------
1 |
2 | def left()
3 | a = 1
4 |
5 | state term = term_ref(a)
6 |
7 | def right()
8 | a = 2
9 |
10 | state term
11 | print('after migration, term points to: ' term.value)
12 |
13 | int = make_vm(left)
14 | int.run
15 |
16 | int.migrate_to(right)
17 | int.run
18 |
--------------------------------------------------------------------------------
/tests/migrate/term_reference.ca.output:
--------------------------------------------------------------------------------
1 | after migration, term points to: 2
2 |
--------------------------------------------------------------------------------
/tests/migrate/type_change_cast.ca:
--------------------------------------------------------------------------------
1 |
2 | def left()
3 | state int a = 1
4 |
5 | def right()
6 | state number a = 2
7 | print('after migration, a is: ' a)
8 |
9 | vm = make_vm(left)
10 | vm.run
11 |
12 | vm.migrate_to(right)
13 | vm.run
14 |
--------------------------------------------------------------------------------
/tests/migrate/type_change_cast.ca.output:
--------------------------------------------------------------------------------
1 | after migration, a is: 1.0
2 |
--------------------------------------------------------------------------------
/tests/migrate/type_change_incompatible.ca:
--------------------------------------------------------------------------------
1 |
2 | def left()
3 | state bool a = true
4 |
5 | def right()
6 | state String a = 'new'
7 | print('after migration, a is: ' a)
8 |
9 | vm = make_vm(left)
10 | vm.run
11 |
12 | vm.migrate_to(right)
13 | vm.run
14 |
--------------------------------------------------------------------------------
/tests/migrate/type_change_incompatible.ca.output:
--------------------------------------------------------------------------------
1 | after migration, a is: new
2 |
--------------------------------------------------------------------------------
/tests/module/in_directory/lib.ca:
--------------------------------------------------------------------------------
1 |
2 | print('Executed in_directory/lib.ca')
3 |
4 | def f(i)
5 | print('Called in_directory/lib.f with ' i)
6 |
7 |
--------------------------------------------------------------------------------
/tests/module/in_directory/lib.ca.output:
--------------------------------------------------------------------------------
1 | Executed in_directory/lib.ca
2 |
--------------------------------------------------------------------------------
/tests/module/lib1.ca.output:
--------------------------------------------------------------------------------
1 | evaluating lib1.ca
2 | Called lib1.get_x
3 |
--------------------------------------------------------------------------------
/tests/module/lib2.ca:
--------------------------------------------------------------------------------
1 |
2 | require_local lib1
3 |
4 | print('evaluating lib2.ca')
5 |
6 | def f(i)
7 | print('Calling lib2.f with ' i)
8 | print('lib2.f is calling lib1.f ..')
9 | lib1.f(i)
10 |
11 | def g(i)
12 | print('Called lib2.g with ' i)
13 |
--------------------------------------------------------------------------------
/tests/module/lib2.ca.output:
--------------------------------------------------------------------------------
1 | evaluating lib2.ca
2 |
--------------------------------------------------------------------------------
/tests/module/lib3.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 |
4 | }
5 |
6 | outerValue = 1 + 2
7 |
8 | def T.f(self, i)
9 | print('called T.f(' i '), outerValue = ' outerValue)
10 |
11 | def newT()
12 | T.make
13 |
--------------------------------------------------------------------------------
/tests/module/lib_with_static_error.ca:
--------------------------------------------------------------------------------
1 |
2 | print("hi
3 |
--------------------------------------------------------------------------------
/tests/module/lib_with_static_error.ca.output:
--------------------------------------------------------------------------------
1 | [tests/module/lib_with_static_error.ca:2]
2 | Error: Syntax error: Expected: )
3 |
--------------------------------------------------------------------------------
/tests/module/libc.ca:
--------------------------------------------------------------------------------
1 |
2 | three = 3
3 |
--------------------------------------------------------------------------------
/tests/module/load_in_directory.ca:
--------------------------------------------------------------------------------
1 |
2 | lib = require_local in_directory/lib
3 |
4 | lib.f('input value')
5 |
--------------------------------------------------------------------------------
/tests/module/load_in_directory.ca.output:
--------------------------------------------------------------------------------
1 | Called in_directory/lib.f with input value
2 |
--------------------------------------------------------------------------------
/tests/module/module_get_with_symbol.ca:
--------------------------------------------------------------------------------
1 |
2 | require_local lib1
3 | require_local lib2
4 |
5 | funcs = [lib1.:f, lib2.:f]
6 |
7 | print('Calling closure list..')
8 |
9 | for i, func in funcs
10 | print('Looping across closures, index = ' i)
11 | func.call(i)
12 |
--------------------------------------------------------------------------------
/tests/module/module_get_with_symbol.ca.output:
--------------------------------------------------------------------------------
1 | Calling closure list..
2 | Looping across closures, index = 0
3 | Called lib1.f with 0
4 | Looping across closures, index = 1
5 | Calling lib2.f with 1
6 | lib2.f is calling lib1.f ..
7 | Called lib1.f with 1
8 |
--------------------------------------------------------------------------------
/tests/module/module_method_with_binding.ca.output:
--------------------------------------------------------------------------------
1 | called T.f(123), outerValue = 3
2 |
--------------------------------------------------------------------------------
/tests/module/nested.ca:
--------------------------------------------------------------------------------
1 |
2 | lib = require_local lib2
3 | lib.f('input2')
4 |
--------------------------------------------------------------------------------
/tests/module/nested.ca.output:
--------------------------------------------------------------------------------
1 | Calling lib2.f with input2
2 | lib2.f is calling lib1.f ..
3 | Called lib1.f with input2
4 |
--------------------------------------------------------------------------------
/tests/module/nonexistant_module.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | foo = require jfkdsjflkds
4 |
5 | vm = make_vm(main)
6 | vm.call
7 | assert(vm.error_message == "Couldn't find module: jfkdsjflkds")
8 |
--------------------------------------------------------------------------------
/tests/module/require_error_module.ca:
--------------------------------------------------------------------------------
1 |
2 | require_local lib_with_static_error
3 |
--------------------------------------------------------------------------------
/tests/module/require_error_module.ca.output:
--------------------------------------------------------------------------------
1 | Module 'lib_with_static_error' has static errors:
2 | [tests/module/lib_with_static_error.ca 2,0 - 3,0] Syntax error: Expected: )
3 | Module 'lib_with_static_error' has static errors:
4 | [tests/module/lib_with_static_error.ca 2,0 - 3,0] Syntax error: Expected: )
5 |
--------------------------------------------------------------------------------
/tests/module/require_file.ca:
--------------------------------------------------------------------------------
1 |
2 | filename = rpath('lib1.ca')
3 | print('loading ' filename)
4 | m = require_file(filename)
5 | m.f(5)
6 |
--------------------------------------------------------------------------------
/tests/module/require_file.ca.output:
--------------------------------------------------------------------------------
1 | loading tests/module/lib1.ca
2 | Called lib1.f with 5
3 |
--------------------------------------------------------------------------------
/tests/module/require_local_dynamic.ca:
--------------------------------------------------------------------------------
1 |
2 | def main(library)
3 | lib = require_local(library)
4 | lib.g(1)
5 |
6 | print("calling main('lib1')")
7 | main("lib1")
8 | print("calling main('lib2')")
9 | main("lib2")
10 |
--------------------------------------------------------------------------------
/tests/module/require_local_dynamic.ca.output:
--------------------------------------------------------------------------------
1 | calling main('lib1')
2 | Called lib1.g with 1
3 | calling main('lib2')
4 | Called lib2.g with 1
5 |
--------------------------------------------------------------------------------
/tests/module/require_local_dynamic_2.ca:
--------------------------------------------------------------------------------
1 |
2 | lib = require_local("lib1")
3 | lib.f(1)
4 |
--------------------------------------------------------------------------------
/tests/module/require_local_dynamic_2.ca.output:
--------------------------------------------------------------------------------
1 | Called lib1.f with 1
2 |
--------------------------------------------------------------------------------
/tests/module/require_statement_syntax.ca:
--------------------------------------------------------------------------------
1 |
2 | require_local lib1
3 |
4 | lib1.f(123)
5 |
--------------------------------------------------------------------------------
/tests/module/require_statement_syntax.ca.output:
--------------------------------------------------------------------------------
1 | Called lib1.f with 123
2 |
--------------------------------------------------------------------------------
/tests/module/simple.ca:
--------------------------------------------------------------------------------
1 |
2 | lib = require_local lib1
3 | lib.f('input1')
4 |
--------------------------------------------------------------------------------
/tests/module/simple.ca.output:
--------------------------------------------------------------------------------
1 | Called lib1.f with input1
2 |
--------------------------------------------------------------------------------
/tests/module/static_value.ca:
--------------------------------------------------------------------------------
1 |
2 | require_local libc
3 |
4 | libc.three | print
5 |
--------------------------------------------------------------------------------
/tests/module/static_value.ca.output:
--------------------------------------------------------------------------------
1 | 3
2 |
--------------------------------------------------------------------------------
/tests/module/use_another_modules_module.ca:
--------------------------------------------------------------------------------
1 |
2 | require_local lib2
3 |
4 | lib2.lib1.f(5)
5 |
--------------------------------------------------------------------------------
/tests/module/use_another_modules_module.ca.output:
--------------------------------------------------------------------------------
1 | Called lib1.f with 5
2 |
--------------------------------------------------------------------------------
/tests/module/use_type.ca:
--------------------------------------------------------------------------------
1 |
2 | require_local lib1
3 |
4 | t = lib1.Lib1_T.make
5 |
6 | print('Created a Lib1_T instance: ', t)
7 |
8 | t.f(123)
9 |
10 | t = lib1.Lib1_T.make('hello')
11 |
12 | print('Created a Lib1_T instance: ', t)
13 |
14 | t.f(456)
15 |
--------------------------------------------------------------------------------
/tests/module/use_type.ca.output:
--------------------------------------------------------------------------------
1 | Created a Lib1_T instance: Lib1_T{s: ''}
2 | Called Lib1_T.f with: 123
3 | Created a Lib1_T instance: Lib1_T{s: 'hello'}
4 | Called Lib1_T.f with: 456
5 |
--------------------------------------------------------------------------------
/tests/move_optimization/nonlocal_user.ca:
--------------------------------------------------------------------------------
1 |
2 | a = 1+1
3 |
4 | def f()
5 | return a
6 |
7 | b = a
8 |
9 | assert(f() == 2)
10 |
--------------------------------------------------------------------------------
/tests/object/update.ca.output:
--------------------------------------------------------------------------------
1 | table initial = {:b => 2, :a => 1}
2 | {:b => 2, :a => 3}
3 | {:b => 0, :a => 0}
4 | {:b => 0, :a => 4}
5 | struct initial = S{a: 1, b: 2}
6 | S{a: 3, b: 2}
7 | S{a: 0, b: 0}
8 | S{a: 4, b: 0}
9 |
--------------------------------------------------------------------------------
/tests/old_cast.ca:
--------------------------------------------------------------------------------
1 |
2 | -- This once failed:
3 | a = [1 0] -> Vec2.cast
4 |
--------------------------------------------------------------------------------
/tests/parser/anon_func.ca.output:
--------------------------------------------------------------------------------
1 | check 1
2 | check 2
3 | check 3
4 | check 4
5 | f, result = nil
6 | f, result = check 5
7 | should equal 2: 2
8 | should equal 5: 5
9 | should equal [1, 3]: [1, 3]
10 | should equal [1, 2, 3]: [1, 2, 3]
11 |
--------------------------------------------------------------------------------
/tests/parser/anon_func2.ca.output:
--------------------------------------------------------------------------------
1 | inside a..
2 | multiline anon function
3 | f, result = 3
4 | another..
5 | multiline anon function
6 | f, result = 3
7 | multiline func with..
8 | x = 10
9 | g(10), result = 13
10 |
--------------------------------------------------------------------------------
/tests/parser/at_symbol_resolved_first.ca.output:
--------------------------------------------------------------------------------
1 | list initial value: [1, 2, 3, 4, 5]
2 | 1st pass with "@list.pop", list = [1, 2, 3, 4]
3 | 2nd pass with "name = @list.pop", list = [1, 2, 3], name = 4
4 | 3rd pass with "list = list.pop", list = [1, 2]
5 |
--------------------------------------------------------------------------------
/tests/parser/bar_to_method.ca:
--------------------------------------------------------------------------------
1 |
2 | print(1 | number.cast)
3 | 2 | number.cast | print
4 |
--------------------------------------------------------------------------------
/tests/parser/bar_to_method.ca.output:
--------------------------------------------------------------------------------
1 | 1.0
2 | 2.0
3 |
--------------------------------------------------------------------------------
/tests/parser/function_called_add.ca:
--------------------------------------------------------------------------------
1 |
2 | def add(int i, int j) -> int
3 |
4 | print('using custom add on: ' i ',' j)
5 | 10
6 |
7 | print('3 + 3 = ', 3 + 3)
8 |
9 |
--------------------------------------------------------------------------------
/tests/parser/function_called_add.ca.output:
--------------------------------------------------------------------------------
1 | 3 + 3 = 6
2 |
--------------------------------------------------------------------------------
/tests/rebinding/bug_repro_input_1.ca:
--------------------------------------------------------------------------------
1 |
2 | def f(int i, int j) -> int
3 | 3
4 |
5 | a = 1
6 | b = 2
7 |
8 | -- There was a bug where this call would wrongly think that it should rebind
9 | -- the name 'b' to the result.
10 | f(@a, b)
11 |
12 | assert(a == 3)
13 | assert(b == 2)
14 |
--------------------------------------------------------------------------------
/tests/rebinding/dynamic_method.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 | any v
4 | }
5 |
6 | t = make(T)
7 | t.v = 0
8 | assert(t == [0])
9 |
10 | t.v = t
11 | assert(t == [[0]])
12 |
13 | t.v.v = []
14 | assert(t == [[[]]])
15 |
16 | assert(t.v.v.append(1) == [1])
17 |
18 | @t.v.v.append(1)
19 | assert(t == [[[1]]])
20 |
--------------------------------------------------------------------------------
/tests/rect/methods.ca:
--------------------------------------------------------------------------------
1 |
2 | r = Rect.make(1 2 4 8)
3 |
4 | assert(r.top_left == [1 2])
5 | assert(r.width == 3)
6 | assert(r.height == 6)
7 | assert(r.intersects([1 2 3 4]))
8 | assert(not r.intersects([5 2 6 10]))
9 |
--------------------------------------------------------------------------------
/tests/recursion.ca:
--------------------------------------------------------------------------------
1 |
2 | def fib(int i) -> int
3 | if i == 0 or i == 1
4 | return 1
5 |
6 | return fib(i - 1) + fib(i - 2)
7 |
8 | def main()
9 | for i in 0..11
10 | print('fib(' i ') = ' fib(i))
11 |
12 | main()
13 |
--------------------------------------------------------------------------------
/tests/recursion.ca.output:
--------------------------------------------------------------------------------
1 | fib(0) = 1
2 | fib(1) = 1
3 | fib(2) = 2
4 | fib(3) = 3
5 | fib(4) = 5
6 | fib(5) = 8
7 | fib(6) = 13
8 | fib(7) = 21
9 | fib(8) = 34
10 | fib(9) = 55
11 | fib(10) = 89
12 |
--------------------------------------------------------------------------------
/tests/recursion_2.ca:
--------------------------------------------------------------------------------
1 |
2 | def recr(int i)
3 | print('recr: ' i)
4 | if i > 0
5 | recr(i - 1)
6 |
7 | recr(3)
8 |
--------------------------------------------------------------------------------
/tests/recursion_2.ca.output:
--------------------------------------------------------------------------------
1 | recr: 3
2 | recr: 2
3 | recr: 1
4 | recr: 0
5 |
--------------------------------------------------------------------------------
/tests/recursion_3.ca:
--------------------------------------------------------------------------------
1 |
2 | def recr(int i) -> int
3 | print('recr: ' i)
4 | if i > 0
5 | sum = i + recr(i - 1)
6 | return sum
7 |
8 | return 1
9 |
10 | print(recr(3))
11 |
--------------------------------------------------------------------------------
/tests/recursion_3.ca.output:
--------------------------------------------------------------------------------
1 | recr: 3
2 | recr: 2
3 | recr: 1
4 | recr: 0
5 | 7
6 |
--------------------------------------------------------------------------------
/tests/reflection/anon_func.ca:
--------------------------------------------------------------------------------
1 |
2 | testBlock = ->
3 | a = 1
4 | b = 2
5 | c = ->
6 | d = 4
7 | e = 5
8 |
9 | br = testBlock.block
10 |
11 | a = br.find_term('a')
12 | b = br.find_term('b')
13 | c = br.find_term('c')
14 |
15 | assert(a.parent == br)
16 | assert(b.parent == br)
17 | assert(c.parent == br)
18 |
19 | c_contents = c.contents
20 |
21 | assert(c_contents.owner == c)
22 |
--------------------------------------------------------------------------------
/tests/reflection/call.ca.output:
--------------------------------------------------------------------------------
1 | call worked
2 |
--------------------------------------------------------------------------------
/tests/reflection/caller.ca:
--------------------------------------------------------------------------------
1 |
2 | def get_caller_name() -> String
3 | caller = reflect_caller(1)
4 | return caller.name
5 |
6 | def get_caller() -> Term
7 | return reflect_caller(1)
8 |
9 |
10 | abc = get_caller_name()
11 | assert(abc == 'abc')
12 |
13 | x = get_caller()
14 | assert(x == term_ref(x))
15 |
--------------------------------------------------------------------------------
/tests/reflection/is_comment.ca:
--------------------------------------------------------------------------------
1 |
2 | def f()
3 | -- this is a comment
4 |
5 | term = f.block.terms[0]
6 | assert(term.is_comment)
7 |
--------------------------------------------------------------------------------
/tests/reflection/link.ca.output:
--------------------------------------------------------------------------------
1 | link worked
2 |
--------------------------------------------------------------------------------
/tests/reflection/list_statements.ca.output:
--------------------------------------------------------------------------------
1 | statements:
2 | a = add(...)
3 | b = mult(...)
4 | value(...)
5 | for(...)
6 | main(...)
7 |
--------------------------------------------------------------------------------
/tests/reflection/trace_dependents.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | def code()
4 | a = 1
5 | b = 2
6 | c = 3
7 | d = a + c
8 | e = 4
9 | f = d
10 |
11 | f_term = code.block.find_term('f')
12 | dependents = f_term.trace_dependents(code.block)
13 |
14 | assert(equals(for dep in dependents { dep.name }, ['c','a','d']))
15 |
--------------------------------------------------------------------------------
/tests/right_apply/bug_with_rebind_operator_1.ca:
--------------------------------------------------------------------------------
1 |
2 | x = 1
3 |
4 | @x | add(2)
5 |
6 | assert(x == 3)
7 |
--------------------------------------------------------------------------------
/tests/right_apply/bug_with_rebind_operator_2.ca:
--------------------------------------------------------------------------------
1 |
2 | def increment(x)
3 | x + 1
4 |
5 | x = 1
6 | @x | increment
7 |
8 | assert(x == 2)
9 |
--------------------------------------------------------------------------------
/tests/runtime_typing/dynamic_method.ca.output:
--------------------------------------------------------------------------------
1 | A.blah
2 | B.blah
3 | A.blah2: str1
4 | B.blah2: str2
5 | calling blah3: 11
6 | A.blah3: A{x: 11}
7 | calling blah3: 22
8 | B.blah3: B{x: 22}
9 | A{x: 1}
10 | B{x: 2}
11 |
--------------------------------------------------------------------------------
/tests/runtime_typing/dynamic_method_1.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 | int i
4 | }
5 |
6 | def T.f(t) -> int
7 | return t.i
8 |
9 | def call_f(any t) -> int
10 | return t.f()
11 |
12 | t = T.make(4)
13 | result = call_f(t)
14 | assert(result == 4)
15 |
--------------------------------------------------------------------------------
/tests/runtime_typing/dynamic_method_2.ca:
--------------------------------------------------------------------------------
1 |
2 | def func(any a)
3 | a.f(1 2 3)
4 |
--------------------------------------------------------------------------------
/tests/selectors/assign_syntax.ca:
--------------------------------------------------------------------------------
1 |
2 | l = [0 1 2]
3 |
4 | l[2] = 4
5 |
6 | assert(l == [0 1 4])
7 |
--------------------------------------------------------------------------------
/tests/selectors/element_type_cast.ca:
--------------------------------------------------------------------------------
1 |
2 | struct A {
3 | Vec2 p
4 | }
5 |
6 | a = A.make
7 |
8 | assert(typeof(a.p) == Vec2)
9 |
10 | a.p = [1 2]
11 |
12 | assert(typeof(a.p) == Vec2)
13 |
14 | print(a)
15 |
--------------------------------------------------------------------------------
/tests/selectors/element_type_cast.ca.output:
--------------------------------------------------------------------------------
1 | A{p: Vec2{x: 1.0, y: 2.0}}
2 |
--------------------------------------------------------------------------------
/tests/selectors/element_type_cast_error.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | struct A {
4 | int p
5 | }
6 |
7 | a = A.make
8 |
9 | a.p = 'hi'
10 |
11 | print(a)
12 |
--------------------------------------------------------------------------------
/tests/selectors/element_type_cast_error.ca.output:
--------------------------------------------------------------------------------
1 | [tests/selectors/element_type_cast_error.ca:11]
2 | [inside set_with_selector()]
3 | Error: Couldn't cast value 'hi' to type int (element :p of type A)
4 |
--------------------------------------------------------------------------------
/tests/selectors/method_assign_1.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 | int i
4 | }
5 |
6 | t = make(T)
7 |
8 | t.i = 9
9 |
10 | assert(t == [9])
11 |
--------------------------------------------------------------------------------
/tests/selectors/method_lens.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 | int i
4 | int j
5 | }
6 |
7 | def T.lens(self) -> int
8 | self[1]
9 |
10 | t = T.make(0 0)
11 |
12 | -- assert(selector_reflect(t.lens) == [1])
13 |
--------------------------------------------------------------------------------
/tests/selectors/runtime_type.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 | int i
4 | }
5 |
6 | t = make(T)
7 | t = any.cast(t)
8 |
9 | print(t)
10 |
11 | t.i = 3
12 |
13 | print(t)
14 |
--------------------------------------------------------------------------------
/tests/selectors/runtime_type.ca.output:
--------------------------------------------------------------------------------
1 | T{i: 0}
2 | T{i: 3}
3 |
--------------------------------------------------------------------------------
/tests/seq/test.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | -- concat
4 | assert(flatten(concat_seq([1] [2 3 4])) == [1 2 3 4])
5 | assert(flatten(concat_seq([1] concat_seq([2] [3 4]))) == [1 2 3 4])
6 | assert(flatten(concat_seq([1] [])) == [1])
7 | assert(flatten(concat_seq([] [])) == [])
8 | assert(flatten(concat_seq([1] [2 3 4])) == [1 2 3 4])
9 |
--------------------------------------------------------------------------------
/tests/state/bug_where_close_was_in_wrong_location.ca:
--------------------------------------------------------------------------------
1 |
2 | state hi = 1
3 |
4 | for i in [1]
5 | if i == 2
6 | @hi | add(1)
7 | break
8 |
--------------------------------------------------------------------------------
/tests/state/declared_state_explicit_call.ca.output:
--------------------------------------------------------------------------------
1 | [tests/state/declared_state_explicit_call.ca:9]
2 | [inside assert()]
3 | Error: Assert failed
4 |
--------------------------------------------------------------------------------
/tests/state/initializer_requires_cast.ca:
--------------------------------------------------------------------------------
1 |
2 | def f()
3 | state number x = 0
4 |
5 | f()
6 |
--------------------------------------------------------------------------------
/tests/state/interpreter_output.ca:
--------------------------------------------------------------------------------
1 |
2 | def b(a)
3 | state mouse_was_down = false
4 | result = false
5 |
6 | state something = 0.0
7 |
8 | a + 1
9 |
10 | int = make_vm(b)
11 | int.call(1)
12 | print(int.get_state)
13 |
--------------------------------------------------------------------------------
/tests/state/interpreter_output.ca.output:
--------------------------------------------------------------------------------
1 | {'mouse_was_down' => false, 'something' => 0.0}
2 |
--------------------------------------------------------------------------------
/tests/state/lazy.ca:
--------------------------------------------------------------------------------
1 |
2 | def lazyCall() -> int
3 | print('called lazyCall')
4 | return 0
5 |
6 | def main()
7 | print('called main')
8 | state s = lazyCall()
9 |
10 | int = make_vm(main)
11 | int.run
12 | int.run
13 | int.run
14 |
--------------------------------------------------------------------------------
/tests/state/lazy.ca.output:
--------------------------------------------------------------------------------
1 | called main
2 | called lazyCall
3 | called main
4 | called main
5 |
--------------------------------------------------------------------------------
/tests/state/list_state_synced_across_discard.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | state list = [0 1 2 3 4]
4 | for i in @list
5 | state s = i
6 |
7 | print('i = ' i ', state = ' s)
8 |
9 | if i == 1
10 | discard
11 |
12 | vm = make_vm(main)
13 | vm.run
14 | vm.run
15 |
--------------------------------------------------------------------------------
/tests/state/list_state_synced_across_discard.ca.output:
--------------------------------------------------------------------------------
1 | i = 0, state = 0
2 | i = 1, state = 1
3 | i = 2, state = 2
4 | i = 3, state = 3
5 | i = 4, state = 4
6 | i = 0, state = 0
7 | i = 2, state = 2
8 | i = 3, state = 3
9 | i = 4, state = 4
10 |
--------------------------------------------------------------------------------
/tests/state/minor_exiting_block.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | state s = 1
4 | if true
5 | s = 2
6 | return
7 |
8 | vm = make_vm(main)
9 | vm.call
10 | print(vm.get_state)
11 |
--------------------------------------------------------------------------------
/tests/state/minor_exiting_block.ca.output:
--------------------------------------------------------------------------------
1 | {'s' => 2}
2 |
--------------------------------------------------------------------------------
/tests/state/minor_exiting_block_2.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | state s = 1
4 | if true
5 | if true
6 | if true
7 | for i in [1]
8 | if false
9 | else
10 | s = 2
11 | return
12 |
13 | int = make_vm(main)
14 | int.call
15 | print(int.get_state)
16 |
--------------------------------------------------------------------------------
/tests/state/minor_exiting_block_2.ca.output:
--------------------------------------------------------------------------------
1 | {'s' => 2}
2 |
--------------------------------------------------------------------------------
/tests/state/minor_exiting_block_3.ca:
--------------------------------------------------------------------------------
1 |
2 | -- In this test, we declare 'state s' but never change its value.
3 |
4 | def main()
5 | state s = 1
6 | if true
7 | return
8 |
9 | int = make_vm(main)
10 | int.call
11 | print(int.get_state)
12 |
--------------------------------------------------------------------------------
/tests/state/minor_exiting_block_3.ca.output:
--------------------------------------------------------------------------------
1 | {'s' => 1}
2 |
--------------------------------------------------------------------------------
/tests/state/simple.ca:
--------------------------------------------------------------------------------
1 |
2 | def main(i,j)
3 | state s = 0
4 | print('existing s = ' s)
5 | s += 1
6 | print('new s = ' s)
7 |
8 | vm = make_vm(main)
9 |
10 | require stack_trace
11 | if vm.has_error
12 | stack_trace.dump(vm)
13 |
14 | --vm.precompile(main.block)
15 | vm.call
16 | vm.call
17 | vm.call
18 |
19 | --require bytecode_analysis
20 | --bytecode_analysis.dump(vm)
21 |
--------------------------------------------------------------------------------
/tests/state/simple.ca.output:
--------------------------------------------------------------------------------
1 | existing s = 0
2 | new s = 1
3 | existing s = 1
4 | new s = 2
5 | existing s = 2
6 | new s = 3
7 |
--------------------------------------------------------------------------------
/tests/state/state_arg.ca:
--------------------------------------------------------------------------------
1 |
2 | def f(int i)
3 | state a = i
4 | print('a = ' a)
5 |
6 | int = make_vm(f)
7 | int.call(4)
8 | print('s = ' int.get_state)
9 |
--------------------------------------------------------------------------------
/tests/state/state_arg.ca.output:
--------------------------------------------------------------------------------
1 | a = 4
2 | s = {'a' => 4}
3 |
--------------------------------------------------------------------------------
/tests/state/state_unique_naming.ca:
--------------------------------------------------------------------------------
1 |
2 | def f(int i)
3 | state s = i
4 |
5 | def g()
6 | a = f(1)
7 | a = f(2)
8 | a = f(3)
9 | f(4)
10 | f(5)
11 | f(6)
12 |
13 | int = make_vm(g)
14 | int.call
15 | print(int.get_state)
16 |
--------------------------------------------------------------------------------
/tests/state/state_unique_naming.ca.output:
--------------------------------------------------------------------------------
1 | {'_f' => {'s' => 4}, '_f_1' => {'s' => 5}, '_f_2' => {'s' => 6}, 'a' => {'s' => 1}, 'a_1' => {'s' => 2}, 'a_2' => {'s' => 3}}
2 |
--------------------------------------------------------------------------------
/tests/state/stateful_call_as_input.ca.output:
--------------------------------------------------------------------------------
1 | {}
2 | {'_sbool' => {'s' => 5}}
3 |
--------------------------------------------------------------------------------
/tests/state/stateful_function.ca.output:
--------------------------------------------------------------------------------
1 | {'_f' => {'s' => 3}}
2 | {'_g' => {'s' => 8}}
3 | {'_h' => {'_f' => {'s' => 14}}}
4 |
--------------------------------------------------------------------------------
/tests/state/stateful_method.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 | }
4 |
5 | def T.f(t)
6 | state int i = 0
7 |
8 | i += 1
9 |
10 | def main()
11 | t = make(T)
12 |
13 | t.f()
14 |
15 | int = make_vm(main)
16 | int.call
17 | print(int.get_state)
18 | int.call
19 | print(int.get_state)
20 | int.call
21 | print(int.get_state)
22 |
--------------------------------------------------------------------------------
/tests/state/stateful_method.ca.output:
--------------------------------------------------------------------------------
1 | {'_T.f' => {'i' => 1}}
2 | {'_T.f' => {'i' => 2}}
3 | {'_T.f' => {'i' => 3}}
4 |
--------------------------------------------------------------------------------
/tests/state/super_simple.ca:
--------------------------------------------------------------------------------
1 | state a = 1
2 |
--------------------------------------------------------------------------------
/tests/static_errors/unknown_function.ca.output:
--------------------------------------------------------------------------------
1 | Error occurred:
2 | [tests/static_errors/unknown_function.ca:2,0] unknown_function()
3 | [$503] output_placeholder() | Unknown function: nonexistant_function
4 |
5 |
--------------------------------------------------------------------------------
/tests/stats/after_each.ca:
--------------------------------------------------------------------------------
1 |
2 | def after_each(self, suffix) -> List
3 | out = []
4 | for el in self
5 | @out.append(el)
6 | @out.append(suffix)
7 | out
8 |
9 | def main()
10 | list = repeat(0 100)
11 | after_each(@list 1)
12 |
13 | vm = make_vm(main)
14 | vm.call
15 | print('large list dupes = ' vm.perf_stats.get(:stat_ListDuplicate_100Count))
16 |
--------------------------------------------------------------------------------
/tests/stats/after_each.ca.output:
--------------------------------------------------------------------------------
1 | large list dupes = 0
2 |
--------------------------------------------------------------------------------
/tests/stats/dummy_lib.ca:
--------------------------------------------------------------------------------
1 |
2 | def f()
3 | print('called dummy_lib.f')
4 |
--------------------------------------------------------------------------------
/tests/stats/field_draw_points.ca.output:
--------------------------------------------------------------------------------
1 | large list dupes = 1800
2 |
--------------------------------------------------------------------------------
/tests/stats/if_block_observability.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | long_list = repeat(0 100)
4 |
5 | if true
6 | @long_list.append(1)
7 |
8 | vm = make_vm(main)
9 | vm.call
10 | print('large list dupes = ' vm.perf_stats.get(:stat_ListDuplicate_100Count))
11 |
--------------------------------------------------------------------------------
/tests/stats/if_block_observability.ca.output:
--------------------------------------------------------------------------------
1 | large list dupes = 0
2 |
--------------------------------------------------------------------------------
/tests/stats/large_copy.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | long_list = repeat(0 100)
4 |
5 | long_list[0] = [1 long_list]
6 |
7 | vm = make_vm(main)
8 | vm.call
9 |
10 | print('large list dupes = ' vm.perf_stats.get(:stat_ListDuplicate_100Count))
11 |
--------------------------------------------------------------------------------
/tests/stats/large_copy.ca.output:
--------------------------------------------------------------------------------
1 | large list dupes = 1
2 |
--------------------------------------------------------------------------------
/tests/stats/list_modify.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | long_list = repeat(0 100)
4 |
5 |
6 | def increment(int x)
7 | x + 1
8 |
9 | @long_list.modify(50 increment)
10 |
11 | vm = make_vm(main)
12 | vm.call
13 | print('large list dupes = ' vm.perf_stats.get(:stat_ListDuplicate_100Count))
14 |
--------------------------------------------------------------------------------
/tests/stats/list_modify.ca.output:
--------------------------------------------------------------------------------
1 | large list dupes = 0
2 |
--------------------------------------------------------------------------------
/tests/stats/looped_value.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | b = make_blob(1)
4 |
5 | for i in range(0 5)
6 | @b.set_u8(0 i)
7 |
8 | b
9 |
10 | vm = make_vm(main)
11 | vm.call
12 | print('dupes = ' vm.perf_stats.get(:stat_BlobDuplicate))
13 |
--------------------------------------------------------------------------------
/tests/stats/looped_value.ca.output:
--------------------------------------------------------------------------------
1 | dupes = 0
2 |
--------------------------------------------------------------------------------
/tests/stats/module_no_dynamic_lookup.ca:
--------------------------------------------------------------------------------
1 |
2 | require ./dummy_lib
3 |
4 | _perf_stats_dump()
5 |
6 | dummy_lib.f
7 |
8 | stats = _perf_stats_dump()
9 | print('lookup count (should be 0) = ' stats.get(:stat_Interpreter_DynamicMethod_ModuleLookup))
10 |
--------------------------------------------------------------------------------
/tests/stats/module_no_dynamic_lookup.ca.output:
--------------------------------------------------------------------------------
1 | called dummy_lib.f
2 | lookup count (should be 0) = 0
3 |
--------------------------------------------------------------------------------
/tests/stats/no_unnecessary_state_calls.ca:
--------------------------------------------------------------------------------
1 |
2 | _perf_stats_dump()
3 |
4 | def func()
5 | out = []
6 | if true
7 | for i in 0..10
8 | @out.append(i)
9 | return out
10 |
11 | func()
12 |
13 | stats = _perf_stats_dump()
14 | assert(stats.get(:stat_LoadFrameState) == 0)
15 | assert(stats.get(:stat_StoreFrameState) == 0)
16 |
--------------------------------------------------------------------------------
/tests/stdlib/list_by_pairs.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | [1].by_pairs
5 |
--------------------------------------------------------------------------------
/tests/string/bug_with_default_value.ca:
--------------------------------------------------------------------------------
1 |
2 | -- this once failed
3 | assert(String.make == '')
4 |
--------------------------------------------------------------------------------
/tests/string/char_code.ca:
--------------------------------------------------------------------------------
1 |
2 | code = 'a'.char_code
3 | print('code of a = ' code)
4 |
5 | a = String.make.from_char_code(code)
6 | print('back to a = ' a)
7 |
--------------------------------------------------------------------------------
/tests/string/char_code.ca.output:
--------------------------------------------------------------------------------
1 | code of a = 97
2 | back to a = a
3 |
--------------------------------------------------------------------------------
/tests/string/index_of.ca:
--------------------------------------------------------------------------------
1 |
2 | index = "abcdef".index_of('bc')
3 |
4 | assert(index == 1)
5 |
6 | index = "abcdef".index_of('fg')
7 | assert(index == nil)
8 |
--------------------------------------------------------------------------------
/tests/subroutine/cast_output.ca:
--------------------------------------------------------------------------------
1 |
2 | def f() -> Vec2
3 | return [3 4]
4 |
5 | p = f()
6 | print(p)
7 | assert(typeof(p) == Vec2)
8 |
--------------------------------------------------------------------------------
/tests/subroutine/cast_output.ca.output:
--------------------------------------------------------------------------------
1 | Vec2{x: 3.0, y: 4.0}
2 |
--------------------------------------------------------------------------------
/tests/subroutine/implicit_return.ca:
--------------------------------------------------------------------------------
1 |
2 | def f() -> int
3 | 5
4 |
5 | assert(f() == 5)
6 |
7 | def g() -> int
8 | if true
9 | 7
10 | else
11 | 9
12 |
13 | assert(g() == 7)
14 |
15 | def h() -> List
16 | for i in [1 2 3]
17 | i + 1
18 |
19 | assert(h() == [2 3 4])
20 |
--------------------------------------------------------------------------------
/tests/subroutine/input_rebind_syntax.ca:
--------------------------------------------------------------------------------
1 |
2 | def f(@i)
3 | i += 1
4 | 3
5 |
6 | assert(f(1) == 2)
7 |
--------------------------------------------------------------------------------
/tests/subroutine/omitted_arg_type.ca.output:
--------------------------------------------------------------------------------
1 | myfunc arg1 static_type:
2 | myfunc arg1 type:
3 | myfunc arg1: sample string
4 | myfunc arg2 static_type:
5 | myfunc arg2 type:
6 | myfunc arg2: 123
7 | T.func self static_type:
8 | T.func type:
9 | T.func b static_type:
10 | T.func b:
11 |
--------------------------------------------------------------------------------
/tests/subroutine/optional_input.ca:
--------------------------------------------------------------------------------
1 |
2 | def f(i, j :optional)
3 | print('i = ' i ', j = ' j)
4 |
5 | print('f(1)')
6 | f(1)
7 |
8 | print('f(1 2)')
9 | f(1 2)
10 |
--------------------------------------------------------------------------------
/tests/subroutine/optional_input.ca.output:
--------------------------------------------------------------------------------
1 | f(1)
2 | i = 1, j = nil
3 | f(1 2)
4 | i = 1, j = 2
5 |
--------------------------------------------------------------------------------
/tests/subroutine/rebind_input.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | def my_rebinding_func(@a)
4 | a += 1
5 | 0
6 |
7 | a = 3
8 | my_rebinding_func(@a)
9 | assert(a == 4)
10 | my_rebinding_func(@a)
11 | assert(a == 5)
12 |
13 |
--------------------------------------------------------------------------------
/tests/subroutine/return_1.ca:
--------------------------------------------------------------------------------
1 |
2 | def f() -> int
3 | return 1
4 |
5 | r = f()
6 | assert(r == 1)
7 |
--------------------------------------------------------------------------------
/tests/subroutine/return_2.ca:
--------------------------------------------------------------------------------
1 |
2 | def f(bool b) -> int
3 | if b
4 | return 1
5 | else
6 | return 2
7 |
8 | f(true) | print
9 | f(false) | print
10 |
--------------------------------------------------------------------------------
/tests/subroutine/return_2.ca.output:
--------------------------------------------------------------------------------
1 | 1
2 | 2
3 |
--------------------------------------------------------------------------------
/tests/subroutine/return_3.ca:
--------------------------------------------------------------------------------
1 |
2 | def main() -> int
3 | state s
4 | s = 2
5 | return 3
6 |
7 | int = make_vm(main)
8 | int.call | print
9 | int.get_state | print
10 |
--------------------------------------------------------------------------------
/tests/subroutine/return_3.ca.output:
--------------------------------------------------------------------------------
1 | 3
2 | {'s' => 2}
3 |
--------------------------------------------------------------------------------
/tests/subroutine/return_4.ca:
--------------------------------------------------------------------------------
1 |
2 | def main() -> int
3 | state s
4 | s = 2
5 | if true
6 | s = 3
7 | return 8
8 |
9 | int = make_vm(main)
10 | int.call | print
11 | int.get_state | print
12 |
--------------------------------------------------------------------------------
/tests/subroutine/return_4.ca.output:
--------------------------------------------------------------------------------
1 | 8
2 | {'s' => 3}
3 |
--------------------------------------------------------------------------------
/tests/subroutine/subroutine.ca.output:
--------------------------------------------------------------------------------
1 | called sub1
2 | should be 3: 3
3 | should be 6: 6
4 | with args
5 | with args2
6 |
--------------------------------------------------------------------------------
/tests/subroutine/subroutine_state.ca.output:
--------------------------------------------------------------------------------
1 | should be 1: 1
2 | should be {s: 1}: {'s' => 1}
3 | should be 2: 2
4 | should be {s: 2}: {'s' => 2}
5 | should be 3: 3
6 | should be {s: 3}: {'s' => 3}
7 |
--------------------------------------------------------------------------------
/tests/subroutine/subroutine_state_1.ca:
--------------------------------------------------------------------------------
1 | def f() -> int
2 | state s = 0
3 | s += 1
4 | return s
5 |
6 | int = make_vm(f)
7 | int.call
8 | result = int.call
9 | print('should be 2: ' result)
10 | result = int.call
11 | print('should be 3: ' result)
12 | result = int.call
13 | print('should be 4: ' result)
14 |
--------------------------------------------------------------------------------
/tests/subroutine/subroutine_state_1.ca.output:
--------------------------------------------------------------------------------
1 | should be 2: 2
2 | should be 3: 3
3 | should be 4: 4
4 |
--------------------------------------------------------------------------------
/tests/subroutine/subroutine_state_2.ca.output:
--------------------------------------------------------------------------------
1 | should be 6: 6
2 | should be 9: 9
3 | should be 5: 5
4 | should be 6: 6
5 |
--------------------------------------------------------------------------------
/tests/switch/local_rebind_simple.ca:
--------------------------------------------------------------------------------
1 |
2 | a = 'outer'
3 |
4 | switch 1
5 | case 1
6 | a = 'inner'
7 |
8 | print(a)
9 |
--------------------------------------------------------------------------------
/tests/switch/local_rebind_simple.ca.output:
--------------------------------------------------------------------------------
1 | inner
2 |
--------------------------------------------------------------------------------
/tests/switch/output_value.ca:
--------------------------------------------------------------------------------
1 |
2 | y = switch
3 | case true
4 | 'pass'
5 | case false
6 | 'fail'
7 |
8 | assert(y == 'pass')
9 |
--------------------------------------------------------------------------------
/tests/switch/simple.ca:
--------------------------------------------------------------------------------
1 |
2 | switch
3 | case false
4 | print("fail")
5 | case true
6 | print("pass")
7 |
--------------------------------------------------------------------------------
/tests/switch/simple.ca.output:
--------------------------------------------------------------------------------
1 | pass
2 |
--------------------------------------------------------------------------------
/tests/switch/simple2.ca:
--------------------------------------------------------------------------------
1 |
2 | switch
3 | case true
4 | print("pass")
5 | case false
6 | print("fail")
7 |
--------------------------------------------------------------------------------
/tests/switch/simple2.ca.output:
--------------------------------------------------------------------------------
1 | pass
2 |
--------------------------------------------------------------------------------
/tests/switch/unindented_case.ca.disable:
--------------------------------------------------------------------------------
1 |
2 | switch 2
3 | case 1
4 | print("it's 1")
5 | case 2
6 | print("it's 2")
7 |
--------------------------------------------------------------------------------
/tests/switch/with_input.ca:
--------------------------------------------------------------------------------
1 |
2 | x = 1
3 |
4 | switch x
5 | case 1
6 | print("pass")
7 | case 2
8 | print("fail")
9 |
--------------------------------------------------------------------------------
/tests/switch/with_input.ca.output:
--------------------------------------------------------------------------------
1 | pass
2 |
--------------------------------------------------------------------------------
/tests/switch/with_input2.ca:
--------------------------------------------------------------------------------
1 |
2 | x = 2
3 |
4 | switch x
5 | case 1
6 | print("fail")
7 | case 2
8 | print("pass")
9 |
--------------------------------------------------------------------------------
/tests/switch/with_input2.ca.output:
--------------------------------------------------------------------------------
1 | pass
2 |
--------------------------------------------------------------------------------
/tests/symbols/simple.ca:
--------------------------------------------------------------------------------
1 |
2 | assert(:a == :a)
3 | assert(:a != :b)
4 |
5 | def test(any a, Symbol b)
6 | return a == b
7 |
8 | assert(test(:a, :a))
9 |
10 |
11 |
--------------------------------------------------------------------------------
/tests/syntax/bar_apply.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | def increment(int i)
4 | i + 1
5 |
6 | 'should be 5: ' | print
7 | 3 | increment | increment | print
8 |
9 | 'should be 4: ' | print
10 |
11 | 1 + 3 | print
12 |
--------------------------------------------------------------------------------
/tests/syntax/bar_apply.ca.output:
--------------------------------------------------------------------------------
1 | should be 5:
2 | 5
3 | should be 4:
4 | 4
5 |
--------------------------------------------------------------------------------
/tests/syntax/bar_apply_method.ca:
--------------------------------------------------------------------------------
1 |
2 | x = []
3 |
4 | x | .append(1) | print
5 |
6 | x = [1 2 3]
7 |
8 | x | .length | print
9 |
10 |
11 | x = [4 5 6]
12 |
13 | @x | .pop
14 |
15 | x | print
16 |
--------------------------------------------------------------------------------
/tests/syntax/bar_apply_method.ca.output:
--------------------------------------------------------------------------------
1 | [1]
2 | 3
3 | [4, 5]
4 |
--------------------------------------------------------------------------------
/tests/syntax/closure.ca.disable:
--------------------------------------------------------------------------------
1 |
2 | outside_value = 2
3 |
4 | def my_closure(number i) -> number
5 | return i * outside_value
6 | end
7 |
8 | print(map(my_closure, [1 2 3]))
9 |
10 | def my_func() -> List
11 | def my_inner_closure(number i) -> number
12 | return i + outside_value
13 | end
14 |
15 | return map(my_inner_closure, [5 6 7])
16 | end
17 |
18 | print(my_func())
19 |
--------------------------------------------------------------------------------
/tests/syntax/compound_type.ca.output:
--------------------------------------------------------------------------------
1 | Composite{myClass: MyClass{a: 0, b: 0, name: '', distance: 0.0}, myClass2: MyClass{a: 0, b: 0, name: '', distance: 0.0}, name: ''}
2 | Vector{x: 5.0, y: 6.0}
3 | v.x = 5.0
4 | v.y = 6.0
5 |
--------------------------------------------------------------------------------
/tests/syntax/for.ca.output:
--------------------------------------------------------------------------------
1 | 0
2 | 1
3 | 2
4 | 3
5 | 4
6 | absalom
7 | bouffant
8 | chilton
9 | should be 16.0: 16.0
10 | if passed
11 | if2 passed
12 | inside function passed
13 |
--------------------------------------------------------------------------------
/tests/syntax/for_rebind.ca:
--------------------------------------------------------------------------------
1 |
2 | L = [1 2 3]
3 |
4 | for i in @L
5 | i += 1
6 |
7 | print(L)
8 |
--------------------------------------------------------------------------------
/tests/syntax/for_rebind.ca.output:
--------------------------------------------------------------------------------
1 | [2, 3, 4]
2 |
--------------------------------------------------------------------------------
/tests/syntax/for_rebind_complex.ca:
--------------------------------------------------------------------------------
1 |
2 | struct S {
3 | List t
4 | }
5 |
6 | s = make(S)
7 | s.t = [1 2 3]
8 |
9 | for i in @s.t
10 | i += 1
11 |
12 | print(s.t)
13 |
--------------------------------------------------------------------------------
/tests/syntax/for_rebind_complex.ca.output:
--------------------------------------------------------------------------------
1 | [2, 3, 4]
2 |
--------------------------------------------------------------------------------
/tests/syntax/if.ca:
--------------------------------------------------------------------------------
1 |
2 | a = 0
3 | if true
4 | a = 1
5 | assert(a == 1)
6 |
7 | if false
8 | assert(false)
9 |
10 | if (1.0 + 2.0) < 1.0
11 | assert(false)
12 |
13 | -- Conditional execution with else
14 | if true
15 | a = 2
16 | else
17 | assert(false)
18 |
19 | if false
20 | assert(false)
21 | else
22 | a = 3
23 |
--------------------------------------------------------------------------------
/tests/syntax/if_indenting_1.ca:
--------------------------------------------------------------------------------
1 |
2 | a = if false
3 | 1
4 | else
5 | 2
6 |
7 | assert(a == 2)
8 |
--------------------------------------------------------------------------------
/tests/syntax/if_indenting_2.ca:
--------------------------------------------------------------------------------
1 |
2 | a = if false
3 | 1
4 | else
5 | 2
6 |
7 | assert(a == 2)
8 |
--------------------------------------------------------------------------------
/tests/syntax/if_indenting_3.ca:
--------------------------------------------------------------------------------
1 |
2 | a = 1
3 |
4 | if false
5 | a = 2
6 | else
7 | a = 3
8 |
9 | assert(a == 3)
10 |
--------------------------------------------------------------------------------
/tests/syntax/if_indenting_4.ca:
--------------------------------------------------------------------------------
1 |
2 | a = 1
3 | if true
4 | if false
5 | a = 2
6 | else
7 | a = 3
8 | else
9 | a = 4
10 |
11 | assert(a == 3)
12 |
--------------------------------------------------------------------------------
/tests/syntax/infix.ca:
--------------------------------------------------------------------------------
1 |
2 | (1.0 + 4.0) | print
3 | (5.0 - 2.0) | print
4 | (2.0*3.0) | print
5 | (5.0/2.5) | print
6 | (5 > 3) | print
7 | (3 == 2) | print
8 |
--------------------------------------------------------------------------------
/tests/syntax/infix.ca.output:
--------------------------------------------------------------------------------
1 | 5.0
2 | 3.0
3 | 6.0
4 | 2.0
5 | true
6 | false
7 |
--------------------------------------------------------------------------------
/tests/syntax/infix_multiline.ca:
--------------------------------------------------------------------------------
1 |
2 | a = (1
3 | + 2)
4 |
5 | assert(a == 3)
6 |
7 | a = (1 +
8 | 3)
9 |
10 | assert(a == 4)
11 |
12 | a = 2 +
13 | 3
14 |
15 | assert(a == 5)
16 |
--------------------------------------------------------------------------------
/tests/syntax/left_arrow.ca.output:
--------------------------------------------------------------------------------
1 | f: 1
2 | f: 1
3 | f: 1
4 | f: {block: Block#600, bindings: []}
5 |
--------------------------------------------------------------------------------
/tests/syntax/lists.ca:
--------------------------------------------------------------------------------
1 |
2 | l = [1,2]
3 |
4 | print(l | str)
5 | print(l.count() | str)
6 | print(l | str)
7 |
8 | @l.append(3)
9 |
10 | print(l | str)
11 | print(l.count() | str)
12 |
13 | [1,2,3] | str | print
14 |
15 | -- omitting commas
16 | l = [1 2 3]
17 | l | str | print
18 |
--------------------------------------------------------------------------------
/tests/syntax/lists.ca.output:
--------------------------------------------------------------------------------
1 | [1, 2]
2 | 2
3 | [1, 2]
4 | [1, 2, 3]
5 | 3
6 | [1, 2, 3]
7 | [1, 2, 3]
8 |
--------------------------------------------------------------------------------
/tests/syntax/literal_map.ca:
--------------------------------------------------------------------------------
1 |
2 | print('empty map = ' {})
3 |
4 | print('1 => 2 : ' {1 => 2})
5 | print('apple => banana : ' {'apple' => 'banana'})
6 | print('1 + 2 => 3 + 4 : ' {1 + 2 => 3 + 4})
7 | print('1=>2, 3=>4, 5=>6 : ' {1 => 2, 3 => 4, 5 => 6})
8 |
9 | {'on left side' => 'of pipe'} | print
10 |
11 | {1 => 'with dot syntax'}.get(1) | print
12 |
--------------------------------------------------------------------------------
/tests/syntax/literal_map.ca.output:
--------------------------------------------------------------------------------
1 | empty map = {}
2 | 1 => 2 : {1 => 2}
3 | apple => banana : {'apple' => 'banana'}
4 | 1 + 2 => 3 + 4 : {3 => 7}
5 | 1=>2, 3=>4, 5=>6 : {1 => 2, 3 => 4, 5 => 6}
6 | {'on left side' => 'of pipe'}
7 | with dot syntax
8 |
--------------------------------------------------------------------------------
/tests/syntax/literal_map_whitespace.ca:
--------------------------------------------------------------------------------
1 |
2 | {}
3 | { }
4 | {1 => 2}
5 | {1 => 2}
6 | { 1 => 2}
7 | {1 => 2}
8 | {1 => 2}
9 | {1 => 2, 3 => 4}
10 | {1 => 2, 3 => 4}
11 | {1 => 2, 3 => 4}
12 | {1 => 2, 3 => 4 }
13 | {1 => 2, 3 => 4 }
14 |
--------------------------------------------------------------------------------
/tests/syntax/local_typedef.ca:
--------------------------------------------------------------------------------
1 |
2 | def f() -> List
3 | struct A {
4 | int x
5 | int y
6 | }
7 |
8 | a = make(A)
9 | a.x = 3
10 | a.y = 4
11 | assert(to_string(a) == '{x: 3, y: 4}')
12 |
13 | return a
14 |
15 | b = f()
16 | assert(to_string(b) == '[3, 4]')
17 |
--------------------------------------------------------------------------------
/tests/syntax/math.ca.output:
--------------------------------------------------------------------------------
1 | one plus two is 3
2 | 5.5 plus 2.2 is 7.7
3 | two minus one is 1
4 | one minus two is -1
5 | two times three is 6
6 | nine divided by four is 2.25
7 | nine integer-divided by four is 2
8 | 1 + 2 * 3 = 7
9 | 1 * 2 + 3 = 5
10 | 5 - 4 + 3 = 4
11 | 1 - 2 * 3 = -5
12 | 1 + 4 / 2 = 3.0
13 | 1 - 4 / 2 = -1.0
14 |
--------------------------------------------------------------------------------
/tests/syntax/method_rebinding.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 | int i
4 | }
5 |
6 | def T.add(@t, int i)
7 | t.i += i
8 |
9 | t = make(T)
10 | print(t)
11 | @t.add(3)
12 | print(t)
13 |
--------------------------------------------------------------------------------
/tests/syntax/method_rebinding.ca.output:
--------------------------------------------------------------------------------
1 | T{i: 0}
2 | T{i: 3}
3 |
--------------------------------------------------------------------------------
/tests/syntax/multiline_comment.ca.output:
--------------------------------------------------------------------------------
1 | check 1
2 | check 2
3 | check 3
4 | check 4
5 |
--------------------------------------------------------------------------------
/tests/syntax/not.ca.output:
--------------------------------------------------------------------------------
1 | not true = false
2 | not false = true
3 | not true or true = true
4 | not true or false = false
5 | not true and false = false
6 | true and not false = true
7 | not true or not true or not false = true
8 | not (true or false) or not (false) = true
9 | not (1 == 3) = true
10 |
--------------------------------------------------------------------------------
/tests/syntax/return_multi.ca:
--------------------------------------------------------------------------------
1 |
2 | def f() -> (int, int)
3 | return 1, 2
4 |
--------------------------------------------------------------------------------
/tests/syntax/subroutine.ca:
--------------------------------------------------------------------------------
1 |
2 | def print_success(number n)
3 | print("Called print_success")
4 |
5 | print_success(0.0)
6 |
7 | def square(number a) -> number
8 | return mult(a,a)
9 |
10 | print("Four squared is ", square(4.0))
11 |
12 | five_squared = square(5.0)
13 |
14 | print("Five squared is ", five_squared)
15 |
--------------------------------------------------------------------------------
/tests/syntax/subroutine.ca.output:
--------------------------------------------------------------------------------
1 | Called print_success
2 | Four squared is 16.0
3 | Five squared is 25.0
4 |
--------------------------------------------------------------------------------
/tests/syntax/subroutine_semicolon.ca:
--------------------------------------------------------------------------------
1 |
2 | -- Make sure that a semicolon after a function defn will start a new statement.
3 |
4 | def func();a = 1 + 2
5 |
6 | assert(a == 3)
7 |
8 | def func()->int;a = 3 + 4
9 |
10 | assert(a == 7)
11 |
--------------------------------------------------------------------------------
/tests/syntax/trailing_dot_method.ca:
--------------------------------------------------------------------------------
1 |
2 | def f()
3 | list = []
4 | .append(1)
5 | .append(2)
6 |
7 | assert(f() == [1 2])
8 |
--------------------------------------------------------------------------------
/tests/syntax/trailing_dot_method_bad_indent.ca:
--------------------------------------------------------------------------------
1 |
2 | def int.increment(i)
3 | i + 1
4 |
5 | def f()
6 | a = 1
7 | .increment
8 | .increment
9 |
10 | assert(f() == 3)
11 |
--------------------------------------------------------------------------------
/tests/syntax/trailing_dot_method_bad_indent.ca.output:
--------------------------------------------------------------------------------
1 | [tests/syntax/trailing_dot_method_bad_indent.ca:10]
2 | Error: Syntax error: Unrecognized start of expression (next token = '.')
3 |
--------------------------------------------------------------------------------
/tests/syntax/type_decl.ca:
--------------------------------------------------------------------------------
1 |
2 | struct Vec2 { number x, number y }
3 | -- a comment
4 |
5 | struct Vector3 { number x, number y, number z }
6 |
7 | -- another comment
8 |
--------------------------------------------------------------------------------
/tests/syntax/type_decl_2.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 |
4 | -- this is a comment
5 | int a
6 |
7 | int b -- this is another comment
8 | }
9 |
10 | t = make(T)
11 | print(t)
12 |
--------------------------------------------------------------------------------
/tests/syntax/type_decl_2.ca.output:
--------------------------------------------------------------------------------
1 | T{a: 0, b: 0}
2 |
--------------------------------------------------------------------------------
/tests/table/apply.ca:
--------------------------------------------------------------------------------
1 |
2 | m = make(Table)
3 | @m.set('a' 1)
4 | @m.set('b' 2)
5 |
6 | assert(str(m) == "{'a' => 1, 'b' => 2}")
7 |
8 | @m.apply('a', (el) -> el + 5 )
9 |
10 | assert(str(m) == "{'a' => 6, 'b' => 2}")
11 |
--------------------------------------------------------------------------------
/tests/table/empty.ca:
--------------------------------------------------------------------------------
1 |
2 | m = make(Table)
3 | assert(m.empty)
4 | @m.set(1,2)
5 | assert(not m.empty)
6 | @m.remove(1)
7 | assert(m.empty)
8 |
--------------------------------------------------------------------------------
/tests/table/hashable_keys.ca:
--------------------------------------------------------------------------------
1 |
2 | m = Table.make
3 |
4 | @m.set(#f00, "Color is hashable")
5 | print(m.get(#f00))
6 |
--------------------------------------------------------------------------------
/tests/table/hashable_keys.ca.output:
--------------------------------------------------------------------------------
1 | Color is hashable
2 |
--------------------------------------------------------------------------------
/tests/table/implicit_get_and_call.ca:
--------------------------------------------------------------------------------
1 |
2 | obj = {f: (i) ->
3 | print('called f with: ' i)
4 | return i * 2
5 | }
6 |
7 | print('obj.f(3) = ' obj.f(3))
8 |
--------------------------------------------------------------------------------
/tests/table/implicit_get_and_call.ca.output:
--------------------------------------------------------------------------------
1 | called f with: 3
2 | obj.f(3) = 6
3 |
--------------------------------------------------------------------------------
/tests/table/list_append.ca:
--------------------------------------------------------------------------------
1 |
2 | m = Table.make
3 |
4 | @m.list_append(:a 1)
5 | print(m)
6 |
7 | @m.list_append(:a 2)
8 | print(m)
9 |
10 | @m.list_append(:a 3)
11 | print(m)
12 |
--------------------------------------------------------------------------------
/tests/table/list_append.ca.output:
--------------------------------------------------------------------------------
1 | {:a => [1]}
2 | {:a => [1, 2]}
3 | {:a => [1, 2, 3]}
4 |
--------------------------------------------------------------------------------
/tests/table/make_table.ca:
--------------------------------------------------------------------------------
1 |
2 | print('with numbers: ' make_table(1, 2, 3, 4))
3 |
4 | print('with symbols: ' make_table(:fruit 'apple' :vegetable 'broccoli'))
5 |
6 | print('empty: ' make_table())
7 |
--------------------------------------------------------------------------------
/tests/table/make_table.ca.output:
--------------------------------------------------------------------------------
1 | with numbers: {1 => 2, 3 => 4}
2 | with symbols: {:vegetable => 'broccoli', :fruit => 'apple'}
3 | empty: {}
4 |
--------------------------------------------------------------------------------
/tests/table/many_inserts.ca:
--------------------------------------------------------------------------------
1 |
2 | table = make(Table)
3 |
4 | @table.set('a', 1)
5 | @table.set('b', 2)
6 | @table.set('c', 2)
7 | @table.set('d', 2)
8 | @table.set('e', 2)
9 | @table.set('f', 2)
10 | @table.set(:a, 2)
11 | @table.set(:b, 2)
12 | @table.set(:c, 2)
13 | @table.set(1, 2)
14 | @table.set(2, 2)
15 | @table.set(10, 2)
16 | @table.set(11, 2)
17 |
18 | print(table)
19 |
--------------------------------------------------------------------------------
/tests/table/many_inserts.ca.output:
--------------------------------------------------------------------------------
1 | {1 => 2, 2 => 2, 10 => 2, 11 => 2, 'a' => 1, 'b' => 2, 'c' => 2, 'd' => 2, 'e' => 2, 'f' => 2, :c => 2, :b => 2, :a => 2}
2 |
--------------------------------------------------------------------------------
/tests/table/method_syntax.ca:
--------------------------------------------------------------------------------
1 |
2 | m = Table.make.set(:one, 1).set(:two 2)
3 |
4 | assert(m.one == 1)
5 | assert(m.two == 2)
6 |
7 | def error_test()
8 | m = Table.make
9 | m.three
10 |
11 | vm = error_test.to_vm
12 | vm.call
13 | vm.errored -> assert
14 |
--------------------------------------------------------------------------------
/tests/table/modify.ca:
--------------------------------------------------------------------------------
1 |
2 | m = Table.make
3 |
4 | @m.set(:a 1)
5 | print(m)
6 |
7 | @m.modify(:a, (el) -> el + 1)
8 | print(m)
9 |
10 | @m.modify(:a, (el) -> el + 1)
11 | print(m)
12 |
13 | @m.modify(:a, (el) -> el + 1)
14 | print(m)
15 |
--------------------------------------------------------------------------------
/tests/table/modify.ca.output:
--------------------------------------------------------------------------------
1 | {:a => 1}
2 | {:a => 2}
3 | {:a => 3}
4 | {:a => 4}
5 |
--------------------------------------------------------------------------------
/tests/table/remove_nonexistant.ca:
--------------------------------------------------------------------------------
1 |
2 | m = Table.make
3 |
4 | -- Remove from empty table
5 | m.remove(:a)
6 | print(m)
7 |
8 | -- Remove from nonempty table
9 | @m.set(:b 1)
10 | m.remove(:a)
11 |
12 | print(m)
13 |
--------------------------------------------------------------------------------
/tests/table/remove_nonexistant.ca.output:
--------------------------------------------------------------------------------
1 | {}
2 | {:b => 1}
3 |
--------------------------------------------------------------------------------
/tests/table/shorthand_syntax.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | print({x: 1})
4 | print({x: 1, y: 2})
5 | print({x: 1, y: 2, :z => 3})
6 |
--------------------------------------------------------------------------------
/tests/table/shorthand_syntax.ca.output:
--------------------------------------------------------------------------------
1 | {:x => 1}
2 | {:y => 2, :x => 1}
3 | {:z => 3, :y => 2, :x => 1}
4 |
--------------------------------------------------------------------------------
/tests/table/simple.ca.output:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andyfischer/circa/39d6473b44bb1f7598703d3f6aed3b4c9942aa27/tests/table/simple.ca.output
--------------------------------------------------------------------------------
/tests/type/interface/override_and_fallthrough.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 | }
4 |
5 | def T.a(self)
6 | 'T.a'
7 |
8 | def T.b(self)
9 | str('T.b calling T.a: ' self.a)
10 |
11 | struct Interface = :interface
12 |
13 | def Interface.a(self)
14 | 'Interface.a'
15 |
16 | def my_func(Interface val)
17 | print('Calling Interface.a: ' val.a)
18 | print('Calling Interface.b: ' val.b)
19 |
20 | my_func(T.make)
21 |
--------------------------------------------------------------------------------
/tests/type/interface/override_and_fallthrough.ca.output:
--------------------------------------------------------------------------------
1 | Calling Interface.a: Interface.a
2 | Calling Interface.b: T.b calling T.a: T.a
3 |
--------------------------------------------------------------------------------
/tests/type/interface/simple.ca:
--------------------------------------------------------------------------------
1 |
2 | struct A = :interface
3 |
4 | def A.f(self) -> String
5 | 'A.f called'
6 |
7 | def use_a(A a)
8 | print(a.f)
9 |
10 | use_a(1)
11 |
--------------------------------------------------------------------------------
/tests/type/interface/simple.ca.output:
--------------------------------------------------------------------------------
1 | A.f called
2 |
--------------------------------------------------------------------------------
/tests/type/make_1.ca:
--------------------------------------------------------------------------------
1 |
2 | -- Don't error if the type is not list-based.
3 | assert(int.make == 0)
4 |
--------------------------------------------------------------------------------
/tests/type/make_no_unnecessary_init.ca.disable:
--------------------------------------------------------------------------------
1 |
2 | struct T = :handle
3 | def T.release()
4 | print('Called T.release')
5 |
6 | struct U {
7 | T t
8 | }
9 |
10 | t = T.make
11 |
12 | print("Calling U.make(t). This shouldn't trigger T.release")
13 |
14 | u = U.make(t)
15 |
16 | print('finished calling U.make')
17 |
--------------------------------------------------------------------------------
/tests/type/make_no_unnecessary_init.ca.output:
--------------------------------------------------------------------------------
1 | Calling U.make(t). This shouldn't trigger T.release
2 | finished calling U.make
3 | Called T.release
4 |
--------------------------------------------------------------------------------
/tests/type_inferrence/assign.ca:
--------------------------------------------------------------------------------
1 |
2 | struct CompoundType {
3 | int i
4 | }
5 |
6 | t = make(CompoundType)
7 | assert(typeof(t) == CompoundType)
8 | t.i = 1
9 | assert(typeof(t) == CompoundType)
10 |
--------------------------------------------------------------------------------
/tests/type_inferrence/bug_with_list_based_type.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 | int a
4 | }
5 |
6 | def f()
7 | if false
8 | return []
9 |
10 | T.make(1)
11 |
12 | print('f() = ' f())
13 | print('output type = ' f.block.output_placeholder(0).get_type)
14 |
--------------------------------------------------------------------------------
/tests/type_inferrence/bug_with_list_based_type.ca.output:
--------------------------------------------------------------------------------
1 | f() = T{a: 1}
2 | output type =
3 |
--------------------------------------------------------------------------------
/tests/type_inferrence/implicit_type_considers_return1.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {}
3 |
4 | def f(bool b)
5 | if b
6 | return T.make
7 |
8 | T.make
9 |
10 | result = f(true)
11 |
12 | assert(static_type(result) == T)
13 | assert(typeof(result) == T)
14 |
--------------------------------------------------------------------------------
/tests/type_inferrence/implicit_type_considers_return2.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {}
3 |
4 | struct U {}
5 |
6 | def f(bool b)
7 | if b
8 | return U.make
9 |
10 | T.make
11 |
12 | result = f(true)
13 |
14 | assert(static_type(result) != T)
15 | assert(typeof(result) == U)
16 |
--------------------------------------------------------------------------------
/tests/type_inferrence/implicit_type_considers_return3.ca:
--------------------------------------------------------------------------------
1 |
2 | def f(bool b)
3 | if b
4 | return [1 0]
5 |
6 | Vec2.make
7 |
8 | result = f(true)
9 |
10 | assert(static_type(result) == any)
11 |
--------------------------------------------------------------------------------
/tests/type_inferrence/method.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T
3 | {
4 | int i
5 | }
6 |
7 | def T.f(self) {
8 | self.i += 1
9 | }
10 |
11 | t = make(T)
12 | assert(typeof(t) == T)
13 | t.f()
14 | assert(typeof(t) == T)
15 |
--------------------------------------------------------------------------------
/tests/type_inferrence/overloaded_func.ca:
--------------------------------------------------------------------------------
1 |
2 | assert(static_type(1.0 + 2.0) == number)
3 |
--------------------------------------------------------------------------------
/tests/types/color_values.ca:
--------------------------------------------------------------------------------
1 |
2 | red = #f00
3 |
4 | assert(red == #f00)
5 | assert(red == #f00f)
6 | assert(red != #00f)
7 |
8 | c = #888
9 | print("c = " c)
10 | print("c.r = " c.r)
11 | c.r = 1.0
12 | print("c = " c)
13 |
14 | green = #00ff00
15 | half_blue = #0000ff88
16 | half_red = #f008
17 |
--------------------------------------------------------------------------------
/tests/types/color_values.ca.output:
--------------------------------------------------------------------------------
1 | c = Color{r: 0.533333, g: 0.533333, b: 0.533333, a: 1.0}
2 | c.r = 0.533333
3 | c = Color{r: 1.0, g: 0.533333, b: 0.533333, a: 1.0}
4 |
--------------------------------------------------------------------------------
/tests/types/dict.ca.output:
--------------------------------------------------------------------------------
1 | d = {}
2 | d.count = 0
3 | d = {a: 1}
4 | d.count = 1
5 | d = {a: 1, b: 2}
6 | d.count = 2
7 | d = {a: 1, b: 3}
8 | d.count = 2
9 | d[a] = 1
10 | d[b] = 3
11 |
--------------------------------------------------------------------------------
/tests/types/rect.ca:
--------------------------------------------------------------------------------
1 |
2 | r = Rect.make(0 2 8 10)
3 |
4 | assert(r.top_left == [0 2])
5 | assert(r.top_right == [8 2])
6 | assert(r.bottom_left == [0 10])
7 | assert(r.bottom_right == [8 10])
8 |
9 | assert(r.center == [4 6])
10 |
--------------------------------------------------------------------------------
/tests/types/semicolon_syntax.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T;
3 |
4 | struct U {}
5 |
6 | struct V {};
7 |
--------------------------------------------------------------------------------
/tests/types/setters.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 | int a
4 | String b
5 | }
6 |
7 | t = T.make(1, 'x')
8 | assert(str(t) == "T{a: 1, b: 'x'}")
9 |
10 | @t.set_a(4)
11 | assert(str(t) == "T{a: 4, b: 'x'}")
12 |
13 | @t.set_a(5).set_b('y')
14 | assert(str(t) == "T{a: 5, b: 'y'}")
15 |
16 | def error_test(t)
17 | t.set_a('hi')
18 |
19 | vm = make_vm(error_test)
20 | vm.call(t)
21 | assert(vm.errored)
22 |
--------------------------------------------------------------------------------
/tests/types/setters.ca.output:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andyfischer/circa/39d6473b44bb1f7598703d3f6aed3b4c9942aa27/tests/types/setters.ca.output
--------------------------------------------------------------------------------
/tests/types/super_special_handle_type_syntax.ca.disable:
--------------------------------------------------------------------------------
1 |
2 | struct T = :handle
3 |
--------------------------------------------------------------------------------
/tests/types/typeof_func.ca:
--------------------------------------------------------------------------------
1 | assert(typeof(1) == int)
2 | assert(typeof(1.0) == number)
3 | assert(typeof('s') == String)
4 |
5 | def runtime_typing(int i) -> any
6 | if i == 0
7 | return 1
8 | elif i == 1
9 | return 1.0
10 | else
11 | return "hi"
12 |
13 | assert(typeof(runtime_typing(0)) == int)
14 | assert(typeof(runtime_typing(1)) == number)
15 | assert(typeof(runtime_typing(2)) == String)
16 |
--------------------------------------------------------------------------------
/tests/varargs/empty.ca:
--------------------------------------------------------------------------------
1 |
2 | def f1(any args :multiple)
3 | print('f1 args = ' args)
4 |
5 | f1()
6 |
7 | def f2(int firstArg, any args :multiple)
8 | print('f2 firstArg = ' firstArg)
9 | print('f2 args = ' args)
10 |
11 | f2(5)
12 |
--------------------------------------------------------------------------------
/tests/varargs/empty.ca.output:
--------------------------------------------------------------------------------
1 | f1 args = []
2 | f2 firstArg = 5
3 | f2 args = []
4 |
--------------------------------------------------------------------------------
/tests/varargs/mixed.ca:
--------------------------------------------------------------------------------
1 |
2 | def f(int a, int b, c :multiple)
3 | print('a = ' a)
4 | print('b = ' b)
5 | print('c = ' c)
6 |
7 |
8 | f(1 2 3 4 5 6)
9 |
--------------------------------------------------------------------------------
/tests/varargs/mixed.ca.output:
--------------------------------------------------------------------------------
1 | a = 1
2 | b = 2
3 | c = [3, 4, 5, 6]
4 |
--------------------------------------------------------------------------------
/tests/varargs/regular.ca:
--------------------------------------------------------------------------------
1 |
2 | def f(any args :multiple)
3 | print('args = ' args)
4 |
5 | f(1 2 3)
6 |
--------------------------------------------------------------------------------
/tests/varargs/regular.ca.output:
--------------------------------------------------------------------------------
1 | args = [1, 2, 3]
2 |
--------------------------------------------------------------------------------
/tests/vectorized_func.ca.output:
--------------------------------------------------------------------------------
1 | should be []: []
2 | should be [1]: [1]
3 | should be [3 4 5]: [3, 4, 5]
4 | should be []: []
5 | should be [3]: [3]
6 | should be [2 4 6]: [2, 4, 6]
7 | should be [4 8 16 0]: [4, 8, 16, 0]
8 | should be [1.0, 2.0]: [1.0, 2.0]
9 |
--------------------------------------------------------------------------------
/tests/vm/append_hack.ca:
--------------------------------------------------------------------------------
1 |
2 | vm = make_vm(->)
3 |
4 | print(vm.env_map)
5 |
6 | vm.append_hack(:thing1)
7 |
8 | print(vm.env_map)
9 |
10 | vm.append_hack(:thing2)
11 |
12 | print(vm.env_map)
13 |
14 | vm.modify_env((env) -> env.remove(:_hacks))
15 |
16 | print(vm.env_map)
17 |
--------------------------------------------------------------------------------
/tests/vm/append_hack.ca.output:
--------------------------------------------------------------------------------
1 | {}
2 | {:hacks => [:thing1]}
3 | {:hacks => [:thing1, :thing2]}
4 | {:hacks => [:thing1, :thing2]}
5 |
--------------------------------------------------------------------------------
/tests/vm/capture_stack.ca.output:
--------------------------------------------------------------------------------
1 | Finished calling f, one = 1
2 | Finished calling f, one = two
3 |
--------------------------------------------------------------------------------
/tests/vm/deep_stack.ca:
--------------------------------------------------------------------------------
1 |
2 | def main(int i)
3 | 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1
4 |
5 | if i == 0
6 | return 0
7 |
8 | return i + main(i - 1)
9 |
10 | vm = make_vm(main)
11 | vm.call(1000) | print
12 |
--------------------------------------------------------------------------------
/tests/vm/deep_stack.ca.output:
--------------------------------------------------------------------------------
1 | 500500
2 |
--------------------------------------------------------------------------------
/tests/vm/eval_term_on_demand.ca.output:
--------------------------------------------------------------------------------
1 | about to call _eval_on_demand..
2 | calling demand_func
3 | result = 5
4 |
--------------------------------------------------------------------------------
/tests/vm/fib.ca:
--------------------------------------------------------------------------------
1 |
2 | def fib(int i) -> int
3 | if i == 0 or i == 1
4 | return 1
5 |
6 | fib(i - 2) + fib(i - 1)
7 |
8 | fib(20) | print
9 |
--------------------------------------------------------------------------------
/tests/vm/fib.ca.output:
--------------------------------------------------------------------------------
1 | 10946
2 |
--------------------------------------------------------------------------------
/tests/vm/find_active_frame.ca.disabled:
--------------------------------------------------------------------------------
1 |
2 |
3 | top_level_binding = 1
4 |
5 | def func2()
6 | stack = capture_stack()
7 |
8 | frame = stack.find_active_frame_for_term(term_ref(top_level_binding))
9 | assert(frame != null)
10 | assert(stack.top.parent.parent == frame)
11 | assert(stack.top != frame)
12 |
13 | def func1()
14 | func2()
15 |
16 | func1()
17 |
--------------------------------------------------------------------------------
/tests/vm/find_active_value.ca.output:
--------------------------------------------------------------------------------
1 | active value for x (fixed): 1, found = true
2 | active value for y (stack): 2, found = true
3 | active value for z (stack): null, found = false
4 |
--------------------------------------------------------------------------------
/tests/vm/make_with_closure.ca.output:
--------------------------------------------------------------------------------
1 | sanity check, should say f(1, 2): f(1, 2)
2 | calling vm, should say f(3, 4): f(3, 4)
3 |
--------------------------------------------------------------------------------
/tests/vm/null_vm.ca:
--------------------------------------------------------------------------------
1 |
2 | struct T {
3 | VM vm
4 | }
5 |
6 | t = T.make
7 | t = nil
8 |
--------------------------------------------------------------------------------
/tests/vm/set_env.ca:
--------------------------------------------------------------------------------
1 |
2 | def main()
3 | env(:key)
4 |
5 | vm = make_vm(main)
6 | assert(vm.call == nil)
7 |
8 | vm.set_env(:key 'value')
9 | assert(vm.call == 'value')
10 |
--------------------------------------------------------------------------------
/tests/while/continue_and_locals.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | i = 0
4 | while i < 6
5 | print('value of i at loop start: ' i)
6 | if i % 2 == 1
7 | print('odd: ' i)
8 | i += 1
9 | continue
10 |
11 | print('value of i after if: ' i)
12 |
13 | print('even: ' i)
14 | i += 1
15 |
16 | print('value of i at loop end: ' i)
17 |
--------------------------------------------------------------------------------
/tests/while/counter.ca:
--------------------------------------------------------------------------------
1 |
2 | i = 0
3 | print('pre loop')
4 | while i < 5
5 | print('i = ' i)
6 | i += 1
7 |
--------------------------------------------------------------------------------
/tests/while/counter.ca.output:
--------------------------------------------------------------------------------
1 | pre loop
2 | i = 0
3 | i = 1
4 | i = 2
5 | i = 3
6 | i = 4
7 |
--------------------------------------------------------------------------------
/tests/while/locals1.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | a = 1
4 | b = 2
5 | c = 3
6 |
7 | while false
8 | a = 4
9 | b = 5
10 | c = 6
11 |
12 |
13 | print('a = ' a)
14 | print('b = ' b)
15 | print('c = ' c)
16 |
--------------------------------------------------------------------------------
/tests/while/locals1.ca.output:
--------------------------------------------------------------------------------
1 | a = 1
2 | b = 2
3 | c = 3
4 |
--------------------------------------------------------------------------------
/tests/while/locals2.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | a = 1
4 | b = 2
5 | c = 3
6 |
7 | while true
8 | a = 4
9 | b = 5
10 | c = 6
11 |
12 | break
13 |
14 |
15 | print('a = ' a)
16 | print('b = ' b)
17 | print('c = ' c)
18 |
--------------------------------------------------------------------------------
/tests/while/locals2.ca.output:
--------------------------------------------------------------------------------
1 | a = 4
2 | b = 5
3 | c = 6
4 |
--------------------------------------------------------------------------------
/tests/while/locals3.ca:
--------------------------------------------------------------------------------
1 |
2 |
3 | a = 1
4 | b = 2
5 | c = 3
6 |
7 | loop = true
8 | while loop
9 | a = 4
10 | b = 5
11 | c = 6
12 |
13 | print('inside loop')
14 | loop = false
15 |
16 |
17 | print('a = ' a)
18 | print('b = ' b)
19 | print('c = ' c)
20 |
--------------------------------------------------------------------------------
/tests/while/locals3.ca.output:
--------------------------------------------------------------------------------
1 | inside loop
2 | a = 4
3 | b = 5
4 | c = 6
5 |
--------------------------------------------------------------------------------
/tests/while/zero.ca:
--------------------------------------------------------------------------------
1 |
2 | while false
3 | print('fail')
4 |
--------------------------------------------------------------------------------
/tools/README:
--------------------------------------------------------------------------------
1 |
2 | This directory contains a bunch of tools and scripts which are useful for development.
3 |
--------------------------------------------------------------------------------
/tools/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andyfischer/circa/39d6473b44bb1f7598703d3f6aed3b4c9942aa27/tools/__init__.py
--------------------------------------------------------------------------------
/tools/ca-d:
--------------------------------------------------------------------------------
1 | cd $CIRCA_HOME && make command_line
2 |
--------------------------------------------------------------------------------
/tools/ca-grep:
--------------------------------------------------------------------------------
1 | grep -r $* $CIRCA_HOME/src
2 |
--------------------------------------------------------------------------------
/tools/ca-r:
--------------------------------------------------------------------------------
1 | cd $CIRCA_HOME && make command_line config=release
2 |
--------------------------------------------------------------------------------
/tools/ca-sed:
--------------------------------------------------------------------------------
1 | # example:
2 | # ca-sed s/apples/oranges/g
3 | find $CIRCA_HOME/src -type f -exec sed --in-place $1 {} \;
4 |
--------------------------------------------------------------------------------
/tools/ca-sed.darwin:
--------------------------------------------------------------------------------
1 | # example:
2 | # ca-sed s/apples/oranges/g
3 | #sed -i '' $* $CIRCA_HOME/src/*.cpp $CIRCA_HOME/src/*.h $CIRCA_HOME/src/tests/*.cpp $CIRCA_HOME/src/builtin_functions/*.cpp
4 | find $CIRCA_HOME/src $CIRCA_HOME/include $CIRCA_HOME/src/unit_tests $CIRCA_HOME/tests -type f -exec sed -i '' -e "$1" {} \;
5 |
--------------------------------------------------------------------------------
/tools/ca-tag:
--------------------------------------------------------------------------------
1 | cd $CIRCA_HOME
2 | ctags -R -o tags src include
3 |
--------------------------------------------------------------------------------
/tools/ca-update-tags:
--------------------------------------------------------------------------------
1 | ctags -R ~/circa/src -o ~/circa/tags
2 |
--------------------------------------------------------------------------------
/tools/ca-valgrind:
--------------------------------------------------------------------------------
1 | valgrind --leak-check=full --num-callers=50 2>&1 build/circa_d $*
2 |
--------------------------------------------------------------------------------
/tools/vagrant/.gitignore:
--------------------------------------------------------------------------------
1 | /.vagrant
2 |
--------------------------------------------------------------------------------
/tools/vagrant/bootstrap.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | apt-get update
4 | apt-get install -y build-essential valgrind
5 |
--------------------------------------------------------------------------------