From: Jérémie Astor Date: Sat, 23 Apr 2022 11:20:41 +0000 (+0200) Subject: :art: improve locale and closures X-Git-Tag: nightly~279 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=95cec4d1901e3b08a8fd2258a7655fa5a0dc8cdf;p=gwion.git :art: improve locale and closures --- diff --git a/src/lib/locale.c b/src/lib/locale.c index 712e3f14..697caad1 100644 --- a/src/lib/locale.c +++ b/src/lib/locale.c @@ -9,17 +9,25 @@ #include "import.h" #include "gwi.h" +static int basic_note(const char c) { + if(c == 'A' || c == 'a') return 0; + if(c == 'B' || c == 'b') return 2; + if(c == 'C' || c == 'c') return 3; + if(c == 'D' || c == 'd') return 5; + if(c == 'E' || c == 'e') return 7; + if(c == 'F' || c == 'f') return 8; + if(c == 'G' || c == 'g') return 10; + return -1; +} + ANN static m_float basic_locale(m_str str) { - const char base = str[0]; + const char base = basic_note(str[0]); + if(base == -1) return -1; str++; - if(base < 'A' || base > 'G') return -1; - m_int bnote = base - 'A'; - if(*str == '#') { bnote++; str++; } - else if(*str == 'b') { bnote--; str++; } char *remainder; const long octave = strtol(str, &remainder, 10); if(*remainder != '\0') return -1; - const int note = bnote + 12 * octave + 21; + const int note = base + 12 * octave + 21; return (pow(2, (note - 69) / 12.0) * 440.0); } diff --git a/src/parse/check.c b/src/parse/check.c index 5d33111e..fab2bc2e 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -333,7 +333,7 @@ static inline Nspc value_owner(const Env env, const Value v) { ANN static void check_upvalue(const Env env, const Exp_Primary *prim) { const Value v = prim->value; - if (GET_FLAG(v, global) || + if (GET_FLAG(v, global) || vflag(v, vflag_fglobal) || (v->from->owner_class && isa(v->from->owner_class, env->class_def) > 0) || nspc_lookup_value1(env->curr, insert_symbol(v->name))) return;