├── .gitattributes ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ ├── cygwin.bat │ └── pythonpackage.yml ├── .gitignore ├── .pylintrc ├── .readthedocs.yml ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.rst ├── docs ├── Makefile ├── _static │ ├── concurrency-scheduling.png │ ├── favicon.ico │ ├── favicon.png │ ├── logo.png │ ├── new.png │ ├── run-features.png │ ├── run-universe.png │ ├── run.png │ ├── test.png │ ├── test_c.png │ ├── test_c_index_html.png │ └── world.svg ├── activity.rst ├── conf.py ├── credits.rst ├── developer-guide.rst ├── developer-guide │ ├── getting-started.rst │ └── transpiler.rst ├── index.rst ├── language-reference.rst ├── language-reference │ ├── assertions.rst │ ├── builtins.rst │ ├── classes-and-traits.rst │ ├── comprehensions.rst │ ├── concurrency.rst │ ├── embedded-cpp.rst │ ├── enumerations.rst │ ├── error-handling.rst │ ├── generics.rst │ ├── global-variables.rst │ ├── importing.rst │ ├── iterators.rst │ ├── loops.rst │ ├── macros.rst │ ├── memory-management.rst │ ├── modules-and-packages.rst │ ├── numeric-literals.rst │ ├── optionals.rst │ ├── overloading.rst │ ├── package-configuration.rst │ ├── pattern-matching.rst │ ├── proposals.rst │ ├── proposals │ │ ├── copy.rst │ │ ├── process.rst │ │ ├── stackless_fibers.rst │ │ ├── traits.rst │ │ ├── tuples.rst │ │ └── type_information.rst │ ├── regular-expressions.rst │ ├── special-symbols.rst │ ├── type-conversions.rst │ └── types.rst ├── make.bat ├── standard-library.rst ├── statistics.rst ├── user-guide.rst └── user-guide │ ├── calling-mys-from-make.rst │ ├── getting-help.rst │ ├── getting-started.rst │ ├── installation.rst │ ├── notable-differences-to-python.rst │ ├── text-editor-settings.rst │ └── the-mys-command.rst ├── examples ├── Makefile ├── README.rst ├── callbacks │ ├── README.rst │ ├── package.toml │ └── src │ │ └── main.mys ├── ctrl_c │ ├── README.rst │ ├── package.toml │ └── src │ │ └── main.mys ├── default_and_named_parameters │ ├── README.rst │ ├── package.toml │ └── src │ │ └── main.mys ├── embedded_cpp │ ├── README.rst │ ├── package.toml │ └── src │ │ ├── cpp │ │ ├── bar.hpp │ │ ├── foo.cpp │ │ └── foo.hpp │ │ └── main.mys ├── enums │ ├── README.rst │ ├── package.toml │ └── src │ │ └── main.mys ├── errors │ ├── README.rst │ ├── package.toml │ └── src │ │ └── main.mys ├── fibers │ ├── README.rst │ ├── package.toml │ └── src │ │ └── main.mys ├── fibonacci │ ├── README.rst │ ├── package.toml │ └── src │ │ └── main.mys ├── fizz_buzz │ ├── README.rst │ ├── package.toml │ └── src │ │ └── main.mys ├── generics │ ├── README.rst │ ├── package.toml │ └── src │ │ └── main.mys ├── hash │ ├── README.rst │ ├── package.toml │ └── src │ │ └── main.mys ├── hello_world │ ├── README.rst │ ├── package.toml │ └── src │ │ └── main.mys ├── local_variables │ ├── README.rst │ ├── package.toml │ └── src │ │ └── main.mys ├── macro │ ├── README.rst │ ├── package.toml │ └── src │ │ └── main.mys ├── optionals │ ├── README.rst │ ├── package.toml │ └── src │ │ └── main.mys ├── pattern_matching │ ├── README.rst │ ├── package.toml │ └── src │ │ └── main.mys ├── pi │ ├── README.rst │ ├── package.toml │ └── src │ │ └── main.mys ├── prechelt_phone_number_encoding │ ├── README.rst │ ├── dictionary.txt │ ├── package.toml │ ├── phone_numbers.txt │ └── src │ │ └── main.mys ├── private_and_public │ ├── package.toml │ └── src │ │ ├── lib.mys │ │ └── main.mys ├── ray_tracing │ ├── README.rst │ ├── output.png │ ├── package.toml │ └── src │ │ ├── main.mys │ │ ├── ray.mys │ │ └── vec.mys ├── regular_expressions │ ├── README.rst │ ├── package.toml │ └── src │ │ └── main.mys ├── string_formatting │ ├── README.rst │ ├── package.toml │ └── src │ │ └── main.mys ├── the_super_tiny_compiler │ ├── README.rst │ ├── package.toml │ └── src │ │ └── main.mys ├── traceback │ ├── README.rst │ ├── package.toml │ └── src │ │ ├── error.mys │ │ ├── main.mys │ │ ├── panic.mys │ │ └── print.mys ├── traits │ ├── README.rst │ ├── package.toml │ └── src │ │ └── main.mys └── wip │ ├── README.rst │ ├── iterators │ ├── README.rst │ ├── main.py │ ├── package.toml │ └── src │ │ └── main.mys │ ├── linked_list │ ├── README.rst │ ├── package.toml │ └── src │ │ ├── lib.mys │ │ └── main.mys │ ├── message_passing │ ├── README.rst │ ├── package.toml │ └── src │ │ ├── calculator.mys │ │ ├── main.mys │ │ ├── message.mys │ │ └── student.mys │ ├── mocking │ ├── README.rst │ ├── package.toml │ └── src │ │ ├── fie.mys │ │ └── lib.mys │ ├── poll │ ├── README.rst │ ├── package.toml │ └── src │ │ ├── lib.mys │ │ └── main.mys │ └── sort_list │ ├── README.rst │ ├── package.toml │ └── src │ └── main.mys ├── mys ├── __init__.py ├── __main__.py ├── cli │ ├── __init__.py │ ├── mys_dir.py │ ├── package_config.py │ ├── packages_finder.py │ ├── run.py │ ├── subparsers │ │ ├── __init__.py │ │ ├── build.py │ │ ├── clean.py │ │ ├── delete.py │ │ ├── dependents.py │ │ ├── deps.py │ │ ├── doc.py │ │ ├── help.py │ │ ├── install.py │ │ ├── list.py │ │ ├── new.py │ │ ├── publish.py │ │ ├── run.py │ │ ├── style │ │ │ ├── __init__.py │ │ │ ├── comments_finder.py │ │ │ ├── comments_reader.py │ │ │ ├── source_styler.py │ │ │ └── utils.py │ │ ├── test.py │ │ └── transpile.py │ ├── templates │ │ ├── build │ │ │ └── Makefile │ │ ├── doc │ │ │ └── conf.py │ │ ├── new │ │ │ ├── .gitattributes │ │ │ ├── .gitignore │ │ │ ├── LICENSE │ │ │ ├── README.rst │ │ │ ├── doc │ │ │ │ └── index.rst │ │ │ ├── package.toml │ │ │ └── src │ │ │ │ ├── lib.mys │ │ │ │ └── main.mys │ │ └── publish │ │ │ ├── MANIFEST.in │ │ │ └── setup.py │ └── utils.py ├── coverage │ ├── CONTRIBUTORS.txt │ ├── LICENSE.txt │ ├── NOTICE.txt │ ├── README.rst │ ├── __init__.py │ ├── config.py │ ├── control.py │ ├── data.py │ ├── debug.py │ ├── files.py │ ├── html.py │ ├── htmlfiles │ │ ├── coverage_html.js │ │ ├── favicon.ico │ │ ├── favicon.png │ │ ├── index.html │ │ ├── jquery.ba-throttle-debounce.min.js │ │ ├── jquery.hotkeys.js │ │ ├── jquery.isonscreen.js │ │ ├── jquery.min.js │ │ ├── jquery.tablesorter.min.js │ │ ├── keybd_closed.png │ │ ├── keybd_open.png │ │ ├── pyfile.html │ │ ├── style.css │ │ └── style.scss │ ├── misc.py │ ├── mys.py │ ├── numbits.py │ ├── phystokens.py │ ├── plugin.py │ ├── report.py │ ├── results.py │ ├── sqldata.py │ ├── templite.py │ └── version.py ├── lib │ ├── fiber.cpp │ ├── memory.cpp │ ├── mys.cpp │ ├── mys.hpp │ ├── mys │ │ ├── builtins.hpp │ │ ├── common.hpp │ │ ├── errors │ │ │ ├── assertion.hpp │ │ │ ├── base.hpp │ │ │ ├── index.hpp │ │ │ ├── interrupt.hpp │ │ │ ├── key.hpp │ │ │ ├── not_implemented.hpp │ │ │ ├── system_exit.hpp │ │ │ ├── unreachable.hpp │ │ │ └── value.hpp │ │ ├── fiber.hpp │ │ ├── memory.hpp │ │ ├── optional.hpp │ │ ├── printable │ │ │ ├── char.hpp │ │ │ └── string.hpp │ │ ├── shared_ptr.hpp │ │ ├── test.hpp │ │ ├── traceback.hpp │ │ ├── types │ │ │ ├── bool.hpp │ │ │ ├── bytes.hpp │ │ │ ├── char.hpp │ │ │ ├── dict.hpp │ │ │ ├── generators.hpp │ │ │ ├── list.hpp │ │ │ ├── number.hpp │ │ │ ├── object.hpp │ │ │ ├── regex.hpp │ │ │ ├── set.hpp │ │ │ ├── string.hpp │ │ │ └── tuple.hpp │ │ └── utils.hpp │ ├── packages │ │ ├── README.rst │ │ ├── builtins │ │ │ ├── package.toml │ │ │ └── src │ │ │ │ └── lib.mys │ │ ├── error │ │ │ ├── package.toml │ │ │ └── src │ │ │ │ └── lib.mys │ │ └── fiber │ │ │ ├── package.toml │ │ │ └── src │ │ │ └── lib.mys │ ├── test │ │ ├── Makefile │ │ ├── catch.cpp │ │ ├── catch.hpp │ │ ├── test_memory.cpp │ │ └── test_optional.cpp │ ├── unicodectype.cpp │ ├── unicodetype_db.hpp │ ├── whereami.c │ └── whereami.h ├── parser │ ├── Mys-Python-ast.h │ ├── Mys-asdl.h │ ├── Mys-ast.h │ ├── Mys-parser_interface.h │ ├── Mys-pegen.h │ ├── Mys-pyarena.h │ ├── Mys-string_parser.h │ ├── Mys-token.h │ ├── Mys-tokenizer.h │ ├── Python-ast.c │ ├── README.rst │ ├── __init__.py │ ├── asdl.c │ ├── ast.py │ ├── parser.c │ ├── peg_api.c │ ├── pegen.c │ ├── pyarena.c │ ├── string_parser.c │ ├── token.c │ └── tokenizer.c ├── pcre2 │ ├── AUTHORS │ ├── COPYING │ ├── HACKING │ ├── INSTALL │ ├── LICENCE │ ├── Makefile │ ├── README │ ├── include │ │ └── pcre2.h │ └── src │ │ ├── config.h │ │ ├── pcre2_auto_possess.c │ │ ├── pcre2_chartables.c │ │ ├── pcre2_compile.c │ │ ├── pcre2_config.c │ │ ├── pcre2_context.c │ │ ├── pcre2_convert.c │ │ ├── pcre2_dfa_match.c │ │ ├── pcre2_error.c │ │ ├── pcre2_extuni.c │ │ ├── pcre2_find_bracket.c │ │ ├── pcre2_fuzzsupport.c │ │ ├── pcre2_internal.h │ │ ├── pcre2_intmodedep.h │ │ ├── pcre2_jit_compile.c │ │ ├── pcre2_jit_match.c │ │ ├── pcre2_jit_misc.c │ │ ├── pcre2_jit_neon_inc.h │ │ ├── pcre2_jit_simd_inc.h │ │ ├── pcre2_maketables.c │ │ ├── pcre2_match.c │ │ ├── pcre2_match_data.c │ │ ├── pcre2_newline.c │ │ ├── pcre2_ord2utf.c │ │ ├── pcre2_pattern_info.c │ │ ├── pcre2_script_run.c │ │ ├── pcre2_serialize.c │ │ ├── pcre2_string_utils.c │ │ ├── pcre2_study.c │ │ ├── pcre2_substitute.c │ │ ├── pcre2_substring.c │ │ ├── pcre2_tables.c │ │ ├── pcre2_ucd.c │ │ ├── pcre2_ucp.h │ │ ├── pcre2_valid_utf.c │ │ └── pcre2_xclass.c ├── pygments │ └── pygments │ │ ├── README.rst │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── cmdline.py │ │ ├── console.py │ │ ├── filter.py │ │ ├── filters │ │ └── __init__.py │ │ ├── formatter.py │ │ ├── formatters │ │ ├── __init__.py │ │ ├── _mapping.py │ │ ├── bbcode.py │ │ ├── html.py │ │ ├── img.py │ │ ├── irc.py │ │ ├── latex.py │ │ ├── other.py │ │ ├── pangomarkup.py │ │ ├── rtf.py │ │ ├── svg.py │ │ ├── terminal.py │ │ └── terminal256.py │ │ ├── lexer.py │ │ ├── lexers │ │ ├── __init__.py │ │ ├── _asy_builtins.py │ │ ├── _cl_builtins.py │ │ ├── _cocoa_builtins.py │ │ ├── _csound_builtins.py │ │ ├── _julia_builtins.py │ │ ├── _lasso_builtins.py │ │ ├── _lua_builtins.py │ │ ├── _mapping.py │ │ ├── _mql_builtins.py │ │ ├── _mysql_builtins.py │ │ ├── _openedge_builtins.py │ │ ├── _php_builtins.py │ │ ├── _postgres_builtins.py │ │ ├── _scilab_builtins.py │ │ ├── _sourcemod_builtins.py │ │ ├── _stan_builtins.py │ │ ├── _stata_builtins.py │ │ ├── _tsql_builtins.py │ │ ├── _usd_builtins.py │ │ ├── _vbscript_builtins.py │ │ ├── _vim_builtins.py │ │ ├── actionscript.py │ │ ├── agile.py │ │ ├── algebra.py │ │ ├── ambient.py │ │ ├── amdgpu.py │ │ ├── ampl.py │ │ ├── apdlexer.py │ │ ├── apl.py │ │ ├── archetype.py │ │ ├── arrow.py │ │ ├── asm.py │ │ ├── automation.py │ │ ├── bare.py │ │ ├── basic.py │ │ ├── bibtex.py │ │ ├── boa.py │ │ ├── business.py │ │ ├── c_cpp.py │ │ ├── c_like.py │ │ ├── capnproto.py │ │ ├── cddl.py │ │ ├── chapel.py │ │ ├── clean.py │ │ ├── compiled.py │ │ ├── configs.py │ │ ├── console.py │ │ ├── crystal.py │ │ ├── csound.py │ │ ├── css.py │ │ ├── d.py │ │ ├── dalvik.py │ │ ├── data.py │ │ ├── devicetree.py │ │ ├── diff.py │ │ ├── dotnet.py │ │ ├── dsls.py │ │ ├── dylan.py │ │ ├── ecl.py │ │ ├── eiffel.py │ │ ├── elm.py │ │ ├── email.py │ │ ├── erlang.py │ │ ├── esoteric.py │ │ ├── ezhil.py │ │ ├── factor.py │ │ ├── fantom.py │ │ ├── felix.py │ │ ├── floscript.py │ │ ├── forth.py │ │ ├── fortran.py │ │ ├── foxpro.py │ │ ├── freefem.py │ │ ├── functional.py │ │ ├── futhark.py │ │ ├── gcodelexer.py │ │ ├── gdscript.py │ │ ├── go.py │ │ ├── grammar_notation.py │ │ ├── graph.py │ │ ├── graphics.py │ │ ├── graphviz.py │ │ ├── haskell.py │ │ ├── haxe.py │ │ ├── hdl.py │ │ ├── hexdump.py │ │ ├── html.py │ │ ├── idl.py │ │ ├── igor.py │ │ ├── inferno.py │ │ ├── installers.py │ │ ├── int_fiction.py │ │ ├── iolang.py │ │ ├── j.py │ │ ├── javascript.py │ │ ├── jslt.py │ │ ├── julia.py │ │ ├── jvm.py │ │ ├── kuin.py │ │ ├── lisp.py │ │ ├── make.py │ │ ├── markup.py │ │ ├── math.py │ │ ├── matlab.py │ │ ├── meson.py │ │ ├── mime.py │ │ ├── ml.py │ │ ├── modeling.py │ │ ├── modula2.py │ │ ├── monte.py │ │ ├── mosel.py │ │ ├── mys.py │ │ ├── ncl.py │ │ ├── nimrod.py │ │ ├── nit.py │ │ ├── nix.py │ │ ├── oberon.py │ │ ├── objective.py │ │ ├── ooc.py │ │ ├── other.py │ │ ├── parasail.py │ │ ├── parsers.py │ │ ├── pascal.py │ │ ├── pawn.py │ │ ├── perl.py │ │ ├── php.py │ │ ├── pointless.py │ │ ├── pony.py │ │ ├── praat.py │ │ ├── procfile.py │ │ ├── prolog.py │ │ ├── promql.py │ │ ├── python.py │ │ ├── qvt.py │ │ ├── r.py │ │ ├── rdf.py │ │ ├── rebol.py │ │ ├── resource.py │ │ ├── ride.py │ │ ├── rnc.py │ │ ├── roboconf.py │ │ ├── robotframework.py │ │ ├── ruby.py │ │ ├── rust.py │ │ ├── sas.py │ │ ├── scdoc.py │ │ ├── scripting.py │ │ ├── sgf.py │ │ ├── shell.py │ │ ├── sieve.py │ │ ├── slash.py │ │ ├── smalltalk.py │ │ ├── smv.py │ │ ├── snobol.py │ │ ├── solidity.py │ │ ├── special.py │ │ ├── sql.py │ │ ├── stata.py │ │ ├── supercollider.py │ │ ├── tcl.py │ │ ├── teal.py │ │ ├── templates.py │ │ ├── teraterm.py │ │ ├── testing.py │ │ ├── text.py │ │ ├── textedit.py │ │ ├── textfmts.py │ │ ├── theorem.py │ │ ├── thingsdb.py │ │ ├── tnt.py │ │ ├── trafficscript.py │ │ ├── typoscript.py │ │ ├── unicon.py │ │ ├── urbi.py │ │ ├── usd.py │ │ ├── varnish.py │ │ ├── verification.py │ │ ├── web.py │ │ ├── webassembly.py │ │ ├── webidl.py │ │ ├── webmisc.py │ │ ├── whiley.py │ │ ├── x10.py │ │ ├── xorg.py │ │ ├── yang.py │ │ └── zig.py │ │ ├── modeline.py │ │ ├── plugin.py │ │ ├── regexopt.py │ │ ├── scanner.py │ │ ├── sphinxext.py │ │ ├── style.py │ │ ├── styles │ │ ├── __init__.py │ │ ├── abap.py │ │ ├── algol.py │ │ ├── algol_nu.py │ │ ├── arduino.py │ │ ├── autumn.py │ │ ├── borland.py │ │ ├── bw.py │ │ ├── colorful.py │ │ ├── default.py │ │ ├── emacs.py │ │ ├── friendly.py │ │ ├── fruity.py │ │ ├── gruvbox.py │ │ ├── igor.py │ │ ├── inkpot.py │ │ ├── lovelace.py │ │ ├── manni.py │ │ ├── material.py │ │ ├── monokai.py │ │ ├── murphy.py │ │ ├── native.py │ │ ├── paraiso_dark.py │ │ ├── paraiso_light.py │ │ ├── pastie.py │ │ ├── perldoc.py │ │ ├── rainbow_dash.py │ │ ├── rrt.py │ │ ├── sas.py │ │ ├── solarized.py │ │ ├── stata_dark.py │ │ ├── stata_light.py │ │ ├── tango.py │ │ ├── trac.py │ │ ├── vim.py │ │ ├── vs.py │ │ ├── xcode.py │ │ └── zenburn.py │ │ ├── token.py │ │ ├── unistring.py │ │ └── util.py ├── sphinx │ └── __init__.py ├── sphinx_rtd_dark_mode │ ├── README.rst │ ├── __init__.py │ ├── dark_mode_loader.py │ └── static │ │ ├── dark_mode_css │ │ ├── dark.css │ │ └── general.css │ │ └── dark_mode_js │ │ ├── default_dark.js │ │ ├── default_light.js │ │ └── theme_switcher.js ├── transpiler │ ├── __init__.py │ ├── base.py │ ├── body_check_visitor.py │ ├── class_transformer.py │ ├── comprehension.py │ ├── constant_visitor.py │ ├── context.py │ ├── coverage_transformer.py │ ├── cpp_reserved.py │ ├── definition_types.py │ ├── definitions.py │ ├── generics.py │ ├── header_visitor.py │ ├── import_order.py │ ├── imports_visitor.py │ ├── iterators.py │ ├── return_checker_visitor.py │ ├── source_visitor.py │ ├── traits.py │ ├── utils.py │ ├── value_check_type_visitor.py │ ├── value_type_visitor.py │ └── variables.py ├── uv │ ├── AUTHORS │ ├── CONTRIBUTING.md │ ├── LICENSE │ ├── LICENSE-docs │ ├── LINKS.md │ ├── MAINTAINERS.md │ ├── Makefile │ ├── README.md │ ├── include │ │ ├── uv.h │ │ └── uv │ │ │ ├── aix.h │ │ │ ├── bsd.h │ │ │ ├── darwin.h │ │ │ ├── errno.h │ │ │ ├── linux.h │ │ │ ├── os390.h │ │ │ ├── posix.h │ │ │ ├── stdint-msvc2008.h │ │ │ ├── sunos.h │ │ │ ├── threadpool.h │ │ │ ├── tree.h │ │ │ ├── unix.h │ │ │ ├── version.h │ │ │ └── win.h │ └── src │ │ ├── fs-poll.c │ │ ├── heap-inl.h │ │ ├── idna.c │ │ ├── idna.h │ │ ├── inet.c │ │ ├── queue.h │ │ ├── random.c │ │ ├── strscpy.c │ │ ├── strscpy.h │ │ ├── threadpool.c │ │ ├── timer.c │ │ ├── unix │ │ ├── aix-common.c │ │ ├── aix.c │ │ ├── async.c │ │ ├── atomic-ops.h │ │ ├── bsd-ifaddrs.c │ │ ├── bsd-proctitle.c │ │ ├── core.c │ │ ├── cygwin.c │ │ ├── darwin-proctitle.c │ │ ├── darwin-stub.h │ │ ├── darwin.c │ │ ├── dl.c │ │ ├── epoll.c │ │ ├── freebsd.c │ │ ├── fs.c │ │ ├── fsevents.c │ │ ├── getaddrinfo.c │ │ ├── getnameinfo.c │ │ ├── haiku.c │ │ ├── hurd.c │ │ ├── ibmi.c │ │ ├── internal.h │ │ ├── kqueue.c │ │ ├── linux-core.c │ │ ├── linux-inotify.c │ │ ├── linux-syscalls.c │ │ ├── linux-syscalls.h │ │ ├── loop-watcher.c │ │ ├── loop.c │ │ ├── netbsd.c │ │ ├── no-fsevents.c │ │ ├── no-proctitle.c │ │ ├── openbsd.c │ │ ├── os390-proctitle.c │ │ ├── os390-syscalls.c │ │ ├── os390-syscalls.h │ │ ├── os390.c │ │ ├── pipe.c │ │ ├── poll.c │ │ ├── posix-hrtime.c │ │ ├── posix-poll.c │ │ ├── process.c │ │ ├── procfs-exepath.c │ │ ├── proctitle.c │ │ ├── pthread-fixes.c │ │ ├── qnx.c │ │ ├── random-devurandom.c │ │ ├── random-getentropy.c │ │ ├── random-getrandom.c │ │ ├── random-sysctl-linux.c │ │ ├── signal.c │ │ ├── spinlock.h │ │ ├── stream.c │ │ ├── sunos.c │ │ ├── sysinfo-loadavg.c │ │ ├── sysinfo-memory.c │ │ ├── tcp.c │ │ ├── thread.c │ │ ├── tty.c │ │ └── udp.c │ │ ├── uv-common.c │ │ ├── uv-common.h │ │ ├── uv-data-getter-setters.c │ │ └── version.c └── version.py ├── requirements.txt ├── setup.py ├── setup.sh └── tests ├── __init__.py ├── files ├── .gitignore ├── asserts.mys ├── assets │ ├── mypkg │ │ ├── README.rst │ │ ├── assets │ │ │ ├── bar │ │ │ │ └── bar.txt │ │ │ └── foo.txt │ │ ├── package.toml │ │ └── src │ │ │ └── lib.mys │ └── mypkg1 │ │ ├── README.rst │ │ ├── assets │ │ └── foo.txt │ │ ├── package.toml │ │ └── src │ │ └── lib.mys ├── bar │ ├── README.rst │ ├── package.toml │ └── src │ │ └── lib.mys ├── bytes.mys ├── c_dependencies │ ├── mypkg │ │ ├── package.toml │ │ └── src │ │ │ └── lib.mys │ └── mypkg1 │ │ ├── package.toml │ │ └── src │ │ └── lib.mys ├── c_dependencies_not_found │ ├── package.toml │ └── src │ │ └── lib.mys ├── calc.mys ├── char_.mys ├── circular_imports │ ├── package.toml │ └── src │ │ ├── mod1.mys │ │ └── mod2.mys ├── classes.mys ├── compare.mys ├── comprehensions.mys ├── copy.mys ├── coverage.mys ├── dict.mys ├── doc │ ├── doc │ │ ├── conf.py │ │ └── index.rst │ ├── examples │ │ └── basic │ │ │ └── src │ │ │ └── main.mys │ ├── index.txt │ ├── package.toml │ └── src │ │ ├── lib.mys │ │ └── mod1.mys ├── embedded_cpp │ ├── mypkg │ │ ├── README.rst │ │ ├── package.toml │ │ └── src │ │ │ ├── cpp │ │ │ ├── bar.hpp │ │ │ ├── foo.cpp │ │ │ └── foo.hpp │ │ │ └── lib.mys │ └── mypkg1 │ │ ├── README.rst │ │ ├── package.toml │ │ └── src │ │ ├── foo.cpp │ │ ├── foo.hpp │ │ └── lib.mys ├── enums.mys ├── error_if_package_name_is_not_snake_case │ ├── package.toml │ └── src │ │ └── lib.mys ├── error_if_package_version_is_not_semantic │ ├── package.toml │ └── src │ │ └── lib.mys ├── errors.mys ├── fibers.mys ├── fie │ ├── README.rst │ ├── package.toml │ └── src │ │ ├── lib.mys │ │ └── main.mys ├── foo │ ├── .gitattributes │ ├── .gitignore │ ├── LICENSE │ ├── README.rst │ ├── doc │ │ ├── conf.py │ │ ├── index.rst │ │ ├── lib.rst │ │ ├── modules.rst │ │ └── modules │ │ │ └── lib.rst │ ├── package.toml │ ├── src │ │ ├── lib.mys │ │ └── main.mys │ └── tests │ │ └── test_lib.mys ├── fstrings.mys ├── functions.mys ├── generics.mys ├── globals_init_order │ └── mypkg │ │ ├── package.toml │ │ └── src │ │ ├── lib.mys │ │ ├── mod1.mys │ │ └── mod2.mys ├── hash.mys ├── hello_world.mys ├── imports │ ├── mypkg │ │ ├── README.rst │ │ ├── package.toml │ │ └── src │ │ │ ├── lib.mys │ │ │ ├── mod1.mys │ │ │ ├── mod2.mys │ │ │ ├── mod3.mys │ │ │ └── mod4.mys │ ├── mypkg1 │ │ ├── README.rst │ │ ├── package.toml │ │ └── src │ │ │ ├── _mod1.mys │ │ │ ├── _subpkg2 │ │ │ └── mod1.mys │ │ │ ├── lib.mys │ │ │ └── subpkg1 │ │ │ └── mod1.mys │ └── mypkg2 │ │ ├── README.rst │ │ ├── package.toml │ │ └── src │ │ ├── lib.mys │ │ └── mod1.mys ├── install │ ├── bar │ │ ├── assets │ │ │ └── bar.txt │ │ ├── package.toml │ │ └── src │ │ │ └── lib.mys │ └── foo │ │ ├── assets │ │ └── foo.json │ │ ├── package.toml │ │ └── src │ │ └── main.mys ├── iterators.mys ├── lib.mys ├── list.mys ├── loops.mys ├── macro.mys ├── match.mys ├── optionals.mys ├── package_and_module_with_same_name │ ├── package.toml │ └── src │ │ └── foo.mys ├── package_with_local_and_registry_dependencies │ ├── dep1 │ │ ├── package.toml │ │ └── src │ │ │ └── lib.mys │ ├── dep2 │ │ ├── package.toml │ │ └── src │ │ │ └── lib.mys │ └── top │ │ ├── package.toml │ │ └── src │ │ └── main.mys ├── print.mys ├── regexp.mys ├── set.mys ├── signals │ ├── package.toml │ └── src │ │ └── lib.mys ├── special_symbols.mys ├── string.mys ├── string_to_integer.mys ├── style │ ├── package.toml │ ├── src │ │ ├── f │ │ │ └── mod.mys │ │ ├── lib.mys │ │ ├── mod.mys │ │ └── trailing_whitespaces.mys │ └── styled-src │ │ ├── f │ │ └── mod.mys │ │ ├── lib.mys │ │ ├── mod.mys │ │ └── trailing_whitespaces.mys ├── test_new_author_from_git │ └── package.toml ├── test_new_multiple_authors │ └── package.toml ├── test_test_new_git_command_failure │ └── package.toml ├── traceback │ ├── package.toml │ └── src │ │ ├── lib.mys │ │ └── main.mys ├── traits.mys ├── tuple.mys ├── unsafe │ ├── package.toml │ └── src │ │ └── lib.mys ├── variables.mys ├── various_1.mys ├── various_2.mys ├── various_3.mys ├── weak.mys └── weak_panic.mys ├── test_asserts.py ├── test_assets.py ├── test_bytes.py ├── test_char.py ├── test_classes.py ├── test_commands.py ├── test_compare.py ├── test_comprehensions.py ├── test_constants.py ├── test_copy.py ├── test_coverage.py ├── test_dependencies.py ├── test_dict.py ├── test_doc.py ├── test_embedded_cpp.py ├── test_enums.py ├── test_errors.py ├── test_fibers.py ├── test_for.py ├── test_fstrings.py ├── test_functions.py ├── test_generics.py ├── test_globals_init_order.py ├── test_hash.py ├── test_if.py ├── test_import_order.py ├── test_imports.py ├── test_iterators.py ├── test_lib.py ├── test_list.py ├── test_loops.py ├── test_macro.py ├── test_match.py ├── test_naming.py ├── test_optionals.py ├── test_print.py ├── test_regexp.py ├── test_set.py ├── test_signals.py ├── test_string.py ├── test_string_to_integer.py ├── test_style.py ├── test_test.py ├── test_traceback.py ├── test_traits.py ├── test_tuple.py ├── test_unsafe.py ├── test_variables.py ├── test_various.py ├── test_weak.py ├── test_while.py └── utils.py /.gitattributes: -------------------------------------------------------------------------------- 1 | *.mys linguist-language=python -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: eerimoq 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Bug report 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **What did you do?** 11 | 12 | 13 | 14 | **What did you expect to see?** 15 | 16 | 17 | 18 | **What did you see instead?** 19 | 20 | 21 | 22 | **Mys version** 23 | 24 | 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest a new feature 4 | title: '' 5 | labels: feature 6 | assignees: '' 7 | 8 | --- 9 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | sphinx: 4 | configuration: docs/conf.py 5 | 6 | formats: 7 | - pdf 8 | 9 | python: 10 | version: 3.8 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This lince applies to everything in this repository except 2 | mys/lib/iter/*. See mys/lib/iter/LICENSE for more details about those 3 | files. 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2020-2021 Erik Moqvist 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | 27 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include Makefile 3 | recursive-include mys * 4 | recursive-include tests *.py 5 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = . 9 | BUILDDIR = build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/_static/concurrency-scheduling.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mys-lang/mys/f3cb604e95eadd9833466dbd43ac9f5913f31d60/docs/_static/concurrency-scheduling.png -------------------------------------------------------------------------------- /docs/_static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mys-lang/mys/f3cb604e95eadd9833466dbd43ac9f5913f31d60/docs/_static/favicon.ico -------------------------------------------------------------------------------- /docs/_static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mys-lang/mys/f3cb604e95eadd9833466dbd43ac9f5913f31d60/docs/_static/favicon.png -------------------------------------------------------------------------------- /docs/_static/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mys-lang/mys/f3cb604e95eadd9833466dbd43ac9f5913f31d60/docs/_static/logo.png -------------------------------------------------------------------------------- /docs/_static/new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mys-lang/mys/f3cb604e95eadd9833466dbd43ac9f5913f31d60/docs/_static/new.png -------------------------------------------------------------------------------- /docs/_static/run-features.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mys-lang/mys/f3cb604e95eadd9833466dbd43ac9f5913f31d60/docs/_static/run-features.png -------------------------------------------------------------------------------- /docs/_static/run-universe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mys-lang/mys/f3cb604e95eadd9833466dbd43ac9f5913f31d60/docs/_static/run-universe.png -------------------------------------------------------------------------------- /docs/_static/run.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mys-lang/mys/f3cb604e95eadd9833466dbd43ac9f5913f31d60/docs/_static/run.png -------------------------------------------------------------------------------- /docs/_static/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mys-lang/mys/f3cb604e95eadd9833466dbd43ac9f5913f31d60/docs/_static/test.png -------------------------------------------------------------------------------- /docs/_static/test_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mys-lang/mys/f3cb604e95eadd9833466dbd43ac9f5913f31d60/docs/_static/test_c.png -------------------------------------------------------------------------------- /docs/_static/test_c_index_html.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mys-lang/mys/f3cb604e95eadd9833466dbd43ac9f5913f31d60/docs/_static/test_c_index_html.png -------------------------------------------------------------------------------- /docs/activity.rst: -------------------------------------------------------------------------------- 1 | Activity 2 | ======== 3 | 4 | Recent website activity. 5 | 6 | {website-activities} 7 | -------------------------------------------------------------------------------- /docs/credits.rst: -------------------------------------------------------------------------------- 1 | Credits 2 | ======= 3 | 4 | This is at least a partial list of people that have contributed to the 5 | Mys project. It is sorted by name. 6 | 7 | - `Ali Chraghi `_ 8 | - `Erik Moqvist `_ 9 | - `Fredrik Hallenberg `_ 10 | - `Simon Bordeyne `_ 11 | 12 | And of course, the Python language, which Mys has taken a lot of 13 | inspiration (and some code) from. And as you probably know, pythons 14 | eats mice... 15 | -------------------------------------------------------------------------------- /docs/developer-guide.rst: -------------------------------------------------------------------------------- 1 | Developer Guide 2 | =============== 3 | 4 | This guide is intended for developers of the Mys programming 5 | language. Users are advised to read the :doc:`user-guide` instead. 6 | 7 | .. toctree:: 8 | :glob: 9 | :maxdepth: 1 10 | 11 | developer-guide/getting-started 12 | developer-guide/transpiler 13 | -------------------------------------------------------------------------------- /docs/developer-guide/transpiler.rst: -------------------------------------------------------------------------------- 1 | Transpiler 2 | ---------- 3 | 4 | The transpiler takes Mys source code as input and outputs C++ source 5 | code. 6 | 7 | Build process 8 | ^^^^^^^^^^^^^ 9 | 10 | ``mys build``, ``mys run`` and ``mys test`` does the following: 11 | 12 | #. Use Python's parser to transform the source code to an Abstract 13 | Syntax Tree (AST). 14 | 15 | #. Generate C++ code from the AST. 16 | 17 | #. Compile the C++ code with ``g++``. 18 | 19 | #. Link the application with ``g++``. 20 | -------------------------------------------------------------------------------- /docs/language-reference.rst: -------------------------------------------------------------------------------- 1 | Language Reference 2 | ================== 3 | 4 | The language reference contains information about syntax, types, 5 | builtins and more. 6 | 7 | .. toctree:: 8 | :glob: 9 | :maxdepth: 1 10 | 11 | language-reference/types 12 | language-reference/classes-and-traits 13 | language-reference/enumerations 14 | language-reference/error-handling 15 | language-reference/generics 16 | language-reference/loops 17 | language-reference/pattern-matching 18 | language-reference/regular-expressions 19 | language-reference/optionals 20 | language-reference/iterators 21 | language-reference/comprehensions 22 | language-reference/overloading 23 | language-reference/global-variables 24 | language-reference/assertions 25 | language-reference/numeric-literals 26 | language-reference/builtins 27 | language-reference/modules-and-packages 28 | language-reference/package-configuration 29 | language-reference/importing 30 | language-reference/type-conversions 31 | language-reference/memory-management 32 | language-reference/concurrency 33 | language-reference/embedded-cpp 34 | language-reference/special-symbols 35 | language-reference/macros 36 | language-reference/proposals 37 | -------------------------------------------------------------------------------- /docs/language-reference/assertions.rst: -------------------------------------------------------------------------------- 1 | Assertions 2 | ---------- 3 | 4 | Use ``assert`` to ensure that given condition is true. 5 | 6 | .. code-block:: mys 7 | 8 | assert True 9 | assert 1 != 5 10 | assert 1 in [1, 3] 11 | v = 1 12 | assert v == 2 13 | 14 | The ``AssertionError`` error is raised if the condition is not true. 15 | 16 | .. code-block:: text 17 | 18 | AssertionError(message="1 == 2 is not true") 19 | 20 | Assertions are always compiled into test and debug binaries, but not 21 | by default into optimized application binaries. 22 | -------------------------------------------------------------------------------- /docs/language-reference/concurrency.rst: -------------------------------------------------------------------------------- 1 | Concurrency 2 | ----------- 3 | 4 | .. warning:: 5 | 6 | Concurrency is not yet fully implemented. 7 | 8 | Concurrency is implemented with stackful fibers scheduled by a 9 | cooperative (not preemptive) scheduler. Only one fiber can run at a 10 | time, which essentially makes Mys single core. Multi core support may 11 | be added in the future if requested. 12 | 13 | Fibers and asynchronous IO is currently implemented using pthreads and 14 | `libuv`_. 15 | 16 | See `the fibers example`_ for example code. 17 | 18 | Scheduler 19 | ^^^^^^^^^ 20 | 21 | There are two fibers that are always present; the main fiber and the 22 | idle fiber. The main fiber calls the application entry point 23 | ``main()``. The idle fiber is running when no other fiber is ready to 24 | run. It waits for IO events to occur and then reschedules to run other 25 | ready fibers. 26 | 27 | The diagram below is an example of how three fibers; ``shell``, 28 | ``main`` and ``idle`` are scheduled over time. 29 | 30 | .. image:: ../_static/concurrency-scheduling.png 31 | 32 | As it is a single core scheduler only one fiber is running at a 33 | time. In the beginning the system is idle and the ``idle`` fiber is 34 | running. After a while the ``main`` and ``shell`` fibers have some 35 | work to do, and since they have higher priority than the ``idle`` 36 | fiber they are scheduled. At the end the ``idle`` fiber is running 37 | again. 38 | 39 | .. _the fibers example: https://github.com/mys-lang/mys/tree/main/examples/fibers/src/main.mys 40 | 41 | .. _libuv: https://libuv.org/ 42 | -------------------------------------------------------------------------------- /docs/language-reference/embedded-cpp.rst: -------------------------------------------------------------------------------- 1 | Extending Mys with C++ 2 | ---------------------- 3 | 4 | .. warning:: 5 | 6 | The Mys C++ API may change at any time and should be avoided if 7 | possible. 8 | 9 | Extending Mys with C++ is extremly easy and flexible. C-strings, 10 | strings prefixed with ``c``, are inserted at the same location in the 11 | generated code. Also, all ``.cpp`` files found in ``src/`` are 12 | compiled and linked with the application. 13 | 14 | Start the c-string with ``header-before-namespace`` or 15 | ``source-before-namespace`` to insert the code before the C++ 16 | namespace in the generated header and source files respectively. 17 | 18 | Using C and C++ libraries is not yet supported. 19 | 20 | Below is the contents of ``src/main.mys`` found in the `embedded_cpp 21 | example`_. 22 | 23 | .. code-block:: mys 24 | 25 | c"""header-before-namespace 26 | #define FOOBAR 1 27 | """ 28 | 29 | c"""source-before-namespace 30 | #include "cpp/foo.hpp" 31 | """ 32 | 33 | func main(): 34 | a = 0 35 | b = 0 36 | 37 | c""" 38 | b = foo::foobar(2); 39 | a++; 40 | """ 41 | 42 | print("a + b:", a + b) 43 | 44 | .. _embedded_cpp example: https://github.com/mys-lang/mys/tree/main/examples/embedded_cpp 45 | -------------------------------------------------------------------------------- /docs/language-reference/enumerations.rst: -------------------------------------------------------------------------------- 1 | Enumerations 2 | ------------ 3 | 4 | Enumerations are integers with named values, similar to C. 5 | 6 | .. code-block:: mys 7 | 8 | enum Color: 9 | Red 10 | Green 11 | Blue 12 | 13 | enum City(u8): 14 | Linkoping = 5 15 | Norrkoping 16 | Vaxjo = 10 17 | 18 | func main(): 19 | assert Color(0) == Color.Red 20 | assert i64(Color.Blue) == 2 21 | assert City(5) == City.Linkoping 22 | 23 | try: 24 | print(Color(3)) 25 | except ValueError: 26 | print("value error") 27 | -------------------------------------------------------------------------------- /docs/language-reference/generics.rst: -------------------------------------------------------------------------------- 1 | Generics 2 | -------- 3 | 4 | Generic functions, classes and traits are useful to reuse logic for 5 | multiple types. 6 | 7 | Generic types cannot be optionals. 8 | 9 | Example code: 10 | 11 | .. code-block:: mys 12 | 13 | @generic(T1, T2) 14 | class Foo: 15 | a: T1 16 | b: T2 17 | 18 | @generic(T) 19 | func fie(v: T) -> T: 20 | return v 21 | 22 | func main(): 23 | print(Foo[bool, u8](True, 100)) 24 | print(Foo("Hello!", 5)) # Not yet implemented. 25 | 26 | print(fie[u8](2)) 27 | print(fie(1)) # Not yet implemented. 28 | 29 | Build and run: 30 | 31 | .. code-block:: myscon 32 | 33 | ❯ mys run 34 | ✔ Reading package configuration (0 seconds) 35 | ✔ Building (0.01 seconds) 36 | Foo(a: True, b: 100) 37 | Foo(a: "Hello!", b: 5) 38 | 2 39 | 1 40 | -------------------------------------------------------------------------------- /docs/language-reference/loops.rst: -------------------------------------------------------------------------------- 1 | Loops 2 | ----- 3 | 4 | ``while`` and ``for`` loops are available. 5 | 6 | ``while`` loops run until given condition is false or until 7 | ``break``. 8 | 9 | ``for`` loops can iterate over ranges, lists, dictionaries, strings, 10 | bytes and iterators. All but dictionaries and :doc:`iterators` 11 | supports combinations of ``enumerate()``, ``slice()``, ``reversed()`` 12 | and ``zip()``. Never modify variables you are iterating over, or the 13 | program may crash! 14 | 15 | .. code-block:: mys 16 | 17 | # While. 18 | v = 0 19 | 20 | while v < 10: 21 | if v < 3: 22 | continue 23 | elif v == 7: 24 | break 25 | 26 | v += 1 27 | 28 | # Ranges. 29 | for v in range(10): 30 | if v < 3: 31 | continue 32 | elif v == 7: 33 | break 34 | 35 | for i, v in enumerate(range(10, 4, -2)): 36 | pass 37 | 38 | # Lists. 39 | for v in [3, 1]: 40 | pass 41 | 42 | for i, v in enumerate([3, 1]): 43 | pass 44 | 45 | for v, s in zip([3, 1], ["a", "c"]): 46 | pass 47 | 48 | for v in slice([3, 1, 4, 2], 1, -1): 49 | pass 50 | 51 | for v in reversed([3, 1, 4, 2]): 52 | pass 53 | 54 | # Dictionaries. 55 | for k, v in {2: 5, 6: 2}: 56 | pass 57 | 58 | # Strings. 'c' is char. 59 | for c in "foo": 60 | pass 61 | 62 | for i, c in enumerate("foo"): 63 | pass 64 | 65 | # Bytes. 'b' is u8. 66 | for b in b"\x03\x78": 67 | pass 68 | 69 | for i, b in enumerate(b"\x03\x78"): 70 | pass 71 | -------------------------------------------------------------------------------- /docs/language-reference/macros.rst: -------------------------------------------------------------------------------- 1 | Macros 2 | ------ 3 | 4 | Macro function and method bodies are compiled into the body of the 5 | caller function or method. Macro parameters may be evaluated zero or 6 | more times. 7 | 8 | Macro names must be upper case to distinguish them from regular 9 | functions and methods. 10 | 11 | Possibly allow modifying the AST in macros in the future. 12 | 13 | .. code-block:: mys 14 | 15 | macro CHECK(cond: bool, message: string): 16 | if not cond: 17 | print(message) 18 | 19 | func not_four() -> string: 20 | print("Called not_four().") 21 | 22 | return "Not 4." 23 | 24 | func add(a: i64, b: i64) -> i64: 25 | print(f"Adding {a} and {b}.") 26 | 27 | return a + b 28 | 29 | class Logger: 30 | enabled: bool 31 | 32 | macro LOG(self, message: string): 33 | if self.enabled: 34 | print(message) 35 | 36 | func main(): 37 | logger = Logger(False) 38 | number = 4 39 | 40 | CHECK(number == 4, not_four()) 41 | 42 | print("Logging with logger disabled.") 43 | logger.LOG(f"3 + 4 = {add(3, number)}") 44 | 45 | print("Logging with logger enabled.") 46 | logger.enabled = True 47 | logger.LOG(f"3 + 4 = {add(3, number)}") 48 | 49 | Build and run: 50 | 51 | .. code-block:: myscon 52 | 53 | ❯ mys run 54 | ✔ Reading package configuration (0 seconds) 55 | ✔ Building (0.01 seconds) 56 | Logging with logger disabled. 57 | Logging with logger enabled. 58 | Adding 3 and 4. 59 | 3 + 4 = 7 60 | -------------------------------------------------------------------------------- /docs/language-reference/memory-management.rst: -------------------------------------------------------------------------------- 1 | Memory management 2 | ----------------- 3 | 4 | Integers and floating point numbers are allocated on the stack, passed 5 | by value to functions and returned by value from functions, just as 6 | any C++ program. 7 | 8 | Strings, bytes, tuples, lists, dicts and classes are normally 9 | allocated on the heap and managed by reference counting. Objects that 10 | are known not to outlive a function are allocated on the stack. 11 | 12 | .. warning:: 13 | 14 | Stack allocations are not yet implemented. 15 | 16 | Reference cycles are not detected and will result in memory leaks. The 17 | programmer must manually break reference cycles by using weak 18 | references where needed. Only class members can be weak references. 19 | 20 | .. code-block:: mys 21 | 22 | class Foo: 23 | parent: weak[Foo?] 24 | 25 | func main(): 26 | foo = Foo(None) 27 | foo.parent = foo 28 | 29 | There is no garbage collector. We want deterministic applications. 30 | -------------------------------------------------------------------------------- /docs/language-reference/modules-and-packages.rst: -------------------------------------------------------------------------------- 1 | Modules and packages 2 | -------------------- 3 | 4 | A package contains modules that other packages can import from. Most 5 | packages contains a file called ``lib.mys``, which is imported from 6 | with ``from import ``. 7 | 8 | Packages that contains ``src/main.mys`` produces executables when 9 | built. Such packages may also be imported from by other packages, in 10 | which case ``src/main.mys`` is ignored. 11 | 12 | A package: 13 | 14 | .. code-block:: text 15 | 16 | my_package/ 17 | ├── doc/ 18 | │ └── index.rst 19 | ├── LICENSE 20 | ├── package.toml 21 | ├── README.rst 22 | └── src/ 23 | ├── lib.mys 24 | └── main.mys # Only part of packages that can build executables. 25 | -------------------------------------------------------------------------------- /docs/language-reference/proposals.rst: -------------------------------------------------------------------------------- 1 | Proposals 2 | ========= 3 | 4 | Proposals to add, change or remove language features. 5 | 6 | .. toctree:: 7 | :glob: 8 | :maxdepth: 1 9 | 10 | proposals/copy 11 | proposals/process 12 | proposals/stackless_fibers 13 | proposals/traits 14 | proposals/tuples 15 | proposals/type_information 16 | -------------------------------------------------------------------------------- /docs/language-reference/proposals/copy.rst: -------------------------------------------------------------------------------- 1 | Copy 2 | ---- 3 | 4 | - Copy objects with the builtin functions ``copy()`` and 5 | ``deepcopy()``. 6 | 7 | - The ``__copy__(self, other: Self)`` method implements ``copy()`` and 8 | the ``__deepcopy__(self, other: Self)`` method implements 9 | ``deepcopy()``. Both have default implementations that simply copies 10 | all members. 11 | 12 | Example 13 | ^^^^^^^ 14 | 15 | .. code-block:: mys 16 | 17 | class Foo: 18 | a: i64 19 | b: string 20 | 21 | class Bar: 22 | foo: Foo 23 | 24 | func main(): 25 | foo = Foo(5, "bar") 26 | foo_copy = copy(foo) 27 | assert foo == foo_copy 28 | assert foo is not foo_copy 29 | 30 | bar = Bar(foo) 31 | bar_copy = copy(bar) 32 | assert bar_copy.foo is bar.foo 33 | bar_deepcopy = deepcopy(bar) 34 | assert bar_deepcopy.foo is not bar.foo 35 | 36 | .. code-block:: mys 37 | 38 | class Foo: 39 | 40 | func __copy__(self, other: Foo): 41 | raise NotImplementedError() 42 | 43 | func __deepcopy__(self, other: Foo): 44 | raise NotImplementedError() 45 | 46 | func main(): 47 | try: 48 | print(copy(Foo())) 49 | except NotImplementedError: 50 | pass 51 | 52 | try: 53 | print(deepcopy(Foo())) 54 | except NotImplementedError: 55 | pass 56 | -------------------------------------------------------------------------------- /docs/language-reference/proposals/traits.rst: -------------------------------------------------------------------------------- 1 | Traits 2 | ------ 3 | 4 | Use ``+`` to require multiple traits. 5 | 6 | .. code-block:: mys 7 | 8 | trait Foo: 9 | pass 10 | 11 | trait Bar: 12 | pass 13 | 14 | trait Fie: 15 | pass 16 | 17 | func foo(value: Foo + Bar + Fie) -> Bar + Fie: 18 | return value 19 | -------------------------------------------------------------------------------- /docs/language-reference/proposals/tuples.rst: -------------------------------------------------------------------------------- 1 | Tuples 2 | ------ 3 | 4 | Remove tuples from the language. 5 | 6 | Allow returning and yielding multiple values. 7 | -------------------------------------------------------------------------------- /docs/language-reference/proposals/type_information.rst: -------------------------------------------------------------------------------- 1 | Type information 2 | ---------------- 3 | 4 | Type information in both build- and runtime. 5 | 6 | Builtin function ``type()`` returns given variables type information 7 | in runtime. 8 | 9 | .. code-block:: mys 10 | 11 | class type: 12 | id: i64 13 | name: string 14 | 15 | Above members can be accessed in buildtime. 16 | -------------------------------------------------------------------------------- /docs/language-reference/regular-expressions.rst: -------------------------------------------------------------------------------- 1 | Regular Expressions 2 | ------------------- 3 | 4 | Regular expressions are part of the language. The string type has 5 | methods that takes regular expressions, for example ``match()``, 6 | ``split()`` and ``replace()``. 7 | 8 | An example 9 | ^^^^^^^^^^ 10 | 11 | .. code-block:: mys 12 | 13 | func main(): 14 | # Match. 15 | mo = "I am 6 years old.".match(re"(\d+) years") 16 | print("mo: ", mo) 17 | print("mo.group(1):", mo.group(1)) 18 | 19 | # Split. 20 | print("split(): ", "I have 15 apples and 3 bananas.".split(re"\d+")) 21 | 22 | # Case-insensitive replace. 23 | print("replace(): ", "I want more AppLEs.".replace(re"apples"i, "bananas")) 24 | 25 | .. code-block:: myscon 26 | 27 | ❯ mys run 28 | ✔ Reading package configuration (0 seconds) 29 | ✔ Building (0.01 seconds) 30 | mo: RegexMatch(span=(5, 12), match="6 years") 31 | mo.group(1): 6 32 | split(): ["I have ", " apples and ", " bananas."] 33 | replace(): I want more bananas. 34 | -------------------------------------------------------------------------------- /docs/language-reference/type-conversions.rst: -------------------------------------------------------------------------------- 1 | Type conversions 2 | ---------------- 3 | 4 | Implicit type conversions are only supported for numeric literals and 5 | traits. 6 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=source 11 | set BUILDDIR=build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.http://sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/standard-library.rst: -------------------------------------------------------------------------------- 1 | Standard Library 2 | ================ 3 | 4 | There is no standard library part of the installation. Functionality 5 | classically in the standard library and functionality in third party 6 | packages are considered equally important and are all 7 | downloaded/copied and built automatically when listed as dependencies 8 | to your package. 9 | 10 | Using 11 | ----- 12 | 13 | To use packages in your project, just add them to the dependencies 14 | section in your ``package.toml``-file. 15 | 16 | .. code-block:: toml 17 | 18 | [dependencies] 19 | random = "latest" 20 | base64 = "latest" 21 | 22 | Publishing 23 | ---------- 24 | 25 | Publish a package by running ``mys publish`` in your package's root 26 | folder. A token is printed the first time a package is published. This 27 | token is required to publish the package again, so make sure to save 28 | it. Run ``mys publish -t `` to publish with a token. 29 | 30 | Delete a published package with ``mys delete ``. 31 | 32 | Packages 33 | -------- 34 | 35 | Number of packages: {website-number-of-packages} 36 | 37 | Number of downloads: {website-number-of-downloads} 38 | 39 | {website-packages} 40 | 41 | API 42 | --- 43 | 44 | There is a `GraphQL`_ end-point, https://mys-lang.org/graphql, that 45 | provides standard library information. 46 | 47 | .. _GraphQL: https://graphql.org 48 | -------------------------------------------------------------------------------- /docs/statistics.rst: -------------------------------------------------------------------------------- 1 | Statistics 2 | ========== 3 | 4 | Website statistics. 5 | 6 | Start date and time 7 | ------------------- 8 | 9 | {website-start-date-time} 10 | 11 | Traffic 12 | ------- 13 | 14 | Unique visitors 15 | ^^^^^^^^^^^^^^^ 16 | 17 | Number of unique visitors: {website-number-of-unique-visitors} 18 | 19 | .. image:: _static/world.svg 20 | 21 | - Green: Latest request succeeded. 22 | 23 | - Red: Latest request failed. 24 | 25 | Requests 26 | ^^^^^^^^ 27 | 28 | Number of requests: {website-number-of-requests} 29 | 30 | {website-requests} 31 | 32 | Referring sites 33 | ^^^^^^^^^^^^^^^ 34 | 35 | {website-referrers} 36 | 37 | API 38 | --- 39 | 40 | There is a `GraphQL`_ end-point, https://mys-lang.org/graphql, that 41 | provides statistics. 42 | 43 | .. _GraphQL: https://graphql.org 44 | -------------------------------------------------------------------------------- /docs/user-guide.rst: -------------------------------------------------------------------------------- 1 | User Guide 2 | ========== 3 | 4 | This guide is intended for users of the Mys programming 5 | language. 6 | 7 | Read the :doc:`language-reference` to explore Mys further. 8 | 9 | .. toctree:: 10 | :glob: 11 | :maxdepth: 1 12 | 13 | user-guide/getting-started 14 | user-guide/getting-help 15 | user-guide/installation 16 | user-guide/the-mys-command 17 | user-guide/text-editor-settings 18 | user-guide/calling-mys-from-make 19 | user-guide/notable-differences-to-python 20 | -------------------------------------------------------------------------------- /docs/user-guide/calling-mys-from-make.rst: -------------------------------------------------------------------------------- 1 | Calling mys from GNU Make recipe 2 | -------------------------------- 3 | 4 | ``mys`` uses ``make`` internally. Always prepend the command with 5 | ``+`` to share jobserver. 6 | -------------------------------------------------------------------------------- /docs/user-guide/getting-help.rst: -------------------------------------------------------------------------------- 1 | Getting help 2 | ============ 3 | 4 | These are the official help channels: 5 | 6 | - Ask for help in the `#help channel`_ on the Mys Discord server. 7 | 8 | - Search and create new discussions in `Discussions`_. 9 | 10 | - Write an `issue`_ if you found a bug or want to propose a feature 11 | request. 12 | 13 | .. _Discussions: https://github.com/mys-lang/mys/discussions 14 | 15 | .. _#help channel: https://discord.com/invite/KeusvGPbd4 16 | 17 | .. _issue: https://github.com/mys-lang/mys/issues 18 | -------------------------------------------------------------------------------- /docs/user-guide/installation.rst: -------------------------------------------------------------------------------- 1 | Installation 2 | ============ 3 | 4 | Linux 5 | ^^^^^ 6 | 7 | #. Install recent versions of ``g++``, ``make`` and ``ccache``. 8 | 9 | #. Install Python 3.8 or later, and then install Mys using ``pip3``. 10 | 11 | .. code-block:: text 12 | 13 | pip3 install mys 14 | 15 | #. Run ``mys`` to make sure it was installed successfully. 16 | 17 | .. code-block:: text 18 | 19 | mys 20 | 21 | macOS 22 | ^^^^^ 23 | 24 | #. Install recent versions of ``ccache`` and ``pkg-config`` using 25 | ``brew``. 26 | 27 | #. Install Python 3.8 or later, and then install Mys using ``pip``. 28 | 29 | .. code-block:: text 30 | 31 | pip3 install mys 32 | 33 | #. Run ``mys`` to make sure it was installed successfully. 34 | 35 | .. code-block:: text 36 | 37 | mys 38 | 39 | Windows 40 | ^^^^^^^ 41 | 42 | #. Install `Cygwin`_. Required packages are ``gcc-g++``, ``make``, 43 | ``python38``, ``python38-pip``, ``python38-devel`` and ``ccache``. 44 | 45 | #. Start Cygwin and install Mys. 46 | 47 | .. code-block:: text 48 | 49 | python -m pip install mys 50 | 51 | #. Run ``mys`` to make sure it was installed successfully. 52 | 53 | .. code-block:: text 54 | 55 | mys 56 | 57 | .. _Cygwin: https://www.cygwin.com/ 58 | -------------------------------------------------------------------------------- /docs/user-guide/notable-differences-to-python.rst: -------------------------------------------------------------------------------- 1 | Notable differences to Python 2 | ----------------------------- 3 | 4 | Mys looks a lot like Python, but there are differences. Below is a 5 | list of the most notable differences that we could think of. 6 | 7 | - Traits instead of classic inheritence. 8 | 9 | - Statically typed. 10 | 11 | - Bytes are mutable. 12 | 13 | - Integers are bound (i32, u32, i64, ...). 14 | 15 | - Iterators/generators do not (yet?) exist. 16 | 17 | - Rust-like generic functions and classes. 18 | 19 | - Only packages. No stand alone modules. 20 | 21 | - Compiled to machine code. No interpreter. 22 | 23 | - Data races and memory corruption possible, but unlikely. 24 | 25 | - No async. 26 | 27 | - Only ``from ... import ...`` is allowed. ``import ...`` is not. 28 | 29 | - Only functions, enums, traits, classes and variables can be 30 | imported, not modules. 31 | 32 | - Ruby-like built in regular expressions. 33 | 34 | - Indentations must be 4 spaces. 35 | -------------------------------------------------------------------------------- /docs/user-guide/text-editor-settings.rst: -------------------------------------------------------------------------------- 1 | Text editor settings 2 | -------------------- 3 | 4 | Visual Code 5 | ^^^^^^^^^^^ 6 | 7 | Use the Python language for ``*.mys`` files by modifying your 8 | ``files.associations`` setting. 9 | 10 | See the `official Visual Code guide`_ for more detils. 11 | 12 | .. code-block:: json 13 | 14 | "files.associations": { 15 | "*.mys": "python" 16 | } 17 | 18 | Emacs 19 | ^^^^^ 20 | 21 | Use the Python mode for ``*.mys`` files by adding the following to 22 | your ``.emacs`` configuration file. 23 | 24 | .. code-block:: emacs 25 | 26 | (add-to-list 'auto-mode-alist '("\\.mys\\'" . python-mode)) 27 | 28 | .. _official Visual Code guide: https://code.visualstudio.com/docs/languages/overview#_adding-a-file-extension-to-a-language 29 | -------------------------------------------------------------------------------- /examples/README.rst: -------------------------------------------------------------------------------- 1 | Examples 2 | ======== 3 | 4 | This folder contains various examples. -------------------------------------------------------------------------------- /examples/callbacks/README.rst: -------------------------------------------------------------------------------- 1 | Callbacks 2 | ========= 3 | 4 | Using objects with virtual methods as callbacks. 5 | 6 | .. code-block:: text 7 | 8 | $ mys run 9 | Available commands: 10 | hi 11 | exit 12 | > hi 13 | Hi! 14 | > exit 15 | Bye! 16 | $ 17 | -------------------------------------------------------------------------------- /examples/callbacks/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "callbacks" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/callbacks/src/main.mys: -------------------------------------------------------------------------------- 1 | trait Handler: 2 | 3 | func execute(self): 4 | pass 5 | 6 | class Commands: 7 | _handlers: {string: Handler} 8 | 9 | func __init__(self): 10 | self._handlers = {} 11 | 12 | func register_command(self, name: string, handler: Handler): 13 | self._handlers[name] = handler 14 | 15 | func execute(self, name: string): 16 | handler = self._handlers.get(name, None) 17 | 18 | if handler is not None: 19 | handler.execute() 20 | elif name != "": 21 | print(f"Unknown command {name}.") 22 | 23 | func print_help(self): 24 | print("Available commands:") 25 | 26 | for name in self._handlers.keys(): 27 | print(" ", name) 28 | 29 | class HiHandler(Handler): 30 | _count: u64 31 | 32 | func execute(self): 33 | self._count += 1 34 | print(f"Hi #{self._count}!") 35 | 36 | class ExitHandler(Handler): 37 | 38 | func execute(self): 39 | print("Bye!") 40 | 41 | raise SystemExitError("exit") 42 | 43 | func main(): 44 | commands = Commands() 45 | commands.register_command("hi", HiHandler()) 46 | commands.register_command("exit", ExitHandler()) 47 | commands.print_help() 48 | 49 | while True: 50 | command = input("> ") 51 | 52 | try: 53 | commands.execute(command) 54 | except: 55 | break 56 | -------------------------------------------------------------------------------- /examples/ctrl_c/README.rst: -------------------------------------------------------------------------------- 1 | Ctrl-C 2 | ====== 3 | 4 | A small example of how to use Ctrl-C. 5 | 6 | .. code-block:: 7 | 8 | $ mys run 9 | -------------------------------------------------------------------------------- /examples/ctrl_c/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ctrl_c" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/ctrl_c/src/main.mys: -------------------------------------------------------------------------------- 1 | from fiber import sleep 2 | 3 | func main(): 4 | print("Press Ctrl-C to exit.") 5 | 6 | try: 7 | sleep(3600.0) 8 | except InterruptError: 9 | print("Interrupted!") 10 | -------------------------------------------------------------------------------- /examples/default_and_named_parameters/README.rst: -------------------------------------------------------------------------------- 1 | Default and named parameters 2 | ============================ 3 | 4 | .. code-block:: text 5 | 6 | $ mys run 7 | foo(): 1 8 | foo(2): 2 9 | bar(1): 6 10 | fie(c=4, a=1): 15 11 | fum(): 1 12 | fum(b=Fum(2)): 3 13 | -------------------------------------------------------------------------------- /examples/default_and_named_parameters/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "default_and_named_parameters" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/default_and_named_parameters/src/main.mys: -------------------------------------------------------------------------------- 1 | func foo(a: i64 = 1) -> i64: 2 | return a 3 | 4 | func bar(a: i64, b: string = "5") -> i64: 5 | return a + i64(b) 6 | 7 | func fie(a: i64, b: string = "10", c: i64 = 2) -> i64: 8 | return a + i64(b) + c 9 | 10 | class Fum: 11 | value: i64 12 | 13 | func fum(a: Fum = Fum(1), b: Fum? = None) -> i64: 14 | if b is not None: 15 | return a.value + b.value 16 | else: 17 | return a.value 18 | 19 | func main(): 20 | print("foo(): ", foo()) 21 | print("foo(2): ", foo(2)) 22 | print("bar(1): ", bar(1)) 23 | print("fie(c=4, a=1):", fie(c=4, a=1)) 24 | print("fum(): ", fum()) 25 | print("fum(b=Fum(2)):", fum(b=Fum(2))) 26 | -------------------------------------------------------------------------------- /examples/embedded_cpp/README.rst: -------------------------------------------------------------------------------- 1 | Embedded C++ 2 | ============ 3 | 4 | A small example of how to extend Mys with C++. 5 | 6 | .. code-block:: 7 | 8 | $ mys run 9 | a + b: 5 10 | -------------------------------------------------------------------------------- /examples/embedded_cpp/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "embedded_cpp" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/embedded_cpp/src/cpp/bar.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Just an empty file. 4 | -------------------------------------------------------------------------------- /examples/embedded_cpp/src/cpp/foo.cpp: -------------------------------------------------------------------------------- 1 | #include "foo.hpp" 2 | #include "bar.hpp" 3 | 4 | // It's good practice to use the package namespace is possible. 5 | namespace mys::embedded_cpp::foo 6 | { 7 | 8 | int foobar(int v) 9 | { 10 | return 2 * v; 11 | } 12 | 13 | }; 14 | -------------------------------------------------------------------------------- /examples/embedded_cpp/src/cpp/foo.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // It's good practice to use the package namespace is possible. 4 | namespace mys::embedded_cpp::foo 5 | { 6 | int foobar(int v); 7 | }; 8 | -------------------------------------------------------------------------------- /examples/embedded_cpp/src/main.mys: -------------------------------------------------------------------------------- 1 | c"""source-before-namespace 2 | #include "cpp/foo.hpp" 3 | """ 4 | 5 | func main(): 6 | a = 0 7 | b = 0 8 | 9 | c""" 10 | b = foo::foobar(2); 11 | a++; 12 | """ 13 | 14 | print("a + b:", a + b) 15 | -------------------------------------------------------------------------------- /examples/enums/README.rst: -------------------------------------------------------------------------------- 1 | Enumerations 2 | ============ 3 | 4 | .. code-block:: text 5 | 6 | $ mys run 7 | Color.Green: 1 8 | Color(1): 1 9 | i64(Color.Green): 1 10 | Color(4): ValueError(message="enum Color does not contain 4") 11 | -------------------------------------------------------------------------------- /examples/enums/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "enums" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/enums/src/main.mys: -------------------------------------------------------------------------------- 1 | enum Color: 2 | Red 3 | Green 4 | Blue 5 | Yellow 6 | 7 | func main(): 8 | print("Color.Green: ", Color.Green) 9 | print("Color(1): ", Color(1)) 10 | print("i64(Color.Green):", i64(Color.Green)) 11 | 12 | try: 13 | print(Color(4)) 14 | except ValueError as error: 15 | print("Color(4): ", error) 16 | -------------------------------------------------------------------------------- /examples/errors/README.rst: -------------------------------------------------------------------------------- 1 | Errors 2 | ====== 3 | 4 | A small example of how to use errors. 5 | 6 | .. code-block:: 7 | 8 | $ mys run 9 | ValueError 10 | finally 11 | -------------------------------------------------------------------------------- /examples/errors/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "exceptions" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/errors/src/main.mys: -------------------------------------------------------------------------------- 1 | func main(): 2 | try: 3 | try: 4 | raise ValueError() 5 | except ValueError: 6 | print("ValueError") 7 | finally: 8 | print("finally") 9 | -------------------------------------------------------------------------------- /examples/fibers/README.rst: -------------------------------------------------------------------------------- 1 | Fibers 2 | ====== 3 | 4 | An example using fibers for `concurrency`_. 5 | 6 | Build and run the program. 7 | 8 | .. code-block:: text 9 | 10 | $ mys run 11 | ✔ Reading package configuration (0 seconds) 12 | ✔ Building (0.58 seconds) 13 | Sleeper run. 14 | Producer run. 15 | Consumer run. 16 | Consumer got 1. 17 | Consumer got 2. 18 | Consumer got 3. 19 | Sleeper awake. 20 | Consumer got 4. 21 | Consumer got 5. 22 | Consumer got 6. 23 | Sleeper awake. 24 | Consumer got 7. 25 | Consumer got 8. 26 | Consumer got 9. 27 | Sleeper awake. 28 | Consumer got 10. 29 | 30 | .. _concurrency: https://mys-lang.org/language-reference/concurrency.html 31 | -------------------------------------------------------------------------------- /examples/fibers/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fibers" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/fibers/src/main.mys: -------------------------------------------------------------------------------- 1 | from fiber import Fiber 2 | from fiber import Queue 3 | from fiber import sleep 4 | 5 | class Sleeper(Fiber): 6 | 7 | func run(self): 8 | print("Sleeper run.") 9 | 10 | while True: 11 | sleep(3.0) 12 | print("Sleeper awake.") 13 | 14 | class Producer(Fiber): 15 | queue: Queue[i64] 16 | 17 | func run(self): 18 | print("Producer run.") 19 | counter = 0 20 | 21 | while True: 22 | counter += 1 23 | self.queue.put(counter) 24 | sleep(1.0) 25 | 26 | class Consumer(Fiber): 27 | queue: Queue[i64] 28 | 29 | func run(self): 30 | print("Consumer run.") 31 | 32 | while True: 33 | count = self.queue.get() 34 | print(f"Consumer got {count}.") 35 | 36 | func main(): 37 | sleeper = Sleeper() 38 | queue = Queue[i64]() 39 | producer = Producer(queue) 40 | consumer = Consumer(queue) 41 | 42 | sleeper.start() 43 | producer.start() 44 | consumer.start() 45 | 46 | sleep(10.0) 47 | #input("Press to exit.") 48 | -------------------------------------------------------------------------------- /examples/fibonacci/README.rst: -------------------------------------------------------------------------------- 1 | Fibonacci 2 | ========= 3 | 4 | A small example that prints the first 11 Fibonacci numbers. 5 | 6 | .. code-block:: 7 | 8 | $ mys run 9 | fibonacci(0): 0 10 | fibonacci(1): 1 11 | fibonacci(2): 1 12 | fibonacci(3): 2 13 | fibonacci(4): 3 14 | fibonacci(5): 5 15 | fibonacci(6): 8 16 | fibonacci(7): 13 17 | fibonacci(8): 21 18 | fibonacci(9): 34 19 | fibonacci(10): 55 20 | 21 | Run the test. 22 | 23 | .. code-block:: 24 | 25 | $ mys test 26 | -------------------------------------------------------------------------------- /examples/fibonacci/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fibonacci" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/fibonacci/src/main.mys: -------------------------------------------------------------------------------- 1 | func fibonacci(number: u64) -> u64: 2 | if number <= 1: 3 | return number 4 | else: 5 | return fibonacci(number - 1) + fibonacci(number - 2) 6 | 7 | func main(): 8 | for i in range(11): 9 | print(f"fibonacci({u64(i)}): {fibonacci(u64(i))}") 10 | 11 | test fibonacci(): 12 | assert fibonacci(0) == 0 13 | assert fibonacci(1) == 1 14 | assert fibonacci(2) == 1 15 | assert fibonacci(3) == 2 16 | assert fibonacci(7) == 13 17 | -------------------------------------------------------------------------------- /examples/fizz_buzz/README.rst: -------------------------------------------------------------------------------- 1 | Fizz buzz 2 | ========= 3 | 4 | First 25 Fizz buzz values. 5 | 6 | .. code-block:: 7 | 8 | $ mys run 9 | 1 10 | 2 11 | Fizz 12 | 4 13 | Buzz 14 | Fizz 15 | 7 16 | 8 17 | Fizz 18 | Buzz 19 | 11 20 | Fizz 21 | 13 22 | 14 23 | Fizz buzz 24 | 16 25 | 17 26 | Fizz 27 | 19 28 | Buzz 29 | Fizz 30 | 22 31 | 23 32 | Fizz 33 | Buzz 34 | -------------------------------------------------------------------------------- /examples/fizz_buzz/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fizz_buzz" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/fizz_buzz/src/main.mys: -------------------------------------------------------------------------------- 1 | func main(): 2 | for i in range(1, 26): 3 | if i % 15 == 0: 4 | print("Fizz buzz") 5 | elif i % 3 == 0: 6 | print("Fizz") 7 | elif i % 5 == 0: 8 | print("Buzz") 9 | else: 10 | print(i) 11 | -------------------------------------------------------------------------------- /examples/generics/README.rst: -------------------------------------------------------------------------------- 1 | Generics 2 | ======== 3 | 4 | Genric functions and classes. 5 | 6 | .. code-block:: text 7 | 8 | $ mys run 9 | triple[u8](5): 15 10 | Adder[i64]: Adder(value=8) 11 | -------------------------------------------------------------------------------- /examples/generics/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "generics" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/generics/src/main.mys: -------------------------------------------------------------------------------- 1 | # Should probably be replaced by "func triple(value: T) -> T:" 2 | # eventually. 3 | @generic(T) 4 | func triple(value: T) -> T: 5 | return 3 * value 6 | 7 | # Should probably be replaced by "class Adder:" eventually. 8 | @generic(T) 9 | class Adder: 10 | 11 | value: T 12 | 13 | func add(self, value: T): 14 | self.value += value 15 | 16 | # Should probably be replaced by "Adder64 = Adder" eventually. We 17 | # want aliases, right? 18 | # Adder64 = Adder[i64] 19 | 20 | func main(): 21 | # Should probably be replaced by "print(triple(5))" 22 | # eventually. 23 | print("triple[u8](5):", triple[u8](5)) 24 | 25 | # Should probably be replaced by "adder = Adder()" 26 | # eventually. 27 | adder = Adder[i64](5) 28 | adder.add(3) 29 | print("Adder[i64]: ", adder) 30 | 31 | # adder64 = Adder64() 32 | # adder64.add(3) 33 | # print(adder64.value) 34 | -------------------------------------------------------------------------------- /examples/hash/README.rst: -------------------------------------------------------------------------------- 1 | Hash objects 2 | ============ 3 | 4 | .. code-block:: text 5 | 6 | $ mys run 7 | hash(1): 1 8 | hash("Hello!"): 112312398 9 | hash(Foo(1)): 1 10 | hash(Foo(2)): 2 11 | hash(Bar(1)): 1 12 | hash(Bar(2)): 2 13 | -------------------------------------------------------------------------------- /examples/hash/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hash" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/hash/src/main.mys: -------------------------------------------------------------------------------- 1 | class Foo: 2 | x: i64 3 | 4 | func __hash__(self) -> i64: 5 | return hash(self.x) 6 | 7 | class Bar: 8 | x: i64 9 | 10 | func main(): 11 | print("hash(1): ", hash(1)) 12 | print("hash(\"Hello!\"):", hash("Hello!")) 13 | print("hash(Foo(1)): ", hash(Foo(1))) 14 | print("hash(Foo(2)): ", hash(Foo(2))) 15 | print("hash(Bar(1)): ", hash(Bar(1))) 16 | print("hash(Bar(2)): ", hash(Bar(2))) 17 | -------------------------------------------------------------------------------- /examples/hello_world/README.rst: -------------------------------------------------------------------------------- 1 | Hello world 2 | =========== 3 | 4 | The hello world example. 5 | 6 | .. code-block:: 7 | 8 | $ mys run 9 | Hello, world! 10 | -------------------------------------------------------------------------------- /examples/hello_world/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hello_world" 3 | version = "0.5.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/hello_world/src/main.mys: -------------------------------------------------------------------------------- 1 | func main(): 2 | print("Hello, world!") 3 | -------------------------------------------------------------------------------- /examples/local_variables/README.rst: -------------------------------------------------------------------------------- 1 | Local variables 2 | =============== 3 | 4 | Local variables are defined in outer scope if set in all branches. 5 | 6 | .. code-block:: text 7 | 8 | $ mys run 2 9 | all_branches: -2 10 | try_set_in_except: -2 11 | try_except_ignore: -2 12 | -------------------------------------------------------------------------------- /examples/local_variables/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "local_variables" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/macro/README.rst: -------------------------------------------------------------------------------- 1 | Macro function and methods 2 | ========================== 3 | 4 | - Macro functions and methods bodies compiled into the body of the 5 | caller function or method. 6 | 7 | - Parameters have types and may be evaluated zero or more times. 8 | 9 | - Macro functions and methods may not return any value. 10 | 11 | .. code-block:: text 12 | 13 | $ mys run 14 | ✔ Reading package configuration (0 seconds) 15 | ✔ Building (0.01 seconds) 16 | Logging with logger disabled. 17 | Logging with logger enabled. 18 | Adding 3 and 4. 19 | 3 + 4 = 7 20 | -------------------------------------------------------------------------------- /examples/macro/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "macro" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/macro/src/main.mys: -------------------------------------------------------------------------------- 1 | macro CHECK(cond: bool, message: string): 2 | if not cond: 3 | print(message) 4 | 5 | func not_four() -> string: 6 | print("Called not_four().") 7 | 8 | return "Not 4." 9 | 10 | func add(a: i64, b: i64) -> i64: 11 | print(f"Adding {a} and {b}.") 12 | 13 | return a + b 14 | 15 | class Logger: 16 | enabled: bool 17 | 18 | macro LOG(self, message: string): 19 | if self.enabled: 20 | print(message) 21 | 22 | func main(): 23 | logger = Logger(False) 24 | number = 4 25 | 26 | CHECK(number == 4, not_four()) 27 | 28 | print("Logging with logger disabled.") 29 | logger.LOG(f"3 + 4 = {add(3, number)}") 30 | 31 | print("Logging with logger enabled.") 32 | logger.enabled = True 33 | logger.LOG(f"3 + 4 = {add(3, number)}") 34 | -------------------------------------------------------------------------------- /examples/optionals/README.rst: -------------------------------------------------------------------------------- 1 | Optionals 2 | ========= 3 | 4 | An example using optionals. 5 | 6 | .. code-block:: text 7 | 8 | $ mys run 9 | Matched None. 10 | Matched 10. 11 | Matched 10. 12 | Matched None. 13 | Matched 0. 14 | res does not have a value 15 | Matched 0. 16 | res has a value 17 | -------------------------------------------------------------------------------- /examples/optionals/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "optionals" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/optionals/src/main.mys: -------------------------------------------------------------------------------- 1 | func foo(a: i64, b: i64? = None) -> i64?: 2 | # Compare to `None` to check for value existence. 3 | if b is not None: 4 | b += b 5 | a += b 6 | 7 | # Optionals can be matched. 8 | match b: 9 | case 1: 10 | print("Matched one.") 11 | case 5: 12 | print("Matched five.") 13 | case None: 14 | print("Matched None.") 15 | case _: 16 | print(f"Matched {b}.") 17 | 18 | # Clear any value. 19 | b = None 20 | 21 | # Adding `b` without a value will terminate the application. 22 | # a += b 23 | 24 | # `None` and `b` (type i64) can be returned as optional. 25 | if a == 0: 26 | return None 27 | else: 28 | return a 29 | 30 | func main(): 31 | assert foo(1, None) == 1 32 | assert foo(1, 5) == 11 33 | b: i64? = 5 34 | assert foo(1, b) == 11 35 | assert foo(0) is None 36 | 37 | for i in range(2): 38 | res = foo(i, 0) 39 | 40 | if res is not None: 41 | print("res has a value") 42 | else: 43 | print("res does not have a value") 44 | -------------------------------------------------------------------------------- /examples/pattern_matching/README.rst: -------------------------------------------------------------------------------- 1 | Pattern matching 2 | ================ 3 | 4 | Use pattern matching to promote an object to its class from one of its 5 | traits. Pattern matching can match object contents or value as well. 6 | 7 | .. code-block:: 8 | 9 | $ mys run 10 | Class Foo with a=1 and b="hi". 11 | Class Foo with a=2 and b="ho". 12 | Class Foo. 13 | Class Bar. 14 | Other class: Fie() 15 | Zero integer. 16 | Five integer. 17 | String foo. 18 | Other string: bar 19 | -------------------------------------------------------------------------------- /examples/pattern_matching/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pattern_matching" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/pattern_matching/src/main.mys: -------------------------------------------------------------------------------- 1 | trait Base: 2 | pass 3 | 4 | class Foo(Base): 5 | a: i64 6 | b: string 7 | 8 | class Bar(Base): 9 | pass 10 | 11 | class Fie(Base): 12 | pass 13 | 14 | func classes(base: Base): 15 | # Foo() and Bar() just means these classes with any state. No 16 | # instance is created, just the type is checked. 17 | match base: 18 | case Foo(a=1) as foo: 19 | print(f"Class Foo with a=1 and b=\"{foo.b}\".") 20 | case Foo(a=2, b="ho"): 21 | print("Class Foo with a=2 and b=\"ho\".") 22 | case Foo(): 23 | print("Class Foo.") 24 | case Bar(): 25 | print("Class Bar.") 26 | case _: 27 | print(f"Other class: {base}") 28 | 29 | func numbers(value: i64): 30 | match value: 31 | case 0: 32 | print("Zero integer.") 33 | case 5: 34 | print("Five integer.") 35 | 36 | func strings(value: string): 37 | match value: 38 | case "foo": 39 | print("String foo.") 40 | case _: 41 | print(f"Other string: {value}") 42 | 43 | func main(): 44 | classes(Foo(1, "hi")) 45 | classes(Foo(2, "ho")) 46 | classes(Foo(3, "")) 47 | classes(Bar()) 48 | classes(Fie()) 49 | numbers(0) 50 | numbers(1) 51 | numbers(5) 52 | strings("foo") 53 | strings("bar") 54 | -------------------------------------------------------------------------------- /examples/pi/README.rst: -------------------------------------------------------------------------------- 1 | Calculate pi 2 | ============ 3 | 4 | .. code-block:: 5 | 6 | $ mys run 7 | π = 3.125000 8 | π = 3.141593 9 | -------------------------------------------------------------------------------- /examples/pi/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pi" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/pi/src/main.mys: -------------------------------------------------------------------------------- 1 | # Calculate and print value of pi. 2 | # 3 | # Based on https://cone.jondgoodwin.com/play/index.html. 4 | # 5 | 6 | func pi(nterms: u32) -> f64: 7 | """Calculate pi using arc-sine fractional sequence. `nterms` is the 8 | number of fractional terms used to estimate pi. 9 | 10 | https://en.wikipedia.org/wiki/Approximations_of_%CF%80#Arcsine 11 | 12 | """ 13 | 14 | if nterms == 0: 15 | return 0.0 16 | 17 | # Initialize working values. 18 | result = 0.5 19 | seed = 1.0 20 | top = 1.0 21 | bot = 1.0 22 | twos = 2.0 23 | term = 0.0 24 | 25 | for _ in range(i64(nterms) - 1): 26 | # Calculate a new fraction and add to result. 27 | top *= seed 28 | bot *= seed + 1.0 29 | twos *= 2.0 * 2.0 30 | term = top / (bot * (seed + 2.0) * twos) 31 | result += term 32 | seed += 2.0 33 | 34 | result *= 6.0 35 | 36 | return result 37 | 38 | func main(): 39 | print(f"π = {pi(2)}") 40 | print(f"π = {pi(9)}") 41 | -------------------------------------------------------------------------------- /examples/prechelt_phone_number_encoding/README.rst: -------------------------------------------------------------------------------- 1 | Prechelt Phone Number Encoding 2 | ============================== 3 | 4 | An implementation of the `Prechelt Phone Number Encoding`_. 5 | 6 | Small example run 7 | ----------------- 8 | 9 | .. code-block:: text 10 | 11 | $ mys run -- dictionary.txt phone_numbers.txt 12 | ✔ Reading package configuration (0 seconds) 13 | ✔ Building (2.09 seconds) 14 | 5624-82: mir Tor 15 | 5624-82: Mix Tor 16 | 4824: Tor 4 17 | 4824: fort 18 | 4824: Torf 19 | 10/783--5: je Bo" da 20 | 10/783--5: je bo"s 5 21 | 10/783--5: neu o"d 5 22 | 381482: so 1 Tor 23 | 04824: 0 Tor 4 24 | 04824: 0 fort 25 | 04824: 0 Torf 26 | 27 | Big example run 28 | --------------- 29 | 30 | .. code-block:: text 31 | 32 | $ wget -O words.txt https://flownet.com/ron/papers/lisp-java/dictionary.txt 33 | $ wget https://flownet.com/ron/papers/lisp-java/input.txt 34 | $ mys run -- words.txt input.txt 35 | 36 | .. _Prechelt Phone Number Encoding: https://flownet.com/ron/papers/lisp-java/. 37 | -------------------------------------------------------------------------------- /examples/prechelt_phone_number_encoding/dictionary.txt: -------------------------------------------------------------------------------- 1 | an 2 | blau 3 | Bo" 4 | Boot 5 | bo"s 6 | da 7 | Fee 8 | fern 9 | Fest 10 | fort 11 | je 12 | jemand 13 | mir 14 | Mix 15 | Mixer 16 | Name 17 | neu 18 | o"d 19 | Ort 20 | so 21 | Tor 22 | Torf 23 | Wasser 24 | -------------------------------------------------------------------------------- /examples/prechelt_phone_number_encoding/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "prechelt_phone_number_encoding" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | 6 | [dependencies] 7 | os = "latest" 8 | argparse = "latest" 9 | string = "latest" 10 | -------------------------------------------------------------------------------- /examples/prechelt_phone_number_encoding/phone_numbers.txt: -------------------------------------------------------------------------------- 1 | 112 2 | 5624-82 3 | 4824 4 | 0721/608-4067 5 | 10/783--5 6 | 1078-913-5 7 | 381482 8 | 04824 9 | -------------------------------------------------------------------------------- /examples/private_and_public/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "private_and_public" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/private_and_public/src/lib.mys: -------------------------------------------------------------------------------- 1 | _A_PRIVATE_VARIABLE: i64 = 1 2 | 3 | A_PUBLIC_VARIABLE: i64 = 1 4 | 5 | class _APrivateClass: 6 | pass 7 | 8 | class APublicClass: 9 | """Public classes should be documented. 10 | 11 | """ 12 | 13 | _a_private_member: i64 14 | a_public_member: i64 15 | """Public data members should be documented. 16 | 17 | """ 18 | 19 | func _a_private_method(self): 20 | pass 21 | 22 | func a_public_method(self): 23 | """Public methods should be documented. 24 | 25 | """ 26 | 27 | func _a_private_function(): 28 | pass 29 | 30 | func a_public_function(): 31 | """Public functions should be documented. 32 | 33 | """ 34 | -------------------------------------------------------------------------------- /examples/private_and_public/src/main.mys: -------------------------------------------------------------------------------- 1 | from private_and_public import APublicClass 2 | from private_and_public import A_PUBLIC_VARIABLE 3 | from private_and_public import a_public_function 4 | 5 | # Importing variables, private classes or private functions will give 6 | # a build error. 7 | 8 | # from private_and_public import _A_PRIVATE_VARIABLE 9 | # from private_and_public import _APrivateClass 10 | # from private_and_public import _a_private_function 11 | 12 | func main(): 13 | a_obj = APublicClass(5) 14 | a_obj.a_public_method() 15 | print(a_obj.a_public_member) 16 | # Private members can't be used. 17 | # a_obj._a_private_method() 18 | # print(a_obj._a_private_member) 19 | a_public_function() 20 | -------------------------------------------------------------------------------- /examples/ray_tracing/README.rst: -------------------------------------------------------------------------------- 1 | Ray tracing 2 | =========== 3 | 4 | A ray tracing example based on `rtiow Nelua`_. 5 | 6 | Run the commands 7 | 8 | .. code-block:: text 9 | 10 | $ mys run 11 | $ eog output.ppm 12 | 13 | and you should see 14 | 15 | .. image:: https://github.com/mys-lang/mys/blob/main/examples/ray_tracing/output.png 16 | .. _rtiow Nelua: https://github.com/nsauzede/realist/tree/master/rtiow/Nelua 17 | -------------------------------------------------------------------------------- /examples/ray_tracing/output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mys-lang/mys/f3cb604e95eadd9833466dbd43ac9f5913f31d60/examples/ray_tracing/output.png -------------------------------------------------------------------------------- /examples/ray_tracing/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ray_tracing" 3 | version = "0.1.0" 4 | authors = ["Erik Moqvist "] 5 | 6 | [dependencies] 7 | math = "latest" 8 | os = "latest" 9 | -------------------------------------------------------------------------------- /examples/ray_tracing/src/ray.mys: -------------------------------------------------------------------------------- 1 | from .vec import Vec3 2 | 3 | class Ray: 4 | origin: Vec3 5 | direction: Vec3 6 | 7 | func point_at_parameter(self, t: f32) -> Vec3: 8 | return self.origin + self.direction * t 9 | -------------------------------------------------------------------------------- /examples/ray_tracing/src/vec.mys: -------------------------------------------------------------------------------- 1 | from math import sqrt 2 | 3 | class Vec3: 4 | x: f32 5 | y: f32 6 | z: f32 7 | 8 | func +(self, other: Vec3) -> Vec3: 9 | return Vec3(self.x + other.x, self.y + other.y, self.z + other.z) 10 | 11 | func -(self, other: Vec3) -> Vec3: 12 | return Vec3(self.x - other.x, self.y - other.y, self.z - other.z) 13 | 14 | func *(self, t: f32) -> Vec3: 15 | return Vec3(self.x * t, self.y * t, self.z * t) 16 | 17 | func /(self, t: f32) -> Vec3: 18 | return Vec3(self.x / t, self.y / t, self.z / t) 19 | 20 | func dot(self, other: Vec3) -> f32: 21 | return self.x * other.x + self.y * other.y + self.z * other.z 22 | 23 | func length(self) -> f32: 24 | return sqrt(self.x * self.x + self.y * self.y + self.z * self.z) 25 | 26 | func unit_vector(self) -> Vec3: 27 | return self / self.length() 28 | -------------------------------------------------------------------------------- /examples/regular_expressions/README.rst: -------------------------------------------------------------------------------- 1 | Regular expressions 2 | =================== 3 | 4 | Build and run. 5 | 6 | .. code-block:: 7 | 8 | $ mys run 9 | mo: RegexMatch(span=(5, 12), match="6 years") 10 | mo.group(1): 6 11 | split(): ["I have ", " apples and ", " bananas."] 12 | replace(): I want more bananas. 13 | -------------------------------------------------------------------------------- /examples/regular_expressions/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "regular_expressions" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/regular_expressions/src/main.mys: -------------------------------------------------------------------------------- 1 | func main(): 2 | # Match. 3 | mo = "I am 6 years old.".match(re"(\d+) years") 4 | print("mo: ", mo) 5 | print("mo.group(1):", mo.group(1)) 6 | 7 | # Split. 8 | print("split(): ", "I have 15 apples and 3 bananas.".split(re"\d+")) 9 | 10 | # Case-insensitive replace. 11 | print("replace(): ", "I want more AppLEs.".replace(re"apples"i, "bananas")) 12 | -------------------------------------------------------------------------------- /examples/string_formatting/README.rst: -------------------------------------------------------------------------------- 1 | String formatting 2 | ================= 3 | 4 | .. code-block:: text 5 | 6 | $ mys run 7 | A short string with value 1. 8 | A long string. Too long to have inline in calling function. 9 | 10 | value_1: 1 11 | 12 | value_2: Hi! 13 | -------------------------------------------------------------------------------- /examples/string_formatting/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "string_formatting" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/string_formatting/src/main.mys: -------------------------------------------------------------------------------- 1 | func format_long(value_1: i64, value_2: string) -> string: 2 | return f"""\ 3 | A long string. Too long to have inline in calling function. 4 | 5 | value_1: {value_1} 6 | 7 | value_2: {value_2} 8 | """ 9 | 10 | func main(): 11 | value = 1 12 | print(f"A short string with value {value}.") 13 | print(format_long(value, "Hi!")) 14 | -------------------------------------------------------------------------------- /examples/the_super_tiny_compiler/README.rst: -------------------------------------------------------------------------------- 1 | The super tiny compiler 2 | ======================= 3 | 4 | Based on https://github.com/jamiebuilds/the-super-tiny-compiler. 5 | 6 | Run with default input code 7 | 8 | .. code-block:: 9 | 10 | $ mys run 11 | ✔ Reading package configuration (0 seconds) 12 | ✔ Building (0.01 seconds) 13 | Input: (add 2 (subtract 4 2)) 14 | Output: add(2, subtract(4, 2)); 15 | 16 | and with user supplied input code 17 | 18 | .. code-block:: 19 | 20 | $ mys run -- "(foo 5 \"10\")" 21 | ✔ Reading package configuration (0 seconds) 22 | ✔ Building (4.25 seconds) 23 | Input: (foo 5 "10") 24 | Output: foo(5, "10"); 25 | -------------------------------------------------------------------------------- /examples/the_super_tiny_compiler/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "the_super_tiny_compiler" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | 6 | [dependencies] 7 | string = "latest" -------------------------------------------------------------------------------- /examples/traceback/README.rst: -------------------------------------------------------------------------------- 1 | Traceback 2 | ========= 3 | 4 | Print a traceback and let the application exit normally. 5 | 6 | .. code-block:: text 7 | 8 | $ mys run -o debug -- print 9 | Traceback (most recent call last): 10 | File "./src/main.mys", line 13, in main 11 | do_print() 12 | File "./src/print.mys", line 7, in do_print 13 | foo() 14 | File "./src/print.mys", line 4, in foo 15 | print(traceback()) 16 | 17 | Raise an error that is not caught. The Mys runtime prints a traceback 18 | and the error. 19 | 20 | .. code-block:: text 21 | 22 | $ mys run -o debug -- error 23 | Traceback (most recent call last): 24 | File "./src/main.mys", line 15, in main 25 | do_error() 26 | File "./src/error.mys", line 10, in do_error 27 | foo() 28 | File "./src/error.mys", line 7, in foo 29 | raise MyError(message) 30 | 31 | MyError(message="Something went wrong.") 32 | 33 | Panics prints a traceback and a message. 34 | 35 | .. code-block:: text 36 | 37 | $ mys run -o debug -- panic 38 | h 39 | i 40 | Traceback (most recent call last): 41 | File "./src/main.mys", line 17, in main 42 | do_panic() 43 | File "./src/panic.mys", line 6, in do_panic 44 | foo() 45 | File "./src/panic.mys", line 3, in foo 46 | print("hi"[i]) 47 | 48 | Panic(message="String index 2 is out of range.") 49 | -------------------------------------------------------------------------------- /examples/traceback/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "traceback_example" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | 6 | [dependencies] 7 | argparse = "latest" 8 | traceback = "latest" 9 | string = "latest" 10 | -------------------------------------------------------------------------------- /examples/traceback/src/error.mys: -------------------------------------------------------------------------------- 1 | class MyError(Error): 2 | message: string 3 | 4 | func foo(): 5 | message = "Something went wrong." 6 | 7 | raise MyError(message) 8 | 9 | func do_error(): 10 | foo() 11 | -------------------------------------------------------------------------------- /examples/traceback/src/main.mys: -------------------------------------------------------------------------------- 1 | from argparse import Parser 2 | from .error import do_error 3 | from .panic import do_panic 4 | from .print import do_print 5 | 6 | func main(argv: [string]): 7 | parser = Parser() 8 | parser.add_positional("kind") 9 | args = parser.parse(argv) 10 | 11 | match args.value_of("kind"): 12 | case "print": 13 | do_print() 14 | case "error": 15 | do_error() 16 | case "panic": 17 | do_panic() 18 | case _ as kind: 19 | print(f"Bad kind '{kind}'. Must be 'print', 'error' or 'panic'.") 20 | -------------------------------------------------------------------------------- /examples/traceback/src/panic.mys: -------------------------------------------------------------------------------- 1 | func foo(): 2 | for i in range(10): 3 | print("hi"[i]) 4 | 5 | func do_panic(): 6 | foo() 7 | -------------------------------------------------------------------------------- /examples/traceback/src/print.mys: -------------------------------------------------------------------------------- 1 | from traceback import traceback 2 | 3 | func foo(): 4 | print(traceback()) 5 | 6 | func do_print(): 7 | foo() 8 | -------------------------------------------------------------------------------- /examples/traits/README.rst: -------------------------------------------------------------------------------- 1 | Traits 2 | ====== 3 | 4 | The traits example. 5 | 6 | .. code-block:: 7 | 8 | $ mys run 9 | base.add(12): 17 10 | foo.mul(12): 36 11 | base.add(12): 22 12 | bar.div(12): 4 13 | -------------------------------------------------------------------------------- /examples/traits/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "traits" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/traits/src/main.mys: -------------------------------------------------------------------------------- 1 | trait Base: 2 | 3 | func add(self, value: i64) -> i64: 4 | pass 5 | 6 | func surprise(self, value: i64) -> i64: 7 | return value * value 8 | 9 | class Foo(Base): 10 | 11 | func add(self, value: i64) -> i64: 12 | return value + 5 13 | 14 | func mul(self, value: i64) -> i64: 15 | return value * 3 16 | 17 | class Bar(Base): 18 | 19 | func add(self, value: i64) -> i64: 20 | return value + 10 21 | 22 | func surprise(self, value: i64) -> i64: 23 | return value * value * value 24 | 25 | func div(self, value: i64) -> i64: 26 | return value / 3 27 | 28 | func calc(base: Base, value: i64): 29 | print(f"base.add({value}):", base.add(value)) 30 | print(f"base.surprise({value}):", base.surprise(value)) 31 | 32 | match base: 33 | case Foo() as foo: 34 | print(f"foo.mul({value}):", foo.mul(value)) 35 | case Bar() as bar: 36 | print(f"bar.div({value}):", bar.div(value)) 37 | 38 | func main(): 39 | value = 12 40 | calc(Foo(), value) 41 | calc(Bar(), value) 42 | -------------------------------------------------------------------------------- /examples/wip/README.rst: -------------------------------------------------------------------------------- 1 | WIP Examples 2 | ============ 3 | 4 | This folder contains various examples that uses features that are not 5 | yet implemented. 6 | -------------------------------------------------------------------------------- /examples/wip/iterators/README.rst: -------------------------------------------------------------------------------- 1 | Iterators 2 | ========= 3 | 4 | An example using iterators. 5 | 6 | .. code-block:: text 7 | 8 | $ mys run 9 | fibonacci(0): 0 10 | fibonacci(1): 1 11 | fibonacci(2): 1 12 | fibonacci(3): 2 13 | fibonacci(4): 3 14 | fibonacci(5): 5 15 | fibonacci(6): 8 16 | fibonacci(7): 13 17 | fibonacci(8): 21 18 | fibonacci(9): 34 19 | 20 | Chunks: 21 | b"1234" 22 | b"5678" 23 | b"9" 24 | 25 | Default iterator: 26 | 0 27 | 1 28 | 2 29 | 3 30 | 31 | Next method: 32 | 0 33 | 1 34 | 2 35 | 3 36 | None 37 | -------------------------------------------------------------------------------- /examples/wip/iterators/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "iterators" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/wip/iterators/src/main.mys: -------------------------------------------------------------------------------- 1 | iterator fibonaccis(count: i64) -> (i64, i64): 2 | curr = 0 3 | next = 1 4 | 5 | for i in range(count): 6 | yield (i, curr) 7 | temp = curr 8 | curr = next 9 | next += temp 10 | 11 | class Memory: 12 | data: bytes 13 | 14 | iterator chunks(self, size: i64) -> bytes: 15 | for offset in range(0, data.length(), size): 16 | yield self.data[offset:offset + size] 17 | 18 | iterator __iter__(self) -> u8: 19 | for value in self.data: 20 | yield value 21 | 22 | func main(): 23 | for index, number in fibonaccis(10): 24 | print(f"fibonacci({index}): {number}") 25 | 26 | print() 27 | print("Chunks:") 28 | 29 | for chunk in Memory(b"123456789").chunks(4): 30 | print(chunk) 31 | 32 | print() 33 | print("Default iterator:") 34 | 35 | for byte in Memory(b"0123"): 36 | print(byte) 37 | 38 | print() 39 | print("Next method:") 40 | 41 | it = iter(Memory(b"0123")) 42 | print(it.next()) 43 | print(it.next()) 44 | print(it.next()) 45 | print(it.next()) 46 | print(it.next()) 47 | -------------------------------------------------------------------------------- /examples/wip/linked_list/README.rst: -------------------------------------------------------------------------------- 1 | Linked list 2 | =========== 3 | 4 | A double linked list. 5 | 6 | .. code-block:: text 7 | 8 | $ mys run 9 | Empty: [] 10 | Appended: [5, 6, 7] 11 | Length: 3 12 | Item: 7 13 | Poped: [5, 6] 14 | -------------------------------------------------------------------------------- /examples/wip/linked_list/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "linked_list" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/wip/linked_list/src/main.mys: -------------------------------------------------------------------------------- 1 | from . import LinkedList 2 | 3 | func main(): 4 | ll = LinkedList[i64]() 5 | 6 | print("Empty: ", ll) 7 | ll.append(5) 8 | ll.append(6) 9 | ll.append(7) 10 | print("Appended:", ll) 11 | print("Length: ", ll.length()) 12 | item = ll.pop() 13 | print("Item: ", item) 14 | print("Poped: ", ll) 15 | -------------------------------------------------------------------------------- /examples/wip/message_passing/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "message_passing" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | 6 | [dependencies] 7 | random = "latest" -------------------------------------------------------------------------------- /examples/wip/message_passing/src/calculator.mys: -------------------------------------------------------------------------------- 1 | from fiber import Fiber 2 | from .student import Student 3 | from .message import Message 4 | 5 | class Add(Message): 6 | first: f32 7 | second: f32 8 | 9 | class Result(Message): 10 | value: f32 11 | 12 | class Calculator(Fiber): 13 | """A calculator used by the student. 14 | 15 | """ 16 | 17 | _calculator_queue: Queue[Message] 18 | _student_queue: Queue[Message] 19 | 20 | func run(self): 21 | while True: 22 | match self._calculator_queue.get(): 23 | case Add() as message: 24 | print(message) 25 | self._student_queue.put(Result(message.first + message.second)) 26 | case Message() as message: 27 | raise ValueError(f"Unexpected message {message}.") 28 | -------------------------------------------------------------------------------- /examples/wip/message_passing/src/main.mys: -------------------------------------------------------------------------------- 1 | from fiber import sleep 2 | from fiber import Queue 3 | from .message import Message 4 | from .calculator import Calculator 5 | from .student import Student 6 | 7 | func main(): 8 | calculator_queue = Queue[Message]() 9 | student_queue = Queue[Message]() 10 | calculator = Calculator(calculator_queue, student_queue) 11 | student = Student(student_queue, calculator_queue) 12 | calculator.start() 13 | student.start() 14 | sleep(10) 15 | -------------------------------------------------------------------------------- /examples/wip/message_passing/src/message.mys: -------------------------------------------------------------------------------- 1 | trait Message: 2 | pass 3 | -------------------------------------------------------------------------------- /examples/wip/mocking/README.rst: -------------------------------------------------------------------------------- 1 | Mocking 2 | ======= 3 | 4 | Mocking playground. 5 | 6 | .. code-block:: text 7 | 8 | $ mys test 9 | ✔ Reading package configuration (0 seconds) 10 | ✔ Downloading dependencies (0 seconds) 11 | ✔ Building tests (0.2 seconds) 12 | ✔ Running tests (0.21 seconds) 13 | -------------------------------------------------------------------------------- /examples/wip/mocking/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mocking" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/wip/poll/README.rst: -------------------------------------------------------------------------------- 1 | Poll 2 | ==== 3 | 4 | Poll for event and queue messages. 5 | 6 | .. code-block:: text 7 | 8 | $ mys run 9 | 1. Setting start event. 10 | 2. Start event occurred. 11 | 3. Putting false break message. 12 | 4. Putting true break message. 13 | 5. Breaking. 14 | -------------------------------------------------------------------------------- /examples/wip/poll/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "poll" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/wip/poll/src/main.mys: -------------------------------------------------------------------------------- 1 | from timer import Timer 2 | from time import Time 3 | from poll import Poll 4 | from event import Event 5 | from queue import Queue 6 | from udp import Socket 7 | 8 | func main(): 9 | start_delay_timer = Timer(Time(3, 0)) 10 | start_event = Event() 11 | break_queue = Queue() 12 | udp_socket = Socket("", 9090) 13 | 14 | poll = Poll() 15 | poll.add(start_delay_timer) 16 | poll.add(start_event) 17 | poll.add(break_queue) 18 | poll.add(udp_socket) 19 | 20 | print("1. Starting start delay timer.") 21 | start_delay_timer.start() 22 | 23 | while True: 24 | item = poll.wait() 25 | 26 | if item is start_delay_timer: 27 | print("2. Start delay timer expired.") 28 | start_delay_timer.read() 29 | print("3. Setting start event.") 30 | start_event.set() 31 | elif item is start_event: 32 | print("4. Start event occurred.") 33 | start_event.clear() 34 | print("5. Putting false break message.") 35 | break_queue.put(False) 36 | elif item is break_queue: 37 | shall_break = break_queue.get() 38 | 39 | if not shall_break: 40 | print("6. Putting true break message.") 41 | break_queue.put(True) 42 | else: 43 | print("7. Breaking.") 44 | break 45 | elif item is udp_socket: 46 | packet = udp_socket.read() 47 | print(f"Got UDP packet: {packet}") 48 | else: 49 | raise UnreachableError() 50 | -------------------------------------------------------------------------------- /examples/wip/sort_list/README.rst: -------------------------------------------------------------------------------- 1 | Sort a list 2 | =========== 3 | 4 | An example of how to sort a list. 5 | 6 | .. code-block:: 7 | 8 | $ mys run 9 | Persons: 10 | [ 11 | Person("Erik", 31), 12 | Person("Linda", 3), 13 | Person("Frida", 76), 14 | Person("Kalle", 77), 15 | ] 16 | Sorted by name: 17 | [ 18 | Person("Erik", 31), 19 | Person("Frida", 76), 20 | Person("Kalle", 77), 21 | Person("Linda", 3) 22 | ] 23 | Sorted by age: 24 | [ 25 | Person("Linda", 3), 26 | Person("Erik", 31), 27 | Person("Frida", 76), 28 | Person("Kalle", 77) 29 | ] 30 | -------------------------------------------------------------------------------- /examples/wip/sort_list/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sort_list" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /examples/wip/sort_list/src/main.mys: -------------------------------------------------------------------------------- 1 | from string import pretty 2 | 3 | class Person: 4 | name: string 5 | age: i64 6 | 7 | class NameComparator(Comparator[Person]): 8 | 9 | func compare(self, a: Person, b: Person) -> bool: 10 | return a.name < b.name 11 | 12 | class AgeComparator(Comparator[Person]): 13 | 14 | func compare(self, a: Person, b: Person) -> bool: 15 | return a.age < b.age 16 | 17 | func main(): 18 | persons = [ 19 | Person("Erik", 31), 20 | Person("Linda", 3), 21 | Person("Frida", 76), 22 | Person("Kalle", 77) 23 | ] 24 | 25 | print("Persons:") 26 | print(pretty(str(persons))) 27 | 28 | print("Sorted by name:") 29 | persons.sort(NameComparator()) 30 | print(pretty(str(persons))) 31 | 32 | print("Sorted by age:") 33 | persons.sort(AgeComparator()) 34 | print(pretty(str(persons))) 35 | -------------------------------------------------------------------------------- /mys/__init__.py: -------------------------------------------------------------------------------- 1 | from .version import __version__ 2 | -------------------------------------------------------------------------------- /mys/__main__.py: -------------------------------------------------------------------------------- 1 | from .cli import main 2 | 3 | main() 4 | -------------------------------------------------------------------------------- /mys/cli/mys_dir.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | MYS_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) 4 | -------------------------------------------------------------------------------- /mys/cli/subparsers/__init__.py: -------------------------------------------------------------------------------- 1 | # Package. 2 | -------------------------------------------------------------------------------- /mys/cli/subparsers/clean.py: -------------------------------------------------------------------------------- 1 | import os 2 | import shutil 3 | 4 | from ..utils import Spinner 5 | from ..utils import read_package_configuration 6 | 7 | 8 | def remove_file(path): 9 | try: 10 | os.remove(path) 11 | except FileNotFoundError: 12 | pass 13 | 14 | def do_clean(_parser, _args, _mys_config): 15 | read_package_configuration() 16 | 17 | with Spinner(text='Cleaning'): 18 | shutil.rmtree('build', ignore_errors=True) 19 | shutil.rmtree('coverage', ignore_errors=True) 20 | remove_file('.coverage') 21 | remove_file('.mys-coverage.txt') 22 | 23 | 24 | def add_subparser(subparsers): 25 | subparser = subparsers.add_parser( 26 | 'clean', 27 | description='Remove build output.') 28 | subparser.set_defaults(func=do_clean) 29 | -------------------------------------------------------------------------------- /mys/cli/subparsers/delete.py: -------------------------------------------------------------------------------- 1 | from http.client import responses 2 | 3 | import requests 4 | 5 | from ..utils import Spinner 6 | from ..utils import add_verbose_argument 7 | 8 | 9 | def do_delete(_parser, args, _mys_config): 10 | print(args.package) 11 | print(args.token) 12 | 13 | with Spinner(f'Deleting {args.package}'): 14 | response = requests.delete(f'{args.address}/package/{args.package}', 15 | params={'token': args.token}) 16 | 17 | if response.status_code != 200: 18 | raise Exception( 19 | 'Package delete failed with HTTP ' 20 | f'{response.status_code} {responses[response.status_code]}.') 21 | 22 | 23 | def add_subparser(subparsers): 24 | subparser = subparsers.add_parser( 25 | 'delete', 26 | description='Delete a package from the registry.') 27 | add_verbose_argument(subparser) 28 | subparser.add_argument('-a', '--address', 29 | default='https://mys-lang.org', 30 | help='Registry address (default: %(default)s)') 31 | subparser.add_argument('package', help='Package to delete.') 32 | subparser.add_argument('token', help='Package access token.') 33 | subparser.set_defaults(func=do_delete) 34 | -------------------------------------------------------------------------------- /mys/cli/subparsers/dependents.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | from ..utils import add_url_argument 4 | 5 | 6 | def do_dependents(_parser, args, _mys_config): 7 | response = requests.get( 8 | f'{args.url}/standard-library/{args.package}/dependents.txt') 9 | 10 | if response.status_code != 200: 11 | raise Exception(f"failed to find dependets on package '{args.package}'") 12 | 13 | print(response.text, end='') 14 | 15 | 16 | def add_subparser(subparsers): 17 | subparser = subparsers.add_parser( 18 | 'dependents', 19 | description='Show dependents.') 20 | add_url_argument(subparser) 21 | subparser.add_argument('package', help='Package to find dependents on.') 22 | subparser.set_defaults(func=do_dependents) 23 | -------------------------------------------------------------------------------- /mys/cli/subparsers/help.py: -------------------------------------------------------------------------------- 1 | def do_help(parser, _args, _mys_config): 2 | parser.print_help() 3 | 4 | 5 | def add_subparser(subparsers): 6 | subparser = subparsers.add_parser( 7 | 'help', 8 | description='Show this help.') 9 | subparser.set_defaults(func=do_help) 10 | -------------------------------------------------------------------------------- /mys/cli/subparsers/list.py: -------------------------------------------------------------------------------- 1 | from gql import Client 2 | from gql import gql 3 | from gql.transport.requests import RequestsHTTPTransport 4 | 5 | from ..utils import add_url_argument 6 | 7 | 8 | def do_list(_parser, args, _mys_config): 9 | client = Client(transport=RequestsHTTPTransport(url=f"{args.url}/graphql")) 10 | response = client.execute(gql("{standardLibrary{packages{name}}}")) 11 | 12 | for package in response['standardLibrary']['packages']: 13 | print(package['name']) 14 | 15 | def add_subparser(subparsers): 16 | subparser = subparsers.add_parser( 17 | 'list', 18 | description='Show packages in registry.') 19 | add_url_argument(subparser) 20 | subparser.set_defaults(func=do_list) 21 | -------------------------------------------------------------------------------- /mys/cli/subparsers/style/__init__.py: -------------------------------------------------------------------------------- 1 | import glob 2 | 3 | from ....parser import ast 4 | from ...utils import Spinner 5 | from ...utils import read_package_configuration 6 | from .comments_finder import CommentsFinder 7 | from .comments_reader import CommentsReader 8 | from .source_styler import SourceStyler 9 | from .utils import get_function_or_class_node_start 10 | from .utils import get_source 11 | 12 | 13 | def style_files(): 14 | source_styler = SourceStyler() 15 | 16 | for src_path in glob.glob('src/**/*.mys', recursive=True): 17 | with open(src_path, 'r') as fin: 18 | source = fin.read() 19 | 20 | tree = ast.parse(source, src_path) 21 | source_lines = source.split('\n') 22 | finder = CommentsFinder(source_lines) 23 | finder.visit(tree) 24 | # from pprint import pprint 25 | # pprint(finder.comments) 26 | styled_source = source_styler.style(source_lines, tree, finder.comments) 27 | 28 | if styled_source != source: 29 | with open(src_path, 'w') as fout: 30 | fout.write(styled_source) 31 | 32 | 33 | def do_style(_parser, _args, _mys_config): 34 | read_package_configuration() 35 | 36 | with Spinner(text="Styling source code"): 37 | style_files() 38 | 39 | 40 | def add_subparser(subparsers): 41 | subparser = subparsers.add_parser( 42 | 'style', 43 | description=( 44 | 'Modify all source code files in the package follow the Mys style ' 45 | 'guidelines.')) 46 | subparser.set_defaults(func=do_style) 47 | -------------------------------------------------------------------------------- /mys/cli/subparsers/style/utils.py: -------------------------------------------------------------------------------- 1 | def get_source(source_lines, lineno, col_offset, end_lineno, end_col_offset): 2 | source = [] 3 | number_of_lines = end_lineno - lineno + 1 4 | new_lineno = lineno 5 | 6 | if number_of_lines == 1: 7 | line = source_lines[lineno - 1] 8 | line = line[col_offset:end_col_offset] 9 | 10 | if line: 11 | source.append(line) 12 | else: 13 | for i in range(number_of_lines): 14 | line = source_lines[lineno + i - 1] 15 | 16 | if i == 0: 17 | line = line[col_offset:] 18 | 19 | if not line: 20 | new_lineno += 1 21 | continue 22 | elif i == number_of_lines - 1: 23 | line = line[:end_col_offset] 24 | 25 | if not line: 26 | continue 27 | 28 | source.append(line) 29 | 30 | return new_lineno, source 31 | 32 | 33 | def get_function_or_class_node_start(node): 34 | if node.decorator_list: 35 | node = node.decorator_list[0] 36 | 37 | return node.lineno, 0 38 | -------------------------------------------------------------------------------- /mys/cli/templates/new/.gitattributes: -------------------------------------------------------------------------------- 1 | *.mys linguist-language=python 2 | -------------------------------------------------------------------------------- /mys/cli/templates/new/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | *~ 3 | .coverage 4 | .mys-coverage.txt 5 | coverage/ 6 | -------------------------------------------------------------------------------- /mys/cli/templates/new/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Mys Lang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /mys/cli/templates/new/README.rst: -------------------------------------------------------------------------------- 1 | {title} 2 | {line} 3 | 4 | {title} in the `Mys programming language`_. 5 | 6 | Documentation: https://mys-lang.org/package/{package}/latest/index.html 7 | 8 | .. _Mys programming language: https://mys-lang.org 9 | -------------------------------------------------------------------------------- /mys/cli/templates/new/doc/index.rst: -------------------------------------------------------------------------------- 1 | About 2 | ===== 3 | 4 | The {package_name} package in the `Mys programming language`_. 5 | 6 | API 7 | === 8 | 9 | .. mysfile:: src/lib.mys 10 | 11 | .. _Mys programming language: https://mys-lang.org 12 | -------------------------------------------------------------------------------- /mys/cli/templates/new/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "{package_name}" 3 | version = "0.1.0" 4 | authors = [{authors}] 5 | description = "Add a short package description here." 6 | 7 | [dependencies] 8 | # foobar = "latest" 9 | -------------------------------------------------------------------------------- /mys/cli/templates/new/src/lib.mys: -------------------------------------------------------------------------------- 1 | func add(first: i32, second: i32) -> i32: 2 | """Returns the sum of given numbers `first` and `second`. 3 | 4 | """ 5 | 6 | return first + second 7 | 8 | test add(): 9 | assert add(1, 2) == 3 10 | -------------------------------------------------------------------------------- /mys/cli/templates/new/src/main.mys: -------------------------------------------------------------------------------- 1 | func main(): 2 | print("Hello, world!") 3 | -------------------------------------------------------------------------------- /mys/cli/templates/publish/MANIFEST.in: -------------------------------------------------------------------------------- 1 | include package.toml 2 | recursive-include src *.mys *.hpp *.cpp 3 | -------------------------------------------------------------------------------- /mys/cli/templates/publish/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | setup(name='{name}', 4 | version='{version}', 5 | description='{description}', 6 | long_description=open('README.rst', 'r').read(), 7 | author={author}, 8 | author_email={author_email}, 9 | install_requires={dependencies}) 10 | -------------------------------------------------------------------------------- /mys/coverage/NOTICE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2001 Gareth Rees. All rights reserved. 2 | Copyright 2004-2021 Ned Batchelder. All rights reserved. 3 | 4 | Except where noted otherwise, this software is licensed under the Apache 5 | License, Version 2.0 (the "License"); you may not use this work except in 6 | compliance with the License. You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | -------------------------------------------------------------------------------- /mys/coverage/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 2 | # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt 3 | 4 | """Code coverage measurement for Python. 5 | 6 | Ned Batchelder 7 | https://nedbatchelder.com/code/coverage 8 | 9 | """ 10 | 11 | from .control import Coverage 12 | from .sqldata import CoverageData 13 | -------------------------------------------------------------------------------- /mys/coverage/data.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 2 | # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt 3 | 4 | 5 | def add_data_to_hash(data, filename, hasher): 6 | """Contribute `filename`'s data to the `hasher`. 7 | 8 | `hasher` is a `coverage.misc.Hasher` instance to be updated with 9 | the file's data. It should only get the results data, not the run 10 | data. 11 | 12 | """ 13 | hasher.update(sorted(data.lines(filename) or [])) 14 | hasher.update(data.file_tracer(filename)) 15 | -------------------------------------------------------------------------------- /mys/coverage/debug.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 2 | # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt 3 | 4 | """Control of and utilities for debugging.""" 5 | 6 | 7 | class SimpleReprMixin: 8 | """A mixin implementing a simple __repr__.""" 9 | simple_repr_ignore = ['simple_repr_ignore', '$coverage.object_id'] 10 | -------------------------------------------------------------------------------- /mys/coverage/htmlfiles/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mys-lang/mys/f3cb604e95eadd9833466dbd43ac9f5913f31d60/mys/coverage/htmlfiles/favicon.ico -------------------------------------------------------------------------------- /mys/coverage/htmlfiles/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mys-lang/mys/f3cb604e95eadd9833466dbd43ac9f5913f31d60/mys/coverage/htmlfiles/favicon.png -------------------------------------------------------------------------------- /mys/coverage/htmlfiles/jquery.ba-throttle-debounce.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | * jQuery throttle / debounce - v1.1 - 3/7/2010 3 | * http://benalman.com/projects/jquery-throttle-debounce-plugin/ 4 | * 5 | * Copyright (c) 2010 "Cowboy" Ben Alman 6 | * Dual licensed under the MIT and GPL licenses. 7 | * http://benalman.com/about/license/ 8 | */ 9 | (function(b,c){var $=b.jQuery||b.Cowboy||(b.Cowboy={}),a;$.throttle=a=function(e,f,j,i){var h,d=0;if(typeof f!=="boolean"){i=j;j=f;f=c}function g(){var o=this,m=+new Date()-d,n=arguments;function l(){d=+new Date();j.apply(o,n)}function k(){h=c}if(i&&!h){l()}h&&clearTimeout(h);if(i===c&&m>e){l()}else{if(f!==true){h=setTimeout(i?k:l,i===c?e-m:e)}}}if($.guid){g.guid=j.guid=j.guid||$.guid++}return g};$.debounce=function(d,e,f){return f===c?a(d,e,false):a(d,f,e!==false)}})(this); 10 | -------------------------------------------------------------------------------- /mys/coverage/htmlfiles/keybd_closed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mys-lang/mys/f3cb604e95eadd9833466dbd43ac9f5913f31d60/mys/coverage/htmlfiles/keybd_closed.png -------------------------------------------------------------------------------- /mys/coverage/htmlfiles/keybd_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mys-lang/mys/f3cb604e95eadd9833466dbd43ac9f5913f31d60/mys/coverage/htmlfiles/keybd_open.png -------------------------------------------------------------------------------- /mys/coverage/report.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 2 | # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt 3 | 4 | """Reporter foundation for coverage.py.""" 5 | 6 | from .files import FnmatchMatcher 7 | from .files import prep_patterns 8 | from .misc import CoverageException 9 | 10 | 11 | def get_analysis_to_report(coverage, morfs): 12 | """Get the files to report on. 13 | 14 | For each morf in `morfs`, if it should be reported on (based on the omit 15 | and include configuration options), yield a pair, the `FileReporter` and 16 | `Analysis` for the morf. 17 | 18 | """ 19 | file_reporters = coverage.get_file_reporters(morfs) 20 | config = coverage.config 21 | 22 | if config.report_include: 23 | matcher = FnmatchMatcher(prep_patterns(config.report_include)) 24 | file_reporters = [fr for fr in file_reporters if matcher.match(fr.filename)] 25 | 26 | if config.report_omit: 27 | matcher = FnmatchMatcher(prep_patterns(config.report_omit)) 28 | file_reporters = [fr 29 | for fr in file_reporters 30 | if not matcher.match(fr.filename)] 31 | 32 | if not file_reporters: 33 | raise CoverageException("No data to report.") 34 | 35 | for fr in sorted(file_reporters): 36 | analysis = coverage._analyze(fr) 37 | yield (fr, analysis) 38 | -------------------------------------------------------------------------------- /mys/coverage/version.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 2 | # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt 3 | 4 | """The version and URL for coverage.py""" 5 | # This file is exec'ed in setup.py, don't import anything! 6 | 7 | # Same semantics as sys.version_info. 8 | version_info = (5, 5, 0, "alpha", 0) 9 | 10 | 11 | def _make_version(major, minor, micro, releaselevel, serial): 12 | """Create a readable version string from version_info tuple components.""" 13 | assert releaselevel in ['alpha', 'beta', 'candidate', 'final'] 14 | version = f"{major}.{minor}" 15 | if micro: 16 | version += f".{micro}" 17 | if releaselevel != 'final': 18 | short = {'alpha': 'a', 'beta': 'b', 'candidate': 'rc'}[releaselevel] 19 | version += f"{short}{serial}" 20 | return version 21 | 22 | 23 | __version__ = _make_version(*version_info) 24 | __url__ = "https://github.com/nedbat/coveragepy" 25 | -------------------------------------------------------------------------------- /mys/lib/memory.cpp: -------------------------------------------------------------------------------- 1 | #include "mys/memory.hpp" 2 | 3 | namespace mys { 4 | 5 | #ifdef MYS_MEMORY_STATISTICS 6 | long long number_of_allocated_objects = 0; 7 | long long number_of_object_decrements = 0; 8 | long long number_of_object_frees = 0; 9 | #endif 10 | 11 | } 12 | -------------------------------------------------------------------------------- /mys/lib/mys.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MYS_HPP 2 | #define MYS_HPP 3 | 4 | #include "mys/memory.hpp" 5 | #include "mys/optional.hpp" 6 | #include "mys/common.hpp" 7 | #include "mys/utils.hpp" 8 | #include "mys/traceback.hpp" 9 | 10 | // Mys defined types 11 | #include "mys/types/number.hpp" 12 | #include "mys/types/bool.hpp" 13 | #include "mys/types/char.hpp" 14 | #include "mys/types/bytes.hpp" 15 | #include "mys/types/string.hpp" 16 | #include "mys/types/object.hpp" 17 | #include "mys/types/tuple.hpp" 18 | #include "mys/types/list.hpp" 19 | #include "mys/types/dict.hpp" 20 | #include "mys/types/set.hpp" 21 | #include "mys/types/generators.hpp" 22 | #include "mys/types/regex.hpp" 23 | 24 | // Errors and exception management 25 | #include "mys/errors/base.hpp" 26 | #include "mys/errors/assertion.hpp" 27 | #include "mys/errors/index.hpp" 28 | #include "mys/errors/interrupt.hpp" 29 | #include "mys/errors/key.hpp" 30 | #include "mys/errors/not_implemented.hpp" 31 | #include "mys/errors/system_exit.hpp" 32 | #include "mys/errors/unreachable.hpp" 33 | #include "mys/errors/value.hpp" 34 | 35 | // Builtins, print, test and shared pointer functions 36 | #include "mys/builtins.hpp" 37 | #include "mys/test.hpp" 38 | #include "mys/shared_ptr.hpp" 39 | #include "mys/printable/char.hpp" 40 | #include "mys/printable/string.hpp" 41 | 42 | #include "mys/fiber.hpp" 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /mys/lib/mys/common.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | -------------------------------------------------------------------------------- /mys/lib/mys/errors/assertion.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "base.hpp" 4 | 5 | namespace mys { 6 | 7 | class AssertionError : public Error { 8 | public: 9 | String m_message; 10 | AssertionError() 11 | { 12 | } 13 | AssertionError(const String& message) : m_message(message) 14 | { 15 | } 16 | virtual ~AssertionError() 17 | { 18 | } 19 | [[ noreturn ]] void __throw(); 20 | String __str__(); 21 | }; 22 | 23 | class __AssertionError final : public __Error { 24 | public: 25 | __AssertionError(const mys::shared_ptr& error) 26 | : __Error(static_cast>(error)) 27 | { 28 | } 29 | }; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /mys/lib/mys/errors/base.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../types/object.hpp" 4 | 5 | namespace mys { 6 | 7 | // The Error trait that all errors must implement. 8 | class Error : public Object { 9 | public: 10 | std::vector m_traceback; 11 | 12 | Error(); 13 | 14 | virtual ~Error() {} 15 | 16 | // Throw the C++ exception. Needed when re-raising the exception. 17 | [[ noreturn ]] virtual void __throw() = 0; 18 | }; 19 | 20 | class __Error : public std::exception { 21 | public: 22 | mys::shared_ptr m_error; 23 | 24 | __Error(const mys::shared_ptr& error) : m_error(error) 25 | { 26 | } 27 | }; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /mys/lib/mys/errors/index.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "base.hpp" 4 | 5 | namespace mys { 6 | 7 | class IndexError : public Error { 8 | public: 9 | String m_message; 10 | IndexError() 11 | { 12 | } 13 | IndexError(const String& message) : m_message(message) 14 | { 15 | } 16 | virtual ~IndexError() 17 | { 18 | } 19 | [[ noreturn ]] void __throw(); 20 | String __str__(); 21 | }; 22 | 23 | class __IndexError final : public __Error { 24 | public: 25 | __IndexError(const mys::shared_ptr& error) 26 | : __Error(static_cast>(error)) 27 | { 28 | } 29 | }; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /mys/lib/mys/errors/interrupt.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "base.hpp" 4 | 5 | namespace mys { 6 | 7 | class InterruptError : public Error { 8 | public: 9 | String m_message; 10 | InterruptError() 11 | { 12 | } 13 | InterruptError(const String& message) : m_message(message) 14 | { 15 | } 16 | virtual ~InterruptError() 17 | { 18 | } 19 | [[ noreturn ]] void __throw(); 20 | String __str__(); 21 | }; 22 | 23 | class __InterruptError final : public __Error { 24 | public: 25 | __InterruptError(const mys::shared_ptr& error) 26 | : __Error(static_cast>(error)) 27 | { 28 | } 29 | }; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /mys/lib/mys/errors/key.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "base.hpp" 4 | 5 | namespace mys { 6 | 7 | class KeyError : public Error { 8 | public: 9 | String m_message; 10 | KeyError() 11 | { 12 | } 13 | KeyError(const String& message) : m_message(message) 14 | { 15 | } 16 | virtual ~KeyError() 17 | { 18 | } 19 | [[ noreturn ]] void __throw(); 20 | String __str__(); 21 | }; 22 | 23 | class __KeyError final : public __Error { 24 | public: 25 | __KeyError(const mys::shared_ptr& error) 26 | : __Error(static_cast>(error)) 27 | { 28 | } 29 | }; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /mys/lib/mys/errors/not_implemented.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "base.hpp" 4 | 5 | namespace mys { 6 | 7 | class NotImplementedError : public Error { 8 | public: 9 | String m_message; 10 | NotImplementedError() 11 | { 12 | } 13 | NotImplementedError(const String& message) : m_message(message) 14 | { 15 | } 16 | virtual ~NotImplementedError() 17 | { 18 | } 19 | [[ noreturn ]] void __throw(); 20 | String __str__(); 21 | }; 22 | 23 | class __NotImplementedError final : public __Error { 24 | public: 25 | __NotImplementedError(const mys::shared_ptr& error) 26 | : __Error(static_cast>(error)) 27 | { 28 | } 29 | }; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /mys/lib/mys/errors/system_exit.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "base.hpp" 4 | 5 | namespace mys { 6 | 7 | class SystemExitError : public Error { 8 | public: 9 | String m_message; 10 | SystemExitError() 11 | { 12 | } 13 | SystemExitError(const String& message) : m_message(message) 14 | { 15 | } 16 | virtual ~SystemExitError() 17 | { 18 | } 19 | [[ noreturn ]] void __throw(); 20 | String __str__(); 21 | }; 22 | 23 | class __SystemExitError final : public __Error { 24 | public: 25 | __SystemExitError(const mys::shared_ptr& error) 26 | : __Error(static_cast>(error)) 27 | { 28 | } 29 | }; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /mys/lib/mys/errors/unreachable.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "base.hpp" 4 | 5 | namespace mys { 6 | 7 | class UnreachableError : public Error { 8 | public: 9 | String m_message; 10 | UnreachableError() 11 | { 12 | } 13 | UnreachableError(const String& message) : m_message(message) 14 | { 15 | } 16 | virtual ~UnreachableError() 17 | { 18 | } 19 | [[ noreturn ]] void __throw(); 20 | String __str__(); 21 | }; 22 | 23 | class __UnreachableError final : public __Error { 24 | public: 25 | __UnreachableError(const mys::shared_ptr& error) 26 | : __Error(static_cast>(error)) 27 | { 28 | } 29 | }; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /mys/lib/mys/errors/value.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "base.hpp" 4 | 5 | namespace mys { 6 | 7 | class ValueError : public Error { 8 | public: 9 | String m_message; 10 | ValueError() 11 | { 12 | } 13 | ValueError(const String& message) : m_message(message) 14 | { 15 | } 16 | virtual ~ValueError() 17 | { 18 | } 19 | [[ noreturn ]] void __throw(); 20 | String __str__(); 21 | }; 22 | 23 | class __ValueError final : public __Error { 24 | public: 25 | __ValueError(const mys::shared_ptr& error) 26 | : __Error(static_cast>(error)) 27 | { 28 | } 29 | }; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /mys/lib/mys/fiber.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "uv.h" 4 | 5 | namespace mys { 6 | 7 | class Fiber : public Object { 8 | public: 9 | void *data_p; 10 | 11 | Fiber(); 12 | 13 | virtual ~Fiber() {} 14 | 15 | virtual void run() = 0; 16 | 17 | bool __eq__(const mys::shared_ptr& other) { 18 | return false; 19 | } 20 | 21 | String __str__(); 22 | }; 23 | 24 | void start(const mys::shared_ptr& fiber); 25 | 26 | bool join(const mys::shared_ptr& fiber); 27 | 28 | bool suspend(); 29 | 30 | void resume(const mys::shared_ptr& fiber); 31 | 32 | void cancel(const mys::shared_ptr& fiber); 33 | 34 | mys::shared_ptr current(); 35 | 36 | bool sleep(f64 seconds); 37 | 38 | void init(); 39 | 40 | void enable_signal(int signum); 41 | 42 | void disable_signal(int signum); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /mys/lib/mys/printable/char.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../common.hpp" 4 | #include "../types/char.hpp" 5 | 6 | namespace mys { 7 | 8 | class PrintChar { 9 | public: 10 | Char m_value; 11 | 12 | PrintChar(Char value) : m_value(value) {} 13 | }; 14 | 15 | std::ostream& operator<<(std::ostream& os, const PrintChar& obj); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /mys/lib/mys/printable/string.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../common.hpp" 4 | #include "../types/string.hpp" 5 | 6 | namespace mys { 7 | 8 | class PrintString { 9 | public: 10 | const String& m_value; 11 | 12 | PrintString(const String& value) : m_value(value) {} 13 | }; 14 | 15 | std::ostream& operator<<(std::ostream& os, const PrintString& obj); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /mys/lib/mys/shared_ptr.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.hpp" 4 | 5 | namespace mys { 6 | 7 | template const mys::shared_ptr& 8 | shared_ptr_not_none(const mys::shared_ptr& obj) 9 | { 10 | #if !defined(MYS_UNSAFE) 11 | if (!obj) { 12 | abort_is_none(); 13 | } 14 | #endif 15 | 16 | return obj; 17 | } 18 | 19 | template mys::shared_ptr& 20 | shared_ptr_not_none(mys::shared_ptr& obj) 21 | { 22 | #if !defined(MYS_UNSAFE) 23 | if (!obj) { 24 | abort_is_none(); 25 | } 26 | #endif 27 | 28 | return obj; 29 | } 30 | 31 | template bool 32 | is(const mys::shared_ptr& a, const mys::shared_ptr& b) 33 | { 34 | return a.m_buf_p == b.m_buf_p; 35 | } 36 | 37 | template bool 38 | is(const mys::shared_ptr& a, void *b) 39 | { 40 | return a.m_buf_p == nullptr; 41 | } 42 | 43 | template bool 44 | is(void *a, const mys::shared_ptr& b) 45 | { 46 | return b.m_buf_p == nullptr; 47 | } 48 | 49 | template bool 50 | is(const std::shared_ptr& a, const std::shared_ptr& b) 51 | { 52 | return a.get() == b.get(); 53 | } 54 | 55 | template bool 56 | is(const std::shared_ptr& a, void *b) 57 | { 58 | return a.get() == nullptr; 59 | } 60 | 61 | template bool 62 | is(void *a, const std::shared_ptr& b) 63 | { 64 | return b.get() == nullptr; 65 | } 66 | 67 | // For nullptr == nullptr 68 | static inline bool is(void *a, void *b) 69 | { 70 | return a == b; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /mys/lib/mys/test.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mys { 4 | 5 | class Test; 6 | 7 | extern Test *tests_head_p; 8 | extern Test *tests_tail_p; 9 | 10 | typedef void (*test_func_t)(void); 11 | 12 | class Test { 13 | 14 | public: 15 | const char *m_name_p; 16 | test_func_t m_func; 17 | Test *m_next_p; 18 | 19 | Test(const char *name_p, test_func_t func); 20 | }; 21 | 22 | #if defined(MYS_COVERAGE) 23 | extern std::ofstream mys_coverage_file; 24 | #endif 25 | 26 | } 27 | -------------------------------------------------------------------------------- /mys/lib/mys/types/bool.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mys { 4 | 5 | // To make str(bool) and print(bool) show True and False. 6 | struct Bool { 7 | bool m_value; 8 | 9 | Bool() : m_value(false) 10 | { 11 | } 12 | 13 | Bool(bool value) : m_value(value) 14 | { 15 | } 16 | 17 | operator bool() const 18 | { 19 | return m_value; 20 | } 21 | }; 22 | 23 | std::ostream& operator<<(std::ostream& os, const Bool& obj); 24 | 25 | } 26 | 27 | namespace std 28 | { 29 | template<> struct hash 30 | { 31 | std::size_t operator()(mys::Bool const& s) const noexcept 32 | { 33 | return s.m_value; 34 | } 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /mys/lib/mys/types/char.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../common.hpp" 4 | #include "number.hpp" 5 | 6 | namespace mys { 7 | 8 | struct Char { 9 | i32 m_value; 10 | 11 | Char() : m_value(-1) 12 | { 13 | } 14 | 15 | Char(i32 value) : m_value(value) 16 | { 17 | } 18 | 19 | operator i32() const 20 | { 21 | return m_value; 22 | } 23 | 24 | bool operator==(const Char& other) const 25 | { 26 | return m_value == other.m_value; 27 | } 28 | 29 | bool operator!=(const Char& other) const 30 | { 31 | return m_value != other.m_value; 32 | } 33 | 34 | bool operator<(const Char& other) const 35 | { 36 | return m_value < other.m_value; 37 | } 38 | 39 | Bool is_digit() const; 40 | Bool is_numeric() const; 41 | Bool is_alpha() const; 42 | Bool is_space() const; 43 | }; 44 | 45 | std::ostream& operator<<(std::ostream& os, const Char& obj); 46 | 47 | } 48 | 49 | namespace std 50 | { 51 | template<> struct hash 52 | { 53 | std::size_t operator()(mys::Char const& s) const noexcept 54 | { 55 | return (std::size_t)s.m_value; 56 | } 57 | }; 58 | } 59 | -------------------------------------------------------------------------------- /mys/lib/mys/types/number.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../common.hpp" 4 | 5 | typedef int8_t i8; 6 | typedef int16_t i16; 7 | typedef int32_t i32; 8 | typedef int64_t i64; 9 | typedef uint8_t u8; 10 | typedef uint16_t u16; 11 | typedef uint32_t u32; 12 | typedef uint64_t u64; 13 | typedef float f32; 14 | typedef double f64; 15 | 16 | // Integer power (a ** b). 17 | template 18 | TB ipow(TB base, TE exp) 19 | { 20 | TB result = 1; 21 | 22 | while (exp != 0) { 23 | if ((exp & 1) == 1) { 24 | result *= base; 25 | } 26 | 27 | exp >>= 1; 28 | base *= base; 29 | } 30 | 31 | return result; 32 | } 33 | -------------------------------------------------------------------------------- /mys/lib/mys/types/object.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../common.hpp" 4 | #include "string.hpp" 5 | 6 | namespace mys { 7 | 8 | class Object { 9 | public: 10 | virtual void __format__(std::ostream& os) const; 11 | virtual String __str__(); 12 | virtual bool __eq__(const mys::shared_ptr& other); 13 | virtual i64 __hash__(); 14 | }; 15 | 16 | std::ostream& operator<<(std::ostream& os, Object& obj); 17 | 18 | template 19 | String object_str(const mys::shared_ptr& value) 20 | { 21 | if (value) { 22 | return value->__str__(); 23 | } else { 24 | return String("None"); 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /mys/lib/mys/utils.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.hpp" 4 | #include "types/number.hpp" 5 | 6 | namespace mys { 7 | 8 | class Error; 9 | 10 | void abort_is_none(void); 11 | void print_traceback(void); 12 | void print_error_traceback(const mys::shared_ptr& error, 13 | std::ostream& os); 14 | 15 | template const mys::shared_ptr& 16 | shared_ptr_not_none(const mys::shared_ptr& obj); 17 | 18 | size_t encode_utf8(char *dst_p, i32 ch); 19 | 20 | // Exception output. 21 | std::ostream& operator<<(std::ostream& os, const std::exception& e); 22 | 23 | template 24 | std::ostream& operator<<(std::ostream& os, const mys::shared_ptr& obj) 25 | { 26 | if (obj) { 27 | os << *obj; 28 | } else { 29 | os << "None"; 30 | } 31 | 32 | return os; 33 | } 34 | 35 | template 36 | std::ostream& operator<<(std::ostream& os, const std::vector& obj) 37 | { 38 | const char *delim_p; 39 | 40 | os << "["; 41 | delim_p = ""; 42 | 43 | for (auto item = obj.begin(); item != obj.end(); item++, delim_p = ", ") { 44 | os << delim_p << *item; 45 | } 46 | 47 | os << "]"; 48 | 49 | return os; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /mys/lib/packages/README.rst: -------------------------------------------------------------------------------- 1 | Builtin packages 2 | ================ 3 | 4 | Builtin packages are automatically added as dependencies when imported 5 | from. They should not be added to the dependencies section in the 6 | package configuration file. 7 | 8 | Builtin packages are often tightly coupled to the transpiler and the 9 | core Mys lib. 10 | -------------------------------------------------------------------------------- /mys/lib/packages/builtins/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "builtins" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | description = "Various builtins." 6 | -------------------------------------------------------------------------------- /mys/lib/packages/error/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "error" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | description = "Error handling." 6 | -------------------------------------------------------------------------------- /mys/lib/packages/error/src/lib.mys: -------------------------------------------------------------------------------- 1 | trait Error: 2 | pass 3 | 4 | class AssertionError(Error): 5 | message: string 6 | 7 | class IndexError(Error): 8 | message: string 9 | 10 | class KeyError(Error): 11 | message: string 12 | 13 | class NotImplementedError(Error): 14 | message: string 15 | 16 | class SystemExitError(Error): 17 | message: string 18 | code: i64 19 | 20 | func __init__(self, message: string): 21 | pass 22 | 23 | func __init__(self, code: i64): 24 | pass 25 | 26 | class UnreachableError(Error): 27 | message: string 28 | 29 | class ValueError(Error): 30 | message: string 31 | -------------------------------------------------------------------------------- /mys/lib/packages/fiber/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fiber" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | description = "Concurrency with fibers." 6 | -------------------------------------------------------------------------------- /mys/lib/test/Makefile: -------------------------------------------------------------------------------- 1 | ifneq ($(shell which ccache),) 2 | CCACHE := ccache 3 | endif 4 | 5 | EXE = test 6 | SRC += test_memory.cpp 7 | SRC += test_optional.cpp 8 | SRC += catch.cpp 9 | SRC += ../memory.cpp 10 | OBJ = $(SRC:%.cpp=%.o) 11 | DEP = $(OBJ:%.o=%.d) 12 | CXXFLAGS += -DMYS_MEMORY_STATISTICS 13 | CXXFLAGS += -std=c++17 14 | CXXFLAGS += -I.. 15 | CXXFLAGS += -MMD 16 | 17 | .PNONY: all clean 18 | 19 | all: $(EXE) 20 | ./$(EXE) $(ARGS) 21 | 22 | clean: 23 | rm -f $(EXE) $(OBJ) $(DEP) 24 | 25 | $(EXE): $(OBJ) 26 | $(CCACHE) $(CXX) -std=c++17 $^ -o $@ 27 | 28 | -include $(DEP) 29 | 30 | %.o: %.cpp 31 | $(CCACHE) $(CXX) $(CXXFLAGS) -c $< -o $@ 32 | -------------------------------------------------------------------------------- /mys/lib/test/test_optional.cpp: -------------------------------------------------------------------------------- 1 | #include "catch.hpp" 2 | #include "mys/optional.hpp" 3 | 4 | using mys::optional; 5 | 6 | TEST_CASE("Various optional") 7 | { 8 | optional v; 9 | REQUIRE(v == nullptr); 10 | v = 1; 11 | REQUIRE(v != nullptr); 12 | REQUIRE(v == 1); 13 | v = nullptr; 14 | REQUIRE(v == nullptr); 15 | optional v2{5}; 16 | v = 5; 17 | REQUIRE(v == v2); 18 | optional v3 = nullptr; 19 | REQUIRE(v3 == nullptr); 20 | optional v4 = static_cast(0); 21 | REQUIRE(v4 == static_cast(0)); 22 | } 23 | -------------------------------------------------------------------------------- /mys/parser/Mys-ast.h: -------------------------------------------------------------------------------- 1 | #ifndef Py_LIMITED_API 2 | #ifndef Mys_Mys_Py_AST_H 3 | #define Mys_Mys_Py_AST_H 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "Mys-Python-ast.h" /* mod_ty */ 9 | 10 | PyAPI_FUNC(int) PyAST_Validate(mod_ty); 11 | 12 | /* _PyAST_ExprAsUnicode is defined in ast_unparse.c */ 13 | PyAPI_FUNC(PyObject *) _PyAST_ExprAsUnicode(expr_ty); 14 | 15 | /* Return the borrowed reference to the first literal string in the 16 | sequence of statements or NULL if it doesn't start from a literal string. 17 | Doesn't set exception. */ 18 | PyAPI_FUNC(PyObject *) _PyAST_GetDocString(asdl_stmt_seq *); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | #endif /* !Py_AST_H */ 24 | #endif /* !Py_LIMITED_API */ 25 | -------------------------------------------------------------------------------- /mys/parser/Mys-parser_interface.h: -------------------------------------------------------------------------------- 1 | #ifndef Mys_Py_PEGENINTERFACE 2 | #define Mys_Py_PEGENINTERFACE 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include "Python.h" 8 | #include "Mys-pyarena.h" 9 | 10 | #ifndef Py_LIMITED_API 11 | PyAPI_FUNC(struct _mod *) Mys_PyParser_ASTFromStringObject( 12 | const char *str, 13 | PyObject* filename, 14 | int mode, 15 | PyCompilerFlags *flags, 16 | Mys_PyArena *arena); 17 | #endif /* !Py_LIMITED_API */ 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | #endif /* !Py_PEGENINTERFACE */ 23 | -------------------------------------------------------------------------------- /mys/parser/README.rst: -------------------------------------------------------------------------------- 1 | Copied from CPython and slightly modified. 2 | 3 | https://github.com/python/cpython 4 | -------------------------------------------------------------------------------- /mys/parser/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | -------------------------------------------------------------------------------- /mys/parser/asdl.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Mys-asdl.h" 3 | 4 | MYS_GENERATE_ASDL_SEQ_CONSTRUCTOR(generic, void*); 5 | MYS_GENERATE_ASDL_SEQ_CONSTRUCTOR(identifier, PyObject*); 6 | MYS_GENERATE_ASDL_SEQ_CONSTRUCTOR(int, int); 7 | -------------------------------------------------------------------------------- /mys/parser/peg_api.c: -------------------------------------------------------------------------------- 1 | #include "Mys-parser_interface.h" 2 | 3 | #include "Mys-tokenizer.h" 4 | #include "Mys-pegen.h" 5 | 6 | mod_ty 7 | Mys_PyParser_ASTFromStringObject(const char *str, PyObject* filename, int mode, 8 | PyCompilerFlags *flags, Mys_PyArena *arena) 9 | { 10 | if (PySys_Audit("compile", "yO", str, filename) < 0) { 11 | return NULL; 12 | } 13 | 14 | mod_ty result = _Mys_PyPegen_run_parser_from_string(str, mode, filename, flags, arena); 15 | return result; 16 | } 17 | -------------------------------------------------------------------------------- /mys/pcre2/AUTHORS: -------------------------------------------------------------------------------- 1 | THE MAIN PCRE2 LIBRARY CODE 2 | --------------------------- 3 | 4 | Written by: Philip Hazel 5 | Email local part: Philip.Hazel 6 | Email domain: gmail.com 7 | 8 | Retired from University of Cambridge Computing Service, 9 | Cambridge, England. 10 | 11 | Copyright (c) 1997-2021 University of Cambridge 12 | All rights reserved 13 | 14 | 15 | PCRE2 JUST-IN-TIME COMPILATION SUPPORT 16 | -------------------------------------- 17 | 18 | Written by: Zoltan Herczeg 19 | Email local part: hzmester 20 | Emain domain: freemail.hu 21 | 22 | Copyright(c) 2010-2021 Zoltan Herczeg 23 | All rights reserved. 24 | 25 | 26 | STACK-LESS JUST-IN-TIME COMPILER 27 | -------------------------------- 28 | 29 | Written by: Zoltan Herczeg 30 | Email local part: hzmester 31 | Emain domain: freemail.hu 32 | 33 | Copyright(c) 2009-2021 Zoltan Herczeg 34 | All rights reserved. 35 | 36 | #### 37 | -------------------------------------------------------------------------------- /mys/pcre2/COPYING: -------------------------------------------------------------------------------- 1 | PCRE2 LICENCE 2 | 3 | Please see the file LICENCE in the PCRE2 distribution for licensing details. 4 | 5 | End 6 | -------------------------------------------------------------------------------- /mys/pcre2/Makefile: -------------------------------------------------------------------------------- 1 | SRCS += src/pcre2_auto_possess.c 2 | SRCS += src/pcre2_chartables.c 3 | SRCS += src/pcre2_compile.c 4 | SRCS += src/pcre2_config.c 5 | SRCS += src/pcre2_context.c 6 | SRCS += src/pcre2_convert.c 7 | SRCS += src/pcre2_dfa_match.c 8 | SRCS += src/pcre2_error.c 9 | SRCS += src/pcre2_extuni.c 10 | SRCS += src/pcre2_find_bracket.c 11 | SRCS += src/pcre2_jit_compile.c 12 | SRCS += src/pcre2_maketables.c 13 | SRCS += src/pcre2_match.c 14 | SRCS += src/pcre2_match_data.c 15 | SRCS += src/pcre2_newline.c 16 | SRCS += src/pcre2_ord2utf.c 17 | SRCS += src/pcre2_pattern_info.c 18 | SRCS += src/pcre2_script_run.c 19 | SRCS += src/pcre2_serialize.c 20 | SRCS += src/pcre2_string_utils.c 21 | SRCS += src/pcre2_study.c 22 | SRCS += src/pcre2_substitute.c 23 | SRCS += src/pcre2_substring.c 24 | SRCS += src/pcre2_tables.c 25 | SRCS += src/pcre2_ucd.c 26 | SRCS += src/pcre2_valid_utf.c 27 | SRCS += src/pcre2_xclass.c 28 | 29 | OBJS = $(SRCS:%.c=%.o) 30 | 31 | LIB = libpcre2.a 32 | 33 | CFLAGS += -Iinclude 34 | CFLAGS += -DHAVE_CONFIG_H 35 | CFLAGS += -DPCRE2_CODE_UNIT_WIDTH=32 36 | CFLAGS += -O2 37 | CFLAGS += -ffunction-sections 38 | CFLAGS += -fdata-sections 39 | # CFLAGS += -flto 40 | 41 | all: $(LIB) 42 | 43 | $(LIB): $(OBJS) 44 | ar -r $@ $^ 45 | 46 | clean: 47 | rm -f $(LIB) $(OBJS) 48 | -------------------------------------------------------------------------------- /mys/pygments/pygments/README.rst: -------------------------------------------------------------------------------- 1 | Based on https://github.com/pygments/pygments. 2 | -------------------------------------------------------------------------------- /mys/pygments/pygments/__main__.py: -------------------------------------------------------------------------------- 1 | """ 2 | pygments.__main__ 3 | ~~~~~~~~~~~~~~~~~ 4 | 5 | Main entry point for ``python -m pygments``. 6 | 7 | :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | """ 10 | 11 | import sys 12 | 13 | import pygments.cmdline 14 | 15 | try: 16 | sys.exit(pygments.cmdline.main(sys.argv)) 17 | except KeyboardInterrupt: 18 | sys.exit(1) 19 | -------------------------------------------------------------------------------- /mys/pygments/pygments/lexers/agile.py: -------------------------------------------------------------------------------- 1 | """ 2 | pygments.lexers.agile 3 | ~~~~~~~~~~~~~~~~~~~~~ 4 | 5 | Just export lexer classes previously contained in this module. 6 | 7 | :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | """ 10 | 11 | from pygments.lexers.d import CrocLexer 12 | from pygments.lexers.d import MiniDLexer 13 | from pygments.lexers.factor import FactorLexer 14 | from pygments.lexers.iolang import IoLexer 15 | from pygments.lexers.jvm import ClojureLexer 16 | from pygments.lexers.jvm import IokeLexer 17 | from pygments.lexers.lisp import SchemeLexer 18 | from pygments.lexers.perl import Perl6Lexer 19 | from pygments.lexers.perl import PerlLexer 20 | from pygments.lexers.python import DgLexer 21 | from pygments.lexers.python import Python3Lexer 22 | from pygments.lexers.python import Python3TracebackLexer 23 | from pygments.lexers.python import PythonConsoleLexer 24 | from pygments.lexers.python import PythonLexer 25 | from pygments.lexers.python import PythonTracebackLexer 26 | from pygments.lexers.ruby import FancyLexer 27 | from pygments.lexers.ruby import RubyConsoleLexer 28 | from pygments.lexers.ruby import RubyLexer 29 | from pygments.lexers.scripting import LuaLexer 30 | from pygments.lexers.scripting import MoonScriptLexer 31 | from pygments.lexers.tcl import TclLexer 32 | 33 | __all__ = [] 34 | -------------------------------------------------------------------------------- /mys/pygments/pygments/lexers/functional.py: -------------------------------------------------------------------------------- 1 | """ 2 | pygments.lexers.functional 3 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 4 | 5 | Just export lexer classes previously contained in this module. 6 | 7 | :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | """ 10 | 11 | from pygments.lexers.erlang import ElixirConsoleLexer 12 | from pygments.lexers.erlang import ElixirLexer 13 | from pygments.lexers.erlang import ErlangLexer 14 | from pygments.lexers.erlang import ErlangShellLexer 15 | from pygments.lexers.haskell import HaskellLexer 16 | from pygments.lexers.haskell import KokaLexer 17 | from pygments.lexers.haskell import LiterateHaskellLexer 18 | from pygments.lexers.lisp import CommonLispLexer 19 | from pygments.lexers.lisp import NewLispLexer 20 | from pygments.lexers.lisp import RacketLexer 21 | from pygments.lexers.lisp import SchemeLexer 22 | from pygments.lexers.lisp import ShenLexer 23 | from pygments.lexers.ml import OcamlLexer 24 | from pygments.lexers.ml import OpaLexer 25 | from pygments.lexers.ml import SMLLexer 26 | from pygments.lexers.theorem import CoqLexer 27 | 28 | __all__ = [] 29 | -------------------------------------------------------------------------------- /mys/pygments/pygments/lexers/gcodelexer.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.gcodelexer 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Lexers for the G Code Language. 7 | 8 | :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | from pygments.lexer import RegexLexer 13 | from pygments.lexer import bygroups 14 | from pygments.token import Comment 15 | from pygments.token import Keyword 16 | from pygments.token import Name 17 | from pygments.token import Number 18 | from pygments.token import Text 19 | 20 | __all__ = ['GcodeLexer'] 21 | 22 | 23 | class GcodeLexer(RegexLexer): 24 | """ 25 | For gcode source code. 26 | 27 | .. versionadded:: 2.9 28 | """ 29 | name = 'g-code' 30 | aliases = ['gcode'] 31 | filenames = ['*.gcode'] 32 | 33 | tokens = { 34 | 'root': [ 35 | (r';.*\n', Comment), 36 | (r'^[gmGM]\d{1,4}\s', Name.Builtin), # M or G commands 37 | (r'([^gGmM])([+-]?\d*[.]?\d+)', bygroups(Keyword, Number)), 38 | (r'\s', Text.Whitespace), 39 | (r'.*\n', Text), 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /mys/pygments/pygments/lexers/math.py: -------------------------------------------------------------------------------- 1 | """ 2 | pygments.lexers.math 3 | ~~~~~~~~~~~~~~~~~~~~ 4 | 5 | Just export lexers that were contained in this module. 6 | 7 | :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | """ 10 | 11 | from pygments.lexers.algebra import MuPADLexer 12 | from pygments.lexers.idl import IDLLexer 13 | from pygments.lexers.julia import JuliaConsoleLexer 14 | from pygments.lexers.julia import JuliaLexer 15 | from pygments.lexers.matlab import MatlabLexer 16 | from pygments.lexers.matlab import MatlabSessionLexer 17 | from pygments.lexers.matlab import OctaveLexer 18 | from pygments.lexers.matlab import ScilabLexer 19 | from pygments.lexers.modeling import BugsLexer 20 | from pygments.lexers.modeling import JagsLexer 21 | from pygments.lexers.modeling import StanLexer 22 | from pygments.lexers.python import NumPyLexer 23 | from pygments.lexers.r import RConsoleLexer 24 | from pygments.lexers.r import RdLexer 25 | from pygments.lexers.r import SLexer 26 | 27 | __all__ = [] 28 | -------------------------------------------------------------------------------- /mys/pygments/pygments/lexers/procfile.py: -------------------------------------------------------------------------------- 1 | """ 2 | pygments.lexers.procfile 3 | ~~~~~~~~~~~~~~~~~~~~~~~~ 4 | 5 | Lexer for Procfile file format. 6 | 7 | :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | """ 10 | 11 | from pygments.lexer import RegexLexer 12 | from pygments.lexer import bygroups 13 | from pygments.token import Name 14 | from pygments.token import Number 15 | from pygments.token import Punctuation 16 | from pygments.token import String 17 | from pygments.token import Text 18 | 19 | __all__ = ["ProcfileLexer"] 20 | 21 | 22 | class ProcfileLexer(RegexLexer): 23 | """ 24 | Lexer for Procfile file format. 25 | 26 | The format is used to run processes on Heroku or is used by Foreman or 27 | Honcho tools. 28 | For more information about the definition of the format, see: 29 | https://devcenter.heroku.com/articles/procfile#procfile-format 30 | 31 | .. versionadded:: 2.10 32 | """ 33 | name = 'Procfile' 34 | aliases = ['procfile'] 35 | filenames = ['Procfile'] 36 | 37 | tokens = { 38 | 'root': [ 39 | (r'^([a-z]+)(:)', bygroups(Name.Label, Punctuation)), 40 | (r'\s+', Text.Whitespace), 41 | (r'"[^"]*"', String), 42 | (r"'[^']*'", String), 43 | (r'[0-9]+', Number.Integer), 44 | (r'\$[a-zA-Z_][\w]*', Name.Variable), 45 | (r'(\w+)(=)(\w+)', bygroups(Name.Variable, Punctuation, String)), 46 | (r'([\w\-\./]+)', Text), 47 | ], 48 | } 49 | -------------------------------------------------------------------------------- /mys/pygments/pygments/lexers/xorg.py: -------------------------------------------------------------------------------- 1 | """ 2 | pygments.lexers.xorg 3 | ~~~~~~~~~~~~~~~~~~~~ 4 | 5 | Lexers for Xorg configs. 6 | 7 | :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | """ 10 | 11 | from pygments.lexer import RegexLexer 12 | from pygments.lexer import bygroups 13 | from pygments.token import Comment 14 | from pygments.token import Name 15 | from pygments.token import String 16 | from pygments.token import Text 17 | 18 | __all__ = ['XorgLexer'] 19 | 20 | 21 | class XorgLexer(RegexLexer): 22 | """Lexer for xorg.conf file.""" 23 | name = 'Xorg' 24 | aliases = ['xorg.conf'] 25 | filenames = ['xorg.conf'] 26 | mimetypes = [] 27 | 28 | tokens = { 29 | 'root': [ 30 | (r'\s+', Text), 31 | (r'#.*$', Comment), 32 | 33 | (r'((?:Sub)?Section)(\s+)("\w+")', 34 | bygroups(String.Escape, Text, String.Escape)), 35 | (r'(End(?:Sub)?Section)', String.Escape), 36 | 37 | (r'(\w+)(\s+)([^\n#]+)', 38 | bygroups(Name.Builtin, Text, Name.Constant)), 39 | ], 40 | } 41 | -------------------------------------------------------------------------------- /mys/pygments/pygments/modeline.py: -------------------------------------------------------------------------------- 1 | """ 2 | pygments.modeline 3 | ~~~~~~~~~~~~~~~~~ 4 | 5 | A simple modeline parser (based on pymodeline). 6 | 7 | :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | """ 10 | 11 | import re 12 | 13 | __all__ = ['get_filetype_from_buffer'] 14 | 15 | 16 | modeline_re = re.compile(r''' 17 | (?: vi | vim | ex ) (?: [<=>]? \d* )? : 18 | .* (?: ft | filetype | syn | syntax ) = ( [^:\s]+ ) 19 | ''', re.VERBOSE) 20 | 21 | 22 | def get_filetype_from_line(l): 23 | m = modeline_re.search(l) 24 | if m: 25 | return m.group(1) 26 | 27 | 28 | def get_filetype_from_buffer(buf, max_lines=5): 29 | """ 30 | Scan the buffer for modelines and return filetype if one is found. 31 | """ 32 | lines = buf.splitlines() 33 | for l in lines[-1:-max_lines-1:-1]: 34 | ret = get_filetype_from_line(l) 35 | if ret: 36 | return ret 37 | for i in range(max_lines, -1, -1): 38 | if i < len(lines): 39 | ret = get_filetype_from_line(lines[i]) 40 | if ret: 41 | return ret 42 | 43 | return None 44 | -------------------------------------------------------------------------------- /mys/pygments/pygments/styles/abap.py: -------------------------------------------------------------------------------- 1 | """ 2 | pygments.styles.abap 3 | ~~~~~~~~~~~~~~~~~~~~ 4 | 5 | ABAP workbench like style. 6 | 7 | :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | """ 10 | 11 | from pygments.style import Style 12 | from pygments.token import Comment 13 | from pygments.token import Error 14 | from pygments.token import Keyword 15 | from pygments.token import Name 16 | from pygments.token import Number 17 | from pygments.token import Operator 18 | from pygments.token import String 19 | 20 | 21 | class AbapStyle(Style): 22 | default_style = "" 23 | styles = { 24 | Comment: 'italic #888', 25 | Comment.Special: '#888', 26 | Keyword: '#00f', 27 | Operator.Word: '#00f', 28 | Name: '#000', 29 | Number: '#3af', 30 | String: '#5a2', 31 | 32 | Error: '#F00', 33 | } 34 | -------------------------------------------------------------------------------- /mys/pygments/pygments/styles/igor.py: -------------------------------------------------------------------------------- 1 | """ 2 | pygments.styles.igor 3 | ~~~~~~~~~~~~~~~~~~~~ 4 | 5 | Igor Pro default style. 6 | 7 | :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | """ 10 | 11 | from pygments.style import Style 12 | from pygments.token import Comment 13 | from pygments.token import Keyword 14 | from pygments.token import Name 15 | from pygments.token import String 16 | 17 | 18 | class IgorStyle(Style): 19 | """ 20 | Pygments version of the official colors for Igor Pro procedures. 21 | """ 22 | default_style = "" 23 | 24 | styles = { 25 | Comment: 'italic #FF0000', 26 | Keyword: '#0000FF', 27 | Name.Function: '#C34E00', 28 | Name.Decorator: '#CC00A3', 29 | Name.Class: '#007575', 30 | String: '#009C00' 31 | } 32 | -------------------------------------------------------------------------------- /mys/pygments/pygments/styles/rrt.py: -------------------------------------------------------------------------------- 1 | """ 2 | pygments.styles.rrt 3 | ~~~~~~~~~~~~~~~~~~~ 4 | 5 | pygments "rrt" theme, based on Zap and Emacs defaults. 6 | 7 | :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | """ 10 | 11 | from pygments.style import Style 12 | from pygments.token import Comment 13 | from pygments.token import Keyword 14 | from pygments.token import Name 15 | from pygments.token import String 16 | 17 | 18 | class RrtStyle(Style): 19 | """ 20 | Minimalistic "rrt" theme, based on Zap and Emacs defaults. 21 | """ 22 | 23 | background_color = '#000000' 24 | highlight_color = '#0000ff' 25 | 26 | styles = { 27 | Comment: '#00ff00', 28 | Name.Function: '#ffff00', 29 | Name.Variable: '#eedd82', 30 | Name.Constant: '#7fffd4', 31 | Keyword: '#ff0000', 32 | Comment.Preproc: '#e5e5e5', 33 | String: '#87ceeb', 34 | Keyword.Type: '#ee82ee', 35 | } 36 | -------------------------------------------------------------------------------- /mys/pygments/pygments/styles/vs.py: -------------------------------------------------------------------------------- 1 | """ 2 | pygments.styles.vs 3 | ~~~~~~~~~~~~~~~~~~ 4 | 5 | Simple style with MS Visual Studio colors. 6 | 7 | :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | """ 10 | 11 | from pygments.style import Style 12 | from pygments.token import Comment 13 | from pygments.token import Error 14 | from pygments.token import Generic 15 | from pygments.token import Keyword 16 | from pygments.token import Name 17 | from pygments.token import Operator 18 | from pygments.token import String 19 | 20 | 21 | class VisualStudioStyle(Style): 22 | 23 | background_color = "#ffffff" 24 | default_style = "" 25 | 26 | styles = { 27 | Comment: "#008000", 28 | Comment.Preproc: "#0000ff", 29 | Keyword: "#0000ff", 30 | Operator.Word: "#0000ff", 31 | Keyword.Type: "#2b91af", 32 | Name.Class: "#2b91af", 33 | String: "#a31515", 34 | 35 | Generic.Heading: "bold", 36 | Generic.Subheading: "bold", 37 | Generic.Emph: "italic", 38 | Generic.Strong: "bold", 39 | Generic.Prompt: "bold", 40 | 41 | Error: "border:#FF0000" 42 | } 43 | -------------------------------------------------------------------------------- /mys/sphinx_rtd_dark_mode/README.rst: -------------------------------------------------------------------------------- 1 | Based on https://github.com/MrDogeBro/sphinx_rtd_dark_mode. 2 | -------------------------------------------------------------------------------- /mys/sphinx_rtd_dark_mode/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Sphinx Read the Docs Dark Mode 3 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4 | 5 | Allows for toggable dark mode on the Read the Docs 6 | theme for Sphinx. 7 | """ 8 | 9 | __title__ = "sphinx-rtd-dark-mode" 10 | __description__ = "Dark mode for the Sphinx Read the Docs theme." 11 | __author__ = "MrDogeBro" 12 | __version__ = "1.2.3" 13 | __license__ = "MIT" 14 | 15 | from .dark_mode_loader import DarkModeLoader 16 | 17 | 18 | def setup(app): 19 | app.add_config_value("default_dark_mode", True, "html") 20 | 21 | app.connect("config-inited", DarkModeLoader().configure) 22 | 23 | return { 24 | "version": __version__, 25 | "parallel_read_safe": True, 26 | "parallel_write_safe": True, 27 | } 28 | -------------------------------------------------------------------------------- /mys/sphinx_rtd_dark_mode/static/dark_mode_js/default_dark.js: -------------------------------------------------------------------------------- 1 | const loadTheme = () => { 2 | let theme = localStorage.getItem('theme'); 3 | 4 | if (theme !== null) { 5 | if (theme === 'dark') 6 | document.documentElement.setAttribute('data-theme', 'dark'); 7 | } else { 8 | localStorage.setItem('theme', 'dark'); 9 | document.documentElement.setAttribute('data-theme', 'dark'); 10 | } 11 | }; 12 | 13 | loadTheme(); 14 | -------------------------------------------------------------------------------- /mys/sphinx_rtd_dark_mode/static/dark_mode_js/default_light.js: -------------------------------------------------------------------------------- 1 | const loadTheme = () => { 2 | let theme = localStorage.getItem('theme'); 3 | 4 | if (theme !== null) { 5 | if (theme === 'dark') 6 | document.documentElement.setAttribute('data-theme', 'dark'); 7 | } else { 8 | localStorage.setItem('theme', 'light'); 9 | document.documentElement.setAttribute('data-theme', 'light'); 10 | } 11 | }; 12 | 13 | loadTheme(); 14 | -------------------------------------------------------------------------------- /mys/sphinx_rtd_dark_mode/static/dark_mode_js/theme_switcher.js: -------------------------------------------------------------------------------- 1 | const createThemeSwitcher = () => { 2 | let btn = document.createElement('BUTTON'); 3 | btn.className = 'theme-switcher'; 4 | btn.id = 'themeSwitcher'; 5 | btn.innerHTML = 6 | ''; 7 | document.body.appendChild(btn); 8 | 9 | if (localStorage.getItem('theme') === 'dark') $('#themeMoon').hide(0); 10 | else $('#themeSun').hide(0); 11 | }; 12 | 13 | $(document).ready(() => { 14 | createThemeSwitcher(); 15 | $('#themeSwitcher').click(switchTheme); 16 | 17 | $('footer').html( 18 | $('footer').html() + 19 | 'Dark theme provided by MrDogeBro.' 20 | ); 21 | }); 22 | 23 | const switchTheme = () => { 24 | if (localStorage.getItem('theme') === 'dark') { 25 | localStorage.setItem('theme', 'light'); 26 | document.documentElement.setAttribute('data-theme', 'light'); 27 | 28 | $('#themeSun').fadeOut(200, () => { 29 | $('#themeMoon').fadeIn(200); 30 | }); 31 | } else { 32 | localStorage.setItem('theme', 'dark'); 33 | document.documentElement.setAttribute('data-theme', 'dark'); 34 | 35 | $('#themeMoon').fadeOut(200, () => { 36 | $('#themeSun').fadeIn(200); 37 | }); 38 | } 39 | }; 40 | -------------------------------------------------------------------------------- /mys/transpiler/body_check_visitor.py: -------------------------------------------------------------------------------- 1 | from ..parser import ast 2 | from .utils import CompileError 3 | 4 | 5 | class BodyCheckVisitor(ast.NodeVisitor): 6 | """Raises an error if given function body contains invalid nodes. 7 | 8 | """ 9 | 10 | def visit_Expr(self, node): 11 | if isinstance(node.value, ast.Name): 12 | raise CompileError("bare name", node) 13 | elif isinstance(node.value, ast.Compare): 14 | raise CompileError("bare comparision", node) 15 | elif isinstance(node.value, ast.BinOp): 16 | raise CompileError("bare binary operation", node) 17 | elif isinstance(node.value, ast.UnaryOp): 18 | raise CompileError("bare unary operation", node) 19 | elif isinstance(node.value, ast.Constant): 20 | if isinstance(node.value.value, str): 21 | # ToDo: embedded C++ 22 | pass 23 | elif isinstance(node.value.value, int): 24 | raise CompileError("bare integer", node) 25 | if isinstance(node.value.value, float): 26 | raise CompileError("bare float", node) 27 | -------------------------------------------------------------------------------- /mys/transpiler/constant_visitor.py: -------------------------------------------------------------------------------- 1 | from ..parser import ast 2 | 3 | 4 | class ConstantVisitor(ast.NodeVisitor): 5 | 6 | def __init__(self): 7 | self.is_constant = True 8 | 9 | def visit_Constant(self, node): 10 | pass 11 | 12 | def visit_UnaryOp(self, node): 13 | self.visit(node.operand) 14 | 15 | def visit_List(self, node): 16 | for item in node.elts: 17 | self.visit(item) 18 | 19 | def visit_Tuple(self, node): 20 | for item in node.elts: 21 | self.visit(item) 22 | 23 | def visit_Dict(self, node): 24 | for item in node.keys: 25 | self.visit(item) 26 | 27 | for item in node.values: 28 | self.visit(item) 29 | 30 | def generic_visit(self, node): 31 | self.is_constant = False 32 | 33 | 34 | def is_constant(node): 35 | """Returns true if given node is a "constant", that is, is does not 36 | contain variables, enums, traits or classes. 37 | 38 | """ 39 | 40 | visitor = ConstantVisitor() 41 | visitor.visit(node) 42 | 43 | return visitor.is_constant 44 | -------------------------------------------------------------------------------- /mys/transpiler/imports_visitor.py: -------------------------------------------------------------------------------- 1 | from ..parser import ast 2 | from .utils import CompileError 3 | 4 | 5 | class ImportsVisitor(ast.NodeVisitor): 6 | """Raises an error if not all imports are at the beginning of the 7 | file. 8 | 9 | """ 10 | 11 | def __init__(self): 12 | self._other_found = False 13 | 14 | def visit_Module(self, node): 15 | for item in node.body: 16 | self.visit(item) 17 | 18 | def visit_Import(self, node): 19 | raise CompileError("only 'from import ...' is allowed", node) 20 | 21 | def visit_ImportFrom(self, node): 22 | if self._other_found: 23 | raise CompileError("imports must be at the beginning of the file", node) 24 | 25 | def generic_visit(self, node): 26 | self._other_found = True 27 | -------------------------------------------------------------------------------- /mys/uv/src/idna.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2011, 2018 Ben Noordhuis 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | */ 15 | 16 | #ifndef UV_SRC_IDNA_H_ 17 | #define UV_SRC_IDNA_H_ 18 | 19 | /* Decode a single codepoint. Returns the codepoint or UINT32_MAX on error. 20 | * |p| is updated on success _and_ error, i.e., bad multi-byte sequences are 21 | * skipped in their entirety, not just the first bad byte. 22 | */ 23 | unsigned uv__utf8_decode1(const char** p, const char* pe); 24 | 25 | /* Convert a UTF-8 domain name to IDNA 2008 / Punycode. A return value >= 0 26 | * is the number of bytes written to |d|, including the trailing nul byte. 27 | * A return value < 0 is a libuv error code. |s| and |d| can not overlap. 28 | */ 29 | long uv__idna_toascii(const char* s, const char* se, char* d, char* de); 30 | 31 | #endif /* UV_SRC_IDNA_H_ */ 32 | -------------------------------------------------------------------------------- /mys/uv/src/strscpy.c: -------------------------------------------------------------------------------- 1 | /* Copyright libuv project contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "strscpy.h" 23 | #include /* SSIZE_MAX */ 24 | 25 | ssize_t uv__strscpy(char* d, const char* s, size_t n) { 26 | size_t i; 27 | 28 | for (i = 0; i < n; i++) 29 | if ('\0' == (d[i] = s[i])) 30 | return i > SSIZE_MAX ? UV_E2BIG : (ssize_t) i; 31 | 32 | if (i == 0) 33 | return 0; 34 | 35 | d[--i] = '\0'; 36 | 37 | return UV_E2BIG; 38 | } 39 | -------------------------------------------------------------------------------- /mys/uv/src/unix/posix-hrtime.c: -------------------------------------------------------------------------------- 1 | /* Copyright libuv project contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "internal.h" 24 | 25 | #include 26 | #include 27 | 28 | #undef NANOSEC 29 | #define NANOSEC ((uint64_t) 1e9) 30 | 31 | uint64_t uv__hrtime(uv_clocktype_t type) { 32 | struct timespec ts; 33 | clock_gettime(CLOCK_MONOTONIC, &ts); 34 | return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec); 35 | } 36 | -------------------------------------------------------------------------------- /mys/version.py: -------------------------------------------------------------------------------- 1 | __version__ = '0.452.0' 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | ansicolors 2 | humanfriendly 3 | pygments 4 | toml 5 | yaspin 6 | isort 7 | sphinx 8 | sphinx_rtd_theme 9 | requests 10 | pexpect 11 | xdg 12 | fasteners 13 | gql[requests] 14 | pytest 15 | pytest-xdist 16 | -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | export PYTHONPATH=$(pwd) 2 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | # The test package. 2 | -------------------------------------------------------------------------------- /tests/files/.gitignore: -------------------------------------------------------------------------------- 1 | *.bin -------------------------------------------------------------------------------- /tests/files/assets/mypkg/README.rst: -------------------------------------------------------------------------------- 1 | Mypkg 2 | ===== 3 | 4 | Add more information about your package here! 5 | -------------------------------------------------------------------------------- /tests/files/assets/mypkg/assets/bar/bar.txt: -------------------------------------------------------------------------------- 1 | Hi 2 | -------------------------------------------------------------------------------- /tests/files/assets/mypkg/assets/foo.txt: -------------------------------------------------------------------------------- 1 | My package. 2 | -------------------------------------------------------------------------------- /tests/files/assets/mypkg/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mypkg" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | 6 | [dependencies] 7 | mypkg1 = { path = "../mypkg1" } 8 | -------------------------------------------------------------------------------- /tests/files/assets/mypkg/src/lib.mys: -------------------------------------------------------------------------------- 1 | from mypkg1 import foo 2 | 3 | test assets(): 4 | assert __assets__.ends_with("test-assets/mypkg") 5 | assert foo().ends_with("test-assets/mypkg1/foo.txt") 6 | -------------------------------------------------------------------------------- /tests/files/assets/mypkg1/README.rst: -------------------------------------------------------------------------------- 1 | Mypkg3 2 | ====== 3 | 4 | Add more information about your package here! 5 | -------------------------------------------------------------------------------- /tests/files/assets/mypkg1/assets/foo.txt: -------------------------------------------------------------------------------- 1 | My package 1. 2 | -------------------------------------------------------------------------------- /tests/files/assets/mypkg1/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mypkg1" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /tests/files/assets/mypkg1/src/lib.mys: -------------------------------------------------------------------------------- 1 | func foo() -> string: 2 | return f"{__assets__}/foo.txt" 3 | -------------------------------------------------------------------------------- /tests/files/bar/README.rst: -------------------------------------------------------------------------------- 1 | Bar 2 | === 3 | 4 | A tiny package that is used in the tutorial. 5 | -------------------------------------------------------------------------------- /tests/files/bar/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "bar" 3 | version = "0.1.0" 4 | authors = ["Erik Moqvist "] 5 | 6 | [dependencies] 7 | -------------------------------------------------------------------------------- /tests/files/bar/src/lib.mys: -------------------------------------------------------------------------------- 1 | func hello(name: string): 2 | print(f"Hello {name}!") 3 | -------------------------------------------------------------------------------- /tests/files/c_dependencies/mypkg/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mypkg" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | 6 | [dependencies] 7 | mypkg1 = { path = "../mypkg1" } 8 | 9 | [c-dependencies] 10 | sqlite3 = "latest" 11 | -------------------------------------------------------------------------------- /tests/files/c_dependencies/mypkg/src/lib.mys: -------------------------------------------------------------------------------- 1 | c"""header-before-namespace 2 | #include 3 | """ 4 | 5 | enum Result: 6 | Ok = c"SQLITE_OK" 7 | Row = c"SQLITE_ROW" 8 | Done = c"SQLITE_DONE" 9 | -------------------------------------------------------------------------------- /tests/files/c_dependencies/mypkg1/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mypkg1" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | 6 | [c-dependencies] 7 | sqlite3 = "latest" 8 | -------------------------------------------------------------------------------- /tests/files/c_dependencies/mypkg1/src/lib.mys: -------------------------------------------------------------------------------- 1 | c"""header-before-namespace 2 | #include 3 | """ 4 | 5 | enum Result: 6 | Ok = c"SQLITE_OK" 7 | Row = c"SQLITE_ROW" 8 | Done = c"SQLITE_DONE" 9 | -------------------------------------------------------------------------------- /tests/files/c_dependencies_not_found/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mypkg" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | 6 | [c-dependencies] 7 | kallebanan = "latest" 8 | -------------------------------------------------------------------------------- /tests/files/c_dependencies_not_found/src/lib.mys: -------------------------------------------------------------------------------- 1 | func foo(): 2 | pass 3 | -------------------------------------------------------------------------------- /tests/files/char_.mys: -------------------------------------------------------------------------------- 1 | func char_foo(v: char) -> char: 2 | return v 3 | 4 | test char(): 5 | a = '1' 6 | b = char(0x31) 7 | 8 | assert a == b 9 | assert char_foo('5') == '5' 10 | assert char_foo(a) == a 11 | 12 | test char_to_i64(): 13 | assert i64('1') == 0x31 14 | 15 | test not_a_character(): 16 | assert i64('') == 0xffff 17 | assert '' == '\uffff' 18 | assert str('') == "￿" 19 | 20 | test str(): 21 | # ToDo: Should be "'1'" 22 | assert str('1') == "1" 23 | 24 | test is_alpha(): 25 | assert not '1'.is_alpha() 26 | assert 'a'.is_alpha() 27 | 28 | test is_digit(): 29 | assert '1'.is_digit() 30 | assert not 'a'.is_digit() 31 | 32 | test is_numeric(): 33 | assert '1'.is_numeric() 34 | assert not 'a'.is_numeric() 35 | 36 | test is_space(): 37 | assert ' '.is_space() 38 | assert not 'a'.is_space() 39 | -------------------------------------------------------------------------------- /tests/files/circular_imports/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "circular_imports" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /tests/files/circular_imports/src/mod1.mys: -------------------------------------------------------------------------------- 1 | from .mod2 import Base2 2 | from .mod2 import Foo2 3 | from .mod2 import VAR2 4 | from .mod2 import func2 5 | 6 | trait Base1: 7 | pass 8 | 9 | class Foo1(Base2): 10 | a: Foo1? 11 | b: Foo2? 12 | c: Base1? 13 | d: Base2? 14 | 15 | VAR1: Foo1 = Foo1(None, Foo2(None, None, None, None), None, None) 16 | 17 | func func1(): 18 | pass 19 | 20 | test foo_1(): 21 | print(Foo1(None, None, None, None)) 22 | 23 | test foo_2(): 24 | print(Foo2(None, None, None, None)) 25 | 26 | test var_1(): 27 | assert VAR1.a is None 28 | assert VAR1.b is not None 29 | 30 | test var_2(): 31 | assert VAR2.i is not None 32 | assert VAR2.j is None 33 | 34 | test func_1(): 35 | func1() 36 | 37 | test func_2(): 38 | func2() 39 | -------------------------------------------------------------------------------- /tests/files/circular_imports/src/mod2.mys: -------------------------------------------------------------------------------- 1 | from .mod1 import Base1 2 | from .mod1 import Foo1 3 | from .mod1 import VAR1 4 | from .mod1 import func1 5 | 6 | trait Base2: 7 | pass 8 | 9 | class Foo2(Base1): 10 | i: Foo1? 11 | j: Foo2? 12 | k: Base1? 13 | l: Base2? 14 | 15 | VAR2: Foo2 = Foo2(Foo1(None, None, None, None), None, None, None) 16 | 17 | func func2(): 18 | pass 19 | 20 | test foo_1(): 21 | print(Foo1(None, None, None, None)) 22 | 23 | test foo_2(): 24 | print(Foo2(None, None, None, None)) 25 | 26 | test var_1(): 27 | assert VAR1.a is None 28 | assert VAR1.b is not None 29 | 30 | test var_2(): 31 | assert VAR2.i is not None 32 | assert VAR2.j is None 33 | 34 | test func_1(): 35 | func1() 36 | 37 | test func_2(): 38 | func2() 39 | -------------------------------------------------------------------------------- /tests/files/compare.mys: -------------------------------------------------------------------------------- 1 | COMPARE_MANY_1_FOO: i64 = 0 2 | 3 | func compare_many_1_foo() -> i64: 4 | COMPARE_MANY_1_FOO += 1 5 | 6 | return 2 7 | 8 | test compare_many_1(): 9 | four = 4 10 | 11 | # if (!([&]() { 12 | # const auto &v_1 = compare_many_1_foo(); 13 | # if (!(1 < v_1)) { 14 | # return false; 15 | # } 16 | # const auto &v_2 = 3; 17 | # if (!(v_1 < v_2)) { 18 | # return false; 19 | # } 20 | # if (!(v_2 <= four)) { 21 | # return false; 22 | # } 23 | # return true; 24 | # }())) 25 | if not (1 < compare_many_1_foo() < 3 <= four): 26 | assert False 27 | 28 | assert COMPARE_MANY_1_FOO == 1 29 | 30 | test compare_many_2(): 31 | # if (!([&]() { 32 | # const auto &v_1 = 2; 33 | # if (!(1 < v_1)) { 34 | # return false; 35 | # } 36 | # const auto &v_2 = __constant_1; 37 | # if (!(contains(v_1, v_2))) { 38 | # return false; 39 | # } 40 | # const auto &v_3 = __constant_2; 41 | # if (!(v_2 != v_3)) { 42 | # return false; 43 | # } 44 | # if (!(!is(v_3, nullptr))) { 45 | # return false; 46 | # } 47 | # return true; 48 | # }())) 49 | if 1 < 2 in [1, 3] != [2] is not None: 50 | assert False 51 | -------------------------------------------------------------------------------- /tests/files/copy.mys: -------------------------------------------------------------------------------- 1 | class Foo: 2 | a: i64 3 | b: string 4 | c: bytes 5 | 6 | func __deepcopy__(self, other: Foo, memo: {string: string}): 7 | self.a = deepcopy(other.a) 8 | self.b = deepcopy(other.b) 9 | self.c = deepcopy(other.c) 10 | 11 | class Bar: 12 | foo: Foo 13 | 14 | func __copy__(self, other: Bar): 15 | self.foo = None 16 | 17 | func __deepcopy__(self, other: Bar, memo: {string: string}): 18 | self.foo = deepcopy(other.foo) 19 | 20 | test copy(): 21 | foo = Foo(5, "bar", b"123") 22 | 23 | foo_copy = copy(foo) 24 | assert foo == foo_copy 25 | assert foo is not foo_copy 26 | assert foo.b is foo_copy.b 27 | assert foo.c is foo_copy.c 28 | 29 | foo_deepcopy = deepcopy(foo) 30 | assert foo == foo_deepcopy 31 | assert foo is not foo_deepcopy 32 | assert foo.c is not foo_deepcopy.c 33 | 34 | bar = Bar(foo) 35 | bar_copy = copy(bar) 36 | assert bar_copy.foo is None 37 | bar_deepcopy = deepcopy(bar) 38 | assert bar_deepcopy.foo is not bar.foo 39 | 40 | class CannotCopyError(Error): 41 | pass 42 | 43 | class CannotCopy: 44 | 45 | func __copy__(self, other: CannotCopy): 46 | raise CannotCopyError() 47 | 48 | test cannot_copy(): 49 | try: 50 | print(copy(CannotCopy())) 51 | assert False 52 | except CannotCopyError: 53 | pass 54 | -------------------------------------------------------------------------------- /tests/files/doc/doc/index.rst: -------------------------------------------------------------------------------- 1 | About 2 | ===== 3 | 4 | The doc package in the `Mys programming language`_. 5 | 6 | Examples 7 | ======== 8 | 9 | .. mysfilecontent:: examples/basic/src/main.mys 10 | 11 | Functions and types 12 | =================== 13 | 14 | .. mysfile:: src/lib.mys 15 | 16 | .. _Mys programming language: https://mys-lang.org 17 | -------------------------------------------------------------------------------- /tests/files/doc/examples/basic/src/main.mys: -------------------------------------------------------------------------------- 1 | func main(): 2 | pass 3 | -------------------------------------------------------------------------------- /tests/files/doc/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "test_doc" 3 | version = "0.1.0" 4 | authors = ["Test Er "] 5 | -------------------------------------------------------------------------------- /tests/files/doc/src/mod1.mys: -------------------------------------------------------------------------------- 1 | func add(first: i32, second: i32) -> i32: 2 | """Returns the sum of given numbers `first` and `second`. 3 | 4 | """ 5 | 6 | return first + second 7 | 8 | test add(): 9 | assert add(1, 2) == 3 10 | -------------------------------------------------------------------------------- /tests/files/embedded_cpp/mypkg/README.rst: -------------------------------------------------------------------------------- 1 | Mypkg 2 | ===== 3 | 4 | Add more information about your package here! 5 | -------------------------------------------------------------------------------- /tests/files/embedded_cpp/mypkg/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mypkg" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | 6 | [dependencies] 7 | mypkg1 = { path = "../mypkg1" } 8 | -------------------------------------------------------------------------------- /tests/files/embedded_cpp/mypkg/src/cpp/bar.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Just an empty file. 4 | -------------------------------------------------------------------------------- /tests/files/embedded_cpp/mypkg/src/cpp/foo.cpp: -------------------------------------------------------------------------------- 1 | #include "foo.hpp" 2 | #include "bar.hpp" 3 | 4 | // It's good practice to use the package namespace is possible. 5 | namespace mys::mypkg::foo 6 | { 7 | 8 | int foobar(int v) 9 | { 10 | return 3 * v; 11 | } 12 | 13 | }; 14 | -------------------------------------------------------------------------------- /tests/files/embedded_cpp/mypkg/src/cpp/foo.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // It's good practice to use the package namespace is possible. 4 | namespace mys::mypkg::foo 5 | { 6 | int foobar(int v); 7 | }; 8 | -------------------------------------------------------------------------------- /tests/files/embedded_cpp/mypkg/src/lib.mys: -------------------------------------------------------------------------------- 1 | from mypkg1 import foo as foo2 2 | 3 | c"""source-before-namespace 4 | #include "cpp/foo.hpp" 5 | """ 6 | 7 | c""" 8 | static int global_variable = 0; 9 | """ 10 | 11 | func foo() -> i32: 12 | a = foo2() 13 | 14 | c""" 15 | a += foo::foobar(3) + global_variable; 16 | """ 17 | 18 | return a 19 | 20 | test foo(): 21 | assert foo2() == 4 22 | assert foo() == 13 23 | 24 | class Foo: 25 | c""" 26 | int m_a; 27 | bool m_b; 28 | """ 29 | 30 | func members(self) -> (i64, bool): 31 | a: i64 = 0 32 | b: bool = False 33 | 34 | c""" 35 | // Backslash should work. 36 | std::cout << "Hi\n"; 37 | a = m_a; 38 | b = Bool(m_b); 39 | """ 40 | 41 | return (a, b) 42 | -------------------------------------------------------------------------------- /tests/files/embedded_cpp/mypkg1/README.rst: -------------------------------------------------------------------------------- 1 | Mypkg3 2 | ====== 3 | 4 | Add more information about your package here! 5 | -------------------------------------------------------------------------------- /tests/files/embedded_cpp/mypkg1/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mypkg1" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /tests/files/embedded_cpp/mypkg1/src/foo.cpp: -------------------------------------------------------------------------------- 1 | #include "foo.hpp" 2 | 3 | // It's good practice to use the package namespace is possible. 4 | namespace mys::mypkg1::foo 5 | { 6 | 7 | int foobar(int v) 8 | { 9 | return 2 * v; 10 | } 11 | 12 | }; 13 | -------------------------------------------------------------------------------- /tests/files/embedded_cpp/mypkg1/src/foo.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // It's good practice to use the package namespace is possible. 4 | namespace mys::mypkg1::foo 5 | { 6 | int foobar(int v); 7 | }; 8 | -------------------------------------------------------------------------------- /tests/files/embedded_cpp/mypkg1/src/lib.mys: -------------------------------------------------------------------------------- 1 | c"""source-before-namespace 2 | #include "foo.hpp" 3 | """ 4 | 5 | func foo() -> i32: 6 | a: i32 = 0 7 | 8 | c""" 9 | a = foo::foobar(2); 10 | """ 11 | 12 | return a 13 | -------------------------------------------------------------------------------- /tests/files/error_if_package_name_is_not_snake_case/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "a-hypen" 3 | version = "0.1.0" 4 | authors = ["Test Er "] 5 | -------------------------------------------------------------------------------- /tests/files/error_if_package_name_is_not_snake_case/src/lib.mys: -------------------------------------------------------------------------------- 1 | func add(first: i32, second: i32) -> i32: 2 | return first + second 3 | -------------------------------------------------------------------------------- /tests/files/error_if_package_version_is_not_semantic/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "foo" 3 | version = "1.0" 4 | authors = ["Test Er "] 5 | -------------------------------------------------------------------------------- /tests/files/error_if_package_version_is_not_semantic/src/lib.mys: -------------------------------------------------------------------------------- 1 | func add(first: i32, second: i32) -> i32: 2 | return first + second 3 | -------------------------------------------------------------------------------- /tests/files/fie/README.rst: -------------------------------------------------------------------------------- 1 | Fie 2 | === 3 | 4 | Add more information about your package here! 5 | -------------------------------------------------------------------------------- /tests/files/fie/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fie" 3 | version = "1.0.0" 4 | authors = ["Erik Moqvist "] 5 | 6 | [dependencies] 7 | -------------------------------------------------------------------------------- /tests/files/fie/src/lib.mys: -------------------------------------------------------------------------------- 1 | func hi(name: string): 2 | print("Hi, " + name + "!") 3 | -------------------------------------------------------------------------------- /tests/files/fie/src/main.mys: -------------------------------------------------------------------------------- 1 | func main(): 2 | print("Hello, world!") 3 | -------------------------------------------------------------------------------- /tests/files/foo/.gitattributes: -------------------------------------------------------------------------------- 1 | *.mys linguist-language=python 2 | -------------------------------------------------------------------------------- /tests/files/foo/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | *~ 3 | .coverage 4 | .mys-coverage.txt 5 | coverage/ 6 | -------------------------------------------------------------------------------- /tests/files/foo/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Mys Lang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /tests/files/foo/README.rst: -------------------------------------------------------------------------------- 1 | Test Foo New And Run 2 | ==================== 3 | 4 | Test Foo New And Run in the `Mys programming language`_. 5 | 6 | Documentation: https://mys-lang.org/package/test-foo-new-and-run/latest/index.html 7 | 8 | .. _Mys programming language: https://mys-lang.org 9 | -------------------------------------------------------------------------------- /tests/files/foo/doc/index.rst: -------------------------------------------------------------------------------- 1 | About 2 | ===== 3 | 4 | The Test Foo New And Run package in the `Mys programming language`_. 5 | 6 | API 7 | === 8 | 9 | .. mysfile:: src/lib.mys 10 | 11 | .. _Mys programming language: https://mys-lang.org 12 | -------------------------------------------------------------------------------- /tests/files/foo/doc/lib.rst: -------------------------------------------------------------------------------- 1 | lib -- My mighty module 2 | ======================= 3 | 4 | Overview of what the module provides and how to use it. 5 | 6 | ---------------------------------------------- 7 | 8 | .. mysfile:: src/lib.mys 9 | -------------------------------------------------------------------------------- /tests/files/foo/doc/modules.rst: -------------------------------------------------------------------------------- 1 | Modules 2 | ======= 3 | 4 | This package provides the following modules. 5 | 6 | .. toctree:: 7 | :maxdepth: 1 8 | :titlesonly: 9 | 10 | modules/lib 11 | -------------------------------------------------------------------------------- /tests/files/foo/doc/modules/lib.rst: -------------------------------------------------------------------------------- 1 | lib -- My mighty module 2 | ======================= 3 | 4 | Overview of what the module provides and how to use it. 5 | 6 | ---------------------------------------------- 7 | 8 | .. mysfile:: src/lib.mys 9 | -------------------------------------------------------------------------------- /tests/files/foo/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "test_foo_new_and_run" 3 | version = "0.1.0" 4 | authors = ["Test Er "] 5 | description = "Add a short package description here." 6 | 7 | [dependencies] 8 | # foobar = "latest" 9 | -------------------------------------------------------------------------------- /tests/files/foo/src/lib.mys: -------------------------------------------------------------------------------- 1 | func add(first: i32, second: i32) -> i32: 2 | """Returns the sum of given numbers `first` and `second`. 3 | 4 | """ 5 | 6 | return first + second 7 | 8 | test add(): 9 | assert add(1, 2) == 3 10 | -------------------------------------------------------------------------------- /tests/files/foo/src/main.mys: -------------------------------------------------------------------------------- 1 | func main(): 2 | print("Hello, world!") 3 | -------------------------------------------------------------------------------- /tests/files/foo/tests/test_lib.mys: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mys-lang/mys/f3cb604e95eadd9833466dbd43ac9f5913f31d60/tests/files/foo/tests/test_lib.mys -------------------------------------------------------------------------------- /tests/files/globals_init_order/mypkg/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mypkg" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /tests/files/globals_init_order/mypkg/src/lib.mys: -------------------------------------------------------------------------------- 1 | from .mod1 import A 2 | from .mod1 import B 3 | from .mod1 import C 4 | from .mod2 import X 5 | from .mod2 import Y 6 | 7 | func f() -> i64: 8 | print("lib") 9 | 10 | return 3 11 | 12 | F: i64 = f() 13 | 14 | test variables(): 15 | assert A is None 16 | assert B == 10 17 | assert C == "Hello" 18 | assert X is None 19 | assert Y == 5 20 | assert F == 3 21 | -------------------------------------------------------------------------------- /tests/files/globals_init_order/mypkg/src/mod1.mys: -------------------------------------------------------------------------------- 1 | from .mod2 import X 2 | from .mod2 import Y 3 | 4 | func a() -> string: 5 | print("mod1 a") 6 | 7 | return X 8 | 9 | func c() -> string: 10 | print("mod1 c") 11 | 12 | return "Hello" 13 | 14 | A: string? = a() 15 | B: i64 = 2 * Y 16 | C: string = c() 17 | -------------------------------------------------------------------------------- /tests/files/globals_init_order/mypkg/src/mod2.mys: -------------------------------------------------------------------------------- 1 | from .mod1 import C 2 | 3 | func x() -> string: 4 | print("mod2") 5 | 6 | return C 7 | 8 | X: string? = x() 9 | Y: i64 = 5 10 | -------------------------------------------------------------------------------- /tests/files/hello_world.mys: -------------------------------------------------------------------------------- 1 | test all(): 2 | print("Hello, world!") 3 | -------------------------------------------------------------------------------- /tests/files/imports/mypkg/README.rst: -------------------------------------------------------------------------------- 1 | Mypkg 2 | ===== 3 | 4 | Add more information about your package here! 5 | -------------------------------------------------------------------------------- /tests/files/imports/mypkg/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mypkg" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | 6 | [dependencies] 7 | mypkg1 = { path = "../mypkg1" } 8 | mypkg2 = { path = "../mypkg2" } 9 | -------------------------------------------------------------------------------- /tests/files/imports/mypkg/src/mod2.mys: -------------------------------------------------------------------------------- 1 | trait Ko: 2 | pass 3 | -------------------------------------------------------------------------------- /tests/files/imports/mypkg/src/mod3.mys: -------------------------------------------------------------------------------- 1 | class Fie: 2 | 3 | func fum(self) -> u8: 4 | return 10 5 | 6 | class Fam: 7 | pass 8 | -------------------------------------------------------------------------------- /tests/files/imports/mypkg/src/mod4.mys: -------------------------------------------------------------------------------- 1 | from .mod1 import Base 2 | 3 | class ImplementsTrait(Base): 4 | # Problem was that the bar method in Base returns a string 5 | # literal, which failed because source_lines was from this file 6 | # instead of mod1.mys. 7 | 8 | func foo(self) -> string: 9 | return "k" 10 | 11 | test strings(): 12 | v = ImplementsTrait() 13 | 14 | assert v.foo() == "k" 15 | assert v.bar() == "base" 16 | assert v.fie() == 'a' 17 | -------------------------------------------------------------------------------- /tests/files/imports/mypkg1/README.rst: -------------------------------------------------------------------------------- 1 | Mypkg3 2 | ====== 3 | 4 | Add more information about your package here! 5 | -------------------------------------------------------------------------------- /tests/files/imports/mypkg1/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mypkg1" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | 6 | [dependencies] 7 | # foobar = "latest" 8 | -------------------------------------------------------------------------------- /tests/files/imports/mypkg1/src/_mod1.mys: -------------------------------------------------------------------------------- 1 | class Foo: 2 | pass 3 | -------------------------------------------------------------------------------- /tests/files/imports/mypkg1/src/_subpkg2/mod1.mys: -------------------------------------------------------------------------------- 1 | class Foo: 2 | pass 3 | -------------------------------------------------------------------------------- /tests/files/imports/mypkg1/src/lib.mys: -------------------------------------------------------------------------------- 1 | from mypkg2 import VAR1 2 | from mypkg2 import Class1 as Pkg2Class1 3 | from mypkg2 import fum 4 | # Foo must be imported from the module that defines it, even if it is 5 | # the type of the fum parameter. It's not allowed to export an 6 | # imported name. You must always import from the module where it is 7 | # defined. That means public names can't be moved from one module to 8 | # another without breaking the public API. 9 | from mypkg2.mod1 import Foo 10 | # Private modules (leading underscore in module or in the path to it) 11 | # can only be used by other modules in the same package. 12 | from ._mod1 import Foo as PackagePrivateFoo1 13 | from ._subpkg2.mod1 import Foo as PackagePrivateFoo2 14 | 15 | VAR2: i32 = 7 16 | VAR3: i32 = 1 17 | 18 | class Class1: 19 | _x: PackagePrivateFoo2? 20 | # Can't use private types in public API. 21 | # y: PackagePrivateFoo2 22 | 23 | func foo(a: Class1, b: Pkg2Class1): 24 | pass 25 | 26 | func bar(): 27 | fum(Foo()) 28 | 29 | func tam(): 30 | print(PackagePrivateFoo1()) 31 | 32 | # It's not allowed to use types private to the package in the public 33 | # API. Compile time error. 34 | 35 | # func tam() -> PackagePrivateFoo1: 36 | # return PackagePrivateFoo1() 37 | -------------------------------------------------------------------------------- /tests/files/imports/mypkg1/src/subpkg1/mod1.mys: -------------------------------------------------------------------------------- 1 | from .. import VAR2 2 | 3 | func func1(first: i32, second: i32) -> i32: 4 | return first + second 5 | 6 | func func2(first: i32, second: i32) -> i32: 7 | return first * second 8 | 9 | class Class1: 10 | 11 | value: i32 12 | 13 | class Class2: 14 | pass 15 | 16 | test func1(): 17 | assert func1(1, 2) == 3 18 | 19 | test var2(): 20 | assert VAR2 == 7 21 | -------------------------------------------------------------------------------- /tests/files/imports/mypkg2/README.rst: -------------------------------------------------------------------------------- 1 | Mypkg4 2 | ====== 3 | 4 | Add more information about your package here! 5 | -------------------------------------------------------------------------------- /tests/files/imports/mypkg2/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mypkg2" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | 6 | [dependencies] 7 | # foobar = "latest" 8 | -------------------------------------------------------------------------------- /tests/files/imports/mypkg2/src/lib.mys: -------------------------------------------------------------------------------- 1 | from .mod1 import Foo 2 | 3 | VAR1: Class1 = Class1(5) 4 | 5 | func func2(first: i32) -> i32: 6 | return first 7 | 8 | class Class1: 9 | 10 | value: i32 11 | 12 | class Class2: 13 | pass 14 | 15 | func fum(a: Foo): 16 | pass 17 | -------------------------------------------------------------------------------- /tests/files/imports/mypkg2/src/mod1.mys: -------------------------------------------------------------------------------- 1 | class Foo: 2 | pass 3 | -------------------------------------------------------------------------------- /tests/files/install/bar/assets/bar.txt: -------------------------------------------------------------------------------- 1 | hi 2 | -------------------------------------------------------------------------------- /tests/files/install/bar/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "bar" 3 | version = "0.1.0" 4 | authors = ["Erik Moqvist "] 5 | description = "Add a short package description here." 6 | 7 | [dependencies] 8 | # foobar = "latest" 9 | -------------------------------------------------------------------------------- /tests/files/install/bar/src/lib.mys: -------------------------------------------------------------------------------- 1 | func hello(): 2 | print("hello") 3 | -------------------------------------------------------------------------------- /tests/files/install/foo/assets/foo.json: -------------------------------------------------------------------------------- 1 | gogo -------------------------------------------------------------------------------- /tests/files/install/foo/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "foo" 3 | version = "0.1.0" 4 | authors = ["Erik Moqvist "] 5 | description = "Add a short package description here." 6 | 7 | [dependencies] 8 | bar = { path = "../bar" } 9 | -------------------------------------------------------------------------------- /tests/files/install/foo/src/main.mys: -------------------------------------------------------------------------------- 1 | from bar import hello 2 | 3 | func main(): 4 | hello() 5 | -------------------------------------------------------------------------------- /tests/files/lib.mys: -------------------------------------------------------------------------------- 1 | class String: 2 | x: string 3 | 4 | test string(): 5 | assert String("5").x == "5" 6 | 7 | class Bool: 8 | x: bool 9 | 10 | test bool(): 11 | assert Bool(True).x 12 | 13 | func shared_ptr_not_none(): 14 | pass 15 | 16 | class Foo: 17 | a: i64 18 | 19 | test shared_ptr_not_none(): 20 | shared_ptr_not_none() 21 | assert Foo(1).a == 1 22 | -------------------------------------------------------------------------------- /tests/files/package_and_module_with_same_name/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "foo" 3 | version = "0.1.0" 4 | authors = ["Mys Lang "] 5 | -------------------------------------------------------------------------------- /tests/files/package_and_module_with_same_name/src/foo.mys: -------------------------------------------------------------------------------- 1 | V: i64 = 1 2 | 3 | func foo(): 4 | pass 5 | 6 | class Foo(): 7 | pass 8 | 9 | enum A: 10 | B = 1 11 | 12 | test foo(): 13 | assert V == 1 14 | foo() 15 | assert str(Foo()) == "Foo()" 16 | assert A.B == A.B 17 | -------------------------------------------------------------------------------- /tests/files/package_with_local_and_registry_dependencies/dep1/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "dep1" 3 | version = "1.1.0" 4 | authors = ["Erik Moqvist "] 5 | description = "Add a short package description here." 6 | 7 | [dependencies] 8 | dep2 = { path = "../dep2" } 9 | hello_world = "2.0.0-rc4" -------------------------------------------------------------------------------- /tests/files/package_with_local_and_registry_dependencies/dep1/src/lib.mys: -------------------------------------------------------------------------------- 1 | func add(first: i32, second: i32) -> i32: 2 | """Returns the sum of given numbers `first` and `second`. 3 | 4 | """ 5 | 6 | return first + second 7 | 8 | test add(): 9 | assert add(1, 2) == 3 10 | -------------------------------------------------------------------------------- /tests/files/package_with_local_and_registry_dependencies/dep2/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "dep2" 3 | version = "0.1.0-rc10" 4 | authors = ["Erik Moqvist "] 5 | description = "Add a short package description here." 6 | 7 | [dependencies] 8 | hello_world = "0.1.0" 9 | -------------------------------------------------------------------------------- /tests/files/package_with_local_and_registry_dependencies/dep2/src/lib.mys: -------------------------------------------------------------------------------- 1 | func add(first: i32, second: i32) -> i32: 2 | """Returns the sum of given numbers `first` and `second`. 3 | 4 | """ 5 | 6 | return first + second 7 | 8 | test add(): 9 | assert add(1, 2) == 3 10 | -------------------------------------------------------------------------------- /tests/files/package_with_local_and_registry_dependencies/top/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "top" 3 | version = "0.1.0" 4 | authors = ["Erik Moqvist "] 5 | description = "Add a short package description here." 6 | 7 | [dependencies] 8 | dep1 = { path = "../dep1" } 9 | dep2 = { path = "../dep2" } 10 | -------------------------------------------------------------------------------- /tests/files/package_with_local_and_registry_dependencies/top/src/main.mys: -------------------------------------------------------------------------------- 1 | func main(): 2 | print("Hello, world!") 3 | -------------------------------------------------------------------------------- /tests/files/regexp.mys: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mys-lang/mys/f3cb604e95eadd9833466dbd43ac9f5913f31d60/tests/files/regexp.mys -------------------------------------------------------------------------------- /tests/files/signals/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "signals" 3 | version = "0.1.0" 4 | authors = ["Erik Moqvist "] 5 | 6 | [dependencies] 7 | -------------------------------------------------------------------------------- /tests/files/signals/src/lib.mys: -------------------------------------------------------------------------------- 1 | from fiber import sleep 2 | 3 | test sigint(): 4 | print("sigint started", flush=True) 5 | 6 | try: 7 | ok = False 8 | sleep(60.0) 9 | except InterruptError as error: 10 | print(error) 11 | ok = True 12 | 13 | assert ok 14 | -------------------------------------------------------------------------------- /tests/files/special_symbols.mys: -------------------------------------------------------------------------------- 1 | test line(): 2 | x: u64 = __line__ 3 | y = __line__ 4 | z = __line__ + __line__ 5 | 6 | assert x == 2 7 | assert y == 3 8 | assert z == 2 * 4 9 | 10 | test unique_id(): 11 | x: i64 = __unique_id__ 12 | y = __unique_id__ 13 | 14 | assert x != y 15 | 16 | test name(): 17 | assert __name__ == "test_special_symbols.special_symbols" 18 | 19 | test file(): 20 | assert __file__ == "./src/special_symbols.mys" 21 | 22 | func foo(path: string, line: u64, name: string, unique_id: i64) -> string: 23 | return f"{path}:{line} {name} {unique_id}" 24 | 25 | test pass_to_function(): 26 | value = foo(__file__, __line__, __name__, __unique_id__) 27 | assert value.starts_with( 28 | "./src/special_symbols.mys:26 test_special_symbols.special_symbols ") 29 | 30 | test version(): 31 | assert __version__ == "0.1.0" 32 | -------------------------------------------------------------------------------- /tests/files/style/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "test_style" 3 | version = "0.1.0" 4 | authors = ["Test Er "] 5 | -------------------------------------------------------------------------------- /tests/files/style/src/f/mod.mys: -------------------------------------------------------------------------------- 1 | V : i64 = 1 2 | -------------------------------------------------------------------------------- /tests/files/style/src/mod.mys: -------------------------------------------------------------------------------- 1 | # Nothing. 2 | -------------------------------------------------------------------------------- /tests/files/style/src/trailing_whitespaces.mys: -------------------------------------------------------------------------------- 1 | # Trailing whitespaces on all lines in this file. 2 | class A: 3 | pass 4 | 5 | func foo(a: i64): 6 | print(a) 7 | 8 | pass 9 | 10 | -------------------------------------------------------------------------------- /tests/files/style/styled-src/f/mod.mys: -------------------------------------------------------------------------------- 1 | V: i64 = 1 2 | -------------------------------------------------------------------------------- /tests/files/style/styled-src/mod.mys: -------------------------------------------------------------------------------- 1 | # Nothing. 2 | -------------------------------------------------------------------------------- /tests/files/style/styled-src/trailing_whitespaces.mys: -------------------------------------------------------------------------------- 1 | # Trailing whitespaces on all lines in this file. 2 | class A: 3 | pass 4 | 5 | func foo(a: i64): 6 | print(a) 7 | 8 | pass 9 | -------------------------------------------------------------------------------- /tests/files/test_new_author_from_git/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "test_new_author_from_git" 3 | version = "0.1.0" 4 | authors = ["First Last "] 5 | description = "Add a short package description here." 6 | 7 | [dependencies] 8 | # foobar = "latest" 9 | -------------------------------------------------------------------------------- /tests/files/test_new_multiple_authors/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "test_new_multiple_authors" 3 | version = "0.1.0" 4 | authors = ["Test Er ", "Test2 Er2 "] 5 | description = "Add a short package description here." 6 | 7 | [dependencies] 8 | # foobar = "latest" 9 | -------------------------------------------------------------------------------- /tests/files/test_test_new_git_command_failure/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "test_new_git_command_failure" 3 | version = "0.1.0" 4 | authors = ["mystester "] 5 | description = "Add a short package description here." 6 | 7 | [dependencies] 8 | # foobar = "latest" 9 | -------------------------------------------------------------------------------- /tests/files/traceback/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "test_traceback" 3 | version = "0.1.0" 4 | authors = ["Test Er "] 5 | -------------------------------------------------------------------------------- /tests/files/traceback/src/main.mys: -------------------------------------------------------------------------------- 1 | class AnError(Error): 2 | message: string 3 | 4 | func main(): 5 | raise AnError("hi") 6 | -------------------------------------------------------------------------------- /tests/files/unsafe/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "test_unsafe" 3 | version = "0.1.0" 4 | authors = ["Test Er "] 5 | -------------------------------------------------------------------------------- /tests/files/weak.mys: -------------------------------------------------------------------------------- 1 | _SIMPLE_DESTROYED: i64 = 0 2 | 3 | class Simple: 4 | parent: weak[Simple?] 5 | l: weak[[i64]] 6 | t: weak[(i64, string)] 7 | d: weak[{i64: i64}] 8 | s: weak[{i64}] 9 | 10 | func __init__(self, parent: Simple?): 11 | self.parent = parent 12 | self.l = [] 13 | self.t = (1, "") 14 | self.d = {} 15 | self.s = {} 16 | 17 | func __del__(self): 18 | _SIMPLE_DESTROYED += 1 19 | 20 | func simple_worker(): 21 | simple = Simple(None) 22 | simple.parent = simple 23 | assert simple.parent is not None 24 | 25 | if simple.parent is None: 26 | assert False 27 | 28 | simple.parent.parent = Simple(simple) 29 | 30 | test simple(): 31 | simple_worker() 32 | assert _SIMPLE_DESTROYED == 2 33 | -------------------------------------------------------------------------------- /tests/files/weak_panic.mys: -------------------------------------------------------------------------------- 1 | class Simple: 2 | parent: weak[Simple?] 3 | 4 | test is_none(): 5 | simple = Simple(None) 6 | print(simple.parent.parent) 7 | 8 | func no_object(simple: Simple): 9 | simple.parent = Simple(None) 10 | 11 | test no_object(): 12 | simple = Simple(None) 13 | no_object(simple) 14 | print(simple.parent.parent) 15 | -------------------------------------------------------------------------------- /tests/test_asserts.py: -------------------------------------------------------------------------------- 1 | from .utils import TestCase 2 | from .utils import build_and_test_module 3 | 4 | 5 | class Test(TestCase): 6 | 7 | def test_asserts(self): 8 | build_and_test_module('asserts') 9 | 10 | def test_assert_function_that_does_not_return_any_value(self): 11 | self.assert_transpile_raises( 12 | 'func foo():\n' 13 | ' pass\n' 14 | 'func bar():\n' 15 | ' assert foo()\n', 16 | ' File "", line 4\n' 17 | ' assert foo()\n' 18 | ' ^\n' 19 | "CompileError: expected a 'bool', got 'None'\n") 20 | -------------------------------------------------------------------------------- /tests/test_assets.py: -------------------------------------------------------------------------------- 1 | import shutil 2 | from unittest.mock import patch 3 | 4 | import mys.cli 5 | 6 | from .utils import Path 7 | from .utils import TestCase 8 | from .utils import remove_build_directory 9 | 10 | 11 | class Test(TestCase): 12 | 13 | def test_assets(self): 14 | name = 'test_assets' 15 | remove_build_directory(name) 16 | shutil.copytree('tests/files/assets', f'tests/build/{name}') 17 | 18 | with Path(f'tests/build/{name}/mypkg'): 19 | with patch('sys.argv', ['mys', '-d', 'test']): 20 | mys.cli.main() 21 | 22 | self.assert_files_equal( 23 | f'tests/build/{name}/mypkg/build/debug/test-assets/mypkg/foo.txt', 24 | 'tests/files/assets/mypkg/assets/foo.txt') 25 | self.assert_files_equal( 26 | f'tests/build/{name}/mypkg/build/debug/test-assets/mypkg/bar/bar.txt', 27 | 'tests/files/assets/mypkg/assets/bar/bar.txt') 28 | self.assert_files_equal( 29 | f'tests/build/{name}/mypkg/build/debug/test-assets/mypkg1/foo.txt', 30 | 'tests/files/assets/mypkg1/assets/foo.txt') 31 | -------------------------------------------------------------------------------- /tests/test_bytes.py: -------------------------------------------------------------------------------- 1 | from .utils import TestCase 2 | from .utils import build_and_test_module 3 | 4 | 5 | class Test(TestCase): 6 | 7 | def test_bytes(self): 8 | build_and_test_module('bytes') 9 | -------------------------------------------------------------------------------- /tests/test_comprehensions.py: -------------------------------------------------------------------------------- 1 | from .utils import TestCase 2 | from .utils import build_and_test_module 3 | 4 | 5 | class Test(TestCase): 6 | 7 | def test_comprehensions(self): 8 | build_and_test_module('comprehensions') 9 | 10 | def test_list_comprehension_two_for_loops(self): 11 | self.assert_transpile_raises( 12 | 'func foo() -> [i64]:\n' 13 | " return [x * y for x in [1] for y in [2]]\n", 14 | ' File "", line 2\n' 15 | ' return [x * y for x in [1] for y in [2]]\n' 16 | " ^\n" 17 | 'CompileError: only one for-loop allowed\n') 18 | 19 | def test_comprehension_over_tuple(self): 20 | self.assert_transpile_raises( 21 | 'func foo() -> [i64]:\n' 22 | " return [x for x in (1, True)]\n", 23 | ' File "", line 2\n' 24 | ' return [x for x in (1, True)]\n' 25 | " ^\n" 26 | 'CompileError: iteration over tuples not allowed\n') 27 | -------------------------------------------------------------------------------- /tests/test_copy.py: -------------------------------------------------------------------------------- 1 | from .utils import TestCase 2 | 3 | # from .utils import build_and_test_module 4 | 5 | 6 | class Test(TestCase): 7 | 8 | def test_copy(self): 9 | # build_and_test_module('copy') 10 | pass 11 | -------------------------------------------------------------------------------- /tests/test_doc.py: -------------------------------------------------------------------------------- 1 | import re 2 | import shutil 3 | from html.parser import HTMLParser 4 | from unittest.mock import patch 5 | 6 | import mys.cli 7 | 8 | from .utils import Path 9 | from .utils import TestCase 10 | from .utils import read_file 11 | from .utils import remove_build_directory 12 | 13 | 14 | class HTMLText(HTMLParser): 15 | 16 | def __init__(self): 17 | super().__init__() 18 | self.text = '' 19 | 20 | def handle_data(self, data): 21 | self.text += data 22 | 23 | 24 | class Test(TestCase): 25 | 26 | def test_doc(self): 27 | name = 'test_doc' 28 | remove_build_directory(name) 29 | 30 | shutil.copytree('tests/files/doc', f'tests/build/{name}') 31 | 32 | with Path(f'tests/build/{name}'): 33 | with patch('sys.argv', ['mys', '-d', 'doc']): 34 | mys.cli.main() 35 | 36 | self.assert_file_exists('build/doc/html/index.html') 37 | 38 | html_text = HTMLText() 39 | html_text.feed(read_file('build/doc/html/index.html')) 40 | 41 | with open('index.txt', 'w') as fout: 42 | mo = re.search( 43 | r'(The doc package in the Mys programming language.*)© Copyright', 44 | html_text.text, 45 | re.DOTALL) 46 | fout.write(mo.group(1).strip()) 47 | 48 | self.assert_files_equal('index.txt', '../../files/doc/index.txt') 49 | -------------------------------------------------------------------------------- /tests/test_fibers.py: -------------------------------------------------------------------------------- 1 | from .utils import TestCase 2 | from .utils import build_and_test_module 3 | 4 | 5 | class Test(TestCase): 6 | 7 | def test_fibers(self): 8 | build_and_test_module('fibers') 9 | -------------------------------------------------------------------------------- /tests/test_fstrings.py: -------------------------------------------------------------------------------- 1 | from .utils import TestCase 2 | from .utils import build_and_test_module 3 | 4 | 5 | class Test(TestCase): 6 | 7 | def test_fstrings(self): 8 | build_and_test_module('fstrings') 9 | 10 | def test_invalid_format_spec(self): 11 | self.assert_transpile_raises( 12 | 'func foo() -> string:\n' 13 | ' return f"{1:f}"\n', 14 | ' File "", line 2\n' 15 | ' return f"{1:f}"\n' 16 | ' ^\n' 17 | "CompileError: invalid integer format specifier 'f'\n") 18 | 19 | def test_invalid_format_spec_2(self): 20 | self.assert_transpile_raises( 21 | 'func foo() -> string:\n' 22 | ' return f"{1:08d}"\n', 23 | ' File "", line 2\n' 24 | ' return f"{1:08d}"\n' 25 | ' ^\n' 26 | "CompileError: invalid integer format specifier '08d'\n") 27 | 28 | def test_float_with_format_spec(self): 29 | self.assert_transpile_raises( 30 | 'func foo() -> string:\n' 31 | ' return f"{1.0:d}"\n', 32 | ' File "", line 2\n' 33 | ' return f"{1.0:d}"\n' 34 | ' ^\n' 35 | "CompileError: format specifiers are only allowed for integers\n") 36 | -------------------------------------------------------------------------------- /tests/test_globals_init_order.py: -------------------------------------------------------------------------------- 1 | import shutil 2 | from unittest.mock import patch 3 | 4 | import mys.cli 5 | 6 | from .utils import Path 7 | from .utils import TestCase 8 | from .utils import remove_build_directory 9 | 10 | 11 | class Test(TestCase): 12 | 13 | def test_globals_init_order(self): 14 | name = 'test_globals_init_order' 15 | remove_build_directory(name) 16 | shutil.copytree('tests/files/globals_init_order', f'tests/build/{name}') 17 | 18 | with Path(f'tests/build/{name}/mypkg'): 19 | with patch('sys.argv', ['mys', '-d', 'test']): 20 | mys.cli.main() 21 | -------------------------------------------------------------------------------- /tests/test_hash.py: -------------------------------------------------------------------------------- 1 | from .utils import TestCase 2 | from .utils import build_and_test_module 3 | 4 | 5 | class Test(TestCase): 6 | 7 | def test_bytes(self): 8 | build_and_test_module('hash') 9 | -------------------------------------------------------------------------------- /tests/test_lib.py: -------------------------------------------------------------------------------- 1 | from .utils import TestCase 2 | from .utils import build_and_test_module 3 | 4 | 5 | class Test(TestCase): 6 | 7 | def test_char(self): 8 | build_and_test_module('lib') 9 | -------------------------------------------------------------------------------- /tests/test_loops.py: -------------------------------------------------------------------------------- 1 | from .utils import TestCase 2 | from .utils import build_and_test_module 3 | 4 | 5 | class Test(TestCase): 6 | 7 | def test_loops(self): 8 | build_and_test_module('loops') 9 | 10 | def test_for_else_not_supported(self): 11 | self.assert_transpile_raises( 12 | 'func foo():\n' 13 | ' for _ in range(3):\n' 14 | ' pass\n' 15 | ' else:\n' 16 | ' pass\n', 17 | ' File "", line 2\n' 18 | ' for _ in range(3):\n' 19 | ' ^\n' 20 | "CompileError: for else clause not supported\n") 21 | 22 | def test_while_else_not_supported(self): 23 | self.assert_transpile_raises( 24 | 'func foo():\n' 25 | ' while False:\n' 26 | ' pass\n' 27 | ' else:\n' 28 | ' pass\n', 29 | ' File "", line 2\n' 30 | ' while False:\n' 31 | ' ^\n' 32 | "CompileError: while else clause not supported\n") 33 | -------------------------------------------------------------------------------- /tests/test_macro.py: -------------------------------------------------------------------------------- 1 | from .utils import TestCase 2 | from .utils import build_and_test_module 3 | 4 | 5 | class Test(TestCase): 6 | 7 | def test_macro(self): 8 | build_and_test_module('macro') 9 | 10 | def test_macros_not_allowed_in_traits(self): 11 | self.assert_transpile_raises( 12 | 'trait Foo:\n' 13 | ' macro FOO(self):\n' 14 | ' pass\n', 15 | ' File "", line 2\n' 16 | ' macro FOO(self):\n' 17 | ' ^\n' 18 | "CompileError: traits cannot have macro methods\n") 19 | -------------------------------------------------------------------------------- /tests/test_naming.py: -------------------------------------------------------------------------------- 1 | import shutil 2 | from unittest.mock import patch 3 | 4 | import mys.cli 5 | 6 | from .utils import Path 7 | from .utils import TestCase 8 | from .utils import remove_build_directory 9 | 10 | 11 | class Test(TestCase): 12 | 13 | def test_package_and_module_with_same_name(self): 14 | name = 'test_package_and_module_with_same_name' 15 | remove_build_directory(name) 16 | shutil.copytree('tests/files/package_and_module_with_same_name', 17 | f'tests/build/{name}') 18 | 19 | with Path(f'tests/build/{name}'): 20 | with patch('sys.argv', ['mys', '-d', 'test']): 21 | mys.cli.main() 22 | -------------------------------------------------------------------------------- /tests/test_optionals.py: -------------------------------------------------------------------------------- 1 | from .utils import TestCase 2 | from .utils import build_and_test_module 3 | 4 | 5 | class Test(TestCase): 6 | 7 | def test_optionals(self): 8 | build_and_test_module('optionals') 9 | 10 | def test_set_non_optional_variable_to_none(self): 11 | self.assert_transpile_raises( 12 | 'func foo():\n' 13 | ' v: string = None\n', 14 | ' File "", line 2\n' 15 | ' v: string = None\n' 16 | ' ^\n' 17 | "CompileError: non-optional type 'string' cannot be None\n") 18 | 19 | def test_set_non_optional_parameter_to_none(self): 20 | self.assert_transpile_raises( 21 | 'func foo(v: string):\n' 22 | ' v = None\n', 23 | ' File "", line 2\n' 24 | ' v = None\n' 25 | ' ^\n' 26 | "CompileError: non-optional type 'string' cannot be None\n") 27 | 28 | def test_set_non_optional_integer_parameter_to_none(self): 29 | self.assert_transpile_raises( 30 | 'func foo(v: i64):\n' 31 | ' v = None\n', 32 | ' File "", line 2\n' 33 | ' v = None\n' 34 | ' ^\n' 35 | "CompileError: non-optional type 'i64' cannot be None\n") 36 | -------------------------------------------------------------------------------- /tests/test_set.py: -------------------------------------------------------------------------------- 1 | from .utils import TestCase 2 | from .utils import build_and_test_module 3 | 4 | 5 | class Test(TestCase): 6 | 7 | def test_set(self): 8 | build_and_test_module('set') 9 | 10 | def test_type_error(self): 11 | self.assert_transpile_raises( 12 | 'func foo():\n' 13 | ' a: u32 = {1}\n' 14 | ' print(a)\n', 15 | ' File "", line 2\n' 16 | ' a: u32 = {1}\n' 17 | ' ^\n' 18 | "CompileError: cannot convert set to 'u32'\n") 19 | 20 | def test_type_cannot_be_optional_variable(self): 21 | self.assert_transpile_raises( 22 | 'func foo():\n' 23 | ' v: {i64?} = {}\n', 24 | ' File "", line 2\n' 25 | ' v: {i64?} = {}\n' 26 | ' ^\n' 27 | "CompileError: set type cannot be optional\n") 28 | 29 | def test_type_cannot_be_optional_global(self): 30 | self.assert_transpile_raises( 31 | 'FOO: {i64?} = {}\n', 32 | ' File "", line 1\n' 33 | ' FOO: {i64?} = {}\n' 34 | ' ^\n' 35 | "CompileError: set type cannot be optional\n") 36 | 37 | def test_type_cannot_be_optional_function_parameter(self): 38 | self.assert_transpile_raises( 39 | 'func foo(x: {i64?}):\n' 40 | ' pass\n', 41 | ' File "", line 1\n' 42 | ' func foo(x: {i64?}):\n' 43 | ' ^\n' 44 | "CompileError: set type cannot be optional\n") 45 | -------------------------------------------------------------------------------- /tests/test_signals.py: -------------------------------------------------------------------------------- 1 | import shutil 2 | import signal 3 | from unittest.mock import patch 4 | 5 | import pexpect 6 | 7 | import mys.cli 8 | 9 | from .utils import Path 10 | from .utils import TestCase 11 | from .utils import remove_build_directory 12 | 13 | 14 | class Test(TestCase): 15 | 16 | def test_sigint(self): 17 | name = 'test_signals_sigint' 18 | remove_build_directory(name) 19 | 20 | shutil.copytree('tests/files/signals', f'tests/build/{name}') 21 | 22 | with Path(f'tests/build/{name}'): 23 | try: 24 | with patch('sys.argv', ['mys', 'test', 'no-test']): 25 | mys.cli.main() 26 | except SystemExit: 27 | pass 28 | 29 | test = pexpect.spawn('./build/debug/test sigint', 30 | encoding='utf-8', 31 | codec_errors='replace') 32 | test.expect('sigint started') 33 | test.kill(signal.SIGINT) 34 | # ToDo: How to fix this? 35 | # test.expect('InterruptError()') 36 | test.wait() 37 | # ToDo: How to fix this? 38 | # self.assertEqual(test.exitstatus, 0) 39 | -------------------------------------------------------------------------------- /tests/test_string_to_integer.py: -------------------------------------------------------------------------------- 1 | from .utils import TestCase 2 | from .utils import build_and_test_module 3 | 4 | 5 | class Test(TestCase): 6 | 7 | def test_string_to_integer(self): 8 | build_and_test_module('string_to_integer') 9 | -------------------------------------------------------------------------------- /tests/test_tuple.py: -------------------------------------------------------------------------------- 1 | from .utils import TestCase 2 | from .utils import build_and_test_module 3 | 4 | 5 | class Test(TestCase): 6 | 7 | def test_tuple(self): 8 | build_and_test_module('tuple') 9 | -------------------------------------------------------------------------------- /tests/test_while.py: -------------------------------------------------------------------------------- 1 | from .utils import TestCase 2 | 3 | 4 | class Test(TestCase): 5 | 6 | def test_while_non_bool(self): 7 | self.assert_transpile_raises( 8 | 'func foo():\n' 9 | ' while 1:\n' 10 | ' pass\n', 11 | ' File "", line 2\n' 12 | " while 1:\n" 13 | ' ^\n' 14 | "CompileError: expected a 'bool', got a 'i64'\n") 15 | 16 | def test_bare_integer_in_while(self): 17 | self.assert_transpile_raises( 18 | 'func foo():\n' 19 | ' while True:\n' 20 | ' 1\n', 21 | ' File "", line 3\n' 22 | ' 1\n' 23 | ' ^\n' 24 | "CompileError: bare integer\n") 25 | 26 | def test_variable_defined_in_while_can_not_be_used_after_1(self): 27 | self.assert_transpile_raises( 28 | 'func foo():\n' 29 | ' while False:\n' 30 | ' v = 1\n' 31 | ' print(v)\n', 32 | ' File "", line 4\n' 33 | ' print(v)\n' 34 | ' ^\n' 35 | "CompileError: undefined variable 'v'\n") 36 | --------------------------------------------------------------------------------