diff --git a/src/interpreter.cc b/src/interpreter.cc index 3d32863..8223fa3 100644 --- a/src/interpreter.cc +++ b/src/interpreter.cc @@ -730,6 +730,33 @@ error: assert(args.back().type == Value::Type::Number, "Only numbers can be used for indexing"); // TODO(assert) return std::move(args.front()).index(i, std::move(args.back()).n.as_int()); }; + + operators["&"] = +[](Interpreter &i, std::vector args) -> Result { + using Chord_Chord = Shape; + + if (Chord_Chord::typecheck(args)) { + auto [lhs, rhs] = Chord_Chord::move_from(args); + auto &l = lhs.notes; + auto &r = rhs.notes; + + // Append one set of notes to another to make bigger chord! + l.reserve(l.size() + r.size()); + std::move(r.begin(), r.end(), std::back_inserter(l)); + + return Value::from(lhs); + } + + return Error { + .details = errors::Unsupported_Types_For { + .type = errors::Unsupported_Types_For::Operator, + .name = "&", + .possibilities = { + "(music, music) -> music", + } + }, + .location = {} + }; + }; } } diff --git a/src/parser.cc b/src/parser.cc index 5dfe760..f4f125f 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -502,7 +502,7 @@ static usize precedense(std::string_view op) if (one_of(op, "and")) return 150; if (one_of(op, "<", ">", "<=", ">=", "==", "!=")) return 200; if (one_of(op, "+", "-")) return 300; - if (one_of(op, "*", "/")) return 400; + if (one_of(op, "*", "/", "&")) return 400; unreachable(); }