diff --git a/CHANGELOG.md b/CHANGELOG.md index d64d89e..155fbc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,14 +9,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Printing version number on non-quiet launch, or when provided `--version` or `:version` - Builtin function documentation generation from C++ Musique implementation source code - New builtins: digits +- Negative numbers! ### Removed - Release builder, since it's separate part of the project +### Fixed + +- `ceil`, `round`, `floor` didn't behave well with negative numbers +- `duration` wasn't filling note length from context and summed all notes inside chord, when it should take max +- `try` evaluated arguments too quickly + ## [0.3.1] ### Fixed diff --git a/doc/musique-vs-languages-cheatsheet.template b/doc/musique-vs-languages-cheatsheet.template index a8aa2ac..b423933 100644 --- a/doc/musique-vs-languages-cheatsheet.template +++ b/doc/musique-vs-languages-cheatsheet.template @@ -74,7 +74,7 @@ r add 1, 3 n Wywołanie funkcji n nie przymujących argumentów -m constant := (say 42, 10); +m constant := (say 42, 10), m say (call foo) p def constant(): p print(42) @@ -199,7 +199,7 @@ c w SonicPi nie ma domyślnej długości nuty; c za każdym razem trzeba ją definiować n Zmiana oktawy do 4tej -m oct 4; +m oct 4, c w SonicPi domyślna oktawa c jest ustalona jako 4 diff --git a/musique/interpreter/builtin_functions.cc b/musique/interpreter/builtin_functions.cc index 56c6225..026a9b0 100644 --- a/musique/interpreter/builtin_functions.cc +++ b/musique/interpreter/builtin_functions.cc @@ -741,7 +741,7 @@ static Result builtin_map(Interpreter &interpreter, std::vector ar //: //: # Przykład //: ``` -//: +//: //: ``` /// Scan computes inclusive prefix sum static Result builtin_scan(Interpreter &interpreter, std::vector args) @@ -1071,9 +1071,11 @@ static Result builtin_duration(Interpreter &interpreter, std::vectorlength; + chord_length = std::max(chord_length, note.length ? *note.length : interpreter.current_context->length); } + total += chord_length; })); } return total; @@ -1149,7 +1151,7 @@ static Result builtin_permute(Interpreter &i, std::vector args) return array; } -//: Funkcja `sortuje` elementy od najmniejszego do największego (w tym nuty). +//: Funkcja `sortuje` elementy od najmniejszego do największego (w tym nuty). //: //: # Sortowanie liczb //: ``` diff --git a/musique/lexer/lexer.cc b/musique/lexer/lexer.cc index be90fc5..b91e322 100644 --- a/musique/lexer/lexer.cc +++ b/musique/lexer/lexer.cc @@ -105,7 +105,7 @@ auto Lexer::next_token() -> Result> // Lex numeric literals // They may have following forms: 0, 0.1 - if (consume_if(unicode::is_digit)) { + if (consume_if(unicode::is_digit) || consume_if('-', unicode::is_digit)) { while (consume_if(unicode::is_digit)) {} if (peek() == '.') { consume(); diff --git a/musique/value/number.cc b/musique/value/number.cc index 5f8d0dd..ed90677 100644 --- a/musique/value/number.cc +++ b/musique/value/number.cc @@ -242,7 +242,7 @@ parse_fractional: .location = std::move(token.location) }; } - result += Number{ frac, pow10(frac_end - num_end) }; + result += Number{ (result.num < 0 ? -1 : 1) * frac, pow10(frac_end - num_end) }; } return result.simplify(); diff --git a/regression-tests/builtin/ceil.mq b/regression-tests/builtin/ceil.mq index 27a78f8..17eceb7 100644 --- a/regression-tests/builtin/ceil.mq +++ b/regression-tests/builtin/ceil.mq @@ -1,8 +1,8 @@ -say (ceil (0 - 4)), -say (ceil (0 - 4.2)), -say (ceil (0 - 4.5)), -say (ceil (0 - 4.8)), -say (ceil (0 - 5)), +say (ceil -4), +say (ceil -4.2), +say (ceil -4.5), +say (ceil -4.8), +say (ceil -5), say (ceil 4), say (ceil 4.2), diff --git a/regression-tests/builtin/duration.mq b/regression-tests/builtin/duration.mq new file mode 100644 index 0000000..28114de --- /dev/null +++ b/regression-tests/builtin/duration.mq @@ -0,0 +1,5 @@ +len (1/4), +say (duration (chord c e g)), +say (duration c), +say (duration (c hn e hn)), +say (duration (c 0.3)), diff --git a/regression-tests/builtin/floor.mq b/regression-tests/builtin/floor.mq index 0696ec1..f98c9d0 100644 --- a/regression-tests/builtin/floor.mq +++ b/regression-tests/builtin/floor.mq @@ -1,8 +1,8 @@ -say (floor (0 - 4)), -say (floor (0 - 4.2)), -say (floor (0 - 4.5)), -say (floor (0 - 4.8)), -say (floor (0 - 5)), +say (floor -4), +say (floor -4.2), +say (floor -4.5), +say (floor -4.8), +say (floor -5), say (floor 4), say (floor 4.2), diff --git a/regression-tests/builtin/range.mq b/regression-tests/builtin/range.mq index 61ae424..656ddaf 100644 --- a/regression-tests/builtin/range.mq +++ b/regression-tests/builtin/range.mq @@ -1,17 +1,17 @@ say (range 0), -say (range (0 - 1)), +say (range -1), say (range 10), say (range 1 10), say (range 1 10 2), say (up 0), -say (up (0 - 1)), +say (up -1), say (up 10), say (up 1 10), say (up 1 10 2), say (down 0), -say (down (0 - 1)), +say (down -1), say (down 10), say (down 1 10), say (down 1 10 2), diff --git a/regression-tests/builtin/round.mq b/regression-tests/builtin/round.mq index 09b9fa9..07eabf4 100644 --- a/regression-tests/builtin/round.mq +++ b/regression-tests/builtin/round.mq @@ -1,8 +1,8 @@ -say (round (0 - 4)), -say (round (0 - 4.2)), -say (round (0 - 4.5)), -say (round (0 - 4.8)), -say (round (0 - 5)), +say (round -4), +say (round -4.2), +say (round -4.5), +say (round -4.8), +say (round -5), say (round 4), say (round 4.2), diff --git a/regression-tests/test_db.json b/regression-tests/test_db.json index 599f1ab..4ed1bcc 100644 --- a/regression-tests/test_db.json +++ b/regression-tests/test_db.json @@ -270,6 +270,18 @@ "5" ], "stderr_lines": [] + }, + { + "name": "duration.mq", + "exit_code": 0, + "stdin_lines": [], + "stdout_lines": [ + "3/4", + "1/4", + "1", + "3/10" + ], + "stderr_lines": [] } ] } diff --git a/scripts/test.mk b/scripts/test.mk index 23df39a..3afa48c 100644 --- a/scripts/test.mk +++ b/scripts/test.mk @@ -1,3 +1,3 @@ -test: bin/debug/musique +test: bin/$(os)/debug/musique python3 scripts/test.py