Gwion coverage report


Directory: src/
File: src/lib/locale.c
Date: 2023-01-30 18:32:28
Exec Total Coverage
Lines: 31 33 93.9%
Functions: 4 4 100.0%
Branches: 21 40 52.5%

Line Branch Exec Source
1 #include "gwion_util.h"
2 #include "gwion_ast.h"
3 #include "gwion_env.h"
4 #include "vm.h"
5 #include "instr.h"
6 #include "gwion.h"
7 #include "object.h"
8 #include "operator.h"
9 #include "import.h"
10 #include "gwi.h"
11
12 2 static int basic_note(const char c) {
13
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
2 if(c == 'A' || c == 'a') return 0;
14
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if(c == 'B' || c == 'b') return 2;
15
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if(c == 'C' || c == 'c') return 3;
16
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if(c == 'D' || c == 'd') return 5;
17
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if(c == 'E' || c == 'e') return 7;
18
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if(c == 'F' || c == 'f') return 8;
19 if(c == 'G' || c == 'g') return 10;
20 return -1;
21 }
22
23 2 ANN static m_float basic_locale(m_str str) {
24 2 int base = basic_note(str[0]);
25
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if(base == -1) return -1;
26 2 str++;
27 2 const char mod = *str;
28
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if(mod == '#') { base++; str++; }
29
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 else if(mod == 'b') { base--; str++; }
30 char *remainder;
31 2 const long octave = strtol(str, &remainder, 10);
32
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if(*remainder != '\0') return -1;
33 1 const int note = base + 12 * octave + 21;
34 1 return (pow(2, (note - 69) / 12.0) * 440.0);
35 }
36
37 2 static SFUN(BasicLocale) {
38 2 const M_Object arg = *(M_Object*)MEM(0);
39 2 const m_float ret = basic_locale(STRING(arg));
40
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if(ret == -1.0)
41 1 xfun_handle(shred, "invalid value for locale");
42 2 *(m_float*)RETURN = ret;
43 2 }
44
45 638 GWION_IMPORT(locale) {
46
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 638 times.
638 gwidoc(gwi, "Definition of the basic locale");
47 638 GWI_BB(gwi_func_ini(gwi, "float", "BasicLocale"));
48 638 GWI_BB(gwi_func_arg(gwi, "string", "str"));
49 638 GWI_BB(gwi_func_end(gwi, BasicLocale, ae_flag_none));
50 638 return GW_OK;
51 }
52