negative numbers; fixed duration builtin
This commit is contained in:
parent
0b8fd86680
commit
87cea02b45
@ -9,14 +9,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Printing version number on non-quiet launch, or when provided `--version` or `:version`
|
|
||||||
- Builtin function documentation generation from C++ Musique implementation source code
|
- Builtin function documentation generation from C++ Musique implementation source code
|
||||||
- New builtins: digits
|
- New builtins: digits
|
||||||
|
- Negative numbers!
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
- Release builder, since it's separate part of the project
|
- 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]
|
## [0.3.1]
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
@ -74,7 +74,7 @@ r add 1, 3
|
|||||||
|
|
||||||
n Wywołanie funkcji
|
n Wywołanie funkcji
|
||||||
n nie przymujących argumentów
|
n nie przymujących argumentów
|
||||||
m constant := (say 42, 10);
|
m constant := (say 42, 10),
|
||||||
m say (call foo)
|
m say (call foo)
|
||||||
p def constant():
|
p def constant():
|
||||||
p print(42)
|
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ć
|
c za każdym razem trzeba ją definiować
|
||||||
|
|
||||||
n Zmiana oktawy do 4tej
|
n Zmiana oktawy do 4tej
|
||||||
m oct 4;
|
m oct 4,
|
||||||
c w SonicPi domyślna oktawa
|
c w SonicPi domyślna oktawa
|
||||||
c jest ustalona jako 4
|
c jest ustalona jako 4
|
||||||
|
|
||||||
|
@ -741,7 +741,7 @@ static Result<Value> builtin_map(Interpreter &interpreter, std::vector<Value> ar
|
|||||||
//:
|
//:
|
||||||
//: # Przykład
|
//: # Przykład
|
||||||
//: ```
|
//: ```
|
||||||
//:
|
//:
|
||||||
//: ```
|
//: ```
|
||||||
/// Scan computes inclusive prefix sum
|
/// Scan computes inclusive prefix sum
|
||||||
static Result<Value> builtin_scan(Interpreter &interpreter, std::vector<Value> args)
|
static Result<Value> builtin_scan(Interpreter &interpreter, std::vector<Value> args)
|
||||||
@ -1071,9 +1071,11 @@ static Result<Value> builtin_duration(Interpreter &interpreter, std::vector<Valu
|
|||||||
auto total = Number{};
|
auto total = Number{};
|
||||||
for (auto &arg : args) {
|
for (auto &arg : args) {
|
||||||
Try(traverse(interpreter, std::move(arg), [&](Chord &c) {
|
Try(traverse(interpreter, std::move(arg), [&](Chord &c) {
|
||||||
|
auto chord_length = Number();
|
||||||
for (Note ¬e : c.notes) {
|
for (Note ¬e : c.notes) {
|
||||||
total += note.length ? *note.length : interpreter.current_context->length;
|
chord_length = std::max(chord_length, note.length ? *note.length : interpreter.current_context->length);
|
||||||
}
|
}
|
||||||
|
total += chord_length;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
@ -1149,7 +1151,7 @@ static Result<Value> builtin_permute(Interpreter &i, std::vector<Value> args)
|
|||||||
return array;
|
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
|
//: # Sortowanie liczb
|
||||||
//: ```
|
//: ```
|
||||||
|
@ -105,7 +105,7 @@ auto Lexer::next_token() -> Result<std::variant<Token, End_Of_File>>
|
|||||||
|
|
||||||
// Lex numeric literals
|
// Lex numeric literals
|
||||||
// They may have following forms: 0, 0.1
|
// 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)) {}
|
while (consume_if(unicode::is_digit)) {}
|
||||||
if (peek() == '.') {
|
if (peek() == '.') {
|
||||||
consume();
|
consume();
|
||||||
|
@ -242,7 +242,7 @@ parse_fractional:
|
|||||||
.location = std::move(token.location)
|
.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();
|
return result.simplify();
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
say (ceil (0 - 4)),
|
say (ceil -4),
|
||||||
say (ceil (0 - 4.2)),
|
say (ceil -4.2),
|
||||||
say (ceil (0 - 4.5)),
|
say (ceil -4.5),
|
||||||
say (ceil (0 - 4.8)),
|
say (ceil -4.8),
|
||||||
say (ceil (0 - 5)),
|
say (ceil -5),
|
||||||
|
|
||||||
say (ceil 4),
|
say (ceil 4),
|
||||||
say (ceil 4.2),
|
say (ceil 4.2),
|
||||||
|
5
regression-tests/builtin/duration.mq
Normal file
5
regression-tests/builtin/duration.mq
Normal file
@ -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)),
|
@ -1,8 +1,8 @@
|
|||||||
say (floor (0 - 4)),
|
say (floor -4),
|
||||||
say (floor (0 - 4.2)),
|
say (floor -4.2),
|
||||||
say (floor (0 - 4.5)),
|
say (floor -4.5),
|
||||||
say (floor (0 - 4.8)),
|
say (floor -4.8),
|
||||||
say (floor (0 - 5)),
|
say (floor -5),
|
||||||
|
|
||||||
say (floor 4),
|
say (floor 4),
|
||||||
say (floor 4.2),
|
say (floor 4.2),
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
say (range 0),
|
say (range 0),
|
||||||
say (range (0 - 1)),
|
say (range -1),
|
||||||
say (range 10),
|
say (range 10),
|
||||||
say (range 1 10),
|
say (range 1 10),
|
||||||
say (range 1 10 2),
|
say (range 1 10 2),
|
||||||
|
|
||||||
say (up 0),
|
say (up 0),
|
||||||
say (up (0 - 1)),
|
say (up -1),
|
||||||
say (up 10),
|
say (up 10),
|
||||||
say (up 1 10),
|
say (up 1 10),
|
||||||
say (up 1 10 2),
|
say (up 1 10 2),
|
||||||
|
|
||||||
say (down 0),
|
say (down 0),
|
||||||
say (down (0 - 1)),
|
say (down -1),
|
||||||
say (down 10),
|
say (down 10),
|
||||||
say (down 1 10),
|
say (down 1 10),
|
||||||
say (down 1 10 2),
|
say (down 1 10 2),
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
say (round (0 - 4)),
|
say (round -4),
|
||||||
say (round (0 - 4.2)),
|
say (round -4.2),
|
||||||
say (round (0 - 4.5)),
|
say (round -4.5),
|
||||||
say (round (0 - 4.8)),
|
say (round -4.8),
|
||||||
say (round (0 - 5)),
|
say (round -5),
|
||||||
|
|
||||||
say (round 4),
|
say (round 4),
|
||||||
say (round 4.2),
|
say (round 4.2),
|
||||||
|
@ -270,6 +270,18 @@
|
|||||||
"5"
|
"5"
|
||||||
],
|
],
|
||||||
"stderr_lines": []
|
"stderr_lines": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "duration.mq",
|
||||||
|
"exit_code": 0,
|
||||||
|
"stdin_lines": [],
|
||||||
|
"stdout_lines": [
|
||||||
|
"3/4",
|
||||||
|
"1/4",
|
||||||
|
"1",
|
||||||
|
"3/10"
|
||||||
|
],
|
||||||
|
"stderr_lines": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
test: bin/debug/musique
|
test: bin/$(os)/debug/musique
|
||||||
python3 scripts/test.py
|
python3 scripts/test.py
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user