diff --git a/src/interpreter.cc b/src/interpreter.cc index 9f7cd67..e1308c1 100644 --- a/src/interpreter.cc +++ b/src/interpreter.cc @@ -609,6 +609,23 @@ error: unreachable(); }); + global.force_define("incoming", +[](Interpreter &i, std::vector args) -> Result { + assert(args.size() == 2, "Wrong arity of 'incoming' function"); + assert(args[0].type == Value::Type::Symbol, "Expected symbol for first argument of 'incoming'"); + assert(is_callable(args[1].type), "Expected function for second argument of 'incoming'"); + + std::string const& symbol = args[0].s; + + if (symbol == "note_on" || symbol == "noteon") { + i.callbacks->note_on = std::move(args[1]); + } else if (symbol == "note_off" || symbol == "noteoff") { + i.callbacks->note_off = std::move(args[1]); + } else { + assert(false, "symbol not recognized for 'incoming'"); + } + return Value{}; + }); + { constexpr auto pgmchange = +[](Interpreter &i, std::vector args) -> Result { using Program = Shape; @@ -668,6 +685,10 @@ Result Interpreter::eval(Ast &&ast) switch (ast.token.type) { case Token::Type::Symbol: { + if (ast.token.source.starts_with('\'')) { + return Value::from(std::move(ast.token.source).substr(1)); + } + auto const value = env->find(std::string(ast.token.source)); assert(value, "Missing variable error is not implemented yet: variable: "s + std::string(ast.token.source)); return *value; diff --git a/src/unicode.cc b/src/unicode.cc index 5f22dd0..a444e5c 100644 --- a/src/unicode.cc +++ b/src/unicode.cc @@ -100,6 +100,11 @@ bool unicode::is_space(u32 space) bool unicode::is_identifier(u32 letter, unicode::First_Character is_first_character) { - return (unicode::is_letter(letter) || letter == '_' || letter == '#' || letter == '$' || letter == '@') - || (!bool(is_first_character) && (letter == '\'' || unicode::is_digit(letter))); + return (unicode::is_letter(letter) + || letter == '\'' + || letter == '_' + || letter == '#' + || letter == '$' + || letter == '@') + || (!bool(is_first_character) && unicode::is_digit(letter)); }